Search in sources :

Example 1 with IndexableGraph

use of com.tinkerpop.blueprints.IndexableGraph in project blueprints by tinkerpop.

the class IndexableGraphHelperTest method testAddUniqueVertex.

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");
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) IndexableGraph(com.tinkerpop.blueprints.IndexableGraph) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph)

Example 2 with IndexableGraph

use of com.tinkerpop.blueprints.IndexableGraph in project blueprints by tinkerpop.

the class ReadOnlyGraphTest method testReadOnlyKeyIndices.

public void testReadOnlyKeyIndices() {
    KeyIndexableGraph graph = new ReadOnlyKeyIndexableGraph<TinkerGraph>(TinkerGraphFactory.createTinkerGraph());
    ((KeyIndexableGraph) ((WrapperGraph<IndexableGraph>) graph).getBaseGraph()).createKeyIndex("blah", Vertex.class);
    assertTrue(graph.getIndexedKeys(Vertex.class) instanceof Set);
    assertEquals(graph.getIndexedKeys(Vertex.class).size(), 1);
    assertTrue(graph.getIndexedKeys(Vertex.class).contains("blah"));
    try {
        graph.createKeyIndex("whatever", Vertex.class);
        assertTrue(false);
    } catch (UnsupportedOperationException e) {
        assertTrue(true);
    }
    try {
        graph.dropKeyIndex("blah", Vertex.class);
        assertTrue(false);
    } catch (UnsupportedOperationException e) {
        assertTrue(true);
    }
}
Also used : KeyIndexableGraph(com.tinkerpop.blueprints.KeyIndexableGraph) IndexableGraph(com.tinkerpop.blueprints.IndexableGraph) Set(java.util.Set) HashSet(java.util.HashSet) KeyIndexableGraph(com.tinkerpop.blueprints.KeyIndexableGraph)

Example 3 with IndexableGraph

use of com.tinkerpop.blueprints.IndexableGraph in project blueprints by tinkerpop.

the class Neo4jBatchGraphTest method testIndexParameters.

public void testIndexParameters() throws Exception {
    final String directory = this.getWorkingDirectory();
    final Neo4jBatchGraph batch = new Neo4jBatchGraph(directory);
    Index<Vertex> index = batch.createIndex("testIdx", Vertex.class, new Parameter("analyzer", LowerCaseKeywordAnalyzer.class.getName()));
    Vertex a = batch.addVertex(null);
    a.setProperty("name", "marko");
    index.put("name", "marko", a);
    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();
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) IndexableGraph(com.tinkerpop.blueprints.IndexableGraph) Neo4jGraph(com.tinkerpop.blueprints.impls.neo4j.Neo4jGraph) Parameter(com.tinkerpop.blueprints.Parameter)

Example 4 with IndexableGraph

use of com.tinkerpop.blueprints.IndexableGraph in project blueprints by tinkerpop.

the class ReadOnlyGraphTest method testReadOnlyIndices.

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()));
    assertEquals(index.getIndexName(), "blah");
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) KeyIndexableGraph(com.tinkerpop.blueprints.KeyIndexableGraph) IndexableGraph(com.tinkerpop.blueprints.IndexableGraph)

Example 5 with IndexableGraph

use of com.tinkerpop.blueprints.IndexableGraph in project blueprints by tinkerpop.

the class RexsterGraphTest method resetGraph.

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());
    }
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) KeyIndexableGraph(com.tinkerpop.blueprints.KeyIndexableGraph) IndexableGraph(com.tinkerpop.blueprints.IndexableGraph) KeyIndexableGraph(com.tinkerpop.blueprints.KeyIndexableGraph) ArrayList(java.util.ArrayList) Index(com.tinkerpop.blueprints.Index)

Aggregations

IndexableGraph (com.tinkerpop.blueprints.IndexableGraph)5 Vertex (com.tinkerpop.blueprints.Vertex)4 KeyIndexableGraph (com.tinkerpop.blueprints.KeyIndexableGraph)3 Index (com.tinkerpop.blueprints.Index)1 Parameter (com.tinkerpop.blueprints.Parameter)1 Neo4jGraph (com.tinkerpop.blueprints.impls.neo4j.Neo4jGraph)1 TinkerGraph (com.tinkerpop.blueprints.impls.tg.TinkerGraph)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1