Search in sources :

Example 1 with TokenCapacityExceededKernelException

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

the class EntityTest method mockedTransactionWithDepletedTokens.

InternalTransaction mockedTransactionWithDepletedTokens() throws KernelException {
    var internalTransaction = mock(InternalTransaction.class);
    var ktx = mock(KernelTransaction.class);
    var tokenWrite = mock(TokenWrite.class);
    when(ktx.tokenWrite()).thenReturn(tokenWrite);
    when(tokenWrite.labelGetOrCreateForName(any())).thenThrow(new TokenCapacityExceededKernelException(new Exception("Just some cause"), TokenHolder.TYPE_LABEL));
    when(tokenWrite.propertyKeyGetOrCreateForName(any())).thenThrow(new TokenCapacityExceededKernelException(new Exception("Just some cause"), TokenHolder.TYPE_PROPERTY_KEY));
    when(tokenWrite.relationshipTypeGetOrCreateForName(any())).thenThrow(new TokenCapacityExceededKernelException(new Exception("Just some cause"), TokenHolder.TYPE_RELATIONSHIP_TYPE));
    when(internalTransaction.kernelTransaction()).thenReturn(ktx);
    return internalTransaction;
}
Also used : TokenCapacityExceededKernelException(org.neo4j.internal.kernel.api.exceptions.schema.TokenCapacityExceededKernelException) KernelException(org.neo4j.exceptions.KernelException) TokenCapacityExceededKernelException(org.neo4j.internal.kernel.api.exceptions.schema.TokenCapacityExceededKernelException)

Example 2 with TokenCapacityExceededKernelException

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

the class RelationshipEntity 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().relationshipSetProperty(id, propertyKeyId, Values.of(value, false));
    } 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 (InvalidTransactionTypeKernelException e) {
        throw new ConstraintViolationException(e.getMessage(), e);
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) InvalidTransactionTypeKernelException(org.neo4j.internal.kernel.api.exceptions.InvalidTransactionTypeKernelException) 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) KernelException(org.neo4j.exceptions.KernelException)

Example 3 with TokenCapacityExceededKernelException

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

the class NodeEntity method createRelationshipTo.

@Override
public Relationship createRelationshipTo(Node otherNode, RelationshipType type) {
    if (otherNode == null) {
        throw new IllegalArgumentException("Other node is null.");
    }
    KernelTransaction transaction = internalTransaction.kernelTransaction();
    int relationshipTypeId;
    try {
        relationshipTypeId = transaction.tokenWrite().relationshipTypeGetOrCreateForName(type.name());
    } catch (IllegalTokenNameException e) {
        throw new IllegalArgumentException(e);
    } catch (TokenCapacityExceededKernelException e) {
        throw new ConstraintViolationException(e.getMessage(), e);
    } catch (KernelException e) {
        throw new TransactionFailureException("Unknown error trying to create relationship type token", e);
    }
    try {
        long relationshipId = transaction.dataWrite().relationshipCreate(nodeId, relationshipTypeId, otherNode.getId());
        return internalTransaction.newRelationshipEntity(relationshipId, nodeId, relationshipTypeId, otherNode.getId());
    } 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 : 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) 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) 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 4 with TokenCapacityExceededKernelException

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

the class NodeEntity method addLabel.

@Override
public void addLabel(Label label) {
    KernelTransaction transaction = internalTransaction.kernelTransaction();
    int labelId;
    try {
        labelId = transaction.tokenWrite().labelGetOrCreateForName(label.name());
    } catch (IllegalTokenNameException e) {
        throw new ConstraintViolationException(format("Invalid label name '%s'.", label.name()), e);
    } catch (TokenCapacityExceededKernelException e) {
        throw new ConstraintViolationException(e.getMessage(), e);
    } catch (KernelException e) {
        throw new TransactionFailureException("Unknown error trying to create label token", e);
    }
    try {
        transaction.dataWrite().nodeAddLabel(getId(), labelId);
    } catch (ConstraintValidationException e) {
        throw new ConstraintViolationException(e.getUserMessage(transaction.tokenRead()), e);
    } catch (EntityNotFoundException e) {
        throw new NotFoundException("No node with id " + getId() + " found.", e);
    } catch (KernelException e) {
        throw new ConstraintViolationException(e.getMessage(), e);
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) TransactionFailureException(org.neo4j.graphdb.TransactionFailureException) ConstraintValidationException(org.neo4j.internal.kernel.api.exceptions.schema.ConstraintValidationException) ConstraintViolationException(org.neo4j.graphdb.ConstraintViolationException) 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) 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 5 with TokenCapacityExceededKernelException

use of org.neo4j.internal.kernel.api.exceptions.schema.TokenCapacityExceededKernelException 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

KernelException (org.neo4j.exceptions.KernelException)5 TokenCapacityExceededKernelException (org.neo4j.internal.kernel.api.exceptions.schema.TokenCapacityExceededKernelException)5 ConstraintViolationException (org.neo4j.graphdb.ConstraintViolationException)4 NotFoundException (org.neo4j.graphdb.NotFoundException)4 TransactionFailureException (org.neo4j.graphdb.TransactionFailureException)4 EntityNotFoundException (org.neo4j.internal.kernel.api.exceptions.EntityNotFoundException)4 InvalidTransactionTypeKernelException (org.neo4j.internal.kernel.api.exceptions.InvalidTransactionTypeKernelException)4 PropertyKeyIdNotFoundKernelException (org.neo4j.internal.kernel.api.exceptions.PropertyKeyIdNotFoundKernelException)4 IllegalTokenNameException (org.neo4j.internal.kernel.api.exceptions.schema.IllegalTokenNameException)4 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)4 LabelNotFoundKernelException (org.neo4j.internal.kernel.api.exceptions.LabelNotFoundKernelException)3 ConstraintValidationException (org.neo4j.internal.kernel.api.exceptions.schema.ConstraintValidationException)2