Search in sources :

Example 56 with ReadOperations

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

the class DataStatementArgumentVerificationTest method shouldAlwaysReturnFalseFromNodeHasLabelForNoSuchLabelConstant.

@Test
public void shouldAlwaysReturnFalseFromNodeHasLabelForNoSuchLabelConstant() throws Exception {
    // given
    ReadOperations statement = stubStatement();
    // when
    boolean hasLabel = statement.nodeHasLabel(17, StatementConstants.NO_SUCH_LABEL);
    // then
    assertFalse("should not contain any ids", hasLabel);
}
Also used : ReadOperations(org.neo4j.kernel.api.ReadOperations) Test(org.junit.Test)

Example 57 with ReadOperations

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

the class IndexCRUDIT method addingANodeWithPropertyShouldGetIndexed.

@Test
public void addingANodeWithPropertyShouldGetIndexed() throws Exception {
    // Given
    String indexProperty = "indexProperty";
    GatheringIndexWriter writer = newWriter();
    createIndex(db, myLabel, indexProperty);
    // When
    int value1 = 12;
    String otherProperty = "otherProperty";
    int otherValue = 17;
    Node node = createNode(map(indexProperty, value1, otherProperty, otherValue), myLabel);
    // Then, for now, this should trigger two NodePropertyUpdates
    try (Transaction tx = db.beginTx()) {
        ReadOperations readOperations = ctxSupplier.get().readOperations();
        int propertyKey1 = readOperations.propertyKeyGetForName(indexProperty);
        int label = readOperations.labelGetForName(myLabel.name());
        LabelSchemaDescriptor descriptor = SchemaDescriptorFactory.forLabel(label, propertyKey1);
        assertThat(writer.updatesCommitted, equalTo(asSet(IndexEntryUpdate.add(node.getId(), descriptor, value1))));
        tx.success();
    }
// We get two updates because we both add a label and a property to be indexed
// in the same transaction, in the future, we should optimize this down to
// one NodePropertyUpdate.
}
Also used : ReadOperations(org.neo4j.kernel.api.ReadOperations) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) LabelSchemaDescriptor(org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor) Test(org.junit.Test)

Example 58 with ReadOperations

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

the class IndexIT method addIndexRuleInATransaction.

@Test
public void addIndexRuleInATransaction() throws Exception {
    // GIVEN
    SchemaWriteOperations schemaWriteOperations = schemaWriteOperationsInNewTransaction();
    // WHEN
    NewIndexDescriptor expectedRule = schemaWriteOperations.indexCreate(SchemaBoundary.map(descriptor));
    commit();
    // THEN
    ReadOperations readOperations = readOperationsInNewTransaction();
    assertEquals(asSet(expectedRule), asSet(readOperations.indexesGetForLabel(labelId)));
    assertEquals(expectedRule, readOperations.indexGetForLabelAndPropertyKey(descriptor));
    commit();
}
Also used : ReadOperations(org.neo4j.kernel.api.ReadOperations) SchemaWriteOperations(org.neo4j.kernel.api.SchemaWriteOperations) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) Test(org.junit.Test) KernelIntegrationTest(org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest)

Example 59 with ReadOperations

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

the class RelationshipIT method askingForNonExistantReltypeOnDenseNodeShouldNotCorruptState.

@Test
public void askingForNonExistantReltypeOnDenseNodeShouldNotCorruptState() throws Exception {
    // Given a dense node with one type of rels
    long[] rels = new long[200];
    long refNode;
    int relTypeTheNodeDoesUse, relTypeTheNodeDoesNotUse;
    {
        Statement statement = statementInNewTransaction(AnonymousContext.writeToken());
        relTypeTheNodeDoesUse = statement.tokenWriteOperations().relationshipTypeGetOrCreateForName("Type1");
        relTypeTheNodeDoesNotUse = statement.tokenWriteOperations().relationshipTypeGetOrCreateForName("Type2");
        refNode = statement.dataWriteOperations().nodeCreate();
        long otherNode = statement.dataWriteOperations().nodeCreate();
        for (int i = 0; i < rels.length; i++) {
            rels[i] = statement.dataWriteOperations().relationshipCreate(relTypeTheNodeDoesUse, refNode, otherNode);
        }
        commit();
    }
    ReadOperations stmt = readOperationsInNewTransaction();
    // When I've asked for rels that the node does not have
    assertRels(stmt.nodeGetRelationships(refNode, Direction.INCOMING, new int[] { relTypeTheNodeDoesNotUse }));
    // Then the node should still load the real rels
    assertRels(stmt.nodeGetRelationships(refNode, Direction.BOTH, new int[] { relTypeTheNodeDoesUse }), rels);
}
Also used : ReadOperations(org.neo4j.kernel.api.ReadOperations) Statement(org.neo4j.kernel.api.Statement) Test(org.junit.Test)

