use of org.neo4j.dbms.api.DatabaseManagementServiceBuilder in project neo4j-documentation by neo4j.
the class ProcedureExampleDocTest method listDenseNodesShouldWork.
@Test
void listDenseNodesShouldWork() throws Throwable {
// Given
new JarBuilder().createJarFor(directory.resolve("myProcedures.jar").toFile(), ProcedureExample.class);
managementService = new DatabaseManagementServiceBuilder(directory).setConfig(GraphDatabaseSettings.plugin_dir, directory.toAbsolutePath()).build();
db = managementService.database(DEFAULT_DATABASE_NAME);
try (Transaction transaction = db.beginTx()) {
Node node1 = transaction.createNode();
Node node2 = transaction.createNode();
Node node3 = transaction.createNode();
node1.createRelationshipTo(node1, RelationshipType.withName("KNOWS"));
node1.createRelationshipTo(node2, RelationshipType.withName("KNOWS"));
node1.createRelationshipTo(node3, RelationshipType.withName("KNOWS"));
// When
Result res = transaction.execute("CALL org.neo4j.examples.findDenseNodes(2)");
// Then
assertEquals(map("degree", 3L, "nodeId", node1.getId()), res.next());
assertFalse(res.hasNext());
}
}
use of org.neo4j.dbms.api.DatabaseManagementServiceBuilder in project neo4j-documentation by neo4j.
the class ReadOnlyDocTest method prepareReadOnlyDatabase.
/**
* Create read only database.
*/
@Before
public void prepareReadOnlyDatabase() throws IOException {
Path dir = Path.of("target/read-only-managementService/location");
if (Files.exists(dir)) {
FileUtils.deleteDirectory(dir);
}
new DatabaseManagementServiceBuilder(dir).build().shutdown();
// tag::createReadOnlyInstance[]
managementService = new DatabaseManagementServiceBuilder(dir).setConfig(GraphDatabaseSettings.read_only_database_default, true).build();
graphDb = managementService.database(DEFAULT_DATABASE_NAME);
// end::createReadOnlyInstance[]
}
use of org.neo4j.dbms.api.DatabaseManagementServiceBuilder in project neo4j-documentation by neo4j.
the class TestGraphvizSubgraphOutput method testSimpleGraph.
@Test
public void testSimpleGraph() throws Exception {
Path folder = Path.of("target/example-db" + System.nanoTime());
DatabaseManagementService managementService = new DatabaseManagementServiceBuilder(folder).build();
try {
GraphDatabaseService neo = managementService.database(DEFAULT_DATABASE_NAME);
try (Transaction tx = neo.beginTx()) {
final Node emil = tx.createNode();
emil.setProperty("name", "Emil Eifrém");
emil.setProperty("country_of_residence", "USA");
final Node tobias = tx.createNode();
tobias.setProperty("name", "Tobias Ivarsson");
tobias.setProperty("country_of_residence", "Sweden");
final Node johan = tx.createNode();
johan.setProperty("name", "Johan Svensson");
johan.setProperty("country_of_residence", "Sweden");
final Relationship emilKNOWStobias = emil.createRelationshipTo(tobias, type.KNOWS);
final Relationship johanKNOWSemil = johan.createRelationshipTo(emil, type.KNOWS);
final Relationship tobiasKNOWSjohan = tobias.createRelationshipTo(johan, type.KNOWS);
final Relationship tobiasWORKS_FORemil = tobias.createRelationshipTo(emil, type.WORKS_FOR);
OutputStream out = new ByteArrayOutputStream();
SubgraphMapper subgraphMapper = node -> {
if (node.hasProperty("country_of_residence")) {
return (String) node.getProperty("country_of_residence");
}
return null;
};
GraphvizWriter writer = new GraphvizWriter();
SubgraphMapper.SubgraphMappingWalker walker = new SubgraphMapper.SubgraphMappingWalker(subgraphMapper) {
@Override
protected Iterable<Node> nodes() {
return asList(emil, tobias, johan);
}
@Override
protected Iterable<Relationship> relationships() {
return asList(emilKNOWStobias, johanKNOWSemil, tobiasKNOWSjohan, tobiasWORKS_FORemil);
}
};
writer.emit(out, walker);
tx.commit();
}
} finally {
managementService.shutdown();
deleteDirectory(folder.toFile());
}
}
use of org.neo4j.dbms.api.DatabaseManagementServiceBuilder in project neo4j-documentation by neo4j.
the class TestNewGraphvizWriter method testSimpleGraph.
@Test
public void testSimpleGraph() throws Exception {
Path folder = Path.of("target/example-db" + System.nanoTime());
DatabaseManagementService managementService = new DatabaseManagementServiceBuilder(folder).build();
try {
GraphDatabaseService neo = managementService.database(DEFAULT_DATABASE_NAME);
try (Transaction tx = neo.beginTx()) {
final Node emil = tx.createNode();
emil.setProperty("name", "Emil Eifrém");
emil.setProperty("age", 30);
final Node tobias = tx.createNode();
tobias.setProperty("name", "Tobias \"thobe\" Ivarsson");
tobias.setProperty("age", 23);
tobias.setProperty("hours", new int[] { 10, 10, 4, 4, 0 });
final Node johan = tx.createNode();
johan.setProperty("!<>)", "!<>)");
johan.setProperty("name", "!<>Johan '\\n00b' !<>Svensson");
final Relationship emilKNOWStobias = emil.createRelationshipTo(tobias, type.KNOWS);
emilKNOWStobias.setProperty("since", "2003-08-17");
final Relationship johanKNOWSemil = johan.createRelationshipTo(emil, type.KNOWS);
final Relationship tobiasKNOWSjohan = tobias.createRelationshipTo(johan, type.KNOWS);
final Relationship tobiasWORKS_FORemil = tobias.createRelationshipTo(emil, type.WORKS_FOR);
OutputStream out = new ByteArrayOutputStream();
GraphvizWriter writer = new GraphvizWriter();
Iterable<Node> traverser = tx.traversalDescription().depthFirst().relationships(type.KNOWS).relationships(type.WORKS_FOR).traverse(emil).nodes();
writer.emit(out, Walker.crosscut(traverser, type.KNOWS, type.WORKS_FOR));
tx.commit();
out.toString();
}
} finally {
managementService.shutdown();
deleteDirectory(folder.toFile());
}
}
use of org.neo4j.dbms.api.DatabaseManagementServiceBuilder in project neo4j-documentation by neo4j.
the class SocnetTest method setup.
@BeforeEach
void setup() throws Exception {
managementService = new DatabaseManagementServiceBuilder(folder).build();
graphDb = managementService.database(DEFAULT_DATABASE_NAME);
try (Transaction tx = graphDb.beginTx()) {
personRepository = new PersonRepository(graphDb, tx);
createPersons(tx);
setupFriendsBetweenPeople(tx, 10);
tx.commit();
}
}
Aggregations