Search in sources :

Example 11 with ConstraintDescriptor

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

the class SchemaCacheTest method shouldListConstraintsForRelationshipType.

@Test
public void shouldListConstraintsForRelationshipType() {
    // Given
    ConstraintRule rule1 = relPropertyExistenceConstraintRule(0, 1, 1);
    ConstraintRule rule2 = relPropertyExistenceConstraintRule(0, 2, 1);
    ConstraintRule rule3 = relPropertyExistenceConstraintRule(0, 1, 2);
    SchemaCache cache = newSchemaCache(rule1, rule2, rule3);
    // When
    Set<ConstraintDescriptor> listed = asSet(cache.constraintsForRelationshipType(1));
    // Then
    Set<ConstraintDescriptor> expected = asSet(rule1.getConstraintDescriptor(), rule3.getConstraintDescriptor());
    assertEquals(expected, listed);
}
Also used : ConstraintRule(org.neo4j.kernel.impl.store.record.ConstraintRule) ConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor) Test(org.junit.Test)

Example 12 with ConstraintDescriptor

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

the class SchemaCacheTest method should_remove_constraints.

@Test
public void should_remove_constraints() {
    // GIVEN
    SchemaCache cache = newSchemaCache();
    cache.addSchemaRule(uniquenessConstraintRule(0L, 1, 2, 133L));
    cache.addSchemaRule(uniquenessConstraintRule(1L, 3, 4, 133L));
    // WHEN
    cache.removeSchemaRule(0L);
    // THEN
    ConstraintDescriptor dropped = ConstraintDescriptorFactory.uniqueForLabel(1, 1);
    ConstraintDescriptor unique = ConstraintDescriptorFactory.uniqueForLabel(3, 4);
    assertEquals(asSet(unique), asSet(cache.constraints()));
    assertEquals(asSet(), asSet(cache.constraintsForLabel(1)));
    assertEquals(asSet(), asSet(cache.constraintsForSchema(dropped.schema())));
}
Also used : ConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor) Test(org.junit.Test)

Example 13 with ConstraintDescriptor

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

the class SchemaCacheTest method should_list_constraints.

@Test
public void should_list_constraints() {
    // GIVEN
    SchemaCache cache = newSchemaCache();
    // WHEN
    cache.addSchemaRule(uniquenessConstraintRule(0L, 1, 2, 133L));
    cache.addSchemaRule(uniquenessConstraintRule(1L, 3, 4, 133L));
    cache.addSchemaRule(relPropertyExistenceConstraintRule(2L, 5, 6));
    cache.addSchemaRule(nodePropertyExistenceConstraintRule(3L, 7, 8));
    // THEN
    ConstraintDescriptor unique1 = ConstraintDescriptorFactory.uniqueForLabel(1, 2);
    ConstraintDescriptor unique2 = ConstraintDescriptorFactory.uniqueForLabel(3, 4);
    ConstraintDescriptor existsRel = ConstraintDescriptorFactory.existsForRelType(5, 6);
    ConstraintDescriptor existsNode = ConstraintDescriptorFactory.existsForLabel(7, 8);
    assertEquals(asSet(unique1, unique2, existsRel, existsNode), asSet(cache.constraints()));
    assertEquals(asSet(unique1), asSet(cache.constraintsForLabel(1)));
    assertEquals(asSet(unique1), asSet(cache.constraintsForSchema(unique1.schema())));
    assertEquals(asSet(), asSet(cache.constraintsForSchema(SchemaDescriptorFactory.forLabel(1, 3))));
    assertEquals(asSet(existsRel), asSet(cache.constraintsForRelationshipType(5)));
}
Also used : ConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor) Test(org.junit.Test)

Example 14 with ConstraintDescriptor

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

the class SchemaCacheTest method shouldListConstraintsForSchema.

@Test
public void shouldListConstraintsForSchema() {
    // Given
    ConstraintRule rule1 = uniquenessConstraintRule(0, 1, 1, 0);
    ConstraintRule rule2 = uniquenessConstraintRule(1, 2, 1, 0);
    ConstraintRule rule3 = nodePropertyExistenceConstraintRule(2, 1, 2);
    SchemaCache cache = newSchemaCache(rule1, rule2, rule3);
    // When
    Set<ConstraintDescriptor> listed = asSet(cache.constraintsForSchema(rule3.schema()));
    // Then
    assertEquals(singleton(rule3.getConstraintDescriptor()), listed);
}
Also used : ConstraintRule(org.neo4j.kernel.impl.store.record.ConstraintRule) ConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor) Test(org.junit.Test)

Example 15 with ConstraintDescriptor

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

the class SchemaCacheTest method shouldListConstraintsForLabel.

@Test
public void shouldListConstraintsForLabel() {
    // Given
    ConstraintRule rule1 = uniquenessConstraintRule(0, 1, 1, 0);
    ConstraintRule rule2 = uniquenessConstraintRule(1, 2, 1, 0);
    ConstraintRule rule3 = nodePropertyExistenceConstraintRule(2, 1, 2);
    SchemaCache cache = newSchemaCache(rule1, rule2, rule3);
    // When
    Set<ConstraintDescriptor> listed = asSet(cache.constraintsForLabel(1));
    // Then
    Set<ConstraintDescriptor> expected = asSet(rule1.getConstraintDescriptor(), rule3.getConstraintDescriptor());
    assertEquals(expected, listed);
}
Also used : ConstraintRule(org.neo4j.kernel.impl.store.record.ConstraintRule) ConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor) Test(org.junit.Test)

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