Search in sources :

Example 26 with IndexProviderDescriptor

use of org.neo4j.internal.schema.IndexProviderDescriptor in project neo4j by neo4j.

the class ConstraintIndexCreatorTest method shouldCreateConstraintIndexForSpecifiedProvider.

@Test
void shouldCreateConstraintIndexForSpecifiedProvider() throws Exception {
    // given
    IndexingService indexingService = mock(IndexingService.class);
    IndexProviderDescriptor providerDescriptor = new IndexProviderDescriptor("Groovy", "1.2");
    IndexPrototype prototype = this.prototype.withIndexProvider(providerDescriptor);
    IndexDescriptor index = prototype.materialise(this.index.getId());
    IndexProxy indexProxy = mock(IndexProxy.class);
    when(indexingService.getIndexProxy(index)).thenReturn(indexProxy);
    ConstraintIndexCreator creator = new ConstraintIndexCreator(() -> kernel, indexingService, logProvider);
    when(schemaRead.indexGetForName(constraint.getName())).thenReturn(IndexDescriptor.NO_INDEX);
    // when
    KernelTransactionImplementation transaction = createTransaction();
    creator.createUniquenessConstraintIndex(transaction, constraint, prototype);
    // then
    assertEquals(1, kernel.transactions.size());
    KernelTransactionImplementation transactionInstance = kernel.transactions.get(0);
    verify(transactionInstance).indexUniqueCreate(prototype);
    verify(schemaRead).indexGetForName(constraint.getName());
    verifyNoMoreInteractions(schemaRead);
}
Also used : ConstraintIndexCreator(org.neo4j.kernel.impl.api.state.ConstraintIndexCreator) IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) KernelTransactionImplementation(org.neo4j.kernel.impl.api.KernelTransactionImplementation) IndexProviderDescriptor(org.neo4j.internal.schema.IndexProviderDescriptor) IndexPrototype(org.neo4j.internal.schema.IndexPrototype) IndexProxy(org.neo4j.kernel.impl.api.index.IndexProxy) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Test(org.junit.jupiter.api.Test)

Example 27 with IndexProviderDescriptor

use of org.neo4j.internal.schema.IndexProviderDescriptor in project neo4j by neo4j.

the class SchemaRuleSerialization35 method readIndexRule.

// PRIVATE
// READ INDEX
private static IndexDescriptor readIndexRule(long id, ByteBuffer source) throws MalformedSchemaRuleException {
    String providerKey = getDecodedStringFrom(source);
    String providerVersion = getDecodedStringFrom(source);
    IndexProviderDescriptor providerDescriptor = new IndexProviderDescriptor(providerKey, providerVersion);
    byte indexRuleType = source.get();
    Optional<String> name;
    switch(indexRuleType) {
        case GENERAL_INDEX:
            {
                SchemaDescriptor schema = readSchema(source);
                name = readRuleName(source);
                IndexPrototype prototype = IndexPrototype.forSchema(schema, providerDescriptor);
                if (schema.isFulltextSchemaDescriptor()) {
                    prototype = prototype.withIndexType(IndexType.FULLTEXT);
                }
                if (name.isPresent()) {
                    prototype = prototype.withName(name.get());
                } else {
                    prototype = prototype.withName(defaultIndexName(id));
                }
                return prototype.materialise(id);
            }
        case UNIQUE_INDEX:
            {
                long readOwningConstraint = source.getLong();
                SchemaDescriptor schema = readSchema(source);
                name = readRuleName(source);
                IndexPrototype prototype = IndexPrototype.uniqueForSchema(schema, providerDescriptor);
                if (name.isPresent()) {
                    prototype = prototype.withName(name.get());
                } else {
                    prototype = prototype.withName(defaultIndexName(id));
                }
                IndexDescriptor index = prototype.materialise(id);
                if (readOwningConstraint != NO_OWNING_CONSTRAINT_YET) {
                    index = index.withOwningConstraintId(readOwningConstraint);
                }
                return index;
            }
        default:
            throw new MalformedSchemaRuleException(format("Got unknown index rule type '%d'.", indexRuleType));
    }
}
Also used : LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) RelationTypeSchemaDescriptor(org.neo4j.internal.schema.RelationTypeSchemaDescriptor) SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) MalformedSchemaRuleException(org.neo4j.internal.kernel.api.exceptions.schema.MalformedSchemaRuleException) IndexProviderDescriptor(org.neo4j.internal.schema.IndexProviderDescriptor) IndexPrototype(org.neo4j.internal.schema.IndexPrototype) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor)

