Search in sources :

Example 31 with TokenWrite

use of org.neo4j.internal.kernel.api.TokenWrite in project neo4j by neo4j.

the class CachingExpandIntoTest method shouldBeAbleToPreformAllCursorMethodsFromReused.

@Test
void shouldBeAbleToPreformAllCursorMethodsFromReused() throws KernelException {
    // given
    long start, end, r1, r2, r3;
    int t1, t2, t3;
    int prop;
    try (KernelTransaction tx = transaction()) {
        start = nodeWithDegree(tx, 43);
        end = nodeWithDegree(tx, 11);
        TokenWrite tokenWrite = tx.tokenWrite();
        t1 = tokenWrite.relationshipTypeGetOrCreateForName("R1");
        t2 = tokenWrite.relationshipTypeGetOrCreateForName("R2");
        t3 = tokenWrite.relationshipTypeGetOrCreateForName("R3");
        prop = tokenWrite.propertyKeyGetOrCreateForName("prop");
        Write write = tx.dataWrite();
        r1 = write.relationshipCreate(start, t1, end);
        r2 = write.relationshipCreate(start, t2, end);
        r3 = write.relationshipCreate(end, t3, start);
        write.relationshipSetProperty(r1, prop, stringValue("Relationship 1"));
        write.relationshipSetProperty(r2, prop, stringValue("Relationship 2"));
        write.relationshipSetProperty(r3, prop, stringValue("Relationship 3"));
        tx.commit();
    }
    try (KernelTransaction tx = transaction();
        NodeCursor nodes = tx.cursors().allocateNodeCursor(tx.cursorContext());
        RelationshipTraversalCursor traversal = tx.cursors().allocateRelationshipTraversalCursor(tx.cursorContext());
        PropertyCursor properties = tx.cursors().allocatePropertyCursor(tx.cursorContext(), tx.memoryTracker())) {
        int[] types = { t2, t3 };
        CachingExpandInto expandInto = new CachingExpandInto(tx.dataRead(), INCOMING, MEMORY_TRACKER);
        // Find r3 first time
        RelationshipTraversalCursor cursor = expandInto.connectingRelationships(nodes, traversal, start, types, end);
        assertTrue(cursor.next());
        assertThat(cursor.relationshipReference()).isEqualTo(r3);
        assertThat(cursor.sourceNodeReference()).isEqualTo(end);
        assertThat(cursor.targetNodeReference()).isEqualTo(start);
        assertThat(cursor.otherNodeReference()).isEqualTo(start);
        assertThat(cursor.type()).isEqualTo(t3);
        cursor.properties(properties);
        assertTrue(properties.next());
        assertThat(properties.propertyValue()).isEqualTo(stringValue("Relationship 3"));
        assertFalse(properties.next());
        assertFalse(cursor.next());
        // Find r3 second time
        cursor = expandInto.connectingRelationships(nodes, traversal, start, types, end);
        assertTrue(cursor.next());
        assertThat(cursor.relationshipReference()).isEqualTo(r3);
        assertThat(cursor.sourceNodeReference()).isEqualTo(end);
        assertThat(cursor.targetNodeReference()).isEqualTo(start);
        assertThat(cursor.otherNodeReference()).isEqualTo(start);
        assertThat(cursor.type()).isEqualTo(t3);
        cursor.properties(properties);
        assertTrue(properties.next());
        assertThat(properties.propertyValue()).isEqualTo(stringValue("Relationship 3"));
        assertFalse(properties.next());
        assertFalse(cursor.next());
        // Find r2 first time
        cursor = expandInto.connectingRelationships(nodes, traversal, end, types, start);
        assertTrue(cursor.next());
        assertThat(cursor.relationshipReference()).isEqualTo(r2);
        assertThat(cursor.sourceNodeReference()).isEqualTo(start);
        assertThat(cursor.targetNodeReference()).isEqualTo(end);
        assertThat(cursor.otherNodeReference()).isEqualTo(end);
        assertThat(cursor.type()).isEqualTo(t2);
        cursor.properties(properties);
        assertTrue(properties.next());
        assertThat(properties.propertyValue()).isEqualTo(stringValue("Relationship 2"));
        assertFalse(properties.next());
        assertFalse(cursor.next());
        // Find r2 second time
        cursor = expandInto.connectingRelationships(nodes, traversal, end, types, start);
        assertTrue(cursor.next());
        assertThat(cursor.relationshipReference()).isEqualTo(r2);
        assertThat(cursor.sourceNodeReference()).isEqualTo(start);
        assertThat(cursor.targetNodeReference()).isEqualTo(end);
        assertThat(cursor.otherNodeReference()).isEqualTo(end);
        assertThat(cursor.type()).isEqualTo(t2);
        cursor.properties(properties);
        assertTrue(properties.next());
        assertThat(properties.propertyValue()).isEqualTo(stringValue("Relationship 2"));
        assertFalse(properties.next());
        assertFalse(cursor.next());
    }
}
Also used : TokenWrite(org.neo4j.internal.kernel.api.TokenWrite) Write(org.neo4j.internal.kernel.api.Write) RelationshipTraversalCursor(org.neo4j.internal.kernel.api.RelationshipTraversalCursor) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) TokenWrite(org.neo4j.internal.kernel.api.TokenWrite) NodeCursor(org.neo4j.internal.kernel.api.NodeCursor) PropertyCursor(org.neo4j.internal.kernel.api.PropertyCursor) Test(org.junit.jupiter.api.Test)

