001: package org.tigris.scarab.om;
002:
003: import java.math.BigDecimal;
004: import java.sql.Connection;
005: import java.util.ArrayList;
006: import java.util.Collections;
007: import java.util.Date;
008: import java.util.List;
009:
010: import org.apache.commons.lang.ObjectUtils;
011: import org.apache.fulcrum.intake.Retrievable;
012: import org.apache.torque.TorqueException;
013: import org.apache.torque.om.BaseObject;
014: import org.apache.torque.om.ComboKey;
015: import org.apache.torque.om.DateKey;
016: import org.apache.torque.om.NumberKey;
017: import org.apache.torque.om.ObjectKey;
018: import org.apache.torque.om.SimpleKey;
019: import org.apache.torque.om.StringKey;
020: import org.apache.torque.om.Persistent;
021: import org.apache.torque.util.Criteria;
022: import org.apache.torque.util.Transaction;
023:
024: /**
025: * You should not use this class directly. It should not even be
026: * extended all references should be to GlobalParameter
027: */
028: public abstract class BaseGlobalParameter extends BaseObject implements
029: org.apache.fulcrum.intake.Retrievable {
030: /** The Peer class */
031: private static final GlobalParameterPeer peer = new GlobalParameterPeer();
032:
033: /** The value for the parameterId field */
034: private Integer parameterId;
035:
036: /** The value for the name field */
037: private String name;
038:
039: /** The value for the value field */
040: private String value;
041:
042: /** The value for the moduleId field */
043: private Integer moduleId;
044:
045: /**
046: * Get the ParameterId
047: *
048: * @return Integer
049: */
050: public Integer getParameterId() {
051: return parameterId;
052: }
053:
054: /**
055: * Set the value of ParameterId
056: *
057: * @param v new value
058: */
059: public void setParameterId(Integer v) {
060:
061: if (!ObjectUtils.equals(this .parameterId, v)) {
062: this .parameterId = v;
063: setModified(true);
064: }
065:
066: }
067:
068: /**
069: * Get the Name
070: *
071: * @return String
072: */
073: public String getName() {
074: return name;
075: }
076:
077: /**
078: * Set the value of Name
079: *
080: * @param v new value
081: */
082: public void setName(String v) {
083:
084: if (!ObjectUtils.equals(this .name, v)) {
085: this .name = v;
086: setModified(true);
087: }
088:
089: }
090:
091: /**
092: * Get the Value
093: *
094: * @return String
095: */
096: public String getValue() {
097: return value;
098: }
099:
100: /**
101: * Set the value of Value
102: *
103: * @param v new value
104: */
105: public void setValue(String v) {
106:
107: if (!ObjectUtils.equals(this .value, v)) {
108: this .value = v;
109: setModified(true);
110: }
111:
112: }
113:
114: /**
115: * Get the ModuleId
116: *
117: * @return Integer
118: */
119: public Integer getModuleId() {
120: return moduleId;
121: }
122:
123: /**
124: * Set the value of ModuleId
125: *
126: * @param v new value
127: */
128: public void setModuleId(Integer v) throws TorqueException {
129:
130: if (!ObjectUtils.equals(this .moduleId, v)) {
131: this .moduleId = v;
132: setModified(true);
133: }
134:
135: if (aModule != null
136: && !ObjectUtils.equals(aModule.getModuleId(), v)) {
137: aModule = null;
138: }
139:
140: }
141:
142: private Module aModule;
143:
144: /**
145: * Declares an association between this object and a Module object
146: *
147: * @param v Module
148: * @throws TorqueException
149: */
150: public void setModule(Module v) throws TorqueException {
151: if (v == null) {
152: setModuleId((Integer) null);
153: } else {
154: setModuleId(v.getModuleId());
155: }
156: aModule = v;
157: }
158:
159: /**
160: * Returns the associated Module object.
161: * If it was not retrieved before, the object is retrieved from
162: * the database
163: *
164: * @return the associated Module object
165: * @throws TorqueException
166: */
167: public Module getModule() throws TorqueException {
168: if (aModule == null
169: && (!ObjectUtils.equals(this .moduleId, null))) {
170: aModule = ModuleManager.getInstance(SimpleKey
171: .keyFor(this .moduleId));
172: }
173: return aModule;
174: }
175:
176: /**
177: * Return the associated Module object
178: * If it was not retrieved before, the object is retrieved from
179: * the database using the passed connection
180: *
181: * @param connection the connection used to retrieve the associated object
182: * from the database, if it was not retrieved before
183: * @return the associated Module object
184: * @throws TorqueException
185: */
186: public Module getModule(Connection connection)
187: throws TorqueException {
188: if (aModule == null
189: && (!ObjectUtils.equals(this .moduleId, null))) {
190: aModule = ModuleManager.getCachedInstance(SimpleKey
191: .keyFor(this .moduleId));
192: if (aModule == null) {
193: aModule = ScarabModulePeer.retrieveByPK(SimpleKey
194: .keyFor(this .moduleId), connection);
195: ModuleManager.putInstance(aModule);
196: }
197: }
198: return aModule;
199: }
200:
201: /**
202: * Provides convenient way to set a relationship based on a
203: * ObjectKey, for example
204: * <code>bar.setFooKey(foo.getPrimaryKey())</code>
205: *
206: */
207: public void setModuleKey(ObjectKey key) throws TorqueException {
208:
209: setModuleId(new Integer(((NumberKey) key).intValue()));
210: }
211:
212: private static List fieldNames = null;
213:
214: /**
215: * Generate a list of field names.
216: *
217: * @return a list of field names
218: */
219: public static synchronized List getFieldNames() {
220: if (fieldNames == null) {
221: fieldNames = new ArrayList();
222: fieldNames.add("ParameterId");
223: fieldNames.add("Name");
224: fieldNames.add("Value");
225: fieldNames.add("ModuleId");
226: fieldNames = Collections.unmodifiableList(fieldNames);
227: }
228: return fieldNames;
229: }
230:
231: /**
232: * Retrieves a field from the object by name passed in as a String.
233: *
234: * @param name field name
235: * @return value
236: */
237: public Object getByName(String name) {
238: if (name.equals("ParameterId")) {
239: return getParameterId();
240: }
241: if (name.equals("Name")) {
242: return getName();
243: }
244: if (name.equals("Value")) {
245: return getValue();
246: }
247: if (name.equals("ModuleId")) {
248: return getModuleId();
249: }
250: return null;
251: }
252:
253: /**
254: * Retrieves a field from the object by name passed in
255: * as a String. The String must be one of the static
256: * Strings defined in this Class' Peer.
257: *
258: * @param name peer name
259: * @return value
260: */
261: public Object getByPeerName(String name) {
262: if (name.equals(GlobalParameterPeer.PARAMETER_ID)) {
263: return getParameterId();
264: }
265: if (name.equals(GlobalParameterPeer.NAME)) {
266: return getName();
267: }
268: if (name.equals(GlobalParameterPeer.VALUE)) {
269: return getValue();
270: }
271: if (name.equals(GlobalParameterPeer.MODULE_ID)) {
272: return getModuleId();
273: }
274: return null;
275: }
276:
277: /**
278: * Retrieves a field from the object by Position as specified
279: * in the xml schema. Zero-based.
280: *
281: * @param pos position in xml schema
282: * @return value
283: */
284: public Object getByPosition(int pos) {
285: if (pos == 0) {
286: return getParameterId();
287: }
288: if (pos == 1) {
289: return getName();
290: }
291: if (pos == 2) {
292: return getValue();
293: }
294: if (pos == 3) {
295: return getModuleId();
296: }
297: return null;
298: }
299:
300: /**
301: * Stores the object in the database. If the object is new,
302: * it inserts it; otherwise an update is performed.
303: *
304: * @throws TorqueException
305: */
306: public void save() throws TorqueException {
307: save(GlobalParameterPeer.getMapBuilder().getDatabaseMap()
308: .getName());
309: }
310:
311: /**
312: * Stores the object in the database. If the object is new,
313: * it inserts it; otherwise an update is performed.
314: * Note: this code is here because the method body is
315: * auto-generated conditionally and therefore needs to be
316: * in this file instead of in the super class, BaseObject.
317: *
318: * @param dbName
319: * @throws TorqueException
320: */
321: public void save(String dbName) throws TorqueException {
322: Connection con = null;
323: try {
324: con = Transaction.begin(dbName);
325: save(con);
326: Transaction.commit(con);
327: } catch (TorqueException e) {
328: Transaction.safeRollback(con);
329: throw e;
330: }
331: }
332:
333: /** flag to prevent endless save loop, if this object is referenced
334: by another object which falls in this transaction. */
335: private boolean alreadyInSave = false;
336:
337: /**
338: * Stores the object in the database. If the object is new,
339: * it inserts it; otherwise an update is performed. This method
340: * is meant to be used as part of a transaction, otherwise use
341: * the save() method and the connection details will be handled
342: * internally
343: *
344: * @param con
345: * @throws TorqueException
346: */
347: public void save(Connection con) throws TorqueException {
348: if (!alreadyInSave) {
349: alreadyInSave = true;
350:
351: // If this object has been modified, then save it to the database.
352: if (isModified()) {
353: if (isNew()) {
354: GlobalParameterPeer.doInsert(
355: (GlobalParameter) this , con);
356: setNew(false);
357: } else {
358: GlobalParameterPeer.doUpdate(
359: (GlobalParameter) this , con);
360: }
361:
362: if (isCacheOnSave()) {
363: GlobalParameterManager.putInstance(this );
364: }
365: }
366:
367: alreadyInSave = false;
368: }
369: }
370:
371: /**
372: * Specify whether to cache the object after saving to the db.
373: * This method returns true
374: */
375: protected boolean isCacheOnSave() {
376: return true;
377: }
378:
379: /**
380: * Set the PrimaryKey using ObjectKey.
381: *
382: * @param key parameterId ObjectKey
383: */
384: public void setPrimaryKey(ObjectKey key)
385:
386: {
387: setParameterId(new Integer(((NumberKey) key).intValue()));
388: }
389:
390: /**
391: * Set the PrimaryKey using a String.
392: *
393: * @param key
394: */
395: public void setPrimaryKey(String key) {
396: setParameterId(new Integer(key));
397: }
398:
399: /**
400: * returns an id that differentiates this object from others
401: * of its class.
402: */
403: public ObjectKey getPrimaryKey() {
404: return SimpleKey.keyFor(getParameterId());
405: }
406:
407: /**
408: * get an id that differentiates this object from others
409: * of its class.
410: */
411: public String getQueryKey() {
412: if (getPrimaryKey() == null) {
413: return "";
414: } else {
415: return getPrimaryKey().toString();
416: }
417: }
418:
419: /**
420: * set an id that differentiates this object from others
421: * of its class.
422: */
423: public void setQueryKey(String key) throws TorqueException {
424: setPrimaryKey(key);
425: }
426:
427: /**
428: * Makes a copy of this object.
429: * It creates a new object filling in the simple attributes.
430: * It then fills all the association collections and sets the
431: * related objects to isNew=true.
432: */
433: public GlobalParameter copy() throws TorqueException {
434: return copyInto(new GlobalParameter());
435: }
436:
437: protected GlobalParameter copyInto(GlobalParameter copyObj)
438: throws TorqueException {
439: copyObj.setParameterId(parameterId);
440: copyObj.setName(name);
441: copyObj.setValue(value);
442: copyObj.setModuleId(moduleId);
443:
444: copyObj.setParameterId((Integer) null);
445:
446: return copyObj;
447: }
448:
449: /**
450: * returns a peer instance associated with this om. Since Peer classes
451: * are not to have any instance attributes, this method returns the
452: * same instance for all member of this class. The method could therefore
453: * be static, but this would prevent one from overriding the behavior.
454: */
455: public GlobalParameterPeer getPeer() {
456: return peer;
457: }
458:
459: public String toString() {
460: StringBuffer str = new StringBuffer();
461: str.append("GlobalParameter:\n");
462: str.append("ParameterId = ").append(getParameterId()).append(
463: "\n");
464: str.append("Name = ").append(getName()).append("\n");
465: str.append("Value = ").append(getValue()).append("\n");
466: str.append("ModuleId = ").append(getModuleId()).append("\n");
467: return (str.toString());
468: }
469: }
|