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


    package performa.orm;

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



public abstract class BaseTestAnalysis extends BaseBusinessClass
{
    // Reference instance for the object
    public static final TestAnalysis REFERENCE_TestAnalysis = new TestAnalysis ();

    // Reference instance for the object
    public static final TestAnalysis DUMMY_TestAnalysis = new DummyTestAnalysis ();

    // Static constants corresponding to field names
    
    public static final String SINGLEREFERENCE_Level = "Level";
    public static final String BACKREF_Level = "";
    public static final String SINGLEREFERENCE_Candidate = "Candidate";
    public static final String BACKREF_Candidate = "";
    public static final String MULTIPLEREFERENCE_FactorScores = "FactorScores";
    public static final String BACKREF_FactorScores = "";

    // 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<TestAnalysis, Level> _Level;
    private SingleAssociation<TestAnalysis, Candidate> _Candidate;
    

    // Private attributes corresponding to multiple references
    private MultipleAssociation<TestAnalysis, FactorScore> _FactorScores;
    

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

    // Arrays of validators for each attribute
    

    // Arrays of behaviour decorators
    private static final TestAnalysisBehaviourDecorator[] TestAnalysis_BehaviourDecorators;
    
    static
    {
        try
        {
            
            String tmp_FactorScores = FactorScore.BACKREF_TestAnalysis;
            String tmp_Level = Level.BACKREF_TestAnalysises;
            String tmp_Candidate = Candidate.BACKREF_TestAnalysises;
            
            Map  validatorMapping = ((Map)ConfigMgr.getConfigObject ("CONFIG.ORMVALIDATOR", "ValidatorMapping"));

            setupAssocMetaData_FactorScores();
            setupAssocMetaData_Level();
            setupAssocMetaData_Candidate();
            

            REFERENCE_TestAnalysis.initialiseReference ();
            DUMMY_TestAnalysis.initialiseReference ();
            TestAnalysis_BehaviourDecorators = BaseBusinessClass.getBBCBehaviours(TestAnalysis.class).toArray(new TestAnalysisBehaviourDecorator[0]);
        }
        catch (RuntimeException e)
        {
            LogMgr.log (BUSINESS_OBJECTS, LogLevel.SYSTEMERROR1, e, "Error initialising");
            throw e;
        }
    }

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

