use of org.neo4j.internal.kernel.api.PropertyCursor in project neo4j by neo4j.
the class RelationshipTransactionStateTestBase method shouldSeeUpdatedPropertyFromExistingRelationshipWithPropertiesInTransaction.
@Test
void shouldSeeUpdatedPropertyFromExistingRelationshipWithPropertiesInTransaction() throws Exception {
// Given
long relationshipId;
String propKey = "prop1";
int propToken;
try (KernelTransaction tx = beginTransaction()) {
Write write = tx.dataWrite();
relationshipId = write.relationshipCreate(write.nodeCreate(), tx.tokenWrite().relationshipTypeGetOrCreateForName("R"), write.nodeCreate());
propToken = tx.token().propertyKeyGetOrCreateForName(propKey);
assertEquals(write.relationshipSetProperty(relationshipId, propToken, stringValue("hello")), NO_VALUE);
tx.commit();
}
// When/Then
try (KernelTransaction tx = beginTransaction()) {
assertEquals(tx.dataWrite().relationshipSetProperty(relationshipId, propToken, stringValue("world")), stringValue("hello"));
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("world"));
assertFalse(property.next(), "should only find one property");
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("world");
}
}
use of org.neo4j.internal.kernel.api.PropertyCursor in project neo4j by neo4j.
the class RelationshipTransactionStateTestBase method shouldSeeAddedPropertyFromExistingRelationshipWithPropertiesInTransaction.
@Test
void shouldSeeAddedPropertyFromExistingRelationshipWithPropertiesInTransaction() throws Exception {
// Given
long relationshipId;
String propKey1 = "prop1";
String propKey2 = "prop2";
int propToken1;
int propToken2;
try (KernelTransaction tx = beginTransaction()) {
Write write = tx.dataWrite();
relationshipId = write.relationshipCreate(write.nodeCreate(), tx.tokenWrite().relationshipTypeGetOrCreateForName("R"), write.nodeCreate());
propToken1 = tx.token().propertyKeyGetOrCreateForName(propKey1);
assertEquals(write.relationshipSetProperty(relationshipId, propToken1, stringValue("hello")), NO_VALUE);
tx.commit();
}
// When/Then
try (KernelTransaction tx = beginTransaction()) {
propToken2 = tx.token().propertyKeyGetOrCreateForName(propKey2);
assertEquals(tx.dataWrite().relationshipSetProperty(relationshipId, propToken2, stringValue("world")), 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);
while (property.next()) {
if (// from disk
property.propertyKey() == propToken1) {
assertEquals(property.propertyValue(), stringValue("hello"));
} else if (// from tx state
property.propertyKey() == propToken2) {
assertEquals(property.propertyValue(), stringValue("world"));
} else {
fail(property.propertyKey() + " was not the property you were looking for");
}
}
assertFalse(relationship.next(), "should only find one relationship");
}
tx.commit();
}
try (org.neo4j.graphdb.Transaction transaction = graphDb.beginTx()) {
Relationship relationship = transaction.getRelationshipById(relationshipId);
assertThat(relationship.getProperty(propKey1)).isEqualTo("hello");
assertThat(relationship.getProperty(propKey2)).isEqualTo("world");
}
}
use of org.neo4j.internal.kernel.api.PropertyCursor in project neo4j by neo4j.
the class RelationshipTransactionStateTestBase method shouldSeeNewRelationshipPropertyInTransaction.
@Test
void shouldSeeNewRelationshipPropertyInTransaction() throws Exception {
try (KernelTransaction tx = beginTransaction()) {
String propKey1 = "prop1";
String propKey2 = "prop2";
long n1 = tx.dataWrite().nodeCreate();
long n2 = tx.dataWrite().nodeCreate();
int label = tx.tokenWrite().relationshipTypeGetOrCreateForName("R");
long r = tx.dataWrite().relationshipCreate(n1, label, n2);
int prop1 = tx.token().propertyKeyGetOrCreateForName(propKey1);
int prop2 = tx.token().propertyKeyGetOrCreateForName(propKey2);
assertEquals(tx.dataWrite().relationshipSetProperty(r, prop1, stringValue("hello")), NO_VALUE);
assertEquals(tx.dataWrite().relationshipSetProperty(r, prop2, stringValue("world")), NO_VALUE);
try (NodeCursor node = tx.cursors().allocateNodeCursor(NULL);
RelationshipTraversalCursor relationship = tx.cursors().allocateRelationshipTraversalCursor(NULL);
PropertyCursor property = tx.cursors().allocatePropertyCursor(NULL, INSTANCE)) {
tx.dataRead().singleNode(n1, node);
assertTrue(node.next(), "should access node");
node.relationships(relationship, ALL_RELATIONSHIPS);
assertTrue(relationship.next(), "should access relationship");
relationship.properties(property);
while (property.next()) {
if (property.propertyKey() == prop1) {
assertEquals(property.propertyValue(), stringValue("hello"));
} else if (property.propertyKey() == prop2) {
assertEquals(property.propertyValue(), stringValue("world"));
} else {
fail(property.propertyKey() + " was not the property key you were looking for");
}
}
assertFalse(relationship.next(), "should only find one relationship");
}
tx.commit();
}
}
use of org.neo4j.internal.kernel.api.PropertyCursor in project neo4j by neo4j.
the class RelationshipTransactionStateTestBase method shouldNotSeeRemovedPropertyInTransaction.
@Test
void shouldNotSeeRemovedPropertyInTransaction() throws Exception {
// Given
long relationshipId;
String propKey = "prop1";
int propToken;
try (KernelTransaction tx = beginTransaction()) {
Write write = tx.dataWrite();
relationshipId = write.relationshipCreate(write.nodeCreate(), tx.tokenWrite().relationshipTypeGetOrCreateForName("R"), write.nodeCreate());
propToken = tx.token().propertyKeyGetOrCreateForName(propKey);
assertEquals(write.relationshipSetProperty(relationshipId, propToken, stringValue("hello")), NO_VALUE);
tx.commit();
}
// When/Then
try (KernelTransaction tx = beginTransaction()) {
assertEquals(tx.dataWrite().relationshipRemoveProperty(relationshipId, propToken), stringValue("hello"));
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);
assertFalse(property.next(), "should not find any properties");
assertFalse(relationship.next(), "should only find one relationship");
}
tx.commit();
}
try (org.neo4j.graphdb.Transaction transaction = graphDb.beginTx()) {
assertFalse(transaction.getRelationshipById(relationshipId).hasProperty(propKey));
}
}
use of org.neo4j.internal.kernel.api.PropertyCursor in project neo4j by neo4j.
the class PropertyCursorTestBase method assertAccessSingleRelationshipProperty.
private void assertAccessSingleRelationshipProperty(long relationshipId, Object expectedValue, ValueGroup expectedValueType) {
// given
try (RelationshipScanCursor relationship = cursors.allocateRelationshipScanCursor(NULL);
PropertyCursor props = cursors.allocatePropertyCursor(NULL, INSTANCE)) {
// when
read.singleRelationship(relationshipId, relationship);
assertTrue(relationship.next(), "relationship by reference");
assertTrue(hasProperties(relationship, props), "has properties");
relationship.properties(props);
assertTrue(props.next(), "has properties by direct method");
assertEquals(expectedValue, props.propertyValue(), "correct value");
assertEquals(expectedValueType, props.propertyType(), "correct value type ");
assertFalse(props.next(), "single property");
read.relationshipProperties(relationship.relationshipReference(), relationship.propertiesReference(), props);
assertTrue(props.next(), "has properties via property ref");
assertEquals(expectedValue, props.propertyValue(), "correct value");
assertFalse(props.next(), "single property");
}
}
Aggregations