Search in sources :

Example 11 with OrientGraphFactory

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

the class ServerRun method createDatabase.

public OrientBaseGraph createDatabase(final String iName, final OCallable<Object, OrientGraphFactory> iCfgCallback) {
    String dbPath = getDatabasePath(iName);
    new File(dbPath).mkdirs();
    OrientGraphFactory factory = new OrientGraphFactory("plocal:" + dbPath);
    if (factory.exists()) {
        System.out.println("Dropping previous database '" + iName + "' under: " + dbPath + "...");
        new ODatabaseDocumentTx("plocal:" + dbPath).open("admin", "admin").drop();
        OFileUtils.deleteRecursively(new File(dbPath));
        factory.drop();
        factory = new OrientGraphFactory("plocal:" + dbPath);
    }
    if (iCfgCallback != null)
        iCfgCallback.call(factory);
    System.out.println("Creating database '" + iName + "' under: " + dbPath + "...");
    return factory.getNoTx();
}
Also used : OrientGraphFactory(com.tinkerpop.blueprints.impls.orient.OrientGraphFactory) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) File(java.io.File)

Example 12 with OrientGraphFactory

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

the class DatabaseConflictStrategyAutoMergeTest method testAutoMerge.

@Test
public void testAutoMerge() throws Throwable {
    OrientGraphFactory factory = new OrientGraphFactory(CLIENT_ORIENT_URL_MAIN);
    OrientBaseGraph graph = factory.getNoTx();
    graph.setConflictStrategy(OAutoMergeRecordConflictStrategy.NAME);
    graph.createVertexType("vertextype");
    graph.createEdgeType("edgetype");
    graph.shutdown();
    factory.close();
    Thread dbClient1 = new Thread() {

        @Override
        public void run() {
            dbClient1();
        }
    };
    dbClient1.start();
    // Start the second DB client.
    Thread dbClient2 = new Thread() {

        @Override
        public void run() {
            dbClient2();
        }
    };
    dbClient2.start();
    dbClient1.join();
    dbClient2.join();
    if (exceptionInThread != null) {
        throw exceptionInThread;
    }
}
Also used : OrientGraphFactory(com.tinkerpop.blueprints.impls.orient.OrientGraphFactory) OrientBaseGraph(com.tinkerpop.blueprints.impls.orient.OrientBaseGraph) Test(org.testng.annotations.Test)

Example 13 with OrientGraphFactory

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

the class OOrientDBLoader method beginLoader.

public void beginLoader(OETLPipeline pipeline) {
    synchronized (this) {
        ODatabaseDocument documentDatabase = null;
        OrientBaseGraph graphDatabase = null;
        final OrientGraphFactory factory = new OrientGraphFactory(dbURL, dbUser, dbPassword);
        graphDatabase = tx ? factory.getTx() : factory.getNoTx();
        graphDatabase.setUseLightweightEdges(useLightweightEdges);
        graphDatabase.setStandardElementConstraints(standardElementConstraints);
        documentDatabase = graphDatabase.getRawGraph();
        pipeline.setDocumentDatabase(documentDatabase);
        pipeline.setGraphDatabase(graphDatabase);
        createSchema(pipeline, documentDatabase);
        documentDatabase.getMetadata().getSchema().reload();
        documentDatabase.declareIntent(new OIntentMassiveInsert());
    }
}
Also used : ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) OrientGraphFactory(com.tinkerpop.blueprints.impls.orient.OrientGraphFactory) OrientBaseGraph(com.tinkerpop.blueprints.impls.orient.OrientBaseGraph) OIntentMassiveInsert(com.orientechnologies.orient.core.intent.OIntentMassiveInsert)

Example 14 with OrientGraphFactory

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

the class OOrientDBLoader method configureGraphDB.

private void configureGraphDB() {
    OrientGraphFactory factory = new OrientGraphFactory(dbURL, dbUser, dbPassword);
    if (dbAutoDropIfExists && factory.exists()) {
        log(INFO, "Dropping existent database '%s'...", dbURL);
        factory.drop();
    }
    if (!factory.exists()) {
        factory = new OrientGraphFactory(dbURL, dbUser, dbPassword);
    }
    final OrientBaseGraph graphDatabase = tx ? factory.getTx() : factory.getNoTx();
    graphDatabase.shutdown();
}
Also used : OrientGraphFactory(com.tinkerpop.blueprints.impls.orient.OrientGraphFactory) OrientBaseGraph(com.tinkerpop.blueprints.impls.orient.OrientBaseGraph)

Example 15 with OrientGraphFactory

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

the class GraphValidationTest method fail.

@Test
public void fail() {
    setupSchema();
    final OrientGraphFactory orientGraphFactory = new OrientGraphFactory(URL, "admin", "admin").setupPool(1, 10);
    OrientGraph graph = orientGraphFactory.getTx();
    try {
        graph.addVertex("class:M", "name", "n0");
        try {
            graph.addVertex("class:M");
            graph.commit();
            // This is what happens => not OK?
            throw new RuntimeException("Schema problem was not detected!");
        } catch (OValidationException e) {
            System.out.println("This is the Message I want to see: \n" + e);
        }
    } finally {
        graph.shutdown();
    }
}
Also used : OValidationException(com.orientechnologies.orient.core.exception.OValidationException) OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) OrientGraphFactory(com.tinkerpop.blueprints.impls.orient.OrientGraphFactory) Test(org.junit.Test)

Aggregations

OrientGraphFactory (com.tinkerpop.blueprints.impls.orient.OrientGraphFactory)40 OrientGraphNoTx (com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx)19 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)13 OrientVertex (com.tinkerpop.blueprints.impls.orient.OrientVertex)13 OrientBaseGraph (com.tinkerpop.blueprints.impls.orient.OrientBaseGraph)8 OrientGraph (com.tinkerpop.blueprints.impls.orient.OrientGraph)7 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)5 ONeedRetryException (com.orientechnologies.common.concur.ONeedRetryException)4 OrientVertexType (com.tinkerpop.blueprints.impls.orient.OrientVertexType)4 Before (org.junit.Before)4 Test (org.junit.Test)4 File (java.io.File)3 HashMap (java.util.HashMap)3 Test (org.testng.annotations.Test)3 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)2 ORecordNotFoundException (com.orientechnologies.orient.core.exception.ORecordNotFoundException)2 OValidationException (com.orientechnologies.orient.core.exception.OValidationException)2 OIntentMassiveInsert (com.orientechnologies.orient.core.intent.OIntentMassiveInsert)2 ORecordDuplicatedException (com.orientechnologies.orient.core.storage.ORecordDuplicatedException)2 ODistributedException (com.orientechnologies.orient.server.distributed.ODistributedException)2