Search in sources :

Example 41 with IndexPrototype

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

the class IndexProviderTests method validatePrototypeMustThrowOnInvalidPrototype.

@Test
void validatePrototypeMustThrowOnInvalidPrototype() {
    // given
    provider = newProvider();
    // when
    List<IndexPrototype> invalidPrototypes = invalidPrototypes();
    // then
    for (IndexPrototype invalidPrototype : invalidPrototypes) {
        assertThrows(IllegalArgumentException.class, () -> provider.validatePrototype(invalidPrototype));
    }
}
Also used : IndexPrototype(org.neo4j.internal.schema.IndexPrototype) Test(org.junit.jupiter.api.Test)

Example 42 with IndexPrototype

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

the class IndexProcedures method createUniquePropertyConstraint.

public Stream<BuiltInProcedures.SchemaIndexInfo> createUniquePropertyConstraint(String constraintName, List<String> labels, List<String> properties, IndexProviderDescriptor indexProviderDescriptor, Map<String, Object> configMap) throws ProcedureException {
    return createIndex(constraintName, labels, properties, indexProviderDescriptor, configMap, "uniqueness constraint online", (schemaWrite, name, schema, provider, indexConfig) -> {
        final IndexPrototype prototype = IndexPrototype.uniqueForSchema(schema, provider).withName(name).withIndexConfig(indexConfig);
        schemaWrite.uniquePropertyConstraintCreate(prototype);
    });
}
Also used : IndexPrototype(org.neo4j.internal.schema.IndexPrototype)

Example 43 with IndexPrototype

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

the class IndexProcedures method createIndex.

public Stream<BuiltInProcedures.SchemaIndexInfo> createIndex(String indexName, List<String> labels, List<String> properties, IndexProviderDescriptor indexProviderDescriptor, Map<String, Object> configMap) throws ProcedureException {
    return createIndex(indexName, labels, properties, indexProviderDescriptor, configMap, "index created", (schemaWrite, name, descriptor, provider, indexConfig) -> {
        IndexPrototype prototype = IndexPrototype.forSchema(descriptor, provider).withName(name).withIndexConfig(indexConfig);
        schemaWrite.indexCreate(prototype);
    });
}
Also used : IndexPrototype(org.neo4j.internal.schema.IndexPrototype)

Example 44 with IndexPrototype

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

the class IndexWriterStep method createIndex.

private IndexDescriptor createIndex(EntityType entityType, IndexConfig config, SchemaRuleAccess schemaRule, SchemaStore schemaStore, MemoryTracker memoryTracker, CursorContext cursorContext) {
    try {
        IndexProviderDescriptor providerDescriptor = new IndexProviderDescriptor("token-lookup", "1.0");
        IndexPrototype prototype = forSchema(forAnyEntityTokens(entityType)).withIndexType(LOOKUP).withIndexProvider(providerDescriptor);
        String name = defaultIfEmpty(config.indexName(entityType), generateName(prototype, new String[] {}, new String[] {}));
        IndexDescriptor descriptor = prototype.withName(name).materialise(schemaStore.nextId(cursorContext));
        schemaRule.writeSchemaRule(descriptor, cursorContext, memoryTracker);
        return descriptor;
    } catch (KernelException e) {
        throw new RuntimeException("Error preparing indexes", e);
    }
}
Also used : IndexProviderDescriptor(org.neo4j.internal.schema.IndexProviderDescriptor) IndexPrototype(org.neo4j.internal.schema.IndexPrototype) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) KernelException(org.neo4j.exceptions.KernelException)

Example 45 with IndexPrototype

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

the class RandomSchema method nextIndex.

public IndexDescriptor nextIndex() {
    int choice = rng.nextInt(4);
    SchemaDescriptor schema;
    switch(choice) {
        case 0:
            schema = nextNodeSchema();
            break;
        case 1:
            schema = nextNodeFulltextSchema();
            break;
        case 2:
            schema = nextRelationshipSchema();
            break;
        case 3:
            schema = nextRelationshipFulltextSchema();
            break;
        default:
            throw new RuntimeException("Bad index choice: " + choice);
    }
    boolean isUnique = rng.nextBoolean() && !schema.isFulltextSchemaDescriptor();
    IndexPrototype prototype = isUnique ? IndexPrototype.uniqueForSchema(schema) : IndexPrototype.forSchema(schema);
    IndexProviderDescriptor providerDescriptor = new IndexProviderDescriptor(nextName(), nextName());
    prototype = prototype.withIndexProvider(providerDescriptor);
    prototype = prototype.withName(nextName());
    if (schema.isFulltextSchemaDescriptor()) {
        prototype = prototype.withIndexType(IndexType.FULLTEXT);
    }
    long ruleId = nextRuleIdForIndex();
    IndexDescriptor index = prototype.materialise(ruleId);
    if (isUnique && rng.nextBoolean()) {
        index = index.withOwningConstraintId(existingConstraintId());
    }
    return index;
}
Also used : LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) RelationTypeSchemaDescriptor(org.neo4j.internal.schema.RelationTypeSchemaDescriptor) SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) IndexPrototype(org.neo4j.internal.schema.IndexPrototype) IndexProviderDescriptor(org.neo4j.internal.schema.IndexProviderDescriptor) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor)

Aggregations

IndexPrototype (org.neo4j.internal.schema.IndexPrototype)45 Test (org.junit.jupiter.api.Test)25 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)24 SchemaDescriptor (org.neo4j.internal.schema.SchemaDescriptor)16 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)9 IndexProviderDescriptor (org.neo4j.internal.schema.IndexProviderDescriptor)8 LabelSchemaDescriptor (org.neo4j.internal.schema.LabelSchemaDescriptor)7 KernelTransactionImplementation (org.neo4j.kernel.impl.api.KernelTransactionImplementation)7 IndexProxy (org.neo4j.kernel.impl.api.index.IndexProxy)7 RelationTypeSchemaDescriptor (org.neo4j.internal.schema.RelationTypeSchemaDescriptor)5 SchemaWrite (org.neo4j.internal.kernel.api.SchemaWrite)4 IndexDefinition (org.neo4j.graphdb.schema.IndexDefinition)3 IndexPopulator (org.neo4j.kernel.api.index.IndexPopulator)3 NamedToken (org.neo4j.token.api.NamedToken)3 KernelException (org.neo4j.exceptions.KernelException)2 Transaction (org.neo4j.graphdb.Transaction)2 IndexReadSession (org.neo4j.internal.kernel.api.IndexReadSession)2 RelationshipValueIndexCursor (org.neo4j.internal.kernel.api.RelationshipValueIndexCursor)2 IndexConfig (org.neo4j.internal.schema.IndexConfig)2 KernelIntegrationTest (org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest)2