BOStudentImpl.java
001 //
002 // This file is generated by MetaBoss Ver 1.4.0001 at Thu Dec 15 22:36:21 EST 2005
003 // MetaBoss is Copyright 2000-2005 © Softaris Pty.Ltd. All Rights Reserved.
004 // Content of this file is Copyright 2000-2005 © Softaris Pty. Ltd. All Rights Reserved.
005 // This content is licensed under Open Source Gnu Public License (GPL)
006 // Full terms and conditions of GPL can be found found at www.gnu.org
007 //
008 package com.almamater.crs.domains.courses.impl;
009 
010 import org.apache.commons.logging.Log;
011 import org.apache.commons.logging.LogFactory;
012 import com.metaboss.enterprise.ps.PSException;
013 import com.metaboss.enterprise.ps.STCollectionDetails;
014 import com.metaboss.enterprise.bo.BOException;
015 import com.metaboss.enterprise.bo.BORecordNotFoundException;
016 import com.metaboss.enterprise.bo.BOIllegalArgumentException;
017 import com.metaboss.enterprise.bo.BOUnexpectedProgramConditionException;
018 import com.metaboss.enterprise.bo.BOPersistenceServiceInvocationException;
019 import com.metaboss.enterprise.bo.BONamingAndDirectoryServiceInvocationException;
020 import com.metaboss.enterprise.bo.impl.BOObjectImpl;
021 import com.metaboss.enterprise.bo.BOSuperceededVersionException;
022 
023 public class BOStudentImpl extends BOObjectImpl implements com.almamater.crs.domains.courses.BOStudent
024 {
025     private static final Log sLogger = LogFactory.getLog(com.almamater.crs.domains.courses.BOStudent.class);
026     private static boolean sClassInitialised = false;
027     private static Object sClassInitialisationSemaphore = new Object();
028     private static String[] sEntityTypes = new String[] { "Enterprise/systems[CRS]/domains[Courses]/entities[Student]"};
029     private static com.almamater.crs.domains.courses.storage.PSDomain sDomainPersistenceService = null;
030     private static com.almamater.crs.domains.courses.storage.PSStudent sEntityPersistenceService = null;
031     private com.almamater.crs.types.system.courses.StudentInstanceId mInstanceId = null;
032     private com.almamater.crs.domains.courses.storage.STStudentRecord mDetails = null;
033     private com.almamater.crs.domains.courses.storage.STStudentRecord mSavedDetails = null;
034     private com.almamater.crs.domains.courses.storage.STStudentRecord mProposedDetails = null;
035     private java.util.HashSet mProposedAddedCourses = null;
036     private java.util.HashSet mProposedRemovedCourses = null;
037     private Object[] mNaturalPrimaryKey = null;
038 
039     // Pseudo class initialiser. Main feature that we can throw exception from here (unable to do that from native java class initialiser)
040     protected static void initialiseStudentClassIfNecessary() throws BOException
041     {
042         if (!sClassInitialised)
043         {
044             synchronized(sClassInitialisationSemaphore)
045             {
046                 if (!sClassInitialised)
047                 {
048                     try
049                     {
050                         javax.naming.Context lCtx = new javax.naming.InitialContext();
051                         sDomainPersistenceService = (com.almamater.crs.domains.courses.storage.PSDomain)lCtx.lookup(com.almamater.crs.domains.courses.storage.PSDomain.COMPONENT_URL);
052                         sEntityPersistenceService = (com.almamater.crs.domains.courses.storage.PSStudent)lCtx.lookup(com.almamater.crs.domains.courses.storage.PSStudent.COMPONENT_URL);
053                     }
054                     catch(javax.naming.NamingException e)
055                     {
056                         throw new BONamingAndDirectoryServiceInvocationException("Unable to initialise BOStudentImpl",e);
057                     }
058                     sClassInitialised = true;
059                 }
060             }
061         }
062     }
063 
064     /* Returns instance of the business object representing an existing entity. Does not do the load of data. */
065     public static com.almamater.crs.domains.courses.BOStudent createInstanceForExistingWithDeferredLoadBODomainImpl pDomain, com.almamater.crs.types.system.courses.StudentInstanceId pInstanceIdthrows BOException
066     {
067        initialiseStudentClassIfNecessary();
068        if (pDomain == null)
069            throw new BOIllegalArgumentException("pDomain argument can not be null");
070        if (pInstanceId == null)
071            throw new BOIllegalArgumentException("pInstanceId argument can not be null");
072        if (pInstanceId.isEmpty())
073            throw new BOIllegalArgumentException("pInstanceId argument can not be empty");
074        if (pInstanceId.isConcealed())
075            throw new BOIllegalArgumentException("pInstanceId argument can not be concealed");
076        BOStudentImpl lImpl = (BOStudentImpl)pDomain.getEntity("Enterprise/systems[CRS]/domains[Courses]/entities[Student]", pInstanceId.toString());
077        if (lImpl == null)
078        {
079            lImpl = new BOStudentImpl(pDomain, pInstanceId);
080            lImpl.setupForExisting();
081        }
082        return lImpl;
083     }
084 
085     /* Returns instance of the business object representing an existing entity. Does the load of data immediately. Essentially this guarantees that the object exists. */
086     public static com.almamater.crs.domains.courses.BOStudent createInstanceForExistingWithImmediateLoadBODomainImpl pDomain, com.almamater.crs.types.system.courses.StudentInstanceId pInstanceIdthrows BOException
087     {
088        initialiseStudentClassIfNecessary();
089        if (pDomain == null)
090            throw new BOIllegalArgumentException("pDomain argument can not be null");
091        if (pInstanceId == null)
092            throw new BOIllegalArgumentException("pInstanceId argument can not be null");
093        if (pInstanceId.isEmpty())
094            throw new BOIllegalArgumentException("pInstanceId argument can not be empty");
095        if (pInstanceId.isConcealed())
096            throw new BOIllegalArgumentException("pInstanceId argument can not be concealed");
097        BOStudentImpl lImpl = (BOStudentImpl)pDomain.getEntity("Enterprise/systems[CRS]/domains[Courses]/entities[Student]", pInstanceId.toString());
098        if (lImpl == null)
099        {
100            com.almamater.crs.domains.courses.storage.STStudentRecord lDetails = null;
101            try
102            {
103                if((lDetails = sEntityPersistenceService.getByInstanceIdpInstanceId, null)) == null)
104                    throw new BORecordNotFoundException("Enterprise/systems[CRS]/domains[Courses]/entities[Student]"new String[] { "InstanceId" }new String[] { pInstanceId.toString() });
105            }
106            catch(PSException e)
107            {
108                throw new BOPersistenceServiceInvocationException("Unable to load instance of the Enterprise/systems[CRS]/domains[Courses]/entities[Student] entity.",e);
109            }
110            lImpl = new BOStudentImpl(pDomain, lDetails.InstanceId);
111            lImpl.setupForExisting();
112            lImpl.setStorageRecord_ImplementationHelper(lDetails,false);
113        }
114        return lImpl;
115     }
116 
117    /* Returns instance of the business object representing an existing entity */
118    public static com.almamater.crs.domains.courses.BOStudent createInstanceForExistingBODomainImpl pDomain, com.almamater.crs.domains.courses.storage.STStudentRecord pDetailsthrows BOException
119    {
120        initialiseStudentClassIfNecessary();
121        if (pDomain == null)
122            throw new BOIllegalArgumentException("pDomain argument can not be null");
123        if (pDetails == null)
124            throw new BOIllegalArgumentException("pDetails argument can not be null");
125        BOStudentImpl lImpl = (BOStudentImpl)createInstanceForExistingWithDeferredLoad(pDomain, pDetails.InstanceId);
126        lImpl.setStorageRecord_ImplementationHelper(pDetails,false);
127        return lImpl;
128    }
129 
130    /* Returns instance of the business object representing an array of existing entities */
131    public static com.almamater.crs.domains.courses.BOStudent[] createInstanceForExistingBODomainImpl pDomain, com.almamater.crs.domains.courses.storage.STStudentRecord[] pDetailsthrows BOException
132    {
133        initialiseStudentClassIfNecessary();
134        if (pDomain == null)
135            throw new BOIllegalArgumentException("pDomain argument can not be null");
136        if (pDetails == null)
137            throw new BOIllegalArgumentException("pDetails argument can not be null");
138        com.almamater.crs.domains.courses.BOStudent[] lReturn = new com.almamater.crs.domains.courses.BOStudent[pDetails.length];
139        for (int i = 0; i < pDetails.length; i++)
140            lReturn[i= createInstanceForExisting(pDomain, pDetails[i]);
141        return lReturn;
142    }
143 
144    /* Returns instance of the business object representing an existing entity */
145    public static com.almamater.crs.domains.courses.BOStudent createInstanceForExistingBODomainImpl pDomain, com.almamater.types.core.StudentNumber pStudentNothrows BOException
146    {
147        initialiseStudentClassIfNecessary();
148        if (pDomain == null)
149            throw new BOIllegalArgumentException("pDomain argument can not be null");
150        if (pStudentNo == null)
151            throw new BOIllegalArgumentException("pStudentNo argument can not be null");
152        if (pStudentNo.isEmpty())
153            throw new BOIllegalArgumentException("pStudentNo argument can not be empty");
154        if (pStudentNo.isConcealed())
155            throw new BOIllegalArgumentException("pStudentNo argument can not be concealed");
156        BOStudentImpl lImpl = (BOStudentImpl)pDomain.getEntityWithNaturalPrimaryKeysEntityTypes, new Object[] { pStudentNo});
157        if (lImpl == null)
158        {
159            com.almamater.crs.domains.courses.storage.STStudentRecord lDetails = null;
160            try
161            {
162                if((lDetails = sEntityPersistenceService.getByPrimaryKeypStudentNo, null)) == null)
163                    throw new BORecordNotFoundException("Enterprise/systems[CRS]/domains[Courses]/entities[Student]"new String[] { "StudentNo"}new String[] { pStudentNo.toString()});
164            }
165            catch(PSException e)
166            {
167                throw new BOPersistenceServiceInvocationException("Unable to load instance of the Enterprise/systems[CRS]/domains[Courses]/entities[Student] entity.",e);
168            }
169            lImpl = new BOStudentImpl(pDomain, lDetails.InstanceId);
170            lImpl.setupForExisting();
171            lImpl.setStorageRecord_ImplementationHelper(lDetails,false);
172        }
173        return lImpl;
174    }
175    /* Returns instance of the business object representing a newly created entity */
176    public static com.almamater.crs.domains.courses.BOStudent createInstanceForNewStudentBODomainImpl pDomain, com.almamater.types.core.StudentNumber pStudentNothrows BOException
177    {
178        initialiseStudentClassIfNecessary();
179        if (pDomain == null)
180            throw new BOIllegalArgumentException("pDomain argument can not be null");
181        if (pStudentNo == null)
182            throw new BOIllegalArgumentException("pStudentNo argument can not be null");
183        if (pStudentNo.isEmpty())
184            throw new BOIllegalArgumentException("pStudentNo argument can not be empty");
185        if (pStudentNo.isConcealed())
186            throw new BOIllegalArgumentException("pStudentNo argument can not be concealed");
187        com.almamater.crs.types.system.courses.StudentInstanceId lNewInstanceId = null;
188        try
189        {
190            lNewInstanceId = sEntityPersistenceService.getNextAvailableInstanceId();
191        }
192        catch(PSException e)
193        {
194            throw new BOPersistenceServiceInvocationException("Unable to create new instance of the Enterprise/systems[CRS]/domains[Courses]/entities[Student] entity.",e);
195        }
196        BOStudentImpl lImpl = new BOStudentImpl(pDomain,lNewInstanceId);
197        lImpl.setupForNew();
198        lImpl.setStudentNo(pStudentNo);
199        return lImpl;
200    }
201     // Helper method. Retrieves array of all entity instances loaded in the domain
202     public static com.almamater.crs.domains.courses.BOStudent[] getCachedStudentsBODomainImpl pDomainthrows BOException
203     {
204        initialiseStudentClassIfNecessary();
205        if (pDomain == null)
206            throw new BOIllegalArgumentException("pDomain argument can not be null");
207        java.util.Collection lCachedInstances = pDomain.getAllEntities(sEntityTypes);
208        return (com.almamater.crs.domains.courses.BOStudent[])lCachedInstances.toArray(new com.almamater.crs.domains.courses.BOStudent[lCachedInstances.size()]);
209     }
210    // Helper method. Sets up the storage record
211    protected void setStorageRecord_ImplementationHelper(com.almamater.crs.domains.courses.storage.STStudentRecord pDetails, boolean pOverwritethrows BOException
212    {
213        if (pDetails == null)
214            throw new BOIllegalArgumentException("pDetails argument can not be null");
215        if (pDetails.InstanceId == null)
216            throw new BOIllegalArgumentException("pDetails.InstanceId field can not be null");
217        if (!pDetails.InstanceId.equals(mInstanceId))
218            throw new BOIllegalArgumentException("pDetails.InstanceId field does not match expected valsue");
219        if (pDetails.VersionId == null)
220            throw new BOIllegalArgumentException("pDetails.VersionId field can not be null");
221        if (pDetails.VersionId.isEmpty())
222            throw new BOIllegalArgumentException("pDetails.VersionId field can not be empty");
223        if (pDetails.VersionId.isConcealed())
224            throw new BOIllegalArgumentException("pDetails.VersionId field can not be concealed");
225        if (pOverwrite)
226        {
227            mDetails = pDetails;
228        }
229        else
230        if (isReadOnly())
231        {
232            if (mDetails == null)
233            {
234                mDetails = pDetails;
235            }
236            else
237            if (!pDetails.VersionId.equals(mDetails.VersionId))
238            {
239                sLogger.warn("Same instance of 'Student' with different version has already been loaded in this domain. Instance details from the repeat loads are ignored in this case.");
240            }
241            else
242            {
243                if (mDetails.StudentNo == null && pDetails.StudentNo != null)
244                    mDetails.StudentNo = pDetails.StudentNo;
245                if (mDetails.FirstName == null && pDetails.FirstName != null)
246                    mDetails.FirstName = pDetails.FirstName;
247                if (mDetails.SecondName == null && pDetails.SecondName != null)
248                    mDetails.SecondName = pDetails.SecondName;
249                if (mDetails.FamilyName == null && pDetails.FamilyName != null)
250                    mDetails.FamilyName = pDetails.FamilyName;
251                if (mDetails.DateOfBirth == null && pDetails.DateOfBirth != null)
252                    mDetails.DateOfBirth = pDetails.DateOfBirth;
253            }
254        }
255        else
256        if (isNewlyCreated())
257        {
258            if (mSavedDetails != null && pDetails.VersionId.equals(mSavedDetails.VersionId== false)
259                sLogger.warn("Same instance of 'Student' has already been created in this domain and it is still being edited. Instance details from the repeat loads are ignored in this case.");
260        }
261        else
262        {
263            if (mSavedDetails != null)
264            {
265                if (!pDetails.VersionId.equals(mSavedDetails.VersionId))
266                    sLogger.warn("Same instance of 'Student' has already been loaded in this domain and it is being edited. Instance details from the repeat loads are ignored in this case.");
267            }
268            else
269            if (!pDetails.VersionId.equals(mDetails.VersionId))
270            {
271                sLogger.warn("Same instance of 'Student' has already been loaded in this domain and it is being edited. Instance details from the repeat loads are ignored in this case.");
272            }
273        }
274    }
275    // Helper method. Sets up the and returns proposed storage record
276    protected com.almamater.crs.domains.courses.storage.STStudentRecord getProposedStudentStorageRecord_ImplementationHelper() throws BOException
277    {
278        if ((!isBeingEdited()) && (!isNewlyCreated()))
279            throw new BOUnexpectedProgramConditionException("Method can olnly be called on editable object.");
280        return mProposedDetails;
281    }
282 
283    protected void onCreateNew( ) throws BOException
284    {
285        super.onCreateNew();
286        mProposedDetails = new com.almamater.crs.domains.courses.storage.STStudentRecord();
287        mProposedDetails.InstanceId = mInstanceId;
288        mProposedDetails.VersionId = com.almamater.crs.types.system.courses.StudentVersionId.createInitial();
289        mSavedDetails = null;
290    }
291 
292    /* Private constructor. Restricts direct creation of the object */
293    private BOStudentImplBODomainImpl pDomain, com.almamater.crs.types.system.courses.StudentInstanceId pInstanceIdthrows BOException
294    {
295        super(pDomain, "Enterprise/systems[CRS]/domains[Courses]/entities[Student]", pInstanceId.toString());
296        mInstanceId = pInstanceId;
297    }
298 
299    /* Getter for domain object */
300    public com.almamater.crs.domains.courses.BODomain getDomain() throws BOException
301    {
302        return (com.almamater.crs.domains.courses.BODomain)getObjectDomain();
303    }
304 
305    protected Object[] getNaturalPrimaryKey() throws BOException
306    {
307        if (mNaturalPrimaryKey == null)
308        {
309            mNaturalPrimaryKey = new Object[] { getStudentNo()};
310        }
311        return mNaturalPrimaryKey;
312    }
313 
314    /* Getter for the instance id attribute */
315    public com.almamater.crs.types.system.courses.StudentInstanceId getStudentInstanceId() throws BOException
316    {
317        assertGetter();
318        return mInstanceId;
319    }
320 
321    /* Getter for the Version Id attribute. Will return new proposed version id for the object, which is being edited or newly created   */
322    public com.almamater.crs.types.system.courses.StudentVersionId getStudentVersionId() throws BOException
323    {
324        assertGetter();
325        if (isBeingEdited() || isNewlyCreated())
326            return mProposedDetails.VersionId;
327        if (mDetails == null || mDetails.VersionId == null)
328            loadFullDetails(false);
329        return mDetails.VersionId;
330    }
331 
332    /* Getter */
333    public com.almamater.types.core.StudentNumber getStudentNo() throws BOException
334    {
335        assertGetter();
336        if (isNewlyCreated())
337        {
338            if (mProposedDetails.StudentNo != null)
339                return mProposedDetails.StudentNo;
340            if (mSavedDetails != null && mSavedDetails.StudentNo != null)
341                return mSavedDetails.StudentNo;
342            return com.almamater.types.core.StudentNumber.createEmpty();
343        }
344        if (isBeingEdited())
345        {
346            if (mProposedDetails.StudentNo != null)
347                return mProposedDetails.StudentNo;
348            if (mSavedDetails != null && mSavedDetails.StudentNo != null)
349                return mSavedDetails.StudentNo;
350            return mDetails.StudentNo;
351        }
352        if (mDetails == null || mDetails.StudentNo == null)
353            loadFullDetails(false);
354        return mDetails.StudentNo;
355    }
356 
357    /* Setter */
358    public void setStudentNocom.almamater.types.core.StudentNumber pStudentNothrows BOException
359    {
360        assertSetter();
361        if (pStudentNo == null)
362            throw new BOIllegalArgumentException("pStudentNo argument can not be null. Do not set the attribute if you do not wish to change it.");
363        if (pStudentNo.isEmpty())
364            throw new BOIllegalArgumentException("pStudentNo argument can not be empty.");
365        if (pStudentNo.isConcealed())
366            throw new BOIllegalArgumentException("pStudentNo argument can not be concealed.");
367        mProposedDetails.StudentNo = null;
368        if (!pStudentNo.equals(getStudentNo()))
369            mProposedDetails.StudentNo = pStudentNo;
370        refreshUpdateStamps();
371    }
372 
373    /* Getter */
374    public com.almamater.types.core.PersonName getFirstName() throws BOException
375    {
376        assertGetter();
377        if (isNewlyCreated())
378        {
379            if (mProposedDetails.FirstName != null)
380                return mProposedDetails.FirstName;
381            if (mSavedDetails != null && mSavedDetails.FirstName != null)
382                return mSavedDetails.FirstName;
383            return com.almamater.types.core.PersonName.createEmpty();
384        }
385        if (isBeingEdited())
386        {
387            if (mProposedDetails.FirstName != null)
388                return mProposedDetails.FirstName;
389            if (mSavedDetails != null && mSavedDetails.FirstName != null)
390                return mSavedDetails.FirstName;
391            return mDetails.FirstName;
392        }
393        if (mDetails == null || mDetails.FirstName == null)
394            loadFullDetails(false);
395        return mDetails.FirstName;
396    }
397 
398    /* Setter */
399    public void setFirstNamecom.almamater.types.core.PersonName pFirstNamethrows BOException
400    {
401        assertSetter();
402        if (pFirstName == null)
403            throw new BOIllegalArgumentException("pFirstName argument can not be null. Do not set the attribute if you do not wish to change it.");
404        if (pFirstName.isEmpty())
405            throw new BOIllegalArgumentException("pFirstName argument can not be empty.");
406        if (pFirstName.isConcealed())
407            throw new BOIllegalArgumentException("pFirstName argument can not be concealed.");
408        mProposedDetails.FirstName = null;
409        if (!pFirstName.equals(getFirstName()))
410            mProposedDetails.FirstName = pFirstName;
411        refreshUpdateStamps();
412    }
413 
414    /* Getter */
415    public com.almamater.types.core.PersonName getSecondName() throws BOException
416    {
417        assertGetter();
418        if (isNewlyCreated())
419        {
420            if (mProposedDetails.SecondName != null)
421                return mProposedDetails.SecondName;
422            if (mSavedDetails != null && mSavedDetails.SecondName != null)
423                return mSavedDetails.SecondName;
424            return com.almamater.types.core.PersonName.createEmpty();
425        }
426        if (isBeingEdited())
427        {
428            if (mProposedDetails.SecondName != null)
429                return mProposedDetails.SecondName;
430            if (mSavedDetails != null && mSavedDetails.SecondName != null)
431                return mSavedDetails.SecondName;
432            return mDetails.SecondName;
433        }
434        if (mDetails == null || mDetails.SecondName == null)
435            loadFullDetails(false);
436        return mDetails.SecondName;
437    }
438 
439    /* Setter */
440    public void setSecondNamecom.almamater.types.core.PersonName pSecondNamethrows BOException
441    {
442        assertSetter();
443        if (pSecondName == null)
444            throw new BOIllegalArgumentException("pSecondName argument can not be null. Do not set the attribute if you do not wish to change it. Set the attribute to empty value if you wish to have it empty.");
445        if (pSecondName.isConcealed())
446            throw new BOIllegalArgumentException("pSecondName argument can not be concealed.");
447        mProposedDetails.SecondName = null;
448        if (!pSecondName.equals(getSecondName()))
449            mProposedDetails.SecondName = pSecondName;
450        refreshUpdateStamps();
451    }
452 
453    /* Getter */
454    public com.almamater.types.core.PersonName getFamilyName() throws BOException
455    {
456        assertGetter();
457        if (isNewlyCreated())
458        {
459            if (mProposedDetails.FamilyName != null)
460                return mProposedDetails.FamilyName;
461            if (mSavedDetails != null && mSavedDetails.FamilyName != null)
462                return mSavedDetails.FamilyName;
463            return com.almamater.types.core.PersonName.createEmpty();
464        }
465        if (isBeingEdited())
466        {
467            if (mProposedDetails.FamilyName != null)
468                return mProposedDetails.FamilyName;
469            if (mSavedDetails != null && mSavedDetails.FamilyName != null)
470                return mSavedDetails.FamilyName;
471            return mDetails.FamilyName;
472        }
473        if (mDetails == null || mDetails.FamilyName == null)
474            loadFullDetails(false);
475        return mDetails.FamilyName;
476    }
477 
478    /* Setter */
479    public void setFamilyNamecom.almamater.types.core.PersonName pFamilyNamethrows BOException
480    {
481        assertSetter();
482        if (pFamilyName == null)
483            throw new BOIllegalArgumentException("pFamilyName argument can not be null. Do not set the attribute if you do not wish to change it.");
484        if (pFamilyName.isEmpty())
485            throw new BOIllegalArgumentException("pFamilyName argument can not be empty.");
486        if (pFamilyName.isConcealed())
487            throw new BOIllegalArgumentException("pFamilyName argument can not be concealed.");
488        mProposedDetails.FamilyName = null;
489        if (!pFamilyName.equals(getFamilyName()))
490            mProposedDetails.FamilyName = pFamilyName;
491        refreshUpdateStamps();
492    }
493 
494    /* Getter */
495    public com.almamater.types.core.DateField getDateOfBirth() throws BOException
496    {
497        assertGetter();
498        if (isNewlyCreated())
499        {
500            if (mProposedDetails.DateOfBirth != null)
501                return mProposedDetails.DateOfBirth;
502            if (mSavedDetails != null && mSavedDetails.DateOfBirth != null)
503                return mSavedDetails.DateOfBirth;
504            return com.almamater.types.core.DateField.createEmpty();
505        }
506        if (isBeingEdited())
507        {
508            if (mProposedDetails.DateOfBirth != null)
509                return mProposedDetails.DateOfBirth;
510            if (mSavedDetails != null && mSavedDetails.DateOfBirth != null)
511                return mSavedDetails.DateOfBirth;
512            return mDetails.DateOfBirth;
513        }
514        if (mDetails == null || mDetails.DateOfBirth == null)
515            loadFullDetails(false);
516        return mDetails.DateOfBirth;
517    }
518 
519    /* Setter */
520    public void setDateOfBirthcom.almamater.types.core.DateField pDateOfBirththrows BOException
521    {
522        assertSetter();
523        if (pDateOfBirth == null)
524            throw new BOIllegalArgumentException("pDateOfBirth argument can not be null. Do not set the attribute if you do not wish to change it. Set the attribute to empty value if you wish to have it empty.");
525        if (pDateOfBirth.isConcealed())
526            throw new BOIllegalArgumentException("pDateOfBirth argument can not be concealed.");
527        mProposedDetails.DateOfBirth = null;
528        if (!pDateOfBirth.equals(getDateOfBirth()))
529            mProposedDetails.DateOfBirth = pDateOfBirth;
530        refreshUpdateStamps();
531    }
532 
533     /* Returns collection, which represents all Courses */
534     public com.almamater.crs.domains.courses.BOCourseCollection getCourses() throws BOException
535 
536     {
537         assertGetter();
538         STCollectionDetails lCollectionDetails = new STCollectionDetails();
539         lCollectionDetails.EntityRef = "Enterprise/systems[CRS]/domains[Courses]/entities[Course]";
540         lCollectionDetails.AssociationRoleRef = "Enterprise/systems[CRS]/domains[Courses]/associations[StudentEnrollsIntoCourse]/roles[Course]";
541         lCollectionDetails.AssociationRoleEntityInstanceId = getStudentInstanceId();
542         return BOCourseCollectionImpl.createBOCourseCollectionInstance((BODomainImpl)getObjectDomain()new STCollectionDetails[] {lCollectionDetails});
543     }
544 
545 
546     /* Adds existing instance of Course to this entity */
547     public void addCoursecom.almamater.crs.domains.courses.BOCourse pCoursethrows BOException
548     {
549         assertSetter();
550         if (pCourse == null)
551             throw new BOIllegalArgumentException("pCourse can not be null");
552         if (mProposedAddedCourses == null)
553             mProposedAddedCourses = new java.util.HashSet();
554         mProposedAddedCourses.add(pCourse.getCourseInstanceId());
555         if (mProposedRemovedCourses != null)
556             mProposedRemovedCourses.remove(pCourse.getCourseInstanceId());
557     }
558 
559     /* Removes existing instance of Course from this entity */
560     public void removeCoursecom.almamater.crs.domains.courses.BOCourse pCoursethrows BOException
561     {
562         assertEditor();
563         if (pCourse == null)
564             throw new BOIllegalArgumentException("pCourse can not be null");
565         if (mProposedRemovedCourses == null)
566             mProposedRemovedCourses = new java.util.HashSet();
567         mProposedRemovedCourses.add(pCourse.getCourseInstanceId());
568         if (mProposedAddedCourses != null)
569             mProposedAddedCourses.remove(pCourse.getCourseInstanceId());
570     }
571 
572     // Overridable method. Called by framework just after successfull save of initial creation.
573     protected void onSaveCreation() throws BOException
574     {
575         if (mSavedDetails == null || isModified())
576         {
577             if (mSavedDetails == null)
578             {
579                 mSavedDetails = new com.almamater.crs.domains.courses.storage.STStudentRecord();
580                 mSavedDetails.InstanceId = mProposedDetails.InstanceId;
581             }
582             mSavedDetails.VersionId = mProposedDetails.VersionId;
583             try
584             {
585                 mProposedDetails.VersionId = mSavedDetails.VersionId.getNext();
586             }
587             catch(com.metaboss.enterprise.datatypes.DataTypeInvalidOperationForEmptyInstanceException e)
588             {
589                 throw new BOUnexpectedProgramConditionException("It appears that Version id of the newly created entity is empty, which is not valid",e);
590             }
591             catch(com.metaboss.enterprise.datatypes.DataTypeInvalidOperationForConcealedInstanceException e)
592             {
593                 throw new BOUnexpectedProgramConditionException("It appears that Version id of the newly created entity is concealed, which is not valid",e);
594             }
595             if (mProposedDetails.StudentNo != null)
596             {
597                 mSavedDetails.StudentNo = mProposedDetails.StudentNo;
598                 mProposedDetails.StudentNo = null;
599             }
600             if (mProposedDetails.FirstName != null)
601             {
602                 mSavedDetails.FirstName = mProposedDetails.FirstName;
603                 mProposedDetails.FirstName = null;
604             }
605             if (mProposedDetails.SecondName != null)
606             {
607                 mSavedDetails.SecondName = mProposedDetails.SecondName;
608                 mProposedDetails.SecondName = null;
609             }
610             if (mProposedDetails.FamilyName != null)
611             {
612                 mSavedDetails.FamilyName = mProposedDetails.FamilyName;
613                 mProposedDetails.FamilyName = null;
614             }
615             if (mProposedDetails.DateOfBirth != null)
616             {
617                 mSavedDetails.DateOfBirth = mProposedDetails.DateOfBirth;
618                 mProposedDetails.DateOfBirth = null;
619             }
620             mProposedAddedCourses = null;
621             mProposedRemovedCourses = null;
622         }
623     }
624 
625     // Overridable method. Called by framework just after successfull commit of initial update.
626     protected void onCommitCreation() throws BOException
627     {
628         mDetails = mSavedDetails;
629         mSavedDetails = null;
630     }
631 
632     protected void onReload() throws BOException
633     {
634         loadFullDetails(true);
635         if (isBeingEdited())
636         {
637             mSavedDetails = null;
638             mProposedDetails = new com.almamater.crs.domains.courses.storage.STStudentRecord();
639             mProposedDetails.InstanceId = mInstanceId;
640             try
641             {
642                 mProposedDetails.VersionId = mDetails.VersionId.getNext();
643             }
644             catch(com.metaboss.enterprise.datatypes.DataTypeInvalidOperationForEmptyInstanceException e)
645             {
646                 // This should never occur as it means that we have got empty from database
647                 throw new BOUnexpectedProgramConditionException("It appears that entity with empty Version id has been submitted for update",e);
648             }
649             catch(com.metaboss.enterprise.datatypes.DataTypeInvalidOperationForConcealedInstanceException e)
650             {
651                 // This should never occur as it means that we have got concealed from database
652                 throw new BOUnexpectedProgramConditionException("It appears that entity with concealed Version id has been submitted for update",e);
653             }
654         }
655     }
656 
657     private void refreshUpdateStamps() throws BOException
658     {
659         if (isModified())
660             renewUpdateStamps();
661         else
662             clearUpdateStamps();
663     }
664 
665     protected void renewUpdateStamps() throws BOException
666     {
667     }
668 
669     protected void clearUpdateStamps() throws BOException
670     {
671     }
672 
673     protected boolean isModified() throws BOException
674     {
675         if (mProposedDetails == null)
676             return false;
677         if (mProposedDetails.StudentNo != null)
678             return true;
679         if (mProposedDetails.FirstName != null)
680             return true;
681         if (mProposedDetails.SecondName != null)
682             return true;
683         if (mProposedDetails.FamilyName != null)
684             return true;
685         if (mProposedDetails.DateOfBirth != null)
686             return true;
687        return false;
688     }
689 
690     // This method is called internally to find out if any attribute or reference needs loading.
691     private boolean isFullyLoaded() throws BOException
692     {
693        // Check if we have full details.
694        if mDetails == null || mInstanceId == null || mDetails.VersionId == null || mDetails.StudentNo == null || mDetails.FirstName == null || mDetails.SecondName == null || mDetails.FamilyName == null || mDetails.DateOfBirth == null)
695            return false// Something not loaded in our object
696        return true// Our object is fully loaded
697     }
698 
699     // This method is called by framework just before existing object enters being edited stage
700     protected void onBeginEdit() throws BOException
701     {
702         if (!isFullyLoaded())
703             loadFullDetails(false);
704         mSavedDetails = null;
705         mProposedDetails = new com.almamater.crs.domains.courses.storage.STStudentRecord();
706         mProposedDetails.InstanceId = mInstanceId;
707         try
708         {
709             mProposedDetails.VersionId = mDetails.VersionId.getNext();
710         }
711         catch(com.metaboss.enterprise.datatypes.DataTypeInvalidOperationForEmptyInstanceException e)
712         {
713             // This should never occur as it means that we have got empty from database
714             throw new BOUnexpectedProgramConditionException("It appears that entity with empty Version id has been submitted for update",e);
715         }
716         catch(com.metaboss.enterprise.datatypes.DataTypeInvalidOperationForConcealedInstanceException e)
717         {
718             // This should never occur as it means that we have got concealed from database
719             throw new BOUnexpectedProgramConditionException("It appears that entity with concealed Version id has been submitted for update",e);
720         }
721     }
722 
723     // Overridable method. Called by framework just after successfull save of update to the entity.
724     protected void onSaveUpdate() throws BOException
725     {
726         if (isModified())
727         {
728             if (mSavedDetails == null)
729             {
730                 mSavedDetails = new com.almamater.crs.domains.courses.storage.STStudentRecord();
731                 mSavedDetails.InstanceId = mProposedDetails.InstanceId;
732             }
733             mSavedDetails.VersionId = mProposedDetails.VersionId;
734             try
735             {
736                 mProposedDetails.VersionId = mSavedDetails.VersionId.getNext();
737             }
738             catch(com.metaboss.enterprise.datatypes.DataTypeInvalidOperationForEmptyInstanceException e)
739             {
740                 throw new BOUnexpectedProgramConditionException("It appears that Version id of the entity being edited is empty, which is not valid",e);
741             }
742             catch(com.metaboss.enterprise.datatypes.DataTypeInvalidOperationForConcealedInstanceException e)
743             {
744                 throw new BOUnexpectedProgramConditionException("It appears that Version id of the entity being edited is concealed, which is not valid",e);
745             }
746             if (mProposedDetails.StudentNo != null)
747             {
748                 mSavedDetails.StudentNo = mProposedDetails.StudentNo;
749                 mProposedDetails.StudentNo = null;
750             }
751             if (mProposedDetails.FirstName != null)
752             {
753                 mSavedDetails.FirstName = mProposedDetails.FirstName;
754                 mProposedDetails.FirstName = null;
755             }
756             if (mProposedDetails.SecondName != null)
757             {
758                 mSavedDetails.SecondName = mProposedDetails.SecondName;
759                 mProposedDetails.SecondName = null;
760             }
761             if (mProposedDetails.FamilyName != null)
762             {
763                 mSavedDetails.FamilyName = mProposedDetails.FamilyName;
764                 mProposedDetails.FamilyName = null;
765             }
766             if (mProposedDetails.DateOfBirth != null)
767             {
768                 mSavedDetails.DateOfBirth = mProposedDetails.DateOfBirth;
769                 mProposedDetails.DateOfBirth = null;
770             }
771         }
772         mProposedAddedCourses = null;
773         mProposedRemovedCourses = null;
774     }
775 
776     // Overridable method. Called by framework just after successfull discard of update to the entity.
777     protected void onDiscardUpdate() throws BOException
778     {
779         if (isModified())
780         {
781             mProposedDetails.StudentNo = null;
782             mProposedDetails.FirstName = null;
783             mProposedDetails.SecondName = null;
784             mProposedDetails.FamilyName = null;
785             mProposedDetails.DateOfBirth = null;
786         }
787         mProposedAddedCourses = null;
788         mProposedRemovedCourses = null;
789     }
790 
791     // Overridable method. Called by framework just after successfull commit of object update.
792     protected void onCommitUpdate() throws BOException
793     {
794         boolean lHadUpdatedDetails = false;
795         if (mSavedDetails != null)
796         {
797             if (mSavedDetails.StudentNo != null)
798             {
799                 mDetails.StudentNo = mSavedDetails.StudentNo;
800                 lHadUpdatedDetails = true;
801             }
802             if (mSavedDetails.FirstName != null)
803             {
804                 mDetails.FirstName = mSavedDetails.FirstName;
805                 lHadUpdatedDetails = true;
806             }
807             if (mSavedDetails.SecondName != null)
808             {
809                 mDetails.SecondName = mSavedDetails.SecondName;
810                 lHadUpdatedDetails = true;
811             }
812             if (mSavedDetails.FamilyName != null)
813             {
814                 mDetails.FamilyName = mSavedDetails.FamilyName;
815                 lHadUpdatedDetails = true;
816             }
817             if (mSavedDetails.DateOfBirth != null)
818             {
819                 mDetails.DateOfBirth = mSavedDetails.DateOfBirth;
820                 lHadUpdatedDetails = true;
821             }
822         }
823         if (lHadUpdatedDetails)
824             mDetails.VersionId = mSavedDetails.VersionId;
825         mSavedDetails = null;
826     }
827 
828     // Overridable method. Called by framework just after unsuccessful commit of initial update.
829     protected void onRollbackUpdate() throws BOException
830     {
831         mSavedDetails = null;
832         mProposedDetails = null;
833         mProposedAddedCourses = null;
834         mProposedRemovedCourses = null;
835     }
836 
837    // Loads full details of this entity
838    private void loadFullDetails(boolean pOverwritethrows BOException
839    {
840        try
841        {
842            com.almamater.crs.domains.courses.storage.STStudentRecord lDetails = null;
843            if((lDetails = sEntityPersistenceService.getByInstanceIdmInstanceId, null)) == null)
844                throw new BORecordNotFoundException("com.almamater.crs.domains.courses.BOStudent"new String[] { "InstanceId" new String[] { mInstanceId.toString() } );
845            setStorageRecord_ImplementationHelper(lDetails,pOverwrite);
846        }
847        catch(PSException e)
848        {
849            throw new BOPersistenceServiceInvocationException("Unable to load full entity details from the storage",e);
850        }
851    }
852 
853     // Helper. Required by enterprise framework. Persists creation of the new entities
854     public static void persistCreate(BOStudentImpl[] pNewBOImplsthrows BOException
855     {
856         try
857         {
858             com.almamater.crs.domains.courses.storage.STStudentRecord[] lNewDetails = new com.almamater.crs.domains.courses.storage.STStudentRecord[pNewBOImpls.length];
859             for (int i = 0; i < pNewBOImpls.length; i++)
860             {
861                 BOStudentImpl lNewBOImpl = pNewBOImpls[i];
862                 lNewBOImpl.validate();
863                 lNewDetails[i= lNewBOImpl.getProposedStudentStorageRecord_ImplementationHelper();
864             }
865             sEntityPersistenceService.insert(lNewDetails);
866         }
867         catch(com.metaboss.enterprise.ps.PSAssociationConstraintViolationException e)
868         {
869             throw new com.metaboss.enterprise.bo.BOObjectConstraintViolationException("Entity association constraint validation error has been detected while attempting to create the entity record.",e);
870         }
871         catch(com.metaboss.enterprise.ps.PSAttributeConstraintViolationException e)
872         {
873             throw new com.metaboss.enterprise.bo.BOObjectConstraintViolationException("Entity attribute constraint validation error has been detected while attempting to create the entity record.",e);
874         }
875         catch(PSException e)
876         {
877             throw new BOPersistenceServiceInvocationException("Caught exception while inserting new Student entity records.",e);
878         }
879     }
880     // Helper. Required by enterprise framework. Persists changes to aggregated many-to-many references
881     public static void persistChangesToReferences(BOStudentImpl[] pBOImplsthrows BOException
882     {
883         try
884         {
885             java.util.ArrayList lNewAssociations = new java.util.ArrayList();
886             java.util.ArrayList lRemovedAssociations = new java.util.ArrayList();
887             for (int i = 0; i < pBOImpls.length; i++)
888             {
889                 BOStudentImpl lBOImpl = pBOImpls[i];
890                 if (lBOImpl.mProposedAddedCourses != null)
891                 {
892                     for (java.util.Iterator lIter = lBOImpl.mProposedAddedCourses.iterator();lIter.hasNext();)
893                     {
894                         com.almamater.crs.domains.courses.storage.STStudentEnrollsIntoCourseAssociation lAssociationDetails = new com.almamater.crs.domains.courses.storage.STStudentEnrollsIntoCourseAssociation();
895                         lAssociationDetails.AttendeeInstanceId = lBOImpl.getStudentInstanceId();
896                         lAssociationDetails.CourseInstanceId = (com.almamater.crs.types.system.courses.CourseInstanceId)lIter.next();
897                         lNewAssociations.add(lAssociationDetails);
898                     }
899                 }
900                if (lBOImpl.mProposedRemovedCourses != null)
901                {
902                    for (java.util.Iterator lIter = lBOImpl.mProposedRemovedCourses.iterator();lIter.hasNext();)
903                    {
904                        com.almamater.crs.domains.courses.storage.STStudentEnrollsIntoCourseAssociation lAssociationDetails = new com.almamater.crs.domains.courses.storage.STStudentEnrollsIntoCourseAssociation();
905                        lAssociationDetails.AttendeeInstanceId = lBOImpl.getStudentInstanceId();
906                        lAssociationDetails.CourseInstanceId = (com.almamater.crs.types.system.courses.CourseInstanceId)lIter.next();
907                        lRemovedAssociations.add(lAssociationDetails);
908                    }
909                }
910             }
911             if (!lNewAssociations.isEmpty())
912                 sEntityPersistenceService.insertCourses((com.almamater.crs.domains.courses.storage.STStudentEnrollsIntoCourseAssociation[])lNewAssociations.toArray(new com.almamater.crs.domains.courses.storage.STStudentEnrollsIntoCourseAssociation[lNewAssociations.size()]));
913             if (!lRemovedAssociations.isEmpty())
914                 sEntityPersistenceService.removeCourses((com.almamater.crs.domains.courses.storage.STStudentEnrollsIntoCourseAssociation[])lRemovedAssociations.toArray(new com.almamater.crs.domains.courses.storage.STStudentEnrollsIntoCourseAssociation[lRemovedAssociations.size()]));
915         }
916         catch(PSException e)
917         {
918             throw new BOPersistenceServiceInvocationException("Caught exception while persisting changes to the Courses of the Student entity.",e);
919         }
920     }
921 
922     // Helper. Required by enterprise framework. Persists updates to the existing entities
923     // Note that the absence of this method indicates that updates are not supported by this entity type
924     public static void persistUpdate(BOStudentImpl[] pModifiedBOImplsthrows BOException
925     {
926         try
927         {
928             // Collect array of details to pass down to persistence method.
929             java.util.ArrayList lModifiedDetails = new  java.util.ArrayList();
930             for (int i = 0; i < pModifiedBOImpls.length; i++)
931             {
932                 BOStudentImpl lModifiedBOImpl = pModifiedBOImpls[i];
933                 if (lModifiedBOImpl.isModified())
934                 {
935                     lModifiedBOImpl.validate();
936                     lModifiedDetails.add(lModifiedBOImpl.getProposedStudentStorageRecord_ImplementationHelper());
937                 }
938             }
939             // Do it if necessary
940             if (!lModifiedDetails.isEmpty())
941                 sEntityPersistenceService.update((com.almamater.crs.domains.courses.storage.STStudentRecord[])lModifiedDetails.toArray(new com.almamater.crs.domains.courses.storage.STStudentRecord[lModifiedDetails.size()]));
942         }
943         catch(com.metaboss.enterprise.ps.PSAssociationConstraintViolationException e)
944         {
945             throw new com.metaboss.enterprise.bo.BOObjectConstraintViolationException("Entity association constraint validation error has been detected while attempting to update the entity record.",e);
946         }
947         catch(com.metaboss.enterprise.ps.PSAttributeConstraintViolationException e)
948         {
949             throw new com.metaboss.enterprise.bo.BOObjectConstraintViolationException("Entity attribute constraint validation error has been detected while attempting to update the entity record.",e);
950         }
951         catch(com.metaboss.enterprise.ps.PSUpdateDataIntegrityViolationException e)
952         {
953             throw new BOSuperceededVersionException("The entity record has been modified by third party and can not be updated.",e);
954         }
955         catch(PSException e)
956         {
957             throw new BOPersistenceServiceInvocationException("Caught exception while persisting changes to the Enterprise/systems[CRS]/domains[Courses]/entities[Student] entity records.",e);
958         }
959     }
960 
961     // Helper. Required by enterprise framework. Persists deletion of the existing entities
962     public static void persistDelete(BOStudentImpl[] pBOImplsToDeletethrows BOException
963     {
964         try
965         {
966             // Collect array of ids to pass down to persistence method
967             com.almamater.crs.types.system.courses.StudentInstanceId[] lIdsToDelete = new com.almamater.crs.types.system.courses.StudentInstanceId[pBOImplsToDelete.length];
968             for (int i = 0; i < pBOImplsToDelete.length; i++)
969                 lIdsToDelete[i= pBOImplsToDelete[i].mInstanceId;
970             // Do it
971             sEntityPersistenceService.delete(lIdsToDelete);
972         }
973         catch(PSException e)
974         {
975             throw new BOPersistenceServiceInvocationException("",e);
976         }
977     }
978     // Helper. Validates the constraints on the entity instance
979     protected void validate() throws BOException
980     {
981    }
982 }