Package com.tinkerpop.blueprints

Examples of com.tinkerpop.blueprints.IndexableGraph


  @Override
  public void visit(final VertexPropertyTest vertexPropertyTest) {
    // TODO improve that code !!!
    Graph g = service.getDatabase();
    if (g instanceof IndexableGraph) {
      final IndexableGraph indexable = (IndexableGraph) g;
      final Index<Vertex> vertices = indexable
              .getIndex(IndexNames.VERTICES.getIndexName(), Vertex.class);
      result.put(new Iterable<Vertex>() {
       
        @Override
        public Iterator<Vertex> iterator() {
View Full Code Here


   */
  public static <Type extends Element> void setIndexedProperty(Graph database, Type entity, String propertyName, Object newValue) {
    Object oldValue = entity.getProperty(propertyName);
    entity.setProperty(propertyName, newValue);
    if(database instanceof IndexableGraph) {
      IndexableGraph indexable = (IndexableGraph) database;
      IndexNames indexName = IndexNames.forElement(entity);
      Index<Type> index = (Index<Type>) indexable.getIndex(indexName.getIndexName(), indexName.getIndexed());
      if(oldValue!=null) {
        index.remove(propertyName, oldValue, entity);
      }
      if(newValue!=null) {
        index.put(propertyName, newValue, entity);
View Full Code Here

   * @param database graph on which remove operation will be performed (must be indexable)
   * @param existing element to remove index entries
   */
  public static <Type extends Element> void removeFromIndex(Graph database, Type existing) {
    if (database instanceof IndexableGraph) {
      IndexableGraph indexable = (IndexableGraph) database;
      IndexNames indexName = IndexNames.forElement(existing);
      if(indexName.isUsable()) {
        Index<Type> index = (Index<Type>) indexable.getIndex(indexName.getIndexName(), indexName.getIndexed());
        for(String propertyName : existing.getPropertyKeys()) {
          index.remove(propertyName, existing.getProperty(propertyName), existing);
        }
      }
    }
View Full Code Here

        batch.flushIndices();
        batch.shutdown();

        // native neo4j graph load

        IndexableGraph graph = new Neo4jGraph(directory);
        Iterator<Vertex> itty = graph.getIndex("testIdx", Vertex.class).query("name", "*rko").iterator();
        int counter = 0;
        while (itty.hasNext()) {
            counter++;
            assertEquals(itty.next().getProperty("name"), "marko");
        }
        assertEquals(counter, 1);

        itty = graph.getIndex("testIdx", Vertex.class).query("name", "MaRkO").iterator();
        counter = 0;
        while (itty.hasNext()) {
            counter++;
            assertEquals(itty.next().getProperty("name"), "marko");
        }
        assertEquals(counter, 1);

        graph.shutdown();
    }
View Full Code Here

        }
    }

    protected void resetGraph() {
        final KeyIndexableGraph graph = (KeyIndexableGraph) this.generateGraph();
        final IndexableGraph idxGraph = (IndexableGraph) graph;

        // since we don't have graph.clear() anymore we manually reset the graph.
        Iterator<Vertex> vertexItty = graph.getVertices().iterator();
        List<Vertex> verticesToRemove = new ArrayList<Vertex>();
        while (vertexItty.hasNext()) {
            verticesToRemove.add(vertexItty.next());
        }

        for (Vertex vertexToRemove : verticesToRemove) {
            graph.removeVertex(vertexToRemove);
        }

        for (String key : graph.getIndexedKeys(Vertex.class)) {
            graph.dropKeyIndex(key, Vertex.class);
        }

        for (String key : graph.getIndexedKeys(Edge.class)) {
            graph.dropKeyIndex(key, Edge.class);
        }

        for (Index idx : idxGraph.getIndices()) {
            idxGraph.dropIndex(idx.getIndexName());
        }
    }
View Full Code Here

* @author Marko A. Rodriguez (http://markorodriguez.com)
*/
public class IndexableGraphHelperTest extends BaseTest {

    public void testAddUniqueVertex() {
        IndexableGraph graph = new TinkerGraph();
        Vertex marko = graph.addVertex(0);
        marko.setProperty("name", "marko");
        Index<Vertex> index = graph.createIndex("txIdx", Vertex.class);
        index.put("name", "marko", marko);
        Vertex vertex = IndexableGraphHelper.addUniqueVertex(graph, null, index, "name", "marko");
        assertEquals(vertex.getProperty("name"), "marko");
        assertEquals(vertex, graph.getVertex(0));
        assertEquals(count(graph.getVertices()), 1);
        assertEquals(count(graph.getEdges()), 0);

        vertex = IndexableGraphHelper.addUniqueVertex(graph, null, index, "name", "darrick");
        assertEquals(vertex.getProperty("name"), "darrick");
        assertEquals(count(graph.getVertices()), 2);
        assertEquals(vertex.getId(), "1");
    }
View Full Code Here

            assertTrue(edge.getVertex(Direction.IN) instanceof ReadOnlyVertex);
        }
    }

    public void testReadOnlyIndices() {
        IndexableGraph graph = new ReadOnlyIndexableGraph<TinkerGraph>(TinkerGraphFactory.createTinkerGraph());
        Index<Vertex> index = ((WrapperGraph<IndexableGraph>) graph).getBaseGraph().createIndex("blah", Vertex.class);
        index.put("name", "marko", graph.getVertex(1));
        assertTrue(graph.getIndices() instanceof ReadOnlyIndexIterable);
        index = graph.getIndex("blah", Vertex.class);
        assertTrue(index instanceof ReadOnlyIndex);
        assertTrue(index.get("name", "marko") instanceof ReadOnlyVertexIterable);
        try {
            index.put("name", "noname", graph.getVertex(1));
            assertTrue(false);
        } catch (UnsupportedOperationException e) {
            assertTrue(true);
        }
        try {
            index.remove("name", "marko", graph.getVertex(1));
            assertTrue(false);
        } catch (UnsupportedOperationException e) {
            assertTrue(true);
        }
        assertTrue(Vertex.class.isAssignableFrom(index.getIndexClass()));
View Full Code Here

   */
  public static <Type extends Element> void setIndexedProperty(Graph database, Type entity, String propertyName, Object newValue) {
    Object oldValue = entity.getProperty(propertyName);
    entity.setProperty(propertyName, newValue);
    if(database instanceof IndexableGraph) {
      IndexableGraph indexable = (IndexableGraph) database;
      IndexNames indexName = IndexNames.forElement(entity);
      Index<Type> index = (Index<Type>) indexable.getIndex(indexName.getIndexName(), indexName.getIndexed());
      if(oldValue!=null) {
        index.remove(propertyName, oldValue, entity);
      }
      if(newValue!=null) {
        index.put(propertyName, newValue, entity);
View Full Code Here

   * @param database graph on which remove operation will be performed (must be indexable)
   * @param existing element to remove index entries
   */
  public static <Type extends Element> void removeFromIndex(Graph database, Type existing) {
    if (database instanceof IndexableGraph) {
      IndexableGraph indexable = (IndexableGraph) database;
      IndexNames indexName = IndexNames.forElement(existing);
      if(indexName.isUsable()) {
        Index<Type> index = (Index<Type>) indexable.getIndex(indexName.getIndexName(), indexName.getIndexed());
        for(String propertyName : existing.getPropertyKeys()) {
          index.remove(propertyName, existing.getProperty(propertyName), existing);
        }
      }
    }
View Full Code Here

        final RexsterApplicationGraph rag = this.getRexsterApplicationGraph(graphName);
        final Graph graph = rag.getGraph();

        final JSONObject theRequestObject = this.getRequestObject();

        final IndexableGraph idxGraph = graph instanceof IndexableGraph ? (IndexableGraph) graph : null;

        if (idxGraph == null) {
            final JSONObject error = this.generateErrorObject("The requested graph is not of type " + IndexableGraph.class.getName() + ".");
            throw new WebApplicationException(Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(error).build());
        }

        final Long start = RequestObjectHelper.getStartOffset(theRequestObject);
        final Long end = RequestObjectHelper.getEndOffset(theRequestObject);

        long counter = 0l;

        try {
            final JSONArray indexArray = new JSONArray();
            for (Index index : idxGraph.getIndices()) {
                if (counter >= start && counter < end) {
                    indexArray.put(createJSONObject(index));
                }
                counter++;
            }
View Full Code Here

TOP

Related Classes of com.tinkerpop.blueprints.IndexableGraph

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.