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