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

import performa.orm.types.*;



public abstract class BaseAssessmentCriteria extends BaseBusinessClass
{
    // Reference instance for the object
    public static final AssessmentCriteria REFERENCE_AssessmentCriteria = new AssessmentCriteria ();

    // Reference instance for the object
    public static final AssessmentCriteria DUMMY_AssessmentCriteria = new DummyAssessmentCriteria ();

    // Static constants corresponding to field names
    
    public static final String FIELD_Name = "Name";
    public static final String FIELD_Importance = "Importance";
    public static final String FIELD_CriteriaType = "CriteriaType";
    public static final String SINGLEREFERENCE_Job = "Job";
    public static final String BACKREF_Job = "";

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

    // Static constants corresponding to attribute helpers
    private static final DefaultAttributeHelper<AssessmentCriteria> HELPER_Name = DefaultAttributeHelper.INSTANCE;
    private static final EnumeratedAttributeHelper<AssessmentCriteria, Importance> HELPER_Importance =  new EnumeratedAttributeHelper<AssessmentCriteria, Importance> (Importance.FACTORY_Importance);
    private static final EnumeratedAttributeHelper<AssessmentCriteria, CriteriaType> HELPER_CriteriaType =  new EnumeratedAttributeHelper<AssessmentCriteria, CriteriaType> (CriteriaType.FACTORY_CriteriaType);
    

    // Private attributes corresponding to business object data
    private String _Name;
    private Importance _Importance;
    private CriteriaType _CriteriaType;
    

    // Private attributes corresponding to single references
    private SingleAssociation<AssessmentCriteria, Job> _Job;
    

    // Private attributes corresponding to multiple references
    

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

    // Arrays of validators for each attribute
    private static final AttributeValidator[] FIELD_Name_Validators;
    private static final AttributeValidator[] FIELD_Importance_Validators;
    private static final AttributeValidator[] FIELD_CriteriaType_Validators;
    

    // Arrays of behaviour decorators
    private static final AssessmentCriteriaBehaviourDecorator[] AssessmentCriteria_BehaviourDecorators;
    
    static
    {
        try
        {
            
            String tmp_Job = Job.BACKREF_AssessmentCriterias;
            
            Map  validatorMapping = ((Map)ConfigMgr.getConfigObject ("CONFIG.ORMVALIDATOR", "ValidatorMapping"));

            setupAssocMetaData_Job();
            FIELD_Name_Validators = (AttributeValidator[])setupAttribMetaData_Name(validatorMapping).toArray (new AttributeValidator[0]);
            FIELD_Importance_Validators = (AttributeValidator[])setupAttribMetaData_Importance(validatorMapping).toArray (new AttributeValidator[0]);
            FIELD_CriteriaType_Validators = (AttributeValidator[])setupAttribMetaData_CriteriaType(validatorMapping).toArray (new AttributeValidator[0]);
            

            REFERENCE_AssessmentCriteria.initialiseReference ();
            DUMMY_AssessmentCriteria.initialiseReference ();
            AssessmentCriteria_BehaviourDecorators = BaseBusinessClass.getBBCBehaviours(AssessmentCriteria.class).toArray(new AssessmentCriteriaBehaviourDecorator[0]);
        }
        catch (RuntimeException e)
        {
            LogMgr.log (BUSINESS_OBJECTS, LogLevel.SYSTEMERROR1, e, "Error initialising");
            throw e;
        }
    }

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

