public AbstractQueryResult toIdList() {
   IdListQueryResult res = new IdListQueryResult(transaction(), knownSize());
   IntIterator4 i = iterateIDs();
   while (i.moveNext()) {
     res.add(i.currentInt());
   }
   return res;
 }
示例#2
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);
  }