Example 32 with TokenWrite

use of org.neo4j.internal.kernel.api.TokenWrite in project neo4j by neo4j.

the class CachingExpandIntoTest method shouldBeAbleToReuseWithoutTypes.

@Test
void shouldBeAbleToReuseWithoutTypes() throws KernelException {
    // given
    long start, end, r1, r2, r3;
    int t1, t2, t3;
    try (KernelTransaction tx = transaction()) {
        start = nodeWithDegree(tx, 43);
        end = nodeWithDegree(tx, 11);
        TokenWrite tokenWrite = tx.tokenWrite();
        t1 = tokenWrite.relationshipTypeGetOrCreateForName("R1");
        t2 = tokenWrite.relationshipTypeGetOrCreateForName("R2");
        t3 = tokenWrite.relationshipTypeGetOrCreateForName("R3");
        Write write = tx.dataWrite();
        r1 = write.relationshipCreate(start, t1, end);
        r2 = write.relationshipCreate(start, t2, end);
        r3 = write.relationshipCreate(end, t3, start);
        tx.commit();
    }
    try (KernelTransaction tx = transaction();
        NodeCursor nodeCursor = tx.cursors().allocateNodeCursor(tx.cursorContext());
        RelationshipTraversalCursor traversalCursor = tx.cursors().allocateRelationshipTraversalCursor(tx.cursorContext())) {
        CachingExpandInto expandInto = new CachingExpandInto(tx.dataRead(), OUTGOING, MEMORY_TRACKER);
        assertThat(toSet(expandInto.connectingRelationships(nodeCursor, traversalCursor, start, null, end))).isEqualTo(immutable.of(r1, r2));
        assertThat(toSet(expandInto.connectingRelationships(nodeCursor, traversalCursor, end, null, start))).isEqualTo(immutable.of(r3));
        assertThat(toSet(expandInto.connectingRelationships(nodeCursor, traversalCursor, start, null, end))).isEqualTo(immutable.of(r1, r2));
        assertThat(toSet(expandInto.connectingRelationships(nodeCursor, traversalCursor, end, null, start))).isEqualTo(immutable.of(r3));
    }
}
Also used : TokenWrite(org.neo4j.internal.kernel.api.TokenWrite) Write(org.neo4j.internal.kernel.api.Write) RelationshipTraversalCursor(org.neo4j.internal.kernel.api.RelationshipTraversalCursor) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) TokenWrite(org.neo4j.internal.kernel.api.TokenWrite) NodeCursor(org.neo4j.internal.kernel.api.NodeCursor) Test(org.junit.jupiter.api.Test)

Example 33 with TokenWrite

use of org.neo4j.internal.kernel.api.TokenWrite in project neo4j by neo4j.

the class CachingExpandIntoTest method shouldBeAbleToReuseWithTypes.

