Search in sources :

Example 16 with GraphDatabaseFactory

use of org.neo4j.graphdb.factory.GraphDatabaseFactory in project blueprints by tinkerpop.

the class Neo4j2BatchGraph method removeReferenceNodeAndFinalizeKeyIndices.

private void removeReferenceNodeAndFinalizeKeyIndices() {
    GraphDatabaseService rawGraphDB = null;
    try {
        GraphDatabaseBuilder builder = new GraphDatabaseFactory().newEmbeddedDatabaseBuilder(this.rawGraph.getStoreDir());
        if (this.vertexIndexKeys.size() > 0)
            builder.setConfig(GraphDatabaseSettings.node_keys_indexable, vertexIndexKeys.toString().replace("[", "").replace("]", "")).setConfig(GraphDatabaseSettings.node_auto_indexing, "true");
        if (this.edgeIndexKeys.size() > 0)
            builder.setConfig(GraphDatabaseSettings.relationship_keys_indexable, edgeIndexKeys.toString().replace("[", "").replace("]", "")).setConfig(GraphDatabaseSettings.relationship_auto_indexing, "true");
        rawGraphDB = builder.newGraphDatabase();
        Transaction tx = rawGraphDB.beginTx();
        try {
            GlobalGraphOperations graphOperations = GlobalGraphOperations.at(rawGraphDB);
            if (this.vertexIndexKeys.size() > 0)
                populateKeyIndices(rawGraphDB, rawGraphDB.index().getNodeAutoIndexer(), graphOperations.getAllNodes(), Vertex.class);
            if (this.edgeIndexKeys.size() > 0)
                populateKeyIndices(rawGraphDB, rawGraphDB.index().getRelationshipAutoIndexer(), graphOperations.getAllRelationships(), Edge.class);
            tx.success();
        } finally {
            tx.close();
        }
    } catch (Exception e) {
        throw new RuntimeException(e.getMessage(), e);
    } finally {
        if (rawGraphDB != null)
            rawGraphDB.shutdown();
    }
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Vertex(com.tinkerpop.blueprints.Vertex) Transaction(org.neo4j.graphdb.Transaction) GraphDatabaseFactory(org.neo4j.graphdb.factory.GraphDatabaseFactory) Edge(com.tinkerpop.blueprints.Edge) GraphDatabaseBuilder(org.neo4j.graphdb.factory.GraphDatabaseBuilder) GlobalGraphOperations(org.neo4j.tooling.GlobalGraphOperations)

Aggregations

GraphDatabaseFactory (org.neo4j.graphdb.factory.GraphDatabaseFactory)16 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)9 Transaction (org.neo4j.graphdb.Transaction)8 GraphDatabaseBuilder (org.neo4j.graphdb.factory.GraphDatabaseBuilder)5 File (java.io.File)4 Test (org.junit.Test)4 TestGraphDatabaseFactory (org.neo4j.test.TestGraphDatabaseFactory)4 DependencyResolver (org.neo4j.graphdb.DependencyResolver)3 Edge (com.tinkerpop.blueprints.Edge)2 Vertex (com.tinkerpop.blueprints.Vertex)2 Label (org.neo4j.graphdb.Label)2 RecordStorageEngine (org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageEngine)2 NeoStores (org.neo4j.kernel.impl.store.NeoStores)2 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)2 GlobalGraphOperations (org.neo4j.tooling.GlobalGraphOperations)2 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 Path (java.nio.file.Path)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1