Search in sources :

Example 16 with TokenWrite

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

the class SchemaReadWriteTestBase method setUp.

@BeforeEach
void setUp() throws Exception {
    try (KernelTransaction transaction = beginTransaction()) {
        SchemaRead schemaRead = transaction.schemaRead();
        SchemaWrite schemaWrite = transaction.schemaWrite();
        Iterator<ConstraintDescriptor> constraints = schemaRead.constraintsGetAll();
        while (constraints.hasNext()) {
            schemaWrite.constraintDrop(constraints.next());
        }
        Iterator<IndexDescriptor> indexes = schemaRead.indexesGetAll();
        while (indexes.hasNext()) {
            schemaWrite.indexDrop(indexes.next());
        }
        TokenWrite tokenWrite = transaction.tokenWrite();
        label = tokenWrite.labelGetOrCreateForName("label");
        label2 = tokenWrite.labelGetOrCreateForName("label2");
        type = tokenWrite.relationshipTypeGetOrCreateForName("relationship");
        prop1 = tokenWrite.propertyKeyGetOrCreateForName("prop1");
        prop2 = tokenWrite.propertyKeyGetOrCreateForName("prop2");
        prop3 = tokenWrite.propertyKeyGetOrCreateForName("prop3");
        transaction.commit();
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) SchemaRead(org.neo4j.internal.kernel.api.SchemaRead) SchemaWrite(org.neo4j.internal.kernel.api.SchemaWrite) ConstraintDescriptor(org.neo4j.internal.schema.ConstraintDescriptor) TokenWrite(org.neo4j.internal.kernel.api.TokenWrite) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 17 with TokenWrite

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

the class TransactionImpl method createNode.

@Override
public Node createNode(Label... labels) {
    var ktx = kernelTransaction();
    try {
        TokenWrite tokenWrite = ktx.tokenWrite();
        int[] labelIds = new int[labels.length];
        String[] labelNames = new String[labels.length];
        for (int i = 0; i < labelNames.length; i++) {
            labelNames[i] = labels[i].name();
        }
        tokenWrite.labelGetOrCreateForNames(labelNames, labelIds);
        Write write = ktx.dataWrite();
        long nodeId = write.nodeCreateWithLabels(labelIds);
        return newNodeEntity(nodeId);
    } catch (ConstraintValidationException e) {
        throw new ConstraintViolationException("Unable to add label.", e);
    } catch (SchemaKernelException e) {
        throw new IllegalArgumentException(e);
    } catch (KernelException e) {
        throw new ConstraintViolationException(e.getMessage(), e);
    }
}
Also used : TokenWrite(org.neo4j.internal.kernel.api.TokenWrite) Write(org.neo4j.internal.kernel.api.Write) ConstraintValidationException(org.neo4j.internal.kernel.api.exceptions.schema.ConstraintValidationException) TokenWrite(org.neo4j.internal.kernel.api.TokenWrite) SchemaKernelException(org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException) ConstraintViolationException(org.neo4j.graphdb.ConstraintViolationException) InvalidTransactionTypeKernelException(org.neo4j.internal.kernel.api.exceptions.InvalidTransactionTypeKernelException) IndexNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException) QueryExecutionKernelException(org.neo4j.kernel.impl.query.QueryExecutionKernelException) SchemaKernelException(org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException) KernelException(org.neo4j.exceptions.KernelException)

Example 18 with TokenWrite

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

the class IndexCreateIT method shouldCreateWithSpecificExistingProviderName.

protected void shouldCreateWithSpecificExistingProviderName(IndexCreator creator) throws KernelException {
    int counter = 0;
    for (GraphDatabaseSettings.SchemaIndex indexSetting : GraphDatabaseSettings.SchemaIndex.values()) {
        // given
        TokenWrite tokenWrite = tokenWriteInNewTransaction();
        int labelId = tokenWrite.labelGetOrCreateForName("Label" + counter);
        int propId = tokenWrite.propertyKeyGetOrCreateForName("property");
        commit();
        SchemaWrite schemaWrite = schemaWriteInNewTransaction();
        LabelSchemaDescriptor descriptor = forLabel(labelId, propId);
        String provider = indexSetting.providerName();
        String indexName = "index-" + counter;
        creator.create(schemaWrite, descriptor, provider, indexName);
        IndexDescriptor index = transaction.kernelTransaction().schemaRead().indexGetForName(indexName);
        // when
        commit();
        // then
        assertEquals(provider, indexingService.getIndexProxy(index).getDescriptor().getIndexProvider().name());
        counter++;
    }
}
Also used : GraphDatabaseSettings(org.neo4j.configuration.GraphDatabaseSettings) SchemaWrite(org.neo4j.internal.kernel.api.SchemaWrite) TokenWrite(org.neo4j.internal.kernel.api.TokenWrite) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor)

Example 19 with TokenWrite

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

the class FullScanStoreViewTest method getOrCreateIds.

private void getOrCreateIds() throws KernelException {
    try (Transaction tx = graphDb.beginTx()) {
        TokenWrite tokenWrite = ((InternalTransaction) tx).kernelTransaction().tokenWrite();
        labelId = tokenWrite.labelGetOrCreateForName("Person");
        relTypeId = tokenWrite.relationshipTypeGetOrCreateForName("Knows");
        propertyKeyId = tokenWrite.propertyKeyGetOrCreateForName("name");
        relPropertyKeyId = tokenWrite.propertyKeyGetOrCreateForName("duration");
        tx.commit();
    }
}
Also used : InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Transaction(org.neo4j.graphdb.Transaction) TokenWrite(org.neo4j.internal.kernel.api.TokenWrite)

Example 20 with TokenWrite

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

the class SchemaStorageIT method initStorage.

@BeforeEach
void initStorage() throws Exception {
    try (Transaction transaction = db.beginTx()) {
        TokenWrite tokenWrite = ((InternalTransaction) transaction).kernelTransaction().tokenWrite();
        tokenWrite.propertyKeyGetOrCreateForName(PROP1);
        tokenWrite.propertyKeyGetOrCreateForName(PROP2);
        tokenWrite.labelGetOrCreateForName(LABEL1);
        tokenWrite.labelGetOrCreateForName(LABEL2);
        tokenWrite.relationshipTypeGetOrCreateForName(TYPE1);
        transaction.commit();
    }
    schemaStore = storageEngine.testAccessNeoStores().getSchemaStore();
    storage = new SchemaStorage(schemaStore, tokenHolders, () -> KernelVersion.LATEST);
}
Also used : InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Transaction(org.neo4j.graphdb.Transaction) SchemaStorage(org.neo4j.internal.recordstorage.SchemaStorage) TokenWrite(org.neo4j.internal.kernel.api.TokenWrite) 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