Search in sources :

Example 21 with OrientVertexType

use of com.tinkerpop.blueprints.impls.orient.OrientVertexType in project orientdb by orientechnologies.

the class OGraphInsertWorkload method init.

@Override
protected void init(OBaseWorkLoadContext context) {
    synchronized (getClass()) {
        final OrientBaseGraph g = ((OWorkLoadContext) context).graph;
        if (g.getVertexType(className) == null) {
            final OrientVertexType c = g.createVertexType(className);
            c.createProperty("_id", OType.LONG);
            c.createProperty("ts", OType.DATETIME);
        }
    }
}
Also used : OrientVertexType(com.tinkerpop.blueprints.impls.orient.OrientVertexType) OrientBaseGraph(com.tinkerpop.blueprints.impls.orient.OrientBaseGraph)

Example 22 with OrientVertexType

use of com.tinkerpop.blueprints.impls.orient.OrientVertexType in project orientdb by orientechnologies.

the class TestGraphIntentMassiveInsert method testIntent.

@Test
public void testIntent() {
    final OrientGraph graph = new OrientGraph("memory:default", false);
    graph.setUseLightweightEdges(true);
    graph.getRawGraph().declareIntent(new OIntentMassiveInsert());
    final OrientVertexType c1 = graph.createVertexType("C1");
    c1.createProperty("p1", OType.INTEGER);
    graph.createEdgeType("parent");
    graph.begin();
    final OrientVertex first = graph.addVertex("class:C1");
    first.setProperty("p1", -1);
    for (int i = 0; i < 10; i++) {
        final OrientVertex v = graph.addVertex("class:C1");
        v.setProperty("p1", i);
        first.addEdge("parent", v);
        //this search fills _source
        graph.command(new OSQLSynchQuery("SELECT from V where p1='" + i + "'")).execute();
    }
    graph.commit();
    //here NPE will be thrown
    final Iterable<Edge> edges = first.getEdges(Direction.BOTH);
    Iterator<Edge> ter = edges.iterator();
    for (int i = 0; i < 10; i++) {
        assertTrue(ter.hasNext());
        assertEquals(ter.next().getVertex(Direction.IN).getProperty("p1"), i);
    }
}
Also used : OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) OrientVertexType(com.tinkerpop.blueprints.impls.orient.OrientVertexType) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) Edge(com.tinkerpop.blueprints.Edge) OIntentMassiveInsert(com.orientechnologies.orient.core.intent.OIntentMassiveInsert) Test(org.junit.Test)

Example 23 with OrientVertexType

use of com.tinkerpop.blueprints.impls.orient.OrientVertexType in project orientdb by orientechnologies.

the class GraphGetVertices method test.

