com.tinkerpop.blueprints.CloseableIterable Java Examples

The following examples show how to use com.tinkerpop.blueprints.CloseableIterable. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BaseIndexValuesTableWrapper.java    From AccumuloGraph with Apache License 2.0 6 votes vote down vote up
/**
 * Get elements with the key/value pair.
 * @param key
 * @param value
 * @return
 */
@SuppressWarnings("unchecked")
public <T extends Element> CloseableIterable<T> readElementsFromIndex(String key, Object value) {
  Scanner scan = getScanner();
  byte[] id = AccumuloByteSerializer.serialize(value);
  scan.setRange(Range.exact(new Text(id)));
  scan.fetchColumnFamily(new Text(key));

  final ElementIndexParser<? extends AccumuloElement> parser =
      Vertex.class.equals(elementType) ? new VertexIndexParser(globals) :
        new EdgeIndexParser(globals);

      return new ScannerIterable<T>(scan) {
        @Override
        public T next(PeekingIterator<Entry<Key,Value>> iterator) {
          return (T) parser.parse(Arrays.asList(iterator.next()));
        }      
      };
}
 
Example #2
Source File: EdgeTableWrapper.java    From AccumuloGraph with Apache License 2.0 5 votes vote down vote up
public CloseableIterable<Edge> getEdges() {
  Scanner scan = getScanner();
  scan.fetchColumnFamily(new Text(Constants.LABEL));

  if (globals.getConfig().getPreloadedProperties() != null) {
    for (String key : globals.getConfig().getPreloadedProperties()) {
      scan.fetchColumnFamily(new Text(key));
    }
  }

  final EdgeParser parser = new EdgeParser(globals);

  return new ScannerIterable<Edge>(scan) {
    @Override
    public Edge next(PeekingIterator<Entry<Key, Value>> iterator) {
      // TODO could also check local cache before creating a new instance?

      String rowId = iterator.peek().getKey().getRow().toString();

      List<Entry<Key, Value>> entries =
          new ArrayList<Entry<Key, Value>>();

      // MDL 05 Jan 2014:  Why is this equalsIgnoreCase??
      while (iterator.peek() != null && rowId.equalsIgnoreCase(iterator
          .peek().getKey().getRow().toString())) {
        entries.add(iterator.next());
      }

      AccumuloEdge edge = parser.parse(rowId, entries);
      globals.getCaches().cache(edge, Edge.class);

      return edge;
    }
  };
}
 
Example #3
Source File: VertexTableWrapper.java    From AccumuloGraph with Apache License 2.0 5 votes vote down vote up
public CloseableIterable<Vertex> getVerticesInRange(Object fromId, Object toId) {
  Scanner scan = getScanner();
  scan.setRange(new Range(fromId != null ? fromId.toString() : null,
      toId != null ? toId.toString() : null));
  scan.fetchColumnFamily(new Text(Constants.LABEL));

  if (globals.getConfig().getPreloadedProperties() != null) {
    for (String key : globals.getConfig().getPreloadedProperties()) {
      scan.fetchColumnFamily(new Text(key));
    }
  }

  final VertexParser parser = new VertexParser(globals);

  return new ScannerIterable<Vertex>(scan) {
    @Override
    public Vertex next(PeekingIterator<Entry<Key, Value>> iterator) {
      // TODO could also check local cache before creating a new instance?

      String rowId = iterator.peek().getKey().getRow().toString();

      List<Entry<Key, Value>> entries =
          new ArrayList<Entry<Key, Value>>();

      while (iterator.peek() != null && rowId.equals(iterator
          .peek().getKey().getRow().toString())) {
        entries.add(iterator.next());
      }

      AccumuloVertex vertex = parser.parse(rowId, entries);
      globals.getCaches().cache(vertex, Vertex.class);

      return vertex;
    }
  };
}
 
Example #4
Source File: AccumuloVertex.java    From AccumuloGraph with Apache License 2.0 5 votes vote down vote up
@Override
public void remove() {
  globals.getCaches().remove(getId(), Vertex.class);

  super.removeElementFromNamedIndexes();

  // Throw exception if the element does not exist.
  if (!globals.getVertexWrapper().elementExists(id)) {
    throw ExceptionFactory.vertexWithIdDoesNotExist(getId());
  }

  // Remove properties from key/value indexes.
  Map<String, Object> props = globals.getVertexWrapper()
      .readAllProperties(this);

  for (Entry<String,Object> ent : props.entrySet()) {
    globals.getVertexKeyIndexWrapper().removePropertyFromIndex(this,
        ent.getKey(), ent.getValue());
  }

  // Remove edges incident to this vertex.
  CloseableIterable<Edge> iter = (CloseableIterable<Edge>)getEdges(Direction.BOTH);
  for (Edge edge : iter) {
    edge.remove();
  }
  iter.close();

  globals.checkedFlush();

  // Get rid of the vertex.
  globals.getVertexWrapper().deleteVertex(this);
  globals.checkedFlush();
}
 
