/*
 * 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 BaseFactorScore extends BaseBusinessClass
{
    // Reference instance for the object
    public static final FactorScore REFERENCE_FactorScore = new FactorScore ();

    // Reference instance for the object
    public static final FactorScore DUMMY_FactorScore = new DummyFactorScore ();

    // Static constants corresponding to field names
    
    public static final String FIELD_Score = "Score";
    public static final String SINGLEREFERENCE_TestAnalysis = "TestAnalysis";
    public static final String BACKREF_TestAnalysis = "";
    public static final String SINGLEREFERENCE_Factor = "Factor";

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

    // Static constants corresponding to attribute helpers
    private static final DefaultAttributeHelper<FactorScore> HELPER_Score = DefaultAttributeHelper.INSTANCE;
    

    // Private attributes corresponding to business object data
    private Integer _Score;
    

    // Private attributes corresponding to single references
    private SingleAssociation<FactorScore, TestAnalysis> _TestAnalysis;
    private SingleAssociation<FactorScore, Factor> _Factor;
    

    // Private attributes corresponding to multiple references
    

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

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

    // Arrays of behaviour decorators
    private static final FactorScoreBehaviourDecorator[] FactorScore_BehaviourDecorators;
    
    static
    {
        try
        {
            
            String tmp_TestAnalysis = TestAnalysis.BACKREF_FactorScores;
            
            Map  validatorMapping = ((Map)ConfigMgr.getConfigObject ("CONFIG.ORMVALIDATOR", "ValidatorMapping"));

            setupAssocMetaData_TestAnalysis();
            setupAssocMetaData_Factor();
            FIELD_Score_Validators = (AttributeValidator[])setupAttribMetaData_Score(validatorMapping).toArray (new AttributeValidator[0]);
            

            REFERENCE_FactorScore.initialiseReference ();
            DUMMY_FactorScore.initialiseReference ();
            FactorScore_BehaviourDecorators = BaseBusinessClass.getBBCBehaviours(FactorScore.class).toArray(new FactorScoreBehaviourDecorator[0]);
        }
        catch (RuntimeException e)
        {
            LogMgr.log (BUSINESS_OBJECTS, LogLevel.SYSTEMERROR1, e, "Error initialising");
            throw e;
        }
    }

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

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

        metaInfo.put ("dbcol", "factor_number");
        metaInfo.put ("name", "Factor");
        metaInfo.put ("type", "Factor");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for FactorScore.Factor:", metaInfo);
        ATTRIBUTES_METADATA_FactorScore.put (SINGLEREFERENCE_Factor, Collections.unmodifiableMap (metaInfo));
    }
    
    
    // Meta Info setup
    private static List setupAttribMetaData_Score(Map validatorMapping)
    {
        Map  metaInfo   = new HashMap ();

        metaInfo.put ("dbcol", "score_number");
        metaInfo.put ("name", "Score");
        metaInfo.put ("type", "Integer");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for FactorScore.Score:", metaInfo);
        ATTRIBUTES_METADATA_FactorScore.put (FIELD_Score, Collections.unmodifiableMap (metaInfo));

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

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


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


    


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

        
        _Score = (Integer)(HELPER_Score.initialise (_Score));
    }


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

        _TestAnalysis = new SingleAssociation<FactorScore, TestAnalysis> (this, SINGLEREFERENCE_TestAnalysis, TestAnalysis.MULTIPLEREFERENCE_FactorScores, TestAnalysis.REFERENCE_TestAnalysis, "score");
        _Factor = new SingleAssociation<FactorScore, Factor> (this, SINGLEREFERENCE_Factor, null, Factor.REFERENCE_Factor, "score");
        
    }


    // Initialise the associations
    protected BaseBusinessClass initialiseReference ()
    {
        super.initialiseReference ();
        
        _TestAnalysis = new SingleAssociation<FactorScore, TestAnalysis> (this, SINGLEREFERENCE_TestAnalysis, TestAnalysis.MULTIPLEREFERENCE_FactorScores, TestAnalysis.REFERENCE_TestAnalysis, "score");
        _Factor = new SingleAssociation<FactorScore, Factor> (this, SINGLEREFERENCE_Factor, null, Factor.REFERENCE_Factor, "score");
        
        
        return this;
    }

    

    /**
     * Get the attribute Score
     */
    public Integer getScore ()
    {
        assertValid();
        Integer valToReturn = _Score;

            for (FactorScoreBehaviourDecorator bhd : FactorScore_BehaviourDecorators)
            {
                valToReturn = bhd.getScore ((FactorScore)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 preScoreChange (Integer newScore) 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 postScoreChange () throws FieldException
    {
    }

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

    /**
     * Set the attribute Score.  Checks to ensure a new value
     * has been supplied.  If so, marks the field as altered and sets the attribute.
     */
    public void setScore (Integer newScore) throws FieldException
    {
        boolean oldAndNewIdentical = HELPER_Score.compare (_Score, newScore);
        
        try
        {
            for (FactorScoreBehaviourDecorator bhd : FactorScore_BehaviourDecorators)
            {
                newScore = bhd.setScore ((FactorScore)this, newScore);
                oldAndNewIdentical = HELPER_Score.compare (_Score, newScore);
            }

            

            if (FIELD_Score_Validators.length > 0)
            {
                Object newScoreObj = HELPER_Score.toObject (newScore);

                if (newScoreObj != null)
                {
                    int     loopMax = FIELD_Score_Validators.length;
                    Map     metadata = (Map)ATTRIBUTES_METADATA_FactorScore.get (FIELD_Score);

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

        if (!oldAndNewIdentical)
        {
            assertValid();
            Debug.assertion (getWriteability_Score () != FieldWriteability.FALSE, "Field  Score is not writeable");
            preScoreChange (newScore);
            markFieldChange (FIELD_Score);
            _Score = newScore;            
            postFieldChange (FIELD_Score);
            postScoreChange ();
        }
    }



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

        
        result.add("TestAnalysis");
        
        result.add("Factor");
        

        return result;
    }
    
    
    public BaseBusinessClass getSingleAssocReferenceInstance (String assocName)
    {
        if (assocName == null)
        {
            throw new RuntimeException ("Game over == null!");
        }
        else if (assocName.equals (SINGLEREFERENCE_TestAnalysis))
        {
            return _TestAnalysis.getReferencedType ();
        }else if (assocName.equals (SINGLEREFERENCE_Factor))
        {
            return _Factor.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_TestAnalysis))
        {
            return TestAnalysis.MULTIPLEREFERENCE_FactorScores ;
        }else if (assocName.equals (SINGLEREFERENCE_Factor))
        {
            return null ;
        }
        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_TestAnalysis))
        {
            return getTestAnalysis ();
        }else if (assocName.equals (SINGLEREFERENCE_Factor))
        {
            return getFactor ();
        }
        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_TestAnalysis))
        {
            return getTestAnalysis (getType);
        }else if (assocName.equals (SINGLEREFERENCE_Factor))
        {
            return getFactor (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_TestAnalysis))
        {
            return getTestAnalysisID ();
        }else if (assocName.equals (SINGLEREFERENCE_Factor))
        {
            return getFactorID ();
        }
        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_TestAnalysis))
        {
            setTestAnalysis ((TestAnalysis)(newValue));
        }else if (assocName.equals (SINGLEREFERENCE_Factor))
        {
            setFactor ((Factor)(newValue));
        }
        else
        {
            super.setSingleAssoc (assocName, newValue);
        }
    }



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


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


    /**
     * Get the object id for the referenced object.  Does not force a DB access.
     */
    public Long getTestAnalysisID ()
    {
        assertValid();
        
        if (_TestAnalysis == null)
        {
            return null;
        }
        else
        {
            return _TestAnalysis.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 preTestAnalysisChange (TestAnalysis newTestAnalysis) 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 postTestAnalysisChange () throws FieldException
    {
    }



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

        if (_TestAnalysis.wouldReferencedChange (newTestAnalysis))
        {
            assertValid();
            Debug.assertion (getWriteability_TestAnalysis () != FieldWriteability.FALSE, "Assoc TestAnalysis is not writeable");
            preTestAnalysisChange (newTestAnalysis);
            TestAnalysis oldTestAnalysis = getTestAnalysis ();

                    if (oldTestAnalysis != null)
                    {
                        // This is to stop validation from triggering when we are removed
                        _TestAnalysis.set (null);
                        oldTestAnalysis.removeFromFactorScores ((FactorScore)(this));
                    }

                    _TestAnalysis.set (newTestAnalysis);

                    if (newTestAnalysis != null)
                    {
                        newTestAnalysis.addToFactorScores ((FactorScore)(this));
                    }
                
            postTestAnalysisChange ();
        }
    }

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


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


    /**
     * Get the object id for the referenced object.  Does not force a DB access.
     */
    public Long getFactorID ()
    {
        assertValid();
        
        if (_Factor == null)
        {
            return null;
        }
        else
        {
            return _Factor.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 preFactorChange (Factor newFactor) 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 postFactorChange () throws FieldException
    {
    }



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

        if (_Factor.wouldReferencedChange (newFactor))
        {
            assertValid();
            Debug.assertion (getWriteability_Factor () != FieldWriteability.FALSE, "Assoc Factor is not writeable");
            preFactorChange (newFactor);
            
                    _Factor.set (newFactor);
                
            postFactorChange ();
        }
    }

    /**
     * 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 (_TestAnalysis.isLoaded () || getTransaction ().isObjectLoaded (_TestAnalysis.getReferencedType (), getTestAnalysisID ()))
            {
                TestAnalysis  referenced = getTestAnalysis ();

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

        super.onDelete ();
    }


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


    public FactorScore referenceInstance ()
    {
        return REFERENCE_FactorScore;
    }


    public FactorScore getInTransaction (ObjectTransaction t) throws StorageException
    {
        return getFactorScoreByID (t, getObjectID());
    }
    
    
    public BaseBusinessClass dummyInstance ()
    {
        return DUMMY_FactorScore;
    }


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





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

        scorePSet.setAttrib (FIELD_ObjectID, myID);
        scorePSet.setAttrib (FIELD_Score, HELPER_Score.toObject (_Score)); //
        _TestAnalysis.getPersistentSets (allSets);
        _Factor.getPersistentSets (allSets);
        
    }


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

        
        PersistentSet   scorePSet = allSets.getPersistentSet (objectID, "score");

        _Score = (Integer)(HELPER_Score.fromObject (_Score, scorePSet.getAttrib (FIELD_Score))); //
        _TestAnalysis.setFromPersistentSets (objectID, allSets);
        _Factor.setFromPersistentSets (objectID, allSets);
        
    }





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

        if (other instanceof FactorScore)
        {
            FactorScore otherFactorScore = (FactorScore)other;
            
            try
            {
                setScore (otherFactorScore.getScore ());
            }
            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 BaseFactorScore)
        {
            BaseFactorScore sourceFactorScore = (BaseFactorScore)(source);

            _Score = sourceFactorScore._Score;
            
        }
    }


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

            _TestAnalysis.copyFrom (sourceFactorScore._TestAnalysis, linkToGhosts);
            _Factor.copyFrom (sourceFactorScore._Factor, 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 BaseFactorScore)
        {
            BaseFactorScore sourceFactorScore = (BaseFactorScore)(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);

        _Score = (Integer)(HELPER_Score.readExternal (_Score, vals.get(FIELD_Score))); //
        _TestAnalysis.readExternalData(vals.get(SINGLEREFERENCE_TestAnalysis));
        _Factor.readExternalData(vals.get(SINGLEREFERENCE_Factor));
        
    }


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

        vals.put (FIELD_Score, HELPER_Score.writeExternal (_Score));
        vals.put (SINGLEREFERENCE_TestAnalysis, _TestAnalysis.writeExternalData());
        vals.put (SINGLEREFERENCE_Factor, _Factor.writeExternalData());
        
    }


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

        if (other instanceof BaseFactorScore)
        {
            BaseFactorScore otherFactorScore = (BaseFactorScore)(other);

            
            if (!HELPER_Score.compare(this._Score, otherFactorScore._Score))
            {
                listener.notifyFieldChange(this, other, FIELD_Score, HELPER_Score.toObject(this._Score), HELPER_Score.toObject(otherFactorScore._Score));
            }

            // Compare single assocs
            _TestAnalysis.compare (otherFactorScore._TestAnalysis, listener);
            _Factor.compare (otherFactorScore._Factor, 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_Score, HELPER_Score.toObject(getScore()));
        visitor.visitAssociation (_TestAnalysis);
        visitor.visitAssociation (_Factor);
        
    }


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

        if (scope.includes (_TestAnalysis))
        {
            visitor.visit (_TestAnalysis);
        }
        if (scope.includes (_Factor))
        {
            visitor.visit (_Factor);
        }
        
    }


    public static FactorScore createFactorScore (ObjectTransaction transaction) throws StorageException
    {
        FactorScore     result = new FactorScore ();

        result.initialiseNewObject (transaction);

        return result;
    }


    public static FactorScore getFactorScoreByID (ObjectTransaction transaction, Long objectID) throws StorageException
    {
        return (FactorScore)(transaction.getObjectByID (REFERENCE_FactorScore, objectID));
    }

    public boolean testFilter (String attribName, QueryFilter filter) throws StorageException
    {
        if (false)
        {
            throw new RuntimeException ("Game over man!!");
        }
        else if (attribName.equals (FIELD_Score))
        {
            return filter.matches (getScore ());
        }
        else if (attribName.equals (SINGLEREFERENCE_TestAnalysis))
        {
            return filter.matches (getTestAnalysis ());
        }
        else if (attribName.equals (SINGLEREFERENCE_Factor))
        {
            return filter.matches (getFactor ());
        }
        else
        {
            return super.testFilter (attribName, filter);
        }
    }


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

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

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

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

            
            public SearchAll andScore (QueryFilter<Integer> filter)
            {
                filter.addFilter (context, "score.score_number", "Score");
                return this;
            }
            
            public SearchAll andTestAnalysis (QueryFilter<TestAnalysis> filter)
            {
                filter.addFilter (context, "score.test_analysis_id", "TestAnalysis");
                return this;
            }
            
            public SearchAll andFactor (QueryFilter<Factor> filter)
            {
                filter.addFilter (context, "score.factor_number", "Factor");
                return this;
            }
            
                public FactorScore[]
             search (ObjectTransaction transaction) throws StorageException
        {
            
            
            BaseBusinessClass[]     results = super.search (transaction, REFERENCE_FactorScore, SEARCH_All, criteria);
            Set<FactorScore>   typedResults = new LinkedHashSet <FactorScore> ();
            for (BaseBusinessClass bbcResult : results)
            {
                FactorScore aResult = (FactorScore)bbcResult;
                
                typedResults.add (aResult);
            }
            
                    return ObjstoreUtils.removeDeleted(transaction, typedResults).toArray (new FactorScore[0]);
                            
        }
    }

        
                public static FactorScore[]
             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_Score))
        {
            return HELPER_Score.toObject (getScore ());
        }
        else
        {
            return super.getAttribute (attribName);
        }
    }


    public AttributeHelper getAttributeHelper (String attribName)
    {
        if (false)
        {
            throw new RuntimeException ("Game over man!!");
        }
        else if (attribName.equals (FIELD_Score))
        {
            return HELPER_Score;
        }
        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_Score))
        {
            setScore ((Integer)(HELPER_Score.fromObject (_Score, 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_Score))
        {
            return getWriteability_Score ();
        }
        else if (fieldName.equals (SINGLEREFERENCE_TestAnalysis))
        {
            return getWriteability_TestAnalysis ();
        }
        else if (fieldName.equals (SINGLEREFERENCE_Factor))
        {
            return getWriteability_Factor ();
        }
        else
        {
            return super.getWriteable (fieldName);
        }
    }


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

        super.putUnwriteable (fields);
    }

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

        
        result.add(HELPER_Score.getAttribObject (getClass (), _Score, false, FIELD_Score));

        return result;
    }


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


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

    /**
     * Get the attribute Score
     */
    public Integer getScore (FactorScore obj, Integer original)
    {
        return original;
    }

    /**
     * Change the value set for attribute Score.
     * May modify the field beforehand
     * Occurs before validation.
     */
    public Integer setScore (FactorScore obj, Integer newScore) throws FieldException
    {
        return newScore;
    }

    }

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

        public FactorScorePipeLineFactory (Collection<From> seed)
        {
            super(seed);
        }
        
        
        public PipeLine<From, ? extends Object> to(String name)
        {
            if (name.equals ("Score"))
            {
                return toScore ();
            }                
            if (name.equals ("TestAnalysis"))
            {
                return toTestAnalysis ();
            }                
            if (name.equals ("Factor"))
            {
                return toFactor ();
            }                
            
            
            return super.to(name);
        }
        
        
        public PipeLine<From, Integer> toScore () { return pipe(new ORMAttributePipe<Me, Integer>(FIELD_Score));  }
        public TestAnalysis.TestAnalysisPipeLineFactory<From, TestAnalysis> toTestAnalysis () { return toTestAnalysis (Filter.ALL); }

        public TestAnalysis.TestAnalysisPipeLineFactory<From, TestAnalysis> toTestAnalysis (Filter<TestAnalysis> filter) 
        { 
            return TestAnalysis.REFERENCE_TestAnalysis.new TestAnalysisPipeLineFactory<From, TestAnalysis> (this, new ORMSingleAssocPipe<Me, TestAnalysis>(SINGLEREFERENCE_TestAnalysis, filter)); 
        }
        public Factor.FactorPipeLineFactory<From, Factor> toFactor () { return toFactor (Filter.ALL); }

        public Factor.FactorPipeLineFactory<From, Factor> toFactor (Filter<Factor> filter) 
        { 
            return Factor.REFERENCE_Factor.new FactorPipeLineFactory<From, Factor> (this, new ORMSingleAssocPipe<Me, Factor>(SINGLEREFERENCE_Factor, filter)); 
        }
        
    }
    
    public boolean isTransientAttrib(String attribName)
    {
        

        return super.isTransientAttrib(attribName);
    }

    public boolean isTransientSingleReference(String assocName)
    {
        

        return super.isTransientSingleReference(assocName);
    }
}

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

    public void assertValid ()
    {
    }


    public TestAnalysis getTestAnalysis () throws StorageException
    {
        return (TestAnalysis)(TestAnalysis.DUMMY_TestAnalysis);
    }


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

    public Factor getFactor () throws StorageException
    {
        return (Factor)(Factor.DUMMY_Factor);
    }


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

}

    
