Exemplo n.º 1
0
  public void run(STClass[] classes, STEngine[] engines, boolean a_quiet) {
    begin();
    setSodaTestOn(classes);

    for (int i = 0; i < engines.length; i++) {
      engine = engines[i];
      engine.reset();
      engine.open();
      store(classes);
      engine.commit();
      engine.close();
      engine.open();
      test(classes);
      engine.close();
      engine.reset();
    }

    if (failedTestClasses.size() > 0) {
      System.err.println("\nFailed test classes:\n");
      Iterator4 i = failedTestClasses.iterator();
      while (i.moveNext()) {
        System.err.println(i.current().getClass().getName());
      }
      System.err.println("\n");
    }
  }
Exemplo n.º 2
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;
  }
Exemplo n.º 3
0
 private void logConstraints() {
   if (Debug4.queries) {
     Iterator4 i = iterateConstraints();
     while (i.moveNext()) {
       ((QCon) i.current()).log("");
     }
   }
 }
Exemplo n.º 4
0
 public void unmarshall(final Transaction a_trans) {
   _evaluationMode = QueryEvaluationMode.fromInt(_evaluationModeAsInt);
   _trans = a_trans;
   Iterator4 i = iterateConstraints();
   while (i.moveNext()) {
     ((QCon) i.current()).unmarshall(a_trans);
   }
 }
Exemplo n.º 5
0
  public void marshall() {
    checkConstraintsEvaluationMode();

    _evaluationModeAsInt = _evaluationMode.asInt();
    Iterator4 i = iterateConstraints();
    while (i.moveNext()) {
      ((QCon) i.current()).getRoot().marshall();
    }
  }
Exemplo n.º 6
0
 public int addressForId(int id) {
   BTreeRange range = _slotTree.searchRange(trans(), new IdSlotMapping(id, 0, 0));
   Iterator4 pointers = range.pointers();
   if (pointers.moveNext()) {
     BTreePointer pointer = (BTreePointer) pointers.current();
     return ((IdSlotMapping) pointer.key())._address;
   }
   return 0;
 }
Exemplo n.º 7
0
 private void addConstraintToCandidatesList(List4 candidatesList, QCon qcon) {
   if (candidatesList == null) {
     return;
   }
   Iterator4 j = new Iterator4Impl(candidatesList);
   while (j.moveNext()) {
     QCandidates candidates = (QCandidates) j.current();
     candidates.addConstraint(qcon);
   }
 }
Exemplo n.º 8
0
 private boolean constraintCanBeAddedToExisting(List4 candidatesList, QCon constraint) {
   Iterator4 j = new Iterator4Impl(candidatesList);
   while (j.moveNext()) {
     QCandidates candidates = (QCandidates) j.current();
     if (candidates.fitsIntoExistingConstraintHierarchy(constraint)) {
       return true;
     }
   }
   return false;
 }
Exemplo n.º 9
0
 public String toString() {
   StringBuffer sb = new StringBuffer();
   sb.append("QQueryBase\n");
   Iterator4 i = iterateConstraints();
   while (i.moveNext()) {
     QCon constraint = (QCon) i.current();
     sb.append(constraint);
     sb.append("\n");
   }
   return sb.toString();
 }
Exemplo n.º 10
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.º 11
0
 public int mappedId(int oldID) {
   if (_cache.orig() == oldID) {
     return _cache.mapped();
   }
   int classID = mappedClassID(oldID);
   if (classID != 0) {
     return classID;
   }
   BTreeRange range = _idTree.searchRange(trans(), new MappedIDPair(oldID, 0));
   Iterator4 pointers = range.pointers();
   if (pointers.moveNext()) {
     BTreePointer pointer = (BTreePointer) pointers.current();
     _cache = (MappedIDPair) pointer.key();
     return _cache.mapped();
   }
   return 0;
 }
Exemplo n.º 12
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.º 13
0
  private static ReflectConstructorSpec findConstructor(
      final ReflectClass claxx, Tree sortedConstructors) {
    if (sortedConstructors == null) {
      return ReflectConstructorSpec.INVALID_CONSTRUCTOR;
    }

    Iterator4 iter = new TreeNodeIterator(sortedConstructors);
    while (iter.moveNext()) {
      Object current = iter.current();
      ReflectConstructor constructor = (ReflectConstructor) ((TreeIntObject) current)._object;
      Object[] args = nullArgumentsFor(constructor);
      Object res = constructor.newInstance(args);
      if (res != null) {
        return new ReflectConstructorSpec(constructor, args);
      }
    }
    return ReflectConstructorSpec.INVALID_CONSTRUCTOR;
  }
