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 nodeSetProperty.
@Override
public Property nodeSetProperty(KernelStatement state, long nodeId, DefinedProperty property) 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, property.propertyKeyId())) {
if (!properties.next()) {
autoIndexing.nodes().propertyAdded(ops, nodeId, property);
} else {
existingProperty = Property.property(properties.get().propertyKeyId(), properties.get().value());
autoIndexing.nodes().propertyChanged(ops, nodeId, existingProperty, property);
}
}
if (existingProperty == NO_SUCH_PROPERTY) {
state.txState().nodeDoAddProperty(node.id(), property);
indexTxStateUpdater.onPropertyAdd(state, node, property);
return Property.noProperty(property.propertyKeyId(), EntityType.NODE, node.id());
} else {
state.txState().nodeDoChangeProperty(node.id(), existingProperty, property);
indexTxStateUpdater.onPropertyChange(state, node, existingProperty, property);
return existingProperty;
}
}
}
use of org.neo4j.kernel.api.DataWriteOperations in project neo4j by neo4j.
the class KernelTransactionSecurityContextTest method shouldAllowWriteAccessInWriteOnlyMode.
@Test
public void shouldAllowWriteAccessInWriteOnlyMode() throws Throwable {
// Given
KernelTransactionImplementation tx = newTransaction(AnonymousContext.writeOnly());
// When
DataWriteOperations writes = tx.acquireStatement().dataWriteOperations();
// Then
assertNotNull(writes);
}
use of org.neo4j.kernel.api.DataWriteOperations in project neo4j by neo4j.
the class TransactionHookIT method shouldRecieveTxStateOnCommit.
@Test
public void shouldRecieveTxStateOnCommit() throws Exception {
// Given
TransactionHook hook = mock(TransactionHook.class);
kernel.registerTransactionHook(hook);
// When
DataWriteOperations ops = dataWriteOperationsInNewTransaction();
ops.nodeCreate();
commit();
// Then
verify(hook).beforeCommit(any(ReadableTransactionState.class), any(KernelTransaction.class), any(StoreReadLayer.class), any(StorageStatement.class));
verify(hook).afterCommit(any(ReadableTransactionState.class), any(KernelTransaction.class), any(TransactionHook.Outcome.class));
verifyNoMoreInteractions(hook);
}
Aggregations