Search in sources :

Example 21 with TokenWrite

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

the class FullCheckIntegrationTest method createFixture.

private GraphStoreFixture createFixture() {
    return new GraphStoreFixture(getRecordFormatName(), testDirectory) {

        @Override
        protected void generateInitialData(GraphDatabaseService db) {
            // because many tests rely on sort order for those token ids.
            try (org.neo4j.graphdb.Transaction tx = db.beginTx()) {
                KernelTransaction ktx = ((InternalTransaction) tx).kernelTransaction();
                TokenWrite tokenWrite = ktx.tokenWrite();
                label1 = tokenWrite.labelGetOrCreateForName("label1");
                label2 = tokenWrite.labelGetOrCreateForName("label2");
                label3 = tokenWrite.labelGetOrCreateForName("label3");
                tokenWrite.labelGetOrCreateForName("label4");
                draconian = tokenWrite.labelGetOrCreateForName("draconian");
                key1 = tokenWrite.propertyKeyGetOrCreateForName(PROP1);
                mandatory = tokenWrite.propertyKeyGetOrCreateForName("mandatory");
                C = tokenWrite.relationshipTypeGetOrCreateForName("C");
                T = tokenWrite.relationshipTypeGetOrCreateForName("T");
                M = tokenWrite.relationshipTypeGetOrCreateForName("M");
                tx.commit();
            } catch (KernelException e) {
                throw new RuntimeException(e);
            }
            // Create indexes
            try (org.neo4j.graphdb.Transaction tx = db.beginTx()) {
                tx.schema().indexFor(label("label3")).on(PROP1).create();
                tx.schema().indexFor(label("label3")).on(PROP1).on(PROP2).create();
                tx.schema().constraintFor(label("label4")).assertPropertyIsUnique(PROP1).create();
                tx.commit();
            }
            try (org.neo4j.graphdb.Transaction tx = db.beginTx()) {
                tx.schema().awaitIndexesOnline(2, TimeUnit.MINUTES);
            }
            // Create initial data
            try (org.neo4j.graphdb.Transaction tx = db.beginTx()) {
                Node node1 = set(tx.createNode(label("label1")));
                Node node2 = set(tx.createNode(label("label2")), property(PROP1, VALUE1));
                node1.createRelationshipTo(node2, withName("C"));
                // Just to create one more rel type
                tx.createNode().createRelationshipTo(tx.createNode(), withName("T"));
                indexedNodes.add(set(tx.createNode(label("label3")), property(PROP1, VALUE1)).getId());
                indexedNodes.add(set(tx.createNode(label("label3")), property(PROP1, VALUE1), property(PROP2, VALUE2)).getId());
                set(tx.createNode(label("label4")), property(PROP1, VALUE1));
                tx.commit();
            }
        }

        @Override
        protected Map<Setting<?>, Object> getConfig() {
            return getSettings();
        }
    };
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Node(org.neo4j.graphdb.Node) Setting(org.neo4j.graphdb.config.Setting) TokenWrite(org.neo4j.internal.kernel.api.TokenWrite) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) KernelException(org.neo4j.exceptions.KernelException) GraphStoreFixture(org.neo4j.consistency.checking.GraphStoreFixture)

Example 22 with TokenWrite

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

the class SchemaComplianceCheckerTest method initialData.

@Override
void initialData(KernelTransaction tx) throws KernelException {
    TokenWrite tokenWrite = tx.tokenWrite();
    propertyKey1 = tokenWrite.propertyKeyGetOrCreateForName("1");
    propertyKey2 = tokenWrite.propertyKeyGetOrCreateForName("2");
    propertyKey3 = tokenWrite.propertyKeyGetOrCreateForName("3");
    label1 = tokenWrite.labelGetOrCreateForName("A");
    label2 = tokenWrite.labelGetOrCreateForName("B");
    label3 = tokenWrite.labelGetOrCreateForName("C");
}
Also used : TokenWrite(org.neo4j.internal.kernel.api.TokenWrite)

Example 23 with TokenWrite

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

the class BuiltInProceduresIT method listPropertyKeys.

@Test
void listPropertyKeys() throws Throwable {
    // Given
    TokenWrite ops = tokenWriteInNewTransaction();
    ops.propertyKeyGetOrCreateForName("MyProp");
    commit();
    // When
    RawIterator<AnyValue[], ProcedureException> stream = procs().procedureCallRead(procs().procedureGet(procedureName("db", "propertyKeys")).id(), new AnyValue[0], ProcedureCallContext.EMPTY);
    // Then
    assertThat(asList(stream)).containsExactly(new AnyValue[] { stringValue("MyProp") });
}
Also used : TokenWrite(org.neo4j.internal.kernel.api.TokenWrite) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) Test(org.junit.jupiter.api.Test)

Example 24 with TokenWrite

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

the class KernelIT method createIndex.

private static IndexDescriptor createIndex(KernelTransaction transaction) throws KernelException {
    TokenWrite tokenWrite = transaction.tokenWrite();
    SchemaWrite schemaWrite = transaction.schemaWrite();
    LabelSchemaDescriptor schema = forLabel(tokenWrite.labelGetOrCreateForName("hello"), tokenWrite.propertyKeyGetOrCreateForName("hepp"));
    return schemaWrite.indexCreate(schema, null);
}
Also used : SchemaWrite(org.neo4j.internal.kernel.api.SchemaWrite) TokenWrite(org.neo4j.internal.kernel.api.TokenWrite) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor)

Example 25 with TokenWrite

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

the class SystemBuiltInProceduresIT method listConstraints.

@Test
void listConstraints() throws Throwable {
    // Given
    KernelTransaction transaction = newTransaction(AUTH_DISABLED);
    TokenWrite tokenWrite = transaction.tokenWrite();
    int labelId = tokenWrite.labelGetOrCreateForName("Label");
    int propId = tokenWrite.propertyKeyGetOrCreateForName("property");
    SchemaWrite schemaWrite = transaction.schemaWrite();
    schemaWrite.uniquePropertyConstraintCreate(uniqueForSchema(forLabel(labelId, propId)).withName("my_constraint"));
    commit();
    try (org.neo4j.graphdb.Transaction tx = db.beginTx()) {
        // When & Then
        assertFalse(tx.execute("CALL db.constraints").hasNext());
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) SchemaWrite(org.neo4j.internal.kernel.api.SchemaWrite) TokenWrite(org.neo4j.internal.kernel.api.TokenWrite) Test(org.junit.jupiter.api.Test)

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