        metaInfo.put ("backreferenceName", "TestAnalysis");
        metaInfo.put ("name", "FactorScores");
        metaInfo.put ("type", "FactorScore");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for TestAnalysis.FactorScores:", metaInfo);
        ATTRIBUTES_METADATA_TestAnalysis.put (MULTIPLEREFERENCE_FactorScores, Collections.unmodifiableMap (metaInfo));
    }
    
    
    // Meta Info setup
    private static void setupAssocMetaData_Level()
    {
        Map metaInfo = new HashMap ();

        metaInfo.put ("backreferenceName", "TestAnalysises");
        metaInfo.put ("dbcol", "level_id");
        metaInfo.put ("name", "Level");
        metaInfo.put ("type", "Level");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for TestAnalysis.Level:", metaInfo);
        ATTRIBUTES_METADATA_TestAnalysis.put (SINGLEREFERENCE_Level, Collections.unmodifiableMap (metaInfo));
    }
    
    
    // Meta Info setup
    private static void setupAssocMetaData_Candidate()
    {
        Map metaInfo = new HashMap ();

        metaInfo.put ("backreferenceName", "TestAnalysises");
        metaInfo.put ("dbcol", "candidate_id");
        metaInfo.put ("name", "Candidate");
        metaInfo.put ("type", "Candidate");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for TestAnalysis.Candidate:", metaInfo);
        ATTRIBUTES_METADATA_TestAnalysis.put (SINGLEREFERENCE_Candidate, Collections.unmodifiableMap (metaInfo));
    }
    
    
    // END OF STATIC METADATA DEFINITION    
    
    
    
    // This constructor should not be called
    protected BaseTestAnalysis ()
    {
    }


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


    


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

        
    }


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

        _Level = new SingleAssociation<TestAnalysis, Level> (this, SINGLEREFERENCE_Level, Level.MULTIPLEREFERENCE_TestAnalysises, Level.REFERENCE_Level, "tl_test_analysis");
        _Candidate = new SingleAssociation<TestAnalysis, Candidate> (this, SINGLEREFERENCE_Candidate, Candidate.MULTIPLEREFERENCE_TestAnalysises, Candidate.REFERENCE_Candidate, "tl_test_analysis");
        _FactorScores = new MultipleAssociation<TestAnalysis, FactorScore> (this, MULTIPLEREFERENCE_FactorScores, FactorScore.SINGLEREFERENCE_TestAnalysis, FactorScore.REFERENCE_FactorScore);
        
    }


    // Initialise the associations
    protected BaseBusinessClass initialiseReference ()
    {
        super.initialiseReference ();
        
        _Level = new SingleAssociation<TestAnalysis, Level> (this, SINGLEREFERENCE_Level, Level.MULTIPLEREFERENCE_TestAnalysises, Level.REFERENCE_Level, "tl_test_analysis");
        _Candidate = new SingleAssociation<TestAnalysis, Candidate> (this, SINGLEREFERENCE_Candidate, Candidate.MULTIPLEREFERENCE_TestAnalysises, Candidate.REFERENCE_Candidate, "tl_test_analysis");
        _FactorScores = new MultipleAssociation<TestAnalysis, FactorScore> (this, MULTIPLEREFERENCE_FactorScores, FactorScore.SINGLEREFERENCE_TestAnalysis, FactorScore.REFERENCE_FactorScore);
        
        
        return this;
    }

    



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

        
        result.add("Level");
        
        result.add("Candidate");
        

        return result;
    }
    
    
    public BaseBusinessClass getSingleAssocReferenceInstance (String assocName)
    {
        if (assocName == null)
        {
            throw new RuntimeException ("Game over == null!");
        }
        else if (assocName.equals (SINGLEREFERENCE_Level))
        {
            return _Level.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_Level))
        {
            return Level.MULTIPLEREFERENCE_TestAnalysises ;
        }else if (assocName.equals (SINGLEREFERENCE_Candidate))
        {
            return Candidate.MULTIPLEREFERENCE_TestAnalysises ;
        }
        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_Level))
        {
            return getLevel ();
        }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_Level))
        {
            return getLevel (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_Level))
        {
            return getLevelID ();
        }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_Level))
        {
            setLevel ((Level)(newValue));
        }else if (assocName.equals (SINGLEREFERENCE_Candidate))
        {
            setCandidate ((Candidate)(newValue));
        }
        else
        {
            super.setSingleAssoc (assocName, newValue);
        }
    }



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


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


    /**
     * Get the object id for the referenced object.  Does not force a DB access.
     */
    public Long getLevelID ()
    {
        assertValid();
        
        if (_Level == null)
        {
            return null;
        }
        else
        {
            return _Level.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 preLevelChange (Level newLevel) 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 postLevelChange () throws FieldException
    {
    }



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

        if (_Level.wouldReferencedChange (newLevel))
        {
            assertValid();
            Debug.assertion (getWriteability_Level () != FieldWriteability.FALSE, "Assoc Level is not writeable");
            preLevelChange (newLevel);
            Level oldLevel = getLevel ();

                    if (oldLevel != null)
                    {
                        // This is to stop validation from triggering when we are removed
                        _Level.set (null);
                        oldLevel.removeFromTestAnalysises ((TestAnalysis)(this));
                    }

                    _Level.set (newLevel);

                    if (newLevel != null)
                    {
                        newLevel.addToTestAnalysises ((TestAnalysis)(this));
                    }
                
            postLevelChange ();
        }
    }

    /**
     * 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 TestAnalysis:", 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
    {
        

        if (_Candidate.wouldReferencedChange (newCandidate))
        {
            assertValid();
            Debug.assertion (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.removeFromTestAnalysises ((TestAnalysis)(this));
                    }

                    _Candidate.set (newCandidate);

                    if (newCandidate != null)
                    {
                        newCandidate.addToTestAnalysises ((TestAnalysis)(this));
                    }
                
            postCandidateChange ();
        }
    }

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

        
        result.add("FactorScores");
        

        return result;
    }


    /**
     * Get the reference instance for the multi assoc name.
     */
    public BaseBusinessClass getMultiAssocReferenceInstance(String attribName)
    {
        
        if (MULTIPLEREFERENCE_FactorScores.equals(attribName))
        {
            return FactorScore.REFERENCE_FactorScore ;
        }
        

        return super.getMultiAssocReferenceInstance(attribName);
    }


    public String getMultiAssocBackReference(String attribName)
    {
        
        if (MULTIPLEREFERENCE_FactorScores.equals(attribName))
        {
            return FactorScore.SINGLEREFERENCE_TestAnalysis ;
        }
        

        return super.getMultiAssocBackReference(attribName);
    }


    /**
     * Get the assoc count for the multi assoc name.
     */
    public int getMultiAssocCount(String attribName) throws StorageException
    {
        
        if (MULTIPLEREFERENCE_FactorScores.equals(attribName))
        {
            return this.getFactorScoresCount();
        }
        

        return super.getMultiAssocCount(attribName);
    }


    /**
     * Get the assoc at a particular index
     */
    public BaseBusinessClass getMultiAssocAt(String attribName, int index) throws StorageException
    {
        
        if (MULTIPLEREFERENCE_FactorScores.equals(attribName))
        {
            return this.getFactorScoresAt(index);
        }
        

        return super.getMultiAssocAt(attribName, index);
    }


    /**
     * Add to a multi assoc by attribute name
     */
    public void addToMultiAssoc(String attribName, BaseBusinessClass newElement) throws StorageException
    {
        
        if (MULTIPLEREFERENCE_FactorScores.equals(attribName))
        {
            addToFactorScores((FactorScore)newElement);

            return;
        }
        

        super.addToMultiAssoc(attribName, newElement);
    }

    /**
     * Remove from a multi assoc by attribute name
     */
    public void removeFromMultiAssoc(String attribName, BaseBusinessClass oldElement) throws StorageException
    {
        
        if (MULTIPLEREFERENCE_FactorScores.equals(attribName))
        {
            removeFromFactorScores((FactorScore)oldElement);

            return;
        }
        

        super.removeFromMultiAssoc(attribName, oldElement);
    }


    protected void __loadMultiAssoc (String attribName, BaseBusinessClass[] elements)
    {
        
        if (MULTIPLEREFERENCE_FactorScores.equals(attribName))
        {
            _FactorScores.__loadAssociation (elements);
            return;
        }
        

        super.__loadMultiAssoc(attribName, elements);
    }


    protected boolean __isMultiAssocLoaded (String attribName)
    {
        
        if (MULTIPLEREFERENCE_FactorScores.equals(attribName))
        {
            return _FactorScores.isLoaded ();
        }
        

        return super.__isMultiAssocLoaded(attribName);
    }

    

    public FieldWriteability getWriteability_FactorScores ()
    {
        return getFieldWritabilityUtil (FieldWriteability.TRUE);
    }
    
    
    public int getFactorScoresCount () throws StorageException
    {
        assertValid();
        return _FactorScores.getReferencedObjectsCount ();
    }


    public void addToFactorScores (FactorScore newElement) throws StorageException
    {
        if (_FactorScores.wouldAddChange (newElement))
        {
            assertValid();
            Debug.assertion (getWriteability_FactorScores () != FieldWriteability.FALSE, "MultiAssoc FactorScores is not writeable (add)");
            _FactorScores.appendElement (newElement);

            try
            {
                if (newElement.getTestAnalysis () != this)
                {
                    newElement.setTestAnalysis ((TestAnalysis)(this));
                }
            }
            catch (Exception e)
            {
                throw NestedException.wrap(e);
            }
        }
    }


    public void removeFromFactorScores (FactorScore elementToRemove) throws StorageException
    {
        if (_FactorScores.wouldRemoveChange (elementToRemove))
        {
            assertValid();
            Debug.assertion (getWriteability_FactorScores () != FieldWriteability.FALSE, "MultiAssoc FactorScores is not writeable (remove)");
            _FactorScores.removeElement (elementToRemove);
            try
            {
                if (elementToRemove.getTestAnalysis () != null)
                {
                    elementToRemove.setTestAnalysis (null);
                }
            }
            catch (Exception e)
            {
                throw NestedException.wrap(e);
            }
        }
    }


    public FactorScore getFactorScoresAt (int index) throws StorageException
    {
        return (FactorScore)(_FactorScores.getElementAt (index));
    }


    public SortedSet<FactorScore> getFactorScoresSet () throws StorageException
    {
        return _FactorScores.getSet ();
    }



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

                if (referenced != null)
                {
                    // Stop the callback
                    LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG1, "Setting backreference to null TestAnalysises from ", getObjectID (), " to ", referenced.getObjectID ());
                    _Level.set (null);
                    referenced.removeFromTestAnalysises ((TestAnalysis)this);
                }
            }
        
            // 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 TestAnalysises from ", getObjectID (), " to ", referenced.getObjectID ());
                    _Candidate.set (null);
                    referenced.removeFromTestAnalysises ((TestAnalysis)this);
                }
            }
        
            for(FactorScore referenced : CollectionUtils.reverse(getFactorScoresSet()))
            { 
                LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG1, "Setting backreference to null TestAnalysis from ", getObjectID (), " to ", referenced.getObjectID ());
                referenced.setTestAnalysis(null);
            }

        }
        catch (Exception e)
        {
            throw NestedException.wrap(e);
        }

        super.onDelete ();
    }


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


    public TestAnalysis referenceInstance ()
    {
        return REFERENCE_TestAnalysis;
    }


    public TestAnalysis getInTransaction (ObjectTransaction t) throws StorageException
    {
        return getTestAnalysisByID (t, getObjectID());
    }
    
    
    public BaseBusinessClass dummyInstance ()
    {
        return DUMMY_TestAnalysis;
    }


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





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

        tl_test_analysisPSet.setAttrib (FIELD_ObjectID, myID);
        _Level.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_test_analysisPSet = allSets.getPersistentSet (objectID, "tl_test_analysis");

        _Level.setFromPersistentSets (objectID, allSets);
        _Candidate.setFromPersistentSets (objectID, allSets);
        
    }





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

        if (other instanceof TestAnalysis)
        {
            TestAnalysis otherTestAnalysis = (TestAnalysis)other;
            
        }
    }


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

        if (source instanceof BaseTestAnalysis)
        {
            BaseTestAnalysis sourceTestAnalysis = (BaseTestAnalysis)(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 BaseTestAnalysis)
        {
            BaseTestAnalysis sourceTestAnalysis = (BaseTestAnalysis)(source);

            _Level.copyFrom (sourceTestAnalysis._Level, linkToGhosts);
            _Candidate.copyFrom (sourceTestAnalysis._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 BaseTestAnalysis)
        {
            BaseTestAnalysis sourceTestAnalysis = (BaseTestAnalysis)(source);

            _FactorScores.copyFrom (sourceTestAnalysis._FactorScores, linkToGhosts);
            
        }
    }


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

        _Level.readExternalData(vals.get(SINGLEREFERENCE_Level));
        _Candidate.readExternalData(vals.get(SINGLEREFERENCE_Candidate));
        _FactorScores.readExternalData(vals.get(MULTIPLEREFERENCE_FactorScores));
        
    }


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

        vals.put (SINGLEREFERENCE_Level, _Level.writeExternalData());
        vals.put (SINGLEREFERENCE_Candidate, _Candidate.writeExternalData());
        vals.put (MULTIPLEREFERENCE_FactorScores, _FactorScores.writeExternalData());
        
    }


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

        if (other instanceof BaseTestAnalysis)
        {
            BaseTestAnalysis otherTestAnalysis = (BaseTestAnalysis)(other);

            

            // Compare single assocs
            _Level.compare (otherTestAnalysis._Level, listener);
            _Candidate.compare (otherTestAnalysis._Candidate, listener);
            

            // Compare multiple assocs
            _FactorScores.compare (otherTestAnalysis._FactorScores, listener);
            
        }
    }


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

        
    }


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

        visitor.visitAssociation (_Level);
        visitor.visitAssociation (_Candidate);
        visitor.visitAssociation (_FactorScores);
        
    }


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

        if (scope.includes (_Level))
        {
            visitor.visit (_Level);
        }
        if (scope.includes (_Candidate))
        {
            visitor.visit (_Candidate);
        }
        if (scope.includes (_FactorScores))
        {
            visitor.visit (_FactorScores);
        }
        
    }


    public static TestAnalysis createTestAnalysis (ObjectTransaction transaction) throws StorageException
    {
        TestAnalysis     result = new TestAnalysis ();

        result.initialiseNewObject (transaction);

        return result;
    }


    public static TestAnalysis getTestAnalysisByID (ObjectTransaction transaction, Long objectID) throws StorageException
    {
        return (TestAnalysis)(transaction.getObjectByID (REFERENCE_TestAnalysis, objectID));
    }

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

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

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

            
            public SearchAll andLevel (QueryFilter<Level> filter)
            {
                filter.addFilter (context, "tl_test_analysis.level_id", "Level");
                return this;
            }
            
            public SearchAll andCandidate (QueryFilter<Candidate> filter)
            {
                filter.addFilter (context, "tl_test_analysis.candidate_id", "Candidate");
                return this;
            }
            
                public TestAnalysis[]
             search (ObjectTransaction transaction) throws StorageException
        {
            
            
            BaseBusinessClass[]     results = super.search (transaction, REFERENCE_TestAnalysis, SEARCH_All, criteria);
            Set<TestAnalysis>   typedResults = new LinkedHashSet <TestAnalysis> ();
            for (BaseBusinessClass bbcResult : results)
            {
                TestAnalysis aResult = (TestAnalysis)bbcResult;
                
                typedResults.add (aResult);
            }
            
                    return ObjstoreUtils.removeDeleted(transaction, typedResults).toArray (new TestAnalysis[0]);
                            
        }
    }

        
                public static TestAnalysis[]
             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 FieldWriteability getWriteable (String fieldName)
    {
        if (false)
        {
            throw new RuntimeException ("Game over man!!");
        }
        else if (fieldName.equals (MULTIPLEREFERENCE_FactorScores))
        {
            return getWriteability_FactorScores ();
        }
        else if (fieldName.equals (SINGLEREFERENCE_Level))
        {
            return getWriteability_Level ();
        }
        else if (fieldName.equals (SINGLEREFERENCE_Candidate))
        {
            return getWriteability_Candidate ();
        }
        else
        {
            return super.getWriteable (fieldName);
        }
    }


    public void putUnwriteable (Set<String> fields)
    {
        

        super.putUnwriteable (fields);
    }

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

        

        return result;
    }


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


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

    }

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

        public TestAnalysisPipeLineFactory (Collection<From> seed)
        {
            super(seed);
        }
        
        
        public PipeLine<From, ? extends Object> to(String name)
        {
            if (name.equals ("FactorScores"))
            {
                return toFactorScores ();
            }                
            if (name.equals ("Level"))
            {
                return toLevel ();
            }                
            if (name.equals ("Candidate"))
            {
                return toCandidate ();
            }                
            
            
            return super.to(name);
        }
        
        public Level.LevelPipeLineFactory<From, Level> toLevel () { return toLevel (Filter.ALL); }

        public Level.LevelPipeLineFactory<From, Level> toLevel (Filter<Level> filter) 
        { 
            return Level.REFERENCE_Level.new LevelPipeLineFactory<From, Level> (this, new ORMSingleAssocPipe<Me, Level>(SINGLEREFERENCE_Level, 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 FactorScore.FactorScorePipeLineFactory<From, FactorScore> toFactorScores () { return toFactorScores(Filter.ALL); }        

        public FactorScore.FactorScorePipeLineFactory<From, FactorScore> toFactorScores (Filter<FactorScore> filter)
        {
            return FactorScore.REFERENCE_FactorScore.new FactorScorePipeLineFactory<From, FactorScore> (this, new ORMMultiAssocPipe<Me, FactorScore>(MULTIPLEREFERENCE_FactorScores, filter)); 
        }
        
    }
    
    public boolean isTransientAttrib(String attribName)
    {
        

        return super.isTransientAttrib(attribName);
    }

    public boolean isTransientSingleReference(String assocName)
    {
        

        return super.isTransientSingleReference(assocName);
    }
}

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

    public void assertValid ()
    {
    }


    public Level getLevel () throws StorageException
    {
        return (Level)(Level.DUMMY_Level);
    }


    /**
     * Get the object id for the referenced object.  Does not force a DB access.
     */
    public Long getLevelID ()
    {
        return Level.DUMMY_Level.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();
    }

    public int getFactorScoresCount () throws StorageException
    {
        return 0;
    }


    public FactorScore getFactorScoresAt (int index) throws StorageException
    {
        throw new RuntimeException ("No elements in a dummy object in association FactorScores");
    }


    public SortedSet getFactorScoresSet () throws StorageException
    {
        return new TreeSet();
    }

}

    
