Search in sources :

Example 6 with EntityNotFoundException

use of org.neo4j.kernel.api.exceptions.EntityNotFoundException in project neo4j by neo4j.

the class RelationshipProxy method setProperty.

@Override
public void setProperty(String key, Object value) {
    try (Statement statement = actions.statement()) {
        int propertyKeyId = statement.tokenWriteOperations().propertyKeyGetOrCreateForName(key);
        statement.dataWriteOperations().relationshipSetProperty(getId(), Property.property(propertyKeyId, value));
    } catch (IllegalArgumentException e) {
        // Trying to set an illegal value is a critical error - fail this transaction
        actions.failTransaction();
        throw e;
    } catch (EntityNotFoundException e) {
        throw new NotFoundException(e);
    } catch (IllegalTokenNameException e) {
        // TODO: Maybe throw more context-specific error than just IllegalArgument
        throw new IllegalArgumentException(e);
    } catch (InvalidTransactionTypeKernelException e) {
        throw new ConstraintViolationException(e.getMessage(), e);
    } catch (AutoIndexingKernelException e) {
        throw new IllegalStateException("Auto indexing encountered a failure while setting property: " + e.getMessage(), e);
    }
}
Also used : Statement(org.neo4j.kernel.api.Statement) InvalidTransactionTypeKernelException(org.neo4j.kernel.api.exceptions.InvalidTransactionTypeKernelException) NotFoundException(org.neo4j.graphdb.NotFoundException) EntityNotFoundException(org.neo4j.kernel.api.exceptions.EntityNotFoundException) PropertyNotFoundException(org.neo4j.kernel.api.exceptions.PropertyNotFoundException) ConstraintViolationException(org.neo4j.graphdb.ConstraintViolationException) EntityNotFoundException(org.neo4j.kernel.api.exceptions.EntityNotFoundException) IllegalTokenNameException(org.neo4j.kernel.api.exceptions.schema.IllegalTokenNameException) AutoIndexingKernelException(org.neo4j.kernel.api.exceptions.legacyindex.AutoIndexingKernelException)

Example 7 with EntityNotFoundException

use of org.neo4j.kernel.api.exceptions.EntityNotFoundException in project neo4j by neo4j.

the class RelationshipProxy method getProperty.

@Override
public Object getProperty(String key) {
    if (null == key) {
        throw new IllegalArgumentException("(null) property key is not allowed");
    }
    try (Statement statement = actions.statement()) {
        try {
            int propertyId = statement.readOperations().propertyKeyGetForName(key);
            if (propertyId == KeyReadOperations.NO_SUCH_PROPERTY_KEY) {
                throw new NotFoundException(String.format("No such property, '%s'.", key));
            }
            Object value = statement.readOperations().relationshipGetProperty(getId(), propertyId);
            if (value == null) {
                throw new PropertyNotFoundException(propertyId, EntityType.RELATIONSHIP, getId());
            }
            return value;
        } catch (EntityNotFoundException | PropertyNotFoundException e) {
            throw new NotFoundException(e.getUserMessage(new StatementTokenNameLookup(statement.readOperations())), e);
        }
    }
}
Also used : PropertyNotFoundException(org.neo4j.kernel.api.exceptions.PropertyNotFoundException) StatementTokenNameLookup(org.neo4j.kernel.api.StatementTokenNameLookup) Statement(org.neo4j.kernel.api.Statement) NotFoundException(org.neo4j.graphdb.NotFoundException) EntityNotFoundException(org.neo4j.kernel.api.exceptions.EntityNotFoundException) PropertyNotFoundException(org.neo4j.kernel.api.exceptions.PropertyNotFoundException) EntityNotFoundException(org.neo4j.kernel.api.exceptions.EntityNotFoundException)

Example 8 with EntityNotFoundException

use of org.neo4j.kernel.api.exceptions.EntityNotFoundException in project neo4j by neo4j.

the class LegacyIndexProxy method putIfAbsent.

@Override
public T putIfAbsent(T entity, String key, Object value) {
    try (Statement statement = statementContextBridge.get()) {
        // Does it already exist?
        long existing = single(internalGet(key, value, statement), -1L);
        if (existing != -1) {
            return entityOf(existing);
        }
        // No, OK so Grab lock
        statement.readOperations().acquireExclusive(LEGACY_INDEX, legacyIndexResourceId(name, key));
        // and check again -- now holding an exclusive lock
        existing = single(internalGet(key, value, statement), -1L);
        if (existing != -1) {
            // Someone else created this entry before us just before we got the lock,
            // release the lock as we won't be needing it
            statement.readOperations().releaseExclusive(LEGACY_INDEX, legacyIndexResourceId(name, key));
            return entityOf(existing);
        }
        internalAdd(entity, key, value, statement);
        return null;
    } catch (EntityNotFoundException e) {
        throw new NotFoundException(format("%s %d not found", type, type.id(entity)), e);
    } catch (InvalidTransactionTypeKernelException e) {
        throw new ConstraintViolationException(e.getMessage(), e);
    } catch (LegacyIndexNotFoundKernelException e) {
        throw new RuntimeException(e);
    }
}
Also used : Statement(org.neo4j.kernel.api.Statement) InvalidTransactionTypeKernelException(org.neo4j.kernel.api.exceptions.InvalidTransactionTypeKernelException) LegacyIndexNotFoundKernelException(org.neo4j.kernel.api.exceptions.legacyindex.LegacyIndexNotFoundKernelException) NotFoundException(org.neo4j.graphdb.NotFoundException) EntityNotFoundException(org.neo4j.kernel.api.exceptions.EntityNotFoundException) ConstraintViolationException(org.neo4j.graphdb.ConstraintViolationException) EntityNotFoundException(org.neo4j.kernel.api.exceptions.EntityNotFoundException)

