use of org.neo4j.kernel.api.KernelTransaction in project neo4j by neo4j.
the class NodeEntity method getAllProperties.
public Map<String, Object> getAllProperties(NodeCursor nodes, PropertyCursor propertyCursor) {
KernelTransaction transaction = internalTransaction.kernelTransaction();
Map<String, Object> properties = new HashMap<>();
try {
TokenRead token = transaction.tokenRead();
if (nodes.isClosed() || nodes.nodeReference() != getId()) {
singleNode(transaction, nodes);
}
nodes.properties(propertyCursor);
while (propertyCursor.next()) {
properties.put(token.propertyKeyName(propertyCursor.propertyKey()), propertyCursor.propertyValue().asObjectCopy());
}
} catch (PropertyKeyIdNotFoundKernelException e) {
throw new IllegalStateException("Property key retrieved through kernel API should exist.", e);
}
return properties;
}
use of org.neo4j.kernel.api.KernelTransaction in project neo4j by neo4j.
the class NodeEntity method getRelationshipTypes.
@Override
public Iterable<RelationshipType> getRelationshipTypes() {
KernelTransaction transaction = internalTransaction.kernelTransaction();
try {
NodeCursor nodes = transaction.ambientNodeCursor();
TokenRead tokenRead = transaction.tokenRead();
singleNode(transaction, nodes);
Degrees degrees = nodes.degrees(ALL_RELATIONSHIPS);
List<RelationshipType> types = new ArrayList<>();
for (int type : degrees.types()) {
// only include this type if there are any relationships with this type
if (degrees.totalDegree(type) > 0) {
types.add(RelationshipType.withName(tokenRead.relationshipTypeName(type)));
}
}
return types;
} catch (KernelException e) {
throw new NotFoundException("Relationship name not found.", e);
}
}
use of org.neo4j.kernel.api.KernelTransaction in project neo4j by neo4j.
the class NodeEntity method removeProperty.
@Override
public Object removeProperty(String key) throws NotFoundException {
KernelTransaction transaction = internalTransaction.kernelTransaction();
int propertyKeyId;
try {
propertyKeyId = transaction.tokenWrite().propertyKeyGetOrCreateForName(key);
} catch (IllegalTokenNameException e) {
throw new IllegalArgumentException(format("Invalid property key '%s'.", key), e);
} catch (KernelException e) {
throw new TransactionFailureException("Unknown error trying to get property key token", e);
}
try {
return transaction.dataWrite().nodeRemoveProperty(nodeId, propertyKeyId).asObjectCopy();
} catch (EntityNotFoundException e) {
throw new NotFoundException(e);
} catch (InvalidTransactionTypeKernelException e) {
throw new ConstraintViolationException(e.getMessage(), e);
}
}
use of org.neo4j.kernel.api.KernelTransaction in project neo4j by neo4j.
the class NodeEntity method isDeletedInCurrentTransaction.
public static boolean isDeletedInCurrentTransaction(Node node) {
if (node instanceof NodeEntity) {
NodeEntity proxy = (NodeEntity) node;
KernelTransaction ktx = proxy.internalTransaction.kernelTransaction();
return ktx.dataRead().nodeDeletedInTransaction(proxy.nodeId);
}
return false;
}
use of org.neo4j.kernel.api.KernelTransaction in project neo4j by neo4j.
the class NodeEntity method getProperty.
@Override
public Object getProperty(String key, Object defaultValue) {
if (null == key) {
throw new IllegalArgumentException("(null) property key is not allowed");
}
KernelTransaction transaction = internalTransaction.kernelTransaction();
NodeCursor nodes = transaction.ambientNodeCursor();
PropertyCursor properties = transaction.ambientPropertyCursor();
int propertyKey = transaction.tokenRead().propertyKey(key);
if (propertyKey == TokenRead.NO_TOKEN) {
return defaultValue;
}
singleNode(transaction, nodes);
nodes.properties(properties);
return properties.seekProperty(propertyKey) ? properties.propertyValue().asObjectCopy() : defaultValue;
}
Aggregations