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);
}
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);
}
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();
}
}
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);
}
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;
}
Aggregations