Exemplo n.º 1
0
 private Collection4 introduceClassConstrain(ReflectClass claxx) {
   final Collection4 newConstraints = new Collection4();
   final Iterator4 existingConstraints = iterateConstraints();
   while (existingConstraints.moveNext()) {
     final QCon existingConstraint = (QConObject) existingConstraints.current();
     final BooleanByRef removeExisting = new BooleanByRef(false);
     final QCon newConstraint = existingConstraint.shareParentForClass(claxx, removeExisting);
     if (newConstraint != null) {
       newConstraints.add(newConstraint);
       addConstraint(newConstraint);
       if (removeExisting.value) {
         removeConstraint(existingConstraint);
       }
     }
   }
   return newConstraints;
 }
Exemplo n.º 2
0
 private List4 createQCandidatesList() {
   List4 candidatesList = null;
   Iterator4 i = iterateConstraints();
   while (i.moveNext()) {
     QCon constraint = (QCon) i.current();
     constraint = constraint.getRoot();
     ClassMetadata classMetadata = constraint.getYapClass();
     if (classMetadata == null) {
       continue;
     }
     if (constraintCanBeAddedToExisting(candidatesList, constraint)) {
       continue;
     }
     QCandidates candidates = new QCandidates((LocalTransaction) _trans, classMetadata, null);
     candidatesList = new List4(candidatesList, candidates);
   }
   return candidatesList;
 }
Exemplo n.º 3
0
 public CreateCandidateCollectionResult createCandidateCollection() {
   List4 candidatesList = createQCandidatesList();
   boolean checkDuplicates = false;
   boolean topLevel = true;
   Iterator4 i = iterateConstraints();
   while (i.moveNext()) {
     QCon constraint = (QCon) i.current();
     QCon old = constraint;
     constraint = constraint.getRoot();
     if (constraint != old) {
       checkDuplicates = true;
       topLevel = false;
     }
     ClassMetadata classMetadata = constraint.getYapClass();
     if (classMetadata == null) {
       break;
     }
     addConstraintToCandidatesList(candidatesList, constraint);
   }
   return new CreateCandidateCollectionResult(candidatesList, checkDuplicates, topLevel);
 }
Exemplo n.º 4
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);
    }
  }
Exemplo n.º 5
0
  private boolean forEachConstraintRecursively(Function4 block) {
    Queue4 queue = new NoDuplicatesQueue(new NonblockingQueue());
    Iterator4 constrIter = iterateConstraints();
    while (constrIter.moveNext()) {
      queue.add(constrIter.current());
    }
    while (queue.hasNext()) {
      QCon constr = (QCon) queue.next();
      Boolean cancel = (Boolean) block.apply(constr);
      if (cancel.booleanValue()) {
        return true;
      }

      Iterator4 childIter = constr.iterateChildren();
      while (childIter.moveNext()) {
        queue.add(childIter.current());
      }
      Iterator4 joinIter = constr.iterateJoins();
      while (joinIter.moveNext()) {
        queue.add(joinIter.current());
      }
    }
    return false;
  }
Exemplo n.º 6
0
 private boolean attachToExistingConstraints(
     Collection4 newConstraintsCollector, Object obj, boolean onlyForPaths) {
   boolean found = false;
   final Iterator4 j = iterateConstraints();
   while (j.moveNext()) {
     QCon existingConstraint = (QCon) j.current();
     final BooleanByRef removeExisting = new BooleanByRef(false);
     if (!onlyForPaths || (existingConstraint instanceof QConPath)) {
       QCon newConstraint = existingConstraint.shareParent(obj, removeExisting);
       if (newConstraint != null) {
         newConstraintsCollector.add(newConstraint);
         addConstraint(newConstraint);
         if (removeExisting.value) {
           removeConstraint(existingConstraint);
         }
         found = true;
         if (!onlyForPaths) {
           break;
         }
       }
     }
   }
   return found;
 }