// Path: redquerybuilder-core/src/main/java/com/redspr/redquerybuilder/core/client/engine/Session.java
// public class Session {
// 
//     private static IdentifierEscaper identifierEscaper = new IdentifierEscaper() {
//         @Override
//         public String quote(String id) {
//             return "\"" + id + "\"";
//         }
//     };
// 
//   public void setIdentifierEscaper(IdentifierEscaper p) {
//       identifierEscaper = p;
//   }
// 
//   /**
//    * Add double quotes around an identifier if required.
//    *
//    * @param s the identifier
//    * @return the quoted identifier
//    */
//   public static String quoteIdentifier(String s) {
//       return identifierEscaper.quote(s);
//   }
// 
//     // XXX need commandBuilder and select?
//     private CommandBuilder commandBuilder;
// 
//     private Select select;
// 
//     private Configuration config;
// 
//     private final ValueRegistry valueRegistry = new ValueRegistry();
// 
//     private final Database database;
// 
//     private final HandlerManager msgbus;
// 
// 
//   // XXX 00 remove one of these constructors
//   public Session(Configuration config2) {
//       this(config2.getDatabase());
//       this.config = config2;
//   }
// 
//   @Deprecated
//   public Session(Database database2) {
//       database = database2;
//       msgbus = new HandlerManager(this);
//   }
// 
//     public Configuration getConfig() {
//         return config;
//     }
// 
//     public CommandBuilder getCommandBuilder() {
//         return commandBuilder;
//     }
// 
//     public void setCommandBuilder(CommandBuilder p) {
//         commandBuilder = p;
//     }
// 
//     public Database getDatabase() {
//         return database;
//     }
// 
// 
//   public HandlerManager getMsgBus() {
//       return msgbus;
//   }
// 
// 
// 
//   public void setSelect(Select p) {
//       select = p;
//   }
// 
//   public Column resolveColumn(String alias, String columnName) {
//       return select.resolveColumn(alias, columnName);
//   }
// 
//   public ObjectArray<TableFilter> getFilters() {
//       return select.getFilters();
//   }
// 
//   public TableFilter getTableFilter(Table t) {
//       for (TableFilter tf : select.getFilters()) {
//           if (tf.getTable().equals(t)) {
//               return tf;
//           }
//       }
//       return null;
//   }
// 
//   public TableFilter createTableFilter(Table t) {
//       TableFilter tf = new TableFilter(this, t, TableFilter.newAlias(), select);
//       select.addTableFilter(tf, true); // XXX really is true?
//       return tf;
//   }
// 
//   public TableFilter getOrCreateTableFilter(Table t) {
//       TableFilter tf = getTableFilter(t);
//       if (tf == null) {
//           tf = createTableFilter(t);
//       }
//       return tf;
//   }
// 
//   //public Table getTable(String alias) {
//   //    return select.getTable(alias);
//   //}
// 
//   public Table getRootTable() {
//       // XXX maybe if no table then grab default?
//       // or should select always have one table?
//       // or ui shouldn't offer condition button till table?
//       return select.getFilters().get(0).getTable();
//   }
// 
//     public ValueRegistry getValueRegistry() {
//         return valueRegistry;
//     }
// }
// 
// Path: redquerybuilder-core/src/main/java/com/redspr/redquerybuilder/core/client/expression/Expression.java
// public class Expression extends BaseSqlWidget {
// 
//     public Expression(Session session) {
//         super(session);
//         // initWidget(new Label("E" + getClass().getName()));
//     }
// 
//     public String getSQL(List<Object> args) {
//         return "blah";
//     }
// 
// }


import com.redspr.redquerybuilder.core.client.engine.Session;
import com.redspr.redquerybuilder.core.client.expression.Expression;
import com.redspr.redquerybuilder.core.client.util.ObjectArray;
/*
 * Copyright 2004-2013 H2 Group. Multiple-Licensed under the H2 License,
 * Version 1.0, and under the Eclipse Public License, Version 1.0
 * (http://h2database.com/html/license.html).
 * Initial Developer: H2 Group
 *
 * Nicolas Fortin, Atelier SIG, IRSTV FR CNRS 24888
 * Support for the operator "&&" as an alias for SPATIAL_INTERSECTS
 */
