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

    // Reference instance for the object
    public static final LevelFactorType DUMMY_LevelFactorType = new DummyLevelFactorType ();

    // Static constants corresponding to field names
    
    public static final String FIELD_TypeFlag = "TypeFlag";
    public static final String SINGLEREFERENCE_Level = "Level";
    public static final String BACKREF_Level = "";
    public static final String SINGLEREFERENCE_Factor = "Factor";
    public static final String BACKREF_Factor = "";

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

    // Static constants corresponding to attribute helpers
    private static final EnumeratedAttributeHelper<LevelFactorType, TypeFlag> HELPER_TypeFlag =  new EnumeratedAttributeHelper<LevelFactorType, TypeFlag> (TypeFlag.FACTORY_TypeFlag);
    

    // Private attributes corresponding to business object data
    private TypeFlag _TypeFlag;
    

    // Private attributes corresponding to single references
    private SingleAssociation<LevelFactorType, Level> _Level;
    private SingleAssociation<LevelFactorType, Factor> _Factor;
    

    // Private attributes corresponding to multiple references
    

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

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

    // Arrays of behaviour decorators
    private static final LevelFactorTypeBehaviourDecorator[] LevelFactorType_BehaviourDecorators;
    
    static
    {
        try
        {
            
            String tmp_Level = Level.BACKREF_LevelFactorTypes;
            String tmp_Factor = Factor.BACKREF_LevelFactorTypes;
            
            Map  validatorMapping = ((Map)ConfigMgr.getConfigObject ("CONFIG.ORMVALIDATOR", "ValidatorMapping"));

            setupAssocMetaData_Level();
            setupAssocMetaData_Factor();
            FIELD_TypeFlag_Validators = (AttributeValidator[])setupAttribMetaData_TypeFlag(validatorMapping).toArray (new AttributeValidator[0]);
            

            REFERENCE_LevelFactorType.initialiseReference ();
            DUMMY_LevelFactorType.initialiseReference ();
            LevelFactorType_BehaviourDecorators = BaseBusinessClass.getBBCBehaviours(LevelFactorType.class).toArray(new LevelFactorTypeBehaviourDecorator[0]);
        }
        catch (RuntimeException e)
        {
            LogMgr.log (BUSINESS_OBJECTS, LogLevel.SYSTEMERROR1, e, "Error initialising");
            throw e;
        }
    }

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

        metaInfo.put ("backreferenceName", "LevelFactorTypes");
        metaInfo.put ("dbcol", "level_number");
        metaInfo.put ("name", "Level");
        metaInfo.put ("type", "Level");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for LevelFactorType.Level:", metaInfo);
        ATTRIBUTES_METADATA_LevelFactorType.put (SINGLEREFERENCE_Level, Collections.unmodifiableMap (metaInfo));
    }
    
    
    // Meta Info setup
    private static void setupAssocMetaData_Factor()
    {
        Map metaInfo = new HashMap ();

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

        metaInfo.put ("attribHelper", "EnumeratedAttributeHelper");
        metaInfo.put ("dbcol", "type_flag");
        metaInfo.put ("name", "TypeFlag");
        metaInfo.put ("type", "TypeFlag");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for LevelFactorType.TypeFlag:", metaInfo);
        ATTRIBUTES_METADATA_LevelFactorType.put (FIELD_TypeFlag, Collections.unmodifiableMap (metaInfo));

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

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


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


    


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

        
        _TypeFlag = (TypeFlag)(HELPER_TypeFlag.initialise (_TypeFlag));
    }


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

        _Level = new SingleAssociation<LevelFactorType, Level> (this, SINGLEREFERENCE_Level, Level.MULTIPLEREFERENCE_LevelFactorTypes, Level.REFERENCE_Level, "tl_level_type");
        _Factor = new SingleAssociation<LevelFactorType, Factor> (this, SINGLEREFERENCE_Factor, Factor.MULTIPLEREFERENCE_LevelFactorTypes, Factor.REFERENCE_Factor, "tl_level_type");
        
    }


    // Initialise the associations
    protected BaseBusinessClass initialiseReference ()
    {
        super.initialiseReference ();
        
        _Level = new SingleAssociation<LevelFactorType, Level> (this, SINGLEREFERENCE_Level, Level.MULTIPLEREFERENCE_LevelFactorTypes, Level.REFERENCE_Level, "tl_level_type");
        _Factor = new SingleAssociation<LevelFactorType, Factor> (this, SINGLEREFERENCE_Factor, Factor.MULTIPLEREFERENCE_LevelFactorTypes, Factor.REFERENCE_Factor, "tl_level_type");
        
        
        return this;
    }

    

    /**
     * Get the attribute TypeFlag
     */
    public TypeFlag getTypeFlag ()
    {
        assertValid();
        TypeFlag valToReturn = _TypeFlag;

            for (LevelFactorTypeBehaviourDecorator bhd : LevelFactorType_BehaviourDecorators)
            {
                valToReturn = bhd.getTypeFlag ((LevelFactorType)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 preTypeFlagChange (TypeFlag newTypeFlag) 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 postTypeFlagChange () throws FieldException
    {
    }

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

    /**
     * Set the attribute TypeFlag.  Checks to ensure a new value
     * has been supplied.  If so, marks the field as altered and sets the attribute.
     */
    public void setTypeFlag (TypeFlag newTypeFlag) throws FieldException
    {
        boolean oldAndNewIdentical = HELPER_TypeFlag.compare (_TypeFlag, newTypeFlag);
        
        try
        {
            for (LevelFactorTypeBehaviourDecorator bhd : LevelFactorType_BehaviourDecorators)
            {
                newTypeFlag = bhd.setTypeFlag ((LevelFactorType)this, newTypeFlag);
                oldAndNewIdentical = HELPER_TypeFlag.compare (_TypeFlag, newTypeFlag);
            }

            

            if (FIELD_TypeFlag_Validators.length > 0)
            {
                Object newTypeFlagObj = HELPER_TypeFlag.toObject (newTypeFlag);

                if (newTypeFlagObj != null)
                {
                    int     loopMax = FIELD_TypeFlag_Validators.length;
                    Map     metadata = (Map)ATTRIBUTES_METADATA_LevelFactorType.get (FIELD_TypeFlag);

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

        if (!oldAndNewIdentical)
        {
            assertValid();
            Debug.assertion (getWriteability_TypeFlag () != FieldWriteability.FALSE, "Field  TypeFlag is not writeable");
            preTypeFlagChange (newTypeFlag);
            markFieldChange (FIELD_TypeFlag);
            _TypeFlag = newTypeFlag;            
            postFieldChange (FIELD_TypeFlag);
            postTypeFlagChange ();
        }
    }



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

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

        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_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_Level))
        {
            return Level.MULTIPLEREFERENCE_LevelFactorTypes ;
        }else if (assocName.equals (SINGLEREFERENCE_Factor))
        {
            return Factor.MULTIPLEREFERENCE_LevelFactorTypes ;
        }
        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_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_Level))
        {
            return getLevel (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_Level))
        {
            return getLevelID ();
        }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_Level))
        {
            setLevel ((Level)(newValue));
        }else if (assocName.equals (SINGLEREFERENCE_Factor))
        {
            setFactor ((Factor)(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 LevelFactorType:", 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.removeFromLevelFactorTypes ((LevelFactorType)(this));
                    }

                    _Level.set (newLevel);

                    if (newLevel != null)
                    {
                        newLevel.addToLevelFactorTypes ((LevelFactorType)(this));
                    }
                
            postLevelChange ();
        }
    }

    /**
     * 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 LevelFactorType:", 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 oldFactor = getFactor ();

                    if (oldFactor != null)
                    {
                        // This is to stop validation from triggering when we are removed
                        _Factor.set (null);
                        oldFactor.removeFromLevelFactorTypes ((LevelFactorType)(this));
                    }

                    _Factor.set (newFactor);

                    if (newFactor != null)
                    {
                        newFactor.addToLevelFactorTypes ((LevelFactorType)(this));
                    }
                
            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 (_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 LevelFactorTypes from ", getObjectID (), " to ", referenced.getObjectID ());
                    _Level.set (null);
                    referenced.removeFromLevelFactorTypes ((LevelFactorType)this);
                }
            }
        
            // Ensure we are removed from any loaded multi-associations that aren't mandatory
            if (_Factor.isLoaded () || getTransaction ().isObjectLoaded (_Factor.getReferencedType (), getFactorID ()))
            {
                Factor  referenced = getFactor ();

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

        super.onDelete ();
    }


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


    public LevelFactorType referenceInstance ()
    {
        return REFERENCE_LevelFactorType;
    }


    public LevelFactorType getInTransaction (ObjectTransaction t) throws StorageException
    {
        return getLevelFactorTypeByID (t, getObjectID());
    }
    
    
    public BaseBusinessClass dummyInstance ()
    {
        return DUMMY_LevelFactorType;
    }


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





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

        tl_level_typePSet.setAttrib (FIELD_ObjectID, myID);
        tl_level_typePSet.setAttrib (FIELD_TypeFlag, HELPER_TypeFlag.toObject (_TypeFlag)); //
        _Level.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   tl_level_typePSet = allSets.getPersistentSet (objectID, "tl_level_type");

        _TypeFlag = (TypeFlag)(HELPER_TypeFlag.fromObject (_TypeFlag, tl_level_typePSet.getAttrib (FIELD_TypeFlag))); //
        _Level.setFromPersistentSets (objectID, allSets);
        _Factor.setFromPersistentSets (objectID, allSets);
        
    }





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

        if (other instanceof LevelFactorType)
        {
            LevelFactorType otherLevelFactorType = (LevelFactorType)other;
            
            try
            {
                setTypeFlag (otherLevelFactorType.getTypeFlag ());
            }
            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 BaseLevelFactorType)
        {
            BaseLevelFactorType sourceLevelFactorType = (BaseLevelFactorType)(source);

            _TypeFlag = sourceLevelFactorType._TypeFlag;
            
        }
    }


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

            _Level.copyFrom (sourceLevelFactorType._Level, linkToGhosts);
            _Factor.copyFrom (sourceLevelFactorType._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 BaseLevelFactorType)
        {
            BaseLevelFactorType sourceLevelFactorType = (BaseLevelFactorType)(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);

        _TypeFlag = (TypeFlag)(HELPER_TypeFlag.readExternal (_TypeFlag, vals.get(FIELD_TypeFlag))); //
        _Level.readExternalData(vals.get(SINGLEREFERENCE_Level));
        _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_TypeFlag, HELPER_TypeFlag.writeExternal (_TypeFlag));
        vals.put (SINGLEREFERENCE_Level, _Level.writeExternalData());
        vals.put (SINGLEREFERENCE_Factor, _Factor.writeExternalData());
        
    }


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

        if (other instanceof BaseLevelFactorType)
        {
            BaseLevelFactorType otherLevelFactorType = (BaseLevelFactorType)(other);

            
            if (!HELPER_TypeFlag.compare(this._TypeFlag, otherLevelFactorType._TypeFlag))
            {
                listener.notifyFieldChange(this, other, FIELD_TypeFlag, HELPER_TypeFlag.toObject(this._TypeFlag), HELPER_TypeFlag.toObject(otherLevelFactorType._TypeFlag));
            }

            // Compare single assocs
            _Level.compare (otherLevelFactorType._Level, listener);
            _Factor.compare (otherLevelFactorType._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_TypeFlag, HELPER_TypeFlag.toObject(getTypeFlag()));
        visitor.visitAssociation (_Level);
        visitor.visitAssociation (_Factor);
        
    }


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

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


    public static LevelFactorType createLevelFactorType (ObjectTransaction transaction) throws StorageException
    {
        LevelFactorType     result = new LevelFactorType ();

        result.initialiseNewObject (transaction);

        return result;
    }


    public static LevelFactorType getLevelFactorTypeByID (ObjectTransaction transaction, Long objectID) throws StorageException
    {
        return (LevelFactorType)(transaction.getObjectByID (REFERENCE_LevelFactorType, objectID));
    }

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

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

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

            
            public SearchAll andTypeFlag (QueryFilter<TypeFlag> filter)
            {
                filter.addFilter (context, "tl_level_type.type_flag", "TypeFlag");
                return this;
            }
            
            public SearchAll andLevel (QueryFilter<Level> filter)
            {
                filter.addFilter (context, "tl_level_type.level_number", "Level");
                return this;
            }
            
            public SearchAll andFactor (QueryFilter<Factor> filter)
            {
                filter.addFilter (context, "tl_level_type.factor_number", "Factor");
                return this;
            }
            
                public LevelFactorType[]
             search (ObjectTransaction transaction) throws StorageException
        {
            
            
            BaseBusinessClass[]     results = super.search (transaction, REFERENCE_LevelFactorType, SEARCH_All, criteria);
            Set<LevelFactorType>   typedResults = new LinkedHashSet <LevelFactorType> ();
            for (BaseBusinessClass bbcResult : results)
            {
                LevelFactorType aResult = (LevelFactorType)bbcResult;
                
                typedResults.add (aResult);
            }
            
                    return ObjstoreUtils.removeDeleted(transaction, typedResults).toArray (new LevelFactorType[0]);
                            
        }
    }

        
                public static LevelFactorType[]
             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_TypeFlag))
        {
            return HELPER_TypeFlag.toObject (getTypeFlag ());
        }
        else
        {
            return super.getAttribute (attribName);
        }
    }


    public AttributeHelper getAttributeHelper (String attribName)
    {
        if (false)
        {
            throw new RuntimeException ("Game over man!!");
        }
        else if (attribName.equals (FIELD_TypeFlag))
        {
            return HELPER_TypeFlag;
        }
        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_TypeFlag))
        {
            setTypeFlag ((TypeFlag)(HELPER_TypeFlag.fromObject (_TypeFlag, 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_TypeFlag))
        {
            return getWriteability_TypeFlag ();
        }
        else if (fieldName.equals (SINGLEREFERENCE_Level))
        {
            return getWriteability_Level ();
        }
        else if (fieldName.equals (SINGLEREFERENCE_Factor))
        {
            return getWriteability_Factor ();
        }
        else
        {
            return super.getWriteable (fieldName);
        }
    }


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

        super.putUnwriteable (fields);
    }

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

        
        result.add(HELPER_TypeFlag.getAttribObject (getClass (), _TypeFlag, false, FIELD_TypeFlag));

        return result;
    }


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


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

    /**
     * Get the attribute TypeFlag
     */
    public TypeFlag getTypeFlag (LevelFactorType obj, TypeFlag original)
    {
        return original;
    }

    /**
     * Change the value set for attribute TypeFlag.
     * May modify the field beforehand
     * Occurs before validation.
     */
    public TypeFlag setTypeFlag (LevelFactorType obj, TypeFlag newTypeFlag) throws FieldException
    {
        return newTypeFlag;
    }

    }

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

        public LevelFactorTypePipeLineFactory (Collection<From> seed)
        {
            super(seed);
        }
        
        
        public PipeLine<From, ? extends Object> to(String name)
        {
            if (name.equals ("TypeFlag"))
            {
                return toTypeFlag ();
            }                
            if (name.equals ("Level"))
            {
                return toLevel ();
            }                
            if (name.equals ("Factor"))
            {
                return toFactor ();
            }                
            
            
            return super.to(name);
        }
        
        
        public PipeLine<From, TypeFlag> toTypeFlag () { return pipe(new ORMAttributePipe<Me, TypeFlag>(FIELD_TypeFlag));  }
        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 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 DummyLevelFactorType extends LevelFactorType
{
    // Default constructor primarily to support Externalisable
    public DummyLevelFactorType()
    {
        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 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();
    }

}

    
