use of org.neo4j.internal.kernel.api.SchemaReadCore in project neo4j by neo4j.
the class SchemaStatementProcedureTest method schemaStatementsMustOnlyIncludeIndexBackedConstraintNotActualIndex.
@Test
void schemaStatementsMustOnlyIncludeIndexBackedConstraintNotActualIndex() throws IndexNotFoundKernelException, ProcedureException {
IndexDescriptor index = someOrphanedIndex();
ConstraintDescriptor constraint = indexBackedConstraint(index);
index = indexBoundToConstraint(index, constraint);
InternalIndexState internalIndexState = InternalIndexState.ONLINE;
SchemaReadCore schemaReadCore = getSchemaReadCore(constraint, index, internalIndexState);
TokenRead tokenRead = mock(TokenRead.class);
Collection<BuiltInProcedures.SchemaStatementResult> result = createSchemaStatementResults(schemaReadCore, tokenRead);
Iterator<BuiltInProcedures.SchemaStatementResult> iter = result.iterator();
assertTrue(iter.hasNext());
BuiltInProcedures.SchemaStatementResult next = iter.next();
assertEquals(SchemaStatementProcedure.SchemaRuleType.CONSTRAINT.name(), next.type);
assertEquals(CONSTRAINT_NAME, next.name);
assertFalse(iter.hasNext());
}
use of org.neo4j.internal.kernel.api.SchemaReadCore in project neo4j by neo4j.
the class BuiltInProcedures method listConstraints.
@Deprecated(since = "4.2.0", forRemoval = true)
@SystemProcedure
@Description("List all constraints in the database.")
@Procedure(name = "db.constraints", mode = READ, deprecatedBy = "SHOW CONSTRAINTS command")
public Stream<ConstraintResult> listConstraints() {
if (callContext.isSystemDatabase()) {
return Stream.empty();
}
SchemaReadCore schemaRead = kernelTransaction.schemaRead().snapshot();
List<ConstraintResult> result = new ArrayList<>();
final List<ConstraintDescriptor> constraintDescriptors = asList(schemaRead.constraintsGetAll());
for (ConstraintDescriptor constraint : constraintDescriptors) {
String description = ConstraintsProcedureUtil.prettyPrint(constraint, kernelTransaction.tokenRead());
String details = constraint.userDescription(kernelTransaction.tokenRead());
result.add(new ConstraintResult(constraint.getName(), description, details));
}
result.sort(Comparator.comparing(r -> r.name));
return result.stream();
}
Aggregations