Search in sources :

Example 1 with TokenWrite

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

the class CountsComputerTest method getRelTypeIdsFrom.

private int[] getRelTypeIdsFrom(Transaction tx, RelationshipType... types) throws KernelException {
    KernelTransaction ktx = ((InternalTransaction) tx).kernelTransaction();
    TokenWrite tokenWrite = ktx.tokenWrite();
    int[] ids = new int[types.length];
    tokenWrite.relationshipTypeGetOrCreateForNames(Arrays.stream(types).map(RelationshipType::name).toArray(String[]::new), ids);
    return ids;
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) RelationshipType(org.neo4j.graphdb.RelationshipType) TokenWrite(org.neo4j.internal.kernel.api.TokenWrite) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction)

Example 2 with TokenWrite

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

the class CountsComputerTest method getLabelIdsFrom.

private int[] getLabelIdsFrom(Transaction tx, Label... labels) throws KernelException {
    KernelTransaction ktx = ((InternalTransaction) tx).kernelTransaction();
    TokenWrite tokenWrite = ktx.tokenWrite();
    int[] ids = new int[labels.length];
    tokenWrite.relationshipTypeGetOrCreateForNames(Arrays.stream(labels).map(Label::name).toArray(String[]::new), ids);
    return ids;
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Label(org.neo4j.graphdb.Label) TokenWrite(org.neo4j.internal.kernel.api.TokenWrite) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction)

Example 3 with TokenWrite

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

the class WriteTestSupport method setup.

@Override
public void setup(Path storeDir, Consumer<GraphDatabaseService> sysCreate) {
    TestDatabaseManagementServiceBuilder databaseManagementServiceBuilder = newManagementServiceBuilder(storeDir);
    managementService = configure(databaseManagementServiceBuilder).build();
    db = managementService.database(DEFAULT_DATABASE_NAME);
    try (KernelTransaction tx = beginTransaction()) {
        // We are creating these dummy tokens so that that the ones that we actually use don't get
        // the value 0. Using 0 may hide bugs that are caused by default the initialization of ints
        TokenWrite tokenWrite = tx.tokenWrite();
        tokenWrite.propertyKeyCreateForName("DO_NOT_USE", false);
        tokenWrite.labelCreateForName("DO_NOT_USE", false);
        tokenWrite.relationshipTypeCreateForName("DO_NOT_USE", false);
    } catch (KernelException e) {
        throw new AssertionError("Failed to setup database", e);
    }
    GraphDatabaseService sysDb = managementService.database(SYSTEM_DATABASE_NAME);
    sysCreate.accept(sysDb);
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) TokenWrite(org.neo4j.internal.kernel.api.TokenWrite) KernelException(org.neo4j.exceptions.KernelException)

Example 4 with TokenWrite

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

the class CachingExpandIntoTest method shouldComputeDegreeWithType.

@Test
void shouldComputeDegreeWithType() throws Exception {
    // GIVEN
    long node;
    int in, out, loop;
    try (KernelTransaction tx = transaction()) {
        Write write = tx.dataWrite();
        node = denseNode(tx);
        TokenWrite tokenWrite = tx.tokenWrite();
        out = tokenWrite.relationshipTypeGetOrCreateForName("OUT");
        in = tokenWrite.relationshipTypeGetOrCreateForName("IN");
        loop = tokenWrite.relationshipTypeGetOrCreateForName("LOOP");
        write.relationshipCreate(node, out, write.nodeCreate());
        write.relationshipCreate(node, out, write.nodeCreate());
        write.relationshipCreate(write.nodeCreate(), in, node);
        write.relationshipCreate(node, loop, node);
        tx.commit();
    }
    try (KernelTransaction tx = transaction()) {
        Read read = tx.dataRead();
        CursorFactory cursors = tx.cursors();
        try (NodeCursor nodes = cursors.allocateNodeCursor(tx.cursorContext())) {
            CachingExpandInto expand = new CachingExpandInto(tx.dataRead(), OUTGOING, MEMORY_TRACKER);
            read.singleNode(node, nodes);
            assertThat(nodes.next()).isEqualTo(true);
            assertThat(nodes.supportsFastDegreeLookup()).isEqualTo(true);
            Degrees degrees = nodes.degrees(ALL_RELATIONSHIPS);
            assertThat(degrees.outgoingDegree(out)).isEqualTo(2);
            assertThat(degrees.outgoingDegree(in)).isEqualTo(0);
            assertThat(degrees.outgoingDegree(loop)).isEqualTo(1);
            assertThat(degrees.incomingDegree(out)).isEqualTo(0);
            assertThat(degrees.incomingDegree(in)).isEqualTo(1);
            assertThat(degrees.incomingDegree(loop)).isEqualTo(1);
            assertThat(degrees.totalDegree(out)).isEqualTo(2);
            assertThat(degrees.totalDegree(in)).isEqualTo(1);
            assertThat(degrees.totalDegree(loop)).isEqualTo(1);
        }
    }
}
Also used : TokenWrite(org.neo4j.internal.kernel.api.TokenWrite) Write(org.neo4j.internal.kernel.api.Write) Read(org.neo4j.internal.kernel.api.Read) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) CursorFactory(org.neo4j.internal.kernel.api.CursorFactory) Degrees(org.neo4j.storageengine.api.Degrees) TokenWrite(org.neo4j.internal.kernel.api.TokenWrite) NodeCursor(org.neo4j.internal.kernel.api.NodeCursor) Test(org.junit.jupiter.api.Test)

Example 5 with TokenWrite

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

the class IndexCreateIT method shouldFailCreateIndexWithDuplicateProperties.

@Test
void shouldFailCreateIndexWithDuplicateProperties() throws KernelException {
    // given
    TokenWrite tokenWrite = tokenWriteInNewTransaction();
    int labelId = tokenWrite.labelGetOrCreateForName("Label");
    int propId = tokenWrite.propertyKeyGetOrCreateForName("property");
    commit();
    SchemaWrite schemaWrite = schemaWriteInNewTransaction();
    // when
    final FulltextSchemaDescriptor descriptor = SchemaDescriptor.fulltext(EntityType.NODE, new int[] { labelId }, new int[] { propId, propId });
    // then
    assertThrows(RepeatedPropertyInSchemaException.class, () -> schemaWrite.indexCreate(descriptor, null));
}
Also used : SchemaWrite(org.neo4j.internal.kernel.api.SchemaWrite) FulltextSchemaDescriptor(org.neo4j.internal.schema.FulltextSchemaDescriptor) TokenWrite(org.neo4j.internal.kernel.api.TokenWrite) Test(org.junit.jupiter.api.Test) KernelIntegrationTest(org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest)

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