001    
002    package railo.runtime.sql.old;
003    
004    import java.util.Vector;
005    
006    
007    public final class ZQuery
008        implements ZStatement, ZExp
009    {
010    
011        public ZQuery()
012        {
013            distinct_ = false;
014            where_ = null;
015            groupby_ = null;
016            setclause_ = null;
017            orderby_ = null;
018            forupdate_ = false;
019        }
020    
021        public void addSelect(Vector vector)
022        {
023            select_ = vector;
024        }
025    
026        public void addFrom(Vector vector)
027        {
028            from_ = vector;
029        }
030    
031        public void addWhere(ZExp zexp)
032        {
033            where_ = zexp;
034        }
035    
036        public void addGroupBy(ZGroupBy zgroupby)
037        {
038            groupby_ = zgroupby;
039        }
040    
041        public void addSet(ZExpression zexpression)
042        {
043            setclause_ = zexpression;
044        }
045    
046        public void addOrderBy(Vector vector)
047        {
048            orderby_ = vector;
049        }
050    
051        public Vector getSelect()
052        {
053            return select_;
054        }
055    
056        public Vector getFrom()
057        {
058            return from_;
059        }
060    
061        public ZExp getWhere()
062        {
063            return where_;
064        }
065    
066        public ZGroupBy getGroupBy()
067        {
068            return groupby_;
069        }
070    
071        public ZExpression getSet()
072        {
073            return setclause_;
074        }
075    
076        public Vector getOrderBy()
077        {
078            return orderby_;
079        }
080    
081        public boolean isDistinct()
082        {
083            return distinct_;
084        }
085    
086        public boolean isForUpdate()
087        {
088            return forupdate_;
089        }
090    
091        public String toString() {
092            StringBuffer stringbuffer = new StringBuffer("select ");
093            if(distinct_) stringbuffer.append("distinct ");
094            stringbuffer.append(select_.elementAt(0).toString());
095            for(int i = 1; i < select_.size(); i++)
096                stringbuffer.append(", " + select_.elementAt(i).toString());
097            
098            stringbuffer.append(" from ");
099            stringbuffer.append(from_.elementAt(0).toString());
100            for(int j = 1; j < from_.size(); j++)
101                stringbuffer.append(", " + from_.elementAt(j).toString());
102            
103            if(where_ != null)
104                stringbuffer.append(" where " + where_.toString());
105            
106            if(groupby_ != null)
107                stringbuffer.append(" " + groupby_.toString());
108            
109            if(setclause_ != null)
110                stringbuffer.append(" " + setclause_.toString());
111            
112            if(orderby_ != null)
113            {
114                stringbuffer.append(" order by ");
115                stringbuffer.append(orderby_.elementAt(0).toString());
116                for(int k = 1; k < orderby_.size(); k++)
117                    stringbuffer.append(", " + orderby_.elementAt(k).toString());
118    
119            }
120            if(forupdate_)
121                stringbuffer.append(" for update");
122            return stringbuffer.toString();
123        }
124    
125        Vector select_;
126        boolean distinct_;
127        Vector from_;
128        ZExp where_;
129        ZGroupBy groupby_;
130        ZExpression setclause_;
131        Vector orderby_;
132        boolean forupdate_;
133    }