Example #5
Source File: ActiveVersionedIndex.java    From antiquity with GNU General Public License v3.0 5 votes vote down vote up
@Override
public CloseableIterable<T> get(final String key, final Object value) {
    if (Vertex.class.isAssignableFrom(this.getIndexClass())) {
        return new ActiveVersionedVertexIterable((Iterable) this.eventIndex.get(key, value), graph);
    } else {
        return (CloseableIterable<T>) new ActiveVersionedEdgeIterable<V>((Iterable<Edge>) this.eventIndex.get(key,
                value), graph);
    }
}
 
Example #6
Source File: ReadOnlyIndex.java    From org.openntf.domino with Apache License 2.0 5 votes vote down vote up
public CloseableIterable<T> get(final String key, final Object value) {
    if (Vertex.class.isAssignableFrom(this.getIndexClass())) {
        return (CloseableIterable<T>) new ReadOnlyVertexIterable((Iterable<Vertex>) this.rawIndex.get(key, value));
    } else {
        return (CloseableIterable<T>) new ReadOnlyEdgeIterable((Iterable<Edge>) this.rawIndex.get(key, value));
    }
}
 
Example #7
Source File: MultiIterable.java    From org.openntf.domino with Apache License 2.0 5 votes vote down vote up
@Override
public void close() {
    for (Iterable<S> itty : iterables) {
        if (itty instanceof CloseableIterable) {
            ((CloseableIterable<S>) itty).close();
        }
    }
}
 
Example #8
Source File: EventIndex.java    From org.openntf.domino with Apache License 2.0 5 votes vote down vote up
public CloseableIterable<T> get(final String key, final Object value) {
    if (Vertex.class.isAssignableFrom(this.getIndexClass())) {
        return (CloseableIterable<T>) new EventVertexIterable((Iterable<Vertex>) this.rawIndex.get(key, value), this.eventGraph);
    } else {
        return (CloseableIterable<T>) new EventEdgeIterable((Iterable<Edge>) this.rawIndex.get(key, value), this.eventGraph);
    }
}
 
Example #9
Source File: EventVertexIterable.java    From org.openntf.domino with Apache License 2.0 4 votes vote down vote up
public void close() {
    if (iterable instanceof CloseableIterable) {
        ((CloseableIterable) iterable).close();
    }
}
 
Example #10
Source File: PartitionVertexIterable.java    From org.openntf.domino with Apache License 2.0 4 votes vote down vote up
public void close() {
    if (this.iterable instanceof CloseableIterable) {
        ((CloseableIterable) iterable).close();
    }
}
 
Example #11
Source File: IdVertexIndex.java    From org.openntf.domino with Apache License 2.0 4 votes vote down vote up
public CloseableIterable<Vertex> get(String key, Object value) {
    return new IdVertexIterable(baseIndex.get(key, value), this.idGraph);
}
 
Example #12
Source File: IdEdgeIterable.java    From org.openntf.domino with Apache License 2.0 4 votes vote down vote up
public void close() {
    if (iterable instanceof CloseableIterable) {
        ((CloseableIterable) iterable).close();
    }
}
 
Example #13
Source File: IdVertexIterable.java    From org.openntf.domino with Apache License 2.0 4 votes vote down vote up
public void close() {
    if (iterable instanceof CloseableIterable) {
        ((CloseableIterable) iterable).close();
    }
}
 
Example #14
Source File: IdEdgeIndex.java    From org.openntf.domino with Apache License 2.0 4 votes vote down vote up
public CloseableIterable<Edge> get(String key, Object value) {
    return new IdEdgeIterable(baseIndex.get(key, value), this.idGraph);
}
 
Example #15
Source File: ReadOnlyEdgeIterable.java    From org.openntf.domino with Apache License 2.0 4 votes vote down vote up
public void close() {
    if (this.iterable instanceof CloseableIterable) {
        ((CloseableIterable) this.iterable).close();
    }
}
 
