Search in sources :

Example 21 with EntityNotFoundException

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

the class GraphDatabaseFacade method getRelationshipById.

@Override
public Relationship getRelationshipById(long id) {
    if (id < 0) {
        throw new NotFoundException(format("Relationship %d not found", id), new EntityNotFoundException(EntityType.RELATIONSHIP, id));
    }
    try (Statement statement = spi.currentStatement()) {
        try {
            RelationshipProxy relationship = new RelationshipProxy(relActions, id);
            statement.readOperations().relationshipVisit(id, relationship);
            return relationship;
        } catch (EntityNotFoundException e) {
            throw new NotFoundException(format("Relationship %d not found", id), e);
        }
    }
}
Also used : RelationshipProxy(org.neo4j.kernel.impl.core.RelationshipProxy) Statement(org.neo4j.kernel.api.Statement) NotFoundException(org.neo4j.graphdb.NotFoundException) SchemaRuleNotFoundException(org.neo4j.kernel.api.exceptions.schema.SchemaRuleNotFoundException) EntityNotFoundException(org.neo4j.kernel.api.exceptions.EntityNotFoundException) EntityNotFoundException(org.neo4j.kernel.api.exceptions.EntityNotFoundException)

Example 22 with EntityNotFoundException

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

the class RelationshipProxy method getAllProperties.

@Override
public Map<String, Object> getAllProperties() {
    try (Statement statement = actions.statement()) {
        try (Cursor<RelationshipItem> relationship = statement.readOperations().relationshipCursorById(getId())) {
            try (Cursor<PropertyItem> propertyCursor = statement.readOperations().relationshipGetProperties(relationship.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("Relationship 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) PropertyItem(org.neo4j.storageengine.api.PropertyItem) RelationshipItem(org.neo4j.storageengine.api.RelationshipItem)

Example 23 with EntityNotFoundException

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

the class RelationshipProxy method getPropertyKeys.

@Override
public Iterable<String> getPropertyKeys() {
    try (Statement statement = actions.statement()) {
        List<String> keys = new ArrayList<>();
        PrimitiveIntIterator properties = statement.readOperations().relationshipGetPropertyKeys(getId());
        while (properties.hasNext()) {
            keys.add(statement.readOperations().propertyKeyGetName(properties.next()));
        }
        return keys;
    } catch (EntityNotFoundException e) {
        throw new NotFoundException("Relationship not found", e);
    } catch (PropertyKeyIdNotFoundKernelException e) {
        throw new IllegalStateException("Property key retrieved through kernel API should exist.");
    }
}
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)

Example 24 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, Object defaultValue) {
    if (null == key) {
        throw new IllegalArgumentException("(null) property key is not allowed");
    }
    try (Statement statement = actions.statement()) {
        int propertyId = statement.readOperations().propertyKeyGetForName(key);
        Object value = statement.readOperations().relationshipGetProperty(getId(), propertyId);
        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 25 with EntityNotFoundException

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

the class NeoStoreIndexStoreView method getProperty.

@Override
public Property getProperty(long nodeId, int propertyKeyId) throws EntityNotFoundException {
    NodeRecord node = nodeStore.getRecord(nodeId, nodeStore.newRecord(), FORCE);
    if (!node.inUse()) {
        throw new EntityNotFoundException(EntityType.NODE, nodeId);
    }
    long firstPropertyId = node.getNextProp();
    if (firstPropertyId == Record.NO_NEXT_PROPERTY.intValue()) {
        return Property.noNodeProperty(nodeId, propertyKeyId);
    }
    for (PropertyRecord propertyRecord : propertyStore.getPropertyRecordChain(firstPropertyId)) {
        PropertyBlock propertyBlock = propertyRecord.getPropertyBlock(propertyKeyId);
        if (propertyBlock != null) {
            return propertyBlock.newPropertyData(propertyStore);
        }
    }
    return Property.noNodeProperty(nodeId, propertyKeyId);
}
Also used : NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) PropertyBlock(org.neo4j.kernel.impl.store.record.PropertyBlock) EntityNotFoundException(org.neo4j.kernel.api.exceptions.EntityNotFoundException)

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