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();
}
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();
}
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();
}
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[]
}
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();
}
Aggregations