Ejemplo n.º 1
0
 Constraint toConstraint(final Collection4 constraints) {
   if (constraints.size() == 1) {
     return (Constraint) constraints.singleElement();
   } else if (constraints.size() > 0) {
     Constraint[] constraintArray = new Constraint[constraints.size()];
     constraints.toArray(constraintArray);
     return new QConstraints(_trans, constraintArray);
   }
   return null;
 }
Ejemplo n.º 2
0
 public Constraints constraints() {
   synchronized (streamLock()) {
     Constraint[] constraints = new Constraint[i_constraints.size()];
     i_constraints.toArray(constraints);
     return new QConstraints(_trans, constraints);
   }
 }
Ejemplo n.º 3
0
  private Constraint addEvaluationToAllConstraints(QConEvaluation eval) {

    if (i_constraints.size() == 0) {
      _trans
          .container()
          .classCollection()
          .iterateTopLevelClasses(
              new Visitor4() {
                public void visit(Object obj) {
                  ClassMetadata classMetadata = (ClassMetadata) obj;
                  QConClass qcc = new QConClass(_trans, classMetadata.classReflector());
                  addConstraint(qcc);
                  toConstraint(i_constraints).or(qcc);
                }
              });
    }

    Iterator4 i = iterateConstraints();
    while (i.moveNext()) {
      ((QCon) i.current()).addConstraint(eval);
    }

    // FIXME: should return valid Constraint object
    return null;
  }
Ejemplo n.º 4
0
 private QConClass classConstraint() {
   if (i_constraints.size() != 1) {
     return null;
   }
   Constraint constr = singleConstraint();
   if (constr.getClass() != QConClass.class) {
     return null;
   }
   return (QConClass) constr;
 }
Ejemplo n.º 5
0
 public QueryResult getQueryResult() {
   synchronized (streamLock()) {
     if (i_constraints.size() == 0) {
       return executeAllObjectsQuery();
     }
     QueryResult result = executeClassOnlyQuery();
     if (result != null) {
       return result;
     }
     optimizeJoins();
     return executeQuery();
   }
 }
Ejemplo n.º 6
0
 private Constraint addInterfaceConstraint(ReflectClass claxx) {
   Collection4 classes = stream().classCollection().forInterface(claxx);
   if (classes.size() == 0) {
     QConClass qcc = new QConClass(_trans, null, null, claxx);
     addConstraint(qcc);
     return qcc;
   }
   Iterator4 i = classes.iterator();
   Constraint constr = null;
   while (i.moveNext()) {
     ClassMetadata classMetadata = (ClassMetadata) i.current();
     ReflectClass classMetadataClaxx = classMetadata.classReflector();
     if (classMetadataClaxx != null) {
       if (!classMetadataClaxx.isInterface()) {
         if (constr == null) {
           constr = constrain(classMetadataClaxx);
         } else {
           constr = constr.or(constrain(classMetadata.classReflector()));
         }
       }
     }
   }
   return constr;
 }
Ejemplo n.º 7
0
  private boolean descend1(final QQuery query, final String fieldName, IntByRef run) {
    if (run.value == 2 || i_constraints.size() == 0) {

      // On the second run we are really creating a second independant
      // query network that is not joined to other higher level
      // constraints.
      // Let's see how this works out. We may need to join networks.

      run.value = 0; // prevent a double run of this code

      stream()
          .classCollection()
          .attachQueryNode(
              fieldName,
              new Visitor4() {

                boolean untypedFieldConstraintCollected = false;

                public void visit(Object obj) {

                  Object[] pair = ((Object[]) obj);
                  ClassMetadata containingClass = (ClassMetadata) pair[0];
                  FieldMetadata field = (FieldMetadata) pair[1];

                  if (isTyped(field)) {
                    addFieldConstraint(containingClass, field);
                    return;
                  }

                  if (untypedFieldConstraintCollected) return;

                  addFieldConstraint(containingClass, field);
                  untypedFieldConstraintCollected = true;
                }

                private boolean isTyped(FieldMetadata field) {
                  return !Handlers4.isUntyped(field.getHandler());
                }

                private void addFieldConstraint(
                    ClassMetadata containingClass, FieldMetadata field) {
                  QConClass qcc =
                      new QConClass(
                          _trans, null, field.qField(_trans), containingClass.classReflector());
                  addConstraint(qcc);
                  toConstraint(i_constraints).or(qcc);
                }
              });
    }

    checkConstraintsEvaluationMode();

    final BooleanByRef foundClass = new BooleanByRef(false);
    Iterator4 i = iterateConstraints();
    while (i.moveNext()) {
      if (((QCon) i.current()).attach(query, fieldName)) {
        foundClass.value = true;
      }
    }
    return foundClass.value;
  }