Example #16
Source File: EventEdgeIterable.java    From org.openntf.domino with Apache License 2.0 4 votes vote down vote up
public void close() {
    if (this.iterable instanceof CloseableIterable) {
        ((CloseableIterable) this.iterable).close();
    }
}
 
Example #17
Source File: WrappedIndex.java    From org.openntf.domino with Apache License 2.0 4 votes vote down vote up
public CloseableIterable<T> get(final String key, final Object value) {
    if (Vertex.class.isAssignableFrom(this.getIndexClass()))
        return (CloseableIterable<T>) new WrappedVertexIterable((Iterable<Vertex>) this.rawIndex.get(key, value));
    else
        return (CloseableIterable<T>) new WrappedEdgeIterable((Iterable<Edge>) this.rawIndex.get(key, value));
}
 
Example #18
Source File: WrappedIndex.java    From org.openntf.domino with Apache License 2.0 4 votes vote down vote up
public CloseableIterable<T> query(final String key, final Object value) {
    if (Vertex.class.isAssignableFrom(this.getIndexClass()))
        return (CloseableIterable<T>) new WrappedVertexIterable((Iterable<Vertex>) this.rawIndex.query(key, value));
    else
        return (CloseableIterable<T>) new WrappedEdgeIterable((Iterable<Edge>) this.rawIndex.query(key, value));
}
 
Example #19
Source File: WrappedVertexIterable.java    From org.openntf.domino with Apache License 2.0 4 votes vote down vote up
public void close() {
    if (this.iterable instanceof CloseableIterable) {
        ((CloseableIterable) iterable).close();
    }
}
 
Example #20
Source File: WrappedEdgeIterable.java    From org.openntf.domino with Apache License 2.0 4 votes vote down vote up
public void close() {
    if (this.iterable instanceof CloseableIterable) {
        ((CloseableIterable) iterable).close();
    }
}
 
Example #21
Source File: PartitionEdgeIterable.java    From org.openntf.domino with Apache License 2.0 4 votes vote down vote up
public void close() {
    if (this.iterable instanceof CloseableIterable) {
        ((CloseableIterable) iterable).close();
    }
}
 
Example #22
Source File: PartitionIndex.java    From org.openntf.domino with Apache License 2.0 4 votes vote down vote up
public CloseableIterable<T> get(final String key, final Object value) {
    if (Vertex.class.isAssignableFrom(this.getIndexClass()))
        return (CloseableIterable<T>) new PartitionVertexIterable((Iterable<Vertex>) this.rawIndex.get(key, value), this.graph);
    else
        return (CloseableIterable<T>) new PartitionEdgeIterable((Iterable<Edge>) this.rawIndex.get(key, value), this.graph);
}
 
Example #23
Source File: ReadOnlyVertexIterable.java    From org.openntf.domino with Apache License 2.0 4 votes vote down vote up
public void close() {
    if (this.iterable instanceof CloseableIterable) {
        ((CloseableIterable) this.iterable).close();
    }
}
 
Example #24
Source File: PropertyFilteredIterable.java    From org.openntf.domino with Apache License 2.0 4 votes vote down vote up
public void close() {
    if (this.iterable instanceof CloseableIterable) {
        ((CloseableIterable) this.iterable).close();
    }
}
 
Example #25
Source File: WrappingCloseableIterable.java    From org.openntf.domino with Apache License 2.0 4 votes vote down vote up
public void close() {
    if (this.iterable instanceof CloseableIterable) {
        ((CloseableIterable) this.iterable).close();
    }
}
 
Example #26
Source File: ActiveVersionedEdgeIterable.java    From antiquity with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void close() {
    if (rawIterable instanceof CloseableIterable) {
        ((CloseableIterable) rawIterable).close();
    }
}
 
Example #27
Source File: HistoricVersionedEdgeIterable.java    From antiquity with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void close() {
    if (this.iterable instanceof CloseableIterable) {
        ((CloseableIterable<Edge>) this.iterable).close();
    }
}
 
Example #28
Source File: ActiveVersionedVertexIterable.java    From antiquity with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void close() {
    if (rawIterable instanceof CloseableIterable) {
        ((CloseableIterable) rawIterable).close();
    }
}
 
Example #29
Source File: HistoricVersionedVertexIterable.java    From antiquity with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void close() {
    if (iterable instanceof CloseableIterable) {
        ((CloseableIterable<Vertex>) iterable).close();
    }
}
 
Example #30
Source File: VertexTableWrapper.java    From AccumuloGraph with Apache License 2.0 4 votes vote down vote up
public CloseableIterable<Vertex> getVertices() {
  return getVerticesInRange(null, null);
}