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: * Free Software Foundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Scott Ferguson
027: */
028:
029: package com.caucho.amber.field;
030:
031: import com.caucho.amber.expr.AmberExpr;
032: import com.caucho.amber.expr.PathExpr;
033: import com.caucho.amber.query.QueryParser;
034: import com.caucho.amber.table.Column;
035: import com.caucho.amber.table.Table;
036: import com.caucho.amber.type.RelatedType;
037: import com.caucho.amber.type.EmbeddableType;
038: import com.caucho.config.ConfigException;
039: import com.caucho.java.JavaWriter;
040: import com.caucho.log.Log;
041: import com.caucho.util.L10N;
042:
043: import java.io.IOException;
044: import java.util.ArrayList;
045: import java.util.HashSet;
046: import java.util.logging.Logger;
047:
048: /**
049: * Configuration for a bean's field
050: */
051: public class EmbeddedIdField extends EntityEmbeddedField implements
052: IdField {
053: private static final L10N L = new L10N(EmbeddedIdField.class);
054: protected static final Logger log = Logger
055: .getLogger(EmbeddedIdField.class.getName());
056:
057: boolean _isKeyField;
058:
059: public EmbeddedIdField(RelatedType ownerType,
060: EmbeddableType embeddableType) {
061: super (ownerType, embeddableType);
062: }
063:
064: public EmbeddedIdField(RelatedType ownerType,
065: EmbeddableType embeddableType, String name)
066: throws ConfigException {
067: super (ownerType, embeddableType, name);
068: }
069:
070: protected EmbeddedSubField createSubField(AmberField field,
071: int index) {
072: return new KeyEmbeddedSubField(this , field, index);
073: }
074:
075: /**
076: * Returns the columns
077: */
078: public ArrayList<Column> getColumns() {
079: return null;
080: }
081:
082: /**
083: * Returns true for a generator.
084: */
085: public boolean isAutoGenerate() {
086: return false;
087: }
088:
089: /**
090: * Set true if key fields are accessed through fields.
091: */
092: public void setKeyField(boolean isKeyField) {
093: _isKeyField = isKeyField;
094: }
095:
096: /**
097: * Returns the component count.
098: */
099: public int getComponentCount() {
100: return 1;
101: }
102:
103: /**
104: * Returns the foreign type.
105: */
106: public String getForeignTypeName() {
107: return null;
108: }
109:
110: /**
111: * Returns the generator.
112: */
113: public String getGenerator() {
114: return null;
115: }
116:
117: /**
118: * Generates the setter for a key property
119: */
120: public String generateSetKeyProperty(String key, String value)
121: throws IOException {
122: return null;
123: }
124:
125: /**
126: * Generates the getter for a key property
127: */
128: public String generateGetKeyProperty(String key) throws IOException {
129: return null;
130: }
131:
132: /**
133: * Generates the property getter for an EJB proxy
134: *
135: * @param value the non-null value
136: */
137: public String generateGetProxyProperty(String value) {
138: return null;
139: }
140:
141: /**
142: * Generates any prologue.
143: */
144: public void generatePrologue(JavaWriter out,
145: HashSet<Object> completedSet) throws IOException {
146: super .generatePrologue(out, completedSet);
147:
148: if (isAbstract()) {
149: out.println();
150:
151: out.println();
152: out.println("public " + getJavaTypeName() + " "
153: + getGetterName() + "()");
154: out.println("{");
155: out.println(" return " + getFieldName() + ";");
156: out.println("}");
157:
158: out.println();
159: out.println("public void " + getSetterName() + "("
160: + getJavaTypeName() + " v)");
161: out.println("{");
162: out.println(" " + getFieldName() + " = v;");
163: out.println("}");
164: }
165: }
166:
167: /**
168: * Generates the set clause.
169: */
170: public void generateSetGeneratedKeys(JavaWriter out, String pstmt)
171: throws IOException {
172: }
173:
174: /**
175: * Returns the where code
176: */
177: public String generateMatchArgWhere(String id) {
178: return generateWhere(id);
179: }
180:
181: /**
182: * Returns the where code
183: */
184: public String generateRawWhere(String id) {
185: return id + "." + getName() + "=?";
186: }
187:
188: /**
189: * Generates loading code
190: */
191: public int generateLoad(JavaWriter out, String rs, String indexVar,
192: int index) throws IOException {
193: return index;
194: }
195:
196: /**
197: * Returns the foreign type.
198: */
199: public int generateLoadForeign(JavaWriter out, String rs,
200: String indexVar, int index) throws IOException {
201: return 0;
202: }
203:
204: /**
205: * Generates loading cache
206: */
207: public void generateLoadFromObject(JavaWriter out, String obj)
208: throws IOException {
209: out.println(generateSuperSetter(generateGet(obj)) + ";");
210: }
211:
212: /**
213: * Generates the select clause.
214: */
215: public String generateLoadSelect(Table table, String id) {
216: return null;
217: }
218:
219: /**
220: * Generates loading cache
221: */
222: public String generateSetNull(String obj) throws IOException {
223: return null;
224: }
225:
226: /**
227: * Returns a test for null.
228: */
229: public String generateIsNull(String value) {
230: return null;
231: }
232:
233: /**
234: * Returns the foreign type.
235: */
236: public int generateLoadForeign(JavaWriter out, String rs,
237: String indexVar, int index, String name) throws IOException {
238: // XXX: 0 == null
239: return 0;
240: }
241:
242: /**
243: * Generates the set clause.
244: */
245: public void generateSet(JavaWriter out, String pstmt, String index,
246: String value) throws IOException {
247: super .generateSet(out, pstmt, index, value);
248: }
249:
250: /**
251: * Generates code for a match.
252: */
253: public void generateMatch(JavaWriter out, String key)
254: throws IOException {
255: }
256:
257: /**
258: * Generates code to test the equals.
259: */
260: public String generateEquals(String left, String right) {
261: return null;
262: }
263:
264: /**
265: * Generates the set clause.
266: */
267: public void generateSetInsert(JavaWriter out, String pstmt,
268: String index) throws IOException {
269: generateSet(out, pstmt, index);
270: }
271:
272: /**
273: * Generates the set clause.
274: */
275: public void generateCheckCreateKey(JavaWriter out)
276: throws IOException {
277: }
278:
279: /**
280: * Creates the expression for the field.
281: */
282: public AmberExpr createExpr(QueryParser parser, PathExpr parent) {
283: return null;
284: }
285:
286: /**
287: * Converts to an object.
288: */
289: public String toObject(String value) {
290: return null;
291: }
292:
293: /**
294: * Converts from an object.
295: */
296: public String toValue(String value) {
297: return null;
298: }
299: }
|