Search in sources :

Example 1 with InvalidTransactionTypeKernelException

use of org.neo4j.kernel.api.exceptions.InvalidTransactionTypeKernelException in project neo4j by neo4j.

the class RelationshipProxy method setProperty.

@Override
public void setProperty(String key, Object value) {
    try (Statement statement = actions.statement()) {
        int propertyKeyId = statement.tokenWriteOperations().propertyKeyGetOrCreateForName(key);
        statement.dataWriteOperations().relationshipSetProperty(getId(), Property.property(propertyKeyId, value));
    } catch (IllegalArgumentException e) {
        // Trying to set an illegal value is a critical error - fail this transaction
        actions.failTransaction();
        throw e;
    } catch (EntityNotFoundException e) {
        throw new NotFoundException(e);
    } catch (IllegalTokenNameException e) {
        // TODO: Maybe throw more context-specific error than just IllegalArgument
        throw new IllegalArgumentException(e);
    } catch (InvalidTransactionTypeKernelException e) {
        throw new ConstraintViolationException(e.getMessage(), e);
    } catch (AutoIndexingKernelException e) {
        throw new IllegalStateException("Auto indexing encountered a failure while setting property: " + e.getMessage(), e);
    }
}
Also used : Statement(org.neo4j.kernel.api.Statement) InvalidTransactionTypeKernelException(org.neo4j.kernel.api.exceptions.InvalidTransactionTypeKernelException) NotFoundException(org.neo4j.graphdb.NotFoundException) EntityNotFoundException(org.neo4j.kernel.api.exceptions.EntityNotFoundException) PropertyNotFoundException(org.neo4j.kernel.api.exceptions.PropertyNotFoundException) ConstraintViolationException(org.neo4j.graphdb.ConstraintViolationException) EntityNotFoundException(org.neo4j.kernel.api.exceptions.EntityNotFoundException) IllegalTokenNameException(org.neo4j.kernel.api.exceptions.schema.IllegalTokenNameException) AutoIndexingKernelException(org.neo4j.kernel.api.exceptions.legacyindex.AutoIndexingKernelException)

Example 2 with InvalidTransactionTypeKernelException

use of org.neo4j.kernel.api.exceptions.InvalidTransactionTypeKernelException in project neo4j by neo4j.

the class LegacyIndexProxy method putIfAbsent.

@Override
public T putIfAbsent(T entity, String key, Object value) {
    try (Statement statement = statementContextBridge.get()) {
        // Does it already exist?
        long existing = single(internalGet(key, value, statement), -1L);
        if (existing != -1) {
            return entityOf(existing);
        }
        // No, OK so Grab lock
        statement.readOperations().acquireExclusive(LEGACY_INDEX, legacyIndexResourceId(name, key));
        // and check again -- now holding an exclusive lock
        existing = single(internalGet(key, value, statement), -1L);
        if (existing != -1) {
            // Someone else created this entry before us just before we got the lock,
            // release the lock as we won't be needing it
            statement.readOperations().releaseExclusive(LEGACY_INDEX, legacyIndexResourceId(name, key));
            return entityOf(existing);
        }
        internalAdd(entity, key, value, statement);
        return null;
    } catch (EntityNotFoundException e) {
        throw new NotFoundException(format("%s %d not found", type, type.id(entity)), e);
    } catch (InvalidTransactionTypeKernelException e) {
        throw new ConstraintViolationException(e.getMessage(), e);
    } catch (LegacyIndexNotFoundKernelException e) {
        throw new RuntimeException(e);
    }
}
Also used : Statement(org.neo4j.kernel.api.Statement) InvalidTransactionTypeKernelException(org.neo4j.kernel.api.exceptions.InvalidTransactionTypeKernelException) LegacyIndexNotFoundKernelException(org.neo4j.kernel.api.exceptions.legacyindex.LegacyIndexNotFoundKernelException) NotFoundException(org.neo4j.graphdb.NotFoundException) EntityNotFoundException(org.neo4j.kernel.api.exceptions.EntityNotFoundException) ConstraintViolationException(org.neo4j.graphdb.ConstraintViolationException) EntityNotFoundException(org.neo4j.kernel.api.exceptions.EntityNotFoundException)

Example 3 with InvalidTransactionTypeKernelException

use of org.neo4j.kernel.api.exceptions.InvalidTransactionTypeKernelException in project neo4j by neo4j.

the class KernelTest method shouldNotAllowCreationOfConstraintsWhenInHA.

