Search in sources :

Example 1 with SchemaDescriptor

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

the class FulltextIndexProviderTest method createAndQueryFulltextRelationshipIndex.

@Test
void createAndQueryFulltextRelationshipIndex() throws Exception {
    IndexDescriptor indexReference;
    try (KernelTransactionImplementation transaction = getKernelTransaction()) {
        SchemaDescriptor schema = SchemaDescriptor.fulltext(EntityType.RELATIONSHIP, new int[] { labelIdHej, labelIdHa, labelIdHe }, new int[] { propIdHej, propIdHa, propIdHe, propIdHo });
        IndexPrototype prototype = IndexPrototype.forSchema(schema, DESCRIPTOR).withIndexType(FULLTEXT).withName("fulltext");
        indexReference = transaction.schemaWrite().indexCreate(prototype);
        transaction.success();
    }
    await(indexReference);
    long secondRelId;
    try (Transaction transaction = db.beginTx()) {
        Relationship ho = transaction.getNodeById(node1.getId()).createRelationshipTo(transaction.getNodeById(node2.getId()), RelationshipType.withName("ho"));
        secondRelId = ho.getId();
        ho.setProperty("hej", "villa");
        ho.setProperty("ho", "value3");
        transaction.commit();
    }
    verifyRelationshipData(secondRelId);
    controller.restartDbms();
    verifyRelationshipData(secondRelId);
}
Also used : SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) KernelTransactionImplementation(org.neo4j.kernel.impl.api.KernelTransactionImplementation) Relationship(org.neo4j.graphdb.Relationship) IndexPrototype(org.neo4j.internal.schema.IndexPrototype) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Test(org.junit.jupiter.api.Test)

Example 2 with SchemaDescriptor

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

the class FulltextIndexProviderTest method createAndRetainRelationshipFulltextIndex.

@Test
void createAndRetainRelationshipFulltextIndex() throws Exception {
    IndexDescriptor indexReference;
    try (KernelTransactionImplementation transaction = getKernelTransaction()) {
        SchemaDescriptor schema = SchemaDescriptor.fulltext(EntityType.RELATIONSHIP, new int[] { labelIdHej, labelIdHa, labelIdHe }, new int[] { propIdHej, propIdHa, propIdHe, propIdHo });
        IndexPrototype prototype = IndexPrototype.forSchema(schema, DESCRIPTOR).withIndexType(FULLTEXT).withName("fulltext");
        indexReference = transaction.schemaWrite().indexCreate(prototype);
        transaction.success();
    }
    await(indexReference);
    controller.restartDbms();
    verifyThatFulltextIndexIsPresent(indexReference);
}
Also used : SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) KernelTransactionImplementation(org.neo4j.kernel.impl.api.KernelTransactionImplementation) IndexPrototype(org.neo4j.internal.schema.IndexPrototype) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Test(org.junit.jupiter.api.Test)

Example 3 with SchemaDescriptor

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

the class FulltextIndexProviderTest method validateMustThrowIfSchemaIsNotFulltext.

@Test
void validateMustThrowIfSchemaIsNotFulltext() throws Exception {
    try (KernelTransactionImplementation transaction = getKernelTransaction()) {
        int[] propertyIds = { propIdHa };
        SchemaDescriptor schema = SchemaDescriptor.forLabel(labelIdHa, propertyIds);
        IndexPrototype prototype = IndexPrototype.forSchema(schema).withIndexType(FULLTEXT).withName(NAME);
        SchemaWrite schemaWrite = transaction.schemaWrite();
        var e = assertThrows(IllegalArgumentException.class, () -> schemaWrite.indexCreate(prototype));
        assertThat(e.getMessage()).contains("schema is not a full-text index schema");
        transaction.success();
    }
}
Also used : SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) SchemaWrite(org.neo4j.internal.kernel.api.SchemaWrite) KernelTransactionImplementation(org.neo4j.kernel.impl.api.KernelTransactionImplementation) IndexPrototype(org.neo4j.internal.schema.IndexPrototype) Test(org.junit.jupiter.api.Test)

Example 4 with SchemaDescriptor

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

the class SchemaStorageIT method shouldWriteAndReadIndexConfig.

