Search in sources :

Example 1 with OrientVertexType

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

the class IndexTest method testPreservingIdentityInIndexTx.

public void testPreservingIdentityInIndexTx() {
    OrientGraph graph = new OrientGraph((ODatabaseDocumentTx) database.getUnderlying(), true);
    graph.setAutoScaleEdgeType(true);
    OrientVertexType fieldClass = graph.getVertexType("PreservingIdentityInIndexTxChild");
    if (fieldClass == null) {
        fieldClass = graph.createVertexType("PreservingIdentityInIndexTxChild");
        fieldClass.createProperty("name", OType.STRING);
        fieldClass.createProperty("in_field", OType.LINK);
        fieldClass.createIndex("nameParentIndex", OClass.INDEX_TYPE.NOTUNIQUE, "in_field", "name");
    }
    Vertex parent = graph.addVertex("class:PreservingIdentityInIndexTxParent");
    Vertex child = graph.addVertex("class:PreservingIdentityInIndexTxChild");
    parent.addEdge("preservingIdentityInIndexTxEdge", child);
    child.setProperty("name", "pokus");
    Vertex parent2 = graph.addVertex("class:PreservingIdentityInIndexTxParent");
    Vertex child2 = graph.addVertex("class:PreservingIdentityInIndexTxChild");
    parent2.addEdge("preservingIdentityInIndexTxEdge", child2);
    child2.setProperty("name", "pokus2");
    graph.commit();
    {
        fieldClass = graph.getVertexType("PreservingIdentityInIndexTxChild");
        OIndex<?> index = fieldClass.getClassIndex("nameParentIndex");
        OCompositeKey key = new OCompositeKey(parent.getId(), "pokus");
        Set<ORecordId> h = (Set<ORecordId>) index.get(key);
        for (ORecordId o : h) {
            Assert.assertNotNull(graph.getVertex(o));
        }
    }
    {
        fieldClass = graph.getVertexType("PreservingIdentityInIndexTxChild");
        OIndex<?> index = fieldClass.getClassIndex("nameParentIndex");
        OCompositeKey key = new OCompositeKey(parent2.getId(), "pokus2");
        Set<ORecordId> h = (Set<ORecordId>) index.get(key);
        for (ORecordId o : h) {
            Assert.assertNotNull(graph.getVertex(o));
        }
    }
    parent.remove();
    child.remove();
    parent2.remove();
    child2.remove();
    graph.shutdown();
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) OrientVertexType(com.tinkerpop.blueprints.impls.orient.OrientVertexType) ORecordId(com.orientechnologies.orient.core.id.ORecordId)

Example 2 with OrientVertexType

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

the class AbstractServerClusterSQLGraphTest method onAfterDatabaseCreation.

@Override
protected void onAfterDatabaseCreation(final OrientBaseGraph graph) {
    System.out.println("Creating graph schema...");
    // CREATE BASIC SCHEMA
    OrientVertexType personClass = graph.createVertexType("Person");
    personClass.createProperty("id", OType.STRING);
    personClass.createProperty("name", OType.STRING);
    personClass.createProperty("birthday", OType.DATE);
    personClass.createProperty("children", OType.STRING);
    OrientVertexType person = graph.getVertexType("Person");
    idx = person.createIndex("Person.name", OClass.INDEX_TYPE.UNIQUE, "name");
    OrientVertexType customer = graph.createVertexType("Customer", person);
    customer.createProperty("totalSold", OType.DECIMAL);
    OrientVertexType provider = graph.createVertexType("Provider", person);
    provider.createProperty("totalPurchased", OType.DECIMAL);
    OrientEdgeType knows = graph.createEdgeType("Knows");
    factory = new OrientGraphFactory(graph.getRawGraph().getURL(), "admin", "admin", false);
    factory.setStandardElementConstraints(false);
}
Also used : OrientEdgeType(com.tinkerpop.blueprints.impls.orient.OrientEdgeType) OrientGraphFactory(com.tinkerpop.blueprints.impls.orient.OrientGraphFactory) OrientVertexType(com.tinkerpop.blueprints.impls.orient.OrientVertexType)

Example 3 with OrientVertexType

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

the class ServerClusterSchemaTest method executeTest.