@Test
void shouldBeAbleToReuseWithTypes() throws KernelException {
    // given
    long start, end, r1, r3;
    int t1, t2, t3;
    try (KernelTransaction tx = transaction()) {
        start = nodeWithDegree(tx, 43);
        end = nodeWithDegree(tx, 11);
        TokenWrite tokenWrite = tx.tokenWrite();
        t1 = tokenWrite.relationshipTypeGetOrCreateForName("R1");
        t2 = tokenWrite.relationshipTypeGetOrCreateForName("R2");
        t3 = tokenWrite.relationshipTypeGetOrCreateForName("R3");
        Write write = tx.dataWrite();
        r1 = write.relationshipCreate(start, t1, end);
        write.relationshipCreate(start, t2, end);
        r3 = write.relationshipCreate(end, t3, start);
        tx.commit();
    }
    try (KernelTransaction tx = transaction();
        NodeCursor nodeCursor = tx.cursors().allocateNodeCursor(tx.cursorContext());
        RelationshipTraversalCursor traversalCursor = tx.cursors().allocateRelationshipTraversalCursor(tx.cursorContext())) {
        int[] types = { t1, t3 };
        CachingExpandInto expandInto = new CachingExpandInto(tx.dataRead(), OUTGOING, MEMORY_TRACKER);
        assertThat(toSet(expandInto.connectingRelationships(nodeCursor, traversalCursor, start, types, end))).isEqualTo(immutable.of(r1));
        assertThat(toSet(expandInto.connectingRelationships(nodeCursor, traversalCursor, end, types, start))).isEqualTo(immutable.of(r3));
        assertThat(toSet(expandInto.connectingRelationships(nodeCursor, traversalCursor, start, types, end))).isEqualTo(immutable.of(r1));
        assertThat(toSet(expandInto.connectingRelationships(nodeCursor, traversalCursor, end, types, start))).isEqualTo(immutable.of(r3));
    }
}
Also used : TokenWrite(org.neo4j.internal.kernel.api.TokenWrite) Write(org.neo4j.internal.kernel.api.Write) RelationshipTraversalCursor(org.neo4j.internal.kernel.api.RelationshipTraversalCursor) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) TokenWrite(org.neo4j.internal.kernel.api.TokenWrite) NodeCursor(org.neo4j.internal.kernel.api.NodeCursor) Test(org.junit.jupiter.api.Test)

Example 34 with TokenWrite

use of org.neo4j.internal.kernel.api.TokenWrite in project neo4j by neo4j.

the class CompositeIndexingIT method setup.

@BeforeEach
void setup() throws Exception {
    try (Transaction tx = graphDatabaseAPI.beginTx()) {
        KernelTransaction ktx = ((InternalTransaction) tx).kernelTransaction();
        TokenWrite tokenWrite = ktx.tokenWrite();
        tokenWrite.labelGetOrCreateForName("Label0");
        labelId = tokenWrite.labelGetOrCreateForName("Label1");
        tokenWrite.relationshipTypeGetOrCreateForName("Type0");
        tokenWrite.relationshipTypeGetOrCreateForName("Type1");
        relTypeId = tokenWrite.relationshipTypeGetOrCreateForName("Type2");
        propIds = new int[10];
        for (int i = 0; i < propIds.length; i++) {
            propIds[i] = tokenWrite.propertyKeyGetOrCreateForName("prop" + i);
        }
        tx.commit();
    }
}
Also used : InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Transaction(org.neo4j.graphdb.Transaction) TokenWrite(org.neo4j.internal.kernel.api.TokenWrite) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

TokenWrite (org.neo4j.internal.kernel.api.TokenWrite)34 Test (org.junit.jupiter.api.Test)12 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)11 SchemaWrite (org.neo4j.internal.kernel.api.SchemaWrite)10 Write (org.neo4j.internal.kernel.api.Write)8 BeforeEach (org.junit.jupiter.api.BeforeEach)6 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)6 KernelException (org.neo4j.exceptions.KernelException)5 KernelIntegrationTest (org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest)5 NodeCursor (org.neo4j.internal.kernel.api.NodeCursor)4 Transaction (org.neo4j.graphdb.Transaction)3 RelationshipTraversalCursor (org.neo4j.internal.kernel.api.RelationshipTraversalCursor)3 FulltextSchemaDescriptor (org.neo4j.internal.schema.FulltextSchemaDescriptor)3 LabelSchemaDescriptor (org.neo4j.internal.schema.LabelSchemaDescriptor)3 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)2 SchemaKernelException (org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException)2 ConstraintDescriptor (org.neo4j.internal.schema.ConstraintDescriptor)2 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)2 ExecutionException (java.util.concurrent.ExecutionException)1 MutableLongSet (org.eclipse.collections.api.set.primitive.MutableLongSet)1