@Test
public void shouldNotAllowCreationOfConstraintsWhenInHA() throws Exception {
    //noinspection deprecation
    GraphDatabaseAPI db = new FakeHaDatabase();
    ThreadToStatementContextBridge stmtBridge = db.getDependencyResolver().resolveDependency(ThreadToStatementContextBridge.class);
    try (Transaction ignored = db.beginTx()) {
        Statement statement = stmtBridge.get();
        try {
            statement.schemaWriteOperations().uniquePropertyConstraintCreate(forLabel(1, 1));
            fail("expected exception here");
        } catch (InvalidTransactionTypeKernelException e) {
            assertThat(e.getMessage(), containsString("HA"));
        }
    }
    db.shutdown();
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Transaction(org.neo4j.graphdb.Transaction) Statement(org.neo4j.kernel.api.Statement) InvalidTransactionTypeKernelException(org.neo4j.kernel.api.exceptions.InvalidTransactionTypeKernelException) ThreadToStatementContextBridge(org.neo4j.kernel.impl.core.ThreadToStatementContextBridge) Test(org.junit.Test)

Example 4 with InvalidTransactionTypeKernelException

use of org.neo4j.kernel.api.exceptions.InvalidTransactionTypeKernelException in project neo4j by neo4j.

the class NodeProxy method createRelationshipTo.

@Override
public Relationship createRelationshipTo(Node otherNode, RelationshipType type) {
    if (otherNode == null) {
        throw new IllegalArgumentException("Other node is null.");
    }
    //}
    try (Statement statement = actions.statement()) {
        int relationshipTypeId = statement.tokenWriteOperations().relationshipTypeGetOrCreateForName(type.name());
        long relationshipId = statement.dataWriteOperations().relationshipCreate(relationshipTypeId, nodeId, otherNode.getId());
        return actions.newRelationshipProxy(relationshipId, nodeId, relationshipTypeId, otherNode.getId());
    } catch (IllegalTokenNameException | RelationshipTypeIdNotFoundKernelException e) {
        throw new IllegalArgumentException(e);
    } catch (EntityNotFoundException e) {
        throw new NotFoundException("Node[" + e.entityId() + "] is deleted and cannot be used to create a relationship");
    } catch (InvalidTransactionTypeKernelException e) {
        throw new ConstraintViolationException(e.getMessage(), e);
    }
}
Also used : Statement(org.neo4j.kernel.api.Statement) InvalidTransactionTypeKernelException(org.neo4j.kernel.api.exceptions.InvalidTransactionTypeKernelException) NotFoundException(org.neo4j.graphdb.NotFoundException) EntityNotFoundException(org.neo4j.kernel.api.exceptions.EntityNotFoundException) PropertyNotFoundException(org.neo4j.kernel.api.exceptions.PropertyNotFoundException) ConstraintViolationException(org.neo4j.graphdb.ConstraintViolationException) RelationshipTypeIdNotFoundKernelException(org.neo4j.kernel.api.exceptions.RelationshipTypeIdNotFoundKernelException) EntityNotFoundException(org.neo4j.kernel.api.exceptions.EntityNotFoundException) IllegalTokenNameException(org.neo4j.kernel.api.exceptions.schema.IllegalTokenNameException)

Aggregations

Statement (org.neo4j.kernel.api.Statement)4 InvalidTransactionTypeKernelException (org.neo4j.kernel.api.exceptions.InvalidTransactionTypeKernelException)4 ConstraintViolationException (org.neo4j.graphdb.ConstraintViolationException)3 NotFoundException (org.neo4j.graphdb.NotFoundException)3 EntityNotFoundException (org.neo4j.kernel.api.exceptions.EntityNotFoundException)3 PropertyNotFoundException (org.neo4j.kernel.api.exceptions.PropertyNotFoundException)2 IllegalTokenNameException (org.neo4j.kernel.api.exceptions.schema.IllegalTokenNameException)2 Test (org.junit.Test)1 Transaction (org.neo4j.graphdb.Transaction)1 RelationshipTypeIdNotFoundKernelException (org.neo4j.kernel.api.exceptions.RelationshipTypeIdNotFoundKernelException)1 AutoIndexingKernelException (org.neo4j.kernel.api.exceptions.legacyindex.AutoIndexingKernelException)1 LegacyIndexNotFoundKernelException (org.neo4j.kernel.api.exceptions.legacyindex.LegacyIndexNotFoundKernelException)1 ThreadToStatementContextBridge (org.neo4j.kernel.impl.core.ThreadToStatementContextBridge)1 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)1