use of org.neo4j.internal.schema.LabelSchemaDescriptor in project neo4j by neo4j.
the class ConstraintTestBase method shouldFindConstraintsBySchema.
@Test
void shouldFindConstraintsBySchema() throws Exception {
// GIVEN
addConstraints("FOO", "prop");
try (KernelTransaction tx = beginTransaction()) {
int label = tx.tokenWrite().labelGetOrCreateForName("FOO");
int prop = tx.tokenWrite().propertyKeyGetOrCreateForName("prop");
LabelSchemaDescriptor descriptor = labelSchemaDescriptor(label, prop);
// WHEN
List<ConstraintDescriptor> constraints = asList(tx.schemaRead().constraintsGetForSchema(descriptor));
// THEN
assertThat(constraints).hasSize(1);
assertThat(constraints.get(0).schema().getPropertyId()).isEqualTo(prop);
}
}
use of org.neo4j.internal.schema.LabelSchemaDescriptor in project neo4j by neo4j.
the class IndexProcedures method createIndex.
private Stream<BuiltInProcedures.SchemaIndexInfo> createIndex(String name, List<String> labels, List<String> properties, IndexProviderDescriptor indexProviderDescriptor, Map<String, Object> configMap, String statusMessage, IndexCreator indexCreator) throws ProcedureException {
IndexConfig indexConfig = IndexSettingUtil.toIndexConfigFromStringObjectMap(configMap);
assertSingleLabel(labels);
assertValidIndexProvider(indexProviderDescriptor);
int labelId = getOrCreateLabelId(labels.get(0));
int[] propertyKeyIds = getOrCreatePropertyIds(properties);
try {
SchemaWrite schemaWrite = ktx.schemaWrite();
LabelSchemaDescriptor labelSchemaDescriptor = SchemaDescriptor.forLabel(labelId, propertyKeyIds);
indexCreator.create(schemaWrite, name, labelSchemaDescriptor, indexProviderDescriptor, indexConfig);
return Stream.of(new BuiltInProcedures.SchemaIndexInfo(name, labels, properties, indexProviderDescriptor.name(), statusMessage));
} catch (KernelException e) {
throw new ProcedureException(e.status(), e, e.getMessage());
}
}
use of org.neo4j.internal.schema.LabelSchemaDescriptor in project neo4j by neo4j.
the class IndexCRUDIT method addingALabelToPreExistingNodeShouldGetIndexed.
@Test
void addingALabelToPreExistingNodeShouldGetIndexed() throws Exception {
// GIVEN
String indexProperty = "indexProperty";
GatheringIndexWriter writer = newWriter();
createIndex(db, myLabel, indexProperty);
// WHEN
String otherProperty = "otherProperty";
int value = 12;
int otherValue = 17;
Node node = createNode(map(indexProperty, value, otherProperty, otherValue));
// THEN
assertThat(writer.updatesCommitted.size()).isEqualTo(0);
// AND WHEN
try (Transaction tx = db.beginTx()) {
node = tx.getNodeById(node.getId());
node.addLabel(myLabel);
tx.commit();
}
// THEN
try (Transaction tx = db.beginTx()) {
KernelTransaction ktx = ((InternalTransaction) tx).kernelTransaction();
TokenRead tokenRead = ktx.tokenRead();
int propertyKey1 = tokenRead.propertyKey(indexProperty);
int label = tokenRead.nodeLabel(myLabel.name());
LabelSchemaDescriptor descriptor = SchemaDescriptor.forLabel(label, propertyKey1);
assertThat(writer.updatesCommitted).isEqualTo(asSet(IndexEntryUpdate.add(node.getId(), descriptor, Values.of(value))));
tx.commit();
}
}
use of org.neo4j.internal.schema.LabelSchemaDescriptor in project neo4j by neo4j.
the class IndexStatisticsTest method createPersonNameIndex.
private IndexDescriptor createPersonNameIndex() throws KernelException {
try (Transaction tx = db.beginTx()) {
KernelTransaction ktx = ((InternalTransaction) tx).kernelTransaction();
int labelId = ktx.tokenWrite().labelGetOrCreateForName(PERSON_LABEL);
int propertyKeyId = ktx.tokenWrite().propertyKeyGetOrCreateForName(NAME_PROPERTY);
LabelSchemaDescriptor schema = forLabel(labelId, propertyKeyId);
var index = ktx.schemaWrite().indexCreate(schema, "my index");
tx.commit();
return index;
}
}
use of org.neo4j.internal.schema.LabelSchemaDescriptor in project neo4j by neo4j.
the class IndexEntryConflictExceptionTest method shouldMakeEntryConflictsForOneNode.
@Test
void shouldMakeEntryConflictsForOneNode() {
LabelSchemaDescriptor schema = SchemaDescriptor.forLabel(labelId, 2);
IndexEntryConflictException e = new IndexEntryConflictException(0L, StatementConstants.NO_SUCH_NODE, value);
assertThat(e.evidenceMessage(tokens, schema)).isEqualTo("Node(0) already exists with label `label1` and property `p2` = 'hi'");
}
Aggregations