Search in sources :

Example 6 with GraphDatabaseFactory

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

the class Neo4jBatchGraph 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, GraphDatabaseSetting.TRUE);
        if (this.edgeIndexKeys.size() > 0)
            builder.setConfig(GraphDatabaseSettings.relationship_keys_indexable, edgeIndexKeys.toString().replace("[", "").replace("]", "")).setConfig(GraphDatabaseSettings.relationship_auto_indexing, GraphDatabaseSetting.TRUE);
        rawGraphDB = builder.newGraphDatabase();
        Transaction tx = rawGraphDB.beginTx();
        try {
            rawGraphDB.getReferenceNode().delete();
            tx.success();
        } catch (Exception e) {
            tx.failure();
        } finally {
            tx.finish();
        }
        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);
    } 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)

Example 7 with GraphDatabaseFactory

use of org.neo4j.graphdb.factory.GraphDatabaseFactory in project javaee7-samples by javaee-samples.

the class PersonSessionBean method initDB.

@PostConstruct
private void initDB() {
    try {
        Path tempDir = Files.createTempDirectory("test-neo4j");
        graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(tempDir.toString());
        try (Transaction tx = graphDb.beginTx()) {
            firstNode = graphDb.createNode();
            secondNode = graphDb.createNode();
            tx.success();
        }
    } catch (IOException ex) {
        Logger.getLogger(PersonSessionBean.class.getName()).log(Level.SEVERE, null, ex);
    }
}
Also used : Path(java.nio.file.Path) Transaction(org.neo4j.graphdb.Transaction) GraphDatabaseFactory(org.neo4j.graphdb.factory.GraphDatabaseFactory) IOException(java.io.IOException) PostConstruct(javax.annotation.PostConstruct)

Example 8 with GraphDatabaseFactory

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

the class DatabaseRebuildTool method newDbBuilder.

private static GraphDatabaseBuilder newDbBuilder(File path, Args args) {
    GraphDatabaseBuilder builder = new GraphDatabaseFactory().newEmbeddedDatabaseBuilder(path);
    for (Map.Entry<String, String> entry : args.asMap().entrySet()) {
        if (entry.getKey().startsWith("D")) {
            String key = entry.getKey().substring(1);
            String value = entry.getValue();
            builder = builder.setConfig(key, value);
        }
    }
    return builder;
}
Also used : GraphDatabaseFactory(org.neo4j.graphdb.factory.GraphDatabaseFactory) Map(java.util.Map) GraphDatabaseBuilder(org.neo4j.graphdb.factory.GraphDatabaseBuilder)

Example 9 with GraphDatabaseFactory

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

the class LegacyIndexesUpgradeTest method startDatabase.

private GraphDatabaseService startDatabase(boolean allowUpgread) {
    GraphDatabaseFactory factory = new TestGraphDatabaseFactory();
    GraphDatabaseBuilder builder = factory.newEmbeddedDatabaseBuilder(testDir.graphDbDir());
    builder.setConfig(GraphDatabaseSettings.allow_store_upgrade, Boolean.toString(allowUpgread));
    builder.setConfig(GraphDatabaseSettings.pagecache_memory, "8m");
    return builder.newGraphDatabase();
}
Also used : GraphDatabaseFactory(org.neo4j.graphdb.factory.GraphDatabaseFactory) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) GraphDatabaseBuilder(org.neo4j.graphdb.factory.GraphDatabaseBuilder)

Example 10 with GraphDatabaseFactory

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

the class RestoreDatabaseCommandTest method createDbAt.

private void createDbAt(File fromPath, int nodesToCreate) {
    GraphDatabaseFactory factory = new GraphDatabaseFactory();
    GraphDatabaseService db = factory.newEmbeddedDatabase(fromPath);
    try (Transaction tx = db.beginTx()) {
        for (int i = 0; i < nodesToCreate; i++) {
            db.createNode();
        }
        tx.success();
    }
    db.shutdown();
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) GraphDatabaseFactory(org.neo4j.graphdb.factory.GraphDatabaseFactory)

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