Search in sources :

Example 1 with KeyIndexableGraph

use of com.tinkerpop.blueprints.KeyIndexableGraph in project pentaho-metaverse by pentaho.

the class SynchronizedGraphFactory method wrapGraph.

/**
 * Wraps the underlying graph with a synchronized one
 * @param graph The graph to wrap
 * @return The synchronized graph
 */
protected static Graph wrapGraph(Graph graph) {
    if (graph instanceof KeyIndexableGraph) {
        KeyIndexableGraph keyIndexableGraph = (KeyIndexableGraph) graph;
        IdGraph<KeyIndexableGraph> idGraph = new IdGraph<KeyIndexableGraph>(keyIndexableGraph);
        return new SynchronizedGraph(idGraph);
    } else {
        throw new IllegalArgumentException(Messages.getString("ERROR.BackingGraph.MustImplement.KeyIndexableGraph"));
    }
}
Also used : KeyIndexableGraph(com.tinkerpop.blueprints.KeyIndexableGraph) IdGraph(com.tinkerpop.blueprints.util.wrappers.id.IdGraph)

Example 2 with KeyIndexableGraph

use of com.tinkerpop.blueprints.KeyIndexableGraph in project pentaho-metaverse by pentaho.

the class SynchronizedGraphFactoryTest method testWrapGraph.

@Test
public void testWrapGraph() throws Exception {
    Graph g = new TinkerGraph();
    SynchronizedGraph wrapped = (SynchronizedGraph) SynchronizedGraphFactory.wrapGraph(g);
    assertTrue(wrapped instanceof SynchronizedGraph);
    assertTrue(wrapped.graph instanceof IdGraph);
    assertTrue(wrapped.graph instanceof KeyIndexableGraph);
}
Also used : TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) Graph(com.tinkerpop.blueprints.Graph) KeyIndexableGraph(com.tinkerpop.blueprints.KeyIndexableGraph) IdGraph(com.tinkerpop.blueprints.util.wrappers.id.IdGraph) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) KeyIndexableGraph(com.tinkerpop.blueprints.KeyIndexableGraph) IdGraph(com.tinkerpop.blueprints.util.wrappers.id.IdGraph) Test(org.junit.Test)

Example 3 with KeyIndexableGraph

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

the class SparkseeKeyIndexableGraphTestSuite method testCreateKeyIndexCannotAcceptNullArgumentForClass.

public void testCreateKeyIndexCannotAcceptNullArgumentForClass() {
    KeyIndexableGraph graph = (KeyIndexableGraph) graphTest.generateGraph();
    try {
        graph.createKeyIndex("test", null);
    } catch (IllegalArgumentException iae) {
        return;
    } finally {
        graph.shutdown();
    }
    fail();
}
Also used : KeyIndexableGraph(com.tinkerpop.blueprints.KeyIndexableGraph)

Example 4 with KeyIndexableGraph

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

the class SparkseeKeyIndexableGraphTestSuite method testUpdateValuesInIndexKeys.

public void testUpdateValuesInIndexKeys() throws Exception {
    KeyIndexableGraph graph = (KeyIndexableGraph) graphTest.generateGraph();
    graph.createKeyIndex("name", Vertex.class);
    if (graph instanceof TransactionalGraph)
        ((TransactionalGraph) graph).commit();
    Vertex v1 = graph.addVertex(null);
    v1.setProperty("name", "marko");
    assertEquals(v1.getProperty("name"), "marko");
    vertexCount(graph, 1);
    if (graph instanceof TransactionalGraph)
        ((TransactionalGraph) graph).commit();
    v1 = graph.getVertices("name", "marko").iterator().next();
    assertEquals(v1.getProperty("name"), "marko");
    v1.setProperty("name", "marko a. rodriguez");
    assertEquals(v1.getProperty("name"), "marko a. rodriguez");
    vertexCount(graph, 1);
    if (graph instanceof TransactionalGraph)
        ((TransactionalGraph) graph).commit();
    assertFalse(graph.getVertices("name", "marko").iterator().hasNext());
    v1 = graph.getVertices("name", "marko a. rodriguez").iterator().next();
    assertEquals(v1.getProperty("name"), "marko a. rodriguez");
    vertexCount(graph, 1);
    if (graph instanceof TransactionalGraph)
        ((TransactionalGraph) graph).commit();
    graph.shutdown();
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) KeyIndexableGraph(com.tinkerpop.blueprints.KeyIndexableGraph) TransactionalGraph(com.tinkerpop.blueprints.TransactionalGraph)

