示例#1
0
        @Override
        public Iterator<TitanRelation> getNew(final VertexCentricQuery query) {
          return (Iterator)
              ((InternalVertex) query.getVertex())
                  .getAddedRelations(
                      new Predicate<InternalRelation>() {
                        // Need to filter out self-loops if query only asks for one direction

                        private TitanRelation previous = null;

                        @Override
                        public boolean apply(@Nullable InternalRelation relation) {
                          if (query.hasSingleDirection()
                              && (relation instanceof TitanEdge)
                              && ((TitanEdge) relation).isLoop()) {
                            if (relation.equals(previous)) return false;
                            else previous = relation;
                          }
                          return query.matches(relation);
                        }
                      })
                  .iterator();
        }
示例#2
0
        @Override
        public Iterator<TitanRelation> execute(final VertexCentricQuery query) {
          if (query.getVertex().isNew()) return Iterators.emptyIterator();

          final EdgeSerializer edgeSerializer = graph.getEdgeSerializer();
          FittedSliceQuery sq = edgeSerializer.getQuery(query);
          final boolean fittedQuery = sq.isFitted();
          final InternalVertex v = query.getVertex();
          final boolean needsFiltering = !sq.isFitted() || !deletedRelations.isEmpty();
          if (needsFiltering && sq.hasLimit())
            sq = new FittedSliceQuery(sq, QueryUtil.updateLimit(sq.getLimit(), 1.1));

          Iterable<TitanRelation> result = null;
          double limitMultiplier = 1.0;
          int previousDiskSize = 0;
          boolean finished;
          do {
            finished = true;
            Iterable<Entry> iter = null;

            if (v instanceof CacheVertex) {
              CacheVertex cv = (CacheVertex) v;
              iter =
                  ((CacheVertex) v)
                      .loadRelations(
                          sq,
                          new Retriever<SliceQuery, List<Entry>>() {
                            @Override
                            public List<Entry> get(SliceQuery query) {
                              return graph.edgeQuery(v.getID(), query, txHandle);
                            }
                          });
            } else {
              iter = graph.edgeQuery(v.getID(), sq, txHandle);
            }
            result =
                Iterables.transform(
                    iter,
                    new Function<Entry, TitanRelation>() {
                      @Nullable
                      @Override
                      public TitanRelation apply(@Nullable Entry entry) {
                        return edgeSerializer.readRelation(v, entry);
                      }
                    });
            if (needsFiltering) {
              result =
                  Iterables.filter(
                      result,
                      new Predicate<TitanRelation>() {
                        @Override
                        public boolean apply(@Nullable TitanRelation relation) {
                          // Filter out updated and deleted relations
                          return (relation == ((InternalRelation) relation).it()
                                  && !deletedRelations.containsKey(Long.valueOf(relation.getID())))
                              && (fittedQuery || query.matches(relation));
                        }
                      });
            }
            // Determine termination
            if (needsFiltering && query.hasLimit()) {
              if (!IterablesUtil.sizeLargerOrEqualThan(result, query.getLimit())) {
                int currentDiskSize = IterablesUtil.size(iter);
                if (currentDiskSize > previousDiskSize) {
                  finished = false;
                  previousDiskSize = currentDiskSize;
                  limitMultiplier *= 2;
                  sq =
                      new FittedSliceQuery(
                          sq, QueryUtil.updateLimit(sq.getLimit(), limitMultiplier));
                }
              }
            }
          } while (!finished);

          return result.iterator();
        }
示例#3
0
 @Override
 public boolean hasNew(final VertexCentricQuery query) {
   return query.getVertex().isNew()
       || ((InternalVertex) query.getVertex()).hasAddedRelations();
 }