/*
 * IMPORTANT!!!! XSL Autogenerated class, DO NOT EDIT!!!!!
 * Template: Infrastructure8.2 rev3 [oneit.objstore.BusinessObjectTemplate.xsl]
 *
 *   Version: 1.0
 *   Vendor: Apache Software Foundation (Xalan XSLTC)
 *   Vendor URL: http://xml.apache.org/xalan-j
 */


    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;



public abstract class BaseHTDiversityQuestion extends BaseBusinessClass
{
    // Reference instance for the object
    public static final HTDiversityQuestion REFERENCE_HTDiversityQuestion = new HTDiversityQuestion ();

    // Reference instance for the object
    public static final HTDiversityQuestion DUMMY_HTDiversityQuestion = new DummyHTDiversityQuestion ();

    // Static constants corresponding to field names
    
    public static final String FIELD_QuestionText = "QuestionText";
    public static final String FIELD_IsApplicable = "IsApplicable";
    public static final String SINGLEREFERENCE_Question = "Question";
    public static final String SINGLEREFERENCE_HiringTeam = "HiringTeam";
    public static final String BACKREF_HiringTeam = "";

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

    // Static constants corresponding to attribute helpers
    private static final DefaultAttributeHelper<HTDiversityQuestion> HELPER_QuestionText = DefaultAttributeHelper.INSTANCE;
    private static final DefaultAttributeHelper<HTDiversityQuestion> HELPER_IsApplicable = DefaultAttributeHelper.INSTANCE;
    

    // Private attributes corresponding to business object data
    private String _QuestionText;
    private Boolean _IsApplicable;
    

    // Private attributes corresponding to single references
    private SingleAssociation<HTDiversityQuestion, DiversityQuestion> _Question;
    private SingleAssociation<HTDiversityQuestion, HiringTeam> _HiringTeam;
    

    // Private attributes corresponding to multiple references
    

    // Map of maps of metadata
    private static final Map ATTRIBUTES_METADATA_HTDiversityQuestion = new HashMap ();

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

    // Arrays of behaviour decorators
    private static final HTDiversityQuestionBehaviourDecorator[] HTDiversityQuestion_BehaviourDecorators;
    
    static
    {
        try
        {
            
            String tmp_HiringTeam = HiringTeam.BACKREF_DiversityQuestions;
            
            Map  validatorMapping = ((Map)ConfigMgr.getConfigObject ("CONFIG.ORMVALIDATOR", "ValidatorMapping"));

            setupAssocMetaData_Question();
            setupAssocMetaData_HiringTeam();
            FIELD_QuestionText_Validators = (AttributeValidator[])setupAttribMetaData_QuestionText(validatorMapping).toArray (new AttributeValidator[0]);
            FIELD_IsApplicable_Validators = (AttributeValidator[])setupAttribMetaData_IsApplicable(validatorMapping).toArray (new AttributeValidator[0]);
            

            REFERENCE_HTDiversityQuestion.initialiseReference ();
            DUMMY_HTDiversityQuestion.initialiseReference ();
            HTDiversityQuestion_BehaviourDecorators = BaseBusinessClass.getBBCBehaviours(HTDiversityQuestion.class).toArray(new HTDiversityQuestionBehaviourDecorator[0]);
        }
        catch (RuntimeException e)
        {
            LogMgr.log (BUSINESS_OBJECTS, LogLevel.SYSTEMERROR1, e, "Error initialising");
            throw e;
        }
    }

    
    // Meta Info setup
    private static void setupAssocMetaData_Question()
    {
        Map metaInfo = new HashMap ();

        metaInfo.put ("dbcol", "question_id");
        metaInfo.put ("mandatory", "true");
        metaInfo.put ("name", "Question");
        metaInfo.put ("type", "DiversityQuestion");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for HTDiversityQuestion.Question:", metaInfo);
        ATTRIBUTES_METADATA_HTDiversityQuestion.put (SINGLEREFERENCE_Question, Collections.unmodifiableMap (metaInfo));
    }
    
    
    // Meta Info setup
    private static void setupAssocMetaData_HiringTeam()
    {
        Map metaInfo = new HashMap ();

        metaInfo.put ("backreferenceName", "DiversityQuestions");
        metaInfo.put ("dbcol", "hiring_team_id");
        metaInfo.put ("mandatory", "true");
        metaInfo.put ("name", "HiringTeam");
        metaInfo.put ("type", "HiringTeam");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for HTDiversityQuestion.HiringTeam:", metaInfo);
        ATTRIBUTES_METADATA_HTDiversityQuestion.put (SINGLEREFERENCE_HiringTeam, Collections.unmodifiableMap (metaInfo));
    }
    
    
    // Meta Info setup
    private static List setupAttribMetaData_QuestionText(Map validatorMapping)
    {
        Map  metaInfo   = new HashMap ();

        metaInfo.put ("dbcol", "question_text");
        metaInfo.put ("mandatory", "true");
        metaInfo.put ("name", "QuestionText");
        metaInfo.put ("type", "String");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for HTDiversityQuestion.QuestionText:", metaInfo);
        ATTRIBUTES_METADATA_HTDiversityQuestion.put (FIELD_QuestionText, Collections.unmodifiableMap (metaInfo));

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

        return validators;
    }
    
