Search in sources :

Example 66 with ReadOperations

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);
}
Also used : ReadOperations(org.neo4j.kernel.api.ReadOperations) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) Test(org.junit.Test)

Example 67 with ReadOperations

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());
}
Also used : ReadOperations(org.neo4j.kernel.api.ReadOperations) DataWriteOperations(org.neo4j.kernel.api.DataWriteOperations) Statement(org.neo4j.kernel.api.Statement) Test(org.junit.Test)

Example 68 with ReadOperations

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())));
    }
}
Also used : ReadOperations(org.neo4j.kernel.api.ReadOperations) DefinedProperty(org.neo4j.kernel.api.properties.DefinedProperty) Statement(org.neo4j.kernel.api.Statement) Test(org.junit.Test)

Example 69 with ReadOperations

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());
}
Also used : ReadOperations(org.neo4j.kernel.api.ReadOperations) DataWriteOperations(org.neo4j.kernel.api.DataWriteOperations) Statement(org.neo4j.kernel.api.Statement) Test(org.junit.Test)

Example 70 with ReadOperations

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());
}
Also used : ReadOperations(org.neo4j.kernel.api.ReadOperations) Statement(org.neo4j.kernel.api.Statement) Test(org.junit.Test)

Aggregations

ReadOperations (org.neo4j.kernel.api.ReadOperations)73 Test (org.junit.Test)52 Statement (org.neo4j.kernel.api.Statement)37 NewIndexDescriptor (org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)22 SchemaWriteOperations (org.neo4j.kernel.api.SchemaWriteOperations)9 KeyReadOperations (org.neo4j.kernel.impl.api.operations.KeyReadOperations)8 IndexNotFoundKernelException (org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException)7 NotFoundException (org.neo4j.graphdb.NotFoundException)5 Transaction (org.neo4j.graphdb.Transaction)5 HashMap (java.util.HashMap)4 PrimitiveLongSet (org.neo4j.collection.primitive.PrimitiveLongSet)4 IndexDefinition (org.neo4j.graphdb.schema.IndexDefinition)4 DataWriteOperations (org.neo4j.kernel.api.DataWriteOperations)4 KernelIntegrationTest (org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest)4 ArrayList (java.util.ArrayList)3 Set (java.util.Set)3 PrimitiveLongIterator (org.neo4j.collection.primitive.PrimitiveLongIterator)3 Label (org.neo4j.graphdb.Label)3 RelationshipType (org.neo4j.graphdb.RelationshipType)3 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)3