@Override
protected void executeTest() throws Exception {
    for (int s = 0; s < SERVERS; ++s) {
        OrientGraphFactory factory = new OrientGraphFactory("plocal:target/server" + s + "/databases/" + getDatabaseName());
        OrientGraphNoTx g = factory.getNoTx();
        try {
            System.out.println("Creating vertex class Client" + s + " against server " + g + "...");
            OrientVertexType t = g.createVertexType("Client" + s);
            t.createProperty("name", OType.STRING).setMandatory(true);
            System.out.println("Creating vertex class Knows" + s + " against server " + g + "...");
            g.createEdgeType("Knows" + s);
        } finally {
            g.shutdown();
        }
    }
    for (int s = 0; s < SERVERS; ++s) {
        System.out.println("Checking vertices classes on server " + s + "...");
        OrientGraphFactory factory = new OrientGraphFactory("plocal:target/server" + s + "/databases/" + getDatabaseName());
        OrientGraphNoTx g = factory.getNoTx();
        try {
            for (int i = 0; i < SERVERS; ++i) {
                Assert.assertNotNull(g.getVertexType("Client" + i));
                Assert.assertNotNull(g.getEdgeType("Knows" + i));
            }
        } finally {
            g.shutdown();
        }
    }
    for (int s = 0; s < SERVERS; ++s) {
        System.out.println("Add vertices on server " + s + "...");
        OrientGraphFactory factory = new OrientGraphFactory("plocal:target/server" + s + "/databases/" + getDatabaseName());
        OrientGraphNoTx g = factory.getNoTx();
        try {
            for (int i = 0; i < SERVERS; ++i) {
                try {
                    final OrientVertex v = g.addVertex("class:" + "Client" + i);
                    Assert.assertTrue(false);
                } catch (OValidationException e) {
                // EXPECTED
                }
            }
        } finally {
            g.shutdown();
        }
    }
    for (int s = 0; s < SERVERS; ++s) {
        System.out.println("Add vertices in TX on server " + s + "...");
        OrientGraphFactory factory = new OrientGraphFactory("plocal:target/server" + s + "/databases/" + getDatabaseName());
        OrientGraph g = factory.getTx();
        try {
            for (int i = 0; i < SERVERS; ++i) {
                try {
                    final OrientVertex v = g.addVertex("class:" + "Client" + i);
                    g.commit();
                    Assert.assertTrue(false);
                } catch (ONeedRetryException e) {
                // EXPECTED
                } catch (OValidationException e) {
                // EXPECTED
                }
            }
        } finally {
            g.shutdown();
        }
    }
}
Also used : OValidationException(com.orientechnologies.orient.core.exception.OValidationException) OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) ONeedRetryException(com.orientechnologies.common.concur.ONeedRetryException) OrientGraphFactory(com.tinkerpop.blueprints.impls.orient.OrientGraphFactory) OrientGraphNoTx(com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx) OrientVertexType(com.tinkerpop.blueprints.impls.orient.OrientVertexType) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex)

Example 4 with OrientVertexType

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

the class OrientDbCreationHelper method createSchemaDB.

public static void createSchemaDB(ODatabaseDocumentTx db) {
    OSchema schema = db.getMetadata().getSchema();
    // item
    OClass item = schema.createClass("Item");
    item.createProperty("stringKey", OType.STRING).createIndex(INDEX_TYPE.UNIQUE);
    item.createProperty("intKey", OType.INTEGER).createIndex(INDEX_TYPE.UNIQUE);
    item.createProperty("date", OType.DATE).createIndex(INDEX_TYPE.NOTUNIQUE);
    item.createProperty("time", OType.DATETIME).createIndex(INDEX_TYPE.NOTUNIQUE);
    item.createProperty("text", OType.STRING);
    item.createProperty("score", OType.DECIMAL);
    item.createProperty("length", OType.LONG).createIndex(INDEX_TYPE.NOTUNIQUE);
    item.createProperty("published", OType.BOOLEAN).createIndex(INDEX_TYPE.NOTUNIQUE);
    item.createProperty("title", OType.STRING).createIndex(INDEX_TYPE.NOTUNIQUE);
    item.createProperty("author", OType.STRING).createIndex(INDEX_TYPE.NOTUNIQUE);
    item.createProperty("tags", OType.EMBEDDEDLIST);
    // class Article
    OClass article = schema.createClass("Article");
    article.createProperty("uuid", OType.INTEGER).createIndex(INDEX_TYPE.UNIQUE);
    article.createProperty("date", OType.DATE).createIndex(INDEX_TYPE.NOTUNIQUE);
    article.createProperty("title", OType.STRING);
    article.createProperty("content", OType.STRING);
    // article.createProperty("attachment", OType.LINK);
    // author
    OClass author = schema.createClass("Author");
    author.createProperty("uuid", OType.LONG).createIndex(INDEX_TYPE.UNIQUE);
    author.createProperty("name", OType.STRING).setMin("3");
    author.createProperty("rating", OType.DOUBLE);
    author.createProperty("articles", OType.LINKLIST, article);
    // link article-->author
    article.createProperty("author", OType.LINK, author);
    //Graph
    OrientGraphNoTx graph = new OrientGraphNoTx(db);
    OrientVertexType post = graph.createVertexType("Post");
    post.createProperty("uuid", OType.LONG);
    post.createProperty("title", OType.STRING);
    post.createProperty("date", OType.DATE).createIndex(INDEX_TYPE.NOTUNIQUE);
    post.createProperty("content", OType.STRING);
    OrientVertexType writer = graph.createVertexType("Writer");
    writer.createProperty("uuid", OType.LONG).createIndex(INDEX_TYPE.UNIQUE);
    writer.createProperty("name", OType.STRING);
    writer.createProperty("is_active", OType.BOOLEAN);
    writer.createProperty("isActive", OType.BOOLEAN);
    graph.createEdgeType("Writes");
    schema.reload();
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) OrientGraphNoTx(com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx) OrientVertexType(com.tinkerpop.blueprints.impls.orient.OrientVertexType)

Example 5 with OrientVertexType

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

the class VertexIndexTest method testFullTextIndexOnvertex.

@Test
public void testFullTextIndexOnvertex() {
    OrientGraph graph = new OrientGraph("memory:TestDB", "admin", "admin");
    OrientVertexType vType = graph.getVertexType("V");
    vType.createProperty("title", OType.STRING);
    vType.createProperty("text", OType.STRING);
    vType.createIndex("V.", "FULLTEXT", null, null, "LUCENE", new String[] { "title", "text" });
    graph.drop();
}
Also used : OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) OrientVertexType(com.tinkerpop.blueprints.impls.orient.OrientVertexType) Test(org.junit.Test)

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