use of org.neo4j.storageengine.api.NodeItem in project neo4j by neo4j.
the class StateHandlingStatementOperations method nodeRemoveLabel.
@Override
public boolean nodeRemoveLabel(KernelStatement state, long nodeId, int labelId) throws EntityNotFoundException {
try (Cursor<NodeItem> cursor = nodeCursorById(state, nodeId)) {
NodeItem node = cursor.get();
if (!node.hasLabel(labelId)) {
// Label does not exist in state or in store, no-op
return false;
}
state.txState().nodeDoRemoveLabel(labelId, node.id());
indexTxStateUpdater.onLabelChange(state, labelId, node, REMOVED_LABEL);
return true;
}
}
use of org.neo4j.storageengine.api.NodeItem in project neo4j by neo4j.
the class TxStateTransactionDataSnapshot method takeSnapshot.
private void takeSnapshot() {
try {
for (long nodeId : state.addedAndRemovedNodes().getRemoved()) {
try (Cursor<NodeItem> node = storeStatement.acquireSingleNodeCursor(nodeId)) {
if (node.next()) {
Lock lock = node.get().lock();
try (Cursor<PropertyItem> properties = storeStatement.acquirePropertyCursor(node.get().nextPropertyId(), lock)) {
while (properties.next()) {
removedNodeProperties.add(new NodePropertyEntryView(nodeId, store.propertyKeyGetName(properties.get().propertyKeyId()), null, properties.get().value()));
}
}
node.get().labels().visitKeys(labelId -> {
removedLabels.add(new LabelEntryView(nodeId, store.labelGetName(labelId)));
return false;
});
}
}
}
for (long relId : state.addedAndRemovedRelationships().getRemoved()) {
Relationship relationshipProxy = relationship(relId);
try (Cursor<RelationshipItem> relationship = storeStatement.acquireSingleRelationshipCursor(relId)) {
if (relationship.next()) {
Lock lock = relationship.get().lock();
try (Cursor<PropertyItem> properties = storeStatement.acquirePropertyCursor(relationship.get().nextPropertyId(), lock)) {
while (properties.next()) {
removedRelationshipProperties.add(new RelationshipPropertyEntryView(relationshipProxy, store.propertyKeyGetName(properties.get().propertyKeyId()), null, properties.get().value()));
}
}
}
}
}
for (NodeState nodeState : state.modifiedNodes()) {
Iterator<StorageProperty> added = nodeState.addedAndChangedProperties();
while (added.hasNext()) {
DefinedProperty property = (DefinedProperty) added.next();
assignedNodeProperties.add(new NodePropertyEntryView(nodeState.getId(), store.propertyKeyGetName(property.propertyKeyId()), property.value(), committedValue(nodeState, property.propertyKeyId())));
}
Iterator<Integer> removed = nodeState.removedProperties();
while (removed.hasNext()) {
Integer property = removed.next();
removedNodeProperties.add(new NodePropertyEntryView(nodeState.getId(), store.propertyKeyGetName(property), null, committedValue(nodeState, property)));
}
ReadableDiffSets<Integer> labels = nodeState.labelDiffSets();
for (Integer label : labels.getAdded()) {
assignedLabels.add(new LabelEntryView(nodeState.getId(), store.labelGetName(label)));
}
for (Integer label : labels.getRemoved()) {
removedLabels.add(new LabelEntryView(nodeState.getId(), store.labelGetName(label)));
}
}
for (RelationshipState relState : state.modifiedRelationships()) {
Relationship relationship = relationship(relState.getId());
Iterator<StorageProperty> added = relState.addedAndChangedProperties();
while (added.hasNext()) {
DefinedProperty property = (DefinedProperty) added.next();
assignedRelationshipProperties.add(new RelationshipPropertyEntryView(relationship, store.propertyKeyGetName(property.propertyKeyId()), property.value(), committedValue(relState, property.propertyKeyId())));
}
Iterator<Integer> removed = relState.removedProperties();
while (removed.hasNext()) {
Integer property = removed.next();
removedRelationshipProperties.add(new RelationshipPropertyEntryView(relationship, store.propertyKeyGetName(property), null, committedValue(relState, property)));
}
}
} catch (PropertyKeyIdNotFoundKernelException | LabelNotFoundKernelException e) {
throw new IllegalStateException("An entity that does not exist was modified.", e);
}
}
use of org.neo4j.storageengine.api.NodeItem 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.NodeItem in project neo4j by neo4j.
the class KernelIT method txReturnsCorrectIdWhenReadOnly.
@Test
public void txReturnsCorrectIdWhenReadOnly() throws Exception {
executeDummyTxs(db, 42);
KernelTransaction tx = kernel.newTransaction(KernelTransaction.Type.implicit, AUTH_DISABLED);
try (Statement statement = tx.acquireStatement();
Cursor<NodeItem> cursor = statement.readOperations().nodeCursorById(1)) {
}
tx.success();
assertEquals(KernelTransaction.READ_ONLY, tx.closeTransaction());
assertFalse(tx.isOpen());
}
use of org.neo4j.storageengine.api.NodeItem in project neo4j by neo4j.
the class ConstraintEnforcingEntityOperations method nodeAddLabel.
@Override
public boolean nodeAddLabel(KernelStatement state, long nodeId, int labelId) throws EntityNotFoundException, ConstraintValidationException {
try (Cursor<NodeItem> cursor = nodeCursorById(state, nodeId)) {
NodeItem node = cursor.get();
Iterator<ConstraintDescriptor> constraints = schemaReadOperations.constraintsGetForLabel(state, labelId);
while (constraints.hasNext()) {
ConstraintDescriptor constraint = constraints.next();
if (constraint.type() == UNIQUE) {
UniquenessConstraintDescriptor uniqueConstraint = (UniquenessConstraintDescriptor) constraint;
ExactPredicate[] propertyValues = getAllPropertyValues(state, uniqueConstraint.schema(), node);
if (propertyValues != null) {
validateNoExistingNodeWithExactValues(state, uniqueConstraint, propertyValues, node.id());
}
}
}
}
return entityWriteOperations.nodeAddLabel(state, nodeId, labelId);
}
Aggregations