use of org.neo4j.internal.kernel.api.NodeCursor in project neo4j by neo4j.
the class NodeParams method getPropertyValueFromStore.
@Override
public Value getPropertyValueFromStore(KernelTransaction tx, CursorFactory cursorFactory, long reference) {
try (NodeCursor storeCursor = cursorFactory.allocateNodeCursor(NULL);
PropertyCursor propertyCursor = cursorFactory.allocatePropertyCursor(NULL, INSTANCE)) {
tx.dataRead().singleNode(reference, storeCursor);
storeCursor.next();
storeCursor.properties(propertyCursor);
propertyCursor.next();
return propertyCursor.propertyValue();
}
}
use of org.neo4j.internal.kernel.api.NodeCursor in project neo4j by neo4j.
the class CachingExpandIntoTest method connections.
private LongSet connections(long start, Direction direction, long end, String... types) throws TransactionFailureException {
try (KernelTransaction tx = transaction();
NodeCursor nodeCursor = tx.cursors().allocateNodeCursor(tx.cursorContext());
RelationshipTraversalCursor traversalCursor = tx.cursors().allocateRelationshipTraversalCursor(tx.cursorContext())) {
int[] typeIds = types.length == 0 ? null : stream(types).mapToInt(tx.tokenRead()::relationshipType).toArray();
CachingExpandInto expandInto = new CachingExpandInto(tx.dataRead(), direction, MEMORY_TRACKER);
return toSet(expandInto.connectingRelationships(nodeCursor, traversalCursor, start, typeIds, end));
}
}
use of org.neo4j.internal.kernel.api.NodeCursor in project neo4j by neo4j.
the class CachingExpandIntoTest method shouldComputeDegreeWithType.
@Test
void shouldComputeDegreeWithType() throws Exception {
// GIVEN
long node;
int in, out, loop;
try (KernelTransaction tx = transaction()) {
Write write = tx.dataWrite();
node = denseNode(tx);
TokenWrite tokenWrite = tx.tokenWrite();
out = tokenWrite.relationshipTypeGetOrCreateForName("OUT");
in = tokenWrite.relationshipTypeGetOrCreateForName("IN");
loop = tokenWrite.relationshipTypeGetOrCreateForName("LOOP");
write.relationshipCreate(node, out, write.nodeCreate());
write.relationshipCreate(node, out, write.nodeCreate());
write.relationshipCreate(write.nodeCreate(), in, node);
write.relationshipCreate(node, loop, node);
tx.commit();
}
try (KernelTransaction tx = transaction()) {
Read read = tx.dataRead();
CursorFactory cursors = tx.cursors();
try (NodeCursor nodes = cursors.allocateNodeCursor(tx.cursorContext())) {
CachingExpandInto expand = new CachingExpandInto(tx.dataRead(), OUTGOING, MEMORY_TRACKER);
read.singleNode(node, nodes);
assertThat(nodes.next()).isEqualTo(true);
assertThat(nodes.supportsFastDegreeLookup()).isEqualTo(true);
Degrees degrees = nodes.degrees(ALL_RELATIONSHIPS);
assertThat(degrees.outgoingDegree(out)).isEqualTo(2);
assertThat(degrees.outgoingDegree(in)).isEqualTo(0);
assertThat(degrees.outgoingDegree(loop)).isEqualTo(1);
assertThat(degrees.incomingDegree(out)).isEqualTo(0);
assertThat(degrees.incomingDegree(in)).isEqualTo(1);
assertThat(degrees.incomingDegree(loop)).isEqualTo(1);
assertThat(degrees.totalDegree(out)).isEqualTo(2);
assertThat(degrees.totalDegree(in)).isEqualTo(1);
assertThat(degrees.totalDegree(loop)).isEqualTo(1);
}
}
}
use of org.neo4j.internal.kernel.api.NodeCursor in project neo4j by neo4j.
the class NodeEntity method getDegree.
@Override
public int getDegree(RelationshipType type) {
KernelTransaction transaction = internalTransaction.kernelTransaction();
int typeId = transaction.tokenRead().relationshipType(type.name());
if (typeId == NO_TOKEN) {
// This type doesn't even exist. Return 0
return 0;
}
NodeCursor nodes = transaction.ambientNodeCursor();
singleNode(transaction, nodes);
return Nodes.countAll(nodes, typeId);
}
use of org.neo4j.internal.kernel.api.NodeCursor 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);
}
}
Aggregations