package com.redspr.redquerybuilder.core.client.command.dml;



/**
 * Represents a union SELECT statement.
 */
public class SelectUnion extends Query {

    /**
     * The type of a UNION statement.
     */
    public static final int UNION = 0;

    /**
     * The type of a UNION ALL statement.
     */
    public static final int UNION_ALL = 1;

    /**
     * The type of an EXCEPT statement.
     */
    public static final int EXCEPT = 2;

    /**
     * The type of an INTERSECT statement.
     */
    public static final int INTERSECT = 3;

    private int unionType;
    private final Query left;

    private Query right;
    private ObjectArray<Expression> expressions;
   // private ObjectArray<SelectOrderBy> orderList;
  // SortOrder sort;
    private boolean distinct;
    private boolean isPrepared, checkInit;
    private boolean isForUpdate;

    public SelectUnion(Session session, Query query) {
        super(session);
        this.left = query;
    }

    public void setUnionType(int type) {
        this.unionType = type;
    }

    public void setRight(Query select) {
        right = select;
    }


//    public void setOrder(ObjectArray<SelectOrderBy> order) {
//        orderList = order;
//    }

//    private Value[] convert(Value[] values, int columnCount) throws SQLException {
//        for (int i = 0; i < columnCount; i++) {
//            Expression e = expressions.get(i);
//           // values[i] = values[i].convertTo(e.getType());
//        }
//        return values;
//    }




//    public HashSet<Table> getTables() {
//        HashSet<Table> set = left.getTables();
//        set.addAll(right.getTables());
//        return set;
//    }

