Search in sources :

Example 16 with EntityNotFoundException

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

the class InternalAutoIndexOperations method propertyChanged.

@Override
public void propertyChanged(DataWriteOperations ops, long entityId, Property oldProperty, Property newProperty) throws AutoIndexingKernelException {
    if (enabled) {
        try {
            String name = propertyKeyLookup.getTokenById(oldProperty.propertyKeyId()).name();
            if (propertyKeysToInclude.get().contains(name)) {
                ensureIndexExists(ops);
                type.remove(ops, entityId, name, oldProperty.value());
                type.add(ops, entityId, name, newProperty.value());
            }
        } catch (LegacyIndexNotFoundKernelException | EntityNotFoundException | PropertyNotFoundException e) {
            throw new AutoIndexingKernelException(e);
        } catch (TokenNotFoundException e) {
            // KernelException now
            throw new AutoIndexingKernelException(new PropertyKeyIdNotFoundKernelException(oldProperty.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)

Example 17 with EntityNotFoundException

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

the class NodeProxy method getProperty.

@Override
public Object getProperty(String key, Object defaultValue) {
    if (null == key) {
        throw new IllegalArgumentException("(null) property key is not allowed");
    }
    try (Statement statement = actions.statement()) {
        int propertyKeyId = statement.readOperations().propertyKeyGetForName(key);
        Object value = statement.readOperations().nodeGetProperty(nodeId, propertyKeyId);
        return value == null ? defaultValue : value;
    } catch (EntityNotFoundException e) {
        throw new NotFoundException(e);
    }
}
Also used : 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 18 with EntityNotFoundException

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

the class NodeProxy method createRelationshipTo.

@Override
public Relationship createRelationshipTo(Node otherNode, RelationshipType type) {
    if (otherNode == null) {
        throw new IllegalArgumentException("Other node is null.");
    }
    //}
    try (Statement statement = actions.statement()) {
        int relationshipTypeId = statement.tokenWriteOperations().relationshipTypeGetOrCreateForName(type.name());
        long relationshipId = statement.dataWriteOperations().relationshipCreate(relationshipTypeId, nodeId, otherNode.getId());
        return actions.newRelationshipProxy(relationshipId, nodeId, relationshipTypeId, otherNode.getId());
    } catch (IllegalTokenNameException | RelationshipTypeIdNotFoundKernelException e) {
        throw new IllegalArgumentException(e);
    } catch (EntityNotFoundException e) {
        throw new NotFoundException("Node[" + e.entityId() + "] is deleted and cannot be used to create a relationship");
    } catch (InvalidTransactionTypeKernelException e) {
        throw new ConstraintViolationException(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) RelationshipTypeIdNotFoundKernelException(org.neo4j.kernel.api.exceptions.RelationshipTypeIdNotFoundKernelException) EntityNotFoundException(org.neo4j.kernel.api.exceptions.EntityNotFoundException) IllegalTokenNameException(org.neo4j.kernel.api.exceptions.schema.IllegalTokenNameException)

Example 19 with EntityNotFoundException

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

the class NodeProxy method getDegree.

@Override
public int getDegree(RelationshipType type, Direction direction) {
    try (Statement statement = actions.statement()) {
        ReadOperations ops = statement.readOperations();
        int typeId = ops.relationshipTypeGetForName(type.name());
        if (typeId == NO_ID) {
            // This type doesn't even exist. Return 0
            return 0;
        }
        return ops.nodeGetDegree(nodeId, direction, typeId);
    } catch (EntityNotFoundException e) {
        throw new NotFoundException("Node not found.", e);
    }
}
Also used : ReadOperations(org.neo4j.kernel.api.ReadOperations) KeyReadOperations(org.neo4j.kernel.impl.api.operations.KeyReadOperations) 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 20 with EntityNotFoundException

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

the class NodeProxy method getPropertyKeys.

@Override
public Iterable<String> getPropertyKeys() {
    try (Statement statement = actions.statement()) {
        List<String> keys = new ArrayList<>();
        PrimitiveIntIterator properties = statement.readOperations().nodeGetPropertyKeys(getId());
        while (properties.hasNext()) {
            keys.add(statement.readOperations().propertyKeyGetName(properties.next()));
        }
        return keys;
    } catch (EntityNotFoundException e) {
        throw new NotFoundException("Node not found", e);
    } catch (PropertyKeyIdNotFoundKernelException e) {
        throw new IllegalStateException("Property key retrieved through kernel API should exist.", e);
    }
}
Also used : Statement(org.neo4j.kernel.api.Statement) ArrayList(java.util.ArrayList) NotFoundException(org.neo4j.graphdb.NotFoundException) EntityNotFoundException(org.neo4j.kernel.api.exceptions.EntityNotFoundException) PropertyNotFoundException(org.neo4j.kernel.api.exceptions.PropertyNotFoundException) PrimitiveIntIterator(org.neo4j.collection.primitive.PrimitiveIntIterator) EntityNotFoundException(org.neo4j.kernel.api.exceptions.EntityNotFoundException) 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