use of org.neo4j.internal.kernel.api.PropertyCursor in project neo4j by neo4j.
the class NodeTransactionStateTestBase method shouldSeeAddedPropertyFromExistingNodeWithoutPropertiesInTransaction.
@Test
void shouldSeeAddedPropertyFromExistingNodeWithoutPropertiesInTransaction() throws Exception {
// Given
long nodeId;
String propKey = "prop1";
try (KernelTransaction tx = beginTransaction()) {
nodeId = tx.dataWrite().nodeCreate();
tx.commit();
}
// When/Then
try (KernelTransaction tx = beginTransaction()) {
int propToken = tx.token().propertyKeyGetOrCreateForName(propKey);
assertEquals(NO_VALUE, tx.dataWrite().nodeSetProperty(nodeId, propToken, stringValue("hello")));
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);
assertTrue(property.next());
assertEquals(propToken, property.propertyKey());
assertEquals(property.propertyValue(), stringValue("hello"));
assertFalse(property.next(), "should only find one properties");
assertFalse(node.next(), "should only find one node");
}
tx.commit();
}
try (org.neo4j.graphdb.Transaction tx = graphDb.beginTx()) {
assertThat(tx.getNodeById(nodeId).getProperty(propKey)).isEqualTo("hello");
}
}
use of org.neo4j.internal.kernel.api.PropertyCursor in project neo4j by neo4j.
the class NodeTransactionStateTestBase method shouldSeeAddedPropertyFromExistingNodeWithPropertiesInTransaction.
@Test
void shouldSeeAddedPropertyFromExistingNodeWithPropertiesInTransaction() throws Exception {
// Given
long nodeId;
String propKey1 = "prop1";
String propKey2 = "prop2";
int propToken1;
int propToken2;
try (KernelTransaction tx = beginTransaction()) {
nodeId = tx.dataWrite().nodeCreate();
propToken1 = tx.token().propertyKeyGetOrCreateForName(propKey1);
assertEquals(NO_VALUE, tx.dataWrite().nodeSetProperty(nodeId, propToken1, stringValue("hello")));
tx.commit();
}
// When/Then
try (KernelTransaction tx = beginTransaction()) {
propToken2 = tx.token().propertyKeyGetOrCreateForName(propKey2);
assertEquals(NO_VALUE, tx.dataWrite().nodeSetProperty(nodeId, propToken2, 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);
// property 2, start with tx state
assertTrue(property.next());
assertEquals(propToken2, property.propertyKey());
assertEquals(property.propertyValue(), stringValue("world"));
// property 1, from disk
assertTrue(property.next());
assertEquals(propToken1, property.propertyKey());
assertEquals(property.propertyValue(), stringValue("hello"));
assertFalse(property.next(), "should only find two properties");
assertFalse(node.next(), "should only find one node");
}
tx.commit();
}
try (org.neo4j.graphdb.Transaction tx = graphDb.beginTx()) {
assertThat(tx.getNodeById(nodeId).getProperty(propKey1)).isEqualTo("hello");
assertThat(tx.getNodeById(nodeId).getProperty(propKey2)).isEqualTo("world");
}
}
use of org.neo4j.internal.kernel.api.PropertyCursor in project neo4j by neo4j.
the class NodeTransactionStateTestBase method propertyTypeShouldBeTxStateAware.
@Test
void propertyTypeShouldBeTxStateAware() throws Exception {
// Given
long node;
try (KernelTransaction tx = beginTransaction()) {
node = tx.dataWrite().nodeCreate();
tx.commit();
}
// Then
try (KernelTransaction tx = beginTransaction()) {
try (NodeCursor nodes = tx.cursors().allocateNodeCursor(tx.cursorContext());
PropertyCursor properties = tx.cursors().allocatePropertyCursor(tx.cursorContext(), tx.memoryTracker())) {
tx.dataRead().singleNode(node, nodes);
assertTrue(nodes.next());
assertFalse(hasProperties(nodes, properties));
int prop = tx.tokenWrite().propertyKeyGetOrCreateForName("prop");
tx.dataWrite().nodeSetProperty(node, prop, stringValue("foo"));
nodes.properties(properties);
assertTrue(properties.next());
assertThat(properties.propertyType()).isEqualTo(ValueGroup.TEXT);
}
}
}
use of org.neo4j.internal.kernel.api.PropertyCursor in project neo4j by neo4j.
the class DefaultPooledCursorsTestBase method shouldReuseFullAccessPropertyCursor.
@Test
void shouldReuseFullAccessPropertyCursor() {
NodeCursor node = cursors.allocateNodeCursor(NULL);
PropertyCursor c1 = cursors.allocateFullAccessPropertyCursor(NULL, INSTANCE);
read.singleNode(propNode, node);
node.next();
node.properties(c1);
node.close();
c1.close();
PropertyCursor c2 = cursors.allocateFullAccessPropertyCursor(NULL, INSTANCE);
assertThat(c1).isSameAs(c2);
c2.close();
}
use of org.neo4j.internal.kernel.api.PropertyCursor in project neo4j by neo4j.
the class RelationshipTransactionStateTestBase method shouldSeeAddedPropertyFromExistingRelationshipWithoutPropertiesInTransaction.
@Test
void shouldSeeAddedPropertyFromExistingRelationshipWithoutPropertiesInTransaction() throws Exception {
// Given
long relationshipId;
String propKey = "prop1";
try (KernelTransaction tx = beginTransaction()) {
Write write = tx.dataWrite();
relationshipId = write.relationshipCreate(write.nodeCreate(), tx.tokenWrite().relationshipTypeGetOrCreateForName("R"), write.nodeCreate());
tx.commit();
}
// When/Then
try (KernelTransaction tx = beginTransaction()) {
int propToken = tx.token().propertyKeyGetOrCreateForName(propKey);
assertEquals(tx.dataWrite().relationshipSetProperty(relationshipId, propToken, stringValue("hello")), NO_VALUE);
try (RelationshipScanCursor relationship = tx.cursors().allocateRelationshipScanCursor(NULL);
PropertyCursor property = tx.cursors().allocatePropertyCursor(NULL, INSTANCE)) {
tx.dataRead().singleRelationship(relationshipId, relationship);
assertTrue(relationship.next(), "should access relationship");
relationship.properties(property);
assertTrue(property.next());
assertEquals(propToken, property.propertyKey());
assertEquals(property.propertyValue(), stringValue("hello"));
assertFalse(property.next(), "should only find one properties");
assertFalse(relationship.next(), "should only find one relationship");
}
tx.commit();
}
try (org.neo4j.graphdb.Transaction transaction = graphDb.beginTx()) {
assertThat(transaction.getRelationshipById(relationshipId).getProperty(propKey)).isEqualTo("hello");
}
}
Aggregations