    // Meta Info setup
    private static List setupAttribMetaData_IsApplicable(Map validatorMapping)
    {
        Map  metaInfo   = new HashMap ();

        metaInfo.put ("dbcol", "is_applicable");
        metaInfo.put ("defaultValue", "Boolean.TRUE");
        metaInfo.put ("name", "IsApplicable");
        metaInfo.put ("type", "Boolean");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for HTDiversityQuestion.IsApplicable:", metaInfo);
        ATTRIBUTES_METADATA_HTDiversityQuestion.put (FIELD_IsApplicable, Collections.unmodifiableMap (metaInfo));

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

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


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


    


    // Initialise the attributes
    protected void _initialiseNewObjAttributes (ObjectTransaction transaction) throws StorageException
    {
        super._initialiseNewObjAttributes (transaction);

        
        _QuestionText = (String)(HELPER_QuestionText.initialise (_QuestionText));
        _IsApplicable = (Boolean)(Boolean.TRUE);
    }


    // Initialise the associations
    protected void _initialiseAssociations ()
    {
        super._initialiseAssociations ();

        _Question = new SingleAssociation<HTDiversityQuestion, DiversityQuestion> (this, SINGLEREFERENCE_Question, null, DiversityQuestion.REFERENCE_DiversityQuestion, "tl_ht_diversity_question");
        _HiringTeam = new SingleAssociation<HTDiversityQuestion, HiringTeam> (this, SINGLEREFERENCE_HiringTeam, HiringTeam.MULTIPLEREFERENCE_DiversityQuestions, HiringTeam.REFERENCE_HiringTeam, "tl_ht_diversity_question");
        
    }


    // Initialise the associations
    protected BaseBusinessClass initialiseReference ()
    {
        super.initialiseReference ();
        
        _Question = new SingleAssociation<HTDiversityQuestion, DiversityQuestion> (this, SINGLEREFERENCE_Question, null, DiversityQuestion.REFERENCE_DiversityQuestion, "tl_ht_diversity_question");
        _HiringTeam = new SingleAssociation<HTDiversityQuestion, HiringTeam> (this, SINGLEREFERENCE_HiringTeam, HiringTeam.MULTIPLEREFERENCE_DiversityQuestions, HiringTeam.REFERENCE_HiringTeam, "tl_ht_diversity_question");
        
        
        return this;
    }

    

    /**
     * Get the attribute QuestionText
     */
    public String getQuestionText ()
    {
        assertValid();
        String valToReturn = _QuestionText;

            for (HTDiversityQuestionBehaviourDecorator bhd : HTDiversityQuestion_BehaviourDecorators)
            {
                valToReturn = bhd.getQuestionText ((HTDiversityQuestion)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 preQuestionTextChange (String newQuestionText) 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 postQuestionTextChange () throws FieldException
    {
    }

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

    /**
     * Set the attribute QuestionText.  Checks to ensure a new value
     * has been supplied.  If so, marks the field as altered and sets the attribute.
     */
    public void setQuestionText (String newQuestionText) throws FieldException
    {
        boolean oldAndNewIdentical = HELPER_QuestionText.compare (_QuestionText, newQuestionText);
        
        try
        {
            for (HTDiversityQuestionBehaviourDecorator bhd : HTDiversityQuestion_BehaviourDecorators)
            {
                newQuestionText = bhd.setQuestionText ((HTDiversityQuestion)this, newQuestionText);
                oldAndNewIdentical = HELPER_QuestionText.compare (_QuestionText, newQuestionText);
            }

            BusinessObjectParser.assertFieldCondition (newQuestionText != null, this, FIELD_QuestionText, "mandatory");
            

            if (FIELD_QuestionText_Validators.length > 0)
            {
                Object newQuestionTextObj = HELPER_QuestionText.toObject (newQuestionText);

                if (newQuestionTextObj != null)
                {
                    int     loopMax = FIELD_QuestionText_Validators.length;
                    Map     metadata = (Map)ATTRIBUTES_METADATA_HTDiversityQuestion.get (FIELD_QuestionText);

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

        if (!oldAndNewIdentical)
        {
            assertValid();
            Debug.assertion (getWriteability_QuestionText () != FieldWriteability.FALSE, "Field  QuestionText is not writeable");
            preQuestionTextChange (newQuestionText);
            markFieldChange (FIELD_QuestionText);
            _QuestionText = newQuestionText;            
            postFieldChange (FIELD_QuestionText);
            postQuestionTextChange ();
        }
    }

    /**
     * Get the attribute IsApplicable
     */
    public Boolean getIsApplicable ()
    {
        assertValid();
        Boolean valToReturn = _IsApplicable;

            for (HTDiversityQuestionBehaviourDecorator bhd : HTDiversityQuestion_BehaviourDecorators)
            {
                valToReturn = bhd.getIsApplicable ((HTDiversityQuestion)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 preIsApplicableChange (Boolean newIsApplicable) 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 postIsApplicableChange () throws FieldException
    {
    }

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

    /**
     * Set the attribute IsApplicable.  Checks to ensure a new value
     * has been supplied.  If so, marks the field as altered and sets the attribute.
     */
    public void setIsApplicable (Boolean newIsApplicable) throws FieldException
    {
        boolean oldAndNewIdentical = HELPER_IsApplicable.compare (_IsApplicable, newIsApplicable);
        
        try
        {
            for (HTDiversityQuestionBehaviourDecorator bhd : HTDiversityQuestion_BehaviourDecorators)
            {
                newIsApplicable = bhd.setIsApplicable ((HTDiversityQuestion)this, newIsApplicable);
                oldAndNewIdentical = HELPER_IsApplicable.compare (_IsApplicable, newIsApplicable);
            }

            

            if (FIELD_IsApplicable_Validators.length > 0)
            {
                Object newIsApplicableObj = HELPER_IsApplicable.toObject (newIsApplicable);

                if (newIsApplicableObj != null)
                {
                    int     loopMax = FIELD_IsApplicable_Validators.length;
                    Map     metadata = (Map)ATTRIBUTES_METADATA_HTDiversityQuestion.get (FIELD_IsApplicable);

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

        if (!oldAndNewIdentical)
        {
            assertValid();
            Debug.assertion (getWriteability_IsApplicable () != FieldWriteability.FALSE, "Field  IsApplicable is not writeable");
            preIsApplicableChange (newIsApplicable);
            markFieldChange (FIELD_IsApplicable);
            _IsApplicable = newIsApplicable;            
            postFieldChange (FIELD_IsApplicable);
            postIsApplicableChange ();
        }
    }



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

        
        result.add("Question");
        
        result.add("HiringTeam");
        

        return result;
    }
    
    
    public BaseBusinessClass getSingleAssocReferenceInstance (String assocName)
    {
        if (assocName == null)
        {
            throw new RuntimeException ("Game over == null!");
        }
        else if (assocName.equals (SINGLEREFERENCE_Question))
        {
            return _Question.getReferencedType ();
        }else if (assocName.equals (SINGLEREFERENCE_HiringTeam))
        {
            return _HiringTeam.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_Question))
        {
            return null ;
        }else if (assocName.equals (SINGLEREFERENCE_HiringTeam))
        {
            return HiringTeam.MULTIPLEREFERENCE_DiversityQuestions ;
        }
        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_Question))
        {
            return getQuestion ();
        }else if (assocName.equals (SINGLEREFERENCE_HiringTeam))
        {
            return getHiringTeam ();
        }
        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_Question))
        {
            return getQuestion (getType);
        }else if (assocName.equals (SINGLEREFERENCE_HiringTeam))
        {
            return getHiringTeam (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_Question))
        {
            return getQuestionID ();
        }else if (assocName.equals (SINGLEREFERENCE_HiringTeam))
        {
            return getHiringTeamID ();
        }
        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_Question))
        {
            setQuestion ((DiversityQuestion)(newValue));
        }else if (assocName.equals (SINGLEREFERENCE_HiringTeam))
        {
            setHiringTeam ((HiringTeam)(newValue));
        }
        else
        {
            super.setSingleAssoc (assocName, newValue);
        }
    }



    /**
     * Get the reference Question
     */
    public DiversityQuestion getQuestion () throws StorageException
    {
        assertValid();
        
        try
        {
            return (DiversityQuestion)(_Question.get ());
        }
        catch (ClassCastException e)
        {
            LogMgr.log (BUSINESS_OBJECTS, LogLevel.SYSTEMERROR2, "Cache collision in HTDiversityQuestion:", this.getObjectID (), ", was trying to get DiversityQuestion:",  getQuestionID ());
            LogMgr.log (BUSINESS_OBJECTS, LogLevel.SYSTEMERROR2, "Instead I got:", _Question.get ().getClass ());
            throw e;
        }
    }


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


    /**
     * Get the object id for the referenced object.  Does not force a DB access.
     */
    public Long getQuestionID ()
    {
        assertValid();
        
        if (_Question == null)
        {
            return null;
        }
        else
        {
            return _Question.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 preQuestionChange (DiversityQuestion newQuestion) 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 postQuestionChange () throws FieldException
    {
    }



    
    public FieldWriteability getWriteability_Question ()
    {
        return getFieldWritabilityUtil (FieldWriteability.TRUE);
    }
    
    
    /**
     * Set the reference Question.  Checks to ensure a new value
     * has been supplied.  If so, marks the reference as altered and sets it.
     */
    public void setQuestion (DiversityQuestion newQuestion) throws StorageException, FieldException
    {
        BusinessObjectParser.assertFieldCondition (newQuestion != null, this, SINGLEREFERENCE_Question, "mandatory");
        

        if (_Question.wouldReferencedChange (newQuestion))
        {
            assertValid();
            Debug.assertion (getWriteability_Question () != FieldWriteability.FALSE, "Assoc Question is not writeable");
            preQuestionChange (newQuestion);
            
                    _Question.set (newQuestion);
                
            postQuestionChange ();
        }
    }

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


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


    /**
     * Get the object id for the referenced object.  Does not force a DB access.
     */
    public Long getHiringTeamID ()
    {
        assertValid();
        
        if (_HiringTeam == null)
        {
            return null;
        }
        else
        {
            return _HiringTeam.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 preHiringTeamChange (HiringTeam newHiringTeam) 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 postHiringTeamChange () throws FieldException
    {
    }



    
    public FieldWriteability getWriteability_HiringTeam ()
    {
        return getFieldWritabilityUtil (FieldWriteability.TRUE);
    }
    
    
    /**
     * Set the reference HiringTeam.  Checks to ensure a new value
     * has been supplied.  If so, marks the reference as altered and sets it.
     */
    public void setHiringTeam (HiringTeam newHiringTeam) throws StorageException, FieldException
    {
        BusinessObjectParser.assertFieldCondition (newHiringTeam != null, this, SINGLEREFERENCE_HiringTeam, "mandatory");
        

        if (_HiringTeam.wouldReferencedChange (newHiringTeam))
        {
            assertValid();
            Debug.assertion (getWriteability_HiringTeam () != FieldWriteability.FALSE, "Assoc HiringTeam is not writeable");
            preHiringTeamChange (newHiringTeam);
            HiringTeam oldHiringTeam = getHiringTeam ();

                    if (oldHiringTeam != null)
                    {
                        // This is to stop validation from triggering when we are removed
                        _HiringTeam.set (null);
                        oldHiringTeam.removeFromDiversityQuestions ((HTDiversityQuestion)(this));
                    }

                    _HiringTeam.set (newHiringTeam);

                    if (newHiringTeam != null)
                    {
                        newHiringTeam.addToDiversityQuestions ((HTDiversityQuestion)(this));
                    }
                
            postHiringTeamChange ();
        }
    }

    /**
     * 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 (_HiringTeam.isLoaded () || getTransaction ().isObjectLoaded (_HiringTeam.getReferencedType (), getHiringTeamID ()))
            {
                HiringTeam  referenced = getHiringTeam ();

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

        super.onDelete ();
    }


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


    public HTDiversityQuestion referenceInstance ()
    {
        return REFERENCE_HTDiversityQuestion;
    }


    public HTDiversityQuestion getInTransaction (ObjectTransaction t) throws StorageException
    {
        return getHTDiversityQuestionByID (t, getObjectID());
    }
    
    
    public BaseBusinessClass dummyInstance ()
    {
        return DUMMY_HTDiversityQuestion;
    }


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





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

        tl_ht_diversity_questionPSet.setAttrib (FIELD_ObjectID, myID);
        tl_ht_diversity_questionPSet.setAttrib (FIELD_QuestionText, HELPER_QuestionText.toObject (_QuestionText)); //
        tl_ht_diversity_questionPSet.setAttrib (FIELD_IsApplicable, HELPER_IsApplicable.toObject (_IsApplicable)); //
        _Question.getPersistentSets (allSets);
        _HiringTeam.getPersistentSets (allSets);
        
    }


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

        
        PersistentSet   tl_ht_diversity_questionPSet = allSets.getPersistentSet (objectID, "tl_ht_diversity_question");

        _QuestionText = (String)(HELPER_QuestionText.fromObject (_QuestionText, tl_ht_diversity_questionPSet.getAttrib (FIELD_QuestionText))); //
        _IsApplicable = (Boolean)(HELPER_IsApplicable.fromObject (_IsApplicable, tl_ht_diversity_questionPSet.getAttrib (FIELD_IsApplicable))); //
        _Question.setFromPersistentSets (objectID, allSets);
        _HiringTeam.setFromPersistentSets (objectID, allSets);
        
    }





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

        if (other instanceof HTDiversityQuestion)
        {
            HTDiversityQuestion otherHTDiversityQuestion = (HTDiversityQuestion)other;
            
            try
            {
                setQuestionText (otherHTDiversityQuestion.getQuestionText ());
            }
            catch (FieldException ex)
            {
                e.addException (ex);
            }
            
            try
            {
                setIsApplicable (otherHTDiversityQuestion.getIsApplicable ());
            }
            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 BaseHTDiversityQuestion)
        {
            BaseHTDiversityQuestion sourceHTDiversityQuestion = (BaseHTDiversityQuestion)(source);

            _QuestionText = sourceHTDiversityQuestion._QuestionText;
            _IsApplicable = sourceHTDiversityQuestion._IsApplicable;
            
        }
    }


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

            _Question.copyFrom (sourceHTDiversityQuestion._Question, linkToGhosts);
            _HiringTeam.copyFrom (sourceHTDiversityQuestion._HiringTeam, 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 BaseHTDiversityQuestion)
        {
            BaseHTDiversityQuestion sourceHTDiversityQuestion = (BaseHTDiversityQuestion)(source);

            
        }
    }


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

        
        context.check (getQuestionID() != null, this, SINGLEREFERENCE_Question, "mandatory");
        
        context.check (getHiringTeamID() != null, this, SINGLEREFERENCE_HiringTeam, "mandatory");
        
    }


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

        _QuestionText = (String)(HELPER_QuestionText.readExternal (_QuestionText, vals.get(FIELD_QuestionText))); //
        _IsApplicable = (Boolean)(HELPER_IsApplicable.readExternal (_IsApplicable, vals.get(FIELD_IsApplicable))); //
        _Question.readExternalData(vals.get(SINGLEREFERENCE_Question));
        _HiringTeam.readExternalData(vals.get(SINGLEREFERENCE_HiringTeam));
        
    }


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

        vals.put (FIELD_QuestionText, HELPER_QuestionText.writeExternal (_QuestionText));
        vals.put (FIELD_IsApplicable, HELPER_IsApplicable.writeExternal (_IsApplicable));
        vals.put (SINGLEREFERENCE_Question, _Question.writeExternalData());
        vals.put (SINGLEREFERENCE_HiringTeam, _HiringTeam.writeExternalData());
        
    }


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

        if (other instanceof BaseHTDiversityQuestion)
        {
            BaseHTDiversityQuestion otherHTDiversityQuestion = (BaseHTDiversityQuestion)(other);

            
            if (!HELPER_QuestionText.compare(this._QuestionText, otherHTDiversityQuestion._QuestionText))
            {
                listener.notifyFieldChange(this, other, FIELD_QuestionText, HELPER_QuestionText.toObject(this._QuestionText), HELPER_QuestionText.toObject(otherHTDiversityQuestion._QuestionText));
            }
            if (!HELPER_IsApplicable.compare(this._IsApplicable, otherHTDiversityQuestion._IsApplicable))
            {
                listener.notifyFieldChange(this, other, FIELD_IsApplicable, HELPER_IsApplicable.toObject(this._IsApplicable), HELPER_IsApplicable.toObject(otherHTDiversityQuestion._IsApplicable));
            }

            // Compare single assocs
            _Question.compare (otherHTDiversityQuestion._Question, listener);
            _HiringTeam.compare (otherHTDiversityQuestion._HiringTeam, 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_QuestionText, HELPER_QuestionText.toObject(getQuestionText()));
        visitor.visitField(this, FIELD_IsApplicable, HELPER_IsApplicable.toObject(getIsApplicable()));
        visitor.visitAssociation (_Question);
        visitor.visitAssociation (_HiringTeam);
        
    }


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

        if (scope.includes (_Question))
        {
            visitor.visit (_Question);
        }
        if (scope.includes (_HiringTeam))
        {
            visitor.visit (_HiringTeam);
        }
        
    }


    public static HTDiversityQuestion createHTDiversityQuestion (ObjectTransaction transaction) throws StorageException
    {
        HTDiversityQuestion     result = new HTDiversityQuestion ();

        result.initialiseNewObject (transaction);

        return result;
    }


    public static HTDiversityQuestion getHTDiversityQuestionByID (ObjectTransaction transaction, Long objectID) throws StorageException
    {
        return (HTDiversityQuestion)(transaction.getObjectByID (REFERENCE_HTDiversityQuestion, objectID));
    }

    public boolean testFilter (String attribName, QueryFilter filter) throws StorageException
    {
        if (false)
        {
            throw new RuntimeException ("Game over man!!");
        }
        else if (attribName.equals (FIELD_QuestionText))
        {
            return filter.matches (getQuestionText ());
        }
        else if (attribName.equals (FIELD_IsApplicable))
        {
            return filter.matches (getIsApplicable ());
        }
        else if (attribName.equals (SINGLEREFERENCE_Question))
        {
            return filter.matches (getQuestion ());
        }
        else if (attribName.equals (SINGLEREFERENCE_HiringTeam))
        {
            return filter.matches (getHiringTeam ());
        }
        else
        {
            return super.testFilter (attribName, filter);
        }
    }


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

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

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

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

            
            public SearchAll andQuestionText (QueryFilter<String> filter)
            {
                filter.addFilter (context, "tl_ht_diversity_question.question_text", "QuestionText");
                return this;
            }
            
            public SearchAll andIsApplicable (QueryFilter<Boolean> filter)
            {
                filter.addFilter (context, "tl_ht_diversity_question.is_applicable", "IsApplicable");
                return this;
            }
            
            public SearchAll andQuestion (QueryFilter<DiversityQuestion> filter)
            {
                filter.addFilter (context, "tl_ht_diversity_question.question_id", "Question");
                return this;
            }
            
            public SearchAll andHiringTeam (QueryFilter<HiringTeam> filter)
            {
                filter.addFilter (context, "tl_ht_diversity_question.hiring_team_id", "HiringTeam");
                return this;
            }
            
                public HTDiversityQuestion[]
             search (ObjectTransaction transaction) throws StorageException
        {
            
            
            BaseBusinessClass[]     results = super.search (transaction, REFERENCE_HTDiversityQuestion, SEARCH_All, criteria);
            Set<HTDiversityQuestion>   typedResults = new LinkedHashSet <HTDiversityQuestion> ();
            for (BaseBusinessClass bbcResult : results)
            {
                HTDiversityQuestion aResult = (HTDiversityQuestion)bbcResult;
                
                typedResults.add (aResult);
            }
            
                    return ObjstoreUtils.removeDeleted(transaction, typedResults).toArray (new HTDiversityQuestion[0]);
                            
        }
    }

        
                public static HTDiversityQuestion[]
             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_QuestionText))
        {
            return HELPER_QuestionText.toObject (getQuestionText ());
        }
        else if (attribName.equals (FIELD_IsApplicable))
        {
            return HELPER_IsApplicable.toObject (getIsApplicable ());
        }
        else
        {
            return super.getAttribute (attribName);
        }
    }


    public AttributeHelper getAttributeHelper (String attribName)
    {
        if (false)
        {
            throw new RuntimeException ("Game over man!!");
        }
        else if (attribName.equals (FIELD_QuestionText))
        {
            return HELPER_QuestionText;
        }
        else if (attribName.equals (FIELD_IsApplicable))
        {
            return HELPER_IsApplicable;
        }
        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_QuestionText))
        {
            setQuestionText ((String)(HELPER_QuestionText.fromObject (_QuestionText, attribValue)));            
        }
        else if (attribName.equals (FIELD_IsApplicable))
        {
            setIsApplicable ((Boolean)(HELPER_IsApplicable.fromObject (_IsApplicable, attribValue)));            
        }
        else
        {
            super.setAttribute (attribName, attribValue);
        }
    }



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


    public FieldWriteability getWriteable (String fieldName)
    {
        if (false)
        {
            throw new RuntimeException ("Game over man!!");
        }
        else if (fieldName.equals (FIELD_QuestionText))
        {
            return getWriteability_QuestionText ();
        }
        else if (fieldName.equals (FIELD_IsApplicable))
        {
            return getWriteability_IsApplicable ();
        }
        else if (fieldName.equals (SINGLEREFERENCE_Question))
        {
            return getWriteability_Question ();
        }
        else if (fieldName.equals (SINGLEREFERENCE_HiringTeam))
        {
            return getWriteability_HiringTeam ();
        }
        else
        {
            return super.getWriteable (fieldName);
        }
    }


    public void putUnwriteable (Set<String> fields)
    {
        
            if (getWriteability_QuestionText () != FieldWriteability.TRUE)
            {
                fields.add (FIELD_QuestionText);
            }
        
            if (getWriteability_IsApplicable () != FieldWriteability.TRUE)
            {
                fields.add (FIELD_IsApplicable);
            }
        

        super.putUnwriteable (fields);
    }

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

        
        result.add(HELPER_QuestionText.getAttribObject (getClass (), _QuestionText, true, FIELD_QuestionText));
        result.add(HELPER_IsApplicable.getAttribObject (getClass (), _IsApplicable, false, FIELD_IsApplicable));

        return result;
    }


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


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

    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 HTDiversityQuestionBehaviourDecorator extends BaseBusinessClass.BBCBehaviourDecorator<HTDiversityQuestion>
    {

    /**
     * Get the attribute QuestionText
     */
    public String getQuestionText (HTDiversityQuestion obj, String original)
    {
        return original;
    }

    /**
     * Change the value set for attribute QuestionText.
     * May modify the field beforehand
     * Occurs before validation.
     */
    public String setQuestionText (HTDiversityQuestion obj, String newQuestionText) throws FieldException
    {
        return newQuestionText;
    }

    /**
     * Get the attribute IsApplicable
     */
    public Boolean getIsApplicable (HTDiversityQuestion obj, Boolean original)
    {
        return original;
    }

    /**
     * Change the value set for attribute IsApplicable.
     * May modify the field beforehand
     * Occurs before validation.
     */
    public Boolean setIsApplicable (HTDiversityQuestion obj, Boolean newIsApplicable) throws FieldException
    {
        return newIsApplicable;
    }

    }

    
    public ORMPipeLine pipes()
    {
        return new HTDiversityQuestionPipeLineFactory<HTDiversityQuestion, HTDiversityQuestion> ((HTDiversityQuestion)this);
    }
      
    /**
     * Use this instead of pipes() to get rid of type casting.
     */  
    public HTDiversityQuestionPipeLineFactory<HTDiversityQuestion, HTDiversityQuestion> pipelineHTDiversityQuestion()
    {
        return (HTDiversityQuestionPipeLineFactory<HTDiversityQuestion, HTDiversityQuestion>) pipes();
    }
    
    public static HTDiversityQuestionPipeLineFactory<HTDiversityQuestion, HTDiversityQuestion> pipesHTDiversityQuestion(Collection<HTDiversityQuestion> items)
    {
        return REFERENCE_HTDiversityQuestion.new HTDiversityQuestionPipeLineFactory<HTDiversityQuestion, HTDiversityQuestion> (items);
    }
    
    public static HTDiversityQuestionPipeLineFactory<HTDiversityQuestion, HTDiversityQuestion> pipesHTDiversityQuestion(HTDiversityQuestion[] _items)
    {
        return pipesHTDiversityQuestion(Arrays.asList (_items));
    }
    
    public static HTDiversityQuestionPipeLineFactory<HTDiversityQuestion, HTDiversityQuestion> pipesHTDiversityQuestion()
    {
        return pipesHTDiversityQuestion((Collection)null);
    }
    
    
    public class HTDiversityQuestionPipeLineFactory<From extends BaseBusinessClass, Me extends HTDiversityQuestion> extends BaseBusinessClass.ORMPipeLine<From, Me>    
    {
        public <Prev> HTDiversityQuestionPipeLineFactory (PipeLine<From, Prev> pipeLine, Pipe<Prev, Me> nextPipe)
        {
            super (pipeLine, nextPipe);
        }
        
        public HTDiversityQuestionPipeLineFactory (From seed)
        {
            super(seed);
        }

        public HTDiversityQuestionPipeLineFactory (Collection<From> seed)
        {
            super(seed);
        }
        
        
        public PipeLine<From, ? extends Object> to(String name)
        {
            if (name.equals ("QuestionText"))
            {
                return toQuestionText ();
            }                
            if (name.equals ("IsApplicable"))
            {
                return toIsApplicable ();
            }                
            if (name.equals ("Question"))
            {
                return toQuestion ();
            }                
            if (name.equals ("HiringTeam"))
            {
                return toHiringTeam ();
            }                
            
            
            return super.to(name);
        }
        
        
        public PipeLine<From, String> toQuestionText () { return pipe(new ORMAttributePipe<Me, String>(FIELD_QuestionText));  }
        
        public PipeLine<From, Boolean> toIsApplicable () { return pipe(new ORMAttributePipe<Me, Boolean>(FIELD_IsApplicable));  }
        public DiversityQuestion.DiversityQuestionPipeLineFactory<From, DiversityQuestion> toQuestion () { return toQuestion (Filter.ALL); }

        public DiversityQuestion.DiversityQuestionPipeLineFactory<From, DiversityQuestion> toQuestion (Filter<DiversityQuestion> filter) 
        { 
            return DiversityQuestion.REFERENCE_DiversityQuestion.new DiversityQuestionPipeLineFactory<From, DiversityQuestion> (this, new ORMSingleAssocPipe<Me, DiversityQuestion>(SINGLEREFERENCE_Question, filter)); 
        }
        public HiringTeam.HiringTeamPipeLineFactory<From, HiringTeam> toHiringTeam () { return toHiringTeam (Filter.ALL); }

        public HiringTeam.HiringTeamPipeLineFactory<From, HiringTeam> toHiringTeam (Filter<HiringTeam> filter) 
        { 
            return HiringTeam.REFERENCE_HiringTeam.new HiringTeamPipeLineFactory<From, HiringTeam> (this, new ORMSingleAssocPipe<Me, HiringTeam>(SINGLEREFERENCE_HiringTeam, filter)); 
        }
        
    }
    
    public boolean isTransientAttrib(String attribName)
    {
        

        return super.isTransientAttrib(attribName);
    }

    public boolean isTransientSingleReference(String assocName)
    {
        

        return super.isTransientSingleReference(assocName);
    }
}

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

    public void assertValid ()
    {
    }


    public DiversityQuestion getQuestion () throws StorageException
    {
        return (DiversityQuestion)(DiversityQuestion.DUMMY_DiversityQuestion);
    }


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

    public HiringTeam getHiringTeam () throws StorageException
    {
        return (HiringTeam)(HiringTeam.DUMMY_HiringTeam);
    }


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

}

    
