private IPiece createPiece(Context ctx,Scope parent,ForeignKey foreignKey) throws ScopeException, SQLScopeException {
  List<ExpressionAST> joins=new LinkedList<ExpressionAST>();
  for (  KeyPair pair : foreignKey.getKeys()) {
    joins.add(ExpressionMaker.EQUAL(new ColumnReference(pair.getPrimary()),new ColumnReference(pair.getExported())));
  }
  if (joins.size() == 1) {
    return createPiece(ctx,parent,joins.get(0));
  }
 else   if (joins.size() > 1) {
    return createPiece(ctx,parent,ExpressionMaker.AND(joins));
  }
 else {
    throw new ScopeException("undefined foreignKey '" + foreignKey.getName() + "' from table "+ foreignKey.getForeignTable()+ " to table "+ foreignKey.getPrimaryTable());
  }
}

private IPiece createPiece ( Context ctx , Scope parent , ForeignKey foreignKey ) throws ScopeException , SQLScopeException { List < ExpressionAST > joins = new LinkedList < ExpressionAST > ( ) ; for ( KeyPair pair : foreignKey . getKeys ( ) ) { joins . add ( ExpressionMaker . EQUAL ( new ColumnReference ( pair . getPrimary ( ) ) , new ColumnReference ( pair . getExported ( ) ) ) ) ; } if ( joins . size ( ) == 1 ) { return createPiece ( ctx , parent , joins . get ( 0 ) ) ; } else if ( joins . size ( ) > 1 ) { return createPiece ( ctx , parent , ExpressionMaker . AND ( joins ) ) ; } else { throw new ScopeException ( "undefined foreignKey '" + foreignKey . getName ( ) + "' from table " + foreignKey . getForeignTable ( ) + " to table " + foreignKey . getPrimaryTable ( ) ) ; } }
create a reference to a foreignkey
