Search in sources :

Example 1 with ConstraintDescriptor

use of org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor in project neo4j by neo4j.

the class ConstraintRuleTest method shouldCreateExistenceConstraint.

@Test
public void shouldCreateExistenceConstraint() throws Exception {
    // GIVEN
    ConstraintDescriptor descriptor = existsForLabel(LABEL_ID, PROPERTY_ID_1);
    ConstraintRule constraintRule = ConstraintRule.constraintRule(RULE_ID, descriptor);
    // THEN
    assertThat(constraintRule.getId(), equalTo(RULE_ID));
    assertThat(constraintRule.schema(), equalTo(descriptor.schema()));
    assertThat(constraintRule.getConstraintDescriptor(), equalTo(descriptor));
    assertException(constraintRule::getOwnedIndex, IllegalStateException.class, "");
}
Also used : UniquenessConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.UniquenessConstraintDescriptor) ConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor) Test(org.junit.Test)

Example 2 with ConstraintDescriptor

use of org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor in project neo4j by neo4j.

the class ConstraintRuleTest method shouldCreateUniquenessConstraint.

@Test
public void shouldCreateUniquenessConstraint() throws Exception {
    // GIVEN
    ConstraintDescriptor descriptor = uniqueForLabel(LABEL_ID, PROPERTY_ID_1);
    ConstraintRule constraintRule = ConstraintRule.constraintRule(RULE_ID, descriptor);
    // THEN
    assertThat(constraintRule.getId(), equalTo(RULE_ID));
    assertThat(constraintRule.schema(), equalTo(descriptor.schema()));
    assertThat(constraintRule.getConstraintDescriptor(), equalTo(descriptor));
    assertException(constraintRule::getOwnedIndex, IllegalStateException.class, "");
}
Also used : UniquenessConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.UniquenessConstraintDescriptor) ConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor) Test(org.junit.Test)

Example 3 with ConstraintDescriptor

use of org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor in project neo4j by neo4j.

the class StateHandlingStatementOperationsTest method shouldGetConstraintsByLabelAndProperty.

@Test
public void shouldGetConstraintsByLabelAndProperty() throws Exception {
    // given
    ConstraintDescriptor constraint = ConstraintDescriptorFactory.uniqueForSchema(descriptor);
    TransactionState txState = new TxState();
    KernelStatement state = mockedState(txState);
    when(inner.constraintsGetForSchema(constraint.schema())).thenAnswer(invocation -> Iterators.emptyIterator());
    StateHandlingStatementOperations context = newTxStateOps(inner);
    context.uniquePropertyConstraintCreate(state, descriptor);
    // when
    Set<ConstraintDescriptor> result = Iterables.asSet(asIterable(context.constraintsGetForSchema(state, constraint.schema())));
    // then
    assertEquals(asSet(constraint), result);
}
Also used : TransactionState(org.neo4j.kernel.api.txstate.TransactionState) KernelStatement(org.neo4j.kernel.impl.api.KernelStatement) UniquenessConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.UniquenessConstraintDescriptor) ConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor) StateHandlingStatementOperations(org.neo4j.kernel.impl.api.StateHandlingStatementOperations) Test(org.junit.Test)

Example 4 with ConstraintDescriptor

use of org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor in project neo4j by neo4j.

the class StateHandlingStatementOperationsTest method shouldGetConstraintsByLabel.

