Search in sources :

Example 41 with SchemaRead

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

the class SchemaImplMockTest method mockKernelTransaction.

private static KernelTransaction mockKernelTransaction() throws IndexNotFoundKernelException {
    SchemaRead schemaRead = mock(SchemaRead.class);
    when(schemaRead.indexGetState(any(IndexDescriptor.class))).thenReturn(InternalIndexState.FAILED);
    when(schemaRead.indexGetFailure(any(IndexDescriptor.class))).thenReturn(Exceptions.stringify(cause));
    KernelTransaction kt = mock(KernelTransaction.class);
    when(kt.tokenRead()).thenReturn(mock(TokenRead.class));
    when(kt.schemaRead()).thenReturn(schemaRead);
    when(kt.isTerminated()).thenReturn(false);
    return kt;
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) SchemaRead(org.neo4j.internal.kernel.api.SchemaRead) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) TokenRead(org.neo4j.internal.kernel.api.TokenRead)

Example 42 with SchemaRead

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

the class BatchInsertIndexTest method batchInserterShouldUseConfiguredIndexProvider.

@ParameterizedTest
@EnumSource(SchemaIndex.class)
void batchInserterShouldUseConfiguredIndexProvider(SchemaIndex schemaIndex) throws Exception {
    configure(schemaIndex);
    BatchInserter inserter = newBatchInserter();
    inserter.createDeferredSchemaIndex(LABEL_ONE).on("key").create();
    inserter.shutdown();
    GraphDatabaseService db = startGraphDatabaseServiceAndAwaitIndexes();
    try (Transaction tx = db.beginTx()) {
        KernelTransaction kernelTransaction = ((InternalTransaction) tx).kernelTransaction();
        TokenRead tokenRead = kernelTransaction.tokenRead();
        SchemaRead schemaRead = kernelTransaction.schemaRead();
        int labelId = tokenRead.nodeLabel(LABEL_ONE.name());
        int propertyId = tokenRead.propertyKey("key");
        IndexDescriptor index = single(schemaRead.index(SchemaDescriptor.forLabel(labelId, propertyId)));
        assertTrue(schemaIndex.providerName().contains(index.getIndexProvider().getKey()), unexpectedIndexProviderMessage(index));
        assertTrue(schemaIndex.providerName().contains(index.getIndexProvider().getVersion()), unexpectedIndexProviderMessage(index));
        tx.commit();
    }
}
Also used : BatchInserter(org.neo4j.batchinsert.BatchInserter) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) SchemaRead(org.neo4j.internal.kernel.api.SchemaRead) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) TokenRead(org.neo4j.internal.kernel.api.TokenRead) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 43 with SchemaRead

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

the class SchemaImpl method getIndexPopulationProgress.

@Override
public IndexPopulationProgress getIndexPopulationProgress(IndexDefinition index) {
    try {
        transaction.assertOpen();
        SchemaRead schemaRead = transaction.schemaRead();
        IndexDescriptor descriptor = getIndexReference(schemaRead, transaction.tokenRead(), (IndexDefinitionImpl) index);
        PopulationProgress progress = schemaRead.indexGetPopulationProgress(descriptor);
        return progress.toIndexPopulationProgress();
    } catch (KernelException e) {
        throw newIndexNotFoundException(index, e);
    }
}
Also used : PopulationProgress(org.neo4j.internal.kernel.api.PopulationProgress) IndexPopulationProgress(org.neo4j.graphdb.schema.IndexPopulationProgress) SchemaRead(org.neo4j.internal.kernel.api.SchemaRead) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) InvalidTransactionTypeKernelException(org.neo4j.internal.kernel.api.exceptions.InvalidTransactionTypeKernelException) IndexNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException) TokenCapacityExceededKernelException(org.neo4j.internal.kernel.api.exceptions.schema.TokenCapacityExceededKernelException) SchemaKernelException(org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException) KernelException(org.neo4j.exceptions.KernelException)

Example 44 with SchemaRead

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

the class SchemaImpl method getIndexes.

@Override
public Iterable<IndexDefinition> getIndexes(final Label label) {
    transaction.assertOpen();
    TokenRead tokenRead = transaction.tokenRead();
    SchemaRead schemaRead = transaction.schemaRead();
    List<IndexDefinition> definitions = new ArrayList<>();
    int labelId = tokenRead.nodeLabel(label.name());
    if (labelId == TokenRead.NO_TOKEN) {
        return emptyList();
    }
    Iterator<IndexDescriptor> indexes = schemaRead.indexesGetForLabel(labelId);
    addDefinitions(definitions, tokenRead, IndexDescriptor.sortByType(indexes));
    return definitions;
}
Also used : SchemaRead(org.neo4j.internal.kernel.api.SchemaRead) IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) ArrayList(java.util.ArrayList) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) TokenRead(org.neo4j.internal.kernel.api.TokenRead)

Example 45 with SchemaRead

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

the class SchemaImpl method getIndexFailure.

@Override
public String getIndexFailure(IndexDefinition index) {
    try {
        transaction.assertOpen();
        SchemaRead schemaRead = transaction.schemaRead();
        IndexDescriptor descriptor = getIndexReference(schemaRead, transaction.tokenRead(), (IndexDefinitionImpl) index);
        return schemaRead.indexGetFailure(descriptor);
    } catch (KernelException e) {
        throw newIndexNotFoundException(index, e);
    }
}
Also used : SchemaRead(org.neo4j.internal.kernel.api.SchemaRead) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) InvalidTransactionTypeKernelException(org.neo4j.internal.kernel.api.exceptions.InvalidTransactionTypeKernelException) IndexNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException) TokenCapacityExceededKernelException(org.neo4j.internal.kernel.api.exceptions.schema.TokenCapacityExceededKernelException) SchemaKernelException(org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException) KernelException(org.neo4j.exceptions.KernelException)

Aggregations

SchemaRead (org.neo4j.internal.kernel.api.SchemaRead)52 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)36 Test (org.junit.jupiter.api.Test)28 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)26 ConstraintDescriptor (org.neo4j.internal.schema.ConstraintDescriptor)22 TokenRead (org.neo4j.internal.kernel.api.TokenRead)12 SchemaReadCore (org.neo4j.internal.kernel.api.SchemaReadCore)9 IndexNotFoundKernelException (org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException)8 ArrayList (java.util.ArrayList)7 Read (org.neo4j.internal.kernel.api.Read)5 HashMap (java.util.HashMap)4 BeforeEach (org.junit.jupiter.api.BeforeEach)4 Arrays (java.util.Arrays)3 Iterator (java.util.Iterator)3 List (java.util.List)3 Map (java.util.Map)3 EntityType (org.neo4j.common.EntityType)3 KernelException (org.neo4j.exceptions.KernelException)3 Transaction (org.neo4j.graphdb.Transaction)3 Iterators (org.neo4j.internal.helpers.collection.Iterators)3