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);
}
}
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);
}
}
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);
}
}
}
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;
}
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;
}
Aggregations