Search in sources :

Example 6 with ReadOperations

use of org.neo4j.kernel.api.ReadOperations in project neo4j by neo4j.

the class BuiltInProcedures method listConstraints.

@Description("List all constraints in the database.")
@Procedure(name = "db.constraints", mode = READ)
public Stream<ConstraintResult> listConstraints() {
    Statement statement = tx.acquireStatement();
    ReadOperations operations = statement.readOperations();
    TokenNameLookup tokens = new StatementTokenNameLookup(operations);
    return asList(operations.constraintsGetAll()).stream().map((constraint) -> constraint.prettyPrint(tokens)).sorted().map(ConstraintResult::new).onClose(statement::close);
}
Also used : IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) ProcedureException(org.neo4j.kernel.api.exceptions.ProcedureException) Label(org.neo4j.graphdb.Label) Context(org.neo4j.procedure.Context) Status(org.neo4j.kernel.api.exceptions.Status) Iterators.asSet(org.neo4j.helpers.collection.Iterators.asSet) StatementTokenNameLookup(org.neo4j.kernel.api.StatementTokenNameLookup) Statement(org.neo4j.kernel.api.Statement) IndexNotFoundKernelException(org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException) ArrayList(java.util.ArrayList) TokenNameLookup(org.neo4j.kernel.api.TokenNameLookup) Procedure(org.neo4j.procedure.Procedure) TokenAccess(org.neo4j.kernel.impl.api.TokenAccess) ReadOperations(org.neo4j.kernel.api.ReadOperations) Set(java.util.Set) READ(org.neo4j.procedure.Mode.READ) Description(org.neo4j.procedure.Description) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Stream(java.util.stream.Stream) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Iterators.asList(org.neo4j.helpers.collection.Iterators.asList) DependencyResolver(org.neo4j.graphdb.DependencyResolver) Name(org.neo4j.procedure.Name) RelationshipType(org.neo4j.graphdb.RelationshipType) Comparator(java.util.Comparator) ReadOperations(org.neo4j.kernel.api.ReadOperations) StatementTokenNameLookup(org.neo4j.kernel.api.StatementTokenNameLookup) TokenNameLookup(org.neo4j.kernel.api.TokenNameLookup) StatementTokenNameLookup(org.neo4j.kernel.api.StatementTokenNameLookup) Statement(org.neo4j.kernel.api.Statement) Description(org.neo4j.procedure.Description) Procedure(org.neo4j.procedure.Procedure)

Example 7 with ReadOperations

use of org.neo4j.kernel.api.ReadOperations in project neo4j by neo4j.

the class IndexIT method shouldNotListConstraintIndexesAmongIndexes.

@Test
public void shouldNotListConstraintIndexesAmongIndexes() throws Exception {
    // given
    SchemaWriteOperations schemaWriteOperations = schemaWriteOperationsInNewTransaction();
    schemaWriteOperations.uniquePropertyConstraintCreate(SchemaBoundary.map(descriptor));
    commit();
    // then/when
    ReadOperations readOperations = readOperationsInNewTransaction();
    assertFalse(readOperations.indexesGetAll().hasNext());
    assertFalse(readOperations.indexesGetForLabel(labelId).hasNext());
}
Also used : ReadOperations(org.neo4j.kernel.api.ReadOperations) SchemaWriteOperations(org.neo4j.kernel.api.SchemaWriteOperations) Test(org.junit.Test) KernelIntegrationTest(org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest)

Example 8 with ReadOperations

use of org.neo4j.kernel.api.ReadOperations in project neo4j by neo4j.

the class IndexIT method shouldNotListIndexesAmongConstraintIndexes.

