Search in sources :

Example 11 with DatabaseManagementServiceBuilder

use of org.neo4j.dbms.api.DatabaseManagementServiceBuilder in project neo4j-documentation by neo4j.

the class TraversalExample method main.

public static void main(String[] args) throws IOException {
    FileUtils.deleteDirectory(databaseDirectory);
    DatabaseManagementService managementService = new DatabaseManagementServiceBuilder(databaseDirectory).build();
    GraphDatabaseService database = managementService.database(DEFAULT_DATABASE_NAME);
    TraversalExample example = new TraversalExample(database);
    Node joe = example.createData();
    example.run(joe);
    managementService.shutdown();
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Node(org.neo4j.graphdb.Node) DatabaseManagementServiceBuilder(org.neo4j.dbms.api.DatabaseManagementServiceBuilder) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService)

Example 12 with DatabaseManagementServiceBuilder

use of org.neo4j.dbms.api.DatabaseManagementServiceBuilder in project neo4j-documentation by neo4j.

the class CalculateShortestPath method main.

public static void main(final String[] args) throws IOException {
    FileUtils.deleteDirectory(databaseDirectory);
    managementService = new DatabaseManagementServiceBuilder(databaseDirectory).build();
    graphDb = managementService.database(DEFAULT_DATABASE_NAME);
    registerShutdownHook();
    try (Transaction tx = graphDb.beginTx()) {
        /*
             *  (Neo) --> (Trinity)
             *     \       ^
             *      v     /
             *    (Morpheus) --> (Cypher)
             *            \         |
             *             v        v
             *            (Agent Smith)
             */
        createChain(tx, "Neo", "Trinity");
        createChain(tx, "Neo", "Morpheus", "Trinity");
        createChain(tx, "Morpheus", "Cypher", "Agent Smith");
        createChain(tx, "Morpheus", "Agent Smith");
        tx.commit();
    }
    try (Transaction tx = graphDb.beginTx()) {
        // So let's find the shortest path between Neo and Agent Smith
        Node neo = getOrCreateNode(tx, "Neo");
        Node agentSmith = getOrCreateNode(tx, "Agent Smith");
        // tag::shortestPathUsage[]
        PathFinder<Path> finder = GraphAlgoFactory.shortestPath(new BasicEvaluationContext(tx, graphDb), PathExpanders.forTypeAndDirection(KNOWS, Direction.BOTH), 4);
        Path foundPath = finder.findSinglePath(neo, agentSmith);
        System.out.println("Path from Neo to Agent Smith: " + Paths.simplePathToString(foundPath, NAME_KEY));
    // end::shortestPathUsage[]
    }
    System.out.println("Shutting down database ...");
    managementService.shutdown();
}
Also used : Path(org.neo4j.graphdb.Path) BasicEvaluationContext(org.neo4j.graphalgo.BasicEvaluationContext) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) DatabaseManagementServiceBuilder(org.neo4j.dbms.api.DatabaseManagementServiceBuilder)

Example 13 with DatabaseManagementServiceBuilder

use of org.neo4j.dbms.api.DatabaseManagementServiceBuilder in project neo4j-documentation by neo4j.

the class EmbeddedNeo4jWithBolt method main.

public static void main(final String[] args) throws IOException {
    System.out.println("Starting database ...");
    FileUtils.deleteDirectory(DB_PATH);
    // tag::startDb[]
    DatabaseManagementService managementService = new DatabaseManagementServiceBuilder(DB_PATH).setConfig(BoltConnector.enabled, true).setConfig(BoltConnector.listen_address, new SocketAddress("localhost", 7687)).build();
    // end::startDb[]
    managementService.shutdown();
}
Also used : DatabaseManagementServiceBuilder(org.neo4j.dbms.api.DatabaseManagementServiceBuilder) SocketAddress(org.neo4j.configuration.helpers.SocketAddress) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService)

Example 14 with DatabaseManagementServiceBuilder

use of org.neo4j.dbms.api.DatabaseManagementServiceBuilder in project neo4j-documentation by neo4j.

the class EmbeddedNeo4j method createDb.

void createDb() throws IOException {
    FileUtils.deleteDirectory(databaseDirectory);
    // tag::startDb[]
    managementService = new DatabaseManagementServiceBuilder(databaseDirectory).build();
    graphDb = managementService.database(DEFAULT_DATABASE_NAME);
    registerShutdownHook(managementService);
    // tag::transaction[]
    try (Transaction tx = graphDb.beginTx()) {
        // Database operations go here
        // end::transaction[]
        // tag::addData[]
        firstNode = tx.createNode();
        firstNode.setProperty("message", "Hello, ");
        secondNode = tx.createNode();
        secondNode.setProperty("message", "World!");
        relationship = firstNode.createRelationshipTo(secondNode, RelTypes.KNOWS);
        relationship.setProperty("message", "brave Neo4j ");
        // end::addData[]
        // tag::readData[]
        System.out.print(firstNode.getProperty("message"));
        System.out.print(relationship.getProperty("message"));
        System.out.print(secondNode.getProperty("message"));
        // end::readData[]
        greeting = ((String) firstNode.getProperty("message")) + ((String) relationship.getProperty("message")) + ((String) secondNode.getProperty("message"));
        // tag::transaction[]
        tx.commit();
    }
// end::transaction[]
}
Also used : Transaction(org.neo4j.graphdb.Transaction) DatabaseManagementServiceBuilder(org.neo4j.dbms.api.DatabaseManagementServiceBuilder)

Example 15 with DatabaseManagementServiceBuilder

use of org.neo4j.dbms.api.DatabaseManagementServiceBuilder in project neo4j-documentation by neo4j.

the class EmbeddedNeo4jWithCustomLogging method main.

public static void main(final String[] args) throws IOException {
    FileUtils.deleteDirectory(databaseDirectory);
    Object output = new Object();
    // tag::startDbWithLogProvider[]
    LogProvider logProvider = new MyCustomLogProvider(output);
    managementService = new DatabaseManagementServiceBuilder(databaseDirectory).setUserLogProvider(logProvider).build();
    // end::startDbWithLogProvider[]
    shutdown();
}
Also used : LogProvider(org.neo4j.logging.LogProvider) DatabaseManagementServiceBuilder(org.neo4j.dbms.api.DatabaseManagementServiceBuilder)

Aggregations

DatabaseManagementServiceBuilder (org.neo4j.dbms.api.DatabaseManagementServiceBuilder)30 DatabaseManagementService (org.neo4j.dbms.api.DatabaseManagementService)19 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)13 Transaction (org.neo4j.graphdb.Transaction)11 Node (org.neo4j.graphdb.Node)10 TestDatabaseManagementServiceBuilder (org.neo4j.test.TestDatabaseManagementServiceBuilder)10 Test (org.junit.jupiter.api.Test)9 Path (java.nio.file.Path)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 OutputStream (java.io.OutputStream)2 Test (org.junit.Test)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 Disabled (org.junit.jupiter.api.Disabled)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 MethodSource (org.junit.jupiter.params.provider.MethodSource)2 Relationship (org.neo4j.graphdb.Relationship)2 RelationshipType (org.neo4j.graphdb.RelationshipType)2 Result (org.neo4j.graphdb.Result)2 DefaultFileSystemAbstraction (org.neo4j.io.fs.DefaultFileSystemAbstraction)2 EphemeralFileSystemAbstraction (org.neo4j.io.fs.EphemeralFileSystemAbstraction)2