001/**
002 *
003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved.
004 *
005 * This library is free software; you can redistribute it and/or
006 * modify it under the terms of the GNU Lesser General Public
007 * License as published by the Free Software Foundation; either 
008 * version 2.1 of the License, or (at your option) any later version.
009 * 
010 * This library is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013 * Lesser General Public License for more details.
014 * 
015 * You should have received a copy of the GNU Lesser General Public 
016 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
017 * 
018 **/
019package lucee.runtime.sql;
020
021import java.util.ArrayList;
022import java.util.List;
023
024import lucee.runtime.sql.exp.Column;
025import lucee.runtime.sql.exp.Expression;
026import lucee.runtime.sql.exp.op.Operation;
027import lucee.runtime.sql.exp.value.ValueNumber;
028
029public class Select {
030        private List selects=new ArrayList();
031        private List froms=new ArrayList();
032        private Operation where;
033        private List groupbys=new ArrayList();
034        private Operation having;
035        private ValueNumber top;
036        private boolean distinct;
037        private boolean unionDistinct;
038        
039        public void addSelectExpression(Expression select) {
040                selects.add(select);
041                select.setIndex(selects.size());
042        }
043
044        public void addFromExpression(Column exp) {
045                froms.add(exp);
046                exp.setIndex(froms.size());
047        }
048
049        public void setWhereExpression(Operation where) {
050                this.where=where;
051        }
052        
053        public void addGroupByExpression(Column col) {
054                this.groupbys.add(col);
055        }
056
057        public void setTop(ValueNumber top) {
058                this.top=top;
059        }
060
061
062        /**
063         * @return the froms
064         */
065        public Column[] getFroms() {
066                return (Column[]) froms.toArray(new Column[froms.size()]);
067        }
068        
069        /**
070         * @return the groupbys
071         */
072        public Column[] getGroupbys() {
073                if(groupbys==null) return new Column[0];
074                return (Column[]) groupbys.toArray(new Column[groupbys.size()]);
075        }
076
077        /**
078         * @return the havings
079         */
080        public Operation getHaving() {
081                return having;
082        }
083
084        /**
085         * @return the selects
086         */
087        public Expression[] getSelects() {
088                return (Expression[]) selects.toArray(new Expression[selects.size()]);
089        }
090
091        /**
092         * @return the where
093         */
094        public Operation getWhere() {
095                return where;
096        }
097
098        public boolean isUnionDistinct() {
099                return unionDistinct; 
100        }
101        
102        public boolean isDistinct() {
103                return distinct;
104        }
105
106        public void setDistinct(boolean b) {
107                this.distinct=b;
108        }
109
110        public void setUnionDistinct(boolean b) {
111                //print.out("-"+b);
112                this.unionDistinct=b;
113        }
114
115        /**
116         * @param having the having to set
117         */
118        public void setHaving(Operation having) {
119                this.having = having;
120        }
121
122        /**
123         * @return the top
124         */
125        public ValueNumber getTop() {
126                return top;
127        }
128
129
130}