KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > amber > field > EmbeddedIdField


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

28
29 package com.caucho.amber.field;
30
31 import com.caucho.amber.expr.AmberExpr;
32 import com.caucho.amber.expr.PathExpr;
33 import com.caucho.amber.query.QueryParser;
34 import com.caucho.amber.table.Column;
35 import com.caucho.amber.table.Table;
36 import com.caucho.amber.type.RelatedType;
37 import com.caucho.config.ConfigException;
38 import com.caucho.java.JavaWriter;
39 import com.caucho.log.Log;
40 import com.caucho.util.L10N;
41
42 import java.io.IOException JavaDoc;
43 import java.util.ArrayList JavaDoc;
44 import java.util.HashSet JavaDoc;
45 import java.util.logging.Logger JavaDoc;
46
47 /**
48  * Configuration for a bean's field
49  */

50 public class EmbeddedIdField extends EntityEmbeddedField implements IdField {
51   private static final L10N L = new L10N(EmbeddedIdField.class);
52   protected static final Logger JavaDoc log = Log.open(EmbeddedIdField.class);
53
54   boolean _isKeyField;
55
56   public EmbeddedIdField(RelatedType tableType)
57   {
58     super(tableType);
59     setEmbeddedId(true);
60   }
61
62   public EmbeddedIdField(RelatedType tableType,
63                          String JavaDoc name)
64     throws ConfigException
65   {
66     super(tableType, name);
67     setEmbeddedId(true);
68   }
69
70   /**
71    * Returns the columns
72    */

73   public ArrayList JavaDoc<Column> getColumns()
74   {
75     return null;
76   }
77
78   /**
79    * Set true if key fields are accessed through fields.
80    */

81   public void setKeyField(boolean isKeyField)
82   {
83     _isKeyField = isKeyField;
84   }
85
86   /**
87    * Returns the component count.
88    */

89   public int getComponentCount()
90   {
91     return 1;
92   }
93
94   /**
95    * Returns the foreign type.
96    */

97   public String JavaDoc getForeignTypeName()
98   {
99     return null;
100   }
101
102   /**
103    * Returns the generator.
104    */

105   public String JavaDoc getGenerator()
106   {
107     return null;
108   }
109
110   /**
111    * Generates the setter for a key property
112    */

113   public String JavaDoc generateSetKeyProperty(String JavaDoc key, String JavaDoc value)
114     throws IOException JavaDoc
115   {
116     return null;
117   }
118
119   /**
120    * Generates the getter for a key property
121    */

122   public String JavaDoc generateGetKeyProperty(String JavaDoc key)
123     throws IOException JavaDoc
124   {
125     return null;
126   }
127
128   /**
129    * Generates the property getter for an EJB proxy
130    *
131    * @param value the non-null value
132    */

133   public String JavaDoc generateGetProxyProperty(String JavaDoc value)
134   {
135     return null;
136   }
137
138   /**
139    * Generates any prologue.
140    */

141   public void generatePrologue(JavaWriter out, HashSet JavaDoc<Object JavaDoc> completedSet)
142     throws IOException JavaDoc
143   {
144     super.generatePrologue(out, completedSet);
145
146     if (isAbstract()) {
147       out.println();
148
149       out.println();
150       out.println("public " + getJavaTypeName() + " " + getGetterName() + "()");
151       out.println("{");
152       out.println(" return " + getFieldName() + ";");
153       out.println("}");
154
155       out.println();
156       out.println("public void " + getSetterName() + "(" + getJavaTypeName() + " v)");
157       out.println("{");
158       out.println(" " + getFieldName() + " = v;");
159       out.println("}");
160     }
161   }
162
163   /**
164    * Generates the set clause.
165    */

166   public void generateSetGeneratedKeys(JavaWriter out, String JavaDoc pstmt)
167     throws IOException JavaDoc
168   {
169   }
170
171   /**
172    * Returns the where code
173    */

174   public String JavaDoc generateMatchArgWhere(String JavaDoc id)
175   {
176     return generateWhere(id);
177   }
178
179   /**
180    * Returns the where code
181    */

182   public String JavaDoc generateRawWhere(String JavaDoc id)
183   {
184     return id + "." + getName() + "=?";
185   }
186
187   /**
188    * Generates loading code
189    */

190   public int generateLoad(JavaWriter out, String JavaDoc rs,
191                           String JavaDoc indexVar, int index)
192     throws IOException JavaDoc
193   {
194     return index;
195   }
196
197   /**
198    * Returns the foreign type.
199    */

200   public int generateLoadForeign(JavaWriter out, String JavaDoc rs,
201                                  String JavaDoc indexVar, int index)
202     throws IOException JavaDoc
203   {
204     return 0;
205   }
206
207   /**
208    * Generates loading cache
209    */

210   public void generateLoadFromObject(JavaWriter out, String JavaDoc obj)
211     throws IOException JavaDoc
212   {
213     out.println(generateSuperSetter(generateGet(obj)) + ";");
214   }
215
216   /**
217    * Generates the select clause.
218    */

219   public String JavaDoc generateLoadSelect(Table table, String JavaDoc id)
220   {
221     return null;
222   }
223
224   /**
225    * Generates loading cache
226    */

227   public String JavaDoc generateSetNull(String JavaDoc obj)
228     throws IOException JavaDoc
229   {
230     return null;
231   }
232
233   /**
234    * Returns a test for null.
235    */

236   public String JavaDoc generateIsNull(String JavaDoc value)
237   {
238     return null;
239   }
240
241   /**
242    * Returns the foreign type.
243    */

244   public int generateLoadForeign(JavaWriter out, String JavaDoc rs,
245                                  String JavaDoc indexVar, int index,
246                                  String JavaDoc name)
247     throws IOException JavaDoc
248   {
249     // XXX: 0 == null
250
return 0;
251   }
252
253   /**
254    * Generates the set clause.
255    */

256   public void generateSet(JavaWriter out, String JavaDoc pstmt,
257                           String JavaDoc index, String JavaDoc value)
258     throws IOException JavaDoc
259   {
260     super.generateSet(out, pstmt, index, value);
261   }
262
263   /**
264    * Generates code for a match.
265    */

266   public void generateMatch(JavaWriter out, String JavaDoc key)
267     throws IOException JavaDoc
268   {
269   }
270
271   /**
272    * Generates code to test the equals.
273    */

274   public String JavaDoc generateEquals(String JavaDoc left, String JavaDoc right)
275   {
276     return null;
277   }
278
279   /**
280    * Generates the set clause.
281    */

282   public void generateSetInsert(JavaWriter out, String JavaDoc pstmt, String JavaDoc index)
283     throws IOException JavaDoc
284   {
285     generateSet(out, pstmt, index);
286   }
287
288   /**
289    * Generates the set clause.
290    */

291   public void generateCheckCreateKey(JavaWriter out)
292     throws IOException JavaDoc
293   {
294   }
295
296   /**
297    * Creates the expression for the field.
298    */

299   public AmberExpr createExpr(QueryParser parser, PathExpr parent)
300   {
301     return null;
302   }
303
304   /**
305    * Converts to an object.
306    */

307   public String JavaDoc toObject(String JavaDoc value)
308   {
309     return null;
310   }
311
312   /**
313    * Converts from an object.
314    */

315   public String JavaDoc toValue(String JavaDoc value)
316   {
317     return null;
318   }
319 }
320
Popular Tags