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