Search in sources :

Example 6 with QueryExecutionException

use of org.neo4j.graphdb.QueryExecutionException in project neo4j by neo4j.

the class AbstractConstraintCreationIT method shouldBeAbleToResolveConflictsAndRecreateConstraintAfterFailingToCreateItDueToConflict.

@Test
public void shouldBeAbleToResolveConflictsAndRecreateConstraintAfterFailingToCreateItDueToConflict() throws Exception {
    // given
    try (Transaction tx = db.beginTx()) {
        createOffendingDataInRunningTx(db);
        tx.success();
    }
    // when
    try (Transaction tx = db.beginTx()) {
        createConstraintInRunningTx(db, KEY, PROP);
        tx.success();
        fail("expected failure");
    } catch (QueryExecutionException e) {
        assertThat(e.getMessage(), startsWith("Unable to create CONSTRAINT"));
    }
    try (Transaction tx = db.beginTx()) {
        removeOffendingDataInRunningTx(db);
        tx.success();
    }
    // then - this should not fail
    SchemaWriteOperations statement = schemaWriteOperationsInNewTransaction();
    createConstraint(statement, descriptor);
    commit();
}
Also used : QueryExecutionException(org.neo4j.graphdb.QueryExecutionException) SchemaWriteOperations(org.neo4j.kernel.api.SchemaWriteOperations) Transaction(org.neo4j.graphdb.Transaction) Test(org.junit.Test)

Example 7 with QueryExecutionException

use of org.neo4j.graphdb.QueryExecutionException in project neo4j by neo4j.

the class DatabaseManagementServiceImpl method systemDatabaseExecute.

private void systemDatabaseExecute(String query, SystemDatabaseExecutionContext beforeCommitHook) {
    try {
        GraphDatabaseAPI database = (GraphDatabaseAPI) database(SYSTEM_DATABASE_NAME);
        try (InternalTransaction transaction = database.beginTransaction(KernelTransaction.Type.EXPLICIT, LoginContext.AUTH_DISABLED)) {
            transaction.execute(query);
            beforeCommitHook.accept(database, transaction);
            transaction.commit();
        }
    } catch (QueryExecutionException | KernelException e) {
        throw new DatabaseManagementException(e);
    }
}
Also used : QueryExecutionException(org.neo4j.graphdb.QueryExecutionException) DatabaseManagementException(org.neo4j.dbms.api.DatabaseManagementException) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) KernelException(org.neo4j.exceptions.KernelException)

Example 8 with QueryExecutionException

use of org.neo4j.graphdb.QueryExecutionException in project neo4j by neo4j.

the class FixturesTestIT method shouldHandleFixturesWithSyntaxErrorsGracefully.

@Test
void shouldHandleFixturesWithSyntaxErrorsGracefully() throws Exception {
    // Given two files in the root folder
    Path targetFolder = testDir.homePath();
    writeFixture(targetFolder.resolve("fixture1.cyp"), "this is not a valid cypher statement");
    // When
    try (Neo4j ignore = getServerBuilder(targetFolder).withFixture(targetFolder).build()) {
        fail("Should have thrown exception");
    } catch (QueryExecutionException e) {
        assertThat(e.getStatusCode()).isEqualTo("Neo.ClientError.Statement.SyntaxError");
    }
}
Also used : Path(java.nio.file.Path) QueryExecutionException(org.neo4j.graphdb.QueryExecutionException) Test(org.junit.jupiter.api.Test)

Example 9 with QueryExecutionException

use of org.neo4j.graphdb.QueryExecutionException in project neo4j by neo4j.

the class QueryRestartIT method queryThatModifiesDataAndSeesUnstableSnapshotShouldThrowException.

@Test
void queryThatModifiesDataAndSeesUnstableSnapshotShouldThrowException() {
    try (Transaction transaction = database.beginTx()) {
        QueryExecutionException e = assertThrows(QueryExecutionException.class, () -> transaction.execute("MATCH (n:toRetry) CREATE () RETURN n.c"));
        assertEquals("Unable to get clean data snapshot for query " + "'MATCH (n:toRetry) CREATE () RETURN n.c' that performs updates.", e.getMessage());
        transaction.commit();
    }
}
Also used : QueryExecutionException(org.neo4j.graphdb.QueryExecutionException) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Transaction(org.neo4j.graphdb.Transaction) Test(org.junit.jupiter.api.Test)

Aggregations

QueryExecutionException (org.neo4j.graphdb.QueryExecutionException)9 Transaction (org.neo4j.graphdb.Transaction)4 Test (org.junit.Test)3 Test (org.junit.jupiter.api.Test)3 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)3 Path (java.nio.file.Path)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 BoltQueryExecution (org.neo4j.bolt.dbapi.BoltQueryExecution)1 ResultSubscriber (org.neo4j.cypher.internal.javacompat.ResultSubscriber)1 DatabaseManagementException (org.neo4j.dbms.api.DatabaseManagementException)1 KernelException (org.neo4j.exceptions.KernelException)1 Neo4jException (org.neo4j.exceptions.Neo4jException)1 FabricException (org.neo4j.fabric.executor.FabricException)1 Schema (org.neo4j.graphdb.schema.Schema)1 SchemaWriteOperations (org.neo4j.kernel.api.SchemaWriteOperations)1 ConstraintValidationException (org.neo4j.kernel.api.exceptions.schema.ConstraintValidationException)1 EnterpriseSecurityContext (org.neo4j.kernel.enterprise.api.security.EnterpriseSecurityContext)1 GraphDatabaseFacade (org.neo4j.kernel.impl.factory.GraphDatabaseFacade)1 QueryExecutionKernelException (org.neo4j.kernel.impl.query.QueryExecutionKernelException)1 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)1