use of org.neo4j.internal.kernel.api.PropertyCursor in project neo4j by neo4j.
the class RelationshipTransactionStateTestBase method propertyTypeShouldBeTxStateAware.
@Test
void propertyTypeShouldBeTxStateAware() throws Exception {
// Given
long relationship;
try (KernelTransaction tx = beginTransaction()) {
Write write = tx.dataWrite();
int token = tx.tokenWrite().relationshipTypeGetOrCreateForName("R");
relationship = write.relationshipCreate(write.nodeCreate(), token, write.nodeCreate());
tx.commit();
}
// Then
try (KernelTransaction tx = beginTransaction()) {
try (RelationshipScanCursor relationships = tx.cursors().allocateRelationshipScanCursor(NULL);
PropertyCursor properties = tx.cursors().allocatePropertyCursor(NULL, INSTANCE)) {
tx.dataRead().singleRelationship(relationship, relationships);
assertTrue(relationships.next());
assertFalse(hasProperties(relationships, tx));
int prop = tx.tokenWrite().propertyKeyGetOrCreateForName("prop");
tx.dataWrite().relationshipSetProperty(relationship, prop, stringValue("foo"));
relationships.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 RelationshipEntity method hasProperty.
@Override
public boolean hasProperty(String key) {
if (null == key) {
return false;
}
KernelTransaction transaction = internalTransaction.kernelTransaction();
int propertyKey = transaction.tokenRead().propertyKey(key);
if (propertyKey == TokenRead.NO_TOKEN) {
return false;
}
RelationshipScanCursor relationships = transaction.ambientRelationshipCursor();
PropertyCursor properties = transaction.ambientPropertyCursor();
singleRelationship(transaction, relationships);
relationships.properties(properties);
return properties.seekProperty(propertyKey);
}
use of org.neo4j.internal.kernel.api.PropertyCursor in project neo4j by neo4j.
the class RelationshipEntity method getPropertyKeys.
@Override
public Iterable<String> getPropertyKeys() {
KernelTransaction transaction = internalTransaction.kernelTransaction();
List<String> keys = new ArrayList<>();
try {
RelationshipScanCursor relationships = transaction.ambientRelationshipCursor();
PropertyCursor properties = transaction.ambientPropertyCursor();
singleRelationship(transaction, relationships);
TokenRead token = transaction.tokenRead();
relationships.properties(properties);
while (properties.next()) {
keys.add(token.propertyKeyName(properties.propertyKey()));
}
} catch (PropertyKeyIdNotFoundKernelException e) {
throw new IllegalStateException("Property key retrieved through kernel API should exist.", e);
}
return keys;
}
use of org.neo4j.internal.kernel.api.PropertyCursor in project neo4j by neo4j.
the class RelationshipEntity method getAllProperties.
@Override
public Map<String, Object> getAllProperties() {
KernelTransaction transaction = internalTransaction.kernelTransaction();
PropertyCursor propertyCursor = transaction.ambientPropertyCursor();
return getAllProperties(propertyCursor);
}
use of org.neo4j.internal.kernel.api.PropertyCursor in project neo4j by neo4j.
the class RelationshipEntity method getProperty.
@Override
public Object getProperty(String key) {
if (null == key) {
throw new IllegalArgumentException("(null) property key is not allowed");
}
KernelTransaction transaction = internalTransaction.kernelTransaction();
int propertyKey = transaction.tokenRead().propertyKey(key);
if (propertyKey == TokenRead.NO_TOKEN) {
throw new NotFoundException(format("No such property, '%s'.", key));
}
RelationshipScanCursor relationships = transaction.ambientRelationshipCursor();
PropertyCursor properties = transaction.ambientPropertyCursor();
singleRelationship(transaction, relationships);
relationships.properties(properties);
if (!properties.seekProperty(propertyKey)) {
throw new NotFoundException(format("No such property, '%s'.", key));
}
return properties.propertyValue().asObjectCopy();
}
Aggregations