001    package railo.runtime.sql;
002    
003    import java.util.ArrayList;
004    import java.util.List;
005    
006    import railo.runtime.sql.exp.Column;
007    import railo.runtime.sql.exp.Expression;
008    import railo.runtime.sql.exp.op.Operation;
009    import railo.runtime.sql.exp.value.ValueNumber;
010    
011    public class Select {
012            private List selects=new ArrayList();
013            private List froms=new ArrayList();
014            private Operation where;
015            private List groupbys=new ArrayList();
016            private Operation having;
017            private ValueNumber top;
018            private boolean distinct;
019            private boolean unionDistinct;
020            
021            public void addSelectExpression(Expression select) {
022                    selects.add(select);
023                    select.setIndex(selects.size());
024            }
025    
026            public void addFromExpression(Column exp) {
027                    froms.add(exp);
028                    exp.setIndex(froms.size());
029            }
030    
031            public void setWhereExpression(Operation where) {
032                    this.where=where;
033            }
034            
035            public void addGroupByExpression(Column col) {
036                    this.groupbys.add(col);
037            }
038    
039            public void setTop(ValueNumber top) {
040                    this.top=top;
041            }
042    
043    
044            /**
045             * @return the froms
046             */
047            public Column[] getFroms() {
048                    return (Column[]) froms.toArray(new Column[froms.size()]);
049            }
050            
051            /**
052             * @return the groupbys
053             */
054            public Column[] getGroupbys() {
055                    if(groupbys==null) return new Column[0];
056                    return (Column[]) groupbys.toArray(new Column[groupbys.size()]);
057            }
058    
059            /**
060             * @return the havings
061             */
062            public Operation getHaving() {
063                    return having;
064            }
065    
066            /**
067             * @return the selects
068             */
069            public Expression[] getSelects() {
070                    return (Expression[]) selects.toArray(new Expression[selects.size()]);
071            }
072    
073            /**
074             * @return the where
075             */
076            public Operation getWhere() {
077                    return where;
078            }
079    
080            public boolean isUnionDistinct() {
081                    return unionDistinct; 
082            }
083            
084            public boolean isDistinct() {
085                    return distinct;
086            }
087    
088            public void setDistinct(boolean b) {
089                    this.distinct=b;
090            }
091    
092            public void setUnionDistinct(boolean b) {
093                    //print.out("-"+b);
094                    this.unionDistinct=b;
095            }
096    
097            /**
098             * @param having the having to set
099             */
100            public void setHaving(Operation having) {
101                    this.having = having;
102            }
103    
104            /**
105             * @return the top
106             */
107            public ValueNumber getTop() {
108                    return top;
109            }
110    
111    
112    }