Search in sources :

Example 66 with OrientGraphNoTx

use of com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx 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 67 with OrientGraphNoTx

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

the class BackupTest method main.

public static void main(String[] args) throws IOException {
    File backupFile = new File("testbackup.zip");
    OutputStream oS = new FileOutputStream(backupFile);
    OrientGraphFactory factory = new OrientGraphFactory("plocal:backupTest", "admin", "admin");
    OrientGraphNoTx graphNoTx = factory.getNoTx();
    graphNoTx.getRawGraph().backup(oS, null, null, null, 1, 1024);
    ZipFile zipFile = new ZipFile(backupFile);
    Enumeration enumeration = zipFile.entries();
    System.out.format("ZipFile : %s%n", zipFile);
    while (enumeration.hasMoreElements()) {
        Object entry = enumeration.nextElement();
        System.out.format("  Entry : %s%n", entry);
    }
    factory.close();
}
Also used : Enumeration(java.util.Enumeration) ZipFile(java.util.zip.ZipFile) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) OrientGraphFactory(com.tinkerpop.blueprints.impls.orient.OrientGraphFactory) OrientGraphNoTx(com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx) ZipFile(java.util.zip.ZipFile) File(java.io.File)

Example 68 with OrientGraphNoTx

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

the class DbCreationTest method testZipCompression.

public void testZipCompression() {
    if (database == null || !database.getURL().startsWith("plocal:"))
        return;
    OGlobalConfiguration.STORAGE_COMPRESSION_METHOD.setValue("gzip");
    final String buildDirectory = System.getProperty("buildDirectory", ".");
    String dburl = "plocal:" + buildDirectory + "/test-db/" + this.getClass().getSimpleName();
    final OrientGraphFactory factory = new OrientGraphFactory(dburl, "admin", "admin");
    if (factory.exists())
        factory.drop();
    factory.close();
    OrientGraphNoTx db = factory.getNoTx();
    db.drop();
    OGlobalConfiguration.STORAGE_COMPRESSION_METHOD.setValue(OGlobalConfiguration.STORAGE_COMPRESSION_METHOD.getValue());
}
Also used : OrientGraphFactory(com.tinkerpop.blueprints.impls.orient.OrientGraphFactory) OrientGraphNoTx(com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx)

Example 69 with OrientGraphNoTx

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

the class PLocalCreateVerticesMultiThreadSpeedTest method init.

@Override
public void init() {
    final OrientGraphNoTx graph = factory.getNoTx();
    try {
        if (graph.getVertexType("Client") == null) {
            final OrientVertexType clientType = graph.createVertexType("Client");
            final OrientVertexType.OrientVertexProperty property = clientType.createProperty("uid", OType.STRING);
            property.createIndex(OClass.INDEX_TYPE.UNIQUE_HASH_INDEX);
            // CREATE ONE CLUSTER PER THREAD
            for (int i = 0; i < getThreads(); ++i) {
                System.out.println("Creating cluster: client_" + i + "...");
                clientType.addCluster("client_" + i);
            }
            foundObjects = 0;
        } else
            foundObjects = graph.countVertices("Client");
    } finally {
        graph.shutdown();
    }
}
Also used : OrientGraphNoTx(com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx) OrientVertexType(com.tinkerpop.blueprints.impls.orient.OrientVertexType)

Example 70 with OrientGraphNoTx

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

the class PLocalCreateVerticesMultiThreadSpeedTest method deinit.

@Override
public void deinit() {
    final OrientGraphNoTx graph = factory.getNoTx();
    try {
        final long total = graph.countVertices("Client");
        System.out.println("\nTotal objects in Client cluster after the test: " + total);
        System.out.println("Created " + (total - foundObjects));
        Assert.assertEquals(total - foundObjects, threadCycles);
        final long indexedItems = graph.getRawGraph().getMetadata().getIndexManager().getIndex("Client.uid").getSize();
        System.out.println("\nTotal indexed objects after the test: " + indexedItems);
    } finally {
        graph.shutdown();
    }
}
Also used : OrientGraphNoTx(com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx)

Aggregations

OrientGraphNoTx (com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx)72 OrientVertex (com.tinkerpop.blueprints.impls.orient.OrientVertex)28 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)23 Test (org.junit.Test)22 OrientGraphFactory (com.tinkerpop.blueprints.impls.orient.OrientGraphFactory)20 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)17 OrientVertexType (com.tinkerpop.blueprints.impls.orient.OrientVertexType)17 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)16 OrientBaseGraph (com.tinkerpop.blueprints.impls.orient.OrientBaseGraph)15 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)7 Vertex (com.tinkerpop.blueprints.Vertex)6 OrientGraph (com.tinkerpop.blueprints.impls.orient.OrientGraph)6 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)5 OGraphMLReader (com.orientechnologies.orient.graph.graphml.OGraphMLReader)5 OGraphRepair (com.tinkerpop.blueprints.impls.orient.OGraphRepair)5 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)4 Edge (com.tinkerpop.blueprints.Edge)4 OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)3 OrientEdge (com.tinkerpop.blueprints.impls.orient.OrientEdge)3 File (java.io.File)3