Search in sources :

Example 11 with IndexPrototype

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

the class IndexProcedures method createNodeKey.

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

Example 12 with IndexPrototype

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

the class SchemaRuleSerialization35Test method assertParseIndexRule.

private static void assertParseIndexRule(String serialized, String name) throws Exception {
    // GIVEN
    long ruleId = 24;
    IndexPrototype prototype = forLabel(512, 4).withIndexProvider(PROVIDER_25);
    byte[] bytes = decodeBase64(serialized);
    // WHEN
    IndexDescriptor deserialized = assertIndexRule(SchemaRuleSerialization35.deserialize(ruleId, ByteBuffer.wrap(bytes)));
    // THEN
    assertThat(deserialized.getId()).isEqualTo(ruleId);
    assertThat(deserialized).isEqualTo(prototype.withName(name).materialise(ruleId));
    assertThat(deserialized.schema()).isEqualTo(prototype.schema());
    assertThat(deserialized.getIndexProvider().getKey()).isEqualTo(PROVIDER_KEY);
    assertThat(deserialized.getIndexProvider().getVersion()).isEqualTo(PROVIDER_VERSION_25);
    assertThat(deserialized.getName()).isEqualTo(name);
    assertTrue(deserialized.getOwningConstraintId().isEmpty());
}
Also used : IndexPrototype(org.neo4j.internal.schema.IndexPrototype) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor)

Example 13 with IndexPrototype

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

the class SchemaStore method buildIndexRule.

private static SchemaRule buildIndexRule(long schemaRuleId, Map<String, Value> props) throws MalformedSchemaRuleException {
    SchemaDescriptor schema = buildSchemaDescriptor(props);
    String indexRuleType = getString(PROP_INDEX_RULE_TYPE, props);
    boolean unique = parseIndexType(indexRuleType);
    IndexPrototype prototype = unique ? IndexPrototype.uniqueForSchema(schema) : IndexPrototype.forSchema(schema);
    prototype = prototype.withName(getString(PROP_SCHEMA_RULE_NAME, props));
    prototype = prototype.withIndexType(getIndexType(getString(PROP_INDEX_TYPE, props)));
    String providerKey = getString(PROP_INDEX_PROVIDER_NAME, props);
    String providerVersion = getString(PROP_INDEX_PROVIDER_VERSION, props);
    IndexProviderDescriptor providerDescriptor = new IndexProviderDescriptor(providerKey, providerVersion);
    prototype = prototype.withIndexProvider(providerDescriptor);
    IndexDescriptor index = prototype.materialise(schemaRuleId);
    IndexConfig indexConfig = extractIndexConfig(props);
    index = index.withIndexConfig(indexConfig);
    if (props.containsKey(PROP_OWNING_CONSTRAINT)) {
        index = index.withOwningConstraintId(getLong(PROP_OWNING_CONSTRAINT, props));
    }
    return index;
}
Also used : SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) IndexConfig(org.neo4j.internal.schema.IndexConfig) IndexPrototype(org.neo4j.internal.schema.IndexPrototype) IndexProviderDescriptor(org.neo4j.internal.schema.IndexProviderDescriptor) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor)

Example 14 with IndexPrototype

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

the class IndexIT method shouldBeAbleToRemoveAConstraintIndexWithoutOwner.

@Test
void shouldBeAbleToRemoveAConstraintIndexWithoutOwner() throws Exception {
    // given
    AssertableLogProvider logProvider = new AssertableLogProvider();
    ConstraintIndexCreator creator = new ConstraintIndexCreator(() -> kernel, indexingService, logProvider);
    IndexProviderDescriptor provider = GenericNativeIndexProvider.DESCRIPTOR;
    IndexPrototype prototype = uniqueForSchema(schema).withName("constraint name").withIndexProvider(provider);
    IndexDescriptor constraintIndex = creator.createConstraintIndex(prototype);
    // then
    KernelTransaction transaction = newTransaction();
    assertEquals(emptySet(), asSet(transaction.schemaRead().constraintsGetForLabel(labelId)));
    commit();
    // when
    SchemaWrite schemaWrite = schemaWriteInNewTransaction();
    schemaWrite.indexDrop(constraintIndex);
    commit();
    // then
    transaction = newTransaction();
    assertEquals(emptySet(), asSet(transaction.schemaRead().indexesGetForLabel(labelId)));
    commit();
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) ConstraintIndexCreator(org.neo4j.kernel.impl.api.state.ConstraintIndexCreator) SchemaWrite(org.neo4j.internal.kernel.api.SchemaWrite) IndexProviderDescriptor(org.neo4j.internal.schema.IndexProviderDescriptor) IndexPrototype(org.neo4j.internal.schema.IndexPrototype) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.jupiter.api.Test) KernelIntegrationTest(org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest)

Example 15 with IndexPrototype

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

the class IndexIT method shouldListMultiTokenIndexesInTheCoreAPI.

@Test
void shouldListMultiTokenIndexesInTheCoreAPI() throws Exception {
    KernelTransaction transaction = newTransaction(AUTH_DISABLED);
    long initialIndexCount = Iterators.count(transaction.schemaRead().indexesGetAll());
    SchemaDescriptor schema = SchemaDescriptor.fulltext(EntityType.NODE, new int[] { labelId, labelId2 }, new int[] { propertyKeyId });
    IndexPrototype prototype = IndexPrototype.forSchema(schema, FulltextIndexProviderFactory.DESCRIPTOR).withIndexType(IndexType.FULLTEXT).withName("multi token index");
    transaction.schemaWrite().indexCreate(prototype);
    commit();
    try (org.neo4j.graphdb.Transaction tx = db.beginTx()) {
        // then
        Set<IndexDefinition> indexes = Iterables.asSet(tx.schema().getIndexes());
        assertThat(indexes.size()).isEqualTo(initialIndexCount + 1);
        IndexDefinition index = tx.schema().getIndexByName("multi token index");
        assertThrows(IllegalStateException.class, index::getRelationshipTypes);
        assertThat(index.getLabels()).containsOnly(label(LABEL), label(LABEL2));
        assertThat(index.getPropertyKeys()).containsOnly(PROPERTY_KEY);
        assertFalse(index.isConstraintIndex(), "should not be a constraint index");
        assertTrue(index.isMultiTokenIndex(), "should be a multi-token index");
        assertFalse(index.isCompositeIndex(), "should not be a composite index");
        assertTrue(index.isNodeIndex(), "should be a node index");
        assertFalse(index.isRelationshipIndex(), "should not be a relationship index");
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) IndexPrototype(org.neo4j.internal.schema.IndexPrototype) Test(org.junit.jupiter.api.Test) KernelIntegrationTest(org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest)

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