Example 60 with ReadOperations

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

the class RelationshipIT method shouldListRelationshipsInCurrentAndSubsequentTx.

@Test
public void shouldListRelationshipsInCurrentAndSubsequentTx() throws Exception {
    // given
    Statement statement = statementInNewTransaction(AnonymousContext.writeToken());
    int relType1 = statement.tokenWriteOperations().relationshipTypeGetOrCreateForName("Type1");
    int relType2 = statement.tokenWriteOperations().relationshipTypeGetOrCreateForName("Type2");
    long refNode = statement.dataWriteOperations().nodeCreate();
    long otherNode = statement.dataWriteOperations().nodeCreate();
    long fromRefToOther1 = statement.dataWriteOperations().relationshipCreate(relType1, refNode, otherNode);
    long fromRefToOther2 = statement.dataWriteOperations().relationshipCreate(relType2, refNode, otherNode);
    long fromOtherToRef = statement.dataWriteOperations().relationshipCreate(relType1, otherNode, refNode);
    long fromRefToRef = statement.dataWriteOperations().relationshipCreate(relType2, refNode, refNode);
    long endNode = statement.dataWriteOperations().nodeCreate();
    long fromRefToThird = statement.dataWriteOperations().relationshipCreate(relType2, refNode, endNode);
    // when & then
    assertRels(statement.readOperations().nodeGetRelationships(refNode, BOTH), fromRefToOther1, fromRefToOther2, fromRefToRef, fromRefToThird, fromOtherToRef);
    assertRels(statement.readOperations().nodeGetRelationships(refNode, BOTH, new int[] { relType1 }), fromRefToOther1, fromOtherToRef);
    assertRels(statement.readOperations().nodeGetRelationships(refNode, BOTH, new int[] { relType1, relType2 }), fromRefToOther1, fromRefToOther2, fromRefToRef, fromRefToThird, fromOtherToRef);
    assertRels(statement.readOperations().nodeGetRelationships(refNode, INCOMING), fromOtherToRef);
    assertRels(statement.readOperations().nodeGetRelationships(refNode, INCOMING, new int[] { relType1 }));
    assertRels(statement.readOperations().nodeGetRelationships(refNode, OUTGOING, new int[] { relType1, relType2 }), fromRefToOther1, fromRefToOther2, fromRefToThird, fromRefToRef);
    // when
    commit();
    ReadOperations readOperations = readOperationsInNewTransaction();
    // when & then
    assertRels(readOperations.nodeGetRelationships(refNode, BOTH), fromRefToOther1, fromRefToOther2, fromRefToRef, fromRefToThird, fromOtherToRef);
    assertRels(readOperations.nodeGetRelationships(refNode, BOTH, new int[] { relType1 }), fromRefToOther1, fromOtherToRef);
    assertRels(readOperations.nodeGetRelationships(refNode, BOTH, new int[] { relType1, relType2 }), fromRefToOther1, fromRefToOther2, fromRefToRef, fromRefToThird, fromOtherToRef);
    assertRels(readOperations.nodeGetRelationships(refNode, INCOMING), fromOtherToRef);
    assertRels(readOperations.nodeGetRelationships(refNode, INCOMING, new int[] { relType1 }));
    assertRels(readOperations.nodeGetRelationships(refNode, OUTGOING, new int[] { relType1, relType2 }), fromRefToOther1, fromRefToOther2, fromRefToThird, fromRefToRef);
}
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