use of org.neo4j.internal.kernel.api.RelationshipScanCursor 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.RelationshipScanCursor 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.RelationshipScanCursor in project neo4j by neo4j.
the class RelationshipEntity method getAllProperties.
public Map<String, Object> getAllProperties(PropertyCursor propertyCursor) {
KernelTransaction transaction = internalTransaction.kernelTransaction();
Map<String, Object> properties = new HashMap<>();
try {
RelationshipScanCursor relationships = transaction.ambientRelationshipCursor();
TokenRead token = transaction.tokenRead();
singleRelationship(transaction, relationships);
relationships.properties(propertyCursor);
while (propertyCursor.next()) {
properties.put(token.propertyKeyName(propertyCursor.propertyKey()), propertyCursor.propertyValue().asObjectCopy());
}
} catch (PropertyKeyIdNotFoundKernelException e) {
throw new IllegalStateException("Property key retrieved through kernel API should exist.", e);
}
return properties;
}
use of org.neo4j.internal.kernel.api.RelationshipScanCursor 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();
}
use of org.neo4j.internal.kernel.api.RelationshipScanCursor in project neo4j by neo4j.
the class RelationshipTransactionStateTestBase method shouldScanRelationshipInTransaction.
@Test
void shouldScanRelationshipInTransaction() throws Exception {
final int nRelationshipsInStore = 10;
int type;
long n1, n2;
try (KernelTransaction tx = beginTransaction()) {
n1 = tx.dataWrite().nodeCreate();
n2 = tx.dataWrite().nodeCreate();
// setup some in store relationships
type = tx.tokenWrite().relationshipTypeGetOrCreateForName("R");
relateNTimes(nRelationshipsInStore, type, n1, n2, tx);
tx.commit();
}
try (KernelTransaction tx = beginTransaction()) {
long r = tx.dataWrite().relationshipCreate(n1, type, n2);
try (RelationshipScanCursor relationship = tx.cursors().allocateRelationshipScanCursor(NULL)) {
tx.dataRead().allRelationshipsScan(relationship);
assertCountRelationships(relationship, nRelationshipsInStore + 1, n1, type, n2);
}
tx.commit();
}
}
Aggregations