Search in sources :

Example 26 with Vertex

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

the class OOrientDBLoaderTest method shouldSaveDocumentsOnGivenCluster.

@Test
public void shouldSaveDocumentsOnGivenCluster() {
    process("{source: { content: { value: 'name,surname\nJay,Miner' } }, extractor : { csv: {} }, loader: { orientdb: {\n" + "      dbURL: \"memory:OETLBaseTest\",\n" + "      dbUser: \"admin\",\n" + "      dbPassword: \"admin\",\n" + "      dbAutoCreate: true,\n" + "      cluster : \"myCluster\",\n" + "      tx: false,\n" + "      batchCommit: 1000,\n" + "      wal : true,\n" + "      dbType: \"graph\",\n" + "      classes: [\n" + "        {name:\"Person\", extends: \"V\" },\n" + "      ],\n" + "      indexes: [{class:\"V\" , fields:[\"surname:String\"], \"type\":\"NOTUNIQUE\", \"metadata\": { \"ignoreNullValues\" : \"false\"}} ]  } } }");
    graph.makeActive();
    int idByName = graph.getRawGraph().getClusterIdByName("myCluster");
    Iterable<Vertex> vertices = graph.getVertices();
    for (Vertex vertex : vertices) {
        assertThat(((ORID) vertex.getId()).getClusterId()).isEqualTo(idByName);
    }
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) ORID(com.orientechnologies.orient.core.id.ORID) Test(org.junit.Test) OETLBaseTest(com.orientechnologies.orient.etl.OETLBaseTest)

Example 27 with Vertex

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

the class OGraphBatchInsertTest method testTraverse.

@Test
public void testTraverse() {
    String dbUrl = "memory:batchinsert_testTraverse";
    OGraphBatchInsert batch = new OGraphBatchInsert(dbUrl, "admin", "admin");
    batch.begin();
    batch.createEdge(0L, 1L, null);
    batch.createEdge(1L, 2L, null);
    batch.createEdge(2L, 3L, null);
    Map<String, Object> vertexProps = new HashMap<String, Object>();
    vertexProps.put("foo", "bar");
    batch.setVertexProperties(3L, vertexProps);
    batch.end();
    OrientGraph g = new OrientGraph(dbUrl, "admin", "admin");
    Iterable<Vertex> result = g.command(new OSQLSynchQuery<Vertex>("select expand(out().in().out().out().in().out()) from V where uid = ?")).execute(1L);
    for (Vertex v : result) {
        assertEquals("bar", v.getProperty("foo"));
    }
    g.shutdown();
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) HashMap(java.util.HashMap) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) Test(org.junit.Test)

Example 28 with Vertex

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

the class OConsoleDatabaseAppTest method testSimple.

