001: // .//GEN-BEGIN:1_be
002: /******************************************************
003: * Code Generated From JAFFA Framework Default Pattern
004: *
005: * The JAFFA Project can be found at http://jaffa.sourceforge.net
006: * and is available under the Lesser GNU Public License
007: ******************************************************/package org.jaffa.persistence.domainobjects;
008:
009: import org.apache.log4j.Logger;
010: import java.util.*;
011: import org.jaffa.datatypes.*;
012: import org.jaffa.metadata.*;
013: import org.jaffa.rules.RulesEngine;
014: import org.jaffa.persistence.*;
015: import org.jaffa.persistence.exceptions.*;
016: import org.jaffa.exceptions.FrameworkException;
017: import org.jaffa.exceptions.RelatedDomainObjectFoundException;
018: import org.jaffa.exceptions.DuplicateKeyException;
019: import org.jaffa.datatypes.exceptions.InvalidForeignKeyException;
020: import org.jaffa.exceptions.ApplicationExceptions;
021:
022: import org.jaffa.persistence.domainobjects.Asset;
023: import org.jaffa.persistence.domainobjects.AssetMeta;
024: import org.jaffa.persistence.domainobjects.Item;
025: import org.jaffa.persistence.domainobjects.ItemMeta;
026:
027: // .//GEN-END:1_be
028: // Add additional imports//GEN-FIRST:imports
029:
030: // .//GEN-LAST:imports
031: // .//GEN-BEGIN:2_be
032: /**
033: * Auto Generated Persistent class for the ZZ_JUT_CONDITION table.
034: * @author Auto-Generated
035: */
036: public class Condition extends Persistent {
037:
038: private static final Logger log = Logger.getLogger(Condition.class);
039:
040: /** Holds value of property condition. */
041: private java.lang.String m_condition;
042:
043: /** Holds value of property description. */
044: private java.lang.String m_description;
045:
046: /** Holds related Asset objects. */
047: private transient Collection m_assetCollection;
048:
049: /** Holds related Item objects. */
050: private transient Collection m_itemCollection;
051:
052: /** Check if the domain object exists for the input Primary Key.
053: * @return true if the domain object exists for the input Primary Key.
054: * @throws FrameworkException Indicates some system error
055: */
056: public static boolean exists(UOW uow, java.lang.String condition)
057: throws FrameworkException {
058: return findByPK(uow, condition) != null ? true : false;
059: }
060:
061: /** Returns the domain object for the input Primary Key.
062: * @return the domain object for the input Primary Key. A null is returned if the domain object is not found.
063: * @throws FrameworkException Indicates some system error
064: */
065: public static Condition findByPK(UOW uow, java.lang.String condition)
066: throws FrameworkException {
067: boolean localUow = false;
068: try {
069: if (uow == null || !uow.isActive()) {
070: uow = new UOW();
071: localUow = true;
072: }
073: Criteria criteria = findByPKCriteria(condition);
074: Iterator itr = uow.query(criteria).iterator();
075: if (itr.hasNext())
076: return (Condition) itr.next();
077: else
078: return null;
079: } finally {
080: if (localUow && uow != null)
081: uow.rollback();
082: }
083: }
084:
085: /** Returns a Criteria object for retrieving the domain object based on the input Primary Key.
086: * @return a Criteria object for retrieving the domain object based on the input Primary Key.
087: */
088: public static Criteria findByPKCriteria(java.lang.String condition) {
089: Criteria criteria = new Criteria();
090: criteria.setTable(ConditionMeta.getName());
091: criteria.addCriteria(ConditionMeta.CONDITION, condition);
092: return criteria;
093: }
094:
095: // .//GEN-END:2_be
096: // .//GEN-BEGIN:condition_be
097: /** Getter for property condition.
098: * @return Value of property condition.
099: */
100: public java.lang.String getCondition() {
101: return m_condition;
102: }
103:
104: /** Use this method to update the property condition.
105: * This method will do nothing and simply return if the input value is the same as the current value.
106: * Validation will be performed on the input value.
107: * This will try to lock the underlying database row, in case CAUTIOUS locking is specified at the time of query.
108: * @param condition New value of property condition.
109: * @throws ValidationException if an invalid value is passed.
110: * @throws UpdatePrimaryKeyException if this domain object was loaded from the database.
111: * @throws ReadOnlyObjectException if a Read-Only object is updated.
112: * @throws AlreadyLockedObjectException if the underlying database row is already locked by another process.
113: * @throws FrameworkException Indicates some system error
114: */
115: public void setCondition(java.lang.String condition)
116: throws ValidationException, UpdatePrimaryKeyException,
117: ReadOnlyObjectException, AlreadyLockedObjectException,
118: FrameworkException {
119: // ignore, if the current value and new value are the same
120: if (m_condition == null ? condition == null : m_condition
121: .equals(condition))
122: return;
123:
124: // this is part of the primary key.. do not update if its a database occurence.
125: if (isDatabaseOccurence())
126: throw new UpdatePrimaryKeyException();
127:
128: condition = validateCondition(condition);
129: // .//GEN-END:condition_be
130: // Add custom code before setting the value//GEN-FIRST:condition
131:
132: // .//GEN-LAST:condition
133: // .//GEN-BEGIN:condition_1_be
134: super .update();
135: super .addInitialValue(ConditionMeta.CONDITION, m_condition);
136: m_condition = condition;
137: // .//GEN-END:condition_1_be
138: // Add custom code after setting the value//GEN-FIRST:condition_3
139:
140: // .//GEN-LAST:condition_3
141: // .//GEN-BEGIN:condition_2_be
142: }
143:
144: /** This method is present for backwards compatibility only.
145: * It merely invokes the setCondition() method.
146: * @param condition New value of property condition.
147: * @throws ValidationException if an invalid value is passed.
148: * @throws UpdatePrimaryKeyException if this domain object was loaded from the database.
149: * @throws ReadOnlyObjectException if a Read-Only object is updated.
150: * @throws AlreadyLockedObjectException if the underlying database row is already locked by another process.
151: * @throws FrameworkException Indicates some system error
152: */
153: public void updateCondition(java.lang.String condition)
154: throws ValidationException, UpdatePrimaryKeyException,
155: ReadOnlyObjectException, AlreadyLockedObjectException,
156: FrameworkException {
157: setCondition(condition);
158: }
159:
160: /** Use this method to validate a value for the property condition.
161: * @param condition Value to be validated for the property condition.
162: * @throws ValidationException if an invalid value is passed
163: * @throws FrameworkException Indicates some system error
164: */
165: public java.lang.String validateCondition(java.lang.String condition)
166: throws ValidationException, FrameworkException {
167: // .//GEN-END:condition_2_be
168: // Add custom code before validation//GEN-FIRST:condition_1
169:
170: // .//GEN-LAST:condition_1
171: // .//GEN-BEGIN:condition_3_be
172: condition = FieldValidator.validate(condition,
173: (StringFieldMetaData) ConditionMeta.META_CONDITION,
174: true);
175:
176: // Invoke the Dynamic Rules Engine
177: RulesEngine.doAllValidationsForDomainField(ConditionMeta
178: .getName(), ConditionMeta.CONDITION, condition, this
179: .getUOW());
180:
181: // .//GEN-END:condition_3_be
182: // Add custom code after a successful validation//GEN-FIRST:condition_2
183:
184: // .//GEN-LAST:condition_2
185: // .//GEN-BEGIN:condition_4_be
186: return condition;
187: }
188:
189: // .//GEN-END:condition_4_be
190: // .//GEN-BEGIN:description_be
191: /** Getter for property description.
192: * @return Value of property description.
193: */
194: public java.lang.String getDescription() {
195: return m_description;
196: }
197:
198: /** Use this method to update the property description.
199: * This method will do nothing and simply return if the input value is the same as the current value.
200: * Validation will be performed on the input value.
201: * This will try to lock the underlying database row, in case CAUTIOUS locking is specified at the time of query.
202: * @param description New value of property description.
203: * @throws ValidationException if an invalid value is passed.
204: * @throws ReadOnlyObjectException if a Read-Only object is updated.
205: * @throws AlreadyLockedObjectException if the underlying database row is already locked by another process.
206: * @throws FrameworkException Indicates some system error
207: */
208: public void setDescription(java.lang.String description)
209: throws ValidationException, ReadOnlyObjectException,
210: AlreadyLockedObjectException, FrameworkException {
211: // ignore, if the current value and new value are the same
212: if (m_description == null ? description == null : m_description
213: .equals(description))
214: return;
215:
216: description = validateDescription(description);
217: // .//GEN-END:description_be
218: // Add custom code before setting the value//GEN-FIRST:description
219:
220: // .//GEN-LAST:description
221: // .//GEN-BEGIN:description_1_be
222: super .update();
223: super .addInitialValue(ConditionMeta.DESCRIPTION, m_description);
224: m_description = description;
225: // .//GEN-END:description_1_be
226: // Add custom code after setting the value//GEN-FIRST:description_3
227:
228: // .//GEN-LAST:description_3
229: // .//GEN-BEGIN:description_2_be
230: }
231:
232: /** This method is present for backwards compatibility only.
233: * It merely invokes the setDescription() method.
234: * @param description New value of property description.
235: * @throws ValidationException if an invalid value is passed.
236: * @throws ReadOnlyObjectException if a Read-Only object is updated.
237: * @throws AlreadyLockedObjectException if the underlying database row is already locked by another process.
238: * @throws FrameworkException Indicates some system error
239: */
240: public void updateDescription(java.lang.String description)
241: throws ValidationException, ReadOnlyObjectException,
242: AlreadyLockedObjectException, FrameworkException {
243: setDescription(description);
244: }
245:
246: /** Use this method to validate a value for the property description.
247: * @param description Value to be validated for the property description.
248: * @throws ValidationException if an invalid value is passed
249: * @throws FrameworkException Indicates some system error
250: */
251: public java.lang.String validateDescription(
252: java.lang.String description) throws ValidationException,
253: FrameworkException {
254: // .//GEN-END:description_2_be
255: // Add custom code before validation//GEN-FIRST:description_1
256:
257: // .//GEN-LAST:description_1
258: // .//GEN-BEGIN:description_3_be
259: description = FieldValidator.validate(description,
260: (StringFieldMetaData) ConditionMeta.META_DESCRIPTION,
261: true);
262:
263: // Invoke the Dynamic Rules Engine
264: RulesEngine.doAllValidationsForDomainField(ConditionMeta
265: .getName(), ConditionMeta.DESCRIPTION, description,
266: this .getUOW());
267:
268: // .//GEN-END:description_3_be
269: // Add custom code after a successful validation//GEN-FIRST:description_2
270:
271: // .//GEN-LAST:description_2
272: // .//GEN-BEGIN:description_4_be
273: return description;
274: }
275:
276: // .//GEN-END:description_4_be
277: // .//GEN-BEGIN:assetArray_1_be
278: /** Returns an array of related Asset objects.
279: * @return an array of related Asset objects.
280: * @throws FrameworkException Indicates some system error
281: */
282: public Asset[] getAssetArray() throws FrameworkException {
283: UOW uow = getUOW();
284: boolean localUow = false;
285: try {
286: Asset[] output = null;
287: if (m_assetCollection == null && isDatabaseOccurence()) {
288: Criteria criteria = findAssetCriteria();
289: if (uow == null || !uow.isActive()) {
290: uow = new UOW();
291: localUow = true;
292: }
293: Collection col = uow.query(criteria);
294: m_assetCollection = new ArrayList();
295: for (Iterator itr = col.iterator(); itr.hasNext();)
296: m_assetCollection.add(itr.next());
297: }
298:
299: if (m_assetCollection != null)
300: output = (Asset[]) m_assetCollection
301: .toArray(new Asset[0]);
302: return output;
303: } finally {
304: if (localUow && uow != null)
305: uow.rollback();
306: }
307: }
308:
309: /** Returns a Criteria object for retrieving the related Asset objects.
310: * @return a Criteria object for retrieving the related Asset objects.
311: */
312: public Criteria findAssetCriteria() {
313: Criteria criteria = new Criteria();
314: criteria.setTable(AssetMeta.getName());
315: criteria.addCriteria(AssetMeta.CONDITION, getCondition());
316: // .//GEN-END:assetArray_1_be
317: // Add custom criteria//GEN-FIRST:assetArray_1
318:
319: // .//GEN-LAST:assetArray_1
320: // .//GEN-BEGIN:assetArray_2_be
321: return criteria;
322: }
323:
324: /** Creates a new Asset object and initializes the related fields.
325: * This will uncache the related Asset objects.
326: * @throws ValidationException if an invalid value is passed.
327: * @throws FrameworkException Indicates some system error
328: * @return the related Asset object with the initialized related fields.
329: */
330: public Asset newAssetObject() throws ValidationException,
331: FrameworkException {
332: m_assetCollection = null;
333: Asset asset = new Asset();
334: asset.setCondition(getCondition());
335: // .//GEN-END:assetArray_2_be
336: // Add custom code//GEN-FIRST:assetArray_2
337:
338: // .//GEN-LAST:assetArray_2
339: // .//GEN-BEGIN:assetArray_3_be
340: return asset;
341: }
342:
343: // .//GEN-END:assetArray_3_be
344: // .//GEN-BEGIN:itemArray_1_be
345: /** Returns an array of related Item objects.
346: * @return an array of related Item objects.
347: * @throws FrameworkException Indicates some system error
348: */
349: public Item[] getItemArray() throws FrameworkException {
350: UOW uow = getUOW();
351: boolean localUow = false;
352: try {
353: Item[] output = null;
354: if (m_itemCollection == null && isDatabaseOccurence()) {
355: Criteria criteria = findItemCriteria();
356: if (uow == null || !uow.isActive()) {
357: uow = new UOW();
358: localUow = true;
359: }
360: Collection col = uow.query(criteria);
361: m_itemCollection = new ArrayList();
362: for (Iterator itr = col.iterator(); itr.hasNext();)
363: m_itemCollection.add(itr.next());
364: }
365:
366: if (m_itemCollection != null)
367: output = (Item[]) m_itemCollection.toArray(new Item[0]);
368: return output;
369: } finally {
370: if (localUow && uow != null)
371: uow.rollback();
372: }
373: }
374:
375: /** Returns a Criteria object for retrieving the related Item objects.
376: * @return a Criteria object for retrieving the related Item objects.
377: */
378: public Criteria findItemCriteria() {
379: Criteria criteria = new Criteria();
380: criteria.setTable(ItemMeta.getName());
381: criteria.addCriteria(ItemMeta.CONDITION, getCondition());
382: // .//GEN-END:itemArray_1_be
383: // Add custom criteria//GEN-FIRST:itemArray_1
384:
385: // .//GEN-LAST:itemArray_1
386: // .//GEN-BEGIN:itemArray_2_be
387: return criteria;
388: }
389:
390: /** Creates a new Item object and initializes the related fields.
391: * This will uncache the related Item objects.
392: * @throws ValidationException if an invalid value is passed.
393: * @throws FrameworkException Indicates some system error
394: * @return the related Item object with the initialized related fields.
395: */
396: public Item newItemObject() throws ValidationException,
397: FrameworkException {
398: m_itemCollection = null;
399: Item item = new Item();
400: item.setCondition(getCondition());
401: // .//GEN-END:itemArray_2_be
402: // Add custom code//GEN-FIRST:itemArray_2
403:
404: // .//GEN-LAST:itemArray_2
405: // .//GEN-BEGIN:itemArray_3_be
406: return item;
407: }
408:
409: // .//GEN-END:itemArray_3_be
410: // .//GEN-BEGIN:toString_1_be
411: /** This returns the diagnostic information.
412: * @return the diagnostic information.
413: */
414: public String toString() {
415: StringBuffer buf = new StringBuffer();
416: buf.append("<Condition>");
417: buf.append("<condition>");
418: if (m_condition != null)
419: buf.append(m_condition);
420: buf.append("</condition>");
421: buf.append("<description>");
422: if (m_description != null)
423: buf.append(m_description);
424: buf.append("</description>");
425: // .//GEN-END:toString_1_be
426: // Add custom debug information//GEN-FIRST:toString_1
427:
428: // .//GEN-LAST:toString_1
429: // .//GEN-BEGIN:toString_2_be
430: buf.append(super .toString());
431: buf.append("</Condition>");
432: return buf.toString();
433: }
434:
435: // .//GEN-END:toString_2_be
436: // .//GEN-BEGIN:clone_1_be
437: /** Returns a clone of the object.
438: * @throws CloneNotSupportedException if cloning is not supported. This should never happen.
439: * @return a clone of the object.
440: */
441: public Object clone() throws CloneNotSupportedException {
442: Condition obj = (Condition) super .clone();
443: obj.m_assetCollection = null;
444: obj.m_itemCollection = null;
445: return obj;
446: }
447:
448: // .//GEN-END:clone_1_be
449: // .//GEN-BEGIN:performForeignKeyValidations_1_be
450: /** This method ensures that the modified foreign-keys are valid.
451: * @throws ApplicationExceptions if an invalid foreign key is set.
452: * @throws FrameworkException Indicates some system error
453: */
454: public void performForeignKeyValidations()
455: throws ApplicationExceptions, FrameworkException {
456: ApplicationExceptions appExps = new ApplicationExceptions();
457: if (appExps.size() > 0)
458: throw appExps;
459: }
460:
461: // .//GEN-END:performForeignKeyValidations_1_be
462: // .//GEN-BEGIN:performPreDeleteReferentialIntegrity_1_be
463: /** This method is triggered by the UOW, before adding this object to the Delete-Store.
464: * This will raise an exception if any associated/aggregated objects exist.
465: * This will cascade delete all composite objects.
466: * @throws PreDeleteFailedException if any error occurs during the process.
467: */
468: public void performPreDeleteReferentialIntegrity()
469: throws PreDeleteFailedException {
470: Asset[] assetArray = null;
471: try {
472: assetArray = getAssetArray();
473: } catch (FrameworkException e) {
474: throw new PreDeleteFailedException(null, e);
475: }
476: if (assetArray != null && assetArray.length > 0) {
477: // Stop the deletion !!
478: throw new PreDeleteFailedException(null,
479: new RelatedDomainObjectFoundException(AssetMeta
480: .getLabelToken()));
481: }
482: Item[] itemArray = null;
483: try {
484: itemArray = getItemArray();
485: } catch (FrameworkException e) {
486: throw new PreDeleteFailedException(null, e);
487: }
488: if (itemArray != null && itemArray.length > 0) {
489: // Stop the deletion !!
490: throw new PreDeleteFailedException(null,
491: new RelatedDomainObjectFoundException(ItemMeta
492: .getLabelToken()));
493: }
494: }
495: // .//GEN-END:performPreDeleteReferentialIntegrity_1_be
496: // .//GEN-BEGIN:3_be
497: /**
498: * @clientCardinality 1
499: * @supplierCardinality 0..*
500: * @clientQualifier condition
501: * @supplierQualifier condition
502: * @link association
503: */
504: /*#Asset lnkAsset;*/
505:
506: /**
507: * @clientCardinality 1
508: * @supplierCardinality 0..*
509: * @clientQualifier condition
510: * @supplierQualifier condition
511: * @link association
512: */
513: /*#Item lnkItem;*/
514:
515: // .//GEN-END:3_be
516: // All the custom code goes here//GEN-FIRST:custom
517:
518: // .//GEN-LAST:custom
519: }
|