Search in sources :

Example 11 with GraphDatabaseFactory

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

the class StoreMigrationIT method createDb.

private static void createDb(RecordFormats recordFormat, File storeDir) throws IOException {
    GraphDatabaseService database = new GraphDatabaseFactory().newEmbeddedDatabaseBuilder(storeDir).setConfig(GraphDatabaseSettings.allow_store_upgrade, Settings.TRUE).setConfig(GraphDatabaseSettings.record_format, recordFormat.storeVersion()).newGraphDatabase();
    database.shutdown();
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) GraphDatabaseFactory(org.neo4j.graphdb.factory.GraphDatabaseFactory) EnterpriseGraphDatabaseFactory(org.neo4j.graphdb.factory.EnterpriseGraphDatabaseFactory)

Example 12 with GraphDatabaseFactory

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

the class BoltFailuresIT method throwsWhenMonitoredWorkerCreationFails.

@Test(timeout = TEST_TIMEOUT)
public void throwsWhenMonitoredWorkerCreationFails() {
    ThrowingSessionMonitor sessionMonitor = new ThrowingSessionMonitor();
    sessionMonitor.throwInSessionStarted();
    Monitors monitors = newMonitorsSpy(sessionMonitor);
    db = startDbWithBolt(new GraphDatabaseFactory().setMonitors(monitors));
    driver = createDriver();
    try {
        driver.session();
        fail("Exception expected");
    } catch (Exception e) {
        assertThat(e, instanceOf(ConnectionFailureException.class));
    }
}
Also used : GraphDatabaseFactory(org.neo4j.graphdb.factory.GraphDatabaseFactory) Monitors(org.neo4j.kernel.monitoring.Monitors) ConnectionFailureException(org.neo4j.driver.v1.exceptions.ConnectionFailureException) Test(org.junit.Test)

Example 13 with GraphDatabaseFactory

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

the class DbStructureTool method main.

public static void main(String[] args) throws IOException {
    if (args.length != 2 && args.length != 3) {
        System.err.println("arguments: <generated class name> [<output source root>] <database dir>");
        System.exit(1);
    }
    boolean writeToFile = args.length == 3;
    String generatedClassWithPackage = args[0];
    String dbDir = writeToFile ? args[2] : args[1];
    Pair<String, String> parsedGenerated = parseClassNameWithPackage(generatedClassWithPackage);
    String generatedClassPackage = parsedGenerated.first();
    String generatedClassName = parsedGenerated.other();
    String generator = format("%s %s [<output source root>] <db-dir>", DbStructureTool.class.getCanonicalName(), generatedClassWithPackage);
    GraphDatabaseService graph = new GraphDatabaseFactory().newEmbeddedDatabase(new File(dbDir));
    try {
        if (writeToFile) {
            File sourceRoot = new File(args[1]);
            String outputPackageDir = generatedClassPackage.replace('.', File.separatorChar);
            String outputFileName = generatedClassName + ".java";
            File outputDir = new File(sourceRoot, outputPackageDir);
            File outputFile = new File(outputDir, outputFileName);
            try (PrintWriter writer = new PrintWriter(outputFile)) {
                traceDb(generator, generatedClassPackage, generatedClassName, graph, writer);
            }
        } else {
            traceDb(generator, generatedClassPackage, generatedClassName, graph, System.out);
        }
    } finally {
        graph.shutdown();
    }
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) GraphDatabaseFactory(org.neo4j.graphdb.factory.GraphDatabaseFactory) File(java.io.File) PrintWriter(java.io.PrintWriter)

Example 14 with GraphDatabaseFactory

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

the class DeferredIndexedConflictResolutionTest method setUp.

