Search in sources :

Example 51 with Vertex

use of com.tinkerpop.blueprints.Vertex in project frames by tinkerpop.

the class TypedGraphModuleTest method testWildcard.

public void testWildcard() {
    Graph graph = new TinkerGraph();
    FramedGraphFactory factory = new FramedGraphFactory(new TypedGraphModuleBuilder().withClass(A.class).withClass(B.class).withClass(C.class).build());
    FramedGraph<Graph> framedGraph = factory.create(graph);
    Vertex v1 = graph.addVertex(null);
    Vertex v2 = graph.addVertex(null);
    v2.setProperty("type", "A");
    Edge cE = graph.addEdge(null, v1, v2, "label");
    cE.setProperty("type", "C");
    Base c = framedGraph.getEdge(cE.getId(), Direction.OUT, Base.class);
    assertTrue(c instanceof C);
    assertTrue(((C) c).getInVertex() instanceof A);
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) Graph(com.tinkerpop.blueprints.Graph) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) TypedGraphModuleBuilder(com.tinkerpop.frames.modules.typedgraph.TypedGraphModuleBuilder) Edge(com.tinkerpop.blueprints.Edge)

Example 52 with Vertex

use of com.tinkerpop.blueprints.Vertex in project frames by tinkerpop.

the class FramedVertexSetTest method testFramedSet.

public void testFramedSet() {
    Graph graph = TinkerGraphFactory.createTinkerGraph();
    FramedGraph<Graph> framedGraph = new FramedGraph<Graph>(graph);
    Set<Vertex> vertices = new HashSet<Vertex>();
    vertices.add(graph.getVertex(1));
    vertices.add(graph.getVertex(4));
    vertices.add(graph.getVertex(6));
    FramedVertexSet<Person> set = new FramedVertexSet<Person>(framedGraph, vertices, Person.class);
    assertEquals(set.size(), 3);
    assertTrue(set.contains(graph.getVertex(1)));
    assertTrue(set.contains(graph.getVertex(4)));
    assertTrue(set.contains(graph.getVertex(6)));
    assertTrue(set.contains(framedGraph.frame(graph.getVertex(1), Person.class)));
    assertTrue(set.contains(framedGraph.frame(graph.getVertex(4), Person.class)));
    assertTrue(set.contains(framedGraph.frame(graph.getVertex(6), Person.class)));
    int counter = 0;
    for (Person person : set) {
        assertTrue(person.asVertex().getId().equals("1") || person.asVertex().getId().equals("4") || person.asVertex().getId().equals("6"));
        counter++;
    }
    assertEquals(counter, 3);
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) Graph(com.tinkerpop.blueprints.Graph) FramedGraph(com.tinkerpop.frames.FramedGraph) FramedGraph(com.tinkerpop.frames.FramedGraph) Person(com.tinkerpop.frames.domain.classes.Person) HashSet(java.util.HashSet)

Example 53 with Vertex

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

the class BatchGraphTest method loadingTest.

public void loadingTest(int total, int bufferSize, VertexIDType type, LoadingFactory ids) {
    final VertexEdgeCounter counter = new VertexEdgeCounter();
    MockTransactionalGraph tgraph = null;
    if (ignoreIDs) {
        tgraph = new MockTransactionalGraph(new IgnoreIdTinkerGraph());
    } else {
        tgraph = new MockTransactionalGraph(new TinkerGraph());
    }
    BLGraph graph = new BLGraph(tgraph, counter, ids);
    BatchGraph<BLGraph> loader = new BatchGraph<BLGraph>(graph, type, bufferSize);
    if (assignKeys) {
        loader.setVertexIdKey(vertexIDKey);
        loader.setEdgeIdKey(edgeIDKey);
    }
    //Create a chain
    int chainLength = total;
    Vertex previous = null;
    for (int i = 0; i <= chainLength; i++) {
        Vertex next = loader.addVertex(ids.getVertexID(i));
        next.setProperty(UID, i);
        counter.numVertices++;
        counter.totalVertices++;
        if (previous != null) {
            Edge e = loader.addEdge(ids.getEdgeID(i), loader.getVertex(previous.getId()), loader.getVertex(next.getId()), "next");
            e.setProperty(UID, i);
            counter.numEdges++;
        }
        previous = next;
    }
    loader.stopTransaction(TransactionalGraph.Conclusion.SUCCESS);
    assertTrue(tgraph.allSuccessful());
    loader.shutdown();
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) IgnoreIdTinkerGraph(com.tinkerpop.blueprints.impls.tg.IgnoreIdTinkerGraph) IgnoreIdTinkerGraph(com.tinkerpop.blueprints.impls.tg.IgnoreIdTinkerGraph) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) MockTransactionalGraph(com.tinkerpop.blueprints.impls.tg.MockTransactionalGraph) Edge(com.tinkerpop.blueprints.Edge)

