Search in sources :

Example 1 with SchemaWriteOperations

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

the class IndexIT method shouldFailToCreateIndexWhereAConstraintAlreadyExists.

@Test
public void shouldFailToCreateIndexWhereAConstraintAlreadyExists() throws Exception {
    // given
    {
        SchemaWriteOperations statement = schemaWriteOperationsInNewTransaction();
        statement.uniquePropertyConstraintCreate(SchemaBoundary.map(descriptor));
        commit();
    }
    // when
    try {
        SchemaWriteOperations statement = schemaWriteOperationsInNewTransaction();
        statement.indexCreate(SchemaBoundary.map(descriptor));
        commit();
        fail("expected exception");
    }// then
     catch (SchemaKernelException e) {
        assertEquals("Label '" + LABEL + "' and property '" + PROPERTY_KEY + "' have a unique constraint defined" + " on them, so an index is already created that matches this.", e.getMessage());
    }
}
Also used : SchemaWriteOperations(org.neo4j.kernel.api.SchemaWriteOperations) SchemaKernelException(org.neo4j.kernel.api.exceptions.schema.SchemaKernelException) Test(org.junit.Test) KernelIntegrationTest(org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest)

Example 2 with SchemaWriteOperations

use of org.neo4j.kernel.api.SchemaWriteOperations 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 3 with SchemaWriteOperations

use of org.neo4j.kernel.api.SchemaWriteOperations 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 4 with SchemaWriteOperations

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

the class IndexIT method shouldDisallowDroppingIndexThatDoesNotExist.

@Test
public void shouldDisallowDroppingIndexThatDoesNotExist() throws Exception {
    // given
    NewIndexDescriptor index;
    {
        SchemaWriteOperations statement = schemaWriteOperationsInNewTransaction();
        index = statement.indexCreate(SchemaBoundary.map(descriptor));
        commit();
    }
    {
        SchemaWriteOperations statement = schemaWriteOperationsInNewTransaction();
        statement.indexDrop(index);
        commit();
    }
    // when
    try {
        SchemaWriteOperations statement = schemaWriteOperationsInNewTransaction();
        statement.indexDrop(index);
        commit();
    }// then
     catch (SchemaKernelException e) {
        assertEquals("Unable to drop index on :label[" + labelId + "](property[" + propertyKeyId + "]): " + "No such INDEX ON :label[" + labelId + "](property[" + propertyKeyId + "]).", e.getMessage());
    }
}
Also used : NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) SchemaWriteOperations(org.neo4j.kernel.api.SchemaWriteOperations) SchemaKernelException(org.neo4j.kernel.api.exceptions.schema.SchemaKernelException) Test(org.junit.Test) KernelIntegrationTest(org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest)

Example 5 with SchemaWriteOperations

use of org.neo4j.kernel.api.SchemaWriteOperations 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)

Aggregations

SchemaWriteOperations (org.neo4j.kernel.api.SchemaWriteOperations)20 Test (org.junit.Test)19 ReadOperations (org.neo4j.kernel.api.ReadOperations)9 KernelIntegrationTest (org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest)8 NewIndexDescriptor (org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)5 Statement (org.neo4j.kernel.api.Statement)4 Iterator (java.util.Iterator)2 ResourceIterator (org.neo4j.graphdb.ResourceIterator)2 DropConstraintFailureException (org.neo4j.kernel.api.exceptions.schema.DropConstraintFailureException)2 SchemaKernelException (org.neo4j.kernel.api.exceptions.schema.SchemaKernelException)2 UniquenessConstraintDescriptor (org.neo4j.kernel.api.schema_new.constaints.UniquenessConstraintDescriptor)2 ArrayList (java.util.ArrayList)1 Node (org.neo4j.graphdb.Node)1 QueryExecutionException (org.neo4j.graphdb.QueryExecutionException)1 Transaction (org.neo4j.graphdb.Transaction)1 TokenWriteOperations (org.neo4j.kernel.api.TokenWriteOperations)1 ProcedureException (org.neo4j.kernel.api.exceptions.ProcedureException)1 AlreadyConstrainedException (org.neo4j.kernel.api.exceptions.schema.AlreadyConstrainedException)1 ConstraintValidationException (org.neo4j.kernel.api.exceptions.schema.ConstraintValidationException)1 CreateConstraintFailureException (org.neo4j.kernel.api.exceptions.schema.CreateConstraintFailureException)1