001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Scott Ferguson
028: */
029:
030: package com.caucho.amber.field;
031:
032: import com.caucho.amber.expr.AmberExpr;
033: import com.caucho.amber.expr.PathExpr;
034: import com.caucho.amber.manager.AmberConnection;
035: import com.caucho.amber.manager.AmberPersistenceUnit;
036: import com.caucho.amber.query.QueryParser;
037: import com.caucho.amber.table.Table;
038: import com.caucho.amber.table.Column;
039: import com.caucho.amber.type.AbstractStatefulType;
040: import com.caucho.bytecode.JMethod;
041: import com.caucho.bytecode.JType;
042: import com.caucho.config.ConfigException;
043: import com.caucho.java.JavaWriter;
044: import com.caucho.util.CharBuffer;
045:
046: import java.io.IOException;
047: import java.io.Serializable;
048: import java.sql.SQLException;
049: import java.util.ArrayList;
050: import java.util.HashSet;
051:
052: /**
053: * Configuration for a bean's property
054: */
055: public interface AmberField {
056: /**
057: * Returns the owning entity class.
058: */
059: public AbstractStatefulType getSourceType();
060:
061: /**
062: * Returns true if and only if this is a LAZY field.
063: */
064: public boolean isLazy();
065:
066: /**
067: * Returns the field name.
068: */
069: public String getName();
070:
071: /**
072: * Returns the table containing the value (or null)
073: */
074: public Table getTable();
075:
076: /**
077: * Returns the column for the field.
078: */
079: public Column getColumn();
080:
081: /**
082: * Returns the property index.
083: */
084: public int getIndex();
085:
086: /**
087: * Returns the property's group index.
088: */
089: public int getLoadGroupIndex();
090:
091: /**
092: * Returns the load group mask.
093: */
094: public long getCreateLoadMask(int group);
095:
096: /**
097: * Returns the getter method.
098: */
099: public JMethod getGetterMethod();
100:
101: /**
102: * Returns the getter name.
103: */
104: public String getGetterName();
105:
106: /**
107: * Returns the type of the field
108: */
109: public JType getJavaType();
110:
111: /**
112: * Returns the name of the java type.
113: */
114: public String getJavaTypeName();
115:
116: /**
117: * Returns the setter method.
118: */
119: public JMethod getSetterMethod();
120:
121: /**
122: * Returns the setter name.
123: */
124: public String getSetterName();
125:
126: /**
127: * Returns true if the methods are abstract.
128: */
129: public boolean isAbstract();
130:
131: /**
132: * Returns true if the field is cascadable.
133: */
134: public boolean isCascadable();
135:
136: /**
137: * Returns true for an updateable field.
138: */
139: public boolean isUpdateable();
140:
141: /**
142: * Links to the target.
143: */
144: public void setIndex(int index);
145:
146: /**
147: * Links to the target.
148: */
149: public void init() throws ConfigException;
150:
151: /**
152: * Returns the actual data.
153: */
154: public String generateSuperGetter();
155:
156: /**
157: * Sets the actual data.
158: */
159: public String generateSuperSetter(String value);
160:
161: /**
162: * Sets the actual data.
163: */
164: public String generateSuperSetter(String objThis, String value);
165:
166: /**
167: * Generates any prologue.
168: */
169: public void generatePrologue(JavaWriter out,
170: HashSet<Object> completedSet) throws IOException;
171:
172: /**
173: * Generates the post constructor fixup
174: */
175: public void generatePostConstructor(JavaWriter out)
176: throws IOException;
177:
178: /**
179: * Generates the select clause for an entity load.
180: */
181: public String generateLoadSelect(Table table, String id);
182:
183: /**
184: * Generates the select clause.
185: */
186: public String generateSelect(String id);
187:
188: /**
189: * Generates the JPA QL select clause.
190: */
191: public String generateJavaSelect(String id);
192:
193: /**
194: * Generates the where clause.
195: */
196: public String generateWhere(String id);
197:
198: /**
199: * Generates the where clause.
200: */
201: public void generateUpdate(CharBuffer sql);
202:
203: /**
204: * Generates loading cache
205: */
206: public void generateUpdate(JavaWriter out, String mask,
207: String pstmt, String index) throws IOException;
208:
209: /**
210: * Generates loading code
211: */
212: public boolean hasLoadGroup(int index);
213:
214: /**
215: * Generates loading code
216: */
217: public int generateLoad(JavaWriter out, String rs, String indexVar,
218: int loadGroupIndex) throws IOException;
219:
220: /**
221: * Generates loading code after the basic fields.
222: */
223: public int generatePostLoadSelect(JavaWriter out, int index)
224: throws IOException;
225:
226: /**
227: * Generates loading cache
228: */
229: public void generateLoadFromObject(JavaWriter out, String obj)
230: throws IOException;
231:
232: /**
233: * Generates loading cache
234: */
235: public void generateSet(JavaWriter out, String obj)
236: throws IOException;
237:
238: /**
239: * Generates loading cache
240: */
241: public void generateUpdateFromObject(JavaWriter out, String obj)
242: throws IOException;
243:
244: /**
245: * Generates the field getter.
246: *
247: * @param value the non-null value
248: */
249: public void generateGet(JavaWriter out, String value)
250: throws IOException;
251:
252: /**
253: * Generates the field getter.
254: *
255: * @param value the non-null value
256: */
257: public String generateGet(String value);
258:
259: /**
260: * Generates the field setter.
261: *
262: * @param value the non-null value
263: */
264: public String generateSet(String obj, String value);
265:
266: /**
267: * Generates the insert.
268: */
269: public void generateInsertColumns(ArrayList<String> columns);
270:
271: /**
272: * Generates the get property.
273: */
274: public void generateGetProperty(JavaWriter out) throws IOException;
275:
276: /**
277: * Generates the set property.
278: */
279: public void generateSetProperty(JavaWriter out) throws IOException;
280:
281: /**
282: * Generates the get property.
283: */
284: public void generateSuperGetter(JavaWriter out) throws IOException;
285:
286: /**
287: * Generates the get property.
288: */
289: public void generateSuperSetter(JavaWriter out) throws IOException;
290:
291: /**
292: * Generates the table create.
293: */
294: public String generateCreateTableSQL(AmberPersistenceUnit manager);
295:
296: /**
297: * Generates the set clause.
298: */
299: public void generateSet(JavaWriter out, String pstmt, String index)
300: throws IOException;
301:
302: /**
303: * Generates the set clause for the insert clause.
304: */
305: public void generateInsertSet(JavaWriter out, String pstmt,
306: String index, String obj) throws IOException;
307:
308: /**
309: * Generates the set clause for the insert clause.
310: */
311: public void generateUpdateSet(JavaWriter out, String pstmt,
312: String index, String obj) throws IOException;
313:
314: /**
315: * Updates the cached copy.
316: */
317: public void generateCopyUpdateObject(JavaWriter out, String dst,
318: String src, int updateIndex) throws IOException;
319:
320: /**
321: * Updates the cached copy.
322: */
323: public void generateCopyLoadObject(JavaWriter out, String dst,
324: String src, int loadIndex) throws IOException;
325:
326: /**
327: * Updates the cached copy.
328: */
329: public void generateCopyMergeObject(JavaWriter out, String dst,
330: String src, int loadIndex) throws IOException;
331:
332: /**
333: * Checks entity-relationships from an object.
334: */
335: public void generateDumpRelationships(JavaWriter out,
336: int updateIndex) throws IOException;
337:
338: /**
339: * Generates the set clause.
340: */
341: public void generateSet(JavaWriter out, String pstmt, String index,
342: String obj) throws IOException;
343:
344: /**
345: * Converts to an object.
346: */
347: public String toObject(String value);
348:
349: /**
350: * Links to the target.
351: */
352: public void link();
353:
354: /**
355: * Generates the delete foreign
356: */
357: public void generatePreDelete(JavaWriter out) throws IOException;
358:
359: /**
360: * Generates the delete foreign
361: */
362: public void generatePostDelete(JavaWriter out) throws IOException;
363:
364: /**
365: * Generates the expire code.
366: */
367: public void generateExpire(JavaWriter out) throws IOException;
368:
369: /**
370: * Generates code for foreign entity create/delete
371: */
372: public void generateInvalidateForeign(JavaWriter out)
373: throws IOException;
374:
375: /**
376: * Deletes the children
377: */
378: public void childDelete(AmberConnection aConn,
379: Serializable primaryKey) throws SQLException;
380:
381: /**
382: * Generates code to convert to the type from the object.
383: */
384: public String generateCastFromObject(String value);
385:
386: /**
387: * Generates code to test the equals.
388: */
389: public String generateEquals(String leftBase, String value);
390:
391: /**
392: * Creates the expression for the field.
393: */
394: public AmberExpr createExpr(QueryParser parser, PathExpr parent);
395: }
|