/*
 * IMPORTANT!!!! XSL Autogenerated class, DO NOT EDIT!!!!!
 * Template: Infrastructure9.0 [oneit.objstore.BusinessObjectTemplate.xsl]
 *   Vendor: Apache Software Foundation (Xalan XSLTC) (Version: 1.0)
 */

    
package performa.orm;

import java.io.*;
import java.util.*;
import oneit.appservices.config.*;
import oneit.logging.*;
import oneit.objstore.*;
import oneit.objstore.assocs.*;
import oneit.objstore.attributes.*;
import oneit.objstore.rdbms.filters.*;
import oneit.objstore.parser.*;
import oneit.objstore.validator.*;
import oneit.objstore.utils.*;
import oneit.utils.*;
import oneit.utils.filter.Filter;
import oneit.utils.transform.*;
import oneit.utils.parsers.FieldException;

import performa.orm.types.*;


public abstract class BaseSentEmail extends BaseBusinessClass
{
    // Reference instance for the object
    public static final SentEmail REFERENCE_SentEmail = new SentEmail ();

    // Reference instance for the object
    public static final SentEmail DUMMY_SentEmail = new DummySentEmail ();

    // Static constants corresponding to field names
    
    public static final String FIELD_Subject = "Subject";
    public static final String FIELD_SentDate = "SentDate";
    public static final String FIELD_ApplicationStatus = "ApplicationStatus";
    public static final String FIELD_MessageContent = "MessageContent";
    public static final String FIELD_EmailTo = "EmailTo";
    public static final String SINGLEREFERENCE_JobApplication = "JobApplication";
    public static final String BACKREF_JobApplication = "";

    // Static constants corresponding to searches
    public static final String SEARCH_All = "All";
    

    // Static constants corresponding to attribute helpers
    private static final DefaultAttributeHelper<SentEmail> HELPER_Subject = DefaultAttributeHelper.INSTANCE;
    private static final DefaultAttributeHelper<SentEmail> HELPER_SentDate = DefaultAttributeHelper.INSTANCE;
    private static final EnumeratedAttributeHelper<SentEmail, ApplicationStatus> HELPER_ApplicationStatus =  new EnumeratedAttributeHelper<SentEmail, ApplicationStatus> (ApplicationStatus.FACTORY_ApplicationStatus);
    private static final DefaultAttributeHelper<SentEmail> HELPER_MessageContent = DefaultAttributeHelper.INSTANCE;
    private static final DefaultAttributeHelper<SentEmail> HELPER_EmailTo = DefaultAttributeHelper.INSTANCE;
    

    // Private attributes corresponding to business object data
    private String _Subject;
    private Date _SentDate;
    private ApplicationStatus _ApplicationStatus;
    private String _MessageContent;
    private String _EmailTo;
    

    // Private attributes corresponding to single references
    private SingleAssociation<SentEmail, JobApplication> _JobApplication;
    

    // Private attributes corresponding to multiple references
    

    // Map of maps of metadata
    private static final Map ATTRIBUTES_METADATA_SentEmail = new LinkedHashMap ();

    // Arrays of validators for each attribute
    private static final AttributeValidator[] FIELD_Subject_Validators;
    private static final AttributeValidator[] FIELD_SentDate_Validators;
    private static final AttributeValidator[] FIELD_ApplicationStatus_Validators;
    private static final AttributeValidator[] FIELD_MessageContent_Validators;
    private static final AttributeValidator[] FIELD_EmailTo_Validators;
    

    // Arrays of AttributeDecorators for each attribute
    private static final AttributeDecorator<SentEmail, String>[] FIELD_Subject_Decorators;
    private static final AttributeDecorator<SentEmail, Date>[] FIELD_SentDate_Decorators;
    private static final AttributeDecorator<SentEmail, ApplicationStatus>[] FIELD_ApplicationStatus_Decorators;
    private static final AttributeDecorator<SentEmail, String>[] FIELD_MessageContent_Decorators;
    private static final AttributeDecorator<SentEmail, String>[] FIELD_EmailTo_Decorators;
    
    
    // Arrays of SingleAssocDecorators for each attribute
    private static final SingleAssocDecorator<SentEmail, JobApplication>[] SINGLEREFERENCE_JobApplication_Decorators;
    
    
    // Arrays of MultiAssocDecorators for each attribute
    

    // Arrays of behaviour decorators
    private static final SentEmailBehaviourDecorator[] SentEmail_BehaviourDecorators;
    
    static
    {
        try
        {
            
            String tmp_JobApplication = JobApplication.BACKREF_SentEmails;
            
            Map  validatorMapping = ((Map)ConfigMgr.getConfigObject ("CONFIG.ORMVALIDATOR", "ValidatorMapping"));

            setupAssocMetaData_JobApplication();
            FIELD_Subject_Validators = (AttributeValidator[])setupAttribMetaData_Subject(validatorMapping).toArray (new AttributeValidator[0]);
            FIELD_SentDate_Validators = (AttributeValidator[])setupAttribMetaData_SentDate(validatorMapping).toArray (new AttributeValidator[0]);
            FIELD_ApplicationStatus_Validators = (AttributeValidator[])setupAttribMetaData_ApplicationStatus(validatorMapping).toArray (new AttributeValidator[0]);
            FIELD_MessageContent_Validators = (AttributeValidator[])setupAttribMetaData_MessageContent(validatorMapping).toArray (new AttributeValidator[0]);
            FIELD_EmailTo_Validators = (AttributeValidator[])setupAttribMetaData_EmailTo(validatorMapping).toArray (new AttributeValidator[0]);
            FIELD_Subject_Decorators = (AttributeDecorator[])AttributeDecoratorUtils.getAttributeDecorators(REFERENCE_SentEmail, FIELD_Subject).toArray (new AttributeDecorator[0]);
            FIELD_SentDate_Decorators = (AttributeDecorator[])AttributeDecoratorUtils.getAttributeDecorators(REFERENCE_SentEmail, FIELD_SentDate).toArray (new AttributeDecorator[0]);
            FIELD_ApplicationStatus_Decorators = (AttributeDecorator[])AttributeDecoratorUtils.getAttributeDecorators(REFERENCE_SentEmail, FIELD_ApplicationStatus).toArray (new AttributeDecorator[0]);
            FIELD_MessageContent_Decorators = (AttributeDecorator[])AttributeDecoratorUtils.getAttributeDecorators(REFERENCE_SentEmail, FIELD_MessageContent).toArray (new AttributeDecorator[0]);
            FIELD_EmailTo_Decorators = (AttributeDecorator[])AttributeDecoratorUtils.getAttributeDecorators(REFERENCE_SentEmail, FIELD_EmailTo).toArray (new AttributeDecorator[0]);
            SINGLEREFERENCE_JobApplication_Decorators = (SingleAssocDecorator[])AttributeDecoratorUtils.getSingleAssocDecorators(REFERENCE_SentEmail, SINGLEREFERENCE_JobApplication).toArray (new SingleAssocDecorator[0]);
            

            REFERENCE_SentEmail.initialiseReference ();
            DUMMY_SentEmail.initialiseReference ();
            SentEmail_BehaviourDecorators = BaseBusinessClass.getBBCBehaviours(SentEmail.class).toArray(new SentEmailBehaviourDecorator[0]);
        }
        catch (RuntimeException e)
        {
            LogMgr.log (BUSINESS_OBJECTS, LogLevel.SYSTEMERROR1, e, "Error initialising");
            throw e;
        }
    }

    
    private static void setupAssocMetaData_JobApplication()
    {
        Map metaInfo = new HashMap ();

        metaInfo.put ("backreferenceName", "SentEmails");
        metaInfo.put ("dbcol", "job_application_id");
        metaInfo.put ("mandatory", "true");
        metaInfo.put ("name", "JobApplication");
        metaInfo.put ("type", "JobApplication");
        metaInfo.put (METADATA_DB_TABLENAME, "tl_sent_email");
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for SentEmail.JobApplication:", metaInfo);
        ATTRIBUTES_METADATA_SentEmail.put (SINGLEREFERENCE_JobApplication, Collections.unmodifiableMap (metaInfo));
    }
    
    
    private static List setupAttribMetaData_Subject(Map validatorMapping)
    {
        Map  metaInfo   = new HashMap ();

        metaInfo.put ("dbcol", "subject");
        metaInfo.put ("length", "200");
        metaInfo.put ("mandatory", "true");
        metaInfo.put ("name", "Subject");
        metaInfo.put ("type", "String");
        metaInfo.put (METADATA_DB_TABLENAME, "tl_sent_email");
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for SentEmail.Subject:", metaInfo);
        ATTRIBUTES_METADATA_SentEmail.put (FIELD_Subject, Collections.unmodifiableMap (metaInfo));

        List validators = BaseBusinessClass.getAttribValidators(SentEmail.class, "Subject", metaInfo, validatorMapping);
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG1, "Validators for SentEmail.Subject:", validators);        

