@Override public Iterable<ConstraintDefinition> getConstraints() { return gdb.schema().getConstraints(); } }
public ListRepresentation getConstraints() { return new ListRepresentation( CONSTRAINT_DEFINITION, map( CONSTRAINT_DEF_TO_REPRESENTATION, graphDb.schema().getConstraints() ) ); }
@Override protected Iterable<ConstraintDefinition> manifest() { return db.schema().getConstraints( ); } };
private Iterable<ConstraintDefinition> filteredNodeConstraints( String labelName, Predicate<ConstraintDefinition> filter ) { Iterable<ConstraintDefinition> constraints = graphDb.schema().getConstraints( label( labelName ) ); return filter( filter, constraints ); }
@Override protected Iterable<ConstraintDefinition> manifest() { return db.schema().getConstraints( label ); } };
@Override protected Iterable<ConstraintDefinition> manifest() { return db.schema().getConstraints( type ); } };
private Iterable<ConstraintDefinition> filteredRelationshipConstraints( String typeName, Predicate<ConstraintDefinition> filter ) { RelationshipType type = RelationshipType.withName( typeName ); Iterable<ConstraintDefinition> constraints = graphDb.schema().getConstraints( type ); return filter( filter, constraints ); }
private Iterable<ConstraintDefinition> filteredRelationshipConstraints( String typeName, final ConstraintType type ) { return filter( item -> item.isConstraintType( type ), graphDb.schema().getConstraints( RelationshipType.withName( typeName ) ) ); }
private Iterable<ConstraintDefinition> filteredNodeConstraints( String labelName, final ConstraintType type ) { return filter( item -> item.isConstraintType( type ), graphDb.schema().getConstraints( label( labelName ) ) ); }
private void deleteAllConstraints() { for ( ConstraintDefinition constraint : db.schema().getConstraints() ) { constraint.drop(); } } }
private List<ConstraintDefinition> constraints( GraphDatabaseService database ) { try ( Transaction ignored = database.beginTx() ) { return Iterables.asList( database.schema().getConstraints() ); } }
private void dropConstraints() { try ( Transaction tx = db.beginTx() ) { for ( ConstraintDefinition constraint : db.schema().getConstraints( LABEL ) ) { constraint.drop(); } tx.success(); } }
@Before public void setup() { try ( org.neo4j.graphdb.Transaction tx = graphDb.beginTx() ) { for ( ConstraintDefinition definition : graphDb.schema().getConstraints() ) { definition.drop(); } tx.success(); } }
private ConstraintDefinition getConstraint( Label label, String propertyKey ) { try ( Transaction tx = graphDb.beginTx() ) { ConstraintDefinition found = null; for ( ConstraintDefinition constraint : graphDb.schema().getConstraints( label ) ) { if ( propertyKey.equals( single( constraint.getPropertyKeys() ) ) ) { assertNull( "Found multiple constraints.", found ); found = constraint; } } tx.success(); return found; } } }
@Test public void shouldRecoverCreationOfUniquenessConstraintFollowedByDeletionOfThatSameConstraint() throws Exception { // given createUniqueConstraint(); dropConstraints(); // when - perform recovery restart( snapshot( storeDir.absolutePath() ) ); // then - just make sure the constraint is gone try ( Transaction tx = db.beginTx() ) { assertFalse( db.schema().getConstraints( LABEL ).iterator().hasNext() ); tx.success(); } }
public static void cleanupSchema( GraphDatabaseService db ) { try ( Transaction tx = db.beginTx() ) { for ( ConstraintDefinition constraint : db.schema().getConstraints() ) { constraint.drop(); } for ( IndexDefinition index : db.schema().getIndexes() ) { index.drop(); } tx.success(); } }
@Test public void shouldDropUniquenessConstraintWithBackingIndexNotInUse() { // given try ( Transaction tx = db.beginTx() ) { db.schema().constraintFor( label ).assertPropertyIsUnique( key ).create(); tx.success(); } // when intentionally breaking the schema by setting the backing index rule to unused RecordStorageEngine storageEngine = db.getDependencyResolver().resolveDependency( RecordStorageEngine.class ); SchemaStore schemaStore = storageEngine.testAccessNeoStores().getSchemaStore(); SchemaRule indexRule = single( filter( rule -> rule instanceof StoreIndexDescriptor, schemaStore.loadAllSchemaRules() ) ); setSchemaRecordNotInUse( schemaStore, indexRule.getId() ); // At this point the SchemaCache doesn't know about this change so we have to reload it storageEngine.loadSchemaCache(); try ( Transaction tx = db.beginTx() ) { single( db.schema().getConstraints( label ).iterator() ).drop(); tx.success(); } // then try ( Transaction ignore = db.beginTx() ) { assertFalse( db.schema().getConstraints().iterator().hasNext() ); assertFalse( db.schema().getIndexes().iterator().hasNext() ); } }
public Iterable<ConstraintDefinition> getPropertyUniquenessConstraints( String labelName, final String propertyKey ) { try ( Transaction tx = database.getGraph().beginTransaction( implicit, AnonymousContext.read() ) ) { Iterable<ConstraintDefinition> definitions = Iterables.filter( item -> { if ( item.isConstraintType( ConstraintType.UNIQUENESS ) ) { Iterable<String> keys = item.getPropertyKeys(); return single( keys ).equals( propertyKey ); } else { return false; } }, database.getGraph().schema().getConstraints( label( labelName ) ) ); tx.success(); return definitions; } }
private static void shouldHaveUniquenessConstraintForNamePropertyOnPersonLabel( GraphDatabaseService db ) { try ( Transaction tx = db.beginTx() ) { ConstraintDefinition constraint = Iterables.single( db.schema().getConstraints() ); assertEquals( ConstraintType.UNIQUENESS, constraint.getConstraintType() ); assertEquals( "Person", constraint.getLabel().name() ); assertEquals( "name", Iterables.single( constraint.getPropertyKeys() ) ); tx.success(); } }
@Test public void convertConstraintToIndex() { try ( Transaction tx = graphDb.beginTx() ) { graphDb.schema().constraintFor( LABEL ).assertPropertyIsUnique( PROPERTY_KEY ).create(); tx.success(); } try ( Transaction tx = graphDb.beginTx() ) { ConstraintDefinition constraint = firstOrNull( graphDb.schema().getConstraints( LABEL ) ); constraint.drop(); graphDb.schema().indexFor( LABEL ).on( PROPERTY_KEY ).create(); tx.success(); } // assert no exception is thrown }