use of org.neo4j.driver.v1.types.Node in project cypher-for-gremlin by opencypher.
the class GremlinNeo4jDriverTest method returnPath.
@Test
public void returnPath() {
Driver driver = GremlinDatabase.driver("//localhost:" + server.getPort());
try (Session session = driver.session()) {
StatementResult setup = session.run("CREATE (n1:Person {name: 'Anders'})-[r:knows]->(n2:Person)" + "RETURN n1,r,n2");
Record createdNodes = setup.single();
Node n1 = createdNodes.get("n1").asNode();
Node n2 = createdNodes.get("n2").asNode();
Relationship r = createdNodes.get("r").asRelationship();
StatementResult result = session.run("MATCH p =(b1 { name: 'Anders' })-->()" + "RETURN p");
Path path = result.single().get("p").asPath();
assertThat(path.contains(n1)).isTrue();
assertThat(path.contains(n2)).isTrue();
assertThat(path.contains(r)).isTrue();
assertThat(path.relationships()).hasSize(1);
assertThat(path.nodes()).hasSize(2);
}
}
use of org.neo4j.driver.v1.types.Node in project structr by structr.
the class BoltDatabaseService method initialize.
@Override
public boolean initialize() {
this.databasePath = Settings.DatabasePath.getValue();
this.tenantId = Settings.TenantIdentifier.getValue();
if (StringUtils.isBlank(this.tenantId)) {
this.tenantId = null;
}
final BoltConnector bolt = new BoltConnector("0");
databaseUrl = Settings.ConnectionUrl.getValue();
final String username = Settings.ConnectionUser.getValue();
final String password = Settings.ConnectionPassword.getValue();
final String driverMode = Settings.DatabaseDriverMode.getValue();
final String confPath = databasePath + "/neo4j.conf";
final File confFile = new File(confPath);
// see https://github.com/neo4j/neo4j-java-driver/issues/364 for an explanation
final String databaseServerUrl;
final String databaseDriverUrl;
if (databaseUrl.length() >= 7 && databaseUrl.substring(0, 7).equalsIgnoreCase("bolt://")) {
databaseServerUrl = databaseUrl.substring(7);
databaseDriverUrl = databaseUrl;
} else if (databaseUrl.length() >= 15 && databaseUrl.substring(0, 15).equalsIgnoreCase("bolt+routing://")) {
databaseServerUrl = databaseUrl.substring(15);
databaseDriverUrl = databaseUrl;
} else {
databaseServerUrl = databaseUrl;
databaseDriverUrl = "bolt://" + databaseUrl;
}
// create db directory if it does not exist
new File(databasePath).mkdirs();
if (!"remote".equals(driverMode)) {
final GraphDatabaseBuilder builder = new GraphDatabaseFactory().newEmbeddedDatabaseBuilder(new File(databasePath)).setConfig(GraphDatabaseSettings.allow_store_upgrade, "true").setConfig("dbms.allow_format_migration", "true").setConfig(bolt.type, "BOLT").setConfig(bolt.enabled, "true").setConfig(bolt.address, databaseServerUrl);
if (confFile.exists()) {
builder.loadPropertiesFromFile(confPath);
}
graphDb = builder.newGraphDatabase();
}
try {
driver = GraphDatabase.driver(databaseDriverUrl, AuthTokens.basic(username, password), Config.build().withoutEncryption().toConfig());
final int relCacheSize = Settings.RelationshipCacheSize.getValue();
final int nodeCacheSize = Settings.NodeCacheSize.getValue();
NodeWrapper.initialize(nodeCacheSize);
logger.info("Node cache size set to {}", nodeCacheSize);
RelationshipWrapper.initialize(relCacheSize);
logger.info("Relationship cache size set to {}", relCacheSize);
// signal success
return true;
} catch (ServiceUnavailableException ex) {
logger.error("Neo4j service is not available.");
}
// service failed to initialize
return false;
}
use of org.neo4j.driver.v1.types.Node in project structr by structr.
the class EntityWrapper method assertNotStale.
// ----- protected methods -----
protected synchronized void assertNotStale() {
if (stale) {
// invalidate caches
onRemoveFromCache();
// if a node/rel was deleted in a previous transaction but the caller keeps a
// reference to this entity, we need to make sure that the reference is fresh.
final SessionTransaction tx = db.getCurrentTransaction();
final Map<String, Object> map = new HashMap<>();
map.put("id", id);
try {
// update data
data.clear();
update(tx.getEntity(getQueryPrefix() + " WHERE ID(n) = {id} RETURN n", map).asMap());
} catch (NoSuchRecordException nex) {
throw new NotFoundException(nex);
}
stale = false;
}
}
use of org.neo4j.driver.v1.types.Node in project cypher-for-gremlin by opencypher.
the class GremlinNeo4jDriverTest method returnNodeAndRelationship.
@Test
public void returnNodeAndRelationship() {
Driver driver = GremlinDatabase.driver("//localhost:" + server.getPort());
try (Session session = driver.session()) {
StatementResult result = session.run("CREATE (n1:Person {name: 'Marko'})-[r:knows {since:1999}]->(n2:Person)" + "RETURN n1,r,n2", parameters("message", "Hello"));
Record record = result.single();
Node n1 = record.get("n1").asNode();
Relationship r = record.get("r").asRelationship();
Node n2 = record.get("n2").asNode();
assertThat(n1.hasLabel("Person")).isTrue();
assertThat(n1.get("name").asString()).isEqualTo("Marko");
assertThat(r.hasType("knows")).isTrue();
assertThat(r.startNodeId()).isEqualTo(n1.id());
assertThat(r.endNodeId()).isEqualTo(n2.id());
assertThat(r.get("since").asLong()).isEqualTo(1999L);
assertThat(n2.hasLabel("Person")).isTrue();
}
}
use of org.neo4j.driver.v1.types.Node in project open-kilda by telstra.
the class PathComputerTest method testGetFlowInfo.
@Test
public void testGetFlowInfo() {
try (Transaction tx = graphDb.beginTx()) {
Node node1, node2;
node1 = graphDb.createNode(Label.label("switch"));
node1.setProperty("name", "00:03");
node2 = graphDb.createNode(Label.label("switch"));
node2.setProperty("name", "00:04");
Relationship rel1 = node1.createRelationshipTo(node2, RelationshipType.withName("flow"));
rel1.setProperty("flowid", "f1");
rel1.setProperty("cookie", 3);
rel1.setProperty("meter_id", 2);
rel1.setProperty("transit_vlan", 1);
rel1.setProperty("src_switch", "00:03");
tx.success();
}
Driver driver = GraphDatabase.driver("bolt://localhost:7878", AuthTokens.basic("neo4j", "password"));
NeoDriver nd = new NeoDriver(driver);
List<FlowInfo> fi = nd.getFlowInfo();
Assert.assertEquals(fi.get(0).getFlowId(), "f1");
Assert.assertEquals(fi.get(0).getCookie(), 3);
Assert.assertEquals(fi.get(0).getMeterId(), 2);
Assert.assertEquals(fi.get(0).getTransitVlanId(), 1);
Assert.assertEquals(fi.get(0).getSrcSwitchId(), "00:03");
}
Aggregations