    public void setDistinct(boolean b) {
        distinct = b;
    }

// Path: redquerybuilder-core/src/main/java/com/redspr/redquerybuilder/core/client/engine/Session.java
// public class Session {
// 
//     private static IdentifierEscaper identifierEscaper = new IdentifierEscaper() {
//         @Override
//         public String quote(String id) {
//             return "\"" + id + "\"";
//         }
//     };
// 
//   public void setIdentifierEscaper(IdentifierEscaper p) {
//       identifierEscaper = p;
//   }
// 
//   /**
//    * Add double quotes around an identifier if required.
//    *
//    * @param s the identifier
//    * @return the quoted identifier
//    */
//   public static String quoteIdentifier(String s) {
//       return identifierEscaper.quote(s);
//   }
// 
//     // XXX need commandBuilder and select?
//     private CommandBuilder commandBuilder;
// 
//     private Select select;
// 
//     private Configuration config;
// 
//     private final ValueRegistry valueRegistry = new ValueRegistry();
// 
//     private final Database database;
// 
//     private final HandlerManager msgbus;
// 
// 
//   // XXX 00 remove one of these constructors
//   public Session(Configuration config2) {
//       this(config2.getDatabase());
//       this.config = config2;
//   }
// 
//   @Deprecated
//   public Session(Database database2) {
//       database = database2;
//       msgbus = new HandlerManager(this);
//   }
// 
//     public Configuration getConfig() {
//         return config;
//     }
// 
//     public CommandBuilder getCommandBuilder() {
//         return commandBuilder;
//     }
// 
//     public void setCommandBuilder(CommandBuilder p) {
//         commandBuilder = p;
//     }
// 
//     public Database getDatabase() {
//         return database;
//     }
// 
// 
//   public HandlerManager getMsgBus() {
//       return msgbus;
//   }
// 
// 
// 
//   public void setSelect(Select p) {
//       select = p;
//   }
// 
//   public Column resolveColumn(String alias, String columnName) {
//       return select.resolveColumn(alias, columnName);
//   }
// 
//   public ObjectArray<TableFilter> getFilters() {
//       return select.getFilters();
//   }
// 
//   public TableFilter getTableFilter(Table t) {
//       for (TableFilter tf : select.getFilters()) {
//           if (tf.getTable().equals(t)) {
//               return tf;
//           }
//       }
//       return null;
//   }
// 
//   public TableFilter createTableFilter(Table t) {
//       TableFilter tf = new TableFilter(this, t, TableFilter.newAlias(), select);
//       select.addTableFilter(tf, true); // XXX really is true?
//       return tf;
//   }
// 
//   public TableFilter getOrCreateTableFilter(Table t) {
//       TableFilter tf = getTableFilter(t);
//       if (tf == null) {
//           tf = createTableFilter(t);
//       }
//       return tf;
//   }
// 
//   //public Table getTable(String alias) {
//   //    return select.getTable(alias);
//   //}
// 
//   public Table getRootTable() {
//       // XXX maybe if no table then grab default?
//       // or should select always have one table?
//       // or ui shouldn't offer condition button till table?
//       return select.getFilters().get(0).getTable();
//   }
// 
//     public ValueRegistry getValueRegistry() {
//         return valueRegistry;
//     }
// }
// 
// Path: redquerybuilder-core/src/main/java/com/redspr/redquerybuilder/core/client/expression/Expression.java
// public class Expression extends BaseSqlWidget {
// 
//     public Expression(Session session) {
//         super(session);
//         // initWidget(new Label("E" + getClass().getName()));
//     }
// 
//     public String getSQL(List<Object> args) {
//         return "blah";
//     }
// 
// }


// Path: redquerybuilder-core/src/main/java/com/redspr/redquerybuilder/core/client/command/dml/SelectUnion.java
import com.redspr.redquerybuilder.core.client.engine.Session;
import com.redspr.redquerybuilder.core.client.expression.Expression;
import com.redspr.redquerybuilder.core.client.util.ObjectArray;

/*
 * Copyright 2004-2013 H2 Group. Multiple-Licensed under the H2 License,
 * Version 1.0, and under the Eclipse Public License, Version 1.0
 * (http://h2database.com/html/license.html).
 * Initial Developer: H2 Group
 *
 * Nicolas Fortin, Atelier SIG, IRSTV FR CNRS 24888
 * Support for the operator "&&" as an alias for SPATIAL_INTERSECTS
 */
package com.redspr.redquerybuilder.core.client.command.dml;



/**
 * Represents a union SELECT statement.
 */
public class SelectUnion extends Query {

    /**
     * The type of a UNION statement.
     */
    public static final int UNION = 0;

    /**
     * The type of a UNION ALL statement.
     */
    public static final int UNION_ALL = 1;

    /**
     * The type of an EXCEPT statement.
     */
    public static final int EXCEPT = 2;

    /**
     * The type of an INTERSECT statement.
     */
    public static final int INTERSECT = 3;

    private int unionType;
    private final Query left;

    private Query right;
    private ObjectArray<Expression> expressions;
   // private ObjectArray<SelectOrderBy> orderList;
  // SortOrder sort;
    private boolean distinct;
    private boolean isPrepared, checkInit;
    private boolean isForUpdate;

    public SelectUnion(Session session, Query query) {
        super(session);
        this.left = query;
    }

    public void setUnionType(int type) {
        this.unionType = type;
    }

    public void setRight(Query select) {
        right = select;
    }


//    public void setOrder(ObjectArray<SelectOrderBy> order) {
//        orderList = order;
//    }

//    private Value[] convert(Value[] values, int columnCount) throws SQLException {
//        for (int i = 0; i < columnCount; i++) {
//            Expression e = expressions.get(i);
//           // values[i] = values[i].convertTo(e.getType());
//        }
//        return values;
//    }




//    public HashSet<Table> getTables() {
//        HashSet<Table> set = left.getTables();
//        set.addAll(right.getTables());
//        return set;
//    }

    public void setDistinct(boolean b) {
        distinct = b;
    }

    public ObjectArray<Expression> getExpressions() {