Search in sources :

Example 46 with ReadOperations

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

the class AbstractConstraintCreationIT method shouldNotPersistConstraintCreatedInAbortedTransaction.

@Test
public void shouldNotPersistConstraintCreatedInAbortedTransaction() throws Exception {
    // given
    SchemaWriteOperations schemaWriteOperations = schemaWriteOperationsInNewTransaction();
    createConstraint(schemaWriteOperations, descriptor);
    // when
    rollback();
    ReadOperations readOperations = readOperationsInNewTransaction();
    // then
    Iterator<?> constraints = readOperations.constraintsGetAll();
    assertFalse("should not have any constraints", constraints.hasNext());
}
Also used : ReadOperations(org.neo4j.kernel.api.ReadOperations) SchemaWriteOperations(org.neo4j.kernel.api.SchemaWriteOperations) Test(org.junit.Test)

Example 47 with ReadOperations

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

the class NodePropertyExistenceConstraintCreationIT method shouldNotDropPropertyExistenceConstraintThatDoesNotExistWhenThereIsAUniquePropertyConstraint.

@Test
public void shouldNotDropPropertyExistenceConstraintThatDoesNotExistWhenThereIsAUniquePropertyConstraint() throws Exception {
    // given
    UniquenessConstraintDescriptor constraint;
    {
        SchemaWriteOperations statement = schemaWriteOperationsInNewTransaction();
        constraint = statement.uniquePropertyConstraintCreate(descriptor);
        commit();
    }
    // when
    try {
        SchemaWriteOperations statement = schemaWriteOperationsInNewTransaction();
        statement.constraintDrop(ConstraintDescriptorFactory.existsForSchema(constraint.schema()));
        fail("expected exception");
    }// then
     catch (DropConstraintFailureException e) {
        assertThat(e.getCause(), instanceOf(NoSuchConstraintException.class));
    } finally {
        rollback();
    }
    // then
    {
        ReadOperations statement = readOperationsInNewTransaction();
        Iterator<ConstraintDescriptor> constraints = statement.constraintsGetForSchema(descriptor);
        assertEquals(constraint, single(constraints));
    }
}
Also used : ReadOperations(org.neo4j.kernel.api.ReadOperations) SchemaWriteOperations(org.neo4j.kernel.api.SchemaWriteOperations) ResourceIterator(org.neo4j.graphdb.ResourceIterator) Iterator(java.util.Iterator) UniquenessConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.UniquenessConstraintDescriptor) DropConstraintFailureException(org.neo4j.kernel.api.exceptions.schema.DropConstraintFailureException) Test(org.junit.Test)

Example 48 with ReadOperations

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

the class UniquenessConstraintCreationIT method shouldNotDropUniquePropertyConstraintThatDoesNotExistWhenThereIsAPropertyExistenceConstraint.

@Test
public void shouldNotDropUniquePropertyConstraintThatDoesNotExistWhenThereIsAPropertyExistenceConstraint() throws Exception {
    // given
    SchemaWriteOperations schemaWriteOperations = schemaWriteOperationsInNewTransaction();
    schemaWriteOperations.nodePropertyExistenceConstraintCreate(descriptor);
    commit();
    // when
    try {
        SchemaWriteOperations statement = schemaWriteOperationsInNewTransaction();
        statement.constraintDrop(ConstraintDescriptorFactory.uniqueForSchema(descriptor));
        fail("expected exception");
    }// then
     catch (DropConstraintFailureException e) {
        assertThat(e.getCause(), instanceOf(NoSuchConstraintException.class));
    } finally {
        rollback();
    }
    // then
    {
        ReadOperations statement = readOperationsInNewTransaction();
        Iterator<ConstraintDescriptor> constraints = statement.constraintsGetForSchema(descriptor);
        assertEquals(ConstraintDescriptorFactory.existsForSchema(descriptor), single(constraints));
    }
}
Also used : ReadOperations(org.neo4j.kernel.api.ReadOperations) SchemaWriteOperations(org.neo4j.kernel.api.SchemaWriteOperations) ResourceIterator(org.neo4j.graphdb.ResourceIterator) Iterator(java.util.Iterator) DropConstraintFailureException(org.neo4j.kernel.api.exceptions.schema.DropConstraintFailureException) Test(org.junit.Test)

Example 49 with ReadOperations

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

the class UniquenessConstraintCreationIT method shouldDropConstraintIndexWhenDroppingConstraint.

@Test
public void shouldDropConstraintIndexWhenDroppingConstraint() throws Exception {
    // given
    Statement statement = statementInNewTransaction(SecurityContext.AUTH_DISABLED);
    UniquenessConstraintDescriptor constraint = statement.schemaWriteOperations().uniquePropertyConstraintCreate(descriptor);
    assertEquals(asSet(uniqueIndex), asSet(statement.readOperations().uniqueIndexesGetAll()));
    commit();
    // when
    SchemaWriteOperations schemaWriteOperations = schemaWriteOperationsInNewTransaction();
    schemaWriteOperations.constraintDrop(constraint);
    commit();
    // then
    ReadOperations readOperations = readOperationsInNewTransaction();
    assertEquals(emptySetOf(NewIndexDescriptor.class), asSet(readOperations.uniqueIndexesGetAll()));
    commit();
}
Also used : ReadOperations(org.neo4j.kernel.api.ReadOperations) SchemaWriteOperations(org.neo4j.kernel.api.SchemaWriteOperations) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) Statement(org.neo4j.kernel.api.Statement) UniquenessConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.UniquenessConstraintDescriptor) Test(org.junit.Test)

Example 50 with ReadOperations

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

the class AbstractConstraintCreationIT method shouldBeAbleToStoreAndRetrieveConstraint.

@Test
public void shouldBeAbleToStoreAndRetrieveConstraint() throws Exception {
    // given
    Statement statement = statementInNewTransaction(SecurityContext.AUTH_DISABLED);
    // when
    ConstraintDescriptor constraint = createConstraint(statement.schemaWriteOperations(), descriptor);
    // then
    assertEquals(constraint, single(statement.readOperations().constraintsGetAll()));
    // given
    commit();
    ReadOperations readOperations = readOperationsInNewTransaction();
    // when
    Iterator<?> constraints = readOperations.constraintsGetAll();
    // then
    assertEquals(constraint, single(constraints));
}
Also used : ReadOperations(org.neo4j.kernel.api.ReadOperations) Statement(org.neo4j.kernel.api.Statement) ConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor) Test(org.junit.Test)

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