use of org.neo4j.kernel.api.Statement in project neo4j by neo4j.
the class LabelIT method shouldListAllLabels.
@Test
public void shouldListAllLabels() throws Exception {
// given
Statement statement = statementInNewTransaction(AnonymousContext.writeToken());
int label1Id = statement.tokenWriteOperations().labelGetOrCreateForName("label1");
int label2Id = statement.tokenWriteOperations().labelGetOrCreateForName("label2");
// when
Iterator<Token> labelIdsBeforeCommit = statement.readOperations().labelsGetAllTokens();
// then
assertThat(asCollection(labelIdsBeforeCommit), hasItems(new Token("label1", label1Id), new Token("label2", label2Id)));
// when
commit();
ReadOperations readOperations = readOperationsInNewTransaction();
Iterator<Token> labelIdsAfterCommit = readOperations.labelsGetAllTokens();
// then
assertThat(asCollection(labelIdsAfterCommit), hasItems(new Token("label1", label1Id), new Token("label2", label2Id)));
}
use of org.neo4j.kernel.api.Statement in project neo4j by neo4j.
the class PropertyIT method nodeHasNotPropertyIfUnset.
@Test
public void nodeHasNotPropertyIfUnset() throws Exception {
// GIVEN
Statement statement = statementInNewTransaction(AnonymousContext.writeToken());
long nodeId = statement.dataWriteOperations().nodeCreate();
// WHEN
int propertyKeyId = statement.tokenWriteOperations().propertyKeyGetOrCreateForName("clown");
// THEN
assertThat(statement.readOperations().nodeHasProperty(nodeId, propertyKeyId), is(false));
assertThat(statement.readOperations().nodeGetProperty(nodeId, propertyKeyId), nullValue());
// WHEN
commit();
ReadOperations readOperations = readOperationsInNewTransaction();
// THEN
assertThat(readOperations.nodeHasProperty(nodeId, propertyKeyId), is(false));
assertThat(readOperations.nodeGetProperty(nodeId, propertyKeyId), nullValue());
}
use of org.neo4j.kernel.api.Statement in project neo4j by neo4j.
the class PropertyIT method nodeHasPropertyIfSet.
@Test
public void nodeHasPropertyIfSet() throws Exception {
// GIVEN
Statement statement = statementInNewTransaction(AnonymousContext.writeToken());
long nodeId = statement.dataWriteOperations().nodeCreate();
// WHEN
int propertyKeyId = statement.tokenWriteOperations().propertyKeyGetOrCreateForName("clown");
statement.dataWriteOperations().nodeSetProperty(nodeId, stringProperty(propertyKeyId, "bozo"));
// THEN
assertThat(statement.readOperations().nodeHasProperty(nodeId, propertyKeyId), is(true));
assertThat(statement.readOperations().nodeGetProperty(nodeId, propertyKeyId), notNullValue());
// WHEN
commit();
ReadOperations readOperations = readOperationsInNewTransaction();
// THEN
assertThat(readOperations.nodeHasProperty(nodeId, propertyKeyId), is(true));
assertThat(readOperations.nodeGetProperty(nodeId, propertyKeyId), notNullValue());
}
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());
}
Aggregations