KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright (c) 1998-2004 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.query;
31
32 import java.sql.ResultSet;
33 import java.sql.SQLException;
34
35 import com.caucho.util.CharBuffer;
36 import com.caucho.util.L10N;
37
38 import com.caucho.amber.type.Type;
39 import com.caucho.amber.type.StringType;
40
41 import com.caucho.amber.entity.EntityItem;
42
43 import com.caucho.amber.connection.AmberConnectionImpl;
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 uses the from item.
103    */

104   public AmberExpr replaceJoin(JoinExpr join)
105   {
106     return this;
107   }
108
109   /**
110    * Returns the number of columns.
111    */

112   public int getColumnCount()
113   {
114     return 1;
115   }
116   
117   /**
118    * Generates the where expression.
119    */

120   public void generateWhere(CharBuffer cb)
121   {
122     throw new UnsupportedOperationException(getClass().getName());
123   }
124   
125   /**
126    * Generates the where in a join expression.
127    */

128   public void generateJoin(CharBuffer cb)
129   {
130     generateWhere(cb);
131   }
132   
133   /**
134    * Generates the select expression.
135    */

136   public void generateSelect(CharBuffer cb)
137   {
138     generateWhere(cb);
139   }
140
141   /**
142    * Returns the object for the expr.
143    */

144   public Object getObject(AmberConnectionImpl aConn, ResultSet rs, int index)
145     throws SQLException
146   {
147     return getType().getObject(aConn, rs, index);
148   }
149
150   /**
151    * Returns the object for the expr.
152    */

153   public Object getCacheObject(AmberConnectionImpl aConn,
154                    ResultSet rs, int index)
155     throws SQLException
156   {
157     return getObject(aConn, rs, index);
158   }
159
160   /**
161    * Returns the object for the expr.
162    */

163   public EntityItem findItem(AmberConnectionImpl aConn, ResultSet rs, int index)
164     throws SQLException
165   {
166     return getType().findItem(aConn, rs, index);
167   }
168 }
169
Popular Tags