Search in sources :

Example 61 with ReadOperations

use of org.neo4j.kernel.api.ReadOperations in project neo4j by neo4j.

the class RelationshipIT method assertRelsInSeparateTx.

private void assertRelsInSeparateTx(final long refNode, final Direction both, final long... longs) throws InterruptedException, ExecutionException, TimeoutException {
    assertTrue(otherThread.execute(state -> {
        try (Transaction tx = db.beginTx()) {
            ReadOperations stmt = statementContextSupplier.get().readOperations();
            assertRels(stmt.nodeGetRelationships(refNode, both), longs);
        }
        return true;
    }).get(10, TimeUnit.SECONDS));
}
Also used : ReadOperations(org.neo4j.kernel.api.ReadOperations) Transaction(org.neo4j.graphdb.Transaction)

Example 62 with ReadOperations

use of org.neo4j.kernel.api.ReadOperations in project neo4j by neo4j.

the class UniquenessConstraintValidationIT method addingUniqueNodeWithUnrelatedValueShouldNotAffectLookup.

@Test
public void addingUniqueNodeWithUnrelatedValueShouldNotAffectLookup() throws Exception {
    // given
    createConstraint("Person", "id");
    long ourNode;
    {
        Statement statement = statementInNewTransaction(AnonymousContext.writeToken());
        ourNode = createLabeledNode(statement, "Person", "id", 1);
        commit();
    }
    Statement statement = statementInNewTransaction(AnonymousContext.writeToken());
    ReadOperations readOps = statement.readOperations();
    int person = readOps.labelGetForName("Person");
    int propId = readOps.propertyKeyGetForName("id");
    NewIndexDescriptor idx = readOps.uniqueIndexGetForLabelAndPropertyKey(new NodePropertyDescriptor(person, propId));
    // when
    createLabeledNode(statement, "Person", "id", 2);
    // then I should find the original node
    assertThat(readOps.nodeGetFromUniqueIndexSeek(idx, exact(propId, 1)), equalTo(ourNode));
}
Also used : ReadOperations(org.neo4j.kernel.api.ReadOperations) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) NodePropertyDescriptor(org.neo4j.kernel.api.schema.NodePropertyDescriptor) Statement(org.neo4j.kernel.api.Statement) Test(org.junit.Test)

Example 63 with ReadOperations

use of org.neo4j.kernel.api.ReadOperations in project neo4j by neo4j.

the class UniquenessConstraintValidationIT method unrelatedNodesWithSamePropertyShouldNotInterfereWithUniquenessCheck.

@Test
public void unrelatedNodesWithSamePropertyShouldNotInterfereWithUniquenessCheck() throws Exception {
    // given
    createConstraint("Person", "id");
    long ourNode;
    {
        Statement statement = statementInNewTransaction(AnonymousContext.writeToken());
        ourNode = createLabeledNode(statement, "Person", "id", 1);
        createLabeledNode(statement, "Item", "id", 2);
        commit();
    }
    Statement statement = statementInNewTransaction(AnonymousContext.writeToken());
    ReadOperations readOps = statement.readOperations();
    int person = readOps.labelGetForName("Person");
    int propId = readOps.propertyKeyGetForName("id");
    NewIndexDescriptor idx = readOps.uniqueIndexGetForLabelAndPropertyKey(new NodePropertyDescriptor(person, propId));
    // when
    createLabeledNode(statement, "Item", "id", 2);
    // then I should find the original node
    assertThat(readOps.nodeGetFromUniqueIndexSeek(idx, exact(propId, 1)), equalTo(ourNode));
}
Also used : ReadOperations(org.neo4j.kernel.api.ReadOperations) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) NodePropertyDescriptor(org.neo4j.kernel.api.schema.NodePropertyDescriptor) Statement(org.neo4j.kernel.api.Statement) Test(org.junit.Test)

Example 64 with ReadOperations

use of org.neo4j.kernel.api.ReadOperations in project neo4j by neo4j.

the class NodeGetUniqueFromIndexSeekIT method shouldCompositeFindMatchingNode.

@Test
public void shouldCompositeFindMatchingNode() throws Exception {
    // given
    NewIndexDescriptor index = createUniquenessConstraint(labelId, propertyId1, propertyId2);
    String value1 = "value1";
    String value2 = "value2";
    long nodeId = createNodeWithValues(value1, value2);
    // when looking for it
    ReadOperations readOperations = readOperationsInNewTransaction();
    long foundId = readOperations.nodeGetFromUniqueIndexSeek(index, exact(propertyId1, value1), exact(propertyId2, value2));
    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 65 with ReadOperations

use of org.neo4j.kernel.api.ReadOperations in project neo4j by neo4j.

the class NodeGetUniqueFromIndexSeekIT method shouldNotFindNonMatchingNode.

@Test
public void shouldNotFindNonMatchingNode() throws Exception {
    // given
    NewIndexDescriptor index = createUniquenessConstraint(labelId, propertyId1);
    String value = "value";
    createNodeWithValue("other_" + value);
    // when looking for it
    ReadOperations readOperations = readOperationsInNewTransaction();
    long foundId = readOperations.nodeGetFromUniqueIndexSeek(index, exact(propertyId1, value));
    commit();
    // then
    assertTrue("Non-matching created node was found", isNoSuchNode(foundId));
}
Also used : ReadOperations(org.neo4j.kernel.api.ReadOperations) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) 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