Пример #1
0
  // Our QConPath objects are just placeholders to fields,
  // so the parents are reachable.
  // If we find a "real" constraint, we throw the QPath
  // out and replace it with the other constraint.
  private void morph(BooleanByRef removeExisting, QCon newConstraint, ReflectClass claxx) {
    boolean mayMorph = true;
    if (claxx != null) {
      ClassMetadata yc = i_trans.container().produceClassMetadata(claxx);
      if (yc != null) {
        Iterator4 i = iterateChildren();
        while (i.moveNext()) {
          QField qf = ((QCon) i.current()).getField();
          if (!yc.hasField(i_trans.container(), qf.name())) {
            mayMorph = false;
            break;
          }
        }
      }
    }

    if (mayMorph) {
      Iterator4 j = iterateChildren();
      while (j.moveNext()) {
        newConstraint.addConstraint((QCon) j.current());
      }
      if (hasJoins()) {
        Iterator4 k = iterateJoins();
        while (k.moveNext()) {
          QConJoin qcj = (QConJoin) k.current();
          qcj.exchangeConstraint(this, newConstraint);
          newConstraint.addJoin(qcj);
        }
      }
      i_parent.exchangeConstraint(this, newConstraint);
      removeExisting.value = true;

    } else {
      i_parent.addConstraint(newConstraint);
    }
  }
Пример #2
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;
  }