public static final StringWithId createItem(
      Configuration conf, SQLTable primaryTable, final SQLRowValues rs, List<SQLField> fields) {
    final String desc;
    if (rs.getID() == primaryTable.getUndefinedID()) desc = "?";
    else
      desc =
          CollectionUtils.join(
              getShowAs(conf).expandGroupBy(fields),
              " ◄ ",
              new ITransformer<Tuple2<Path, List<FieldPath>>, Object>() {
                public Object transformChecked(Tuple2<Path, List<FieldPath>> ancestorFields) {
                  final List<String> filtered =
                      CollectionUtils.transformAndFilter(
                          ancestorFields.get1(),
                          new ITransformer<FieldPath, String>() {
                            // no need to keep this Transformer in an attribute
                            // even when creating one per line it's the same speed
                            public String transformChecked(FieldPath input) {
                              return input.getString(rs);
                            }
                          },
                          IPredicate.notNullPredicate(),
                          new ArrayList<String>());
                  return CollectionUtils.join(filtered, " ");
                }
              });
    // don't store the whole SQLRowValues to save some memory
    final StringWithId res = new StringWithId(rs.getID(), desc);

    return res;
  }
示例#2
0
 private static <K> SQLTable getSoleTable(CollectionMap<K, SQLTable> m, K key)
     throws IllegalArgumentException {
   final Collection<SQLTable> res = m.getNonNull(key);
   if (res.size() > 1)
     throw new IllegalArgumentException(
         key
             + " is not unique: "
             + CollectionUtils.join(
                 res,
                 ",",
                 new ITransformer<SQLTable, SQLName>() {
                   @Override
                   public SQLName transformChecked(SQLTable input) {
                     return input.getSQLName();
                   }
                 }));
   return CollectionUtils.getSole(res);
 }
示例#3
0
 protected final void outClausesAsString(
     final StringBuffer res, final SQLName tableName, final Set<ClauseType> types) {
   final List<DeferredClause> clauses = new ArrayList<DeferredClause>();
   for (final ClauseType type : types) clauses.addAll(this.outClauses.getNonNull(type));
   this.modifyOutClauses(clauses);
   if (clauses.size() > 0) {
     res.append("\n\n");
     res.append(
         CollectionUtils.join(
             clauses,
             "\n",
             new ITransformer<DeferredClause, String>() {
               @Override
               public String transformChecked(DeferredClause input) {
                 return input.asString(ChangeTable.this, tableName);
               }
             }));
   }
 }
示例#4
0
 private static List<String> cat(
     List<? extends ChangeTable<?>> cts, final String r, final boolean forceCat) {
   final List<String> res = new ArrayList<String>();
   for (final ConcatStep step : ConcatStep.values()) {
     for (final ChangeTable<?> ct : cts) {
       final String asString = ct.asString(r, step);
       if (asString != null && asString.length() > 0) {
         res.add(asString);
       }
     }
   }
   // don't return [""] because the caller might test the size of the result and assume that
   // the DB was changed
   // MySQL needs to have its "alter table add/drop fk" in separate execute()
   // (multiple add would work in 5.0)
   if (!forceCat && (cts.size() == 0 || cts.get(0).getSyntax().getSystem() == SQLSystem.MYSQL))
     return res;
   else return Collections.singletonList(CollectionUtils.join(res, "\n"));
 }
示例#5
0
 /**
  * Construct a clause like "field1 not in (value, ...)".
  *
  * @param field1 le champs à tester.
  * @param in <code>true</code> for "in", <code>false</code> for "not in".
  * @param values les valeurs.
  */
 public Where(final FieldRef field1, final boolean in, Collection<?> values) {
   if (values.isEmpty()) {
     this.clause = in ? FALSE.getClause() : TRUE.getClause();
   } else {
     this.fields.add(field1);
     this.clause =
         getInClause(
             field1,
             in,
             CollectionUtils.join(
                 values,
                 ",",
                 new ITransformer<Object, String>() {
                   @Override
                   public String transformChecked(Object input) {
                     return field1.getField().getType().toString(input);
                   }
                 }));
   }
 }