@Test
public void shouldGetConstraintsByLabel() throws Exception {
    // given
    UniquenessConstraintDescriptor constraint1 = ConstraintDescriptorFactory.uniqueForLabel(2, 3);
    UniquenessConstraintDescriptor constraint2 = ConstraintDescriptorFactory.uniqueForLabel(4, 5);
    TransactionState txState = new TxState();
    KernelStatement state = mockedState(txState);
    when(inner.constraintsGetForSchema(constraint1.schema())).thenAnswer(invocation -> Iterators.emptyIterator());
    when(inner.constraintsGetForSchema(constraint2.schema())).thenAnswer(invocation -> Iterators.emptyIterator());
    when(inner.constraintsGetForLabel(1)).thenAnswer(invocation -> Iterators.emptyIterator());
    when(inner.constraintsGetForLabel(2)).thenAnswer(invocation -> iterator(constraint1));
    StateHandlingStatementOperations context = newTxStateOps(inner);
    context.uniquePropertyConstraintCreate(state, constraint1.ownedIndexDescriptor().schema());
    context.uniquePropertyConstraintCreate(state, constraint2.ownedIndexDescriptor().schema());
    // when
    Set<ConstraintDescriptor> result = Iterables.asSet(asIterable(context.constraintsGetForLabel(state, 2)));
    // then
    assertEquals(asSet(constraint1), result);
}
Also used : TransactionState(org.neo4j.kernel.api.txstate.TransactionState) KernelStatement(org.neo4j.kernel.impl.api.KernelStatement) UniquenessConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.UniquenessConstraintDescriptor) ConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor) StateHandlingStatementOperations(org.neo4j.kernel.impl.api.StateHandlingStatementOperations) UniquenessConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.UniquenessConstraintDescriptor) Test(org.junit.Test)

Example 5 with ConstraintDescriptor

use of org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor in project neo4j by neo4j.

the class DataIntegrityValidatingStatementOperations method uniquePropertyConstraintCreate.

@Override
public UniquenessConstraintDescriptor uniquePropertyConstraintCreate(KernelStatement state, LabelSchemaDescriptor descriptor) throws AlreadyConstrainedException, CreateConstraintFailureException, AlreadyIndexedException, RepeatedPropertyInCompositeSchemaException {
    assertValidDescriptor(descriptor, OperationContext.CONSTRAINT_CREATION);
    ConstraintDescriptor constraint = ConstraintDescriptorFactory.uniqueForSchema(descriptor);
    assertConstraintDoesNotExist(state, constraint);
    // It is not allowed to create uniqueness constraints on indexed label/property pairs
    assertIndexDoesNotExist(state, OperationContext.CONSTRAINT_CREATION, SchemaBoundary.map(descriptor));
    return schemaWriteDelegate.uniquePropertyConstraintCreate(state, descriptor);
}
Also used : UniquenessConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.UniquenessConstraintDescriptor) NodeExistenceConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.NodeExistenceConstraintDescriptor) ConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor) RelExistenceConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.RelExistenceConstraintDescriptor)

Aggregations

ConstraintDescriptor (org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor)25 UniquenessConstraintDescriptor (org.neo4j.kernel.api.schema_new.constaints.UniquenessConstraintDescriptor)15 Test (org.junit.Test)11 NodeExistenceConstraintDescriptor (org.neo4j.kernel.api.schema_new.constaints.NodeExistenceConstraintDescriptor)6 RelExistenceConstraintDescriptor (org.neo4j.kernel.api.schema_new.constaints.RelExistenceConstraintDescriptor)6 TransactionState (org.neo4j.kernel.api.txstate.TransactionState)3 KernelStatement (org.neo4j.kernel.impl.api.KernelStatement)3 StateHandlingStatementOperations (org.neo4j.kernel.impl.api.StateHandlingStatementOperations)3 ConstraintRule (org.neo4j.kernel.impl.store.record.ConstraintRule)3 ArrayList (java.util.ArrayList)2 ReadOperations (org.neo4j.kernel.api.ReadOperations)2 Statement (org.neo4j.kernel.api.Statement)2 PropertyConstraint (org.neo4j.kernel.api.constraints.PropertyConstraint)2 NodeItem (org.neo4j.storageengine.api.NodeItem)2 ByteBuffer (java.nio.ByteBuffer)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 Set (java.util.Set)1 ConstraintViolationException (org.neo4j.graphdb.ConstraintViolationException)1