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.BORelationalEntityTable;
029: import com.metaboss.sdlctools.domains.storagemodel.BORelationalEntityTableAssociationRoleList;
030: import com.metaboss.sdlctools.domains.storagemodel.BORelationalEntityTableAttributeList;
031: import com.metaboss.sdlctools.domains.storagemodel.storage.PSRelationalDomainStorage;
032: import com.metaboss.sdlctools.domains.storagemodel.storage.STDomainStorageKey;
033: import com.metaboss.sdlctools.domains.storagemodel.storage.STRelationalEntityTable;
034: import com.oldboss.framework.bo.BOTransaction;
035: import com.oldboss.framework.bo.impl.BOObjectImpl;
036:
037: public class BORelationalEntityTableImpl extends BOObjectImpl implements
038: BORelationalEntityTable {
039: private BOMetaBossDomainImpl mMetaBossDomainImpl = null;
040: private BORelationalDomainStorage mDomainStorage = null;
041: private String mEntityRef = null;
042: private STRelationalEntityTable mRelationalEntityTableDetails = null;
043:
044: /* Instance creator */
045: public static BORelationalEntityTable createInstanceForExisting(
046: BOMetaBossDomainImpl pMetaBossDomainImpl,
047: BORelationalDomainStorage pDomainStorage, String pEntityRef)
048: throws BOException {
049: BORelationalEntityTableImpl lImpl = new BORelationalEntityTableImpl();
050: lImpl.setupInstanceForExisting(pMetaBossDomainImpl,
051: pDomainStorage, pEntityRef);
052: lImpl.setupForExisting();
053: return lImpl;
054: }
055:
056: /* Instance creator */
057: public static BORelationalEntityTable createInstanceForNew(
058: BOTransaction pTransaction,
059: BOMetaBossDomainImpl pMetaBossDomainImpl,
060: BORelationalDomainStorage pDomainStorage, String pEntityRef)
061: throws BOException {
062: BORelationalEntityTableImpl lImpl = new BORelationalEntityTableImpl();
063: lImpl.setupInstanceForNew(pMetaBossDomainImpl, pDomainStorage,
064: pEntityRef);
065: lImpl.setupForNew(pTransaction);
066: return lImpl;
067: }
068:
069: /* Protect an access to this constructor */
070: protected BORelationalEntityTableImpl() throws BOException {
071: }
072:
073: /* Setup instance representing an existing entity */
074: protected void setupInstanceForExisting(
075: BOMetaBossDomainImpl pMetaBossDomainImpl,
076: BORelationalDomainStorage pDomainStorage, String pEntityRef)
077: throws BOException {
078: mMetaBossDomainImpl = pMetaBossDomainImpl;
079: mDomainStorage = pDomainStorage;
080: mEntityRef = pEntityRef;
081: }
082:
083: /* Setup instance representing new entity */
084: protected void setupInstanceForNew(
085: BOMetaBossDomainImpl pMetaBossDomainImpl,
086: BORelationalDomainStorage pDomainStorage, String pEntityRef)
087: throws BOException {
088: mMetaBossDomainImpl = pMetaBossDomainImpl;
089: mDomainStorage = pDomainStorage;
090: mEntityRef = pEntityRef;
091: mRelationalEntityTableDetails = new STRelationalEntityTable();
092: mRelationalEntityTableDetails.EntityRef = pEntityRef;
093: }
094:
095: /* Retrieves associated entity ref */
096: public String getEntityRef() throws BOException {
097: return mEntityRef;
098: }
099:
100: /* Returns relational domain storage this entity table definition belongs to */
101: public BORelationalDomainStorage getDomainStorage()
102: throws BOException {
103: return mDomainStorage;
104: }
105:
106: /* Getter for the list of table attributes */
107: public BORelationalEntityTableAttributeList getTableAttributes()
108: throws BOException {
109: return BORelationalEntityTableAttributeListImpl
110: .createInstanceForExisting(mMetaBossDomainImpl,
111: mDomainStorage, this );
112: }
113:
114: /* Getter for the list of table association role attributes */
115: public BORelationalEntityTableAssociationRoleList getTableAssociationRoles()
116: throws BOException {
117: return BORelationalEntityTableAssociationRoleListImpl
118: .createInstanceForExisting(mMetaBossDomainImpl, this );
119: }
120:
121: /* Getter for the alias of the table */
122: public String getTableAlias() throws BOException {
123: loadDetailsIfNecessary();
124: return mRelationalEntityTableDetails.TableAlias;
125: }
126:
127: /* Getter for the suggested name of the table */
128: public String getNameSuggestion() throws BOException {
129: loadDetailsIfNecessary();
130: return mRelationalEntityTableDetails.NameSuggestion;
131: }
132:
133: /* Getter for the overriden name of the table */
134: public String getNameOverride() throws BOException {
135: loadDetailsIfNecessary();
136: return mRelationalEntityTableDetails.NameOverride;
137: }
138:
139: /* Getter for the suggested name of the column to store entity instance id */
140: public String getInstanceIdColumnNameSuggestion()
141: throws BOException {
142: loadDetailsIfNecessary();
143: return mRelationalEntityTableDetails.InstanceIdColumnNameSuggestion;
144: }
145:
146: /* Getter for the overriden name of the column to store entity instance id */
147: public String getInstanceIdColumnNameOverride() throws BOException {
148: loadDetailsIfNecessary();
149: return mRelationalEntityTableDetails.InstanceIdColumnNameOverride;
150: }
151:
152: /* Getter for the version id column presence flag */
153: public boolean hasVersionIdColumnNameDefinition()
154: throws BOException {
155: loadDetailsIfNecessary();
156: return mRelationalEntityTableDetails.HasVersionIdColumnNameDefinition;
157: }
158:
159: /* Getter for the name of the column to store entity version id.
160: * Note that table does not always has a version id column - this depends on the model */
161: public String getVersionIdColumnNameSuggestion() throws BOException {
162: loadDetailsIfNecessary();
163: return mRelationalEntityTableDetails.VersionIdColumnNameSuggestion;
164: }
165:
166: /* Getter for the name of the column to store entity version id.
167: * Note that table does not always has a version id column - this depends on the model */
168: public String getVersionIdColumnNameOverride() throws BOException {
169: loadDetailsIfNecessary();
170: return mRelationalEntityTableDetails.VersionIdColumnNameOverride;
171: }
172:
173: /* Getter for the state column presence flag */
174: public boolean hasStateColumnDefinition() throws BOException {
175: loadDetailsIfNecessary();
176: return mRelationalEntityTableDetails.HasStateColumnDefinition;
177: }
178:
179: /* Getter for the name of the column to store entity state
180: * Note that table does not always has a state column - this depends on the model */
181: public String getStateColumnNameSuggestion() throws BOException {
182: loadDetailsIfNecessary();
183: return mRelationalEntityTableDetails.StateColumnNameSuggestion;
184: }
185:
186: /* Getter for the name of the column to store entity state
187: * Note that table does not always has a state column - this depends on the model */
188: public String getStateColumnNameOverride() throws BOException {
189: loadDetailsIfNecessary();
190: return mRelationalEntityTableDetails.StateColumnNameOverride;
191: }
192:
193: /* Getter for the suggested name of the referential constraint of the entity state
194: * Note that table does not always has a state column - this depends on the model */
195: public String getStateRefConstraintNameSuggestion()
196: throws BOException {
197: loadDetailsIfNecessary();
198: return mRelationalEntityTableDetails.StateRefConstraintNameSuggestion;
199: }
200:
201: /* Getter for the overridden name of the referential constraint of the entity state
202: * Note that table does not always has a state column - this depends on the model */
203: public String getStateRefConstraintNameOverride()
204: throws BOException {
205: loadDetailsIfNecessary();
206: return mRelationalEntityTableDetails.StateRefConstraintNameOverride;
207: }
208:
209: /** Getter for the name of the primary key constraint */
210: public String getPrimaryKeyConstraintNameSuggestion()
211: throws BOException {
212: loadDetailsIfNecessary();
213: return mRelationalEntityTableDetails.PrimaryKeyConstraintNameSuggestion;
214: }
215:
216: /** Getter for the name of the primary key constraint */
217: public String getPrimaryKeyConstraintNameOverride()
218: throws BOException {
219: loadDetailsIfNecessary();
220: return mRelationalEntityTableDetails.PrimaryKeyConstraintNameOverride;
221: }
222:
223: /** Getter for the natural primary key constraint name definition presence flag */
224: public boolean hasNaturalPrimaryKeyConstraintNameDefinition()
225: throws BOException {
226: loadDetailsIfNecessary();
227: return mRelationalEntityTableDetails.HasNaturalPrimaryKeyConstraintNameDefinition;
228: }
229:
230: /** Getter for the name of the natural primary key constraint
231: * Note that table does not always has a natural primary key - this depends on the model */
232: public String getNaturalPrimaryKeyConstraintNameSuggestion()
233: throws BOException {
234: loadDetailsIfNecessary();
235: return mRelationalEntityTableDetails.NaturalPrimaryKeyConstraintNameSuggestion;
236: }
237:
238: /** Getter for the name of the natural primary key constraint
239: * Note that table does not always has natural primary key constraint - this depends on the model */
240: public String getNaturalPrimaryKeyConstraintNameOverride()
241: throws BOException {
242: loadDetailsIfNecessary();
243: return mRelationalEntityTableDetails.NaturalPrimaryKeyConstraintNameOverride;
244: }
245:
246: /* Setter for the name of the table */
247: public void setNameSuggestion(String pName) throws BOException {
248: if (!isBeingEdited())
249: throw new BOInvalidOperationForReadOnlyObjectException();
250: mRelationalEntityTableDetails.NameSuggestion = pName;
251: }
252:
253: /* Setter for the alias of the table */
254: public void setTableAlias(String pName) throws BOException {
255: if (!isBeingEdited())
256: throw new BOInvalidOperationForReadOnlyObjectException();
257: mRelationalEntityTableDetails.TableAlias = pName;
258: }
259:
260: /* Setter for the name of the column to store entity instance id */
261: public void setInstanceIdColumnNameSuggestion(String pName)
262: throws BOException {
263: if (!isBeingEdited())
264: throw new BOInvalidOperationForReadOnlyObjectException();
265: mRelationalEntityTableDetails.InstanceIdColumnNameSuggestion = pName;
266: }
267:
268: /* Setter for the version id column presence flag */
269: public void setHasVersionIdColumnNameDefinition(boolean pHasColumn)
270: throws BOException {
271: if (!isBeingEdited())
272: throw new BOInvalidOperationForReadOnlyObjectException();
273: if (mRelationalEntityTableDetails.HasVersionIdColumnNameDefinition != pHasColumn) {
274: mRelationalEntityTableDetails.HasVersionIdColumnNameDefinition = pHasColumn;
275: if (!mRelationalEntityTableDetails.HasVersionIdColumnNameDefinition) {
276: mRelationalEntityTableDetails.VersionIdColumnNameSuggestion = null;
277: mRelationalEntityTableDetails.VersionIdColumnNameOverride = null;
278: } else {
279: mRelationalEntityTableDetails.VersionIdColumnNameSuggestion = "";
280: mRelationalEntityTableDetails.VersionIdColumnNameOverride = "";
281: }
282: }
283: }
284:
285: /** Setter for the name of the column to store entity version id.
286: * Note that table does not always has a version id column - this depends on the model */
287: public void setVersionIdColumnNameSuggestion(String pName)
288: throws BOException {
289: if (!isBeingEdited())
290: throw new BOInvalidOperationForReadOnlyObjectException();
291: if (!mRelationalEntityTableDetails.HasVersionIdColumnNameDefinition)
292: throw new BOInvalidOperationForObjectException(
293: "Version Id column definition is absent in entity table definition (possibly because attribute is not in the entity), suggestion can not be set. StorageTechnologyRef: "
294: + mDomainStorage.getStorageTechnology()
295: .getRef()
296: + " DomainRef: "
297: + mDomainStorage.getDomainRef()
298: + " EntityRef: " + mEntityRef);
299: mRelationalEntityTableDetails.VersionIdColumnNameSuggestion = pName;
300: }
301:
302: /** Setter for the state column presence flag */
303: public void setHasStateColumnDefinition(boolean pHasColumn)
304: throws BOException {
305: if (!isBeingEdited())
306: throw new BOInvalidOperationForReadOnlyObjectException();
307: if (mRelationalEntityTableDetails.HasStateColumnDefinition != pHasColumn) {
308: mRelationalEntityTableDetails.HasStateColumnDefinition = pHasColumn;
309: if (!mRelationalEntityTableDetails.HasStateColumnDefinition) {
310: mRelationalEntityTableDetails.StateColumnNameSuggestion = null;
311: mRelationalEntityTableDetails.StateColumnNameOverride = null;
312: } else {
313: mRelationalEntityTableDetails.StateColumnNameSuggestion = "";
314: mRelationalEntityTableDetails.StateColumnNameOverride = "";
315: }
316: }
317: }
318:
319: /** Setter for the name of the column to store entity state
320: * Note that table does not always has a state column - this depends on the model */
321: public void setStateColumnNameSuggestion(String pName)
322: throws BOException {
323: if (!isBeingEdited())
324: throw new BOInvalidOperationForReadOnlyObjectException();
325: if (!mRelationalEntityTableDetails.HasStateColumnDefinition)
326: throw new BOInvalidOperationForObjectException(
327: "State column definition is absent in entity table definition (possibly because entity does not have attached state machine), column name suggestion can not be set. StorageTechnologyRef: "
328: + mDomainStorage.getStorageTechnology()
329: .getRef()
330: + " DomainRef: "
331: + mDomainStorage.getDomainRef()
332: + " EntityRef: " + mEntityRef);
333: mRelationalEntityTableDetails.StateColumnNameSuggestion = pName;
334: }
335:
336: /** Setter for the name of the constraint to look after state column referential integrity
337: * Note that table does not always has a state column - this depends on the model */
338: public void setStateRefConstraintNameSuggestion(String pName)
339: throws BOException {
340: if (!isBeingEdited())
341: throw new BOInvalidOperationForReadOnlyObjectException();
342: if (!mRelationalEntityTableDetails.HasStateColumnDefinition)
343: throw new BOInvalidOperationForObjectException(
344: "State column definition is absent in entity table definition (possibly because entity does not have attached state machine), ref constraint suggestion can not be set. StorageTechnologyRef: "
345: + mDomainStorage.getStorageTechnology()
346: .getRef()
347: + " DomainRef: "
348: + mDomainStorage.getDomainRef()
349: + " EntityRef: " + mEntityRef);
350: mRelationalEntityTableDetails.StateRefConstraintNameSuggestion = pName;
351: }
352:
353: /* Setter for the name of the primary key constraint */
354: public void setPrimaryKeyConstraintNameSuggestion(String pName)
355: throws BOException {
356: if (!isBeingEdited())
357: throw new BOInvalidOperationForReadOnlyObjectException();
358: mRelationalEntityTableDetails.PrimaryKeyConstraintNameSuggestion = pName;
359: }
360:
361: /* Setter for the natural primary key constraint presence flag */
362: public void setHasNaturalPrimaryKeyConstraintNameDefinition(
363: boolean pHasDefinition) throws BOException {
364: if (!isBeingEdited())
365: throw new BOInvalidOperationForReadOnlyObjectException();
366: if (mRelationalEntityTableDetails.HasNaturalPrimaryKeyConstraintNameDefinition != pHasDefinition) {
367: mRelationalEntityTableDetails.HasNaturalPrimaryKeyConstraintNameDefinition = pHasDefinition;
368: if (!mRelationalEntityTableDetails.HasNaturalPrimaryKeyConstraintNameDefinition) {
369: mRelationalEntityTableDetails.NaturalPrimaryKeyConstraintNameSuggestion = null;
370: mRelationalEntityTableDetails.NaturalPrimaryKeyConstraintNameOverride = null;
371: } else {
372: mRelationalEntityTableDetails.NaturalPrimaryKeyConstraintNameSuggestion = "";
373: mRelationalEntityTableDetails.NaturalPrimaryKeyConstraintNameOverride = "";
374: }
375: }
376: }
377:
378: /* Setter for the name of the natural primary key constraint
379: * Note that table does not always has a natural primary key constraint - this depends on the model */
380: public void setNaturalPrimaryKeyConstraintNameSuggestion(
381: String pName) throws BOException {
382: if (!isBeingEdited())
383: throw new BOInvalidOperationForReadOnlyObjectException();
384: if (!mRelationalEntityTableDetails.HasNaturalPrimaryKeyConstraintNameDefinition)
385: throw new BOInvalidOperationForObjectException(
386: "Natural primary key definition is absent in entity table definition (possibly because it is not defined in the model), suggestion can not be set. StorageTechnologyRef: "
387: + mDomainStorage.getStorageTechnology()
388: .getRef()
389: + " DomainRef: "
390: + mDomainStorage.getDomainRef()
391: + " EntityRef: " + mEntityRef);
392: mRelationalEntityTableDetails.NaturalPrimaryKeyConstraintNameSuggestion = pName;
393: }
394:
395: /* Overridable method. Called when existing object enters being edited stage */
396: protected void onBeginEdit() throws BOException {
397: loadDetailsIfNecessary();
398: }
399:
400: /* Encapsulates commit action by this object */
401: protected void onCommitDeletion() throws BOException {
402: try {
403: Context ctx = new InitialContext();
404: PSRelationalDomainStorage lPs = (PSRelationalDomainStorage) ctx
405: .lookup(PSRelationalDomainStorage.COMPONENT_URL);
406: STDomainStorageKey lKey = new STDomainStorageKey();
407: lKey.StorageTechnologyRef = mDomainStorage
408: .getStorageTechnology().getRef();
409: lKey.DomainRef = mDomainStorage.getDomainRef();
410: lPs.deleteEntityTable(lKey, mEntityRef);
411: } catch (NamingException e) {
412: throw new BONamingAndDirectoryServiceInvocationException(
413: "", e);
414: } catch (PSException e) {
415: throw new BOPersistenceServiceInvocationException("", e);
416: }
417: }
418:
419: /* Encapsulates commit action by this object */
420: protected void onCommitUpdate() throws BOException {
421: try {
422: Context ctx = new InitialContext();
423: PSRelationalDomainStorage lPs = (PSRelationalDomainStorage) ctx
424: .lookup(PSRelationalDomainStorage.COMPONENT_URL);
425: STDomainStorageKey lKey = new STDomainStorageKey();
426: lKey.StorageTechnologyRef = mDomainStorage
427: .getStorageTechnology().getRef();
428: lKey.DomainRef = mDomainStorage.getDomainRef();
429: lPs.updateEntityTable(lKey, mRelationalEntityTableDetails);
430: } catch (NamingException e) {
431: throw new BONamingAndDirectoryServiceInvocationException(
432: "", e);
433: } catch (PSException e) {
434: throw new BOPersistenceServiceInvocationException("", e);
435: }
436: }
437:
438: /* Encapsulates commit action by this object */
439: protected void onCommitCreation() throws BOException {
440: try {
441: Context ctx = new InitialContext();
442: PSRelationalDomainStorage lPs = (PSRelationalDomainStorage) ctx
443: .lookup(PSRelationalDomainStorage.COMPONENT_URL);
444: STDomainStorageKey lKey = new STDomainStorageKey();
445: lKey.StorageTechnologyRef = mDomainStorage
446: .getStorageTechnology().getRef();
447: lKey.DomainRef = mDomainStorage.getDomainRef();
448: lPs.insertEntityTable(lKey, mRelationalEntityTableDetails);
449: } catch (NamingException e) {
450: throw new BONamingAndDirectoryServiceInvocationException(
451: "", e);
452: } catch (PSException e) {
453: throw new BOPersistenceServiceInvocationException("", e);
454: }
455: }
456:
457: private void loadDetailsIfNecessary() throws BOException {
458: if (mRelationalEntityTableDetails == null) {
459: try {
460: // Get the instance of the enterprise ps home via jndi
461: Context ctx = new InitialContext();
462: PSRelationalDomainStorage lPs = (PSRelationalDomainStorage) ctx
463: .lookup(PSRelationalDomainStorage.COMPONENT_URL);
464: STDomainStorageKey lKey = new STDomainStorageKey();
465: lKey.StorageTechnologyRef = mDomainStorage
466: .getStorageTechnology().getRef();
467: lKey.DomainRef = mDomainStorage.getDomainRef();
468: mRelationalEntityTableDetails = lPs.getEntityTable(
469: lKey, mEntityRef);
470: if (mRelationalEntityTableDetails == null)
471: throw new BOException(
472: "Entity Table Definition not found. StorageTechnologyRef: "
473: + mDomainStorage
474: .getStorageTechnology()
475: .getRef());
476: } catch (NamingException e) {
477: throw new BONamingAndDirectoryServiceInvocationException(
478: "", e);
479: } catch (PSException e) {
480: throw new BOPersistenceServiceInvocationException(
481: "Exception caught during loading of Relational Storage Technology details. StorageTechnologyRef: "
482: + mDomainStorage.getStorageTechnology()
483: .getRef(), e);
484: }
485: }
486: }
487: }
|