use of org.neo4j.storageengine.api.PropertyItem in project neo4j by neo4j.
the class IndexTxStateUpdater method getOrderedPropertyValues.
private OrderedPropertyValues getOrderedPropertyValues(KernelStatement state, NodeItem node, DefinedProperty changedProperty, int[] indexPropertyIds) {
DefinedProperty[] values = new DefinedProperty[indexPropertyIds.length];
Cursor<PropertyItem> propertyCursor = readOps.nodeGetProperties(state, node);
while (propertyCursor.next()) {
PropertyItem property = propertyCursor.get();
int k = ArrayUtils.indexOf(indexPropertyIds, property.propertyKeyId());
if (k >= 0) {
values[k] = indexPropertyIds[k] == changedProperty.propertyKeyId() ? changedProperty : Property.property(indexPropertyIds[k], property.value());
}
}
if (changedProperty != NO_SUCH_PROPERTY) {
int k = ArrayUtils.indexOf(indexPropertyIds, changedProperty.propertyKeyId());
if (k >= 0) {
values[k] = changedProperty;
}
}
return OrderedPropertyValues.of(values);
}
use of org.neo4j.storageengine.api.PropertyItem in project neo4j by neo4j.
the class NodeProxy method getAllProperties.
@Override
public Map<String, Object> getAllProperties() {
try (Statement statement = actions.statement()) {
try (Cursor<NodeItem> node = statement.readOperations().nodeCursorById(nodeId)) {
try (Cursor<PropertyItem> propertyCursor = statement.readOperations().nodeGetProperties(node.get())) {
Map<String, Object> properties = new HashMap<>();
// Get all properties
while (propertyCursor.next()) {
String name = statement.readOperations().propertyKeyGetName(propertyCursor.get().propertyKeyId());
properties.put(name, propertyCursor.get().value());
}
return properties;
}
} catch (EntityNotFoundException e) {
throw new NotFoundException("Node not found", e);
}
} catch (PropertyKeyIdNotFoundKernelException e) {
throw new IllegalStateException("Property key retrieved through kernel API should exist.", e);
}
}
use of org.neo4j.storageengine.api.PropertyItem in project neo4j by neo4j.
the class PropertyContainerProxyHelper method getProperties.
static Map<String, Object> getProperties(Statement statement, Cursor<PropertyItem> propertyCursor, String[] keys) {
// Create a map which is slightly larger than the list of keys
int numberOfKeys = keys.length;
Map<String, Object> properties = new HashMap<>((int) (numberOfKeys * 1.3f));
// Specific properties given
int[] propertyKeys = getPropertyKeys(statement, keys, numberOfKeys);
int propertiesToFind = numberOfKeys;
while (propertiesToFind > 0 && propertyCursor.next()) {
PropertyItem propertyItem = propertyCursor.get();
int propertyKeyId = propertyItem.propertyKeyId();
for (int i = 0; i < propertyKeys.length; i++) {
if (propertyKeys[i] == propertyKeyId) {
properties.put(keys[i], propertyItem.value());
propertiesToFind--;
break;
}
}
}
return properties;
}
use of org.neo4j.storageengine.api.PropertyItem in project neo4j by neo4j.
the class ConstraintEnforcingEntityOperations method getAllPropertyValues.
/**
* Fetch the property values for all properties in schema for a given node. Return these as an exact predicate
* array.
*
* The changedProperty is used to override the store/txState value of the property. This is used when we intend
* to change a property, and that to verify that the post-change values do not validate some constraint.
*/
private ExactPredicate[] getAllPropertyValues(KernelStatement state, SchemaDescriptor schema, NodeItem node, DefinedProperty changedProperty) {
int[] schemaPropertyIds = schema.getPropertyIds();
ExactPredicate[] values = new ExactPredicate[schemaPropertyIds.length];
int nMatched = 0;
Cursor<PropertyItem> nodePropertyCursor = nodeGetProperties(state, node);
int changedPropId = changedProperty.propertyKeyId();
while (nodePropertyCursor.next()) {
PropertyItem property = nodePropertyCursor.get();
int nodePropertyId = property.propertyKeyId();
int k = ArrayUtils.indexOf(schemaPropertyIds, nodePropertyId);
if (k >= 0) {
if (nodePropertyId != changedPropId) {
values[k] = IndexQuery.exact(nodePropertyId, property.value());
}
nMatched++;
}
}
if (changedPropId != NO_SUCH_PROPERTY_KEY) {
int k = ArrayUtils.indexOf(schemaPropertyIds, changedPropId);
if (k >= 0) {
values[k] = IndexQuery.exact(changedPropId, changedProperty.value());
nMatched++;
}
}
if (nMatched < values.length) {
return null;
}
return values;
}
use of org.neo4j.storageengine.api.PropertyItem in project neo4j by neo4j.
the class StateOperationsAutoIndexingTest method shouldSignalRelationshipPropertyRemovedToAutoIndex.
@Test
public void shouldSignalRelationshipPropertyRemovedToAutoIndex() throws Exception {
// Given
PropertyItem existingProperty = mock(PropertyItem.class);
int propertyKeyId = 1;
when(existingProperty.propertyKeyId()).thenReturn(propertyKeyId);
when(existingProperty.value()).thenReturn("Goodbye!");
RelationshipItem relationship = mock(RelationshipItem.class);
when(storeStmt.acquireSingleRelationshipCursor(1337)).thenReturn(cursor(relationship));
when(storeLayer.relationshipGetProperty(storeStmt, relationship, propertyKeyId)).thenReturn(cursor(existingProperty));
// When
context.relationshipRemoveProperty(stmt, 1337, existingProperty.propertyKeyId());
// Then
verify(relOps).propertyRemoved(writeOps, 1337L, existingProperty.propertyKeyId());
}
Aggregations