Search in sources :

Example 31 with KernelException

use of org.neo4j.exceptions.KernelException 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 32 with KernelException

use of org.neo4j.exceptions.KernelException in project neo4j by neo4j.

the class SchemaImpl method descriptorToDefinition.

private IndexDefinition descriptorToDefinition(final TokenRead tokenRead, IndexDescriptor index) {
    try {
        SchemaDescriptor schema = index.schema();
        int[] entityTokenIds = schema.getEntityTokenIds();
        boolean constraintIndex = index.isUnique();
        String[] propertyNames = PropertyNameUtils.getPropertyKeysOrThrow(tokenRead, index.schema().getPropertyIds());
        switch(schema.entityType()) {
            case NODE:
                Label[] labels = new Label[entityTokenIds.length];
                for (int i = 0; i < labels.length; i++) {
                    labels[i] = label(tokenRead.nodeLabelName(entityTokenIds[i]));
                }
                return new IndexDefinitionImpl(actions, index, labels, propertyNames, constraintIndex);
            case RELATIONSHIP:
                RelationshipType[] relTypes = new RelationshipType[entityTokenIds.length];
                for (int i = 0; i < relTypes.length; i++) {
                    relTypes[i] = withName(tokenRead.relationshipTypeName(entityTokenIds[i]));
                }
                return new IndexDefinitionImpl(actions, index, relTypes, propertyNames, constraintIndex);
            default:
                throw new IllegalArgumentException("Cannot create IndexDefinition for " + schema.entityType() + " entity-typed schema.");
        }
    } catch (KernelException e) {
        throw new RuntimeException(e);
    }
}
Also used : SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) RelationTypeSchemaDescriptor(org.neo4j.internal.schema.RelationTypeSchemaDescriptor) Label(org.neo4j.graphdb.Label) SchemaDescriptor.forLabel(org.neo4j.internal.schema.SchemaDescriptor.forLabel) RelationshipType(org.neo4j.graphdb.RelationshipType) InvalidTransactionTypeKernelException(org.neo4j.internal.kernel.api.exceptions.InvalidTransactionTypeKernelException) IndexNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException) TokenCapacityExceededKernelException(org.neo4j.internal.kernel.api.exceptions.schema.TokenCapacityExceededKernelException) SchemaKernelException(org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException) KernelException(org.neo4j.exceptions.KernelException)

Example 33 with KernelException

use of org.neo4j.exceptions.KernelException in project neo4j by neo4j.

the class Invocation method executeStatements.

private void executeStatements() {
    try {
        while (outputError == null) {
            memoryPool.reserveHeap(Statement.SHALLOW_SIZE);
            try {
                Statement statement = readStatement();
                if (statement == null) {
                    return;
                }
                executeStatement(statement);
            } finally {
                memoryPool.releaseHeap(Statement.SHALLOW_SIZE);
            }
        }
    } catch (InputFormatException e) {
        handleNeo4jError(Status.Request.InvalidFormat, e);
    } catch (KernelException | Neo4jException | AuthorizationViolationException | WriteOperationsNotAllowedException e) {
        handleNeo4jError(e.status(), e);
    } catch (DeadlockDetectedException e) {
        handleNeo4jError(Status.Transaction.DeadlockDetected, e);
    } catch (Exception e) {
        Throwable cause = e.getCause();
        if (cause instanceof Status.HasStatus) {
            handleNeo4jError(((Status.HasStatus) cause).status(), cause);
        } else {
            handleNeo4jError(Status.Statement.ExecutionFailed, e);
        }
    }
}
Also used : Status(org.neo4j.kernel.api.exceptions.Status) Statement(org.neo4j.server.http.cypher.format.api.Statement) DeadlockDetectedException(org.neo4j.kernel.DeadlockDetectedException) Neo4jException(org.neo4j.exceptions.Neo4jException) InputFormatException(org.neo4j.server.http.cypher.format.api.InputFormatException) QueryExecutionKernelException(org.neo4j.kernel.impl.query.QueryExecutionKernelException) Neo4jException(org.neo4j.exceptions.Neo4jException) WriteOperationsNotAllowedException(org.neo4j.graphdb.WriteOperationsNotAllowedException) KernelException(org.neo4j.exceptions.KernelException) InputFormatException(org.neo4j.server.http.cypher.format.api.InputFormatException) ConnectionException(org.neo4j.server.http.cypher.format.api.ConnectionException) AuthorizationViolationException(org.neo4j.graphdb.security.AuthorizationViolationException) InvalidSemanticsException(org.neo4j.exceptions.InvalidSemanticsException) DeadlockDetectedException(org.neo4j.kernel.DeadlockDetectedException) OutputFormatException(org.neo4j.server.http.cypher.format.api.OutputFormatException) WriteOperationsNotAllowedException(org.neo4j.graphdb.WriteOperationsNotAllowedException) QueryExecutionKernelException(org.neo4j.kernel.impl.query.QueryExecutionKernelException) KernelException(org.neo4j.exceptions.KernelException) AuthorizationViolationException(org.neo4j.graphdb.security.AuthorizationViolationException)