        metaInfo.put ("backreferenceName", "AssessmentCriterias");
        metaInfo.put ("dbcol", "job_id");
        metaInfo.put ("name", "Job");
        metaInfo.put ("type", "Job");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for AssessmentCriteria.Job:", metaInfo);
        ATTRIBUTES_METADATA_AssessmentCriteria.put (SINGLEREFERENCE_Job, Collections.unmodifiableMap (metaInfo));
    }
    
    
    // Meta Info setup
    private static List setupAttribMetaData_Name(Map validatorMapping)
    {
        Map  metaInfo   = new HashMap ();

        metaInfo.put ("dbcol", "name");
        metaInfo.put ("length", "200");
        metaInfo.put ("name", "Name");
        metaInfo.put ("type", "String");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for AssessmentCriteria.Name:", metaInfo);
        ATTRIBUTES_METADATA_AssessmentCriteria.put (FIELD_Name, Collections.unmodifiableMap (metaInfo));

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

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

        metaInfo.put ("attribHelper", "EnumeratedAttributeHelper");
        metaInfo.put ("dbcol", "importance");
        metaInfo.put ("name", "Importance");
        metaInfo.put ("type", "Importance");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for AssessmentCriteria.Importance:", metaInfo);
        ATTRIBUTES_METADATA_AssessmentCriteria.put (FIELD_Importance, Collections.unmodifiableMap (metaInfo));

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

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

        metaInfo.put ("attribHelper", "EnumeratedAttributeHelper");
        metaInfo.put ("dbcol", "assessment_type");
        metaInfo.put ("name", "CriteriaType");
        metaInfo.put ("type", "CriteriaType");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for AssessmentCriteria.CriteriaType:", metaInfo);
        ATTRIBUTES_METADATA_AssessmentCriteria.put (FIELD_CriteriaType, Collections.unmodifiableMap (metaInfo));

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

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


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


    


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

        
        _Name = (String)(HELPER_Name.initialise (_Name));
        _Importance = (Importance)(HELPER_Importance.initialise (_Importance));
        _CriteriaType = (CriteriaType)(HELPER_CriteriaType.initialise (_CriteriaType));
    }


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

        _Job = new SingleAssociation<AssessmentCriteria, Job> (this, SINGLEREFERENCE_Job, Job.MULTIPLEREFERENCE_AssessmentCriterias, Job.REFERENCE_Job, "tl_assessment_criteria");
        
    }


    // Initialise the associations
    protected BaseBusinessClass initialiseReference ()
    {
        super.initialiseReference ();
        
        _Job = new SingleAssociation<AssessmentCriteria, Job> (this, SINGLEREFERENCE_Job, Job.MULTIPLEREFERENCE_AssessmentCriterias, Job.REFERENCE_Job, "tl_assessment_criteria");
        
        
        return this;
    }

    

    /**
     * Get the attribute Name
     */
    public String getName ()
    {
        assertValid();
        String valToReturn = _Name;

            for (AssessmentCriteriaBehaviourDecorator bhd : AssessmentCriteria_BehaviourDecorators)
            {
                valToReturn = bhd.getName ((AssessmentCriteria)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 preNameChange (String newName) 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 postNameChange () throws FieldException
    {
    }

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

    /**
     * Set the attribute Name.  Checks to ensure a new value
     * has been supplied.  If so, marks the field as altered and sets the attribute.
     */
    public void setName (String newName) throws FieldException
    {
        boolean oldAndNewIdentical = HELPER_Name.compare (_Name, newName);
        
        try
        {
            for (AssessmentCriteriaBehaviourDecorator bhd : AssessmentCriteria_BehaviourDecorators)
            {
                newName = bhd.setName ((AssessmentCriteria)this, newName);
                oldAndNewIdentical = HELPER_Name.compare (_Name, newName);
            }

            

            if (FIELD_Name_Validators.length > 0)
            {
                Object newNameObj = HELPER_Name.toObject (newName);

                if (newNameObj != null)
                {
                    int     loopMax = FIELD_Name_Validators.length;
                    Map     metadata = (Map)ATTRIBUTES_METADATA_AssessmentCriteria.get (FIELD_Name);

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

        if (!oldAndNewIdentical)
        {
            assertValid();
            Debug.assertion (getWriteability_Name () != FieldWriteability.FALSE, "Field  Name is not writeable");
            preNameChange (newName);
            markFieldChange (FIELD_Name);
            _Name = newName;            
            postFieldChange (FIELD_Name);
            postNameChange ();
        }
    }

    /**
     * Get the attribute Importance
     */
    public Importance getImportance ()
    {
        assertValid();
        Importance valToReturn = _Importance;

            for (AssessmentCriteriaBehaviourDecorator bhd : AssessmentCriteria_BehaviourDecorators)
            {
                valToReturn = bhd.getImportance ((AssessmentCriteria)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 preImportanceChange (Importance newImportance) 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 postImportanceChange () throws FieldException
    {
    }

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

    /**
     * Set the attribute Importance.  Checks to ensure a new value
     * has been supplied.  If so, marks the field as altered and sets the attribute.
     */
    public void setImportance (Importance newImportance) throws FieldException
    {
        boolean oldAndNewIdentical = HELPER_Importance.compare (_Importance, newImportance);
        
        try
        {
            for (AssessmentCriteriaBehaviourDecorator bhd : AssessmentCriteria_BehaviourDecorators)
            {
                newImportance = bhd.setImportance ((AssessmentCriteria)this, newImportance);
                oldAndNewIdentical = HELPER_Importance.compare (_Importance, newImportance);
            }

            

            if (FIELD_Importance_Validators.length > 0)
            {
                Object newImportanceObj = HELPER_Importance.toObject (newImportance);

                if (newImportanceObj != null)
                {
                    int     loopMax = FIELD_Importance_Validators.length;
                    Map     metadata = (Map)ATTRIBUTES_METADATA_AssessmentCriteria.get (FIELD_Importance);

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

        if (!oldAndNewIdentical)
        {
            assertValid();
            Debug.assertion (getWriteability_Importance () != FieldWriteability.FALSE, "Field  Importance is not writeable");
            preImportanceChange (newImportance);
            markFieldChange (FIELD_Importance);
            _Importance = newImportance;            
            postFieldChange (FIELD_Importance);
            postImportanceChange ();
        }
    }

    /**
     * Get the attribute CriteriaType
     */
    public CriteriaType getCriteriaType ()
    {
        assertValid();
        CriteriaType valToReturn = _CriteriaType;

            for (AssessmentCriteriaBehaviourDecorator bhd : AssessmentCriteria_BehaviourDecorators)
            {
                valToReturn = bhd.getCriteriaType ((AssessmentCriteria)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 preCriteriaTypeChange (CriteriaType newCriteriaType) 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 postCriteriaTypeChange () throws FieldException
    {
    }

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

    /**
     * Set the attribute CriteriaType.  Checks to ensure a new value
     * has been supplied.  If so, marks the field as altered and sets the attribute.
     */
    public void setCriteriaType (CriteriaType newCriteriaType) throws FieldException
    {
        boolean oldAndNewIdentical = HELPER_CriteriaType.compare (_CriteriaType, newCriteriaType);
        
        try
        {
            for (AssessmentCriteriaBehaviourDecorator bhd : AssessmentCriteria_BehaviourDecorators)
            {
                newCriteriaType = bhd.setCriteriaType ((AssessmentCriteria)this, newCriteriaType);
                oldAndNewIdentical = HELPER_CriteriaType.compare (_CriteriaType, newCriteriaType);
            }

            

            if (FIELD_CriteriaType_Validators.length > 0)
            {
                Object newCriteriaTypeObj = HELPER_CriteriaType.toObject (newCriteriaType);

                if (newCriteriaTypeObj != null)
                {
                    int     loopMax = FIELD_CriteriaType_Validators.length;
                    Map     metadata = (Map)ATTRIBUTES_METADATA_AssessmentCriteria.get (FIELD_CriteriaType);

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

        if (!oldAndNewIdentical)
        {
            assertValid();
            Debug.assertion (getWriteability_CriteriaType () != FieldWriteability.FALSE, "Field  CriteriaType is not writeable");
            preCriteriaTypeChange (newCriteriaType);
            markFieldChange (FIELD_CriteriaType);
            _CriteriaType = newCriteriaType;            
            postFieldChange (FIELD_CriteriaType);
            postCriteriaTypeChange ();
        }
    }



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

        
        result.add("Job");
        

        return result;
    }
    
    
    public BaseBusinessClass getSingleAssocReferenceInstance (String assocName)
    {
        if (assocName == null)
        {
            throw new RuntimeException ("Game over == null!");
        }
        else if (assocName.equals (SINGLEREFERENCE_Job))
        {
            return _Job.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_Job))
        {
            return Job.MULTIPLEREFERENCE_AssessmentCriterias ;
        }
        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_Job))
        {
            return getJob ();
        }
        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_Job))
        {
            return getJob (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_Job))
        {
            return getJobID ();
        }
        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_Job))
        {
            setJob ((Job)(newValue));
        }
        else
        {
            super.setSingleAssoc (assocName, newValue);
        }
    }



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


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


    /**
     * Get the object id for the referenced object.  Does not force a DB access.
     */
    public Long getJobID ()
    {
        assertValid();
        
        if (_Job == null)
        {
            return null;
        }
        else
        {
            return _Job.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 preJobChange (Job newJob) 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 postJobChange () throws FieldException
    {
    }



    
    public FieldWriteability getWriteability_Job ()
    {
        return getFieldWritabilityUtil (FieldWriteability.TRUE);
    }
    
    
    /**
     * Set the reference Job.  Checks to ensure a new value
     * has been supplied.  If so, marks the reference as altered and sets it.
     */
    public void setJob (Job newJob) throws StorageException, FieldException
    {
        

        if (_Job.wouldReferencedChange (newJob))
        {
            assertValid();
            Debug.assertion (getWriteability_Job () != FieldWriteability.FALSE, "Assoc Job is not writeable");
            preJobChange (newJob);
            Job oldJob = getJob ();

                    if (oldJob != null)
                    {
                        // This is to stop validation from triggering when we are removed
                        _Job.set (null);
                        oldJob.removeFromAssessmentCriterias ((AssessmentCriteria)(this));
                    }

                    _Job.set (newJob);

                    if (newJob != null)
                    {
                        newJob.addToAssessmentCriterias ((AssessmentCriteria)(this));
                    }
                
            postJobChange ();
        }
    }

    /**
     * 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 (_Job.isLoaded () || getTransaction ().isObjectLoaded (_Job.getReferencedType (), getJobID ()))
            {
                Job  referenced = getJob ();

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

        super.onDelete ();
    }


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


    public AssessmentCriteria referenceInstance ()
    {
        return REFERENCE_AssessmentCriteria;
    }


    public AssessmentCriteria getInTransaction (ObjectTransaction t) throws StorageException
    {
        return getAssessmentCriteriaByID (t, getObjectID());
    }
    
    
    public BaseBusinessClass dummyInstance ()
    {
        return DUMMY_AssessmentCriteria;
    }


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





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

        tl_assessment_criteriaPSet.setAttrib (FIELD_ObjectID, myID);
        tl_assessment_criteriaPSet.setAttrib (FIELD_Name, HELPER_Name.toObject (_Name)); //
        tl_assessment_criteriaPSet.setAttrib (FIELD_Importance, HELPER_Importance.toObject (_Importance)); //
        tl_assessment_criteriaPSet.setAttrib (FIELD_CriteriaType, HELPER_CriteriaType.toObject (_CriteriaType)); //
        _Job.getPersistentSets (allSets);
        
    }


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

        
        PersistentSet   tl_assessment_criteriaPSet = allSets.getPersistentSet (objectID, "tl_assessment_criteria");

        _Name = (String)(HELPER_Name.fromObject (_Name, tl_assessment_criteriaPSet.getAttrib (FIELD_Name))); //
        _Importance = (Importance)(HELPER_Importance.fromObject (_Importance, tl_assessment_criteriaPSet.getAttrib (FIELD_Importance))); //
        _CriteriaType = (CriteriaType)(HELPER_CriteriaType.fromObject (_CriteriaType, tl_assessment_criteriaPSet.getAttrib (FIELD_CriteriaType))); //
        _Job.setFromPersistentSets (objectID, allSets);
        
    }





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

        if (other instanceof AssessmentCriteria)
        {
            AssessmentCriteria otherAssessmentCriteria = (AssessmentCriteria)other;
            
            try
            {
                setName (otherAssessmentCriteria.getName ());
            }
            catch (FieldException ex)
            {
                e.addException (ex);
            }
            
            try
            {
                setImportance (otherAssessmentCriteria.getImportance ());
            }
            catch (FieldException ex)
            {
                e.addException (ex);
            }
            
            try
            {
                setCriteriaType (otherAssessmentCriteria.getCriteriaType ());
            }
            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 BaseAssessmentCriteria)
        {
            BaseAssessmentCriteria sourceAssessmentCriteria = (BaseAssessmentCriteria)(source);

            _Name = sourceAssessmentCriteria._Name;
            _Importance = sourceAssessmentCriteria._Importance;
            _CriteriaType = sourceAssessmentCriteria._CriteriaType;
            
        }
    }


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

            _Job.copyFrom (sourceAssessmentCriteria._Job, 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 BaseAssessmentCriteria)
        {
            BaseAssessmentCriteria sourceAssessmentCriteria = (BaseAssessmentCriteria)(source);

            
        }
    }


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

        
    }


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

        _Name = (String)(HELPER_Name.readExternal (_Name, vals.get(FIELD_Name))); //
        _Importance = (Importance)(HELPER_Importance.readExternal (_Importance, vals.get(FIELD_Importance))); //
        _CriteriaType = (CriteriaType)(HELPER_CriteriaType.readExternal (_CriteriaType, vals.get(FIELD_CriteriaType))); //
        _Job.readExternalData(vals.get(SINGLEREFERENCE_Job));
        
    }


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

        vals.put (FIELD_Name, HELPER_Name.writeExternal (_Name));
        vals.put (FIELD_Importance, HELPER_Importance.writeExternal (_Importance));
        vals.put (FIELD_CriteriaType, HELPER_CriteriaType.writeExternal (_CriteriaType));
        vals.put (SINGLEREFERENCE_Job, _Job.writeExternalData());
        
    }


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

        if (other instanceof BaseAssessmentCriteria)
        {
            BaseAssessmentCriteria otherAssessmentCriteria = (BaseAssessmentCriteria)(other);

            
            if (!HELPER_Name.compare(this._Name, otherAssessmentCriteria._Name))
            {
                listener.notifyFieldChange(this, other, FIELD_Name, HELPER_Name.toObject(this._Name), HELPER_Name.toObject(otherAssessmentCriteria._Name));
            }
            if (!HELPER_Importance.compare(this._Importance, otherAssessmentCriteria._Importance))
            {
                listener.notifyFieldChange(this, other, FIELD_Importance, HELPER_Importance.toObject(this._Importance), HELPER_Importance.toObject(otherAssessmentCriteria._Importance));
            }
            if (!HELPER_CriteriaType.compare(this._CriteriaType, otherAssessmentCriteria._CriteriaType))
            {
                listener.notifyFieldChange(this, other, FIELD_CriteriaType, HELPER_CriteriaType.toObject(this._CriteriaType), HELPER_CriteriaType.toObject(otherAssessmentCriteria._CriteriaType));
            }

            // Compare single assocs
            _Job.compare (otherAssessmentCriteria._Job, 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_Name, HELPER_Name.toObject(getName()));
        visitor.visitField(this, FIELD_Importance, HELPER_Importance.toObject(getImportance()));
        visitor.visitField(this, FIELD_CriteriaType, HELPER_CriteriaType.toObject(getCriteriaType()));
        visitor.visitAssociation (_Job);
        
    }


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

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


    public static AssessmentCriteria createAssessmentCriteria (ObjectTransaction transaction) throws StorageException
    {
        AssessmentCriteria     result = new AssessmentCriteria ();

        result.initialiseNewObject (transaction);

        return result;
    }


    public static AssessmentCriteria getAssessmentCriteriaByID (ObjectTransaction transaction, Long objectID) throws StorageException
    {
        return (AssessmentCriteria)(transaction.getObjectByID (REFERENCE_AssessmentCriteria, objectID));
    }

    public boolean testFilter (String attribName, QueryFilter filter) throws StorageException
    {
        if (false)
        {
            throw new RuntimeException ("Game over man!!");
        }
        else if (attribName.equals (FIELD_Name))
        {
            return filter.matches (getName ());
        }
        else if (attribName.equals (FIELD_Importance))
        {
            return filter.matches (getImportance ());
        }
        else if (attribName.equals (FIELD_CriteriaType))
        {
            return filter.matches (getCriteriaType ());
        }
        else if (attribName.equals (SINGLEREFERENCE_Job))
        {
            return filter.matches (getJob ());
        }
        else
        {
            return super.testFilter (attribName, filter);
        }
    }


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

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

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

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

            
            public SearchAll andName (QueryFilter<String> filter)
            {
                filter.addFilter (context, "tl_assessment_criteria.name", "Name");
                return this;
            }
            
            public SearchAll andImportance (QueryFilter<Importance> filter)
            {
                filter.addFilter (context, "tl_assessment_criteria.importance", "Importance");
                return this;
            }
            
            public SearchAll andCriteriaType (QueryFilter<CriteriaType> filter)
            {
                filter.addFilter (context, "tl_assessment_criteria.assessment_type", "CriteriaType");
                return this;
            }
            
            public SearchAll andJob (QueryFilter<Job> filter)
            {
                filter.addFilter (context, "tl_assessment_criteria.job_id", "Job");
                return this;
            }
            
                public AssessmentCriteria[]
             search (ObjectTransaction transaction) throws StorageException
        {
            
            
            BaseBusinessClass[]     results = super.search (transaction, REFERENCE_AssessmentCriteria, SEARCH_All, criteria);
            Set<AssessmentCriteria>   typedResults = new LinkedHashSet <AssessmentCriteria> ();
            for (BaseBusinessClass bbcResult : results)
            {
                AssessmentCriteria aResult = (AssessmentCriteria)bbcResult;
                
                typedResults.add (aResult);
            }
            
                    return ObjstoreUtils.removeDeleted(transaction, typedResults).toArray (new AssessmentCriteria[0]);
                            
        }
    }

        
                public static AssessmentCriteria[]
             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_Name))
        {
            return HELPER_Name.toObject (getName ());
        }
        else if (attribName.equals (FIELD_Importance))
        {
            return HELPER_Importance.toObject (getImportance ());
        }
        else if (attribName.equals (FIELD_CriteriaType))
        {
            return HELPER_CriteriaType.toObject (getCriteriaType ());
        }
        else
        {
            return super.getAttribute (attribName);
        }
    }


    public AttributeHelper getAttributeHelper (String attribName)
    {
        if (false)
        {
            throw new RuntimeException ("Game over man!!");
        }
        else if (attribName.equals (FIELD_Name))
        {
            return HELPER_Name;
        }
        else if (attribName.equals (FIELD_Importance))
        {
            return HELPER_Importance;
        }
        else if (attribName.equals (FIELD_CriteriaType))
        {
            return HELPER_CriteriaType;
        }
        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_Name))
        {
            setName ((String)(HELPER_Name.fromObject (_Name, attribValue)));            
        }
        else if (attribName.equals (FIELD_Importance))
        {
            setImportance ((Importance)(HELPER_Importance.fromObject (_Importance, attribValue)));            
        }
        else if (attribName.equals (FIELD_CriteriaType))
        {
            setCriteriaType ((CriteriaType)(HELPER_CriteriaType.fromObject (_CriteriaType, 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_Name))
        {
            return getWriteability_Name ();
        }
        else if (fieldName.equals (FIELD_Importance))
        {
            return getWriteability_Importance ();
        }
        else if (fieldName.equals (FIELD_CriteriaType))
        {
            return getWriteability_CriteriaType ();
        }
        else if (fieldName.equals (SINGLEREFERENCE_Job))
        {
            return getWriteability_Job ();
        }
        else
        {
            return super.getWriteable (fieldName);
        }
    }


    public void putUnwriteable (Set<String> fields)
    {
        
            if (getWriteability_Name () != FieldWriteability.TRUE)
            {
                fields.add (FIELD_Name);
            }
        
            if (getWriteability_Importance () != FieldWriteability.TRUE)
            {
                fields.add (FIELD_Importance);
            }
        
            if (getWriteability_CriteriaType () != FieldWriteability.TRUE)
            {
                fields.add (FIELD_CriteriaType);
            }
        

        super.putUnwriteable (fields);
    }

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

        
        result.add(HELPER_Name.getAttribObject (getClass (), _Name, false, FIELD_Name));
        result.add(HELPER_Importance.getAttribObject (getClass (), _Importance, false, FIELD_Importance));
        result.add(HELPER_CriteriaType.getAttribObject (getClass (), _CriteriaType, false, FIELD_CriteriaType));

        return result;
    }


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


    public Object getAttributeMetadata (String attribute, String metadata)
    {
        if (ATTRIBUTES_METADATA_AssessmentCriteria.containsKey (attribute))
        {
            return ((Map)ATTRIBUTES_METADATA_AssessmentCriteria.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 AssessmentCriteriaBehaviourDecorator extends BaseBusinessClass.BBCBehaviourDecorator<AssessmentCriteria>
    {

    /**
     * Get the attribute Name
     */
    public String getName (AssessmentCriteria obj, String original)
    {
        return original;
    }

    /**
     * Change the value set for attribute Name.
     * May modify the field beforehand
     * Occurs before validation.
     */
    public String setName (AssessmentCriteria obj, String newName) throws FieldException
    {
        return newName;
    }

    /**
     * Get the attribute Importance
     */
    public Importance getImportance (AssessmentCriteria obj, Importance original)
    {
        return original;
    }

    /**
     * Change the value set for attribute Importance.
     * May modify the field beforehand
     * Occurs before validation.
     */
    public Importance setImportance (AssessmentCriteria obj, Importance newImportance) throws FieldException
    {
        return newImportance;
    }

    /**
     * Get the attribute CriteriaType
     */
    public CriteriaType getCriteriaType (AssessmentCriteria obj, CriteriaType original)
    {
        return original;
    }

    /**
     * Change the value set for attribute CriteriaType.
     * May modify the field beforehand
     * Occurs before validation.
     */
    public CriteriaType setCriteriaType (AssessmentCriteria obj, CriteriaType newCriteriaType) throws FieldException
    {
        return newCriteriaType;
    }

    }

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

        public AssessmentCriteriaPipeLineFactory (Collection<From> seed)
        {
            super(seed);
        }
        
        
        public PipeLine<From, ? extends Object> to(String name)
        {
            if (name.equals ("Name"))
            {
                return toName ();
            }                
            if (name.equals ("Importance"))
            {
                return toImportance ();
            }                
            if (name.equals ("CriteriaType"))
            {
                return toCriteriaType ();
            }                
            if (name.equals ("Job"))
            {
                return toJob ();
            }                
            
            
            return super.to(name);
        }
        
        
        public PipeLine<From, String> toName () { return pipe(new ORMAttributePipe<Me, String>(FIELD_Name));  }
        
        public PipeLine<From, Importance> toImportance () { return pipe(new ORMAttributePipe<Me, Importance>(FIELD_Importance));  }
        
        public PipeLine<From, CriteriaType> toCriteriaType () { return pipe(new ORMAttributePipe<Me, CriteriaType>(FIELD_CriteriaType));  }
        public Job.JobPipeLineFactory<From, Job> toJob () { return toJob (Filter.ALL); }

        public Job.JobPipeLineFactory<From, Job> toJob (Filter<Job> filter) 
        { 
            return Job.REFERENCE_Job.new JobPipeLineFactory<From, Job> (this, new ORMSingleAssocPipe<Me, Job>(SINGLEREFERENCE_Job, filter)); 
        }
        
    }
    
    public boolean isTransientAttrib(String attribName)
    {
        

        return super.isTransientAttrib(attribName);
    }

    public boolean isTransientSingleReference(String assocName)
    {
        

        return super.isTransientSingleReference(assocName);
    }
}

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

    public void assertValid ()
    {
    }


    public Job getJob () throws StorageException
    {
        return (Job)(Job.DUMMY_Job);
    }


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

}

    