@Test
public void test() {
    Iterator<Vertex> iterator = null;
    OrientGraphNoTx graph = new OrientGraphNoTx("memory:/TestDB", "admin", "admin");
    OrientVertexType personType = graph.createVertexType("Person");
    personType.createProperty("person_id", OType.STRING);
    personType.createProperty("name", OType.STRING);
    // Adding 3 vertices to the orient graph
    OrientVertex p1 = graph.addVertex("class:Person");
    p1.setProperty("person_id", "01");
    p1.setProperty("name", "Gabriel");
    OrientVertex p2 = graph.addVertex("class:Person");
    p2.setProperty("person_id", "02");
    p2.setProperty("name", "Daniel");
    OrientVertex p3 = graph.addVertex("class:Person");
    p3.setProperty("person_id", "03");
    p3.setProperty("name", "Emanuel");
    /*
     * CASE 1 GetVertices call without indexes, query on one key and one value
     */
    // String key and value
    String[] singleKey = { "person_id" };
    String[] singleValue = { "01" };
    iterator = graph.getVertices("Person", singleKey, singleValue).iterator();
    int resultsAmount = 0;
    while (iterator.hasNext()) {
        iterator.next();
        resultsAmount++;
    }
    assertEquals(1, resultsAmount);
    iterator = graph.getVertices("Person", singleKey, singleValue).iterator();
    Vertex firstVertex = iterator.next();
    assertEquals(firstVertex.getProperty("person_id"), "01");
    assertEquals(firstVertex.getProperty("name"), "Gabriel");
    /*
     * CASE 2 GetVertices call with index built on a single property, query on one key and one value
     */
    // Defining an index (unique_hash_index) on a single property
    String statement = "create index Person.pkey on Person (person_id) unique_hash_index";
    OCommandSQL sqlCommand = new OCommandSQL(statement);
    graph.getRawGraph().command(sqlCommand).execute();
    // String key and value
    singleValue[0] = "02";
    iterator = graph.getVertices("Person", singleKey, singleValue).iterator();
    resultsAmount = 0;
    while (iterator.hasNext()) {
        iterator.next();
        resultsAmount++;
    }
    assertEquals(1, resultsAmount);
    iterator = graph.getVertices("Person", singleKey, singleValue).iterator();
    firstVertex = iterator.next();
    assertEquals(firstVertex.getProperty("person_id"), "02");
    assertEquals(firstVertex.getProperty("name"), "Daniel");
    /*
     * CASE 3 GetVertices call with index built on two properties (composite key), query on two key and two values in order to test
     * "composite key behaviour"
     */
    // Dropping precedent index and defining a new index (unique_hash_index) on two properties
    graph.dropIndex("Person.pkey");
    statement = "create index Person.pkey on Person (person_id,name) unique_hash_index";
    sqlCommand = new OCommandSQL(statement);
    graph.getRawGraph().command(sqlCommand).execute();
    // String key and value
    String[] keys = { "person_id", "name" };
    String[] values = { "03", "Emanuel" };
    iterator = graph.getVertices("Person", keys, values).iterator();
    resultsAmount = 0;
    while (iterator.hasNext()) {
        iterator.next();
        resultsAmount++;
    }
    assertEquals(1, resultsAmount);
    iterator = graph.getVertices("Person", keys, values).iterator();
    firstVertex = iterator.next();
    assertEquals(firstVertex.getProperty("person_id"), "03");
    assertEquals(firstVertex.getProperty("name"), "Emanuel");
    graph.createVertexType("PersonDummy");
    Iterator<Vertex> personDummy = graph.getVertices("PersonDummy", singleKey, singleValue).iterator();
    resultsAmount = 0;
    while (personDummy.hasNext()) {
        personDummy.next();
        resultsAmount++;
    }
    assertEquals(0, resultsAmount);
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) Vertex(com.tinkerpop.blueprints.Vertex) OrientGraphNoTx(com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx) OrientVertexType(com.tinkerpop.blueprints.impls.orient.OrientVertexType) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) Test(org.junit.Test)

Example 24 with OrientVertexType

use of com.tinkerpop.blueprints.impls.orient.OrientVertexType in project orientdb by orientechnologies.

the class SQLMoveVertexCommandTest method reinitVertexType.

private OrientVertexType reinitVertexType(String className) {
    OrientVertexType clazz = graph.getVertexType(className);
    if (clazz != null) {
        graph.command(new OCommandSQL("delete vertex " + className)).execute();
        graph.dropVertexType(className);
    }
    clazz = graph.createVertexType(className);
    return clazz;
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OrientVertexType(com.tinkerpop.blueprints.impls.orient.OrientVertexType)

Example 25 with OrientVertexType

use of com.tinkerpop.blueprints.impls.orient.OrientVertexType in project orientdb by orientechnologies.

the class GraphEmbeddedTest method init.

@Before
public void init() {
    graph = new OrientGraph(db, false);
    OrientVertexType type = graph.createVertexType("City");
    type.createProperty("latitude", OType.DOUBLE);
    type.createProperty("longitude", OType.DOUBLE);
    type.createProperty("name", OType.STRING);
    db.command(new OCommandSQL("create index City.name on City (name) FULLTEXT ENGINE LUCENE")).execute();
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) OrientVertexType(com.tinkerpop.blueprints.impls.orient.OrientVertexType) Before(org.junit.Before)

Aggregations

OrientVertexType (com.tinkerpop.blueprints.impls.orient.OrientVertexType)31 OrientGraphNoTx (com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx)17 OrientVertex (com.tinkerpop.blueprints.impls.orient.OrientVertex)13 OrientGraph (com.tinkerpop.blueprints.impls.orient.OrientGraph)12 Test (org.junit.Test)9 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)8 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)5 OrientEdgeType (com.tinkerpop.blueprints.impls.orient.OrientEdgeType)5 Vertex (com.tinkerpop.blueprints.Vertex)4 OrientGraphFactory (com.tinkerpop.blueprints.impls.orient.OrientGraphFactory)4 Before (org.junit.Before)4 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)3 OrientBaseGraph (com.tinkerpop.blueprints.impls.orient.OrientBaseGraph)3 OValidationException (com.orientechnologies.orient.core.exception.OValidationException)2 ORecordId (com.orientechnologies.orient.core.id.ORecordId)2 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)2 OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)2 ONeedRetryException (com.orientechnologies.common.concur.ONeedRetryException)1 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)1 ORID (com.orientechnologies.orient.core.id.ORID)1