KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > ejb > ql > ThisExpr


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  * Free SoftwareFoundation, Inc.
23  * 59 Temple Place, Suite 330
24  * Boston, MA 02111-1307 USA
25  *
26  * @author Scott Ferguson
27  */

28
29 package com.caucho.ejb.ql;
30
31 import com.caucho.config.ConfigException;
32 import com.caucho.ejb.cfg.EjbEntityBean;
33 import com.caucho.util.CharBuffer;
34
35 /**
36  * Identifier expression for EJB-QL.
37  */

38 class ThisExpr extends PathExpr {
39   // the table name
40
private String JavaDoc _tableName;
41
42   /**
43    * Creates a new identifier expression.
44    *
45    * @param query the owning query
46    * @param bean the mapped bean
47    */

48   ThisExpr(Query query, EjbEntityBean bean)
49     throws ConfigException
50   {
51     super(bean);
52
53     _query = query;
54     
55     // setJavaType(bean.getBeanClass());
56
}
57
58   /**
59    * Returns the identifier name.
60    */

61   String JavaDoc getName()
62   {
63     return "this";
64   }
65   
66   String JavaDoc getKeyTable()
67   {
68     return getName();
69   }
70   
71   String JavaDoc []getKeyFields()
72   {
73     /*
74     PrimaryKey key = _bean.getPrimaryKey();
75     
76     return key.getSQLColumns();
77     */

78     throw new UnsupportedOperationException JavaDoc();
79   }
80
81   String JavaDoc getTable()
82   {
83     return "this";
84   }
85
86   /**
87    * Returns the persistent bean this id is a member of
88    */

89   EjbEntityBean getBean()
90   {
91     return _bean;
92   }
93   
94   /**
95    * Sets the persistent bean this id is a member of
96    */

97   void setBean(EjbEntityBean bean)
98   {
99     _bean = bean;
100   }
101
102   /**
103    * Returns the SQL table name for the id
104    */

105   String JavaDoc getTableName()
106   {
107     if (_tableName != null)
108       return _tableName;
109     else if (_bean != null)
110       return _bean.getSQLTable();
111     else
112       return null;
113   }
114
115   /**
116    * Sets the SQL table name for the id
117    */

118   void setTableName(String JavaDoc tableName)
119   {
120     _tableName = tableName;
121   }
122
123   /**
124    * Returns the item bean of a collection.
125    */

126   EjbEntityBean getItemBean()
127   {
128     return _bean;
129   }
130
131   int getComponentCount()
132   {
133     //return _bean.getPrimaryKey().getSQLColumns().length;
134
throw new UnsupportedOperationException JavaDoc();
135   }
136
137   /**
138    * Prints the select SQL for this expression
139    *
140    * @param gen the java code generator
141    */

142   void generateSelect(CharBuffer cb)
143   {
144     if (_bean == null)
145       throw new IllegalStateException JavaDoc("no bean for " + getName());
146
147     /*
148     PrimaryKey key = _bean.getPrimaryKey();
149
150     String []names = key.getSQLColumns();
151     for (int i = 0; i < names.length; i++) {
152       if (i != 0)
153         gen.print(", ");
154
155       if (_query.getFromList().size() == 1) {
156         // special case to handle strange databases
157         gen.print(names[i]);
158       }
159       else {
160         gen.print(getName());
161         gen.print(".");
162         gen.print(names[i]);
163       }
164     }
165     */

166   }
167
168   /**
169    * Prints the select SQL for this expression
170    *
171    * @param gen the java code generator
172    */

173   String JavaDoc getSelectTable(CharBuffer cb)
174     throws ConfigException
175   {
176     /*
177     if (_query.getFromList().size() == 1) {
178       // special case to handle strange databases
179       return null;
180     }
181     else
182       return getName();
183     */

184     return getName();
185   }
186
187   /**
188    * Prints the where SQL for this expression
189    *
190    * @param gen the java code generator
191    */

192   void generateWhere(CharBuffer cb)
193   {
194     if (_bean == null)
195       throw new IllegalStateException JavaDoc("no bean for " + getName());
196
197     /*
198     String []names = _bean.getPrimaryKey().getSQLColumns();
199     if (names.length != 1)
200       throw new RuntimeException("multiple values need special test.");
201
202     if (_query.getFromList().size() == 1) {
203       // special case to handle strange databases
204       cb.append(names[0]);
205     }
206     else {
207       cb.append(getName());
208       cb.append(".");
209       cb.append(names[0]);
210     }
211     */

212     throw new UnsupportedOperationException JavaDoc();
213   }
214
215   void generateComponent(CharBuffer cb, int index)
216   {
217     if (_bean == null)
218       throw new IllegalStateException JavaDoc("no bean for " + getName());
219
220     /*
221     String []names = _bean.getPrimaryKey().getSQLColumns();
222
223     cb.append(getName());
224     cb.append(".");
225     cb.append(names[index]);
226     */

227     throw new UnsupportedOperationException JavaDoc();
228   }
229   
230   /**
231    * Returns true if the two expressions are equal
232    */

233   public boolean equals(Object JavaDoc bObj)
234   {
235     return bObj instanceof ThisExpr;
236   }
237
238   /**
239    * Returns a hash code for the expression
240    */

241   public int hashCode()
242   {
243     return "this".hashCode();
244   }
245
246   /**
247    * Printable version of the object.
248    */

249   public String JavaDoc toString()
250   {
251     return "this";
252   }
253 }
254
Popular Tags