@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 = first( graphDb.schema().getConstraints( LABEL ) ); constraint.drop(); graphDb.schema().indexFor( LABEL ).on( PROPERTY_KEY ).create(); tx.success(); } // assert no exception is thrown }
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; } }
public NeoProfile run(NeoProfiler parent) { SchemaProfile p = new SchemaProfile(); try(Transaction tx = parent.getDB().beginTx()) { Schema schema = parent.getDB().schema(); Iterator<ConstraintDefinition> constraints = schema.getConstraints().iterator(); while(constraints.hasNext()) { ConstraintDefinition c = constraints.next(); p.addConstraint(new NeoConstraint(true, false, c.getPropertyKeys(), c.getLabel(), c.getConstraintType())); } Iterator<IndexDefinition> idxs = schema.getIndexes().iterator(); while(idxs.hasNext()) { IndexDefinition idx = idxs.next(); p.addConstraint(new NeoConstraint(idx.isConstraintIndex(), true, idx.getPropertyKeys(), idx.getLabel(), null)); } } return p; }
private boolean doesConstraintExist(Iterable<ConstraintDefinition> constraints, String name) { for (ConstraintDefinition cd : constraints) { if (cd.getLabel().equals(Label.label(name))) { return true; } } return false; }
private ConstraintDefinition recreate( ConstraintDefinition constraint, int times ) { for ( int i = 0; i < times; i++ ) { constraint.drop(); constraint = graphDb.schema() .constraintFor( constraint.getLabel() ) .assertPropertyIsUnique( single( constraint.getPropertyKeys() ) ) .create(); } return constraint; }
private void dropConstraints() { try ( Transaction tx = db.beginTx() ) { for ( ConstraintDefinition constraint : db.schema().getConstraints( LABEL ) ) { constraint.drop(); } tx.success(); } }