Example 9 with EntityNotFoundException

use of org.neo4j.kernel.api.exceptions.EntityNotFoundException in project neo4j by neo4j.

the class TxStateTransactionDataSnapshot method relationship.

private Relationship relationship(long relId) {
    RelationshipProxy relationship = new RelationshipProxy(relationshipActions, relId);
    if (!state.relationshipVisit(relId, relationship)) {
        // This relationship has been created or changed in this transaction
        RelationshipProxy cached = relationshipsReadFromStore.get(relId);
        if (cached != null) {
            return cached;
        }
        try {
            // Get this relationship data from the store
            store.relationshipVisit(relId, relationship);
            relationshipsReadFromStore.put(relId, relationship);
        } catch (EntityNotFoundException e) {
            throw new IllegalStateException("Getting deleted relationship data should have been covered by the tx state");
        }
    }
    return relationship;
}
Also used : RelationshipProxy(org.neo4j.kernel.impl.core.RelationshipProxy) EntityNotFoundException(org.neo4j.kernel.api.exceptions.EntityNotFoundException)

Example 10 with EntityNotFoundException

use of org.neo4j.kernel.api.exceptions.EntityNotFoundException in project neo4j by neo4j.

the class InternalAutoIndexOperations method propertyAdded.

@Override
public void propertyAdded(DataWriteOperations ops, long entityId, Property property) throws AutoIndexingKernelException {
    if (enabled) {
        try {
            String name = propertyKeyLookup.getTokenById(property.propertyKeyId()).name();
            if (propertyKeysToInclude.get().contains(name)) {
                ensureIndexExists(ops);
                type.add(ops, entityId, name, property.value());
            }
        } catch (LegacyIndexNotFoundKernelException | EntityNotFoundException | PropertyNotFoundException e) {
            throw new AutoIndexingKernelException(e);
        } catch (TokenNotFoundException e) {
            // KernelException now
            throw new AutoIndexingKernelException(new PropertyKeyIdNotFoundKernelException(property.propertyKeyId(), e));
        }
    }
}
Also used : PropertyNotFoundException(org.neo4j.kernel.api.exceptions.PropertyNotFoundException) LegacyIndexNotFoundKernelException(org.neo4j.kernel.api.exceptions.legacyindex.LegacyIndexNotFoundKernelException) EntityNotFoundException(org.neo4j.kernel.api.exceptions.EntityNotFoundException) TokenNotFoundException(org.neo4j.kernel.impl.core.TokenNotFoundException) AutoIndexingKernelException(org.neo4j.kernel.api.exceptions.legacyindex.AutoIndexingKernelException) PropertyKeyIdNotFoundKernelException(org.neo4j.kernel.api.exceptions.PropertyKeyIdNotFoundKernelException)

Aggregations

EntityNotFoundException (org.neo4j.kernel.api.exceptions.EntityNotFoundException)30 Statement (org.neo4j.kernel.api.Statement)20 NotFoundException (org.neo4j.graphdb.NotFoundException)14 PropertyNotFoundException (org.neo4j.kernel.api.exceptions.PropertyNotFoundException)14 PropertyKeyIdNotFoundKernelException (org.neo4j.kernel.api.exceptions.PropertyKeyIdNotFoundKernelException)7 Test (org.junit.Test)5 AutoIndexingKernelException (org.neo4j.kernel.api.exceptions.legacyindex.AutoIndexingKernelException)5 LegacyIndexNotFoundKernelException (org.neo4j.kernel.api.exceptions.legacyindex.LegacyIndexNotFoundKernelException)5 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)4 ConstraintViolationException (org.neo4j.graphdb.ConstraintViolationException)3 Node (org.neo4j.graphdb.Node)3 Transaction (org.neo4j.graphdb.Transaction)3 InvalidTransactionTypeKernelException (org.neo4j.kernel.api.exceptions.InvalidTransactionTypeKernelException)3 TokenNotFoundException (org.neo4j.kernel.impl.core.TokenNotFoundException)3 NodeItem (org.neo4j.storageengine.api.NodeItem)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 PrimitiveIntIterator (org.neo4j.collection.primitive.PrimitiveIntIterator)2 ReadOperations (org.neo4j.kernel.api.ReadOperations)2 StatementTokenNameLookup (org.neo4j.kernel.api.StatementTokenNameLookup)2