use of nikita.model.noark5.v4.Record 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 nikita.model.noark5.v4.Record in project structr by structr.
the class SessionTransaction method getStrings.
public QueryResult<String> getStrings(final String statement, final Map<String, Object> map) {
final long t0 = System.currentTimeMillis();
try {
final StatementResult result = tx.run(statement, map);
final Record record = result.next();
final Value value = record.get(0);
return new QueryResult<String>() {
@Override
public void close() {
result.consume();
}
@Override
public Iterator<String> iterator() {
return value.asList(Values.ofString()).iterator();
}
};
} catch (TransientException tex) {
closed = true;
throw new RetryException(tex);
} catch (NoSuchRecordException nex) {
throw new NotFoundException(nex);
} catch (ServiceUnavailableException ex) {
throw new NetworkException(ex.getMessage(), ex);
} finally {
logQuery(statement, map, t0);
}
}
use of nikita.model.noark5.v4.Record in project wildfly-swarm by wildfly-swarm.
the class BMTStatefulTestBean method twoTransactions.
public String twoTransactions() throws Exception {
// start the JTA transaction via javax.transaction.UserTransaction
userTransaction.begin();
try {
// obtain session which will be enlisted into the JTA transaction.
Session session = driver.session();
if (session != driver.session()) {
throw new RuntimeException("multiple calls to Driver.session() must return the same session within JTA transaction.");
}
// Calls to Session.beginTransaction() in a JTA transaction are expected to throw a RuntimeException
try {
Transaction transaction = session.beginTransaction();
fail("Calling Session.beginTransaction in a JTA transaction should throw a RuntimeException.");
} catch (RuntimeException expectedException) {
// success
}
session.run("CREATE (a:Person {name:'BMT', title:'King'})");
// calls to close the session should also be ignored, since the session is also considered to be enlisted into the JTA transaction
session.close();
if (session.isOpen() != true) {
throw new RuntimeException("Session should be open since JTA transaction is still active.");
}
// commit the JTA transaction, which also calls org.neo4j.driver.v1.Transaction.success()/close().
// if the JTA transaction rolls back, org.neo4j.driver.v1.Transaction.failure()/close() would instead be called.
userTransaction.commit();
if (session.isOpen() != false) {
throw new RuntimeException("Session should now be closed since JTA transaction ended.");
}
// should be ignored
session.close();
// Start another JTA transaction, note that the session has to be obtained again
userTransaction.begin();
session = driver.session();
if (session != driver.session()) {
throw new RuntimeException("multiple calls to Driver.session() must return the same session within JTA transaction.");
}
// Calls to Session.beginTransaction() in a JTA transaction are expected to throw a RuntimeException
try {
Transaction transaction = session.beginTransaction();
fail("Calling Session.beginTransaction in a JTA transaction should throw a RuntimeException.");
} catch (RuntimeException expectedException) {
// success
}
StatementResult result = session.run("MATCH (a:Person) WHERE a.name = 'BMT' RETURN a.name AS name, a.title AS title");
Record record = result.next();
return record.toString();
} finally {
if (userTransaction.getStatus() == Status.STATUS_ACTIVE) {
// second JTA transaction is ended, which also closes the enlisted org.neo4j.driver.v1.Transaction/Session
userTransaction.commit();
}
Session cleanupSession = driver.session();
cleanupSession.run("MATCH (a:Person) delete a");
cleanupSession.close();
}
}
use of nikita.model.noark5.v4.Record in project wildfly-swarm by wildfly-swarm.
the class StatefulTestBean method addPersonClassInstanceInjection.
public String addPersonClassInstanceInjection() {
Session session = injectedDriver.session();
try {
session.run("CREATE (a:Person {name:'CDI', title:'King'})");
StatementResult result = session.run("MATCH (a:Person) WHERE a.name = 'CDI' RETURN a.name AS name, a.title AS title");
Record record = result.next();
return record.toString();
} finally {
session.run("MATCH (a:Person) delete a");
session.close();
}
}
use of nikita.model.noark5.v4.Record in project wildfly-swarm by wildfly-swarm.
the class StatefulTestBean method addPerson.
public String addPerson() {
Session session = driver.session();
try {
session.run("CREATE (a:Person {name:'Arthur', title:'King'})");
StatementResult result = session.run("MATCH (a:Person) WHERE a.name = 'Arthur' RETURN a.name AS name, a.title AS title");
Record record = result.next();
return record.toString();
} finally {
session.run("MATCH (a:Person) delete a");
session.close();
}
}
Aggregations