use of com.jimmysun.algorithms.chapter2_1.Transaction in project wildfly-swarm by wildfly-swarm.
the class StatefulTestBean method transactionEnlistmentReadAfterCallingTransactionClose.
public String transactionEnlistmentReadAfterCallingTransactionClose() {
// JTA transaction is started by CMT, the following obtains a Session that is enlisted into the JTA transaction.
Session session = injectedDriver.session();
// 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
}
try {
session.run("CREATE (a:Person {name:'TRANSACTION', title:'King'})");
return nestedBean.getPerson("TRANSACTION");
} finally {
if (session.isOpen()) {
// this will be true
session.run("MATCH (a:Person) delete a");
// ignored, session is auto closed when the transaction ends.
session.close();
}
}
}
use of com.jimmysun.algorithms.chapter2_1.Transaction in project AlgorithmsSolutions by Allenskoo856.
the class TopM method main.
public static void main(String[] args) {
int M = Integer.parseInt(args[0]);
MinPQ<Transaction> pq = new MinPQ<Transaction>(M + 1);
while (StdIn.hasNextLine()) {
pq.insert(new Transaction(StdIn.readLine()));
if (pq.size() > M) {
pq.delMin();
}
}
Stack<Transaction> stack = new Stack<Transaction>();
while (!pq.isEmpty()) {
stack.push(pq.delMin());
}
for (Transaction t : stack) {
StdOut.println(t);
}
}
use of com.jimmysun.algorithms.chapter2_1.Transaction in project neo4j by neo4j.
the class BoltCausalClusteringIT method bookmarksShouldWorkWithDriverPinnedToSingleServer.
// Ensure that Bookmarks work with single instances using a driver created using a bolt[not+routing] URI.
@Test
public void bookmarksShouldWorkWithDriverPinnedToSingleServer() throws Exception {
// given
cluster = clusterRule.withNumberOfReadReplicas(1).startCluster();
CoreClusterMember leader = cluster.awaitLeader();
try (Driver driver = GraphDatabase.driver(leader.directURI(), AuthTokens.basic("neo4j", "neo4j"))) {
String bookmark = inExpirableSession(driver, Driver::session, (session) -> {
try (Transaction tx = session.beginTransaction()) {
tx.run("CREATE (p:Person {name: {name} })", Values.parameters("name", "Alistair"));
tx.success();
}
return session.lastBookmark();
});
assertNotNull(bookmark);
try (Session session = driver.session();
Transaction tx = session.beginTransaction(bookmark)) {
Record record = tx.run("MATCH (n:Person) RETURN COUNT(*) AS count").next();
assertEquals(1, record.get("count").asInt());
tx.success();
}
}
}
use of com.jimmysun.algorithms.chapter2_1.Transaction in project neo4j by neo4j.
the class BoltCausalClusteringIT method shouldUseBookmarkFromAReadSessionInAWriteSession.
@Test
public void shouldUseBookmarkFromAReadSessionInAWriteSession() throws Exception {
// given
cluster = clusterRule.withNumberOfReadReplicas(1).startCluster();
CoreClusterMember leader = cluster.awaitLeader();
try (Driver driver = GraphDatabase.driver(leader.directURI(), AuthTokens.basic("neo4j", "neo4j"))) {
inExpirableSession(driver, (d) -> d.session(AccessMode.WRITE), (session) -> {
session.run("CREATE (p:Person {name: {name} })", Values.parameters("name", "Jim"));
return null;
});
String bookmark;
try (Session session = driver.session(AccessMode.READ)) {
try (Transaction tx = session.beginTransaction()) {
tx.run("MATCH (n:Person) RETURN COUNT(*) AS count").next();
tx.success();
}
bookmark = session.lastBookmark();
}
assertNotNull(bookmark);
inExpirableSession(driver, (d) -> d.session(AccessMode.WRITE), (session) -> {
try (Transaction tx = session.beginTransaction(bookmark)) {
tx.run("CREATE (p:Person {name: {name} })", Values.parameters("name", "Alistair"));
tx.success();
}
return null;
});
try (Session session = driver.session()) {
Record record = session.run("MATCH (n:Person) RETURN COUNT(*) AS count").next();
assertEquals(2, record.get("count").asInt());
}
}
}
use of com.jimmysun.algorithms.chapter2_1.Transaction in project neo4j by neo4j.
the class BoltCausalClusteringIT method executeReadQuery.
private void executeReadQuery(String bookmark, Session session) {
try (Transaction tx = session.beginTransaction(bookmark)) {
Record record = tx.run("MATCH (n:Person) RETURN COUNT(*) AS count").next();
assertEquals(1, record.get("count").asInt());
}
}
Aggregations