        return validators;
    }
    
    private static List setupAttribMetaData_SentDate(Map validatorMapping)
    {
        Map  metaInfo   = new HashMap ();

        metaInfo.put ("dbcol", "sent_date");
        metaInfo.put ("mandatory", "true");
        metaInfo.put ("name", "SentDate");
        metaInfo.put ("type", "Date");
        metaInfo.put (METADATA_DB_TABLENAME, "tl_sent_email");
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for SentEmail.SentDate:", metaInfo);
        ATTRIBUTES_METADATA_SentEmail.put (FIELD_SentDate, Collections.unmodifiableMap (metaInfo));

        List validators = BaseBusinessClass.getAttribValidators(SentEmail.class, "SentDate", metaInfo, validatorMapping);
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG1, "Validators for SentEmail.SentDate:", validators);        

        return validators;
    }
    
    private static List setupAttribMetaData_ApplicationStatus(Map validatorMapping)
    {
        Map  metaInfo   = new HashMap ();

        metaInfo.put ("attribHelper", "EnumeratedAttributeHelper");
        metaInfo.put ("dbcol", "application_status");
        metaInfo.put ("mandatory", "true");
        metaInfo.put ("name", "ApplicationStatus");
        metaInfo.put ("type", "ApplicationStatus");
        metaInfo.put (METADATA_DB_TABLENAME, "tl_sent_email");
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for SentEmail.ApplicationStatus:", metaInfo);
        ATTRIBUTES_METADATA_SentEmail.put (FIELD_ApplicationStatus, Collections.unmodifiableMap (metaInfo));

        List validators = BaseBusinessClass.getAttribValidators(SentEmail.class, "ApplicationStatus", metaInfo, validatorMapping);
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG1, "Validators for SentEmail.ApplicationStatus:", validators);        

        return validators;
    }
    
    private static List setupAttribMetaData_MessageContent(Map validatorMapping)
    {
        Map  metaInfo   = new HashMap ();

        metaInfo.put ("dbcol", "message_content");
        metaInfo.put ("mandatory", "true");
        metaInfo.put ("name", "MessageContent");
        metaInfo.put ("type", "String");
        metaInfo.put (METADATA_DB_TABLENAME, "tl_sent_email");
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for SentEmail.MessageContent:", metaInfo);
        ATTRIBUTES_METADATA_SentEmail.put (FIELD_MessageContent, Collections.unmodifiableMap (metaInfo));

        List validators = BaseBusinessClass.getAttribValidators(SentEmail.class, "MessageContent", metaInfo, validatorMapping);
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG1, "Validators for SentEmail.MessageContent:", validators);        

        return validators;
    }
    
    private static List setupAttribMetaData_EmailTo(Map validatorMapping)
    {
        Map  metaInfo   = new HashMap ();

        metaInfo.put ("dbcol", "email_to");
        metaInfo.put ("mandatory", "true");
        metaInfo.put ("name", "EmailTo");
        metaInfo.put ("type", "String");
        metaInfo.put (METADATA_DB_TABLENAME, "tl_sent_email");
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for SentEmail.EmailTo:", metaInfo);
        ATTRIBUTES_METADATA_SentEmail.put (FIELD_EmailTo, Collections.unmodifiableMap (metaInfo));

        List validators = BaseBusinessClass.getAttribValidators(SentEmail.class, "EmailTo", metaInfo, validatorMapping);
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG1, "Validators for SentEmail.EmailTo:", validators);        

        return validators;
    }
    
    // END OF STATIC METADATA DEFINITION    
    
    
    
    // This constructor should not be called
    protected BaseSentEmail ()
    {
    }


    protected BBCBehaviourDecorator[] getBehaviours()
    {
        return SentEmail_BehaviourDecorators;
    }

    


    protected void _initialiseNewObjAttributes (ObjectTransaction transaction) throws StorageException
    {
        super._initialiseNewObjAttributes (transaction);

        
        _Subject = (String)(HELPER_Subject.initialise (_Subject));
        _SentDate = (Date)(HELPER_SentDate.initialise (_SentDate));
        _ApplicationStatus = (ApplicationStatus)(HELPER_ApplicationStatus.initialise (_ApplicationStatus));
        _MessageContent = (String)(HELPER_MessageContent.initialise (_MessageContent));
        _EmailTo = (String)(HELPER_EmailTo.initialise (_EmailTo));
    }


    protected void _initialiseAssociations ()
    {
        super._initialiseAssociations ();

        _JobApplication = new SingleAssociation<SentEmail, JobApplication> (this, SINGLEREFERENCE_JobApplication, JobApplication.MULTIPLEREFERENCE_SentEmails, JobApplication.REFERENCE_JobApplication, "tl_sent_email");
        
    }


    protected BaseBusinessClass initialiseReference ()
    {
        super.initialiseReference ();
        
        _JobApplication = new SingleAssociation<SentEmail, JobApplication> (this, SINGLEREFERENCE_JobApplication, JobApplication.MULTIPLEREFERENCE_SentEmails, JobApplication.REFERENCE_JobApplication, "tl_sent_email");
        
        
        return this;
    }


    /**
     * Attribute Subject
     */
    public String getSubject ()
    {
        assertValid();
        String valToReturn = AttributeDecoratorUtils.getValue (FIELD_Subject_Decorators, (SentEmail)this, FIELD_Subject, _Subject);

        
        for (SentEmailBehaviourDecorator bhd : SentEmail_BehaviourDecorators)
        {
            valToReturn = bhd.getSubject ((SentEmail)this, valToReturn);
        }

        return valToReturn;
    }


    /**
     * Called prior to the attribute changing.  Subclasses need not call super.  If a field exception
     * is thrown, the attribute change will fail.  The new value is different to the old value.
     */
    protected void preSubjectChange (String newSubject) throws FieldException
    {
    }


    /**
     * Called after the attribute changes.
     * If a field exception is thrown, the value is still changed, however it 
     * may lead to the TX being rolled back
     */
    protected void postSubjectChange () throws FieldException
    {
    }

    
    public FieldWriteability getWriteability_Subject ()
    {
        return getFieldWritabilityUtil (FieldWriteability.TRUE);
    }

    /**
     * Set the attribute Subject.  Checks to ensure a new value
     * has been supplied.  If so, marks the field as altered and sets the attribute.
     */
    public void setSubject (String newSubject) throws FieldException
    {
        newSubject = AttributeDecoratorUtils.setValue (FIELD_Subject_Decorators, (SentEmail)this, FIELD_Subject, newSubject);

        boolean oldAndNewIdentical = HELPER_Subject.compare (_Subject, newSubject);
        
        try
        {
            for (SentEmailBehaviourDecorator bhd : SentEmail_BehaviourDecorators)
            {
                newSubject = bhd.setSubject ((SentEmail)this, newSubject);
                oldAndNewIdentical = HELPER_Subject.compare (_Subject, newSubject);
            }

            BusinessObjectParser.assertFieldCondition (newSubject != null, this, FIELD_Subject, "mandatory");
            

            if (FIELD_Subject_Validators.length > 0)
            {
                Object newSubjectObj = HELPER_Subject.toObject (newSubject);

                if (newSubjectObj != null)
                {
                    int     loopMax = FIELD_Subject_Validators.length;
                    Map     metadata = (Map)ATTRIBUTES_METADATA_SentEmail.get (FIELD_Subject);

                    for (int v = 0 ; v < loopMax ; ++v)
                    {
                        FIELD_Subject_Validators[v].checkAttribute (this, FIELD_Subject, metadata, newSubjectObj);
                    }
                }
            }
        }
        catch (FieldException e)
        {
            if (!oldAndNewIdentical)
            {
                e.setWouldModify ();
            }
            
            throw e;
        }

        if (!oldAndNewIdentical)
        {
            assertValid();
            Debug.assertion (AttributeDecoratorUtils.getWriteability (FIELD_Subject_Decorators, (SentEmail)this, FIELD_Subject ,getWriteability_Subject ()) != FieldWriteability.FALSE, "Field  Subject is not writeable");
            preSubjectChange (newSubject);
            markFieldChange (FIELD_Subject);
            _Subject = newSubject;            
            postFieldChange (FIELD_Subject);
            postSubjectChange ();
        }
    }

    /**
     * Attribute SentDate
     */
    public Date getSentDate ()
    {
        assertValid();
        Date valToReturn = AttributeDecoratorUtils.getValue (FIELD_SentDate_Decorators, (SentEmail)this, FIELD_SentDate, _SentDate);

        
        for (SentEmailBehaviourDecorator bhd : SentEmail_BehaviourDecorators)
        {
            valToReturn = bhd.getSentDate ((SentEmail)this, valToReturn);
        }

        return valToReturn;
    }


    /**
     * Called prior to the attribute changing.  Subclasses need not call super.  If a field exception
     * is thrown, the attribute change will fail.  The new value is different to the old value.
     */
    protected void preSentDateChange (Date newSentDate) throws FieldException
    {
    }


    /**
     * Called after the attribute changes.
     * If a field exception is thrown, the value is still changed, however it 
     * may lead to the TX being rolled back
     */
    protected void postSentDateChange () throws FieldException
    {
    }

    
    public FieldWriteability getWriteability_SentDate ()
    {
        return getFieldWritabilityUtil (FieldWriteability.TRUE);
    }

    /**
     * Set the attribute SentDate.  Checks to ensure a new value
     * has been supplied.  If so, marks the field as altered and sets the attribute.
     */
    public void setSentDate (Date newSentDate) throws FieldException
    {
        newSentDate = AttributeDecoratorUtils.setValue (FIELD_SentDate_Decorators, (SentEmail)this, FIELD_SentDate, newSentDate);

        boolean oldAndNewIdentical = HELPER_SentDate.compare (_SentDate, newSentDate);
        
        try
        {
            for (SentEmailBehaviourDecorator bhd : SentEmail_BehaviourDecorators)
            {
                newSentDate = bhd.setSentDate ((SentEmail)this, newSentDate);
                oldAndNewIdentical = HELPER_SentDate.compare (_SentDate, newSentDate);
            }

            BusinessObjectParser.assertFieldCondition (newSentDate != null, this, FIELD_SentDate, "mandatory");
            

            if (FIELD_SentDate_Validators.length > 0)
            {
                Object newSentDateObj = HELPER_SentDate.toObject (newSentDate);

                if (newSentDateObj != null)
                {
                    int     loopMax = FIELD_SentDate_Validators.length;
                    Map     metadata = (Map)ATTRIBUTES_METADATA_SentEmail.get (FIELD_SentDate);

                    for (int v = 0 ; v < loopMax ; ++v)
                    {
                        FIELD_SentDate_Validators[v].checkAttribute (this, FIELD_SentDate, metadata, newSentDateObj);
                    }
                }
            }
        }
        catch (FieldException e)
        {
            if (!oldAndNewIdentical)
            {
                e.setWouldModify ();
            }
            
            throw e;
        }

        if (!oldAndNewIdentical)
        {
            assertValid();
            Debug.assertion (AttributeDecoratorUtils.getWriteability (FIELD_SentDate_Decorators, (SentEmail)this, FIELD_SentDate ,getWriteability_SentDate ()) != FieldWriteability.FALSE, "Field  SentDate is not writeable");
            preSentDateChange (newSentDate);
            markFieldChange (FIELD_SentDate);
            _SentDate = newSentDate;            
            postFieldChange (FIELD_SentDate);
            postSentDateChange ();
        }
    }

    /**
     * Attribute ApplicationStatus
     */
    public ApplicationStatus getApplicationStatus ()
    {
        assertValid();
        ApplicationStatus valToReturn = AttributeDecoratorUtils.getValue (FIELD_ApplicationStatus_Decorators, (SentEmail)this, FIELD_ApplicationStatus, _ApplicationStatus);

        
        for (SentEmailBehaviourDecorator bhd : SentEmail_BehaviourDecorators)
        {
            valToReturn = bhd.getApplicationStatus ((SentEmail)this, valToReturn);
        }

        return valToReturn;
    }


    /**
     * Called prior to the attribute changing.  Subclasses need not call super.  If a field exception
     * is thrown, the attribute change will fail.  The new value is different to the old value.
     */
    protected void preApplicationStatusChange (ApplicationStatus newApplicationStatus) throws FieldException
    {
    }


    /**
     * Called after the attribute changes.
     * If a field exception is thrown, the value is still changed, however it 
     * may lead to the TX being rolled back
     */
    protected void postApplicationStatusChange () throws FieldException
    {
    }

    
    public FieldWriteability getWriteability_ApplicationStatus ()
    {
        return getFieldWritabilityUtil (FieldWriteability.TRUE);
    }

    /**
     * Set the attribute ApplicationStatus.  Checks to ensure a new value
     * has been supplied.  If so, marks the field as altered and sets the attribute.
     */
    public void setApplicationStatus (ApplicationStatus newApplicationStatus) throws FieldException
    {
        newApplicationStatus = AttributeDecoratorUtils.setValue (FIELD_ApplicationStatus_Decorators, (SentEmail)this, FIELD_ApplicationStatus, newApplicationStatus);

        boolean oldAndNewIdentical = HELPER_ApplicationStatus.compare (_ApplicationStatus, newApplicationStatus);
        
        try
        {
            for (SentEmailBehaviourDecorator bhd : SentEmail_BehaviourDecorators)
            {
                newApplicationStatus = bhd.setApplicationStatus ((SentEmail)this, newApplicationStatus);
                oldAndNewIdentical = HELPER_ApplicationStatus.compare (_ApplicationStatus, newApplicationStatus);
            }

            BusinessObjectParser.assertFieldCondition (newApplicationStatus != null, this, FIELD_ApplicationStatus, "mandatory");
            

            if (FIELD_ApplicationStatus_Validators.length > 0)
            {
                Object newApplicationStatusObj = HELPER_ApplicationStatus.toObject (newApplicationStatus);

                if (newApplicationStatusObj != null)
                {
                    int     loopMax = FIELD_ApplicationStatus_Validators.length;
                    Map     metadata = (Map)ATTRIBUTES_METADATA_SentEmail.get (FIELD_ApplicationStatus);

                    for (int v = 0 ; v < loopMax ; ++v)
                    {
                        FIELD_ApplicationStatus_Validators[v].checkAttribute (this, FIELD_ApplicationStatus, metadata, newApplicationStatusObj);
                    }
                }
            }
        }
        catch (FieldException e)
        {
            if (!oldAndNewIdentical)
            {
                e.setWouldModify ();
            }
            
            throw e;
        }

        if (!oldAndNewIdentical)
        {
            assertValid();
            Debug.assertion (AttributeDecoratorUtils.getWriteability (FIELD_ApplicationStatus_Decorators, (SentEmail)this, FIELD_ApplicationStatus ,getWriteability_ApplicationStatus ()) != FieldWriteability.FALSE, "Field  ApplicationStatus is not writeable");
            preApplicationStatusChange (newApplicationStatus);
            markFieldChange (FIELD_ApplicationStatus);
            _ApplicationStatus = newApplicationStatus;            
            postFieldChange (FIELD_ApplicationStatus);
            postApplicationStatusChange ();
        }
    }

    /**
     * Attribute MessageContent
     */
    public String getMessageContent ()
    {
        assertValid();
        String valToReturn = AttributeDecoratorUtils.getValue (FIELD_MessageContent_Decorators, (SentEmail)this, FIELD_MessageContent, _MessageContent);

        
        for (SentEmailBehaviourDecorator bhd : SentEmail_BehaviourDecorators)
        {
            valToReturn = bhd.getMessageContent ((SentEmail)this, valToReturn);
        }

        return valToReturn;
    }


    /**
     * Called prior to the attribute changing.  Subclasses need not call super.  If a field exception
     * is thrown, the attribute change will fail.  The new value is different to the old value.
     */
    protected void preMessageContentChange (String newMessageContent) throws FieldException
    {
    }


    /**
     * Called after the attribute changes.
     * If a field exception is thrown, the value is still changed, however it 
     * may lead to the TX being rolled back
     */
    protected void postMessageContentChange () throws FieldException
    {
    }

    
    public FieldWriteability getWriteability_MessageContent ()
    {
        return getFieldWritabilityUtil (FieldWriteability.TRUE);
    }

    /**
     * Set the attribute MessageContent.  Checks to ensure a new value
     * has been supplied.  If so, marks the field as altered and sets the attribute.
     */
    public void setMessageContent (String newMessageContent) throws FieldException
    {
        newMessageContent = AttributeDecoratorUtils.setValue (FIELD_MessageContent_Decorators, (SentEmail)this, FIELD_MessageContent, newMessageContent);

        boolean oldAndNewIdentical = HELPER_MessageContent.compare (_MessageContent, newMessageContent);
        
        try
        {
            for (SentEmailBehaviourDecorator bhd : SentEmail_BehaviourDecorators)
            {
                newMessageContent = bhd.setMessageContent ((SentEmail)this, newMessageContent);
                oldAndNewIdentical = HELPER_MessageContent.compare (_MessageContent, newMessageContent);
            }

            BusinessObjectParser.assertFieldCondition (newMessageContent != null, this, FIELD_MessageContent, "mandatory");
            

            if (FIELD_MessageContent_Validators.length > 0)
            {
                Object newMessageContentObj = HELPER_MessageContent.toObject (newMessageContent);

                if (newMessageContentObj != null)
                {
                    int     loopMax = FIELD_MessageContent_Validators.length;
                    Map     metadata = (Map)ATTRIBUTES_METADATA_SentEmail.get (FIELD_MessageContent);

                    for (int v = 0 ; v < loopMax ; ++v)
                    {
                        FIELD_MessageContent_Validators[v].checkAttribute (this, FIELD_MessageContent, metadata, newMessageContentObj);
                    }
                }
            }
        }
        catch (FieldException e)
        {
            if (!oldAndNewIdentical)
            {
                e.setWouldModify ();
            }
            
            throw e;
        }

        if (!oldAndNewIdentical)
        {
            assertValid();
            Debug.assertion (AttributeDecoratorUtils.getWriteability (FIELD_MessageContent_Decorators, (SentEmail)this, FIELD_MessageContent ,getWriteability_MessageContent ()) != FieldWriteability.FALSE, "Field  MessageContent is not writeable");
            preMessageContentChange (newMessageContent);
            markFieldChange (FIELD_MessageContent);
            _MessageContent = newMessageContent;            
            postFieldChange (FIELD_MessageContent);
            postMessageContentChange ();
        }
    }

    /**
     * Attribute EmailTo
     */
    public String getEmailTo ()
    {
        assertValid();
        String valToReturn = AttributeDecoratorUtils.getValue (FIELD_EmailTo_Decorators, (SentEmail)this, FIELD_EmailTo, _EmailTo);

        
        for (SentEmailBehaviourDecorator bhd : SentEmail_BehaviourDecorators)
        {
            valToReturn = bhd.getEmailTo ((SentEmail)this, valToReturn);
        }

        return valToReturn;
    }


    /**
     * Called prior to the attribute changing.  Subclasses need not call super.  If a field exception
     * is thrown, the attribute change will fail.  The new value is different to the old value.
     */
    protected void preEmailToChange (String newEmailTo) throws FieldException
    {
    }


    /**
     * Called after the attribute changes.
     * If a field exception is thrown, the value is still changed, however it 
     * may lead to the TX being rolled back
     */
    protected void postEmailToChange () throws FieldException
    {
    }

    
    public FieldWriteability getWriteability_EmailTo ()
    {
        return getFieldWritabilityUtil (FieldWriteability.TRUE);
    }

    /**
     * Set the attribute EmailTo.  Checks to ensure a new value
     * has been supplied.  If so, marks the field as altered and sets the attribute.
     */
    public void setEmailTo (String newEmailTo) throws FieldException
    {
        newEmailTo = AttributeDecoratorUtils.setValue (FIELD_EmailTo_Decorators, (SentEmail)this, FIELD_EmailTo, newEmailTo);

        boolean oldAndNewIdentical = HELPER_EmailTo.compare (_EmailTo, newEmailTo);
        
        try
        {
            for (SentEmailBehaviourDecorator bhd : SentEmail_BehaviourDecorators)
            {
                newEmailTo = bhd.setEmailTo ((SentEmail)this, newEmailTo);
                oldAndNewIdentical = HELPER_EmailTo.compare (_EmailTo, newEmailTo);
            }

            BusinessObjectParser.assertFieldCondition (newEmailTo != null, this, FIELD_EmailTo, "mandatory");
            

            if (FIELD_EmailTo_Validators.length > 0)
            {
                Object newEmailToObj = HELPER_EmailTo.toObject (newEmailTo);

                if (newEmailToObj != null)
                {
                    int     loopMax = FIELD_EmailTo_Validators.length;
                    Map     metadata = (Map)ATTRIBUTES_METADATA_SentEmail.get (FIELD_EmailTo);

                    for (int v = 0 ; v < loopMax ; ++v)
                    {
                        FIELD_EmailTo_Validators[v].checkAttribute (this, FIELD_EmailTo, metadata, newEmailToObj);
                    }
                }
            }
        }
        catch (FieldException e)
        {
            if (!oldAndNewIdentical)
            {
                e.setWouldModify ();
            }
            
            throw e;
        }

        if (!oldAndNewIdentical)
        {
            assertValid();
            Debug.assertion (AttributeDecoratorUtils.getWriteability (FIELD_EmailTo_Decorators, (SentEmail)this, FIELD_EmailTo ,getWriteability_EmailTo ()) != FieldWriteability.FALSE, "Field  EmailTo is not writeable");
            preEmailToChange (newEmailTo);
            markFieldChange (FIELD_EmailTo);
            _EmailTo = newEmailTo;            
            postFieldChange (FIELD_EmailTo);
            postEmailToChange ();
        }
    }



    /**
     * A list of multi assoc names e.g. list of strings.
     */
    public List<String> getSingleAssocs()
    {
        List result = super.getSingleAssocs ();
        
        result.add("JobApplication");

        return result;
    }
    
    
    public BaseBusinessClass getSingleAssocReferenceInstance (String assocName)
    {
        if (assocName == null)
        {
            throw new RuntimeException ("Game over == null!");
        }
        else if (assocName.equals (SINGLEREFERENCE_JobApplication))
        {
            return _JobApplication.getReferencedType ();
        }
        else
        {
            return super.getSingleAssocReferenceInstance (assocName);
        }
    }


    public String getSingleAssocBackReference(String assocName)
    {
        if (assocName == null)
        {
            throw new RuntimeException ("Game over == null!");
        }
        else if (assocName.equals (SINGLEREFERENCE_JobApplication))
        {
            return JobApplication.MULTIPLEREFERENCE_SentEmails ;
        }
        else
        {
            return super.getSingleAssocBackReference (assocName);
        }
    }
    
    
    public BaseBusinessClass getSingleAssoc (String assocName) throws StorageException
    {
        if (assocName == null)
        {
            throw new RuntimeException ("Game over == null!");
        }
        else if (assocName.equals (SINGLEREFERENCE_JobApplication))
        {
            return getJobApplication ();
        }
        else
        {
            return super.getSingleAssoc (assocName);
        }
    }


    public BaseBusinessClass getSingleAssoc (String assocName, Get getType) throws StorageException
    {
        if (assocName == null)
        {
            throw new RuntimeException ("Game over == null!");
        }
        else if (assocName.equals (SINGLEREFERENCE_JobApplication))
        {
            return getJobApplication (getType);
        }
        else
        {
            return super.getSingleAssoc (assocName, getType);
        }
    }


    public Long getSingleAssocID (String assocName) throws StorageException
    {
        if (assocName == null)
        {
            throw new RuntimeException ("Game over == null!");
        }
        else if (assocName.equals (SINGLEREFERENCE_JobApplication))
        {
            return getJobApplicationID ();
        }
        else
        {
            return super.getSingleAssocID (assocName);
        }
    }


    public void setSingleAssoc (String assocName, BaseBusinessClass newValue) throws StorageException, FieldException
    {
        if (assocName == null)
        {
            throw new RuntimeException ("Game over == null!");
        }
        else if (assocName.equals (SINGLEREFERENCE_JobApplication))
        {
            setJobApplication ((JobApplication)(newValue));
        }
        else
        {
            super.setSingleAssoc (assocName, newValue);
        }
    }



    /**
     * Get the reference JobApplication
     */
    public JobApplication getJobApplication () throws StorageException
    {
        assertValid();
        
        try
        {
            return (JobApplication)(_JobApplication.get ());
        }
        catch (ClassCastException e)
        {
            LogMgr.log (BUSINESS_OBJECTS, LogLevel.SYSTEMERROR2, "Cache collision in SentEmail:", this.getObjectID (), ", was trying to get JobApplication:",  getJobApplicationID ());
            LogMgr.log (BUSINESS_OBJECTS, LogLevel.SYSTEMERROR2, "Instead I got:", _JobApplication.get ().getClass ());
            throw e;
        }
    }


    /**
     * Get the object id for the referenced object.  Does not force a DB access.
     */
    public JobApplication getJobApplication (Get getType) throws StorageException
    {
        assertValid();
        return _JobApplication.get(getType);
    }


    /**
     * Get the object id for the referenced object.  Does not force a DB access.
     */
    public Long getJobApplicationID ()
    {
        assertValid();
        
        if (_JobApplication == null)
        {
            return null;
        }
        else
        {
            return _JobApplication.getID ();
        }
    }

    /**
     * Called prior to the assoc changing.  Subclasses need not call super.  If a field exception
     * is thrown, the attribute change will fail.  The new value is different to the old value.
     */
    protected void preJobApplicationChange (JobApplication newJobApplication) throws FieldException
    {
    }


    /**
     * Called after the assoc changes.
     * If a field exception is thrown, the value is still changed, however it 
     * may lead to the TX being rolled back
     */
    protected void postJobApplicationChange () throws FieldException
    {
    }


    
    public FieldWriteability getWriteability_JobApplication ()
    {
        return getFieldWritabilityUtil (FieldWriteability.TRUE);
    }

        
    /**
     * Set the reference JobApplication.  Checks to ensure a new value
     * has been supplied.  If so, marks the reference as altered and sets it.
     */
    public void setJobApplication (JobApplication newJobApplication) throws StorageException, FieldException
    {
        BusinessObjectParser.assertFieldCondition (newJobApplication != null, this, SINGLEREFERENCE_JobApplication, "mandatory");

        if (_JobApplication.wouldReferencedChange (newJobApplication))
        {
            assertValid();
            Debug.assertion (AttributeDecoratorUtils.getWriteability (SINGLEREFERENCE_JobApplication_Decorators, (SentEmail)this, SINGLEREFERENCE_JobApplication ,getWriteability_JobApplication ()) != FieldWriteability.FALSE, "Assoc JobApplication is not writeable");
            preJobApplicationChange (newJobApplication);
            JobApplication oldJobApplication = getJobApplication ();

            if (oldJobApplication != null)
            {
                // This is to stop validation from triggering when we are removed
                _JobApplication.set (null);
                oldJobApplication.removeFromSentEmails ((SentEmail)(this));
            }

            _JobApplication.set (newJobApplication);

            if (newJobApplication != null)
            {
                newJobApplication.addToSentEmails ((SentEmail)(this));
            }
                
            postJobApplicationChange ();
        }
    }

    /**
     * A list of multi assoc names e.g. list of strings.
     */
    public List<String> getMultiAssocs()
    {
        List result = super.getMultiAssocs ();
        

        return result;
    }


    /**
     * Get the reference instance for the multi assoc name.
     */
    public BaseBusinessClass getMultiAssocReferenceInstance(String attribName)
    {

        return super.getMultiAssocReferenceInstance(attribName);
    }


    public String getMultiAssocBackReference(String attribName)
    {

        return super.getMultiAssocBackReference(attribName);
    }


    /**
     * Get the assoc count for the multi assoc name.
     */
    public int getMultiAssocCount(String attribName) throws StorageException
    {

        return super.getMultiAssocCount(attribName);
    }


    /**
     * Get the assoc at a particular index
     */
    public BaseBusinessClass getMultiAssocAt(String attribName, int index) throws StorageException
    {

        return super.getMultiAssocAt(attribName, index);
    }


    /**
     * Add to a multi assoc by attribute name
     */
    public void addToMultiAssoc(String attribName, BaseBusinessClass newElement) throws StorageException
    {

        super.addToMultiAssoc(attribName, newElement);
    }

    /**
     * Remove from a multi assoc by attribute name
     */
    public void removeFromMultiAssoc(String attribName, BaseBusinessClass oldElement) throws StorageException
    {

        super.removeFromMultiAssoc(attribName, oldElement);
    }


    protected void __loadMultiAssoc (String attribName, BaseBusinessClass[] elements)
    {

        super.__loadMultiAssoc(attribName, elements);
    }


    protected boolean __isMultiAssocLoaded (String attribName)
    {

        return super.__isMultiAssocLoaded(attribName);
    }




    public void onDelete ()
    {
        try 
        {
            // Ensure we are removed from any loaded multi-associations that aren't mandatory
            if (_JobApplication.isLoaded () || getTransaction ().isObjectLoaded (_JobApplication.getReferencedType (), getJobApplicationID ()))
            {
                JobApplication  referenced = getJobApplication ();

                if (referenced != null)
                {
                    // Stop the callback
                    LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG1, "Setting backreference to null SentEmails from ", getObjectID (), " to ", referenced.getObjectID ());
                    _JobApplication.set (null);
                    referenced.removeFromSentEmails ((SentEmail)this);
                }
            }
        
        }
        catch (Exception e)
        {
            throw NestedException.wrap(e);
        }

        super.onDelete ();
    }


    public SentEmail newInstance ()
    {
        return new SentEmail ();
    }


    public SentEmail referenceInstance ()
    {
        return REFERENCE_SentEmail;
    }


    public SentEmail getInTransaction (ObjectTransaction t) throws StorageException
    {
        return getSentEmailByID (t, getObjectID());
    }
    
    
    public BaseBusinessClass dummyInstance ()
    {
        return DUMMY_SentEmail;
    }


    public String getBaseSetName ()
    {
        return "tl_sent_email";
    }



    /**
     * This is where an object returns the Persistent sets that will
     * store it into the database.
     * The should be entered into allSets
     */
    public void getPersistentSets (PersistentSetCollection allSets)
    {
        ObjectStatus        myStatus = getStatus ();
        PersistentSetStatus myPSetStatus = myStatus.getPSetStatus();
        ObjectID            myID = getID();

        super.getPersistentSets (allSets);
        
        PersistentSet   tl_sent_emailPSet = allSets.getPersistentSet (myID, "tl_sent_email", myPSetStatus);

        tl_sent_emailPSet.setAttrib (FIELD_ObjectID, myID);
        tl_sent_emailPSet.setAttrib (FIELD_Subject, HELPER_Subject.toObject (_Subject)); //
        tl_sent_emailPSet.setAttrib (FIELD_SentDate, HELPER_SentDate.toObject (_SentDate)); //
        tl_sent_emailPSet.setAttrib (FIELD_ApplicationStatus, HELPER_ApplicationStatus.toObject (_ApplicationStatus)); //
        tl_sent_emailPSet.setAttrib (FIELD_MessageContent, HELPER_MessageContent.toObject (_MessageContent)); //
        tl_sent_emailPSet.setAttrib (FIELD_EmailTo, HELPER_EmailTo.toObject (_EmailTo)); //
        _JobApplication.getPersistentSets (allSets);
        
    }


    /**
     * Sets the objects state based on Persistent sets.
     */
    public void setFromPersistentSets (ObjectID objectID, PersistentSetCollection allSets)
    {
        super.setFromPersistentSets (objectID, allSets);
        
        PersistentSet   tl_sent_emailPSet = allSets.getPersistentSet (objectID, "tl_sent_email");

        _Subject = (String)(HELPER_Subject.fromObject (_Subject, tl_sent_emailPSet.getAttrib (FIELD_Subject))); //
        _SentDate = (Date)(HELPER_SentDate.fromObject (_SentDate, tl_sent_emailPSet.getAttrib (FIELD_SentDate))); //
        _ApplicationStatus = (ApplicationStatus)(HELPER_ApplicationStatus.fromObject (_ApplicationStatus, tl_sent_emailPSet.getAttrib (FIELD_ApplicationStatus))); //
        _MessageContent = (String)(HELPER_MessageContent.fromObject (_MessageContent, tl_sent_emailPSet.getAttrib (FIELD_MessageContent))); //
        _EmailTo = (String)(HELPER_EmailTo.fromObject (_EmailTo, tl_sent_emailPSet.getAttrib (FIELD_EmailTo))); //
        _JobApplication.setFromPersistentSets (objectID, allSets);
        
    }


    public void setAttributesFrom (BaseBusinessClass other, MultiException e)
    {
        super.setAttributesFrom (other, e);

        if (other instanceof SentEmail)
        {
            SentEmail otherSentEmail = (SentEmail)other;
            

            try
            {
                setSubject (otherSentEmail.getSubject ());
            }
            catch (FieldException ex)
            {
                e.addException (ex);
            }

            try
            {
                setSentDate (otherSentEmail.getSentDate ());
            }
            catch (FieldException ex)
            {
                e.addException (ex);
            }

            try
            {
                setApplicationStatus (otherSentEmail.getApplicationStatus ());
            }
            catch (FieldException ex)
            {
                e.addException (ex);
            }

            try
            {
                setMessageContent (otherSentEmail.getMessageContent ());
            }
            catch (FieldException ex)
            {
                e.addException (ex);
            }

            try
            {
                setEmailTo (otherSentEmail.getEmailTo ());
            }
            catch (FieldException ex)
            {
                e.addException (ex);
            }
        }
    }


    /**
     * Set the attributes in this to copies of the attributes in source.
     */
    public void copyAttributesFrom (BaseBusinessClass source)
    {
        super.copyAttributesFrom (source);

        if (source instanceof BaseSentEmail)
        {
            BaseSentEmail sourceSentEmail = (BaseSentEmail)(source);

            _Subject = sourceSentEmail._Subject;
            _SentDate = sourceSentEmail._SentDate;
            _ApplicationStatus = sourceSentEmail._ApplicationStatus;
            _MessageContent = sourceSentEmail._MessageContent;
            _EmailTo = sourceSentEmail._EmailTo;
            
        }
    }


    /**
     * Set the associations in this to copies of the attributes in source.
     */
    public void copySingleAssociationsFrom (BaseBusinessClass source, boolean linkToGhosts)
    {
        super.copySingleAssociationsFrom (source, linkToGhosts);

        if (source instanceof BaseSentEmail)
        {
            BaseSentEmail sourceSentEmail = (BaseSentEmail)(source);

            _JobApplication.copyFrom (sourceSentEmail._JobApplication, linkToGhosts);
            
        }
    }


    /**
     * Set the associations in this to copies of the attributes in source.
     */
    public void copyAssociationsFrom (BaseBusinessClass source, boolean linkToGhosts)
    {
        super.copyAssociationsFrom (source, linkToGhosts);

        if (source instanceof BaseSentEmail)
        {
            BaseSentEmail sourceSentEmail = (BaseSentEmail)(source);

            
        }
    }


    public void validate (ValidationContext context)
    {
        super.validate (context);

        
        context.check (getJobApplicationID() != null, this, SINGLEREFERENCE_JobApplication, "mandatory");
        
    }


    /**
     * Subclasses must override this to read in their attributes
     */
    protected void readExternalData(Map<String, Object> vals) throws IOException, ClassNotFoundException
    {
        super.readExternalData(vals);

        _Subject = (String)(HELPER_Subject.readExternal (_Subject, vals.get(FIELD_Subject))); //
        _SentDate = (Date)(HELPER_SentDate.readExternal (_SentDate, vals.get(FIELD_SentDate))); //
        _ApplicationStatus = (ApplicationStatus)(HELPER_ApplicationStatus.readExternal (_ApplicationStatus, vals.get(FIELD_ApplicationStatus))); //
        _MessageContent = (String)(HELPER_MessageContent.readExternal (_MessageContent, vals.get(FIELD_MessageContent))); //
        _EmailTo = (String)(HELPER_EmailTo.readExternal (_EmailTo, vals.get(FIELD_EmailTo))); //
        _JobApplication.readExternalData(vals.get(SINGLEREFERENCE_JobApplication));
        
    }


    /**
     * Subclasses must override this to write out their attributes
     */
    protected void writeExternalData(Map<String, Object> vals) throws IOException
    {
        super.writeExternalData(vals);

        vals.put (FIELD_Subject, HELPER_Subject.writeExternal (_Subject));
        vals.put (FIELD_SentDate, HELPER_SentDate.writeExternal (_SentDate));
        vals.put (FIELD_ApplicationStatus, HELPER_ApplicationStatus.writeExternal (_ApplicationStatus));
        vals.put (FIELD_MessageContent, HELPER_MessageContent.writeExternal (_MessageContent));
        vals.put (FIELD_EmailTo, HELPER_EmailTo.writeExternal (_EmailTo));
        vals.put (SINGLEREFERENCE_JobApplication, _JobApplication.writeExternalData());
        
    }


    public void compare (BaseBusinessClass other, AttributeChangeListener listener) throws StorageException
    {
        super.compare (other, listener);

        if (other instanceof BaseSentEmail)
        {
            BaseSentEmail otherSentEmail = (BaseSentEmail)(other);

            
            if (!HELPER_Subject.compare(this._Subject, otherSentEmail._Subject))
            {
                listener.notifyFieldChange(this, other, FIELD_Subject, HELPER_Subject.toObject(this._Subject), HELPER_Subject.toObject(otherSentEmail._Subject));
            }
            if (!HELPER_SentDate.compare(this._SentDate, otherSentEmail._SentDate))
            {
                listener.notifyFieldChange(this, other, FIELD_SentDate, HELPER_SentDate.toObject(this._SentDate), HELPER_SentDate.toObject(otherSentEmail._SentDate));
            }
            if (!HELPER_ApplicationStatus.compare(this._ApplicationStatus, otherSentEmail._ApplicationStatus))
            {
                listener.notifyFieldChange(this, other, FIELD_ApplicationStatus, HELPER_ApplicationStatus.toObject(this._ApplicationStatus), HELPER_ApplicationStatus.toObject(otherSentEmail._ApplicationStatus));
            }
            if (!HELPER_MessageContent.compare(this._MessageContent, otherSentEmail._MessageContent))
            {
                listener.notifyFieldChange(this, other, FIELD_MessageContent, HELPER_MessageContent.toObject(this._MessageContent), HELPER_MessageContent.toObject(otherSentEmail._MessageContent));
            }
            if (!HELPER_EmailTo.compare(this._EmailTo, otherSentEmail._EmailTo))
            {
                listener.notifyFieldChange(this, other, FIELD_EmailTo, HELPER_EmailTo.toObject(this._EmailTo), HELPER_EmailTo.toObject(otherSentEmail._EmailTo));
            }

            // Compare single assocs
            _JobApplication.compare (otherSentEmail._JobApplication, listener);
            

            // Compare multiple assocs
            
        }
    }


    public void visitTransients (AttributeVisitor visitor) throws StorageException
    {
        super.visitAttributes (visitor);

        
    }


    public void visitAttributes (AttributeVisitor visitor) throws StorageException
    {
        super.visitAttributes (visitor);

        visitor.visitField(this, FIELD_Subject, HELPER_Subject.toObject(getSubject()));
        visitor.visitField(this, FIELD_SentDate, HELPER_SentDate.toObject(getSentDate()));
        visitor.visitField(this, FIELD_ApplicationStatus, HELPER_ApplicationStatus.toObject(getApplicationStatus()));
        visitor.visitField(this, FIELD_MessageContent, HELPER_MessageContent.toObject(getMessageContent()));
        visitor.visitField(this, FIELD_EmailTo, HELPER_EmailTo.toObject(getEmailTo()));
        visitor.visitAssociation (_JobApplication);
        
    }


    public void visitAssociations (AssociationVisitor visitor, AssociatedScope scope) throws StorageException
    {
        super.visitAssociations (visitor, scope);

        if (scope.includes (_JobApplication))
        {
            visitor.visit (_JobApplication);
        }
        
    }


    public static SentEmail createSentEmail (ObjectTransaction transaction) throws StorageException
    {
        SentEmail     result = new SentEmail ();

        result.initialiseNewObject (transaction);

        return result;
    }


    public static SentEmail getSentEmailByID (ObjectTransaction transaction, Long objectID) throws StorageException
    {
        return (SentEmail)(transaction.getObjectByID (REFERENCE_SentEmail, objectID));
    }

    public boolean testFilter (String attribName, QueryFilter filter) throws StorageException
    {
        if (false)
        {
            throw new RuntimeException ("Game over man!!");
        }
        else if (attribName.equals (FIELD_Subject))
        {
            return filter.matches (getSubject ());
        }
        else if (attribName.equals (FIELD_SentDate))
        {
            return filter.matches (getSentDate ());
        }
        else if (attribName.equals (FIELD_ApplicationStatus))
        {
            return filter.matches (getApplicationStatus ());
        }
        else if (attribName.equals (FIELD_MessageContent))
        {
            return filter.matches (getMessageContent ());
        }
        else if (attribName.equals (FIELD_EmailTo))
        {
            return filter.matches (getEmailTo ());
        }
        else if (attribName.equals (SINGLEREFERENCE_JobApplication))
        {
            return filter.matches (getJobApplication ());
        }
        else
        {
            return super.testFilter (attribName, filter);
        }
    }


    public static SearchAll SearchByAll () { return new SearchAll (); }

    public static class SearchAll extends SearchObject<SentEmail>
    {
        public SearchAll andObjectID (QueryFilter<Long> filter)
        {
            filter.addFilter (context, "tl_sent_email.object_id", FIELD_ObjectID);
            return this;
        }

        public SearchAll andObjectCreated (QueryFilter<Date> filter)
        {
            filter.addFilter (context, "tl_sent_email.object_created_date", FIELD_ObjectCreated);
            return this;
        }

        public SearchAll andObjectLastModified (QueryFilter<Date> filter)
        {
            filter.addFilter (context, "tl_sent_email.object_last_updated_date", FIELD_ObjectLastModified);
            return this;
        }

            
        public SearchAll andSubject (QueryFilter<String> filter)
        {
            filter.addFilter (context, "tl_sent_email.subject", "Subject");
            return this;
        }
            
        public SearchAll andSentDate (QueryFilter<Date> filter)
        {
            filter.addFilter (context, "tl_sent_email.sent_date", "SentDate");
            return this;
        }
            
        public SearchAll andApplicationStatus (QueryFilter<ApplicationStatus> filter)
        {
            filter.addFilter (context, "tl_sent_email.application_status", "ApplicationStatus");
            return this;
        }
            
        public SearchAll andMessageContent (QueryFilter<String> filter)
        {
            filter.addFilter (context, "tl_sent_email.message_content", "MessageContent");
            return this;
        }
            
        public SearchAll andEmailTo (QueryFilter<String> filter)
        {
            filter.addFilter (context, "tl_sent_email.email_to", "EmailTo");
            return this;
        }
            
        public SearchAll andJobApplication (QueryFilter<JobApplication> filter)
        {
            filter.addFilter (context, "tl_sent_email.job_application_id", "JobApplication");
            return this;
        }
            
        public SentEmail[] search (ObjectTransaction transaction) throws StorageException
        {
            
            BaseBusinessClass[]     results = super.search (transaction, REFERENCE_SentEmail, SEARCH_All, criteria);
            Set<SentEmail>   typedResults = new LinkedHashSet <SentEmail> ();
            for (BaseBusinessClass bbcResult : results)
            {
                SentEmail aResult = (SentEmail)bbcResult;
                
                typedResults.add (aResult);
            }
            
            return ObjstoreUtils.removeDeleted(transaction, typedResults).toArray (new SentEmail[0]);
                            
        }
    }

        
    public static SentEmail[] searchAll (ObjectTransaction transaction) throws StorageException
    {
        return SearchByAll ()
               .search (transaction);
    }



    public Object getAttribute (String attribName)
    {
        if (false)
        {
            throw new RuntimeException ("Game over man!!");
        }
        else if (attribName.equals (FIELD_Subject))
        {
            return HELPER_Subject.toObject (getSubject ());
        }
        else if (attribName.equals (FIELD_SentDate))
        {
            return HELPER_SentDate.toObject (getSentDate ());
        }
        else if (attribName.equals (FIELD_ApplicationStatus))
        {
            return HELPER_ApplicationStatus.toObject (getApplicationStatus ());
        }
        else if (attribName.equals (FIELD_MessageContent))
        {
            return HELPER_MessageContent.toObject (getMessageContent ());
        }
        else if (attribName.equals (FIELD_EmailTo))
        {
            return HELPER_EmailTo.toObject (getEmailTo ());
        }
        else
        {
            return super.getAttribute (attribName);
        }
    }


    public AttributeHelper getAttributeHelper (String attribName)
    {
        if (false)
        {
            throw new RuntimeException ("Game over man!!");
        }
        else if (attribName.equals (FIELD_Subject))
        {
            return HELPER_Subject;
        }
        else if (attribName.equals (FIELD_SentDate))
        {
            return HELPER_SentDate;
        }
        else if (attribName.equals (FIELD_ApplicationStatus))
        {
            return HELPER_ApplicationStatus;
        }
        else if (attribName.equals (FIELD_MessageContent))
        {
            return HELPER_MessageContent;
        }
        else if (attribName.equals (FIELD_EmailTo))
        {
            return HELPER_EmailTo;
        }
        else
        {
            return super.getAttributeHelper (attribName);
        }
    }


    public void setAttribute (String attribName, Object attribValue) throws FieldException
    {
        if (false)
        {
            throw new RuntimeException ("Game over man!!");
        }
        else if (attribName.equals (FIELD_Subject))
        {
            setSubject ((String)(HELPER_Subject.fromObject (_Subject, attribValue)));            
        }
        else if (attribName.equals (FIELD_SentDate))
        {
            setSentDate ((Date)(HELPER_SentDate.fromObject (_SentDate, attribValue)));            
        }
        else if (attribName.equals (FIELD_ApplicationStatus))
        {
            setApplicationStatus ((ApplicationStatus)(HELPER_ApplicationStatus.fromObject (_ApplicationStatus, attribValue)));            
        }
        else if (attribName.equals (FIELD_MessageContent))
        {
            setMessageContent ((String)(HELPER_MessageContent.fromObject (_MessageContent, attribValue)));            
        }
        else if (attribName.equals (FIELD_EmailTo))
        {
            setEmailTo ((String)(HELPER_EmailTo.fromObject (_EmailTo, attribValue)));            
        }
        else
        {
            super.setAttribute (attribName, attribValue);
        }
    }

    

    public boolean isWriteable (String fieldName)
    {        
        return getWriteable (fieldName) == FieldWriteability.TRUE;
    }

    public boolean isReadable ()
    {
        return super.isReadable();
    }

    public boolean isReadable (String fieldName)
    {
        return super.isReadable(fieldName);
    }


    public FieldWriteability getWriteable (String fieldName)
    {
        if (false)
        {
            throw new RuntimeException ("Game over man!!");
        }
        else if (fieldName.equals (FIELD_Subject))
        {
            return getWriteability_Subject ();
        }
        else if (fieldName.equals (FIELD_SentDate))
        {
            return getWriteability_SentDate ();
        }
        else if (fieldName.equals (FIELD_ApplicationStatus))
        {
            return getWriteability_ApplicationStatus ();
        }
        else if (fieldName.equals (FIELD_MessageContent))
        {
            return getWriteability_MessageContent ();
        }
        else if (fieldName.equals (FIELD_EmailTo))
        {
            return getWriteability_EmailTo ();
        }
        else if (fieldName.equals (SINGLEREFERENCE_JobApplication))
        {
            return getWriteability_JobApplication ();
        }
        else
        {
            return super.getWriteable (fieldName);
        }
    }


    public void putUnwriteable (Set<String> fields)
    {
        if (getWriteability_Subject () != FieldWriteability.TRUE)
        {
            fields.add (FIELD_Subject);
        }
        
        if (getWriteability_SentDate () != FieldWriteability.TRUE)
        {
            fields.add (FIELD_SentDate);
        }
        
        if (getWriteability_ApplicationStatus () != FieldWriteability.TRUE)
        {
            fields.add (FIELD_ApplicationStatus);
        }
        
        if (getWriteability_MessageContent () != FieldWriteability.TRUE)
        {
            fields.add (FIELD_MessageContent);
        }
        
        if (getWriteability_EmailTo () != FieldWriteability.TRUE)
        {
            fields.add (FIELD_EmailTo);
        }
        

        super.putUnwriteable (fields);
    }

    public String[] getAllTableNames()
    {
        return new String[] {"tl_sent_email"};
    }
    
    public boolean isPolymorphic(String tableName)
    {
        return super.isPolymorphic(tableName);
    }


    public List<AbstractAttribute> getAttributes ()
    {
        List result = super.getAttributes ();

        
        result.add(HELPER_Subject.getAttribObject (getClass (), _Subject, true, FIELD_Subject));
        result.add(HELPER_SentDate.getAttribObject (getClass (), _SentDate, true, FIELD_SentDate));
        result.add(HELPER_ApplicationStatus.getAttribObject (getClass (), _ApplicationStatus, true, FIELD_ApplicationStatus));
        result.add(HELPER_MessageContent.getAttribObject (getClass (), _MessageContent, true, FIELD_MessageContent));
        result.add(HELPER_EmailTo.getAttribObject (getClass (), _EmailTo, true, FIELD_EmailTo));

        return result;
    }


    public Map getAttributeMetadata (String attribute)
    {
        if (ATTRIBUTES_METADATA_SentEmail.containsKey (attribute))
        {
            return (Map)ATTRIBUTES_METADATA_SentEmail.get (attribute);
        }
        else
        {
            return super.getAttributeMetadata (attribute);
        }
    }


    public Object getAttributeMetadata (String attribute, String metadata)
    {
        if (ATTRIBUTES_METADATA_SentEmail.containsKey (attribute))
        {
            return ((Map)ATTRIBUTES_METADATA_SentEmail.get (attribute)).get(metadata);
        }
        else
        {
            return super.getAttributeMetadata (attribute, metadata);
        }
    }

    public void copyAllAttributeMetadata (Map copyInto)
    {
        super.copyAllAttributeMetadata(copyInto);

        copyInto.putAll(ATTRIBUTES_METADATA_SentEmail);
    }
            

    public void preCommit (boolean willBeStored) throws Exception
    {
        super.preCommit(willBeStored);
        
        if(willBeStored)
        {
        
        }
    }

    public oneit.servlets.objstore.binary.BinaryContentHandler getBinaryContentHandler(String attribName)
    {
        
        return super.getBinaryContentHandler(attribName);
    }

    public static class SentEmailBehaviourDecorator extends BaseBusinessClass.BBCBehaviourDecorator<SentEmail>
    {

    /**
     * Get the attribute Subject
     */
    public String getSubject (SentEmail obj, String original)
    {
        return original;
    }

    /**
     * Change the value set for attribute Subject.
     * May modify the field beforehand
     * Occurs before validation.
     */
    public String setSubject (SentEmail obj, String newSubject) throws FieldException
    {
        return newSubject;
    }

    /**
     * Get the attribute SentDate
     */
    public Date getSentDate (SentEmail obj, Date original)
    {
        return original;
    }

    /**
     * Change the value set for attribute SentDate.
     * May modify the field beforehand
     * Occurs before validation.
     */
    public Date setSentDate (SentEmail obj, Date newSentDate) throws FieldException
    {
        return newSentDate;
    }

    /**
     * Get the attribute ApplicationStatus
     */
    public ApplicationStatus getApplicationStatus (SentEmail obj, ApplicationStatus original)
    {
        return original;
    }

    /**
     * Change the value set for attribute ApplicationStatus.
     * May modify the field beforehand
     * Occurs before validation.
     */
    public ApplicationStatus setApplicationStatus (SentEmail obj, ApplicationStatus newApplicationStatus) throws FieldException
    {
        return newApplicationStatus;
    }

    /**
     * Get the attribute MessageContent
     */
    public String getMessageContent (SentEmail obj, String original)
    {
        return original;
    }

    /**
     * Change the value set for attribute MessageContent.
     * May modify the field beforehand
     * Occurs before validation.
     */
    public String setMessageContent (SentEmail obj, String newMessageContent) throws FieldException
    {
        return newMessageContent;
    }

    /**
     * Get the attribute EmailTo
     */
    public String getEmailTo (SentEmail obj, String original)
    {
        return original;
    }

    /**
     * Change the value set for attribute EmailTo.
     * May modify the field beforehand
     * Occurs before validation.
     */
    public String setEmailTo (SentEmail obj, String newEmailTo) throws FieldException
    {
        return newEmailTo;
    }

    }

    @Override
    public ORMPipeLine pipes()
    {
        return new SentEmailPipeLineFactory<SentEmail, SentEmail> ((SentEmail)this);
    }

    @Override
    public ORMPipeLine pipes(Collection _items)
    {
        return pipesSentEmail(_items);
    }
      
    /**
     * Use this instead of pipes() to get rid of type casting.
     */  
    public SentEmailPipeLineFactory<SentEmail, SentEmail> pipelineSentEmail()
    {
        return (SentEmailPipeLineFactory<SentEmail, SentEmail>) pipes();
    }
    
    public static SentEmailPipeLineFactory<SentEmail, SentEmail> pipesSentEmail(Collection<SentEmail> items)
    {
        return REFERENCE_SentEmail.new SentEmailPipeLineFactory<SentEmail, SentEmail> (items);
    }
    
    public static SentEmailPipeLineFactory<SentEmail, SentEmail> pipesSentEmail(SentEmail[] _items)
    {
        return pipesSentEmail(Arrays.asList (_items));
    }
    
    public static SentEmailPipeLineFactory<SentEmail, SentEmail> pipesSentEmail()
    {
        return pipesSentEmail((Collection)null);
    }
    
    
    public class SentEmailPipeLineFactory<From extends BaseBusinessClass, Me extends SentEmail> extends BaseBusinessClass.ORMPipeLine<From, Me>    
    {
        public <Prev> SentEmailPipeLineFactory (PipeLine<From, Prev> pipeLine, Pipe<Prev, Me> nextPipe)
        {
            super (pipeLine, nextPipe);
        }
        
        public SentEmailPipeLineFactory (From seed)
        {
            super(seed);
        }

        public SentEmailPipeLineFactory (Collection<From> seed)
        {
            super(seed);
        }
        
        
        public PipeLine<From, ? extends Object> to(String name)
        {
            if (name.equals ("Subject"))
            {
                return toSubject ();
            }                
            if (name.equals ("SentDate"))
            {
                return toSentDate ();
            }                
            if (name.equals ("ApplicationStatus"))
            {
                return toApplicationStatus ();
            }                
            if (name.equals ("MessageContent"))
            {
                return toMessageContent ();
            }                
            if (name.equals ("EmailTo"))
            {
                return toEmailTo ();
            }                
            if (name.equals ("JobApplication"))
            {
                return toJobApplication ();
            }                
            
            
            return super.to(name);
        }
        
        
        public PipeLine<From, String> toSubject () { return pipe(new ORMAttributePipe<Me, String>(FIELD_Subject));  }
        
        public PipeLine<From, Date> toSentDate () { return pipe(new ORMAttributePipe<Me, Date>(FIELD_SentDate));  }
        
        public ApplicationStatus.ApplicationStatusPipeLineFactory<From, ApplicationStatus> toApplicationStatus () 
        { 
            return new ApplicationStatus.ApplicationStatusPipeLineFactory<> (this, new ORMAttributePipe<>(FIELD_ApplicationStatus));
        }
        
        public PipeLine<From, String> toMessageContent () { return pipe(new ORMAttributePipe<Me, String>(FIELD_MessageContent));  }
        
        public PipeLine<From, String> toEmailTo () { return pipe(new ORMAttributePipe<Me, String>(FIELD_EmailTo));  }

        public JobApplication.JobApplicationPipeLineFactory<From, JobApplication> toJobApplication () { return toJobApplication (Filter.ALL); }

        public JobApplication.JobApplicationPipeLineFactory<From, JobApplication> toJobApplication (Filter<JobApplication> filter) 
        { 
            return JobApplication.REFERENCE_JobApplication.new JobApplicationPipeLineFactory<From, JobApplication> (this, new ORMSingleAssocPipe<Me, JobApplication>(SINGLEREFERENCE_JobApplication, filter)); 
        }
    }
    
    public boolean isTransientAttrib(String attribName)
    {
        

        return super.isTransientAttrib(attribName);
    }

    public boolean isTransientSingleReference(String assocName)
    {
        

        return super.isTransientSingleReference(assocName);
    }
}

class DummySentEmail extends SentEmail
{
    // Default constructor primarily to support Externalisable
    public DummySentEmail()
    {
        super();
    }

    public void assertValid ()
    {
    }


    public JobApplication getJobApplication () throws StorageException
    {
        return (JobApplication)(JobApplication.DUMMY_JobApplication);
    }


    /**
     * Get the object id for the referenced object.  Does not force a DB access.
     */
    public Long getJobApplicationID ()
    {
        return JobApplication.DUMMY_JobApplication.getObjectID();
    }

}

    