@Test
public void testSimple() {
    String dbUrl = "memory:OConsoleDatabaseAppTest";
    StringBuilder builder = new StringBuilder();
    builder.append("create database " + dbUrl + ";\n");
    builder.append("profile storage on;\n");
    builder.append("create class foo;\n");
    builder.append("config;\n");
    builder.append("list classes;\n");
    builder.append("list properties;\n");
    builder.append("list clusters;\n");
    builder.append("list indexes;\n");
    builder.append("info class OUser;\n");
    builder.append("info property OUser.name;\n");
    builder.append("begin;\n");
    builder.append("insert into foo set name = 'foo';\n");
    builder.append("insert into foo set name = 'bla';\n");
    builder.append("update foo set surname = 'bar' where name = 'foo';\n");
    builder.append("commit;\n");
    builder.append("select from foo;\n");
    builder.append("create class bar;\n");
    builder.append("create property bar.name STRING;\n");
    builder.append("create index bar_name on bar (name) NOTUNIQUE;\n");
    builder.append("insert into bar set name = 'foo';\n");
    builder.append("delete from bar;\n");
    builder.append("begin;\n");
    builder.append("insert into bar set name = 'foo';\n");
    builder.append("rollback;\n");
    builder.append("create vertex V set name = 'foo';\n");
    builder.append("create vertex V set name = 'bar';\n");
    builder.append("traverse out() from V;\n");
    builder.append("create edge from (select from V where name = 'foo') to (select from V where name = 'bar');\n");
    builder.append("traverse out() from V;\n");
    //    builder.append("create user TestUser identified by password ROLE ['reader','writer'];\n");
    builder.append("drop user TestUser;\n");
    builder.append("profile storage off;\n");
    builder.append("repair database -v;\n");
    ConsoleTest c = new ConsoleTest(new String[] { builder.toString() });
    OConsoleDatabaseApp console = c.console();
    try {
        console.run();
        ODatabaseDocumentTx db = new ODatabaseDocumentTx(dbUrl);
        db.open("admin", "admin");
        try {
            List<ODocument> result = db.query(new OSQLSynchQuery<ODocument>("select from foo where name = 'foo'"));
            Assert.assertEquals(1, result.size());
            ODocument doc = result.get(0);
            Assert.assertEquals("bar", doc.field("surname"));
            result = db.query(new OSQLSynchQuery<ODocument>("select from bar"));
            Assert.assertEquals(0, result.size());
        } finally {
            db.close();
        }
        OrientGraph graph = new OrientGraph(dbUrl);
        try {
            Iterable<Vertex> result = graph.command(new OSQLSynchQuery<Vertex>("select expand(out()) from (select from V where name = 'foo')")).execute();
            Iterator<Vertex> iterator = result.iterator();
            Assert.assertTrue(iterator.hasNext());
            Vertex next = iterator.next();
            Assert.assertEquals("bar", next.getProperty("name"));
            Assert.assertFalse(iterator.hasNext());
        } finally {
            graph.shutdown();
        }
    } finally {
        console.close();
    }
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OConsoleDatabaseApp(com.orientechnologies.orient.console.OConsoleDatabaseApp) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.junit.Test)

Example 29 with Vertex

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

the class GraphCommands method testParams.

@Test
public void testParams() {
    String sql = "SELECT FROM V WHERE tags IN :tags";
    Map<String, Object> queryParams = new HashMap<String, Object>();
    queryParams.put("tags", new HashSet<String>() {

        {
            add("Genius");
        }
    });
    Iterable<Vertex> results = ((Iterable<Vertex>) graph.command(new OSQLSynchQuery(sql)).execute(queryParams));
    Assert.assertTrue(results.iterator().hasNext());
    sql = "SELECT FROM V WHERE tags NOT IN :tags";
    queryParams = new HashMap<String, Object>();
    queryParams.put("tags", new HashSet<String>() {

        {
            add("Genius");
        }
    });
    results = ((Iterable<Vertex>) graph.command(new OSQLSynchQuery(sql)).execute(queryParams));
    Assert.assertFalse(results.iterator().hasNext());
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) HashMap(java.util.HashMap) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) GraphNoTxAbstractTest(com.orientechnologies.orient.graph.GraphNoTxAbstractTest) Test(org.junit.Test)

Example 30 with Vertex

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

the class GraphCommands method testAddValueSQL.

@Test
public void testAddValueSQL() {
    graph.command(new OCommandSQL("update V add testprop = 'first' return after @this limit 1")).execute();
    Iterable<Vertex> results = ((Iterable<Vertex>) graph.command(new OSQLSynchQuery("select from V where 'first' in testprop")).execute());
    Assert.assertTrue(results.iterator().hasNext());
    graph.command(new OCommandSQL("update V add testprop = 'second' return after @this limit 1")).execute();
    results = ((Iterable<Vertex>) graph.command(new OSQLSynchQuery("select from V where 'first' in testprop")).execute());
    Assert.assertTrue(results.iterator().hasNext());
    results = ((Iterable<Vertex>) graph.command(new OSQLSynchQuery("select from V where 'second' in testprop")).execute());
    Assert.assertTrue(results.iterator().hasNext());
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) Vertex(com.tinkerpop.blueprints.Vertex) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) GraphNoTxAbstractTest(com.orientechnologies.orient.graph.GraphNoTxAbstractTest) Test(org.junit.Test)

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