use of org.neo4j.internal.kernel.api.SchemaReadCore in project neo4j by neo4j.
the class BuiltInProcedures method schemaStatements.
@Deprecated(since = "4.2.0", forRemoval = true)
@SystemProcedure
@Description("List all statements for creating and dropping existing indexes and constraints. " + "Note that only index types introduced before Neo4j 4.3 are included.")
@Procedure(name = "db.schemaStatements", mode = READ, deprecatedBy = "SHOW INDEXES YIELD * command and SHOW CONSTRAINTS YIELD * command")
public Stream<SchemaStatementResult> schemaStatements() throws ProcedureException {
if (callContext.isSystemDatabase()) {
return Stream.empty();
}
SchemaReadCore schemaRead = kernelTransaction.schemaRead().snapshot();
final TokenRead tokenRead = kernelTransaction.tokenRead();
return SchemaStatementProcedure.createSchemaStatementResults(schemaRead, tokenRead).stream();
}
use of org.neo4j.internal.kernel.api.SchemaReadCore in project neo4j by neo4j.
the class BuiltInProcedures method listIndexes.
@Deprecated(since = "4.2.0", forRemoval = true)
@SystemProcedure
@Description("List all indexes in the database.")
@Procedure(name = "db.indexes", mode = READ, deprecatedBy = "SHOW INDEXES command")
public Stream<IndexResult> listIndexes() {
if (callContext.isSystemDatabase()) {
return Stream.empty();
}
TokenRead tokenRead = kernelTransaction.tokenRead();
IndexingService indexingService = resolver.resolveDependency(IndexingService.class);
SchemaReadCore schemaRead = kernelTransaction.schemaRead().snapshot();
List<IndexDescriptor> indexes = asList(schemaRead.indexesGetAll());
List<IndexResult> result = new ArrayList<>();
for (IndexDescriptor index : indexes) {
IndexResult indexResult;
indexResult = asIndexResult(tokenRead, schemaRead, index);
result.add(indexResult);
}
result.sort(Comparator.comparing(r -> r.name));
return result.stream();
}
use of org.neo4j.internal.kernel.api.SchemaReadCore in project neo4j by neo4j.
the class SchemaReadWriteTestBase method shouldSeeUniqueConstraintFromTransaction.
@Test
void shouldSeeUniqueConstraintFromTransaction() throws Exception {
ConstraintDescriptor existing;
try (KernelTransaction transaction = beginTransaction()) {
existing = transaction.schemaWrite().uniquePropertyConstraintCreate(uniqueForSchema(forLabel(label, prop1)).withName("existing constraint"));
transaction.commit();
}
try (KernelTransaction transaction = beginTransaction()) {
SchemaReadCore before = transaction.schemaRead().snapshot();
ConstraintDescriptor newConstraint = transaction.schemaWrite().uniquePropertyConstraintCreate(uniqueForSchema(forLabel(label, prop2)).withName("new constraint"));
SchemaRead schemaRead = transaction.schemaRead();
SchemaReadCore after = schemaRead.snapshot();
assertTrue(schemaRead.constraintExists(existing));
assertTrue(schemaRead.constraintExists(newConstraint));
assertThat(asList(schemaRead.constraintsGetForLabel(label))).contains(existing, newConstraint);
assertThat(asList(before.constraintsGetForLabel(label))).contains(existing, newConstraint);
assertThat(asList(after.constraintsGetForLabel(label))).contains(existing, newConstraint);
assertThat(before.constraintGetForName("existing constraint")).isEqualTo(existing);
assertThat(after.constraintGetForName("existing constraint")).isEqualTo(existing);
assertThat(before.constraintGetForName("new constraint")).isEqualTo(newConstraint);
assertThat(after.constraintGetForName("new constraint")).isEqualTo(newConstraint);
}
}
use of org.neo4j.internal.kernel.api.SchemaReadCore in project neo4j by neo4j.
the class SchemaReadWriteTestBase method shouldNotSeeDroppedUniqueConstraintFromTransaction.
@Test
void shouldNotSeeDroppedUniqueConstraintFromTransaction() throws Exception {
ConstraintDescriptor existing;
try (KernelTransaction transaction = beginTransaction()) {
existing = transaction.schemaWrite().uniquePropertyConstraintCreate(uniqueForSchema(forLabel(label, prop1)));
transaction.commit();
}
try (KernelTransaction transaction = beginTransaction()) {
SchemaReadCore before = transaction.schemaRead().snapshot();
transaction.schemaWrite().constraintDrop(existing);
SchemaRead schemaRead = transaction.schemaRead();
assertFalse(schemaRead.constraintExists(existing));
assertThat(asList(schemaRead.constraintsGetForLabel(label))).isEmpty();
assertThat(asList(schemaRead.snapshot().constraintsGetForLabel(label))).isEmpty();
assertThat(asList(before.constraintsGetForLabel(label))).isEmpty();
}
}
use of org.neo4j.internal.kernel.api.SchemaReadCore in project neo4j by neo4j.
the class SchemaReadWriteTestBase method shouldNotSeeDroppedIndexFromTransactionInSnapshot.
@Test
void shouldNotSeeDroppedIndexFromTransactionInSnapshot() throws Exception {
IndexDescriptor index;
try (KernelTransaction transaction = beginTransaction()) {
index = transaction.schemaWrite().indexCreate(forLabel(label, prop1), "my index");
transaction.commit();
}
try (KernelTransaction transaction = beginTransaction()) {
SchemaReadCore schemaReadBefore = transaction.schemaRead().snapshot();
transaction.schemaWrite().indexDrop(index);
SchemaReadCore schemaReadAfter = transaction.schemaRead().snapshot();
assertFalse(schemaReadBefore.index(forLabel(label, prop2)).hasNext());
assertFalse(schemaReadAfter.index(forLabel(label, prop2)).hasNext());
assertThat(schemaReadBefore.indexGetForName("my index")).isEqualTo(NO_INDEX);
}
}
Aggregations