Search in sources :

Example 16 with SchemaWriteOperations

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

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

the class AbstractConstraintCreationIT method shouldBeAbleToResolveConflictsAndRecreateConstraintAfterFailingToCreateItDueToConflict.

@Test
public void shouldBeAbleToResolveConflictsAndRecreateConstraintAfterFailingToCreateItDueToConflict() throws Exception {
    // given
    try (Transaction tx = db.beginTx()) {
        createOffendingDataInRunningTx(db);
        tx.success();
    }
    // when
    try (Transaction tx = db.beginTx()) {
        createConstraintInRunningTx(db, KEY, PROP);
        tx.success();
        fail("expected failure");
    } catch (QueryExecutionException e) {
        assertThat(e.getMessage(), startsWith("Unable to create CONSTRAINT"));
    }
    try (Transaction tx = db.beginTx()) {
        removeOffendingDataInRunningTx(db);
        tx.success();
    }
    // then - this should not fail
    SchemaWriteOperations statement = schemaWriteOperationsInNewTransaction();
    createConstraint(statement, descriptor);
    commit();
}
Also used : QueryExecutionException(org.neo4j.graphdb.QueryExecutionException) SchemaWriteOperations(org.neo4j.kernel.api.SchemaWriteOperations) Transaction(org.neo4j.graphdb.Transaction) Test(org.junit.Test)

Example 18 with SchemaWriteOperations

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

the class KernelTransactionSecurityContextTest method shouldAllowSchemaWriteAccessInFullMode.

@Test
public void shouldAllowSchemaWriteAccessInFullMode() throws Throwable {
    // Given
    KernelTransactionImplementation tx = newTransaction(AUTH_DISABLED);
    // When
    SchemaWriteOperations writes = tx.acquireStatement().schemaWriteOperations();
    // Then
    assertNotNull(writes);
}
Also used : SchemaWriteOperations(org.neo4j.kernel.api.SchemaWriteOperations) Test(org.junit.Test)

Example 19 with SchemaWriteOperations

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

the class IndexIT method addIndexRuleInATransaction.

@Test
public void addIndexRuleInATransaction() throws Exception {
    // GIVEN
    SchemaWriteOperations schemaWriteOperations = schemaWriteOperationsInNewTransaction();
    // WHEN
    NewIndexDescriptor expectedRule = schemaWriteOperations.indexCreate(SchemaBoundary.map(descriptor));
    commit();
    // THEN
    ReadOperations readOperations = readOperationsInNewTransaction();
    assertEquals(asSet(expectedRule), asSet(readOperations.indexesGetForLabel(labelId)));
    assertEquals(expectedRule, readOperations.indexGetForLabelAndPropertyKey(descriptor));
    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 20 with SchemaWriteOperations

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

the class UniquenessConstraintValidationIT method createConstraint.

private void createConstraint(String label, String propertyKey) throws KernelException {
    //TODO: Consider testing composite indexes
    int labelId, propertyKeyId;
    TokenWriteOperations tokenWriteOperations = tokenWriteOperationsInNewTransaction();
    labelId = tokenWriteOperations.labelGetOrCreateForName(label);
    propertyKeyId = tokenWriteOperations.propertyKeyGetOrCreateForName(propertyKey);
    commit();
    SchemaWriteOperations schemaWriteOperations = schemaWriteOperationsInNewTransaction();
    schemaWriteOperations.uniquePropertyConstraintCreate(forLabel(labelId, propertyKeyId));
    commit();
}
Also used : TokenWriteOperations(org.neo4j.kernel.api.TokenWriteOperations) SchemaWriteOperations(org.neo4j.kernel.api.SchemaWriteOperations)

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