Example 34 with KernelException

use of org.neo4j.exceptions.KernelException in project neo4j by neo4j.

the class AllStoreHolder method countsForNodeInTxState.

private long countsForNodeInTxState(int labelId) {
    long count = 0;
    if (ktx.hasTxStateWithChanges()) {
        CountsDelta counts = new CountsDelta();
        try {
            TransactionState txState = ktx.txState();
            CursorContext cursorContext = ktx.cursorContext();
            try (var countingVisitor = new TransactionCountingStateVisitor(EMPTY, storageReader, txState, counts, cursorContext)) {
                txState.accept(countingVisitor);
            }
            if (counts.hasChanges()) {
                count += counts.nodeCount(labelId, cursorContext);
            }
        } catch (KernelException e) {
            throw new IllegalArgumentException("Unexpected error: " + e.getMessage());
        }
    }
    return count;
}
Also used : TransactionState(org.neo4j.kernel.api.txstate.TransactionState) CursorContext(org.neo4j.io.pagecache.context.CursorContext) CountsDelta(org.neo4j.storageengine.api.CountsDelta) IndexNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException) KernelException(org.neo4j.exceptions.KernelException) TransactionCountingStateVisitor(org.neo4j.storageengine.api.txstate.TransactionCountingStateVisitor)

Example 35 with KernelException

use of org.neo4j.exceptions.KernelException in project neo4j by neo4j.

the class AllStoreHolder method countsForRelationshipInTxState.

private long countsForRelationshipInTxState(int startLabelId, int typeId, int endLabelId) {
    long count = 0;
    if (ktx.hasTxStateWithChanges()) {
        CursorContext cursorContext = ktx.cursorContext();
        CountsDelta counts = new CountsDelta();
        try {
            TransactionState txState = ktx.txState();
            try (var countingVisitor = new TransactionCountingStateVisitor(EMPTY, storageReader, txState, counts, cursorContext)) {
                txState.accept(countingVisitor);
            }
            if (counts.hasChanges()) {
                count += counts.relationshipCount(startLabelId, typeId, endLabelId, cursorContext);
            }
        } catch (KernelException e) {
            throw new IllegalArgumentException("Unexpected error: " + e.getMessage());
        }
    }
    return count;
}
Also used : TransactionState(org.neo4j.kernel.api.txstate.TransactionState) CursorContext(org.neo4j.io.pagecache.context.CursorContext) CountsDelta(org.neo4j.storageengine.api.CountsDelta) IndexNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException) KernelException(org.neo4j.exceptions.KernelException) TransactionCountingStateVisitor(org.neo4j.storageengine.api.txstate.TransactionCountingStateVisitor)

Aggregations

KernelException (org.neo4j.exceptions.KernelException)58 IndexNotFoundKernelException (org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException)22 InvalidTransactionTypeKernelException (org.neo4j.internal.kernel.api.exceptions.InvalidTransactionTypeKernelException)21 SchemaKernelException (org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException)16 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)15 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)13 TokenCapacityExceededKernelException (org.neo4j.internal.kernel.api.exceptions.schema.TokenCapacityExceededKernelException)12 Test (org.junit.jupiter.api.Test)11 ProcedureException (org.neo4j.internal.kernel.api.exceptions.ProcedureException)10 PropertyKeyIdNotFoundKernelException (org.neo4j.internal.kernel.api.exceptions.PropertyKeyIdNotFoundKernelException)10 QueryExecutionKernelException (org.neo4j.kernel.impl.query.QueryExecutionKernelException)10 List (java.util.List)8 NotFoundException (org.neo4j.graphdb.NotFoundException)8 SchemaRead (org.neo4j.internal.kernel.api.SchemaRead)8 Arrays (java.util.Arrays)7 Collectors (java.util.stream.Collectors)7 ConstraintViolationException (org.neo4j.graphdb.ConstraintViolationException)7 EntityNotFoundException (org.neo4j.internal.kernel.api.exceptions.EntityNotFoundException)7 IllegalTokenNameException (org.neo4j.internal.kernel.api.exceptions.schema.IllegalTokenNameException)7 ArrayList (java.util.ArrayList)6