@Test
void shouldWriteAndReadIndexConfig() throws KernelException {
    // given
    IndexConfig expected = IndexConfig.with(MapUtil.genericMap("value.string", Values.stringValue("value"), "value.int", Values.intValue(1), "value.doubleArray", Values.doubleArray(new double[] { 0.4, 0.6, 1.0 }), "value.boolean", Values.booleanValue(true)));
    var cursorContext = NULL;
    SchemaDescriptor schema = forLabel(labelId(LABEL1), propId(PROP1));
    long id = schemaStore.nextId(cursorContext);
    IndexDescriptor storeIndexDescriptor = forSchema(schema).withName("index_" + id).materialise(id).withIndexConfig(expected);
    storage.writeSchemaRule(storeIndexDescriptor, cursorContext, INSTANCE);
    // when
    IndexDescriptor schemaRule = (IndexDescriptor) storage.loadSingleSchemaRule(id, NULL);
    // Clean up after ourselves.
    storage.deleteSchemaRule(schemaRule, NULL);
    // then
    IndexConfig actual = schemaRule.getIndexConfig();
    assertEquals(expected, actual, "Read index config not same as written, expected " + expected + ", actual " + actual);
}
Also used : SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) IndexConfig(org.neo4j.internal.schema.IndexConfig) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Test(org.junit.jupiter.api.Test)

Example 5 with SchemaDescriptor

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

the class Operations method uniquePropertyConstraintCreate.

@Override
public ConstraintDescriptor uniquePropertyConstraintCreate(IndexPrototype prototype) throws KernelException {
    SchemaDescriptor schema = prototype.schema();
    exclusiveSchemaLock(schema);
    ktx.assertOpen();
    prototype = ensureIndexPrototypeHasIndexProvider(prototype);
    UniquenessConstraintDescriptor constraint = ConstraintDescriptorFactory.uniqueForSchema(schema);
    try {
        assertValidDescriptor(schema, SchemaKernelException.OperationContext.CONSTRAINT_CREATION);
        if (prototype.getName().isEmpty()) {
            constraint = ensureConstraintHasName(constraint);
            prototype = prototype.withName(constraint.getName());
        } else {
            constraint = constraint.withName(prototype.getName().get());
        }
        exclusiveSchemaNameLock(constraint.getName());
        assertNoBlockingSchemaRulesExists(constraint);
    } catch (KernelException e) {
        // Try not to hold on to exclusive schema locks when we don't strictly need them.
        exclusiveSchemaUnlock(schema);
        throw e;
    }
    // Create constraints
    constraint = indexBackedConstraintCreate(constraint, prototype);
    return constraint;
}
Also used : RelationTypeSchemaDescriptor(org.neo4j.internal.schema.RelationTypeSchemaDescriptor) SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) UniquenessConstraintDescriptor(org.neo4j.internal.schema.constraints.UniquenessConstraintDescriptor) IndexNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException) KernelException(org.neo4j.exceptions.KernelException) UnspecifiedKernelException(org.neo4j.exceptions.UnspecifiedKernelException) IndexBrokenKernelException(org.neo4j.kernel.api.exceptions.schema.IndexBrokenKernelException) IndexNotApplicableKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotApplicableKernelException) SchemaKernelException(org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException) PropertyKeyIdNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.PropertyKeyIdNotFoundKernelException)

Aggregations

SchemaDescriptor (org.neo4j.internal.schema.SchemaDescriptor)58 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)27 LabelSchemaDescriptor (org.neo4j.internal.schema.LabelSchemaDescriptor)23 Test (org.junit.jupiter.api.Test)18 IndexPrototype (org.neo4j.internal.schema.IndexPrototype)18 RelationTypeSchemaDescriptor (org.neo4j.internal.schema.RelationTypeSchemaDescriptor)18 Value (org.neo4j.values.storable.Value)11 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)10 ArrayList (java.util.ArrayList)6 KernelTransactionImplementation (org.neo4j.kernel.impl.api.KernelTransactionImplementation)6 IndexNotFoundKernelException (org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException)5 IndexConfig (org.neo4j.internal.schema.IndexConfig)5 MemoryTracker (org.neo4j.memory.MemoryTracker)5 KernelException (org.neo4j.exceptions.KernelException)4 UnspecifiedKernelException (org.neo4j.exceptions.UnspecifiedKernelException)4 IndexDefinition (org.neo4j.graphdb.schema.IndexDefinition)4 IndexNotApplicableKernelException (org.neo4j.internal.kernel.api.exceptions.schema.IndexNotApplicableKernelException)4 SchemaKernelException (org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException)4 ConstraintDescriptor (org.neo4j.internal.schema.ConstraintDescriptor)4 IndexProviderDescriptor (org.neo4j.internal.schema.IndexProviderDescriptor)4