@Before
public void setUp() {
    GraphDatabaseFactory factory = new TestGraphDatabaseFactory();
    db = factory.newEmbeddedDatabase(storePath.absolutePath());
    GraphDatabaseAPI api = (GraphDatabaseAPI) db;
    Label nodeLabel = Label.label("Label");
    String propertyKey = "someProp";
    long nodeId;
    try (Transaction transaction = db.beginTx()) {
        Node node = db.createNode(nodeLabel);
        node.setProperty(propertyKey, "someVal");
        nodeId = node.getId();
        transaction.success();
    }
    DependencyResolver resolver = api.getDependencyResolver();
    NeoStores neoStores = resolver.resolveDependency(RecordStorageEngine.class).testAccessNeoStores();
    nodeStore = neoStores.getNodeStore();
    propertyStore = neoStores.getPropertyStore();
    Map<String, Integer> propertyKeys = PropertyDeduplicatorTestUtil.indexPropertyKeys(neoStores.getPropertyKeyTokenStore());
    nodeRecord = RecordStore.getRecord(nodeStore, nodeId);
    int propertyKeyId = propertyKeys.get(propertyKey);
    clusterToRemove = createDuplicateCluster(propertyKeyId, nodeRecord.getNextProp());
    clusters = new ArrayList<>();
    clusters.add(createDuplicateCluster(propertyKeyId + 1, nodeRecord.getNextProp()));
    // This is the one we want to remove
    clusters.add(clusterToRemove);
    clusters.add(createDuplicateCluster(propertyKeyId + 2, nodeRecord.getNextProp()));
}
Also used : Node(org.neo4j.graphdb.Node) Label(org.neo4j.graphdb.Label) DependencyResolver(org.neo4j.graphdb.DependencyResolver) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Transaction(org.neo4j.graphdb.Transaction) GraphDatabaseFactory(org.neo4j.graphdb.factory.GraphDatabaseFactory) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) RecordStorageEngine(org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageEngine) NeoStores(org.neo4j.kernel.impl.store.NeoStores) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) Before(org.junit.Before)

Example 15 with GraphDatabaseFactory

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

the class TestLuceneSchemaBatchInsertIT method shouldLoadAndUseLuceneProvider.

@Test
public void shouldLoadAndUseLuceneProvider() throws Exception {
    // GIVEN
    File storeDir = testDirectory.graphDbDir();
    BatchInserter inserter = BatchInserters.inserter(storeDir, fileSystemRule.get());
    inserter.createDeferredSchemaIndex(LABEL).on("name").create();
    // WHEN
    inserter.createNode(map("name", "Mattias"), LABEL);
    inserter.shutdown();
    // THEN
    GraphDatabaseFactory graphDatabaseFactory = new TestGraphDatabaseFactory();
    GraphDatabaseAPI db = (GraphDatabaseAPI) graphDatabaseFactory.newEmbeddedDatabase(storeDir);
    DependencyResolver dependencyResolver = db.getDependencyResolver();
    SchemaIndexProvider schemaIndexProvider = dependencyResolver.resolveDependency(SchemaIndexProvider.class, HighestSelectionStrategy.getInstance());
    // assert the indexProvider is a Lucene one
    try (Transaction ignore = db.beginTx()) {
        IndexDefinition indexDefinition = Iterables.single(db.schema().getIndexes(LABEL));
        assertThat(db.schema().getIndexState(indexDefinition), is(Schema.IndexState.ONLINE));
        assertThat(schemaIndexProvider, instanceOf(LuceneSchemaIndexProvider.class));
    }
    // CLEANUP
    db.shutdown();
}
Also used : LuceneSchemaIndexProvider(org.neo4j.kernel.api.impl.schema.LuceneSchemaIndexProvider) LuceneSchemaIndexProvider(org.neo4j.kernel.api.impl.schema.LuceneSchemaIndexProvider) SchemaIndexProvider(org.neo4j.kernel.api.index.SchemaIndexProvider) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Transaction(org.neo4j.graphdb.Transaction) IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) GraphDatabaseFactory(org.neo4j.graphdb.factory.GraphDatabaseFactory) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) File(java.io.File) DependencyResolver(org.neo4j.graphdb.DependencyResolver) Test(org.junit.Test)

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