Search in sources :

Example 11 with EntityNotFoundException

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

the class InternalAutoIndexOperations method propertyRemoved.

@Override
public void propertyRemoved(DataWriteOperations ops, long entityId, int propertyKey) throws AutoIndexingKernelException {
    if (enabled) {
        try {
            String name = propertyKeyLookup.getTokenById(propertyKey).name();
            if (propertyKeysToInclude.get().contains(name)) {
                ensureIndexExists(ops);
                type.remove(ops, entityId, name);
            }
        } catch (LegacyIndexNotFoundKernelException | EntityNotFoundException e) {
            throw new AutoIndexingKernelException(e);
        } catch (TokenNotFoundException e) {
            // KernelException now
            throw new AutoIndexingKernelException(new PropertyKeyIdNotFoundKernelException(propertyKey, e));
        }
    }
}
Also used : 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 12 with EntityNotFoundException

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

the class NodeProxy method getAllProperties.

@Override
public Map<String, Object> getAllProperties() {
    try (Statement statement = actions.statement()) {
        try (Cursor<NodeItem> node = statement.readOperations().nodeCursorById(nodeId)) {
            try (Cursor<PropertyItem> propertyCursor = statement.readOperations().nodeGetProperties(node.get())) {
                Map<String, Object> properties = new HashMap<>();
                // Get all properties
                while (propertyCursor.next()) {
                    String name = statement.readOperations().propertyKeyGetName(propertyCursor.get().propertyKeyId());
                    properties.put(name, propertyCursor.get().value());
                }
                return properties;
            }
        } 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 : HashMap(java.util.HashMap) 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) PropertyKeyIdNotFoundKernelException(org.neo4j.kernel.api.exceptions.PropertyKeyIdNotFoundKernelException) NodeItem(org.neo4j.storageengine.api.NodeItem) PropertyItem(org.neo4j.storageengine.api.PropertyItem)

Example 13 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) throws NotFoundException {
    if (null == key) {
        throw new IllegalArgumentException("(null) property key is not allowed");
    }
    try (Statement statement = actions.statement()) {
        try {
            int propertyKeyId = statement.readOperations().propertyKeyGetForName(key);
            if (propertyKeyId == KeyReadOperations.NO_SUCH_PROPERTY_KEY) {
                throw new NotFoundException(format("No such property, '%s'.", key));
            }
            Object value = statement.readOperations().nodeGetProperty(nodeId, propertyKeyId);
            if (value == null) {
                throw new PropertyNotFoundException(propertyKeyId, EntityType.NODE, nodeId);
            }
            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 14 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) {
    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.BOTH, 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 15 with EntityNotFoundException

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

the class InternalAutoIndexOperations method entityRemoved.

@Override
public void entityRemoved(DataWriteOperations ops, long entityId) throws AutoIndexingKernelException {
    if (enabled) {
        try {
            ensureIndexExists(ops);
            type.remove(ops, entityId);
        } catch (LegacyIndexNotFoundKernelException | EntityNotFoundException e) {
            throw new AutoIndexingKernelException(e);
        }
    }
}
Also used : LegacyIndexNotFoundKernelException(org.neo4j.kernel.api.exceptions.legacyindex.LegacyIndexNotFoundKernelException) EntityNotFoundException(org.neo4j.kernel.api.exceptions.EntityNotFoundException) AutoIndexingKernelException(org.neo4j.kernel.api.exceptions.legacyindex.AutoIndexingKernelException)

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