Java 类org.neo4j.graphdb.schema.ConstraintDefinition 实例源码

项目:neo4j-lucene5-index    文件:IndexConstraintsTest.java   
@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
}
项目:neo4j-lucene5-index    文件:IndexConstraintsTest.java   
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;
    }
}
项目:neoprofiler    文件:SchemaProfiler.java   
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;
}
项目:pheno4j    文件:DatabaseIndexCreator.java   
private boolean doesConstraintExist(Iterable<ConstraintDefinition> constraints, String name) {
    for (ConstraintDefinition cd : constraints) {
        if (cd.getLabel().equals(Label.label(name))) {
            return true;
        }
    }
    return false;
}
项目:neo4j-lucene5-index    文件:IndexConstraintsTest.java   
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;
}
项目:neo4j-lucene5-index    文件:UniqueIndexRecoveryTests.java   
private void dropConstraints()
{
    try ( Transaction tx = db.beginTx() )
    {
        for ( ConstraintDefinition constraint : db.schema().getConstraints( LABEL ) )
        {
            constraint.drop();
        }
        tx.success();
    }
}