Search in sources :

Example 6 with ConstraintValidationException

use of org.neo4j.internal.kernel.api.exceptions.schema.ConstraintValidationException in project neo4j by neo4j.

the class NodeEntity method setProperty.

@Override
public void setProperty(String key, Object value) {
    KernelTransaction transaction = internalTransaction.kernelTransaction();
    int propertyKeyId;
    try {
        propertyKeyId = transaction.tokenWrite().propertyKeyGetOrCreateForName(key);
    } catch (IllegalTokenNameException e) {
        throw new IllegalArgumentException(format("Invalid property key '%s'.", key), e);
    } catch (TokenCapacityExceededKernelException e) {
        throw new ConstraintViolationException(e.getMessage(), e);
    } catch (KernelException e) {
        throw new TransactionFailureException("Unknown error trying to create property key token", e);
    }
    try {
        transaction.dataWrite().nodeSetProperty(nodeId, propertyKeyId, Values.of(value, false));
    } catch (ConstraintValidationException e) {
        throw new ConstraintViolationException(e.getUserMessage(transaction.tokenRead()), e);
    } catch (IllegalArgumentException e) {
        try {
            transaction.rollback();
        } catch (org.neo4j.internal.kernel.api.exceptions.TransactionFailureException ex) {
            ex.addSuppressed(e);
            throw new TransactionFailureException("Fail to rollback transaction.", ex);
        }
        throw e;
    } catch (EntityNotFoundException e) {
        throw new NotFoundException(e);
    } catch (KernelException e) {
        throw new ConstraintViolationException(e.getMessage(), e);
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) ConstraintValidationException(org.neo4j.internal.kernel.api.exceptions.schema.ConstraintValidationException) NotFoundException(org.neo4j.graphdb.NotFoundException) EntityNotFoundException(org.neo4j.internal.kernel.api.exceptions.EntityNotFoundException) TokenCapacityExceededKernelException(org.neo4j.internal.kernel.api.exceptions.schema.TokenCapacityExceededKernelException) EntityNotFoundException(org.neo4j.internal.kernel.api.exceptions.EntityNotFoundException) IllegalTokenNameException(org.neo4j.internal.kernel.api.exceptions.schema.IllegalTokenNameException) TransactionFailureException(org.neo4j.graphdb.TransactionFailureException) ConstraintViolationException(org.neo4j.graphdb.ConstraintViolationException) PropertyKeyIdNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.PropertyKeyIdNotFoundKernelException) InvalidTransactionTypeKernelException(org.neo4j.internal.kernel.api.exceptions.InvalidTransactionTypeKernelException) TokenCapacityExceededKernelException(org.neo4j.internal.kernel.api.exceptions.schema.TokenCapacityExceededKernelException) LabelNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.LabelNotFoundKernelException) KernelException(org.neo4j.exceptions.KernelException)

Aggregations

ConstraintValidationException (org.neo4j.internal.kernel.api.exceptions.schema.ConstraintValidationException)6 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)4 KernelException (org.neo4j.exceptions.KernelException)3 ConstraintViolationException (org.neo4j.graphdb.ConstraintViolationException)3 InvalidTransactionTypeKernelException (org.neo4j.internal.kernel.api.exceptions.InvalidTransactionTypeKernelException)3 Test (org.junit.jupiter.api.Test)2 Node (org.neo4j.graphdb.Node)2 NotFoundException (org.neo4j.graphdb.NotFoundException)2 TransactionFailureException (org.neo4j.graphdb.TransactionFailureException)2 NodeCursor (org.neo4j.internal.kernel.api.NodeCursor)2 EntityNotFoundException (org.neo4j.internal.kernel.api.exceptions.EntityNotFoundException)2 LabelNotFoundKernelException (org.neo4j.internal.kernel.api.exceptions.LabelNotFoundKernelException)2 PropertyKeyIdNotFoundKernelException (org.neo4j.internal.kernel.api.exceptions.PropertyKeyIdNotFoundKernelException)2 IllegalTokenNameException (org.neo4j.internal.kernel.api.exceptions.schema.IllegalTokenNameException)2 TokenCapacityExceededKernelException (org.neo4j.internal.kernel.api.exceptions.schema.TokenCapacityExceededKernelException)2 TransientFailureException (org.neo4j.graphdb.TransientFailureException)1 PropertyCursor (org.neo4j.internal.kernel.api.PropertyCursor)1 TokenWrite (org.neo4j.internal.kernel.api.TokenWrite)1 Write (org.neo4j.internal.kernel.api.Write)1 ConstraintViolationTransactionFailureException (org.neo4j.internal.kernel.api.exceptions.ConstraintViolationTransactionFailureException)1