Example 28 with IndexProviderDescriptor

use of org.neo4j.internal.schema.IndexProviderDescriptor in project neo4j by neo4j.

the class SchemaStore method indexProviderToMap.

private static void indexProviderToMap(IndexDescriptor rule, Map<String, Value> map) {
    IndexProviderDescriptor provider = rule.getIndexProvider();
    String name = provider.getKey();
    String version = provider.getVersion();
    putStringProperty(map, PROP_INDEX_PROVIDER_NAME, name);
    putStringProperty(map, PROP_INDEX_PROVIDER_VERSION, version);
}
Also used : IndexProviderDescriptor(org.neo4j.internal.schema.IndexProviderDescriptor)

Example 29 with IndexProviderDescriptor

use of org.neo4j.internal.schema.IndexProviderDescriptor in project neo4j by neo4j.

the class DefaultIndexProviderMap method completeConfiguration.

@Override
public IndexDescriptor completeConfiguration(IndexDescriptor index) {
    IndexProviderDescriptor providerDescriptor = index.getIndexProvider();
    IndexProvider provider = lookup(providerDescriptor);
    return provider.completeConfiguration(index);
}
Also used : IndexProvider(org.neo4j.kernel.api.index.IndexProvider) TokenIndexProvider(org.neo4j.kernel.impl.index.schema.TokenIndexProvider) IndexProviderDescriptor(org.neo4j.internal.schema.IndexProviderDescriptor)

Example 30 with IndexProviderDescriptor

use of org.neo4j.internal.schema.IndexProviderDescriptor in project neo4j by neo4j.

the class DefaultIndexProviderMapTest method provider.

private static IndexProvider provider(String name, String version) {
    IndexProviderDescriptor descriptor = new IndexProviderDescriptor(name, version);
    IndexProvider provider = mock(IndexProvider.class);
    when(provider.getProviderDescriptor()).thenReturn(descriptor);
    return provider;
}
Also used : IndexProvider(org.neo4j.kernel.api.index.IndexProvider) IndexProviderDescriptor(org.neo4j.internal.schema.IndexProviderDescriptor)

Aggregations

IndexProviderDescriptor (org.neo4j.internal.schema.IndexProviderDescriptor)41 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)18 Test (org.junit.jupiter.api.Test)16 IndexProvider (org.neo4j.kernel.api.index.IndexProvider)11 IndexPrototype (org.neo4j.internal.schema.IndexPrototype)10 ArrayList (java.util.ArrayList)5 FulltextSchemaDescriptor (org.neo4j.internal.schema.FulltextSchemaDescriptor)5 IndexDirectoryStructure (org.neo4j.kernel.api.index.IndexDirectoryStructure)5 IndexConfig (org.neo4j.internal.schema.IndexConfig)4 LabelSchemaDescriptor (org.neo4j.internal.schema.LabelSchemaDescriptor)4 Path (java.nio.file.Path)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3 IndexPopulator (org.neo4j.kernel.api.index.IndexPopulator)3 IOException (java.io.IOException)2 UncheckedIOException (java.io.UncheckedIOException)2 String.format (java.lang.String.format)2 Arrays (java.util.Arrays)2 Collection (java.util.Collection)2 EnumMap (java.util.EnumMap)2 HashMap (java.util.HashMap)2