use of org.neo4j.ogm.exception.TransactionException in project neo4j-ogm by neo4j.
the class BoltTransaction method rollback.
@Override
public void rollback() {
try {
if (transactionManager.canRollback()) {
LOGGER.debug("Rolling back native transaction: {}", nativeTransaction);
if (nativeTransaction.isOpen()) {
nativeTransaction.rollback();
nativeTransaction.close();
} else {
LOGGER.warn("Transaction is already closed");
}
closeNativeSessionIfPossible();
}
} catch (Exception e) {
closeNativeSessionIfPossible();
throw new TransactionException(e.getLocalizedMessage(), e);
} finally {
super.rollback();
}
}
use of org.neo4j.ogm.exception.TransactionException in project neo4j-ogm by neo4j.
the class BoltTransaction method commit.
@Override
public void commit() {
final boolean canCommit = transactionManager.canCommit();
try {
if (canCommit) {
LOGGER.debug("Committing native transaction: {}", nativeTransaction);
if (nativeTransaction.isOpen()) {
nativeTransaction.commit();
nativeTransaction.close();
nativeSession.close();
} else {
throw new IllegalStateException("Transaction is already closed");
}
}
} catch (ClientException ce) {
closeNativeSessionIfPossible();
if (ce.code().startsWith(NEO_CLIENT_ERROR_SECURITY)) {
throw new ConnectionException("Security Error: " + ce.code() + ", " + ce.getMessage(), ce);
}
throw new CypherException(ce.code(), ce.getMessage(), ce);
} catch (Exception e) {
closeNativeSessionIfPossible();
throw new TransactionException(e.getLocalizedMessage(), e);
} finally {
super.commit();
if (canCommit) {
Bookmark bookmark = nativeSession.lastBookmark();
if (bookmark != null) {
String bookmarkAsString = String.join(BOOKMARK_SEPARATOR, ((InternalBookmark) bookmark).values());
transactionManager.bookmark(bookmarkAsString);
}
}
}
}
use of org.neo4j.ogm.exception.TransactionException in project neo4j-ogm by neo4j.
the class EmbeddedTransaction method rollback.
@Override
public void rollback() {
try {
if (transactionManager.canRollback()) {
LOGGER.debug("rolling back native transaction: {}", nativeTransaction);
nativeTransaction.rollback();
nativeTransaction.close();
}
} catch (Exception e) {
throw new TransactionException(e.getLocalizedMessage(), e);
} finally {
super.rollback();
}
}
use of org.neo4j.ogm.exception.TransactionException in project neo4j-ogm by neo4j.
the class HttpTransaction method commit.
@Override
public void commit() {
try {
if (transactionManager.canCommit()) {
HttpPost request = new HttpPost(url + "/commit");
request.setHeader(new BasicHeader(HTTP.CONTENT_TYPE, "application/json;charset=UTF-8"));
request.setHeader(new BasicHeader("X-WRITE", readOnly() ? "0" : "1"));
driver.executeHttpRequest(request);
}
} catch (Exception e) {
throw new TransactionException(e.getLocalizedMessage(), e);
} finally {
// must always be done to keep extension depth correct
super.commit();
}
}
use of org.neo4j.ogm.exception.TransactionException in project cpg by Fraunhofer-AISEC.
the class EOGTest method testCPPCallGraph.
/**
* Test function (not method) calls.
*
* @throws TransactionException
*/
@Test
void testCPPCallGraph() throws Exception {
List<Node> nodes = translateToNodes("src/test/resources/cg.cpp");
List<CallExpression> calls = TestUtils.subnodesOfType(nodes, CallExpression.class);
List<FunctionDeclaration> functions = TestUtils.subnodesOfType(nodes, FunctionDeclaration.class);
FunctionDeclaration target;
CallExpression first = TestUtils.findByUniqueName(calls, "first");
target = TestUtils.findByUniqueName(functions, "first");
assertEquals(List.of(target), first.getInvokes());
CallExpression second = TestUtils.findByUniqueName(calls, "second");
target = TestUtils.findByUniqueName(functions, "second");
assertEquals(List.of(target), second.getInvokes());
CallExpression third = TestUtils.findByUniqueName(calls, "third");
target = TestUtils.findByUniquePredicate(functions, f -> f.getName().equals("third") && f.getParameters().size() == 2);
assertEquals(List.of(target), third.getInvokes());
CallExpression fourth = TestUtils.findByUniqueName(calls, "fourth");
target = TestUtils.findByUniqueName(functions, "fourth");
assertEquals(List.of(target), fourth.getInvokes());
}
Aggregations