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.BOInvalidOperationForReadOnlyObjectException;
023: import com.metaboss.enterprise.bo.BONamingAndDirectoryServiceInvocationException;
024: import com.metaboss.enterprise.bo.BOPersistenceServiceInvocationException;
025: import com.metaboss.enterprise.ps.PSException;
026: import com.metaboss.sdlctools.domains.storagemodel.BORelationalEntityTable;
027: import com.metaboss.sdlctools.domains.storagemodel.BORelationalEntityTableAssociationRole;
028: import com.metaboss.sdlctools.domains.storagemodel.storage.PSRelationalDomainStorage;
029: import com.metaboss.sdlctools.domains.storagemodel.storage.STDomainStorageKey;
030: import com.metaboss.sdlctools.domains.storagemodel.storage.STRelationalEntityTableAssociationRole;
031: import com.oldboss.framework.bo.BOTransaction;
032: import com.oldboss.framework.bo.impl.BOObjectImpl;
033:
034: public class BORelationalEntityTableAssociationRoleImpl extends
035: BOObjectImpl implements BORelationalEntityTableAssociationRole {
036: private BOMetaBossDomainImpl mMetaBossDomainImpl = null;
037: private BORelationalEntityTable mEntityTable = null;
038: private String mAssociationRoleRef = null;
039: private STRelationalEntityTableAssociationRole mRelationalEntityTableAssociationRoleDetails = null;
040:
041: /* Instance creator */
042: public static BORelationalEntityTableAssociationRole createInstanceForExisting(
043: BOMetaBossDomainImpl pMetaBossDomainImpl,
044: BORelationalEntityTable pEntityTable,
045: String pAssociationRoleRef) throws BOException {
046: BORelationalEntityTableAssociationRoleImpl lImpl = new BORelationalEntityTableAssociationRoleImpl();
047: lImpl.setupInstanceForExisting(pMetaBossDomainImpl,
048: pEntityTable, pAssociationRoleRef);
049: lImpl.setupForExisting();
050: return lImpl;
051: }
052:
053: /* Instance creator */
054: public static BORelationalEntityTableAssociationRole createInstanceForNew(
055: BOTransaction pTransaction,
056: BOMetaBossDomainImpl pMetaBossDomainImpl,
057: BORelationalEntityTable pEntityTable,
058: String pAssociationRoleRef) throws BOException {
059: BORelationalEntityTableAssociationRoleImpl lImpl = new BORelationalEntityTableAssociationRoleImpl();
060: lImpl.setupInstanceForNew(pMetaBossDomainImpl, pEntityTable,
061: pAssociationRoleRef);
062: lImpl.setupForNew(pTransaction);
063: return lImpl;
064: }
065:
066: /* Protect an access to this constructor */
067: protected BORelationalEntityTableAssociationRoleImpl()
068: throws BOException {
069: }
070:
071: /* Setup instance representing an existing entity */
072: protected void setupInstanceForExisting(
073: BOMetaBossDomainImpl pMetaBossDomainImpl,
074: BORelationalEntityTable pEntityTable,
075: String pAssociationRoleRef) throws BOException {
076: mMetaBossDomainImpl = pMetaBossDomainImpl;
077: mEntityTable = pEntityTable;
078: mAssociationRoleRef = pAssociationRoleRef;
079: }
080:
081: /* Setup instance representing new entity */
082: protected void setupInstanceForNew(
083: BOMetaBossDomainImpl pMetaBossDomainImpl,
084: BORelationalEntityTable pEntityTable,
085: String pAssociationRoleRef) throws BOException {
086: mMetaBossDomainImpl = pMetaBossDomainImpl;
087: mEntityTable = pEntityTable;
088: mAssociationRoleRef = pAssociationRoleRef;
089: mRelationalEntityTableAssociationRoleDetails = new STRelationalEntityTableAssociationRole();
090: mRelationalEntityTableAssociationRoleDetails.AssociationRoleRef = pAssociationRoleRef;
091: }
092:
093: /* Retrieves associated attribute ref */
094: public String getAssociationRoleRef() throws BOException {
095: return mAssociationRoleRef;
096: }
097:
098: /* Getter for the suggested name of the column */
099: public String getInstanceIdColumnNameSuggestion()
100: throws BOException {
101: loadDetailsIfNecessary();
102: return mRelationalEntityTableAssociationRoleDetails.InstanceIdColumnNameSuggestion;
103: }
104:
105: /* Getter for the overriden name of the column */
106: public String getInstanceIdColumnNameOverride() throws BOException {
107: loadDetailsIfNecessary();
108: return mRelationalEntityTableAssociationRoleDetails.InstanceIdColumnNameOverride;
109: }
110:
111: /* Getter for the suggested name of the referential constraint */
112: public String getReferentialConstraintNameSuggestion()
113: throws BOException {
114: loadDetailsIfNecessary();
115: return mRelationalEntityTableAssociationRoleDetails.ReferentialConstraintNameSuggestion;
116: }
117:
118: /* Getter for the overriden name of the referential constraint */
119: public String getReferentialConstraintNameOverride()
120: throws BOException {
121: loadDetailsIfNecessary();
122: return mRelationalEntityTableAssociationRoleDetails.ReferentialConstraintNameOverride;
123: }
124:
125: /* Setter for the suggested name of the column */
126: public void setInstanceIdColumnNameSuggestion(String pName)
127: throws BOException {
128: if (!isBeingEdited())
129: throw new BOInvalidOperationForReadOnlyObjectException();
130: mRelationalEntityTableAssociationRoleDetails.InstanceIdColumnNameSuggestion = pName;
131: }
132:
133: /* Setter for the suggested name of the referential constraint */
134: public void setReferentialConstraintNameSuggestion(String pName)
135: throws BOException {
136: if (!isBeingEdited())
137: throw new BOInvalidOperationForReadOnlyObjectException();
138: mRelationalEntityTableAssociationRoleDetails.ReferentialConstraintNameSuggestion = pName;
139: }
140:
141: /* Overridable method. Called when existing object enters being edited stage */
142: protected void onBeginEdit() throws BOException {
143: loadDetailsIfNecessary();
144: }
145:
146: /* Encapsulates commit action by this object */
147: protected void onCommitUpdate() throws BOException {
148: try {
149: Context ctx = new InitialContext();
150: PSRelationalDomainStorage lPs = (PSRelationalDomainStorage) ctx
151: .lookup(PSRelationalDomainStorage.COMPONENT_URL);
152: STDomainStorageKey lKey = new STDomainStorageKey();
153: lKey.StorageTechnologyRef = mEntityTable.getDomainStorage()
154: .getStorageTechnology().getRef();
155: lKey.DomainRef = mEntityTable.getDomainStorage()
156: .getDomainRef();
157: lPs.updateEntityTableAssociationRole(lKey, mEntityTable
158: .getEntityRef(),
159: mRelationalEntityTableAssociationRoleDetails);
160: } catch (NamingException e) {
161: throw new BONamingAndDirectoryServiceInvocationException(
162: "", e);
163: } catch (PSException e) {
164: throw new BOPersistenceServiceInvocationException("", e);
165: }
166: }
167:
168: /* Encapsulates commit action by this object */
169: protected void onCommitDeletion() throws BOException {
170: try {
171: Context ctx = new InitialContext();
172: PSRelationalDomainStorage lPs = (PSRelationalDomainStorage) ctx
173: .lookup(PSRelationalDomainStorage.COMPONENT_URL);
174: STDomainStorageKey lKey = new STDomainStorageKey();
175: lKey.StorageTechnologyRef = mEntityTable.getDomainStorage()
176: .getStorageTechnology().getRef();
177: lKey.DomainRef = mEntityTable.getDomainStorage()
178: .getDomainRef();
179: lPs.deleteEntityTableAssociationRole(lKey, mEntityTable
180: .getEntityRef(), mAssociationRoleRef);
181: } catch (NamingException e) {
182: throw new BONamingAndDirectoryServiceInvocationException(
183: "", e);
184: } catch (PSException e) {
185: throw new BOPersistenceServiceInvocationException("", e);
186: }
187: }
188:
189: /* Encapsulates commit action by this object */
190: protected void onCommitCreation() throws BOException {
191: try {
192: Context ctx = new InitialContext();
193: PSRelationalDomainStorage lPs = (PSRelationalDomainStorage) ctx
194: .lookup(PSRelationalDomainStorage.COMPONENT_URL);
195: STDomainStorageKey lKey = new STDomainStorageKey();
196: lKey.StorageTechnologyRef = mEntityTable.getDomainStorage()
197: .getStorageTechnology().getRef();
198: lKey.DomainRef = mEntityTable.getDomainStorage()
199: .getDomainRef();
200: lPs.insertEntityTableAssociationRole(lKey, mEntityTable
201: .getEntityRef(),
202: mRelationalEntityTableAssociationRoleDetails);
203: } catch (NamingException e) {
204: throw new BONamingAndDirectoryServiceInvocationException(
205: "", e);
206: } catch (PSException e) {
207: throw new BOPersistenceServiceInvocationException("", e);
208: }
209: }
210:
211: private void loadDetailsIfNecessary() throws BOException {
212: if (mRelationalEntityTableAssociationRoleDetails == null) {
213: try {
214: // Get the instance of the enterprise ps home via jndi
215: Context ctx = new InitialContext();
216: PSRelationalDomainStorage lPs = (PSRelationalDomainStorage) ctx
217: .lookup(PSRelationalDomainStorage.COMPONENT_URL);
218: STDomainStorageKey lKey = new STDomainStorageKey();
219: lKey.StorageTechnologyRef = mEntityTable
220: .getDomainStorage().getStorageTechnology()
221: .getRef();
222: lKey.DomainRef = mEntityTable.getDomainStorage()
223: .getDomainRef();
224: mRelationalEntityTableAssociationRoleDetails = lPs
225: .getEntityTableAssociationRole(lKey,
226: mEntityTable.getEntityRef(),
227: mAssociationRoleRef);
228: if (mRelationalEntityTableAssociationRoleDetails == null)
229: throw new BOException(
230: "Entity Table Association Role column definition not found. StorageTechnologyRef: "
231: + mEntityTable.getDomainStorage()
232: .getStorageTechnology()
233: .getRef()
234: + " EntityRef: "
235: + mEntityTable.getEntityRef()
236: + " AssociationRoleRef: "
237: + mAssociationRoleRef);
238: } catch (NamingException e) {
239: throw new BONamingAndDirectoryServiceInvocationException(
240: "", e);
241: } catch (PSException e) {
242: throw new BOPersistenceServiceInvocationException(
243: "Exception caught during loading of Entity Table Association Role column. StorageTechnologyRef: "
244: + mEntityTable.getDomainStorage()
245: .getStorageTechnology()
246: .getRef()
247: + " AssociationRoleRef: "
248: + mAssociationRoleRef, e);
249: }
250: }
251: }
252: }
|