Exemplo n.º 14
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.º 15
0
  public Iterator4 executeSnapshot() {
    final CreateCandidateCollectionResult r = createCandidateCollection();

    final Collection4 executionPath = executionPath(r);

    Iterator4 candidatesIterator = new Iterator4Impl(r.candidateCollection);

    Collection4 snapshots = new Collection4();
    while (candidatesIterator.moveNext()) {
      QCandidates candidates = (QCandidates) candidatesIterator.current();
      snapshots.add(candidates.executeSnapshot(executionPath));
    }

    Iterator4 snapshotsIterator = snapshots.iterator();
    final CompositeIterator4 resultingIDs = new CompositeIterator4(snapshotsIterator);

    if (!r.checkDuplicates) {
      return resultingIDs;
    }

    return checkDuplicates(resultingIDs);
  }
Exemplo n.º 16
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;
 }
Exemplo n.º 17
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;
 }
Exemplo n.º 18
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.º 19
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.º 20
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;
  }
Exemplo n.º 21
0
  public void executeLocal(final IdListQueryResult result) {
    checkConstraintsEvaluationMode();

    CreateCandidateCollectionResult r = createCandidateCollection();

    boolean checkDuplicates = r.checkDuplicates;
    boolean topLevel = r.topLevel;
    List4 candidateCollection = r.candidateCollection;

    if (Debug4.queries) {
      logConstraints();
    }

    if (candidateCollection != null) {

      final Collection4 executionPath = topLevel ? null : fieldPathFromTop();

      Iterator4 i = new Iterator4Impl(candidateCollection);
      while (i.moveNext()) {
        ((QCandidates) i.current()).execute();
      }

      if (candidateCollection._next != null) {
        checkDuplicates = true;
      }

      if (checkDuplicates) {
        result.checkDuplicates();
      }

      final ObjectContainerBase stream = stream();
      i = new Iterator4Impl(candidateCollection);
      while (i.moveNext()) {
        QCandidates candidates = (QCandidates) i.current();
        if (topLevel) {
          candidates.traverse(result);
        } else {
          candidates.traverse(
              new Visitor4() {
                public void visit(Object a_object) {
                  QCandidate candidate = (QCandidate) a_object;
                  if (candidate.include()) {
                    TreeInt ids = new TreeInt(candidate._key);
                    final ByRef<TreeInt> idsNew = new ByRef<TreeInt>();
                    Iterator4 itPath = executionPath.iterator();
                    while (itPath.moveNext()) {
                      idsNew.value = null;
                      final String fieldName = (String) (itPath.current());
                      if (ids != null) {
                        ids.traverse(
                            new Visitor4() {
                              public void visit(Object treeInt) {
                                int id = ((TreeInt) treeInt)._key;
                                StatefulBuffer reader = stream.readStatefulBufferById(_trans, id);
                                if (reader != null) {
                                  ObjectHeader oh = new ObjectHeader(stream, reader);
                                  CollectIdContext context =
                                      new CollectIdContext(_trans, oh, reader);
                                  oh.classMetadata().collectIDs(context, fieldName);
                                  Tree.traverse(
                                      context.ids(),
                                      new Visitor4<TreeInt>() {
                                        public void visit(TreeInt node) {
                                          idsNew.value = TreeInt.add(idsNew.value, node._key);
                                        }
                                      });
                                }
                              }
                            });
                      }
                      ids = (TreeInt) idsNew.value;
                    }
                    if (ids != null) {
                      ids.traverse(
                          new Visitor4() {
                            public void visit(Object treeInt) {
                              result.addKeyCheckDuplicates(((TreeInt) treeInt)._key);
                            }
                          });
                    }
                  }
                }
              });
        }
      }
    }
    sort(result);
  }
Exemplo n.º 22
0
 public void checkConstraintsEvaluationMode() {
   Iterator4 constraints = iterateConstraints();
   while (constraints.moveNext()) {
     ((QConObject) constraints.current()).setEvaluationMode();
   }
 }