Example 5 with KeyIndexableGraph

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

the class SparkseeKeyIndexableGraphTestSuite method testAutoIndexKeyManagementWithPersistence.

public void testAutoIndexKeyManagementWithPersistence() {
    KeyIndexableGraph graph = (KeyIndexableGraph) graphTest.generateGraph();
    if (graph.getFeatures().supportsVertexKeyIndex) {
        assertEquals(graph.getIndexedKeys(Vertex.class).size(), 0);
        this.stopWatch();
        graph.createKeyIndex("name", Vertex.class);
        graph.createKeyIndex("location", Vertex.class);
        printPerformance(graph.toString(), 2, "automatic index keys added", this.stopWatch());
        assertEquals(graph.getIndexedKeys(Vertex.class).size(), 2);
        assertTrue(graph.getIndexedKeys(Vertex.class).contains("name"));
        assertTrue(graph.getIndexedKeys(Vertex.class).contains("location"));
    }
    if (graph.getFeatures().supportsEdgeKeyIndex) {
        assertEquals(graph.getIndexedKeys(Edge.class).size(), 0);
        this.stopWatch();
        graph.createKeyIndex("weight", Edge.class);
        graph.createKeyIndex("since", Edge.class);
        printPerformance(graph.toString(), 2, "automatic index keys added", this.stopWatch());
        assertEquals(graph.getIndexedKeys(Edge.class).size(), 2);
        assertTrue(graph.getIndexedKeys(Edge.class).contains("weight"));
        assertTrue(graph.getIndexedKeys(Edge.class).contains("since"));
    }
    graph.shutdown();
    if (graph.getFeatures().isPersistent) {
        graph = (KeyIndexableGraph) graphTest.generateGraph();
        if (graph.getFeatures().supportsVertexKeyIndex) {
            assertEquals(graph.getIndexedKeys(Vertex.class).size(), 2);
            assertTrue(graph.getIndexedKeys(Vertex.class).contains("name"));
            assertTrue(graph.getIndexedKeys(Vertex.class).contains("location"));
        }
        if (graph.getFeatures().supportsEdgeKeyIndex) {
            assertEquals(graph.getIndexedKeys(Edge.class).size(), 2);
            assertTrue(graph.getIndexedKeys(Edge.class).contains("weight"));
            assertTrue(graph.getIndexedKeys(Edge.class).contains("since"));
        }
        graph.shutdown();
    }
}
Also used : KeyIndexableGraph(com.tinkerpop.blueprints.KeyIndexableGraph)

Aggregations

KeyIndexableGraph (com.tinkerpop.blueprints.KeyIndexableGraph)17 Vertex (com.tinkerpop.blueprints.Vertex)6 Edge (com.tinkerpop.blueprints.Edge)3 TinkerGraph (com.tinkerpop.blueprints.impls.tg.TinkerGraph)3 Test (org.junit.Test)3 IndexableGraph (com.tinkerpop.blueprints.IndexableGraph)2 IdGraph (com.tinkerpop.blueprints.util.wrappers.id.IdGraph)2 ArrayList (java.util.ArrayList)2 Graph (com.tinkerpop.blueprints.Graph)1 Index (com.tinkerpop.blueprints.Index)1 TransactionalGraph (com.tinkerpop.blueprints.TransactionalGraph)1 WrapperGraph (com.tinkerpop.blueprints.util.wrappers.WrapperGraph)1 File (java.io.File)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 Sail (org.openrdf.sail.Sail)1 SailConnection (org.openrdf.sail.SailConnection)1