Search in sources :

Example 1 with InvalidTransactionTypeKernelException

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);
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) TransactionFailureException(org.neo4j.graphdb.TransactionFailureException) InvalidTransactionTypeKernelException(org.neo4j.internal.kernel.api.exceptions.InvalidTransactionTypeKernelException) NotFoundException(org.neo4j.graphdb.NotFoundException) EntityNotFoundException(org.neo4j.internal.kernel.api.exceptions.EntityNotFoundException) ConstraintViolationException(org.neo4j.graphdb.ConstraintViolationException) 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 2 with InvalidTransactionTypeKernelException

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());
}
Also used : InvalidTransactionTypeKernelException(org.neo4j.internal.kernel.api.exceptions.InvalidTransactionTypeKernelException) Test(org.junit.jupiter.api.Test)

Example 3 with InvalidTransactionTypeKernelException

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);
    }
}
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 4 with InvalidTransactionTypeKernelException

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;
}
Also used : StorageReader(org.neo4j.storageengine.api.StorageReader) TransactionState(org.neo4j.kernel.api.txstate.TransactionState) InvalidTransactionTypeKernelException(org.neo4j.internal.kernel.api.exceptions.InvalidTransactionTypeKernelException) KernelTransactionImplementation(org.neo4j.kernel.impl.api.KernelTransactionImplementation) IndexPrototype(org.neo4j.internal.schema.IndexPrototype) Locks(org.neo4j.kernel.impl.locking.Locks) StorageEngine(org.neo4j.storageengine.api.StorageEngine)

Example 5 with InvalidTransactionTypeKernelException

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());
}
Also used : InvalidTransactionTypeKernelException(org.neo4j.internal.kernel.api.exceptions.InvalidTransactionTypeKernelException) Test(org.junit.jupiter.api.Test)

Aggregations

InvalidTransactionTypeKernelException (org.neo4j.internal.kernel.api.exceptions.InvalidTransactionTypeKernelException)7 KernelException (org.neo4j.exceptions.KernelException)4 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 PropertyKeyIdNotFoundKernelException (org.neo4j.internal.kernel.api.exceptions.PropertyKeyIdNotFoundKernelException)4 IllegalTokenNameException (org.neo4j.internal.kernel.api.exceptions.schema.IllegalTokenNameException)4 TokenCapacityExceededKernelException (org.neo4j.internal.kernel.api.exceptions.schema.TokenCapacityExceededKernelException)4 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)4 Test (org.junit.jupiter.api.Test)2 LabelNotFoundKernelException (org.neo4j.internal.kernel.api.exceptions.LabelNotFoundKernelException)2 IndexPrototype (org.neo4j.internal.schema.IndexPrototype)1 TransactionState (org.neo4j.kernel.api.txstate.TransactionState)1 KernelTransactionImplementation (org.neo4j.kernel.impl.api.KernelTransactionImplementation)1 Locks (org.neo4j.kernel.impl.locking.Locks)1 StorageEngine (org.neo4j.storageengine.api.StorageEngine)1 StorageReader (org.neo4j.storageengine.api.StorageReader)1