/*
 * 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 oneit.security.*;


public abstract class BaseNote extends BaseBusinessClass
{
    // Reference instance for the object
    public static final Note REFERENCE_Note = new Note ();

    // Reference instance for the object
    public static final Note DUMMY_Note = new DummyNote ();

    // Static constants corresponding to field names
    
    public static final String FIELD_Comment = "Comment";
    public static final String SINGLEREFERENCE_CreatedUser = "CreatedUser";
    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<Note> HELPER_Comment = DefaultAttributeHelper.INSTANCE;
    

    // Private attributes corresponding to business object data
    private String _Comment;
    

    // Private attributes corresponding to single references
    private SingleAssociation<Note, CompanyUser> _CreatedUser;
    private SingleAssociation<Note, JobApplication> _JobApplication;
    

    // Private attributes corresponding to multiple references
    

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

    // Arrays of validators for each attribute
    private static final AttributeValidator[] FIELD_Comment_Validators;
    

    // Arrays of AttributeDecorators for each attribute
    private static final AttributeDecorator<Note, String>[] FIELD_Comment_Decorators;
    
    
    // Arrays of SingleAssocDecorators for each attribute
    private static final SingleAssocDecorator<Note, CompanyUser>[] SINGLEREFERENCE_CreatedUser_Decorators;
    private static final SingleAssocDecorator<Note, JobApplication>[] SINGLEREFERENCE_JobApplication_Decorators;
    
    
    // Arrays of MultiAssocDecorators for each attribute
    

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

            setupAssocMetaData_CreatedUser();
            setupAssocMetaData_JobApplication();
            FIELD_Comment_Validators = (AttributeValidator[])setupAttribMetaData_Comment(validatorMapping).toArray (new AttributeValidator[0]);
            FIELD_Comment_Decorators = (AttributeDecorator[])AttributeDecoratorUtils.getAttributeDecorators(REFERENCE_Note, FIELD_Comment).toArray (new AttributeDecorator[0]);
            SINGLEREFERENCE_CreatedUser_Decorators = (SingleAssocDecorator[])AttributeDecoratorUtils.getSingleAssocDecorators(REFERENCE_Note, SINGLEREFERENCE_CreatedUser).toArray (new SingleAssocDecorator[0]);
            SINGLEREFERENCE_JobApplication_Decorators = (SingleAssocDecorator[])AttributeDecoratorUtils.getSingleAssocDecorators(REFERENCE_Note, SINGLEREFERENCE_JobApplication).toArray (new SingleAssocDecorator[0]);
            

            REFERENCE_Note.initialiseReference ();
            DUMMY_Note.initialiseReference ();
            Note_BehaviourDecorators = BaseBusinessClass.getBBCBehaviours(Note.class).toArray(new NoteBehaviourDecorator[0]);
        }
        catch (RuntimeException e)
        {
            LogMgr.log (BUSINESS_OBJECTS, LogLevel.SYSTEMERROR1, e, "Error initialising");
            throw e;
        }
    }

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

        metaInfo.put ("dbcol", "created_user_id");
        metaInfo.put ("mandatory", "true");
        metaInfo.put ("name", "CreatedUser");
        metaInfo.put ("type", "CompanyUser");
        metaInfo.put (METADATA_DB_TABLENAME, "tl_note");
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for Note.CreatedUser:", metaInfo);
        ATTRIBUTES_METADATA_Note.put (SINGLEREFERENCE_CreatedUser, Collections.unmodifiableMap (metaInfo));
    }
    
    
    private static void setupAssocMetaData_JobApplication()
    {
        Map metaInfo = new HashMap ();

        metaInfo.put ("backreferenceName", "Notes");
        metaInfo.put ("dbcol", "job_application_id");
        metaInfo.put ("mandatory", "true");
        metaInfo.put ("name", "JobApplication");
        metaInfo.put ("type", "JobApplication");
        metaInfo.put (METADATA_DB_TABLENAME, "tl_note");
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for Note.JobApplication:", metaInfo);
        ATTRIBUTES_METADATA_Note.put (SINGLEREFERENCE_JobApplication, Collections.unmodifiableMap (metaInfo));
    }
    
    
    private static List setupAttribMetaData_Comment(Map validatorMapping)
    {
        Map  metaInfo   = new HashMap ();

        metaInfo.put ("dbcol", "comment");
        metaInfo.put ("length", "1000");
        metaInfo.put ("mandatory", "true");
        metaInfo.put ("name", "Comment");
        metaInfo.put ("type", "String");
        metaInfo.put (METADATA_DB_TABLENAME, "tl_note");
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for Note.Comment:", metaInfo);
        ATTRIBUTES_METADATA_Note.put (FIELD_Comment, Collections.unmodifiableMap (metaInfo));

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

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


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

    


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

        
        _Comment = (String)(HELPER_Comment.initialise (_Comment));
    }


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

        _CreatedUser = new SingleAssociation<Note, CompanyUser> (this, SINGLEREFERENCE_CreatedUser, null, CompanyUser.REFERENCE_CompanyUser, "tl_note");
        _JobApplication = new SingleAssociation<Note, JobApplication> (this, SINGLEREFERENCE_JobApplication, JobApplication.MULTIPLEREFERENCE_Notes, JobApplication.REFERENCE_JobApplication, "tl_note");
        
    }


    protected BaseBusinessClass initialiseReference ()
    {
        super.initialiseReference ();
        
        _CreatedUser = new SingleAssociation<Note, CompanyUser> (this, SINGLEREFERENCE_CreatedUser, null, CompanyUser.REFERENCE_CompanyUser, "tl_note");
        _JobApplication = new SingleAssociation<Note, JobApplication> (this, SINGLEREFERENCE_JobApplication, JobApplication.MULTIPLEREFERENCE_Notes, JobApplication.REFERENCE_JobApplication, "tl_note");
        
        
        return this;
    }


    /**
     * Attribute Comment
     */
    public String getComment ()
    {
        assertValid();
        String valToReturn = AttributeDecoratorUtils.getValue (FIELD_Comment_Decorators, (Note)this, FIELD_Comment, _Comment);

        
        for (NoteBehaviourDecorator bhd : Note_BehaviourDecorators)
        {
            valToReturn = bhd.getComment ((Note)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 preCommentChange (String newComment) 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 postCommentChange () throws FieldException
    {
    }

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

    /**
     * Set the attribute Comment.  Checks to ensure a new value
     * has been supplied.  If so, marks the field as altered and sets the attribute.
     */
    public void setComment (String newComment) throws FieldException
    {
        newComment = AttributeDecoratorUtils.setValue (FIELD_Comment_Decorators, (Note)this, FIELD_Comment, newComment);

        boolean oldAndNewIdentical = HELPER_Comment.compare (_Comment, newComment);
        
        try
        {
            for (NoteBehaviourDecorator bhd : Note_BehaviourDecorators)
            {
                newComment = bhd.setComment ((Note)this, newComment);
                oldAndNewIdentical = HELPER_Comment.compare (_Comment, newComment);
            }

            BusinessObjectParser.assertFieldCondition (newComment != null, this, FIELD_Comment, "mandatory");
            

            if (FIELD_Comment_Validators.length > 0)
            {
                Object newCommentObj = HELPER_Comment.toObject (newComment);

                if (newCommentObj != null)
                {
                    int     loopMax = FIELD_Comment_Validators.length;
                    Map     metadata = (Map)ATTRIBUTES_METADATA_Note.get (FIELD_Comment);

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

        if (!oldAndNewIdentical)
        {
            assertValid();
            Debug.assertion (AttributeDecoratorUtils.getWriteability (FIELD_Comment_Decorators, (Note)this, FIELD_Comment ,getWriteability_Comment ()) != FieldWriteability.FALSE, "Field  Comment is not writeable");
            preCommentChange (newComment);
            markFieldChange (FIELD_Comment);
            _Comment = newComment;            
            postFieldChange (FIELD_Comment);
            postCommentChange ();
        }
    }



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

        return result;
    }
    
    
    public BaseBusinessClass getSingleAssocReferenceInstance (String assocName)
    {
        if (assocName == null)
        {
            throw new RuntimeException ("Game over == null!");
        }
        else if (assocName.equals (SINGLEREFERENCE_CreatedUser))
        {
            return _CreatedUser.getReferencedType ();
        }
        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_CreatedUser))
        {
            return null ;
        }
        else if (assocName.equals (SINGLEREFERENCE_JobApplication))
        {
            return JobApplication.MULTIPLEREFERENCE_Notes ;
        }
        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_CreatedUser))
        {
            return getCreatedUser ();
        }
        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_CreatedUser))
        {
            return getCreatedUser (getType);
        }
        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_CreatedUser))
        {
            return getCreatedUserID ();
        }
        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_CreatedUser))
        {
            setCreatedUser ((CompanyUser)(newValue));
        }
        else if (assocName.equals (SINGLEREFERENCE_JobApplication))
        {
            setJobApplication ((JobApplication)(newValue));
        }
        else
        {
            super.setSingleAssoc (assocName, newValue);
        }
    }



    /**
     * Get the reference CreatedUser
     */
    public CompanyUser getCreatedUser () throws StorageException
    {
        assertValid();
        
        try
        {
            return (CompanyUser)(_CreatedUser.get ());
        }
        catch (ClassCastException e)
        {
            LogMgr.log (BUSINESS_OBJECTS, LogLevel.SYSTEMERROR2, "Cache collision in Note:", this.getObjectID (), ", was trying to get CompanyUser:",  getCreatedUserID ());
            LogMgr.log (BUSINESS_OBJECTS, LogLevel.SYSTEMERROR2, "Instead I got:", _CreatedUser.get ().getClass ());
            throw e;
        }
    }


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


    /**
     * Get the object id for the referenced object.  Does not force a DB access.
     */
    public Long getCreatedUserID ()
    {
        assertValid();
        
        if (_CreatedUser == null)
        {
            return null;
        }
        else
        {
            return _CreatedUser.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 preCreatedUserChange (CompanyUser newCreatedUser) 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 postCreatedUserChange () throws FieldException
    {
    }


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

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

        if (_CreatedUser.wouldReferencedChange (newCreatedUser))
        {
            assertValid();
            Debug.assertion (AttributeDecoratorUtils.getWriteability (SINGLEREFERENCE_CreatedUser_Decorators, (Note)this, SINGLEREFERENCE_CreatedUser ,getWriteability_CreatedUser ()) != FieldWriteability.FALSE, "Assoc CreatedUser is not writeable");
            preCreatedUserChange (newCreatedUser);
            
            _CreatedUser.set (newCreatedUser);
                
            postCreatedUserChange ();
        }
    }

    /**
     * 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 Note:", 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, (Note)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.removeFromNotes ((Note)(this));
            }

            _JobApplication.set (newJobApplication);

            if (newJobApplication != null)
            {
                newJobApplication.addToNotes ((Note)(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 Notes from ", getObjectID (), " to ", referenced.getObjectID ());
                    _JobApplication.set (null);
                    referenced.removeFromNotes ((Note)this);
                }
            }
        
        }
        catch (Exception e)
        {
            throw NestedException.wrap(e);
        }

        super.onDelete ();
    }


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


    public Note referenceInstance ()
    {
        return REFERENCE_Note;
    }


    public Note getInTransaction (ObjectTransaction t) throws StorageException
    {
        return getNoteByID (t, getObjectID());
    }
    
    
    public BaseBusinessClass dummyInstance ()
    {
        return DUMMY_Note;
    }


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



    /**
     * 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_notePSet = allSets.getPersistentSet (myID, "tl_note", myPSetStatus);

        tl_notePSet.setAttrib (FIELD_ObjectID, myID);
        tl_notePSet.setAttrib (FIELD_Comment, HELPER_Comment.toObject (_Comment)); //
        _CreatedUser.getPersistentSets (allSets);
        _JobApplication.getPersistentSets (allSets);
        
    }


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

        _Comment = (String)(HELPER_Comment.fromObject (_Comment, tl_notePSet.getAttrib (FIELD_Comment))); //
        _CreatedUser.setFromPersistentSets (objectID, allSets);
        _JobApplication.setFromPersistentSets (objectID, allSets);
        
    }


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

        if (other instanceof Note)
        {
            Note otherNote = (Note)other;
            

            try
            {
                setComment (otherNote.getComment ());
            }
            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 BaseNote)
        {
            BaseNote sourceNote = (BaseNote)(source);

            _Comment = sourceNote._Comment;
            
        }
    }


    /**
     * 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 BaseNote)
        {
            BaseNote sourceNote = (BaseNote)(source);

            _CreatedUser.copyFrom (sourceNote._CreatedUser, linkToGhosts);
            _JobApplication.copyFrom (sourceNote._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 BaseNote)
        {
            BaseNote sourceNote = (BaseNote)(source);

            
        }
    }


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

        
        context.check (getCreatedUserID() != null, this, SINGLEREFERENCE_CreatedUser, "mandatory");
        
        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);

        _Comment = (String)(HELPER_Comment.readExternal (_Comment, vals.get(FIELD_Comment))); //
        _CreatedUser.readExternalData(vals.get(SINGLEREFERENCE_CreatedUser));
        _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_Comment, HELPER_Comment.writeExternal (_Comment));
        vals.put (SINGLEREFERENCE_CreatedUser, _CreatedUser.writeExternalData());
        vals.put (SINGLEREFERENCE_JobApplication, _JobApplication.writeExternalData());
        
    }


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

        if (other instanceof BaseNote)
        {
            BaseNote otherNote = (BaseNote)(other);

            
            if (!HELPER_Comment.compare(this._Comment, otherNote._Comment))
            {
                listener.notifyFieldChange(this, other, FIELD_Comment, HELPER_Comment.toObject(this._Comment), HELPER_Comment.toObject(otherNote._Comment));
            }

            // Compare single assocs
            _CreatedUser.compare (otherNote._CreatedUser, listener);
            _JobApplication.compare (otherNote._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_Comment, HELPER_Comment.toObject(getComment()));
        visitor.visitAssociation (_CreatedUser);
        visitor.visitAssociation (_JobApplication);
        
    }


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

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


    public static Note createNote (ObjectTransaction transaction) throws StorageException
    {
        Note     result = new Note ();

        result.initialiseNewObject (transaction);

        return result;
    }


    public static Note getNoteByID (ObjectTransaction transaction, Long objectID) throws StorageException
    {
        return (Note)(transaction.getObjectByID (REFERENCE_Note, objectID));
    }

    public boolean testFilter (String attribName, QueryFilter filter) throws StorageException
    {
        if (false)
        {
            throw new RuntimeException ("Game over man!!");
        }
        else if (attribName.equals (FIELD_Comment))
        {
            return filter.matches (getComment ());
        }
        else if (attribName.equals (SINGLEREFERENCE_CreatedUser))
        {
            return filter.matches (getCreatedUser ());
        }
        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<Note>
    {
        public SearchAll andObjectID (QueryFilter<Long> filter)
        {
            filter.addFilter (context, "tl_note.object_id", FIELD_ObjectID);
            return this;
        }

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

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

            
        public SearchAll andComment (QueryFilter<String> filter)
        {
            filter.addFilter (context, "tl_note.comment", "Comment");
            return this;
        }
            
        public SearchAll andCreatedUser (QueryFilter<CompanyUser> filter)
        {
            filter.addFilter (context, "tl_note.created_user_id", "CreatedUser");
            return this;
        }
            
        public SearchAll andJobApplication (QueryFilter<JobApplication> filter)
        {
            filter.addFilter (context, "tl_note.job_application_id", "JobApplication");
            return this;
        }
            
        public Note[] search (ObjectTransaction transaction) throws StorageException
        {
            
            BaseBusinessClass[]     results = super.search (transaction, REFERENCE_Note, SEARCH_All, criteria);
            Set<Note>   typedResults = new LinkedHashSet <Note> ();
            for (BaseBusinessClass bbcResult : results)
            {
                Note aResult = (Note)bbcResult;
                
                typedResults.add (aResult);
            }
            
            return ObjstoreUtils.removeDeleted(transaction, typedResults).toArray (new Note[0]);
                            
        }
    }

        
    public static Note[] 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_Comment))
        {
            return HELPER_Comment.toObject (getComment ());
        }
        else
        {
            return super.getAttribute (attribName);
        }
    }


    public AttributeHelper getAttributeHelper (String attribName)
    {
        if (false)
        {
            throw new RuntimeException ("Game over man!!");
        }
        else if (attribName.equals (FIELD_Comment))
        {
            return HELPER_Comment;
        }
        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_Comment))
        {
            setComment ((String)(HELPER_Comment.fromObject (_Comment, 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_Comment))
        {
            return getWriteability_Comment ();
        }
        else if (fieldName.equals (SINGLEREFERENCE_CreatedUser))
        {
            return getWriteability_CreatedUser ();
        }
        else if (fieldName.equals (SINGLEREFERENCE_JobApplication))
        {
            return getWriteability_JobApplication ();
        }
        else
        {
            return super.getWriteable (fieldName);
        }
    }


    public void putUnwriteable (Set<String> fields)
    {
        if (getWriteability_Comment () != FieldWriteability.TRUE)
        {
            fields.add (FIELD_Comment);
        }
        

        super.putUnwriteable (fields);
    }

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


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

        
        result.add(HELPER_Comment.getAttribObject (getClass (), _Comment, true, FIELD_Comment));

        return result;
    }


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


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

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

        copyInto.putAll(ATTRIBUTES_METADATA_Note);
    }
            

    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 NoteBehaviourDecorator extends BaseBusinessClass.BBCBehaviourDecorator<Note>
    {

    /**
     * Get the attribute Comment
     */
    public String getComment (Note obj, String original)
    {
        return original;
    }

    /**
     * Change the value set for attribute Comment.
     * May modify the field beforehand
     * Occurs before validation.
     */
    public String setComment (Note obj, String newComment) throws FieldException
    {
        return newComment;
    }

    }

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

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

        public NotePipeLineFactory (Collection<From> seed)
        {
            super(seed);
        }
        
        
        public PipeLine<From, ? extends Object> to(String name)
        {
            if (name.equals ("Comment"))
            {
                return toComment ();
            }                
            if (name.equals ("CreatedUser"))
            {
                return toCreatedUser ();
            }                
            if (name.equals ("JobApplication"))
            {
                return toJobApplication ();
            }                
            
            
            return super.to(name);
        }
        
        
        public PipeLine<From, String> toComment () { return pipe(new ORMAttributePipe<Me, String>(FIELD_Comment));  }

        public CompanyUser.CompanyUserPipeLineFactory<From, CompanyUser> toCreatedUser () { return toCreatedUser (Filter.ALL); }

        public CompanyUser.CompanyUserPipeLineFactory<From, CompanyUser> toCreatedUser (Filter<CompanyUser> filter) 
        { 
            return CompanyUser.REFERENCE_CompanyUser.new CompanyUserPipeLineFactory<From, CompanyUser> (this, new ORMSingleAssocPipe<Me, CompanyUser>(SINGLEREFERENCE_CreatedUser, filter)); 
        }

        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 DummyNote extends Note
{
    // Default constructor primarily to support Externalisable
    public DummyNote()
    {
        super();
    }

    public void assertValid ()
    {
    }


    public CompanyUser getCreatedUser () throws StorageException
    {
        return (CompanyUser)(CompanyUser.DUMMY_CompanyUser);
    }


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

    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();
    }

}

