Search in sources :

Example 1 with TransactionException

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();
    }
}
Also used : TransactionException(org.neo4j.ogm.exception.TransactionException) CypherException(org.neo4j.ogm.exception.CypherException) ConnectionException(org.neo4j.ogm.exception.ConnectionException) TransactionException(org.neo4j.ogm.exception.TransactionException) ClientException(org.neo4j.driver.exceptions.ClientException)

Example 2 with TransactionException

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);
            }
        }
    }
}
Also used : TransactionException(org.neo4j.ogm.exception.TransactionException) InternalBookmark(org.neo4j.driver.internal.InternalBookmark) Bookmark(org.neo4j.driver.Bookmark) ClientException(org.neo4j.driver.exceptions.ClientException) CypherException(org.neo4j.ogm.exception.CypherException) ConnectionException(org.neo4j.ogm.exception.ConnectionException) CypherException(org.neo4j.ogm.exception.CypherException) ConnectionException(org.neo4j.ogm.exception.ConnectionException) TransactionException(org.neo4j.ogm.exception.TransactionException) ClientException(org.neo4j.driver.exceptions.ClientException)

Example 3 with TransactionException

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();
    }
}
Also used : TransactionException(org.neo4j.ogm.exception.TransactionException) TransactionException(org.neo4j.ogm.exception.TransactionException)

Example 4 with TransactionException

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();
    }
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) TransactionException(org.neo4j.ogm.exception.TransactionException) BasicHeader(org.apache.http.message.BasicHeader) TransactionException(org.neo4j.ogm.exception.TransactionException)

Example 5 with TransactionException

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());
}
Also used : EvaluationOrderGraphPass(de.fraunhofer.aisec.cpg.passes.EvaluationOrderGraphPass) Properties(de.fraunhofer.aisec.cpg.graph.edge.Properties) SUBTREE(de.fraunhofer.aisec.cpg.helpers.Util.Connect.SUBTREE) de.fraunhofer.aisec.cpg.graph(de.fraunhofer.aisec.cpg.graph) BaseTest(de.fraunhofer.aisec.cpg.BaseTest) NodeComparator(de.fraunhofer.aisec.cpg.helpers.NodeComparator) ConstructorDeclaration(de.fraunhofer.aisec.cpg.graph.declarations.ConstructorDeclaration) Util(de.fraunhofer.aisec.cpg.helpers.Util) SubgraphWalker(de.fraunhofer.aisec.cpg.helpers.SubgraphWalker) FunctionDeclaration(de.fraunhofer.aisec.cpg.graph.declarations.FunctionDeclaration) PropertyEdge(de.fraunhofer.aisec.cpg.graph.edge.PropertyEdge) Path(java.nio.file.Path) EXITS(de.fraunhofer.aisec.cpg.helpers.Util.Edge.EXITS) PhysicalLocation.locationLink(de.fraunhofer.aisec.cpg.sarif.PhysicalLocation.locationLink) NODE(de.fraunhofer.aisec.cpg.helpers.Util.Connect.NODE) ALL(de.fraunhofer.aisec.cpg.helpers.Util.Quantifier.ALL) DeclaredReferenceExpression(de.fraunhofer.aisec.cpg.graph.statements.expressions.DeclaredReferenceExpression) Strategy(de.fraunhofer.aisec.cpg.processing.strategy.Strategy) TestUtils(de.fraunhofer.aisec.cpg.TestUtils) TransactionException(org.neo4j.ogm.exception.TransactionException) ANY(de.fraunhofer.aisec.cpg.helpers.Util.Quantifier.ANY) Collectors(java.util.stream.Collectors) File(java.io.File) BinaryOperator(de.fraunhofer.aisec.cpg.graph.statements.expressions.BinaryOperator) Objects(java.util.Objects) Test(org.junit.jupiter.api.Test) ENTRIES(de.fraunhofer.aisec.cpg.helpers.Util.Edge.ENTRIES) TranslationException(de.fraunhofer.aisec.cpg.frontends.TranslationException) List(java.util.List) IVisitor(de.fraunhofer.aisec.cpg.processing.IVisitor) Stream(java.util.stream.Stream) de.fraunhofer.aisec.cpg.graph.statements(de.fraunhofer.aisec.cpg.graph.statements) Assertions(org.junit.jupiter.api.Assertions) TranslationUnitDeclaration(de.fraunhofer.aisec.cpg.graph.declarations.TranslationUnitDeclaration) CallExpression(de.fraunhofer.aisec.cpg.graph.statements.expressions.CallExpression) FunctionDeclaration(de.fraunhofer.aisec.cpg.graph.declarations.FunctionDeclaration) CallExpression(de.fraunhofer.aisec.cpg.graph.statements.expressions.CallExpression) BaseTest(de.fraunhofer.aisec.cpg.BaseTest) Test(org.junit.jupiter.api.Test)

Aggregations

TransactionException (org.neo4j.ogm.exception.TransactionException)6 ClientException (org.neo4j.driver.exceptions.ClientException)2 ConnectionException (org.neo4j.ogm.exception.ConnectionException)2 CypherException (org.neo4j.ogm.exception.CypherException)2 BaseTest (de.fraunhofer.aisec.cpg.BaseTest)1 TestUtils (de.fraunhofer.aisec.cpg.TestUtils)1 TranslationException (de.fraunhofer.aisec.cpg.frontends.TranslationException)1 de.fraunhofer.aisec.cpg.graph (de.fraunhofer.aisec.cpg.graph)1 ConstructorDeclaration (de.fraunhofer.aisec.cpg.graph.declarations.ConstructorDeclaration)1 FunctionDeclaration (de.fraunhofer.aisec.cpg.graph.declarations.FunctionDeclaration)1 TranslationUnitDeclaration (de.fraunhofer.aisec.cpg.graph.declarations.TranslationUnitDeclaration)1 Properties (de.fraunhofer.aisec.cpg.graph.edge.Properties)1 PropertyEdge (de.fraunhofer.aisec.cpg.graph.edge.PropertyEdge)1 de.fraunhofer.aisec.cpg.graph.statements (de.fraunhofer.aisec.cpg.graph.statements)1 BinaryOperator (de.fraunhofer.aisec.cpg.graph.statements.expressions.BinaryOperator)1 CallExpression (de.fraunhofer.aisec.cpg.graph.statements.expressions.CallExpression)1 DeclaredReferenceExpression (de.fraunhofer.aisec.cpg.graph.statements.expressions.DeclaredReferenceExpression)1 NodeComparator (de.fraunhofer.aisec.cpg.helpers.NodeComparator)1 SubgraphWalker (de.fraunhofer.aisec.cpg.helpers.SubgraphWalker)1 Util (de.fraunhofer.aisec.cpg.helpers.Util)1