use of org.neo4j.internal.kernel.api.PropertyCursor in project neo4j by neo4j.
the class KernelReadTracerTxStateTest method shouldTracePropertyAccess.
@Test
void shouldTracePropertyAccess() throws Exception {
// given
TestKernelReadTracer tracer = new TestKernelReadTracer();
try (KernelTransaction tx = beginTransaction();
NodeCursor nodeCursor = tx.cursors().allocateNodeCursor(tx.cursorContext());
PropertyCursor propertyCursor = tx.cursors().allocatePropertyCursor(tx.cursorContext(), tx.memoryTracker())) {
long n = tx.dataWrite().nodeCreate();
int name = tx.token().propertyKey("name");
tx.dataWrite().nodeSetProperty(n, name, Values.stringValue("Bosse"));
// when
propertyCursor.setTracer(tracer);
tx.dataRead().singleNode(n, nodeCursor);
assertTrue(nodeCursor.next());
nodeCursor.properties(propertyCursor);
assertTrue(propertyCursor.next());
tracer.assertEvents(OnProperty(name));
assertFalse(propertyCursor.next());
tracer.assertEvents();
}
}
use of org.neo4j.internal.kernel.api.PropertyCursor in project neo4j by neo4j.
the class NodeTransactionStateTestBase method shouldSeeNewNodePropertyInTransaction.
@Test
void shouldSeeNewNodePropertyInTransaction() throws Exception {
long nodeId;
String propKey1 = "prop1";
String propKey2 = "prop2";
try (KernelTransaction tx = beginTransaction()) {
nodeId = tx.dataWrite().nodeCreate();
int prop1 = tx.token().propertyKeyGetOrCreateForName(propKey1);
int prop2 = tx.token().propertyKeyGetOrCreateForName(propKey2);
assertEquals(NO_VALUE, tx.dataWrite().nodeSetProperty(nodeId, prop1, stringValue("hello")));
assertEquals(NO_VALUE, tx.dataWrite().nodeSetProperty(nodeId, prop2, stringValue("world")));
try (NodeCursor node = tx.cursors().allocateNodeCursor(tx.cursorContext());
PropertyCursor property = tx.cursors().allocatePropertyCursor(tx.cursorContext(), tx.memoryTracker())) {
tx.dataRead().singleNode(nodeId, node);
assertTrue(node.next(), "should access node");
node.properties(property);
IntObjectHashMap<Value> foundProperties = IntObjectHashMap.newMap();
while (property.next()) {
assertNull(foundProperties.put(property.propertyKey(), property.propertyValue()), "should only find each property once");
}
assertThat(foundProperties).hasSize(2);
assertThat(foundProperties.get(prop1)).isEqualTo(stringValue("hello"));
assertThat(foundProperties.get(prop2)).isEqualTo(stringValue("world"));
assertFalse(node.next(), "should only find one node");
}
tx.commit();
}
}
use of org.neo4j.internal.kernel.api.PropertyCursor in project neo4j by neo4j.
the class NodeWriteTestBase method shouldSetAndReadLargeByteArrayPropertyToNode.
@Test
void shouldSetAndReadLargeByteArrayPropertyToNode() throws Exception {
// Given
int prop;
long node = createNode();
Value largeByteArray = Values.of(new byte[100_000]);
// When
try (KernelTransaction tx = beginTransaction()) {
prop = tx.token().propertyKeyGetOrCreateForName(propertyKey);
assertThat(tx.dataWrite().nodeSetProperty(node, prop, largeByteArray)).isEqualTo(NO_VALUE);
tx.commit();
}
// Then
try (KernelTransaction tx = beginTransaction();
NodeCursor nodeCursor = tx.cursors().allocateNodeCursor(tx.cursorContext());
PropertyCursor propertyCursor = tx.cursors().allocatePropertyCursor(tx.cursorContext(), tx.memoryTracker())) {
tx.dataRead().singleNode(node, nodeCursor);
assertTrue(nodeCursor.next());
nodeCursor.properties(propertyCursor);
assertTrue(propertyCursor.next());
assertEquals(propertyCursor.propertyKey(), prop);
assertThat(propertyCursor.propertyValue()).isEqualTo(largeByteArray);
}
}
use of org.neo4j.internal.kernel.api.PropertyCursor in project neo4j by neo4j.
the class FulltextIndexTransactionState method updateSearcher.
private void updateSearcher(QueryContext context, CursorContext cursorContext, MemoryTracker memoryTracker) throws Exception {
Read read = context.getRead();
CursorFactory cursors = context.cursors();
ReadableTransactionState state = context.getTransactionStateOrNull();
// Clear this, so we don't filter out entities who have had their changes reversed since last time.
modifiedEntityIdsInThisTransaction.clear();
writer.resetWriterState();
try (NodeCursor nodeCursor = visitingNodes ? cursors.allocateFullAccessNodeCursor(cursorContext) : null;
RelationshipScanCursor relationshipCursor = visitingNodes ? null : cursors.allocateRelationshipScanCursor(cursorContext);
PropertyCursor propertyCursor = cursors.allocateFullAccessPropertyCursor(cursorContext, memoryTracker)) {
state.accept(txStateVisitor.init(read, nodeCursor, relationshipCursor, propertyCursor));
}
currentSearcher = writer.getNearRealTimeSearcher();
toCloseLater.add(currentSearcher);
lastUpdateRevision = state.getDataRevision();
}
use of org.neo4j.internal.kernel.api.PropertyCursor in project neo4j by neo4j.
the class SchemaCalculator method scanEverythingBelongingToNodes.
private void scanEverythingBelongingToNodes(NodeMappings nodeMappings, CursorContext cursorContext, MemoryTracker memoryTracker) {
try (NodeCursor nodeCursor = cursors.allocateNodeCursor(cursorContext);
PropertyCursor propertyCursor = cursors.allocatePropertyCursor(cursorContext, memoryTracker)) {
dataRead.allNodesScan(nodeCursor);
while (nodeCursor.next()) {
// each node
SortedLabels labels = SortedLabels.from(nodeCursor.labels());
nodeCursor.properties(propertyCursor);
MutableIntSet propertyIds = IntSets.mutable.empty();
while (propertyCursor.next()) {
Value currentValue = propertyCursor.propertyValue();
int propertyKeyId = propertyCursor.propertyKey();
Pair<SortedLabels, Integer> key = Pair.of(labels, propertyKeyId);
updateValueTypeInMapping(currentValue, key, nodeMappings.labelSetANDNodePropertyKeyIdToValueType);
propertyIds.add(propertyKeyId);
}
propertyCursor.close();
MutableIntSet oldPropertyKeySet = nodeMappings.labelSetToPropertyKeys.getOrDefault(labels, emptyPropertyIdSet);
// find out which old properties we did not visited and mark them as nullable
if (oldPropertyKeySet == emptyPropertyIdSet) {
if (propertyIds.size() == 0) {
// Even if we find property key on other nodes with those labels, set all of them nullable
nodeMappings.nullableLabelSets.add(labels);
}
propertyIds.addAll(oldPropertyKeySet);
} else {
MutableIntSet currentPropertyIdsHelperSet = new IntHashSet(propertyIds.size());
currentPropertyIdsHelperSet.addAll(propertyIds);
// only the brand new ones in propIds now
propertyIds.removeAll(oldPropertyKeySet);
// only the old ones that are not on the new node
oldPropertyKeySet.removeAll(currentPropertyIdsHelperSet);
propertyIds.addAll(oldPropertyKeySet);
propertyIds.forEach(id -> {
Pair<SortedLabels, Integer> key = Pair.of(labels, id);
nodeMappings.labelSetANDNodePropertyKeyIdToValueType.get(key).setNullable();
});
propertyIds.addAll(currentPropertyIdsHelperSet);
}
nodeMappings.labelSetToPropertyKeys.put(labels, propertyIds);
}
}
}
Aggregations