use of org.neo4j.internal.kernel.api.exceptions.InvalidTransactionTypeKernelException in project neo4j by neo4j.
the class NodeEntity method removeProperty.
@Override
public Object removeProperty(String key) throws NotFoundException {
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().nodeRemoveProperty(nodeId, propertyKeyId).asObjectCopy();
} catch (EntityNotFoundException e) {
throw new NotFoundException(e);
} catch (InvalidTransactionTypeKernelException e) {
throw new ConstraintViolationException(e.getMessage(), e);
}
}
use of org.neo4j.internal.kernel.api.exceptions.InvalidTransactionTypeKernelException in project neo4j by neo4j.
the class TransactionStatementSequenceTest method shouldRejectSchemaStatementAfterDataStatement.
@Test
void shouldRejectSchemaStatementAfterDataStatement() throws Exception {
// given
KernelTransaction tx = kernelTransaction(AUTH_DISABLED);
tx.dataWrite();
// when
InvalidTransactionTypeKernelException exception = assertThrows(InvalidTransactionTypeKernelException.class, tx::schemaWrite);
assertEquals("Cannot perform schema updates in a transaction that has performed data updates.", exception.getMessage());
}
use of org.neo4j.internal.kernel.api.exceptions.InvalidTransactionTypeKernelException 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.internal.kernel.api.exceptions.InvalidTransactionTypeKernelException in project neo4j by neo4j.
the class ConstraintIndexCreatorTest method createTransaction.
private KernelTransactionImplementation createTransaction() {
KernelTransactionImplementation transaction = mock(KernelTransactionImplementation.class);
try {
StorageEngine storageEngine = mock(StorageEngine.class);
StorageReader storageReader = mock(StorageReader.class);
when(storageEngine.newReader()).thenReturn(storageReader);
Locks.Client locks = mock(Locks.Client.class);
when(transaction.lockClient()).thenReturn(locks);
when(transaction.tokenRead()).thenReturn(tokenRead);
when(transaction.schemaRead()).thenReturn(schemaRead);
when(transaction.schemaWrite()).thenReturn(schemaWrite);
TransactionState transactionState = mock(TransactionState.class);
when(transaction.txState()).thenReturn(transactionState);
when(transaction.indexUniqueCreate(any(IndexPrototype.class))).thenAnswer(i -> i.<IndexPrototype>getArgument(0).materialise(INDEX_ID));
when(transaction.newStorageReader()).thenReturn(mock(StorageReader.class));
} catch (InvalidTransactionTypeKernelException e) {
fail("Expected write transaction");
}
return transaction;
}
use of org.neo4j.internal.kernel.api.exceptions.InvalidTransactionTypeKernelException in project neo4j by neo4j.
the class TransactionStatementSequenceTest method shouldRejectDataStatementAfterSchemaStatement.
@Test
void shouldRejectDataStatementAfterSchemaStatement() throws Exception {
// given
KernelTransaction tx = kernelTransaction(AUTH_DISABLED);
tx.schemaWrite();
// when
InvalidTransactionTypeKernelException exception = assertThrows(InvalidTransactionTypeKernelException.class, tx::dataWrite);
assertEquals("Cannot perform data updates in a transaction that has performed schema updates.", exception.getMessage());
}
Aggregations