Package org.jooq

Examples of org.jooq.Condition


            // The product {aggregateFunctions} x {in}
            List<Field<?>> aggregationSelects = new ArrayList<Field<?>>();
            for (Field<?> inField : in) {
                for (Field<?> aggregateFunction : aggregateFunctions) {
                    Condition join = trueCondition();

                    for (Field<?> field : groupingFields) {
                        join = join.and(condition(pivot, field));
                    }

                    @SuppressWarnings("unchecked")
                    Select<?> aggregateSelect = using(configuration)
                            .select(aggregateFunction)
View Full Code Here


                }

                // The condition for the ON clause:
                // --------------------------------
                Set<Field<?>> onFields = new HashSet<Field<?>>();
                Condition condition = null;
                if (getH2Keys().isEmpty()) {
                    UniqueKey<?> key = table.getPrimaryKey();

                    if (key != null) {
                        onFields.addAll(key.getFields());

                        for (int i = 0; i < key.getFields().size(); i++) {
                            Condition rhs = key.getFields().get(i).equal((Field) src.field(i));

                            if (condition == null) {
                                condition = rhs;
                            }
                            else {
                                condition = condition.and(rhs);
                            }
                        }
                    }

                    // This should probably execute an INSERT statement
                    else {
                        throw new IllegalStateException("Cannot omit KEY() clause on a non-Updatable Table");
                    }
                }
                else {
                    for (int i = 0; i < getH2Keys().size(); i++) {
                        int matchIndex = getH2Fields().indexOf(getH2Keys().get(i));
                        if (matchIndex == -1) {
                            throw new IllegalStateException("Fields in KEY() clause must be part of the fields specified in MERGE INTO table (...)");
                        }

                        onFields.addAll(getH2Keys());
                        Condition rhs = getH2Keys().get(i).equal((Field) src.field(matchIndex));

                        if (condition == null) {
                            condition = rhs;
                        }
                        else {
View Full Code Here

        if (getOrderBy().isEmpty() || getSeek().isEmpty()) {
            return condition;
        }
        else {
            SortFieldList o = getOrderBy();
            Condition c = null;

            // [#2786] TODO: Check if NULLS FIRST | NULLS LAST clauses are
            // contained in the SortFieldList, in case of which, the below
            // predicates will become a lot more complicated.
            if (o.nulls()) {}
View Full Code Here

            for (int i = 0; i < leftFields.length; i++) {
                conditions.add(leftFields[i].equal((Field) rightFields[i]));
            }

            Condition result = new CombinedCondition(Operator.AND, conditions);

            if (comparator == NOT_EQUALS) {
                result = result.not();
            }

            return (QueryPartInternal) result;
        }

        // Ordering comparison predicate simulation
        else if (asList(GREATER, GREATER_OR_EQUAL, LESS, LESS_OR_EQUAL).contains(comparator) &&
                 asList(DERBY, CUBRID, FIREBIRD, SQLITE).contains(dialect.family())) {

            // The order component of the comparator (stripping the equal component)
            Comparator order
                = (comparator == GREATER) ? GREATER
                : (comparator == GREATER_OR_EQUAL) ? GREATER
                : (comparator == LESS) ? LESS
                : (comparator == LESS_OR_EQUAL) ? LESS
                : null;

            // [#2658] The factored order component of the comparator (enforcing the equal component)
            Comparator factoredOrder
                = (comparator == GREATER) ? GREATER_OR_EQUAL
                : (comparator == GREATER_OR_EQUAL) ? GREATER_OR_EQUAL
                : (comparator == LESS) ? LESS_OR_EQUAL
                : (comparator == LESS_OR_EQUAL) ? LESS_OR_EQUAL
                : null;

            // Whether the comparator has an equal component
            boolean equal
                = (comparator == GREATER_OR_EQUAL)
                ||(comparator == LESS_OR_EQUAL);

            // The following algorithm simulates the equivalency of these expressions:
            // (A, B, C) > (X, Y, Z)
            // (A > X) OR (A = X AND B > Y) OR (A = X AND B = Y AND C > Z)
            List<Condition> outer = new ArrayList<Condition>();

            Field<?>[] leftFields = left.fields();
            Field<?>[] rightFields = right.fields();

            for (int i = 0; i < leftFields.length; i++) {
                List<Condition> inner = new ArrayList<Condition>();

                for (int j = 0; j < i; j++) {
                    inner.add(leftFields[j].equal((Field) rightFields[j]));
                }

                inner.add(leftFields[i].compare(order, (Field) rightFields[i]));
                outer.add(new CombinedCondition(Operator.AND, inner));
            }

            if (equal) {
                outer.add(new RowCondition(left, right, Comparator.EQUALS));
            }

            Condition result = new CombinedCondition(Operator.OR, outer);

            // [#2658] For performance reasons, an additional, redundant
            // predicate is factored out to favour the application of range
            // scans as the topmost predicate is AND-connected, not
            // OR-connected:
View Full Code Here

      LambdaInfo where = LambdaInfo.analyze(context.metamodel, lambda);
      if (where == null) throw new IllegalArgumentException("Could not create convert Lambda into a query");
      WhereTransform whereTransform = new WhereTransform(context.metamodel, where);
      List<Table<?>> from = new ArrayList<>();
      from.addAll(fromTables);
      Condition cond = whereTransform.apply(from);
      return new JinqJooqQueryN(context, fromTables, cond);
   }
View Full Code Here

//      }
      if (!left.isSingleColumn() || !right.isSingleColumn())
         throw new TypedValueVisitorException("Do not know how to compare multiple columns together");
      Field leftField = (Field)left.getOnlyColumn();
      Field rightField = (Field)right.getOnlyColumn();
      Condition result = null;
      switch (val.compOp)
      {
         case eq:
            result = leftField.eq(rightField);
            break;
View Full Code Here

//         if (query instanceof SelectFromWhere)
//         {
//            SelectFromWhere<V> sfw = (SelectFromWhere<V>)query;
            SymbExToColumns translator = new SymbExToColumns(metamodel,
                  new SelectFromWhereLambdaArgumentHandler(where, fromList));
            Condition methodExpr = null;
            for (int n = 0; n < where.symbolicAnalysis.paths.size(); n++)
            {
               PathAnalysis path = where.symbolicAnalysis.paths.get(n);

               TypedValue returnVal = PathAnalysisSimplifier.simplifyBoolean(path.getReturnValue(), Collections.emptyMap());
               ColumnExpressions<?> returnColumns = translator.transform(returnVal);
               if (!returnColumns.isSingleColumn()) throw new IllegalArgumentException("Where lambda should only return a single column of data");
               QueryPart returnExpr = returnColumns.getOnlyColumn();

               if (returnVal instanceof ConstantValue.BooleanConstant)
               {
                  if (((ConstantValue.BooleanConstant)returnVal).val)
                  {
                     // This path returns true, so it's redundant to actually
                     // put true into the final code.
                     returnExpr = null;
                  }
                  else
                  {
                     // This path returns false, so we can ignore it
                     continue;
                  }
               }
              
               // Handle where path conditions
               Condition conditionExpr = null;
               for (TypedValue cmp: path.getConditions())
               {
                  ColumnExpressions<?> col = translator.transform(cmp);
                  if (!col.isSingleColumn()) throw new IllegalArgumentException("Expecting a single column");
                  Condition expr = (Condition)col.getOnlyColumn();
                  if (conditionExpr != null)
                     conditionExpr = conditionExpr.and(expr);
                  else
                     conditionExpr = expr;
               }
              
               // Merge path conditions and return value to create a value for the path
               Condition pathExpr = (Condition)returnExpr;
               if (conditionExpr != null)
               {
                  if (pathExpr == null)
                     pathExpr = conditionExpr;
                  else
                     pathExpr = pathExpr.and(conditionExpr);
               }
              
               // Merge into new expression summarizing the method
               if (methodExpr != null)
                  methodExpr = methodExpr.or(pathExpr);
View Full Code Here

TOP

Related Classes of org.jooq.Condition

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.