/*
 * 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;



public abstract class BaseCultureCriteriaAnswer extends BaseBusinessClass
{
    // Reference instance for the object
    public static final CultureCriteriaAnswer REFERENCE_CultureCriteriaAnswer = new CultureCriteriaAnswer ();

    // Reference instance for the object
    public static final CultureCriteriaAnswer DUMMY_CultureCriteriaAnswer = new DummyCultureCriteriaAnswer ();

    // Static constants corresponding to field names
    
    public static final String SINGLEREFERENCE_CultureElement = "CultureElement";
    public static final String SINGLEREFERENCE_SelectedQuestion = "SelectedQuestion";
    public static final String SINGLEREFERENCE_Candidate = "Candidate";
    public static final String BACKREF_Candidate = "";

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

    // Static constants corresponding to attribute helpers
    

    // Private attributes corresponding to business object data
    

    // Private attributes corresponding to single references
    private SingleAssociation<CultureCriteriaAnswer, CultureElement> _CultureElement;
    private SingleAssociation<CultureCriteriaAnswer, CultureElementQuestion> _SelectedQuestion;
    private SingleAssociation<CultureCriteriaAnswer, Candidate> _Candidate;
    

    // Private attributes corresponding to multiple references
    

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

    // Arrays of validators for each attribute
    

    // Arrays of AttributeDecorators for each attribute
    
    
    // Arrays of SingleAssocDecorators for each attribute
    private static final SingleAssocDecorator<CultureCriteriaAnswer, CultureElement>[] SINGLEREFERENCE_CultureElement_Decorators;
    private static final SingleAssocDecorator<CultureCriteriaAnswer, CultureElementQuestion>[] SINGLEREFERENCE_SelectedQuestion_Decorators;
    private static final SingleAssocDecorator<CultureCriteriaAnswer, Candidate>[] SINGLEREFERENCE_Candidate_Decorators;
    
    
    // Arrays of MultiAssocDecorators for each attribute
    

    // Arrays of behaviour decorators
    private static final CultureCriteriaAnswerBehaviourDecorator[] CultureCriteriaAnswer_BehaviourDecorators;
    
    static
    {
        try
        {
            
            String tmp_Candidate = Candidate.BACKREF_CultureCriteriaAnswers;
            
            Map  validatorMapping = ((Map)ConfigMgr.getConfigObject ("CONFIG.ORMVALIDATOR", "ValidatorMapping"));

            setupAssocMetaData_CultureElement();
            setupAssocMetaData_SelectedQuestion();
            setupAssocMetaData_Candidate();
            SINGLEREFERENCE_CultureElement_Decorators = (SingleAssocDecorator[])AttributeDecoratorUtils.getSingleAssocDecorators(REFERENCE_CultureCriteriaAnswer, SINGLEREFERENCE_CultureElement).toArray (new SingleAssocDecorator[0]);
            SINGLEREFERENCE_SelectedQuestion_Decorators = (SingleAssocDecorator[])AttributeDecoratorUtils.getSingleAssocDecorators(REFERENCE_CultureCriteriaAnswer, SINGLEREFERENCE_SelectedQuestion).toArray (new SingleAssocDecorator[0]);
            SINGLEREFERENCE_Candidate_Decorators = (SingleAssocDecorator[])AttributeDecoratorUtils.getSingleAssocDecorators(REFERENCE_CultureCriteriaAnswer, SINGLEREFERENCE_Candidate).toArray (new SingleAssocDecorator[0]);
            

            REFERENCE_CultureCriteriaAnswer.initialiseReference ();
            DUMMY_CultureCriteriaAnswer.initialiseReference ();
            CultureCriteriaAnswer_BehaviourDecorators = BaseBusinessClass.getBBCBehaviours(CultureCriteriaAnswer.class).toArray(new CultureCriteriaAnswerBehaviourDecorator[0]);
        }
        catch (RuntimeException e)
        {
            LogMgr.log (BUSINESS_OBJECTS, LogLevel.SYSTEMERROR1, e, "Error initialising");
            throw e;
        }
    }

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

        metaInfo.put ("dbcol", "culture_element_id");
        metaInfo.put ("mandatory", "true");
        metaInfo.put ("name", "CultureElement");
        metaInfo.put ("type", "CultureElement");
        metaInfo.put (METADATA_DB_TABLENAME, "tl_culture_criteria_answer");
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for CultureCriteriaAnswer.CultureElement:", metaInfo);
        ATTRIBUTES_METADATA_CultureCriteriaAnswer.put (SINGLEREFERENCE_CultureElement, Collections.unmodifiableMap (metaInfo));
    }
    
    
    private static void setupAssocMetaData_SelectedQuestion()
    {
        Map metaInfo = new HashMap ();

        metaInfo.put ("dbcol", "selected_question_id");
        metaInfo.put ("mandatory", "true");
        metaInfo.put ("name", "SelectedQuestion");
        metaInfo.put ("type", "CultureElementQuestion");
        metaInfo.put (METADATA_DB_TABLENAME, "tl_culture_criteria_answer");
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for CultureCriteriaAnswer.SelectedQuestion:", metaInfo);
        ATTRIBUTES_METADATA_CultureCriteriaAnswer.put (SINGLEREFERENCE_SelectedQuestion, Collections.unmodifiableMap (metaInfo));
    }
    
    
    private static void setupAssocMetaData_Candidate()
    {
        Map metaInfo = new HashMap ();

        metaInfo.put ("backreferenceName", "CultureCriteriaAnswers");
        metaInfo.put ("dbcol", "candidate_id");
        metaInfo.put ("mandatory", "true");
        metaInfo.put ("name", "Candidate");
        metaInfo.put ("type", "Candidate");
        metaInfo.put (METADATA_DB_TABLENAME, "tl_culture_criteria_answer");
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for CultureCriteriaAnswer.Candidate:", metaInfo);
        ATTRIBUTES_METADATA_CultureCriteriaAnswer.put (SINGLEREFERENCE_Candidate, Collections.unmodifiableMap (metaInfo));
    }
    
    
    // END OF STATIC METADATA DEFINITION    
    
    
    
    // This constructor should not be called
    protected BaseCultureCriteriaAnswer ()
    {
    }


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

    


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

        
    }


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

        _CultureElement = new SingleAssociation<CultureCriteriaAnswer, CultureElement> (this, SINGLEREFERENCE_CultureElement, null, CultureElement.REFERENCE_CultureElement, "tl_culture_criteria_answer");
        _SelectedQuestion = new SingleAssociation<CultureCriteriaAnswer, CultureElementQuestion> (this, SINGLEREFERENCE_SelectedQuestion, null, CultureElementQuestion.REFERENCE_CultureElementQuestion, "tl_culture_criteria_answer");
        _Candidate = new SingleAssociation<CultureCriteriaAnswer, Candidate> (this, SINGLEREFERENCE_Candidate, Candidate.MULTIPLEREFERENCE_CultureCriteriaAnswers, Candidate.REFERENCE_Candidate, "tl_culture_criteria_answer");
        
    }


    protected BaseBusinessClass initialiseReference ()
    {
        super.initialiseReference ();
        
        _CultureElement = new SingleAssociation<CultureCriteriaAnswer, CultureElement> (this, SINGLEREFERENCE_CultureElement, null, CultureElement.REFERENCE_CultureElement, "tl_culture_criteria_answer");
        _SelectedQuestion = new SingleAssociation<CultureCriteriaAnswer, CultureElementQuestion> (this, SINGLEREFERENCE_SelectedQuestion, null, CultureElementQuestion.REFERENCE_CultureElementQuestion, "tl_culture_criteria_answer");
        _Candidate = new SingleAssociation<CultureCriteriaAnswer, Candidate> (this, SINGLEREFERENCE_Candidate, Candidate.MULTIPLEREFERENCE_CultureCriteriaAnswers, Candidate.REFERENCE_Candidate, "tl_culture_criteria_answer");
        
        
        return this;
    }




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

        return result;
    }
    
    
    public BaseBusinessClass getSingleAssocReferenceInstance (String assocName)
    {
        if (assocName == null)
        {
            throw new RuntimeException ("Game over == null!");
        }
        else if (assocName.equals (SINGLEREFERENCE_CultureElement))
        {
            return _CultureElement.getReferencedType ();
        }
        else if (assocName.equals (SINGLEREFERENCE_SelectedQuestion))
        {
            return _SelectedQuestion.getReferencedType ();
        }
        else if (assocName.equals (SINGLEREFERENCE_Candidate))
        {
            return _Candidate.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_CultureElement))
        {
            return null ;
        }
        else if (assocName.equals (SINGLEREFERENCE_SelectedQuestion))
        {
            return null ;
        }
        else if (assocName.equals (SINGLEREFERENCE_Candidate))
        {
            return Candidate.MULTIPLEREFERENCE_CultureCriteriaAnswers ;
        }
        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_CultureElement))
        {
            return getCultureElement ();
        }
        else if (assocName.equals (SINGLEREFERENCE_SelectedQuestion))
        {
            return getSelectedQuestion ();
        }
        else if (assocName.equals (SINGLEREFERENCE_Candidate))
        {
            return getCandidate ();
        }
        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_CultureElement))
        {
            return getCultureElement (getType);
        }
        else if (assocName.equals (SINGLEREFERENCE_SelectedQuestion))
        {
            return getSelectedQuestion (getType);
        }
        else if (assocName.equals (SINGLEREFERENCE_Candidate))
        {
            return getCandidate (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_CultureElement))
        {
            return getCultureElementID ();
        }
        else if (assocName.equals (SINGLEREFERENCE_SelectedQuestion))
        {
            return getSelectedQuestionID ();
        }
        else if (assocName.equals (SINGLEREFERENCE_Candidate))
        {
            return getCandidateID ();
        }
        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_CultureElement))
        {
            setCultureElement ((CultureElement)(newValue));
        }
        else if (assocName.equals (SINGLEREFERENCE_SelectedQuestion))
        {
            setSelectedQuestion ((CultureElementQuestion)(newValue));
        }
        else if (assocName.equals (SINGLEREFERENCE_Candidate))
        {
            setCandidate ((Candidate)(newValue));
        }
        else
        {
            super.setSingleAssoc (assocName, newValue);
        }
    }



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


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


    /**
     * Get the object id for the referenced object.  Does not force a DB access.
     */
    public Long getCultureElementID ()
    {
        assertValid();
        
        if (_CultureElement == null)
        {
            return null;
        }
        else
        {
            return _CultureElement.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 preCultureElementChange (CultureElement newCultureElement) 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 postCultureElementChange () throws FieldException
    {
    }


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

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

        if (_CultureElement.wouldReferencedChange (newCultureElement))
        {
            assertValid();
            Debug.assertion (AttributeDecoratorUtils.getWriteability (SINGLEREFERENCE_CultureElement_Decorators, (CultureCriteriaAnswer)this, SINGLEREFERENCE_CultureElement ,getWriteability_CultureElement ()) != FieldWriteability.FALSE, "Assoc CultureElement is not writeable");
            preCultureElementChange (newCultureElement);
            
            _CultureElement.set (newCultureElement);
                
            postCultureElementChange ();
        }
    }

    /**
     * Get the reference SelectedQuestion
     */
    public CultureElementQuestion getSelectedQuestion () throws StorageException
    {
        assertValid();
        
        try
        {
            return (CultureElementQuestion)(_SelectedQuestion.get ());
        }
        catch (ClassCastException e)
        {
            LogMgr.log (BUSINESS_OBJECTS, LogLevel.SYSTEMERROR2, "Cache collision in CultureCriteriaAnswer:", this.getObjectID (), ", was trying to get CultureElementQuestion:",  getSelectedQuestionID ());
            LogMgr.log (BUSINESS_OBJECTS, LogLevel.SYSTEMERROR2, "Instead I got:", _SelectedQuestion.get ().getClass ());
            throw e;
        }
    }


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


    /**
     * Get the object id for the referenced object.  Does not force a DB access.
     */
    public Long getSelectedQuestionID ()
    {
        assertValid();
        
        if (_SelectedQuestion == null)
        {
            return null;
        }
        else
        {
            return _SelectedQuestion.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 preSelectedQuestionChange (CultureElementQuestion newSelectedQuestion) 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 postSelectedQuestionChange () throws FieldException
    {
    }


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

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

        if (_SelectedQuestion.wouldReferencedChange (newSelectedQuestion))
        {
            assertValid();
            Debug.assertion (AttributeDecoratorUtils.getWriteability (SINGLEREFERENCE_SelectedQuestion_Decorators, (CultureCriteriaAnswer)this, SINGLEREFERENCE_SelectedQuestion ,getWriteability_SelectedQuestion ()) != FieldWriteability.FALSE, "Assoc SelectedQuestion is not writeable");
            preSelectedQuestionChange (newSelectedQuestion);
            
            _SelectedQuestion.set (newSelectedQuestion);
                
            postSelectedQuestionChange ();
        }
    }

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


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


    /**
     * Get the object id for the referenced object.  Does not force a DB access.
     */
    public Long getCandidateID ()
    {
        assertValid();
        
        if (_Candidate == null)
        {
            return null;
        }
        else
        {
            return _Candidate.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 preCandidateChange (Candidate newCandidate) 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 postCandidateChange () throws FieldException
    {
    }


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

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

        if (_Candidate.wouldReferencedChange (newCandidate))
        {
            assertValid();
            Debug.assertion (AttributeDecoratorUtils.getWriteability (SINGLEREFERENCE_Candidate_Decorators, (CultureCriteriaAnswer)this, SINGLEREFERENCE_Candidate ,getWriteability_Candidate ()) != FieldWriteability.FALSE, "Assoc Candidate is not writeable");
            preCandidateChange (newCandidate);
            Candidate oldCandidate = getCandidate ();

            if (oldCandidate != null)
            {
                // This is to stop validation from triggering when we are removed
                _Candidate.set (null);
                oldCandidate.removeFromCultureCriteriaAnswers ((CultureCriteriaAnswer)(this));
            }

            _Candidate.set (newCandidate);

            if (newCandidate != null)
            {
                newCandidate.addToCultureCriteriaAnswers ((CultureCriteriaAnswer)(this));
            }
                
            postCandidateChange ();
        }
    }

    /**
     * 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 (_Candidate.isLoaded () || getTransaction ().isObjectLoaded (_Candidate.getReferencedType (), getCandidateID ()))
            {
                Candidate  referenced = getCandidate ();

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

        super.onDelete ();
    }


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


    public CultureCriteriaAnswer referenceInstance ()
    {
        return REFERENCE_CultureCriteriaAnswer;
    }


    public CultureCriteriaAnswer getInTransaction (ObjectTransaction t) throws StorageException
    {
        return getCultureCriteriaAnswerByID (t, getObjectID());
    }
    
    
    public BaseBusinessClass dummyInstance ()
    {
        return DUMMY_CultureCriteriaAnswer;
    }


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



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

        tl_culture_criteria_answerPSet.setAttrib (FIELD_ObjectID, myID);
        _CultureElement.getPersistentSets (allSets);
        _SelectedQuestion.getPersistentSets (allSets);
        _Candidate.getPersistentSets (allSets);
        
    }


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

        _CultureElement.setFromPersistentSets (objectID, allSets);
        _SelectedQuestion.setFromPersistentSets (objectID, allSets);
        _Candidate.setFromPersistentSets (objectID, allSets);
        
    }


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

        if (other instanceof CultureCriteriaAnswer)
        {
            CultureCriteriaAnswer otherCultureCriteriaAnswer = (CultureCriteriaAnswer)other;
            
        }
    }


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

        if (source instanceof BaseCultureCriteriaAnswer)
        {
            BaseCultureCriteriaAnswer sourceCultureCriteriaAnswer = (BaseCultureCriteriaAnswer)(source);

            
        }
    }


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

            _CultureElement.copyFrom (sourceCultureCriteriaAnswer._CultureElement, linkToGhosts);
            _SelectedQuestion.copyFrom (sourceCultureCriteriaAnswer._SelectedQuestion, linkToGhosts);
            _Candidate.copyFrom (sourceCultureCriteriaAnswer._Candidate, 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 BaseCultureCriteriaAnswer)
        {
            BaseCultureCriteriaAnswer sourceCultureCriteriaAnswer = (BaseCultureCriteriaAnswer)(source);

            
        }
    }


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

        
        context.check (getCultureElementID() != null, this, SINGLEREFERENCE_CultureElement, "mandatory");
        
        context.check (getSelectedQuestionID() != null, this, SINGLEREFERENCE_SelectedQuestion, "mandatory");
        
        context.check (getCandidateID() != null, this, SINGLEREFERENCE_Candidate, "mandatory");
        
    }


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

        _CultureElement.readExternalData(vals.get(SINGLEREFERENCE_CultureElement));
        _SelectedQuestion.readExternalData(vals.get(SINGLEREFERENCE_SelectedQuestion));
        _Candidate.readExternalData(vals.get(SINGLEREFERENCE_Candidate));
        
    }


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

        vals.put (SINGLEREFERENCE_CultureElement, _CultureElement.writeExternalData());
        vals.put (SINGLEREFERENCE_SelectedQuestion, _SelectedQuestion.writeExternalData());
        vals.put (SINGLEREFERENCE_Candidate, _Candidate.writeExternalData());
        
    }


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

        if (other instanceof BaseCultureCriteriaAnswer)
        {
            BaseCultureCriteriaAnswer otherCultureCriteriaAnswer = (BaseCultureCriteriaAnswer)(other);

            

            // Compare single assocs
            _CultureElement.compare (otherCultureCriteriaAnswer._CultureElement, listener);
            _SelectedQuestion.compare (otherCultureCriteriaAnswer._SelectedQuestion, listener);
            _Candidate.compare (otherCultureCriteriaAnswer._Candidate, 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.visitAssociation (_CultureElement);
        visitor.visitAssociation (_SelectedQuestion);
        visitor.visitAssociation (_Candidate);
        
    }


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

        if (scope.includes (_CultureElement))
        {
            visitor.visit (_CultureElement);
        }
        if (scope.includes (_SelectedQuestion))
        {
            visitor.visit (_SelectedQuestion);
        }
        if (scope.includes (_Candidate))
        {
            visitor.visit (_Candidate);
        }
        
    }


    public static CultureCriteriaAnswer createCultureCriteriaAnswer (ObjectTransaction transaction) throws StorageException
    {
        CultureCriteriaAnswer     result = new CultureCriteriaAnswer ();

        result.initialiseNewObject (transaction);

        return result;
    }


    public static CultureCriteriaAnswer getCultureCriteriaAnswerByID (ObjectTransaction transaction, Long objectID) throws StorageException
    {
        return (CultureCriteriaAnswer)(transaction.getObjectByID (REFERENCE_CultureCriteriaAnswer, objectID));
    }

    public boolean testFilter (String attribName, QueryFilter filter) throws StorageException
    {
        if (false)
        {
            throw new RuntimeException ("Game over man!!");
        }
        else if (attribName.equals (SINGLEREFERENCE_CultureElement))
        {
            return filter.matches (getCultureElement ());
        }
        else if (attribName.equals (SINGLEREFERENCE_SelectedQuestion))
        {
            return filter.matches (getSelectedQuestion ());
        }
        else if (attribName.equals (SINGLEREFERENCE_Candidate))
        {
            return filter.matches (getCandidate ());
        }
        else
        {
            return super.testFilter (attribName, filter);
        }
    }


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

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

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

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

            
        public SearchAll andCultureElement (QueryFilter<CultureElement> filter)
        {
            filter.addFilter (context, "tl_culture_criteria_answer.culture_element_id", "CultureElement");
            return this;
        }
            
        public SearchAll andSelectedQuestion (QueryFilter<CultureElementQuestion> filter)
        {
            filter.addFilter (context, "tl_culture_criteria_answer.selected_question_id", "SelectedQuestion");
            return this;
        }
            
        public SearchAll andCandidate (QueryFilter<Candidate> filter)
        {
            filter.addFilter (context, "tl_culture_criteria_answer.candidate_id", "Candidate");
            return this;
        }
            
        public CultureCriteriaAnswer[] search (ObjectTransaction transaction) throws StorageException
        {
            
            BaseBusinessClass[]     results = super.search (transaction, REFERENCE_CultureCriteriaAnswer, SEARCH_All, criteria);
            Set<CultureCriteriaAnswer>   typedResults = new LinkedHashSet <CultureCriteriaAnswer> ();
            for (BaseBusinessClass bbcResult : results)
            {
                CultureCriteriaAnswer aResult = (CultureCriteriaAnswer)bbcResult;
                
                typedResults.add (aResult);
            }
            
            return ObjstoreUtils.removeDeleted(transaction, typedResults).toArray (new CultureCriteriaAnswer[0]);
                            
        }
    }

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



    public Object getAttribute (String attribName)
    {
        if (false)
        {
            throw new RuntimeException ("Game over man!!");
        }
        else
        {
            return super.getAttribute (attribName);
        }
    }


    public AttributeHelper getAttributeHelper (String attribName)
    {
        if (false)
        {
            throw new RuntimeException ("Game over man!!");
        }
        else
        {
            return super.getAttributeHelper (attribName);
        }
    }


    public void setAttribute (String attribName, Object attribValue) throws FieldException
    {
        if (false)
        {
            throw new RuntimeException ("Game over man!!");
        }
        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 (SINGLEREFERENCE_CultureElement))
        {
            return getWriteability_CultureElement ();
        }
        else if (fieldName.equals (SINGLEREFERENCE_SelectedQuestion))
        {
            return getWriteability_SelectedQuestion ();
        }
        else if (fieldName.equals (SINGLEREFERENCE_Candidate))
        {
            return getWriteability_Candidate ();
        }
        else
        {
            return super.getWriteable (fieldName);
        }
    }


    public void putUnwriteable (Set<String> fields)
    {

        super.putUnwriteable (fields);
    }

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


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

        

        return result;
    }


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


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

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

        copyInto.putAll(ATTRIBUTES_METADATA_CultureCriteriaAnswer);
    }
            

    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 CultureCriteriaAnswerBehaviourDecorator extends BaseBusinessClass.BBCBehaviourDecorator<CultureCriteriaAnswer>
    {

    }

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

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

        public CultureCriteriaAnswerPipeLineFactory (Collection<From> seed)
        {
            super(seed);
        }
        
        
        public PipeLine<From, ? extends Object> to(String name)
        {
            if (name.equals ("CultureElement"))
            {
                return toCultureElement ();
            }                
            if (name.equals ("SelectedQuestion"))
            {
                return toSelectedQuestion ();
            }                
            if (name.equals ("Candidate"))
            {
                return toCandidate ();
            }                
            
            
            return super.to(name);
        }
        

        public CultureElement.CultureElementPipeLineFactory<From, CultureElement> toCultureElement () { return toCultureElement (Filter.ALL); }

        public CultureElement.CultureElementPipeLineFactory<From, CultureElement> toCultureElement (Filter<CultureElement> filter) 
        { 
            return CultureElement.REFERENCE_CultureElement.new CultureElementPipeLineFactory<From, CultureElement> (this, new ORMSingleAssocPipe<Me, CultureElement>(SINGLEREFERENCE_CultureElement, filter)); 
        }

        public CultureElementQuestion.CultureElementQuestionPipeLineFactory<From, CultureElementQuestion> toSelectedQuestion () { return toSelectedQuestion (Filter.ALL); }

        public CultureElementQuestion.CultureElementQuestionPipeLineFactory<From, CultureElementQuestion> toSelectedQuestion (Filter<CultureElementQuestion> filter) 
        { 
            return CultureElementQuestion.REFERENCE_CultureElementQuestion.new CultureElementQuestionPipeLineFactory<From, CultureElementQuestion> (this, new ORMSingleAssocPipe<Me, CultureElementQuestion>(SINGLEREFERENCE_SelectedQuestion, filter)); 
        }

        public Candidate.CandidatePipeLineFactory<From, Candidate> toCandidate () { return toCandidate (Filter.ALL); }

        public Candidate.CandidatePipeLineFactory<From, Candidate> toCandidate (Filter<Candidate> filter) 
        { 
            return Candidate.REFERENCE_Candidate.new CandidatePipeLineFactory<From, Candidate> (this, new ORMSingleAssocPipe<Me, Candidate>(SINGLEREFERENCE_Candidate, filter)); 
        }
    }
    
    public boolean isTransientAttrib(String attribName)
    {
        

        return super.isTransientAttrib(attribName);
    }

    public boolean isTransientSingleReference(String assocName)
    {
        

        return super.isTransientSingleReference(assocName);
    }
}

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

    public void assertValid ()
    {
    }


    public CultureElement getCultureElement () throws StorageException
    {
        return (CultureElement)(CultureElement.DUMMY_CultureElement);
    }


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

    public CultureElementQuestion getSelectedQuestion () throws StorageException
    {
        return (CultureElementQuestion)(CultureElementQuestion.DUMMY_CultureElementQuestion);
    }


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

    public Candidate getCandidate () throws StorageException
    {
        return (Candidate)(Candidate.DUMMY_Candidate);
    }


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

}

    
