use of org.neo4j.kernel.api.ReadOperations in project neo4j by neo4j.
the class NodeGetUniqueFromIndexSeekIT method shouldFindMatchingNode.
// nodeGetUniqueWithLabelAndProperty(statement, :Person, foo=val)
//
// Given we have a unique constraint on :Person(foo)
// (If not, throw)
//
// If there is a node n with n:Person and n.foo == val, return it
// If there is no such node, return ?
//
// Ensure that if that method is called again with the same argument from some other transaction,
// that transaction blocks until this transaction has finished
//
// [X] must return node from the unique index with the given property
// [X] must return NO_SUCH_NODE if it is not in the index for the given property
//
// must block other transactions that try to call it with the same arguments
@Test
public void shouldFindMatchingNode() throws Exception {
// given
NewIndexDescriptor index = createUniquenessConstraint(labelId, propertyId1);
String value = "value";
long nodeId = createNodeWithValue(value);
// when looking for it
ReadOperations readOperations = readOperationsInNewTransaction();
int propertyId = index.schema().getPropertyId();
long foundId = readOperations.nodeGetFromUniqueIndexSeek(index, exact(propertyId, value));
commit();
// then
assertTrue("Created node was not found", nodeId == foundId);
}
use of org.neo4j.kernel.api.ReadOperations in project neo4j by neo4j.
the class PropertyIT method shouldBeAbleToRemoveResetAndTwiceRemovePropertyOnRelationship.
@Test
public void shouldBeAbleToRemoveResetAndTwiceRemovePropertyOnRelationship() throws Exception {
// given
Statement statement = statementInNewTransaction(AnonymousContext.writeToken());
int prop = statement.tokenWriteOperations().propertyKeyGetOrCreateForName("foo");
int type = statement.tokenWriteOperations().relationshipTypeGetOrCreateForName("RELATED");
long startNodeId = statement.dataWriteOperations().nodeCreate();
long endNodeId = statement.dataWriteOperations().nodeCreate();
long rel = statement.dataWriteOperations().relationshipCreate(type, startNodeId, endNodeId);
statement.dataWriteOperations().relationshipSetProperty(rel, property(prop, "bar"));
commit();
// when
DataWriteOperations dataWriteOperations = dataWriteOperationsInNewTransaction();
dataWriteOperations.relationshipRemoveProperty(rel, prop);
dataWriteOperations.relationshipSetProperty(rel, property(prop, "bar"));
dataWriteOperations.relationshipRemoveProperty(rel, prop);
dataWriteOperations.relationshipRemoveProperty(rel, prop);
commit();
// then
ReadOperations readOperations = readOperationsInNewTransaction();
assertThat(readOperations.relationshipGetProperty(rel, prop), nullValue());
}
use of org.neo4j.kernel.api.ReadOperations in project neo4j by neo4j.
the class PropertyIT method shouldRemoveSetExistingProperty.
@Test
public void shouldRemoveSetExistingProperty() throws Exception {
// GIVEN
dbWithNoCache();
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();
}
DefinedProperty newProperty = stringProperty(propertyKeyId, "ozob");
{
Statement statement = statementInNewTransaction(AnonymousContext.writeToken());
// WHEN
statement.dataWriteOperations().nodeRemoveProperty(nodeId, propertyKeyId);
statement.dataWriteOperations().nodeSetProperty(nodeId, newProperty);
// THEN
assertThat(statement.readOperations().nodeGetProperty(nodeId, propertyKeyId), equalTo(newProperty.value()));
// WHEN
commit();
}
// THEN
{
ReadOperations readOperations = readOperationsInNewTransaction();
assertThat(readOperations.nodeGetProperty(nodeId, propertyKeyId), equalTo(newProperty.value()));
assertThat(toList(readOperations.nodeGetPropertyKeys(nodeId)), equalTo(asList(newProperty.propertyKeyId())));
}
}
use of org.neo4j.kernel.api.ReadOperations in project neo4j by neo4j.
the class PropertyIT method shouldRollbackSetNodePropertyValue.
@Test
public void shouldRollbackSetNodePropertyValue() throws Exception {
// GIVEN
Statement statement = statementInNewTransaction(AnonymousContext.writeToken());
long nodeId = statement.dataWriteOperations().nodeCreate();
int propertyKeyId = statement.tokenWriteOperations().propertyKeyGetOrCreateForName("clown");
commit();
// WHEN
DataWriteOperations dataWriteOperations = dataWriteOperationsInNewTransaction();
dataWriteOperations.nodeSetProperty(nodeId, stringProperty(propertyKeyId, "bozo"));
rollback();
// THEN
ReadOperations readOperations = readOperationsInNewTransaction();
assertThat(readOperations.nodeHasProperty(nodeId, propertyKeyId), is(false));
assertThat(readOperations.nodeGetProperty(nodeId, propertyKeyId), nullValue());
}
use of org.neo4j.kernel.api.ReadOperations in project neo4j by neo4j.
the class PropertyIT method shouldRemoveSetNodeProperty.
@Test
public void shouldRemoveSetNodeProperty() throws Exception {
// GIVEN
Statement statement = statementInNewTransaction(AnonymousContext.writeToken());
long nodeId = statement.dataWriteOperations().nodeCreate();
int propertyKeyId = statement.tokenWriteOperations().propertyKeyGetOrCreateForName("clown");
statement.dataWriteOperations().nodeSetProperty(nodeId, stringProperty(propertyKeyId, "bozo"));
// WHEN
statement.dataWriteOperations().nodeRemoveProperty(nodeId, propertyKeyId);
// THEN
assertThat(statement.readOperations().nodeGetProperty(nodeId, propertyKeyId), nullValue());
// WHEN
commit();
// THEN
ReadOperations readOperations = readOperationsInNewTransaction();
assertThat(readOperations.nodeGetProperty(nodeId, propertyKeyId), nullValue());
}
Aggregations