use of org.neo4j.kernel.api.DataWriteOperations in project neo4j by neo4j.
the class NodeGetUniqueFromIndexSeekIT method createNodeWithValues.
private long createNodeWithValues(String value1, String value2) throws KernelException {
DataWriteOperations dataStatement = dataWriteOperationsInNewTransaction();
long nodeId = dataStatement.nodeCreate();
dataStatement.nodeAddLabel(nodeId, labelId);
dataStatement.nodeSetProperty(nodeId, Property.stringProperty(propertyId1, value1));
dataStatement.nodeSetProperty(nodeId, Property.stringProperty(propertyId2, value2));
commit();
return nodeId;
}
use of org.neo4j.kernel.api.DataWriteOperations in project neo4j by neo4j.
the class PropertyIT method shouldBeAbleToRemoveResetAndTwiceRemovePropertyOnNode.
@Test
public void shouldBeAbleToRemoveResetAndTwiceRemovePropertyOnNode() throws Exception {
// given
Statement statement = statementInNewTransaction(AnonymousContext.writeToken());
int prop = statement.tokenWriteOperations().propertyKeyGetOrCreateForName("foo");
long node = statement.dataWriteOperations().nodeCreate();
statement.dataWriteOperations().nodeSetProperty(node, property(prop, "bar"));
commit();
// when
DataWriteOperations dataWriteOperations = dataWriteOperationsInNewTransaction();
dataWriteOperations.nodeRemoveProperty(node, prop);
dataWriteOperations.nodeSetProperty(node, property(prop, "bar"));
dataWriteOperations.nodeRemoveProperty(node, prop);
dataWriteOperations.nodeRemoveProperty(node, prop);
commit();
// then
ReadOperations readOperations = readOperationsInNewTransaction();
assertThat(readOperations.nodeGetProperty(node, prop), nullValue());
}
use of org.neo4j.kernel.api.DataWriteOperations in project neo4j by neo4j.
the class StateHandlingStatementOperations method nodeRemoveProperty.
@Override
public Property nodeRemoveProperty(KernelStatement state, long nodeId, int propertyKeyId) throws EntityNotFoundException, InvalidTransactionTypeKernelException, AutoIndexingKernelException {
DataWriteOperations ops = state.dataWriteOperations();
try (Cursor<NodeItem> cursor = nodeCursorById(state, nodeId)) {
NodeItem node = cursor.get();
DefinedProperty existingProperty = NO_SUCH_PROPERTY;
try (Cursor<PropertyItem> properties = nodeGetPropertyCursor(state, node, propertyKeyId)) {
if (properties.next()) {
existingProperty = Property.property(properties.get().propertyKeyId(), properties.get().value());
autoIndexing.nodes().propertyRemoved(ops, nodeId, propertyKeyId);
state.txState().nodeDoRemoveProperty(node.id(), existingProperty);
indexTxStateUpdater.onPropertyRemove(state, node, existingProperty);
}
}
if (existingProperty == NO_SUCH_PROPERTY) {
return Property.noProperty(propertyKeyId, EntityType.NODE, node.id());
}
return existingProperty;
}
}
use of org.neo4j.kernel.api.DataWriteOperations in project neo4j by neo4j.
the class StateHandlingStatementOperations method relationshipRemoveProperty.
@Override
public Property relationshipRemoveProperty(KernelStatement state, long relationshipId, int propertyKeyId) throws EntityNotFoundException, InvalidTransactionTypeKernelException, AutoIndexingKernelException {
DataWriteOperations ops = state.dataWriteOperations();
try (Cursor<RelationshipItem> cursor = relationshipCursorById(state, relationshipId)) {
RelationshipItem relationship = cursor.get();
Property existingProperty;
try (Cursor<PropertyItem> properties = relationshipGetPropertyCursor(state, relationship, propertyKeyId)) {
if (!properties.next()) {
existingProperty = Property.noProperty(propertyKeyId, EntityType.RELATIONSHIP, relationship.id());
} else {
existingProperty = Property.property(properties.get().propertyKeyId(), properties.get().value());
autoIndexing.relationships().propertyRemoved(ops, relationshipId, propertyKeyId);
state.txState().relationshipDoRemoveProperty(relationship.id(), (DefinedProperty) existingProperty);
}
}
return existingProperty;
}
}
use of org.neo4j.kernel.api.DataWriteOperations in project neo4j by neo4j.
the class StateHandlingStatementOperations method relationshipSetProperty.
@Override
public Property relationshipSetProperty(KernelStatement state, long relationshipId, DefinedProperty property) throws EntityNotFoundException, InvalidTransactionTypeKernelException, AutoIndexingKernelException {
DataWriteOperations ops = state.dataWriteOperations();
try (Cursor<RelationshipItem> cursor = relationshipCursorById(state, relationshipId)) {
RelationshipItem relationship = cursor.get();
Property existingProperty;
try (Cursor<PropertyItem> properties = relationshipGetPropertyCursor(state, relationship, property.propertyKeyId())) {
if (!properties.next()) {
autoIndexing.relationships().propertyAdded(ops, relationshipId, property);
existingProperty = Property.noProperty(property.propertyKeyId(), EntityType.RELATIONSHIP, relationship.id());
} else {
existingProperty = Property.property(properties.get().propertyKeyId(), properties.get().value());
autoIndexing.relationships().propertyChanged(ops, relationshipId, existingProperty, property);
}
}
state.txState().relationshipDoReplaceProperty(relationship.id(), existingProperty, property);
return existingProperty;
}
}
Aggregations