Example 54 with Vertex

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

the class BatchGraphTest method testLoadingWithExisting2.

public void testLoadingWithExisting2() {
    int numEdges = 1000;
    String[][] quads = generateQuads(100, numEdges, new String[] { "knows", "friend" });
    TinkerGraph tg = new IgnoreIdTinkerGraph();
    BatchGraph bg = new BatchGraph(new WritethroughGraph(tg), VertexIDType.STRING, 100);
    try {
        bg.setLoadingFromScratch(false);
        fail();
    } catch (IllegalStateException e) {
    }
    bg.setVertexIdKey("uid");
    bg.setLoadingFromScratch(false);
    try {
        bg.setVertexIdKey(null);
        fail();
    } catch (IllegalStateException e) {
    }
    Graph graph = null;
    int counter = 0;
    for (String[] quad : quads) {
        if (counter < numEdges / 2)
            graph = tg;
        else
            graph = bg;
        Vertex[] vertices = new Vertex[2];
        for (int i = 0; i < 2; i++) {
            vertices[i] = graph.getVertex(quad[i]);
            if (vertices[i] == null)
                vertices[i] = graph.addVertex(quad[i]);
        }
        Edge edge = graph.addEdge(null, vertices[0], vertices[1], quad[2]);
        edge.setProperty("annotation", quad[3]);
        counter++;
    }
    assertEquals(numEdges, BaseTest.count(tg.getEdges()));
    bg.shutdown();
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) IgnoreIdTinkerGraph(com.tinkerpop.blueprints.impls.tg.IgnoreIdTinkerGraph) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) IgnoreIdTinkerGraph(com.tinkerpop.blueprints.impls.tg.IgnoreIdTinkerGraph) TransactionalGraph(com.tinkerpop.blueprints.TransactionalGraph) IgnoreIdTinkerGraph(com.tinkerpop.blueprints.impls.tg.IgnoreIdTinkerGraph) MockTransactionalGraph(com.tinkerpop.blueprints.impls.tg.MockTransactionalGraph) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) Graph(com.tinkerpop.blueprints.Graph) Edge(com.tinkerpop.blueprints.Edge)

Example 55 with Vertex

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

the class BatchGraphTest method testQuadLoading.

public void testQuadLoading() {
    int numEdges = 10000;
    String[][] quads = generateQuads(100, numEdges, new String[] { "knows", "friend" });
    TinkerGraph graph = new TinkerGraph();
    BatchGraph bgraph = new BatchGraph(new WritethroughGraph(graph), VertexIDType.STRING, 1000);
    for (String[] quad : quads) {
        Vertex[] vertices = new Vertex[2];
        for (int i = 0; i < 2; i++) {
            vertices[i] = bgraph.getVertex(quad[i]);
            if (vertices[i] == null)
                vertices[i] = bgraph.addVertex(quad[i]);
        }
        Edge edge = bgraph.addEdge(null, vertices[0], vertices[1], quad[2]);
        edge.setProperty("annotation", quad[3]);
    }
    assertEquals(numEdges, BaseTest.count(graph.getEdges()));
    bgraph.shutdown();
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) IgnoreIdTinkerGraph(com.tinkerpop.blueprints.impls.tg.IgnoreIdTinkerGraph) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) Edge(com.tinkerpop.blueprints.Edge)

Aggregations

Vertex (com.tinkerpop.blueprints.Vertex)406 Test (org.junit.Test)119 Edge (com.tinkerpop.blueprints.Edge)111 Graph (com.tinkerpop.blueprints.Graph)85 TinkerGraph (com.tinkerpop.blueprints.impls.tg.TinkerGraph)84 JSONObject (org.codehaus.jettison.json.JSONObject)51 HashSet (java.util.HashSet)49 ArrayList (java.util.ArrayList)40 OrientVertex (com.tinkerpop.blueprints.impls.orient.OrientVertex)37 GremlinPipeline (com.tinkerpop.gremlin.java.GremlinPipeline)28 HashMap (java.util.HashMap)25 OrientGraph (com.tinkerpop.blueprints.impls.orient.OrientGraph)22 JSONArray (org.codehaus.jettison.json.JSONArray)20 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)19 Test (org.testng.annotations.Test)16 KeyIndexableGraph (com.tinkerpop.blueprints.KeyIndexableGraph)15 Map (java.util.Map)15 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)14 OrientBaseGraph (com.tinkerpop.blueprints.impls.orient.OrientBaseGraph)13 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)11