Search in sources :

Example 31 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 32 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 33 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)

Example 34 with ReadOperations

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

the class IndexCRUDIT method addingALabelToPreExistingNodeShouldGetIndexed.

@Test
public 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(), equalTo(0));
    // AND WHEN
    try (Transaction tx = db.beginTx()) {
        node.addLabel(myLabel);
        tx.success();
    }
    // THEN
    try (Transaction tx = db.beginTx()) {
        ReadOperations readOperations = ctxSupplier.get().readOperations();
        int propertyKey1 = readOperations.propertyKeyGetForName(indexProperty);
        int label = readOperations.labelGetForName(myLabel.name());
        LabelSchemaDescriptor descriptor = SchemaDescriptorFactory.forLabel(label, propertyKey1);
        assertThat(writer.updatesCommitted, equalTo(asSet(IndexEntryUpdate.add(node.getId(), descriptor, value))));
        tx.success();
    }
}
Also used : ReadOperations(org.neo4j.kernel.api.ReadOperations) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) LabelSchemaDescriptor(org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor) Test(org.junit.Test)

Example 35 with ReadOperations

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

the class GraphDbStructureGuide method showStructure.

private void showStructure(Statement statement, DbStructureVisitor visitor) {
    ReadOperations read = statement.readOperations();
    try {
        showTokens(visitor, read);
        showSchema(visitor, read);
        showStatistics(visitor, read);
    } catch (KernelException e) {
        throw new IllegalStateException("Kernel exception when traversing database schema structure and statistics.  This is not expected to happen.", e);
    }
}
Also used : ReadOperations(org.neo4j.kernel.api.ReadOperations) IndexNotFoundKernelException(org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException) KernelException(org.neo4j.kernel.api.exceptions.KernelException)

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