use of org.neo4j.kernel.api.Statement in project neo4j by neo4j.
the class PropertyIT method shouldSetNodePropertyValue.
@Test
public void shouldSetNodePropertyValue() throws Exception {
// GIVEN
String value = "bozo";
Statement statement = statementInNewTransaction(AnonymousContext.writeToken());
long nodeId = statement.dataWriteOperations().nodeCreate();
// WHEN
int propertyKeyId = statement.tokenWriteOperations().propertyKeyGetOrCreateForName("clown");
statement.dataWriteOperations().nodeSetProperty(nodeId, stringProperty(propertyKeyId, value));
// THEN
assertEquals(value, statement.readOperations().nodeGetProperty(nodeId, propertyKeyId));
// WHEN
commit();
ReadOperations readOperations = readOperationsInNewTransaction();
// THEN
assertEquals(value, readOperations.nodeGetProperty(nodeId, propertyKeyId));
}
use of org.neo4j.kernel.api.Statement 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.Statement in project neo4j by neo4j.
the class PropertyIT method shouldListAllPropertyKeys.
@Test
public void shouldListAllPropertyKeys() throws Exception {
// given
dbWithNoCache();
Statement statement = statementInNewTransaction(AnonymousContext.writeToken());
int prop1 = statement.tokenWriteOperations().propertyKeyGetOrCreateForName("prop1");
int prop2 = statement.tokenWriteOperations().propertyKeyGetOrCreateForName("prop2");
// when
Iterator<Token> propIdsBeforeCommit = statement.readOperations().propertyKeyGetAllTokens();
// then
assertThat(asCollection(propIdsBeforeCommit), hasItems(new Token("prop1", prop1), new Token("prop2", prop2)));
// when
commit();
ReadOperations readOperations = readOperationsInNewTransaction();
Iterator<Token> propIdsAfterCommit = readOperations.propertyKeyGetAllTokens();
// then
assertThat(asCollection(propIdsAfterCommit), hasItems(new Token("prop1", prop1), new Token("prop2", prop2)));
}
use of org.neo4j.kernel.api.Statement in project neo4j by neo4j.
the class PropertyIT method shouldRemoveSetNodePropertyAcrossTransactions.
@Test
public void shouldRemoveSetNodePropertyAcrossTransactions() throws Exception {
// GIVEN
int propertyKeyId;
long nodeId;
{
Statement statement = statementInNewTransaction(AnonymousContext.writeToken());
nodeId = statement.dataWriteOperations().nodeCreate();
propertyKeyId = statement.tokenWriteOperations().propertyKeyGetOrCreateForName("clown");
statement.dataWriteOperations().nodeSetProperty(nodeId, stringProperty(propertyKeyId, "bozo"));
commit();
}
{
Statement statement = statementInNewTransaction(AnonymousContext.writeToken());
// WHEN
Object previous = statement.dataWriteOperations().nodeRemoveProperty(nodeId, propertyKeyId).value();
// THEN
assertEquals("bozo", previous);
assertThat(statement.readOperations().nodeGetProperty(nodeId, propertyKeyId), nullValue());
// WHEN
commit();
}
// THEN
ReadOperations readOperations = readOperationsInNewTransaction();
assertThat(readOperations.nodeGetProperty(nodeId, propertyKeyId), nullValue());
}
use of org.neo4j.kernel.api.Statement in project neo4j by neo4j.
the class KernelIT method transactionStateShouldRemovePreviouslyAddedLabel.
@Test
public void transactionStateShouldRemovePreviouslyAddedLabel() throws Exception {
Transaction tx = db.beginTx();
Statement statement = statementContextSupplier.get();
// WHEN
Node node = db.createNode();
int labelId1 = statement.tokenWriteOperations().labelGetOrCreateForName("labello1");
int labelId2 = statement.tokenWriteOperations().labelGetOrCreateForName("labello2");
statement.dataWriteOperations().nodeAddLabel(node.getId(), labelId1);
statement.dataWriteOperations().nodeAddLabel(node.getId(), labelId2);
statement.dataWriteOperations().nodeRemoveLabel(node.getId(), labelId2);
statement.close();
tx.success();
tx.close();
// THEN
tx = db.beginTx();
statement = statementContextSupplier.get();
assertEquals(PrimitiveIntCollections.asSet(new int[] { labelId1 }), PrimitiveIntCollections.asSet(statement.readOperations().nodeGetLabels(node.getId())));
tx.close();
}
Aggregations