KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > amber > expr > AbstractAmberExpr


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  *
23  * Free Software Foundation, Inc.
24  * 59 Temple Place, Suite 330
25  * Boston, MA 02111-1307 USA
26  *
27  * @author Scott Ferguson
28  */

29
30 package com.caucho.amber.expr;
31
32 import com.caucho.amber.entity.EntityItem;
33 import com.caucho.amber.manager.AmberConnection;
34 import com.caucho.amber.query.FromItem;
35 import com.caucho.amber.query.QueryParseException;
36 import com.caucho.amber.query.QueryParser;
37 import com.caucho.amber.type.StringType;
38 import com.caucho.amber.type.Type;
39 import com.caucho.util.CharBuffer;
40 import com.caucho.util.L10N;
41
42 import java.sql.ResultSet JavaDoc;
43 import java.sql.SQLException JavaDoc;
44
45 /**
46  * Represents an Amber query expression
47  */

48 abstract public class AbstractAmberExpr implements AmberExpr {
49   private static final L10N L = new L10N(AbstractAmberExpr.class);
50
51   /**
52    * Returns true for a boolean expression.
53    */

54   public boolean isBoolean()
55   {
56     return false;
57   }
58
59   /**
60    * Returns the expr type.
61    */

62   public Type getType()
63   {
64     return StringType.create();
65   }
66
67   /**
68    * Converts to a boolean expression.
69    */

70   public AmberExpr createBoolean()
71     throws QueryParseException
72   {
73     if (isBoolean())
74       return this;
75     else
76       throw new QueryParseException(L.l("'{0}' can't be used as a boolean",
77                                         this));
78   }
79
80   /**
81    * Binds the expression as a select item.
82    */

83   abstract public AmberExpr bindSelect(QueryParser parser);
84
85   /**
86    * Returns true if the expression uses the from item.
87    */

88   public boolean usesFrom(FromItem from, int type)
89   {
90     return usesFrom(from, type, false);
91   }
92
93   /**
94    * Returns true if the expression uses the from item.
95    */

96   public boolean usesFrom(FromItem from, int type, boolean isNot)
97   {
98     return false;
99   }
100
101   /**
102    * Returns true if the expression must exist
103    */

104   public boolean exists(FromItem from)
105   {
106     return false;
107   }
108
109   /**
110    * Returns true if the expression must exist
111    */

112   public boolean exists()
113   {
114     return false;
115   }
116
117   /**
118    * Returns true if the expression uses the from item.
119    */

120   public AmberExpr replaceJoin(JoinExpr join)
121   {
122     return this;
123   }
124
125   /**
126    * Returns the number of columns.
127    */

128   public int getColumnCount()
129   {
130     return 1;
131   }
132
133   /**
134    * Generates the where expression.
135    */

136   public void generateWhere(CharBuffer cb)
137   {
138     throw new UnsupportedOperationException JavaDoc(getClass().getName());
139   }
140
141   /**
142    * Generates the (update) where expression.
143    */

144   public void generateUpdateWhere(CharBuffer cb)
145   {
146     generateWhere(cb);
147   }
148
149   /**
150    * Generates the having expression.
151    */

152   public void generateHaving(CharBuffer cb)
153   {
154     generateWhere(cb);
155   }
156
157   /**
158    * Generates the where in a join expression.
159    */

160   public void generateJoin(CharBuffer cb)
161   {
162     generateWhere(cb);
163   }
164
165   /**
166    * Generates the select expression.
167    */

168   public void generateSelect(CharBuffer cb)
169   {
170     generateWhere(cb);
171   }
172
173   /**
174    * Returns the object for the expr.
175    */

176   public Object JavaDoc getObject(AmberConnection aConn, ResultSet JavaDoc rs, int index)
177     throws SQLException JavaDoc
178   {
179     return getType().getObject(aConn, rs, index);
180   }
181
182   /**
183    * Returns the object for the expr.
184    */

185   public Object JavaDoc getCacheObject(AmberConnection aConn,
186                                ResultSet JavaDoc rs, int index)
187     throws SQLException JavaDoc
188   {
189     return getObject(aConn, rs, index);
190   }
191
192   /**
193    * Returns the object for the expr.
194    */

195   public EntityItem findItem(AmberConnection aConn, ResultSet JavaDoc rs, int index)
196     throws SQLException JavaDoc
197   {
198     return getType().findItem(aConn, rs, index);
199   }
200 }
201
Popular Tags