use of org.neo4j.internal.kernel.api.TokenRead in project neo4j by neo4j.
the class NodeEntity method getProperties.
@Override
public Map<String, Object> getProperties(String... keys) {
Objects.requireNonNull(keys, "Properties keys should be not null array.");
if (keys.length == 0) {
return Collections.emptyMap();
}
KernelTransaction transaction = internalTransaction.kernelTransaction();
int itemsToReturn = keys.length;
Map<String, Object> properties = new HashMap<>(itemsToReturn);
TokenRead token = transaction.tokenRead();
// Find ids, note we are betting on that the number of keys
// is small enough not to use a set here.
int[] propertyIds = new int[itemsToReturn];
for (int i = 0; i < itemsToReturn; i++) {
String key = keys[i];
if (key == null) {
throw new NullPointerException(String.format("Key %d was null", i));
}
propertyIds[i] = token.propertyKey(key);
}
NodeCursor nodes = transaction.ambientNodeCursor();
PropertyCursor propertyCursor = transaction.ambientPropertyCursor();
singleNode(transaction, nodes);
nodes.properties(propertyCursor);
int propertiesToFind = itemsToReturn;
while (propertiesToFind > 0 && propertyCursor.next()) {
// Do a linear check if this is a property we are interested in.
int currentKey = propertyCursor.propertyKey();
for (int i = 0; i < itemsToReturn; i++) {
if (propertyIds[i] == currentKey) {
properties.put(keys[i], propertyCursor.propertyValue().asObjectCopy());
propertiesToFind--;
break;
}
}
}
return properties;
}
use of org.neo4j.internal.kernel.api.TokenRead in project neo4j by neo4j.
the class NodeEntity method getLabels.
public Iterable<Label> getLabels(NodeCursor nodes) {
KernelTransaction transaction = internalTransaction.kernelTransaction();
try {
singleNode(transaction, nodes);
TokenSet tokenSet = nodes.labels();
TokenRead tokenRead = transaction.tokenRead();
List<Label> list = new ArrayList<>(tokenSet.numberOfTokens());
for (int i = 0; i < tokenSet.numberOfTokens(); i++) {
list.add(label(tokenRead.nodeLabelName(tokenSet.token(i))));
}
return list;
} catch (LabelNotFoundKernelException e) {
throw new IllegalStateException("Label retrieved through kernel API should exist.", e);
}
}
use of org.neo4j.internal.kernel.api.TokenRead in project neo4j by neo4j.
the class NodeEntity method getPropertyKeys.
@Override
public Iterable<String> getPropertyKeys() {
KernelTransaction transaction = internalTransaction.kernelTransaction();
List<String> keys = new ArrayList<>();
try {
NodeCursor nodes = transaction.ambientNodeCursor();
PropertyCursor properties = transaction.ambientPropertyCursor();
singleNode(transaction, nodes);
TokenRead token = transaction.tokenRead();
nodes.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.TokenRead in project neo4j by neo4j.
the class RelationshipEntity method getProperties.
@Override
public Map<String, Object> getProperties(String... keys) {
Objects.requireNonNull(keys, "Properties keys should be not null array.");
if (keys.length == 0) {
return Collections.emptyMap();
}
KernelTransaction transaction = internalTransaction.kernelTransaction();
int itemsToReturn = keys.length;
TokenRead token = transaction.tokenRead();
// Find ids, note we are betting on that the number of keys
// is small enough not to use a set here.
int[] propertyIds = new int[itemsToReturn];
for (int i = 0; i < itemsToReturn; i++) {
String key = keys[i];
if (key == null) {
throw new NullPointerException(String.format("Key %d was null", i));
}
propertyIds[i] = token.propertyKey(key);
}
Map<String, Object> properties = new HashMap<>(itemsToReturn);
RelationshipScanCursor relationships = transaction.ambientRelationshipCursor();
PropertyCursor propertyCursor = transaction.ambientPropertyCursor();
singleRelationship(transaction, relationships);
relationships.properties(propertyCursor);
int propertiesToFind = itemsToReturn;
while (propertiesToFind > 0 && propertyCursor.next()) {
// Do a linear check if this is a property we are interested in.
int currentKey = propertyCursor.propertyKey();
for (int i = 0; i < itemsToReturn; i++) {
if (propertyIds[i] == currentKey) {
properties.put(keys[i], propertyCursor.propertyValue().asObjectCopy());
propertiesToFind--;
break;
}
}
}
return properties;
}
Aggregations