@Test
public void shouldNotListIndexesAmongConstraintIndexes() throws Exception {
    // given
    SchemaWriteOperations schemaWriteOperations = schemaWriteOperationsInNewTransaction();
    schemaWriteOperations.indexCreate(SchemaBoundary.map(descriptor));
    commit();
    // then/when
    ReadOperations readOperations = readOperationsInNewTransaction();
    assertFalse(readOperations.uniqueIndexesGetAll().hasNext());
    assertFalse(readOperations.uniqueIndexesGetForLabel(labelId).hasNext());
}
Also used : ReadOperations(org.neo4j.kernel.api.ReadOperations) SchemaWriteOperations(org.neo4j.kernel.api.SchemaWriteOperations) Test(org.junit.Test) KernelIntegrationTest(org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest)

Example 9 with ReadOperations

use of org.neo4j.kernel.api.ReadOperations in project neo4j by neo4j.

the class IndexIT method rollBackIndexRuleShouldNotBeCommitted.

@Test
public void rollBackIndexRuleShouldNotBeCommitted() throws Exception {
    // GIVEN
    SchemaWriteOperations schemaWriteOperations = schemaWriteOperationsInNewTransaction();
    // WHEN
    schemaWriteOperations.indexCreate(SchemaBoundary.map(descriptor));
    // don't mark as success
    rollback();
    // THEN
    ReadOperations readOperations = readOperationsInNewTransaction();
    assertEquals(emptySetOf(NewIndexDescriptor.class), asSet(readOperations.indexesGetForLabel(labelId)));
    commit();
}
Also used : ReadOperations(org.neo4j.kernel.api.ReadOperations) SchemaWriteOperations(org.neo4j.kernel.api.SchemaWriteOperations) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) Test(org.junit.Test) KernelIntegrationTest(org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest)

Example 10 with ReadOperations

use of org.neo4j.kernel.api.ReadOperations in project neo4j by neo4j.

the class IndexIT method shouldRemoveAConstraintIndexWithoutOwnerInRecovery.

@Test
public void shouldRemoveAConstraintIndexWithoutOwnerInRecovery() throws Exception {
    // given
    PropertyAccessor propertyAccessor = mock(PropertyAccessor.class);
    ConstraintIndexCreator creator = new ConstraintIndexCreator(() -> kernel, indexingService, propertyAccessor, false);
    creator.createConstraintIndex(SchemaBoundary.map(descriptor));
    // when
    restartDb();
    // then
    ReadOperations readOperations = readOperationsInNewTransaction();
    assertEquals(emptySetOf(NewIndexDescriptor.class), asSet(readOperations.indexesGetForLabel(labelId)));
    commit();
}
Also used : ReadOperations(org.neo4j.kernel.api.ReadOperations) ConstraintIndexCreator(org.neo4j.kernel.impl.api.state.ConstraintIndexCreator) PropertyAccessor(org.neo4j.kernel.api.index.PropertyAccessor) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) Test(org.junit.Test) KernelIntegrationTest(org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest)

Aggregations

ReadOperations (org.neo4j.kernel.api.ReadOperations)73 Test (org.junit.Test)52 Statement (org.neo4j.kernel.api.Statement)37 NewIndexDescriptor (org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)22 SchemaWriteOperations (org.neo4j.kernel.api.SchemaWriteOperations)9 KeyReadOperations (org.neo4j.kernel.impl.api.operations.KeyReadOperations)8 IndexNotFoundKernelException (org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException)7 NotFoundException (org.neo4j.graphdb.NotFoundException)5 Transaction (org.neo4j.graphdb.Transaction)5 HashMap (java.util.HashMap)4 PrimitiveLongSet (org.neo4j.collection.primitive.PrimitiveLongSet)4 IndexDefinition (org.neo4j.graphdb.schema.IndexDefinition)4 DataWriteOperations (org.neo4j.kernel.api.DataWriteOperations)4 KernelIntegrationTest (org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest)4 ArrayList (java.util.ArrayList)3 Set (java.util.Set)3 PrimitiveLongIterator (org.neo4j.collection.primitive.PrimitiveLongIterator)3 Label (org.neo4j.graphdb.Label)3 RelationshipType (org.neo4j.graphdb.RelationshipType)3 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)3