Search in sources :

Example 56 with TransactionFailureException

use of org.neo4j.graphdb.TransactionFailureException 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)

Example 57 with TransactionFailureException

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

the class RelationshipEntity method removeProperty.

@Override
public Object removeProperty(String key) {
    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 (KernelException e) {
        throw new TransactionFailureException("Unknown error trying to get property key token", e);
    }
    try {
        return transaction.dataWrite().relationshipRemoveProperty(id, propertyKeyId).asObjectCopy();
    } catch (InvalidTransactionTypeKernelException e) {
        throw new ConstraintViolationException(e.getMessage(), e);
    } catch (EntityNotFoundException e) {
        throw new NotFoundException(e);
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) TransactionFailureException(org.neo4j.graphdb.TransactionFailureException) InvalidTransactionTypeKernelException(org.neo4j.internal.kernel.api.exceptions.InvalidTransactionTypeKernelException) ConstraintViolationException(org.neo4j.graphdb.ConstraintViolationException) NotFoundException(org.neo4j.graphdb.NotFoundException) EntityNotFoundException(org.neo4j.internal.kernel.api.exceptions.EntityNotFoundException) EntityNotFoundException(org.neo4j.internal.kernel.api.exceptions.EntityNotFoundException) IllegalTokenNameException(org.neo4j.internal.kernel.api.exceptions.schema.IllegalTokenNameException) 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) KernelException(org.neo4j.exceptions.KernelException)

Aggregations

TransactionFailureException (org.neo4j.graphdb.TransactionFailureException)57 Transaction (org.neo4j.graphdb.Transaction)17 NotFoundException (org.neo4j.graphdb.NotFoundException)9 Node (org.neo4j.graphdb.Node)8 Test (org.junit.Test)7 ConstraintViolationException (org.neo4j.graphdb.ConstraintViolationException)7 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)7 LinkedList (java.util.LinkedList)6 SystemException (javax.transaction.SystemException)6 XAException (javax.transaction.xa.XAException)6 XAResource (javax.transaction.xa.XAResource)6 KernelException (org.neo4j.exceptions.KernelException)6 EntityNotFoundException (org.neo4j.internal.kernel.api.exceptions.EntityNotFoundException)6 InvalidTransactionTypeKernelException (org.neo4j.internal.kernel.api.exceptions.InvalidTransactionTypeKernelException)6 PropertyKeyIdNotFoundKernelException (org.neo4j.internal.kernel.api.exceptions.PropertyKeyIdNotFoundKernelException)6 IllegalTokenNameException (org.neo4j.internal.kernel.api.exceptions.schema.IllegalTokenNameException)6 TokenCapacityExceededKernelException (org.neo4j.internal.kernel.api.exceptions.schema.TokenCapacityExceededKernelException)6 XaDataSource (org.neo4j.kernel.impl.transaction.xaframework.XaDataSource)6 XaResource (org.neo4j.kernel.impl.transaction.xaframework.XaResource)6 IOException (java.io.IOException)5