001: // THIS SOFTWARE IS PROVIDED BY SOFTARIS PTY.LTD. AND OTHER METABOSS
002: // CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
003: // BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
004: // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTARIS PTY.LTD.
005: // OR OTHER METABOSS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
006: // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
007: // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
008: // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
009: // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
010: // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
011: // EVEN IF SOFTARIS PTY.LTD. OR OTHER METABOSS CONTRIBUTORS ARE ADVISED OF THE
012: // POSSIBILITY OF SUCH DAMAGE.
013: //
014: // Copyright 2000-2005 © Softaris Pty.Ltd. All Rights Reserved.
015: package com.metaboss.sdlctools.domains.storagemodel.impl;
016:
017: import javax.naming.Context;
018: import javax.naming.InitialContext;
019: import javax.naming.NamingException;
020:
021: import com.metaboss.enterprise.bo.BOException;
022: import com.metaboss.enterprise.bo.BOInvalidOperationForObjectException;
023: import com.metaboss.enterprise.bo.BOInvalidOperationForReadOnlyObjectException;
024: import com.metaboss.enterprise.bo.BONamingAndDirectoryServiceInvocationException;
025: import com.metaboss.enterprise.bo.BOPersistenceServiceInvocationException;
026: import com.metaboss.enterprise.ps.PSException;
027: import com.metaboss.sdlctools.domains.storagemodel.BORelationalDomainStorage;
028: import com.metaboss.sdlctools.domains.storagemodel.BORelationalReferenceTable;
029: import com.metaboss.sdlctools.domains.storagemodel.storage.PSRelationalDomainStorage;
030: import com.metaboss.sdlctools.domains.storagemodel.storage.STDomainStorageKey;
031: import com.metaboss.sdlctools.domains.storagemodel.storage.STRelationalReferenceTable;
032: import com.oldboss.framework.bo.BOTransaction;
033:
034: public class BORelationalReferenceTableImpl extends
035: BOStorageTechnologyImpl implements BORelationalReferenceTable {
036: private BOMetaBossDomainImpl mMetaBossDomainImpl = null;
037: private BORelationalDomainStorage mDomainStorage = null;
038: private String mDataTypeRef = null;
039: private STRelationalReferenceTable mRelationalReferenceTableDetails = null;
040:
041: /* Instance creator */
042: public static BORelationalReferenceTable createInstanceForExisting(
043: BOMetaBossDomainImpl pMetaBossDomainImpl,
044: BORelationalDomainStorage pDomainStorage,
045: String pDataTypeRef) throws BOException {
046: BORelationalReferenceTableImpl lImpl = new BORelationalReferenceTableImpl();
047: lImpl.setupInstanceForExisting(pMetaBossDomainImpl,
048: pDomainStorage, pDataTypeRef);
049: lImpl.setupForExisting();
050: return lImpl;
051: }
052:
053: /* Instance creator */
054: public static BORelationalReferenceTable createInstanceForNew(
055: BOTransaction pTransaction,
056: BOMetaBossDomainImpl pMetaBossDomainImpl,
057: BORelationalDomainStorage pDomainStorage,
058: String pDataTypeRef) throws BOException {
059: BORelationalReferenceTableImpl lImpl = new BORelationalReferenceTableImpl();
060: lImpl.setupInstanceForNew(pMetaBossDomainImpl, pDomainStorage,
061: pDataTypeRef);
062: lImpl.setupForNew(pTransaction);
063: return lImpl;
064: }
065:
066: /* Protect an access to this constructor */
067: protected BORelationalReferenceTableImpl() throws BOException {
068: }
069:
070: /* Setup instance representing an existing entity */
071: protected void setupInstanceForExisting(
072: BOMetaBossDomainImpl pMetaBossDomainImpl,
073: BORelationalDomainStorage pDomainStorage,
074: String pDataTypeRef) throws BOException {
075: mMetaBossDomainImpl = pMetaBossDomainImpl;
076: mDomainStorage = pDomainStorage;
077: mDataTypeRef = pDataTypeRef;
078: }
079:
080: /* Setup instance representing new entity */
081: protected void setupInstanceForNew(
082: BOMetaBossDomainImpl pMetaBossDomainImpl,
083: BORelationalDomainStorage pDomainStorage,
084: String pDataTypeRef) throws BOException {
085: mMetaBossDomainImpl = pMetaBossDomainImpl;
086: mDomainStorage = pDomainStorage;
087: mDataTypeRef = pDataTypeRef;
088: mRelationalReferenceTableDetails = new STRelationalReferenceTable();
089: mRelationalReferenceTableDetails.DataTypeRef = pDataTypeRef;
090: }
091:
092: /* Retrieves associated entity ref */
093: public String getDataTypeRef() throws BOException {
094: return mDataTypeRef;
095: }
096:
097: /* Returns relational domain storage this entity table definition belongs to */
098: public BORelationalDomainStorage getDomainStorage()
099: throws BOException {
100: return mDomainStorage;
101: }
102:
103: /* Getter for the alias of the table */
104: public String getTableAlias() throws BOException {
105: loadDetailsIfNecessary();
106: return mRelationalReferenceTableDetails.TableAlias;
107: }
108:
109: /* Getter for the suggested name of the table */
110: public String getNameSuggestion() throws BOException {
111: loadDetailsIfNecessary();
112: return mRelationalReferenceTableDetails.NameSuggestion;
113: }
114:
115: /* Getter for the overriden name of the table */
116: public String getNameOverride() throws BOException {
117: loadDetailsIfNecessary();
118: return mRelationalReferenceTableDetails.NameOverride;
119: }
120:
121: /* Getter for the suggested name of the column to store valid value */
122: public String getValueColumnNameSuggestion() throws BOException {
123: loadDetailsIfNecessary();
124: return mRelationalReferenceTableDetails.ValueColumnNameSuggestion;
125: }
126:
127: /* Getter for the overriden name of the column to store valid value */
128: public String getValueColumnNameOverride() throws BOException {
129: loadDetailsIfNecessary();
130: return mRelationalReferenceTableDetails.ValueColumnNameOverride;
131: }
132:
133: /* Getter for the suggested name of the column to store store valid value description */
134: public String getDescriptionColumnNameSuggestion()
135: throws BOException {
136: loadDetailsIfNecessary();
137: return mRelationalReferenceTableDetails.DescriptionColumnNameSuggestion;
138: }
139:
140: /* Getter for the overriden name of the column to store valid value description */
141: public String getDescriptionColumnNameOverride() throws BOException {
142: loadDetailsIfNecessary();
143: return mRelationalReferenceTableDetails.DescriptionColumnNameOverride;
144: }
145:
146: /* Getter for the weight column presence flag */
147: public boolean hasComparisonMechanismDefinition()
148: throws BOException {
149: loadDetailsIfNecessary();
150: return mRelationalReferenceTableDetails.HasComparisonMechanismDefinition;
151: }
152:
153: /* Getter for the suggested name of the column to store store valid value weight */
154: public String getWeightColumnNameSuggestion() throws BOException {
155: loadDetailsIfNecessary();
156: return mRelationalReferenceTableDetails.WeightColumnNameSuggestion;
157: }
158:
159: /* Getter for the overriden name of the column to store valid value weight */
160: public String getWeightColumnNameOverride() throws BOException {
161: loadDetailsIfNecessary();
162: return mRelationalReferenceTableDetails.WeightColumnNameOverride;
163: }
164:
165: /* Getter for the suggested name of the weight constraint */
166: public String getWeightConstraintNameSuggestion()
167: throws BOException {
168: loadDetailsIfNecessary();
169: return mRelationalReferenceTableDetails.WeightConstraintNameSuggestion;
170: }
171:
172: /* Getter for the overriden name of the weight constraint */
173: public String getWeightConstraintNameOverride() throws BOException {
174: loadDetailsIfNecessary();
175: return mRelationalReferenceTableDetails.WeightConstraintNameOverride;
176: }
177:
178: /* Getter for the name of the primary key constraint */
179: public String getPrimaryKeyConstraintNameSuggestion()
180: throws BOException {
181: loadDetailsIfNecessary();
182: return mRelationalReferenceTableDetails.PrimaryKeyConstraintNameSuggestion;
183: }
184:
185: /** Getter for the name of the primary key constraint */
186: public String getPrimaryKeyConstraintNameOverride()
187: throws BOException {
188: loadDetailsIfNecessary();
189: return mRelationalReferenceTableDetails.PrimaryKeyConstraintNameOverride;
190: }
191:
192: /* Setter for the alias of the table */
193: public void setTableAlias(String pName) throws BOException {
194: if (!isBeingEdited())
195: throw new BOInvalidOperationForReadOnlyObjectException();
196: mRelationalReferenceTableDetails.TableAlias = pName;
197: }
198:
199: /* Setter for the name of the table */
200: public void setNameSuggestion(String pName) throws BOException {
201: if (!isBeingEdited())
202: throw new BOInvalidOperationForReadOnlyObjectException();
203: mRelationalReferenceTableDetails.NameSuggestion = pName;
204: }
205:
206: /* Setter for the name of the column to store store valid value */
207: public void setValueColumnNameSuggestion(String pName)
208: throws BOException {
209: if (!isBeingEdited())
210: throw new BOInvalidOperationForReadOnlyObjectException();
211: mRelationalReferenceTableDetails.ValueColumnNameSuggestion = pName;
212: }
213:
214: /* Setter for the name of the column to store valid value description */
215: public void setDescriptionColumnNameSuggestion(String pName)
216: throws BOException {
217: if (!isBeingEdited())
218: throw new BOInvalidOperationForReadOnlyObjectException();
219: mRelationalReferenceTableDetails.DescriptionColumnNameSuggestion = pName;
220: }
221:
222: /* Setter for the weight column presence flag */
223: public void setHasComparisonMechanismDefinition(boolean pHasColumn)
224: throws BOException {
225: if (!isBeingEdited())
226: throw new BOInvalidOperationForReadOnlyObjectException();
227: if (mRelationalReferenceTableDetails.HasComparisonMechanismDefinition != pHasColumn) {
228: mRelationalReferenceTableDetails.HasComparisonMechanismDefinition = pHasColumn;
229: if (!mRelationalReferenceTableDetails.HasComparisonMechanismDefinition) {
230: mRelationalReferenceTableDetails.WeightColumnNameSuggestion = null;
231: mRelationalReferenceTableDetails.WeightColumnNameOverride = null;
232: mRelationalReferenceTableDetails.WeightConstraintNameSuggestion = null;
233: mRelationalReferenceTableDetails.WeightConstraintNameOverride = null;
234: } else {
235: mRelationalReferenceTableDetails.WeightColumnNameSuggestion = "";
236: mRelationalReferenceTableDetails.WeightColumnNameOverride = "";
237: mRelationalReferenceTableDetails.WeightConstraintNameSuggestion = "";
238: mRelationalReferenceTableDetails.WeightConstraintNameOverride = "";
239: }
240: }
241: }
242:
243: /* Setter for the name of the column to store valid value weight */
244: public void setWeightColumnNameSuggestion(String pName)
245: throws BOException {
246: if (!isBeingEdited())
247: throw new BOInvalidOperationForReadOnlyObjectException();
248: if (!mRelationalReferenceTableDetails.HasComparisonMechanismDefinition)
249: throw new BOInvalidOperationForObjectException(
250: "Comparabe weight column definition is absent in reference table definition (possibly because datatype is not comparable), column name suggestion can not be set. StorageTechnologyRef: "
251: + mDomainStorage.getStorageTechnology()
252: .getRef()
253: + " DomainRef: "
254: + mDomainStorage.getDomainRef()
255: + " DataTypeRef: " + mDataTypeRef);
256: mRelationalReferenceTableDetails.WeightColumnNameSuggestion = pName;
257: }
258:
259: /* Setter for the name of the weight constraint */
260: public void setWeightConstraintNameSuggestion(String pName)
261: throws BOException {
262: if (!isBeingEdited())
263: throw new BOInvalidOperationForReadOnlyObjectException();
264: if (!mRelationalReferenceTableDetails.HasComparisonMechanismDefinition)
265: throw new BOInvalidOperationForObjectException(
266: "Comparabe weight column definition is absent in reference table definition (possibly because datatype is not comparable), constraint name suggestion can not be set. StorageTechnologyRef: "
267: + mDomainStorage.getStorageTechnology()
268: .getRef()
269: + " DomainRef: "
270: + mDomainStorage.getDomainRef()
271: + " DataTypeRef: " + mDataTypeRef);
272: mRelationalReferenceTableDetails.WeightConstraintNameSuggestion = pName;
273: }
274:
275: /* Setter for the name of the primary key constraint */
276: public void setPrimaryKeyConstraintNameSuggestion(String pName)
277: throws BOException {
278: if (!isBeingEdited())
279: throw new BOInvalidOperationForReadOnlyObjectException();
280: mRelationalReferenceTableDetails.PrimaryKeyConstraintNameSuggestion = pName;
281: }
282:
283: /* Overridable method. Called when existing object enters being edited stage */
284: protected void onBeginEdit() throws BOException {
285: loadDetailsIfNecessary();
286: }
287:
288: /* Encapsulates commit action by this object */
289: protected void onCommitDeletion() throws BOException {
290: try {
291: Context ctx = new InitialContext();
292: PSRelationalDomainStorage lPs = (PSRelationalDomainStorage) ctx
293: .lookup(PSRelationalDomainStorage.COMPONENT_URL);
294: STDomainStorageKey lKey = new STDomainStorageKey();
295: lKey.StorageTechnologyRef = mDomainStorage
296: .getStorageTechnology().getRef();
297: lKey.DomainRef = mDomainStorage.getDomainRef();
298: lPs.deleteReferenceTable(lKey, mDataTypeRef);
299: } catch (NamingException e) {
300: throw new BONamingAndDirectoryServiceInvocationException(
301: "", e);
302: } catch (PSException e) {
303: throw new BOPersistenceServiceInvocationException("", e);
304: }
305: }
306:
307: /* Encapsulates commit action by this object */
308: protected void onCommitUpdate() throws BOException {
309: try {
310: Context ctx = new InitialContext();
311: PSRelationalDomainStorage lPs = (PSRelationalDomainStorage) ctx
312: .lookup(PSRelationalDomainStorage.COMPONENT_URL);
313: STDomainStorageKey lKey = new STDomainStorageKey();
314: lKey.StorageTechnologyRef = mDomainStorage
315: .getStorageTechnology().getRef();
316: lKey.DomainRef = mDomainStorage.getDomainRef();
317: lPs.updateReferenceTable(lKey,
318: mRelationalReferenceTableDetails);
319: } catch (NamingException e) {
320: throw new BONamingAndDirectoryServiceInvocationException(
321: "", e);
322: } catch (PSException e) {
323: throw new BOPersistenceServiceInvocationException("", e);
324: }
325: }
326:
327: /* Encapsulates commit action by this object */
328: protected void onCommitCreation() throws BOException {
329: try {
330: Context ctx = new InitialContext();
331: PSRelationalDomainStorage lPs = (PSRelationalDomainStorage) ctx
332: .lookup(PSRelationalDomainStorage.COMPONENT_URL);
333: STDomainStorageKey lKey = new STDomainStorageKey();
334: lKey.StorageTechnologyRef = mDomainStorage
335: .getStorageTechnology().getRef();
336: lKey.DomainRef = mDomainStorage.getDomainRef();
337: lPs.insertReferenceTable(lKey,
338: mRelationalReferenceTableDetails);
339: } catch (NamingException e) {
340: throw new BONamingAndDirectoryServiceInvocationException(
341: "", e);
342: } catch (PSException e) {
343: throw new BOPersistenceServiceInvocationException("", e);
344: }
345: }
346:
347: private void loadDetailsIfNecessary() throws BOException {
348: if (mRelationalReferenceTableDetails == null) {
349: try {
350: // Get the instance of the enterprise ps home via jndi
351: Context ctx = new InitialContext();
352: PSRelationalDomainStorage lPs = (PSRelationalDomainStorage) ctx
353: .lookup(PSRelationalDomainStorage.COMPONENT_URL);
354: STDomainStorageKey lKey = new STDomainStorageKey();
355: lKey.StorageTechnologyRef = mDomainStorage
356: .getStorageTechnology().getRef();
357: lKey.DomainRef = mDomainStorage.getDomainRef();
358: mRelationalReferenceTableDetails = lPs
359: .getReferenceTable(lKey, mDataTypeRef);
360: if (mRelationalReferenceTableDetails == null)
361: throw new BOException(
362: "Reference Table Definition not found. StorageTechnologyRef: "
363: + getRef());
364: } catch (NamingException e) {
365: throw new BONamingAndDirectoryServiceInvocationException(
366: "", e);
367: } catch (PSException e) {
368: throw new BOPersistenceServiceInvocationException(
369: "Exception caught during loading of Relational Storage Technology details. StorageTechnologyRef: "
370: + getRef(), e);
371: }
372: }
373: }
374: }
|