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);
}
}
}
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);
}
}
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.");
}
}
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);
}
}
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);
}
Aggregations