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

import performa.orm.types.TimeZone;



public abstract class BaseCompany extends BaseBusinessClass
{
    // Reference instance for the object
    public static final Company REFERENCE_Company = new Company ();

    // Reference instance for the object
    public static final Company DUMMY_Company = new DummyCompany ();

    // Static constants corresponding to field names
    
    public static final String FIELD_CompanyName = "CompanyName";
    public static final String FIELD_HiringTeamType = "HiringTeamType";
    public static final String FIELD_Industry = "Industry";
    public static final String FIELD_TimeZone = "TimeZone";
    public static final String SINGLEREFERENCE_AddedByUser = "AddedByUser";
    public static final String MULTIPLEREFERENCE_Users = "Users";
    public static final String BACKREF_Users = "";
    public static final String MULTIPLEREFERENCE_Clients = "Clients";
    public static final String BACKREF_Clients = "";

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

    // Static constants corresponding to attribute helpers
    private static final DefaultAttributeHelper<Company> HELPER_CompanyName = DefaultAttributeHelper.INSTANCE;
    private static final EnumeratedAttributeHelper<Company, HiringTeamType> HELPER_HiringTeamType =  new EnumeratedAttributeHelper<Company, HiringTeamType> (HiringTeamType.FACTORY_HiringTeamType);
    private static final EnumeratedAttributeHelper<Company, Industry> HELPER_Industry =  new EnumeratedAttributeHelper<Company, Industry> (Industry.FACTORY_Industry);
    private static final EnumeratedAttributeHelper<Company, TimeZone> HELPER_TimeZone =  new EnumeratedAttributeHelper<Company, TimeZone> (TimeZone.FACTORY_TimeZone);
    

    // Private attributes corresponding to business object data
    private String _CompanyName;
    private HiringTeamType _HiringTeamType;
    private Industry _Industry;
    private TimeZone _TimeZone;
    

    // Private attributes corresponding to single references
    private SingleAssociation<Company, CompanyUser> _AddedByUser;
    

    // Private attributes corresponding to multiple references
    private MultipleAssociation<Company, CompanyUser> _Users;
    private MultipleAssociation<Company, Client> _Clients;
    

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

    // Arrays of validators for each attribute
    private static final AttributeValidator[] FIELD_CompanyName_Validators;
    private static final AttributeValidator[] FIELD_HiringTeamType_Validators;
    private static final AttributeValidator[] FIELD_Industry_Validators;
    private static final AttributeValidator[] FIELD_TimeZone_Validators;
    

    // Arrays of behaviour decorators
    private static final CompanyBehaviourDecorator[] Company_BehaviourDecorators;
    
    static
    {
        try
        {
            
            String tmp_Users = CompanyUser.BACKREF_Company;
            String tmp_Clients = Client.BACKREF_Company;
            
            Map  validatorMapping = ((Map)ConfigMgr.getConfigObject ("CONFIG.ORMVALIDATOR", "ValidatorMapping"));

            setupAssocMetaData_Users();
            setupAssocMetaData_Clients();
            setupAssocMetaData_AddedByUser();
            FIELD_CompanyName_Validators = (AttributeValidator[])setupAttribMetaData_CompanyName(validatorMapping).toArray (new AttributeValidator[0]);
            FIELD_HiringTeamType_Validators = (AttributeValidator[])setupAttribMetaData_HiringTeamType(validatorMapping).toArray (new AttributeValidator[0]);
            FIELD_Industry_Validators = (AttributeValidator[])setupAttribMetaData_Industry(validatorMapping).toArray (new AttributeValidator[0]);
            FIELD_TimeZone_Validators = (AttributeValidator[])setupAttribMetaData_TimeZone(validatorMapping).toArray (new AttributeValidator[0]);
            

            REFERENCE_Company.initialiseReference ();
            DUMMY_Company.initialiseReference ();
            Company_BehaviourDecorators = BaseBusinessClass.getBBCBehaviours(Company.class).toArray(new CompanyBehaviourDecorator[0]);
        }
        catch (RuntimeException e)
        {
            LogMgr.log (BUSINESS_OBJECTS, LogLevel.SYSTEMERROR1, e, "Error initialising");
            throw e;
        }
    }

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

        metaInfo.put ("backreferenceName", "Company");
        metaInfo.put ("name", "Users");
        metaInfo.put ("type", "CompanyUser");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for Company.Users:", metaInfo);
        ATTRIBUTES_METADATA_Company.put (MULTIPLEREFERENCE_Users, Collections.unmodifiableMap (metaInfo));
    }
    
    
    // Meta Info setup
    private static void setupAssocMetaData_Clients()
    {
        Map metaInfo = new HashMap ();

        metaInfo.put ("backreferenceName", "Company");
        metaInfo.put ("name", "Clients");
        metaInfo.put ("type", "Client");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for Company.Clients:", metaInfo);
        ATTRIBUTES_METADATA_Company.put (MULTIPLEREFERENCE_Clients, Collections.unmodifiableMap (metaInfo));
    }
    
    
    // Meta Info setup
    private static void setupAssocMetaData_AddedByUser()
    {
        Map metaInfo = new HashMap ();

        metaInfo.put ("dbcol", "added_by_user_id");
        metaInfo.put ("mandatory", "true");
        metaInfo.put ("name", "AddedByUser");
        metaInfo.put ("type", "CompanyUser");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for Company.AddedByUser:", metaInfo);
        ATTRIBUTES_METADATA_Company.put (SINGLEREFERENCE_AddedByUser, Collections.unmodifiableMap (metaInfo));
    }
    
    
    // Meta Info setup
    private static List setupAttribMetaData_CompanyName(Map validatorMapping)
    {
        Map  metaInfo   = new HashMap ();

        metaInfo.put ("dbcol", "company_name");
        metaInfo.put ("length", "100");
        metaInfo.put ("mandatory", "true");
        metaInfo.put ("name", "CompanyName");
        metaInfo.put ("type", "String");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for Company.CompanyName:", metaInfo);
        ATTRIBUTES_METADATA_Company.put (FIELD_CompanyName, Collections.unmodifiableMap (metaInfo));

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

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

        metaInfo.put ("attribHelper", "EnumeratedAttributeHelper");
        metaInfo.put ("dbcol", "hiring_team_type");
        metaInfo.put ("mandatory", "false");
        metaInfo.put ("name", "HiringTeamType");
        metaInfo.put ("type", "HiringTeamType");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for Company.HiringTeamType:", metaInfo);
        ATTRIBUTES_METADATA_Company.put (FIELD_HiringTeamType, Collections.unmodifiableMap (metaInfo));

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

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

        metaInfo.put ("attribHelper", "EnumeratedAttributeHelper");
        metaInfo.put ("dbcol", "industry");
        metaInfo.put ("mandatory", "false");
        metaInfo.put ("name", "Industry");
        metaInfo.put ("type", "Industry");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for Company.Industry:", metaInfo);
        ATTRIBUTES_METADATA_Company.put (FIELD_Industry, Collections.unmodifiableMap (metaInfo));

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

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

        metaInfo.put ("attribHelper", "EnumeratedAttributeHelper");
        metaInfo.put ("dbcol", "time_zone");
        metaInfo.put ("mandatory", "false");
        metaInfo.put ("name", "TimeZone");
        metaInfo.put ("type", "TimeZone");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for Company.TimeZone:", metaInfo);
        ATTRIBUTES_METADATA_Company.put (FIELD_TimeZone, Collections.unmodifiableMap (metaInfo));

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

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


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


    


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

        
        _CompanyName = (String)(HELPER_CompanyName.initialise (_CompanyName));
        _HiringTeamType = (HiringTeamType)(HELPER_HiringTeamType.initialise (_HiringTeamType));
        _Industry = (Industry)(HELPER_Industry.initialise (_Industry));
        _TimeZone = (TimeZone)(HELPER_TimeZone.initialise (_TimeZone));
    }


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

        _AddedByUser = new SingleAssociation<Company, CompanyUser> (this, SINGLEREFERENCE_AddedByUser, null, CompanyUser.REFERENCE_CompanyUser, "tl_company");
        _Users = new MultipleAssociation<Company, CompanyUser> (this, MULTIPLEREFERENCE_Users, CompanyUser.SINGLEREFERENCE_Company, CompanyUser.REFERENCE_CompanyUser);
        _Clients = new MultipleAssociation<Company, Client> (this, MULTIPLEREFERENCE_Clients, Client.SINGLEREFERENCE_Company, Client.REFERENCE_Client);
        
    }


    // Initialise the associations
    protected BaseBusinessClass initialiseReference ()
    {
        super.initialiseReference ();
        
        _AddedByUser = new SingleAssociation<Company, CompanyUser> (this, SINGLEREFERENCE_AddedByUser, null, CompanyUser.REFERENCE_CompanyUser, "tl_company");
        _Users = new MultipleAssociation<Company, CompanyUser> (this, MULTIPLEREFERENCE_Users, CompanyUser.SINGLEREFERENCE_Company, CompanyUser.REFERENCE_CompanyUser);
        _Clients = new MultipleAssociation<Company, Client> (this, MULTIPLEREFERENCE_Clients, Client.SINGLEREFERENCE_Company, Client.REFERENCE_Client);
        
        
        return this;
    }

    

    /**
     * Get the attribute CompanyName
     */
    public String getCompanyName ()
    {
        assertValid();
        String valToReturn = _CompanyName;

            for (CompanyBehaviourDecorator bhd : Company_BehaviourDecorators)
            {
                valToReturn = bhd.getCompanyName ((Company)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 preCompanyNameChange (String newCompanyName) 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 postCompanyNameChange () throws FieldException
    {
    }

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

    /**
     * Set the attribute CompanyName.  Checks to ensure a new value
     * has been supplied.  If so, marks the field as altered and sets the attribute.
     */
    public void setCompanyName (String newCompanyName) throws FieldException
    {
        boolean oldAndNewIdentical = HELPER_CompanyName.compare (_CompanyName, newCompanyName);
        
        try
        {
            for (CompanyBehaviourDecorator bhd : Company_BehaviourDecorators)
            {
                newCompanyName = bhd.setCompanyName ((Company)this, newCompanyName);
                oldAndNewIdentical = HELPER_CompanyName.compare (_CompanyName, newCompanyName);
            }

            BusinessObjectParser.assertFieldCondition (newCompanyName != null, this, FIELD_CompanyName, "mandatory");
            

            if (FIELD_CompanyName_Validators.length > 0)
            {
                Object newCompanyNameObj = HELPER_CompanyName.toObject (newCompanyName);

                if (newCompanyNameObj != null)
                {
                    int     loopMax = FIELD_CompanyName_Validators.length;
                    Map     metadata = (Map)ATTRIBUTES_METADATA_Company.get (FIELD_CompanyName);

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

        if (!oldAndNewIdentical)
        {
            assertValid();
            Debug.assertion (getWriteability_CompanyName () != FieldWriteability.FALSE, "Field  CompanyName is not writeable");
            preCompanyNameChange (newCompanyName);
            markFieldChange (FIELD_CompanyName);
            _CompanyName = newCompanyName;            
            postFieldChange (FIELD_CompanyName);
            postCompanyNameChange ();
        }
    }

    /**
     * Get the attribute HiringTeamType
     */
    public HiringTeamType getHiringTeamType ()
    {
        assertValid();
        HiringTeamType valToReturn = _HiringTeamType;

            for (CompanyBehaviourDecorator bhd : Company_BehaviourDecorators)
            {
                valToReturn = bhd.getHiringTeamType ((Company)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 preHiringTeamTypeChange (HiringTeamType newHiringTeamType) 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 postHiringTeamTypeChange () throws FieldException
    {
    }

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

    /**
     * Set the attribute HiringTeamType.  Checks to ensure a new value
     * has been supplied.  If so, marks the field as altered and sets the attribute.
     */
    public void setHiringTeamType (HiringTeamType newHiringTeamType) throws FieldException
    {
        boolean oldAndNewIdentical = HELPER_HiringTeamType.compare (_HiringTeamType, newHiringTeamType);
        
        try
        {
            for (CompanyBehaviourDecorator bhd : Company_BehaviourDecorators)
            {
                newHiringTeamType = bhd.setHiringTeamType ((Company)this, newHiringTeamType);
                oldAndNewIdentical = HELPER_HiringTeamType.compare (_HiringTeamType, newHiringTeamType);
            }

            

            if (FIELD_HiringTeamType_Validators.length > 0)
            {
                Object newHiringTeamTypeObj = HELPER_HiringTeamType.toObject (newHiringTeamType);

                if (newHiringTeamTypeObj != null)
                {
                    int     loopMax = FIELD_HiringTeamType_Validators.length;
                    Map     metadata = (Map)ATTRIBUTES_METADATA_Company.get (FIELD_HiringTeamType);

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

        if (!oldAndNewIdentical)
        {
            assertValid();
            Debug.assertion (getWriteability_HiringTeamType () != FieldWriteability.FALSE, "Field  HiringTeamType is not writeable");
            preHiringTeamTypeChange (newHiringTeamType);
            markFieldChange (FIELD_HiringTeamType);
            _HiringTeamType = newHiringTeamType;            
            postFieldChange (FIELD_HiringTeamType);
            postHiringTeamTypeChange ();
        }
    }

    /**
     * Get the attribute Industry
     */
    public Industry getIndustry ()
    {
        assertValid();
        Industry valToReturn = _Industry;

            for (CompanyBehaviourDecorator bhd : Company_BehaviourDecorators)
            {
                valToReturn = bhd.getIndustry ((Company)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 preIndustryChange (Industry newIndustry) 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 postIndustryChange () throws FieldException
    {
    }

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

    /**
     * Set the attribute Industry.  Checks to ensure a new value
     * has been supplied.  If so, marks the field as altered and sets the attribute.
     */
    public void setIndustry (Industry newIndustry) throws FieldException
    {
        boolean oldAndNewIdentical = HELPER_Industry.compare (_Industry, newIndustry);
        
        try
        {
            for (CompanyBehaviourDecorator bhd : Company_BehaviourDecorators)
            {
                newIndustry = bhd.setIndustry ((Company)this, newIndustry);
                oldAndNewIdentical = HELPER_Industry.compare (_Industry, newIndustry);
            }

            

            if (FIELD_Industry_Validators.length > 0)
            {
                Object newIndustryObj = HELPER_Industry.toObject (newIndustry);

                if (newIndustryObj != null)
                {
                    int     loopMax = FIELD_Industry_Validators.length;
                    Map     metadata = (Map)ATTRIBUTES_METADATA_Company.get (FIELD_Industry);

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

        if (!oldAndNewIdentical)
        {
            assertValid();
            Debug.assertion (getWriteability_Industry () != FieldWriteability.FALSE, "Field  Industry is not writeable");
            preIndustryChange (newIndustry);
            markFieldChange (FIELD_Industry);
            _Industry = newIndustry;            
            postFieldChange (FIELD_Industry);
            postIndustryChange ();
        }
    }

    /**
     * Get the attribute TimeZone
     */
    public TimeZone getTimeZone ()
    {
        assertValid();
        TimeZone valToReturn = _TimeZone;

            for (CompanyBehaviourDecorator bhd : Company_BehaviourDecorators)
            {
                valToReturn = bhd.getTimeZone ((Company)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 preTimeZoneChange (TimeZone newTimeZone) 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 postTimeZoneChange () throws FieldException
    {
    }

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

    /**
     * Set the attribute TimeZone.  Checks to ensure a new value
     * has been supplied.  If so, marks the field as altered and sets the attribute.
     */
    public void setTimeZone (TimeZone newTimeZone) throws FieldException
    {
        boolean oldAndNewIdentical = HELPER_TimeZone.compare (_TimeZone, newTimeZone);
        
        try
        {
            for (CompanyBehaviourDecorator bhd : Company_BehaviourDecorators)
            {
                newTimeZone = bhd.setTimeZone ((Company)this, newTimeZone);
                oldAndNewIdentical = HELPER_TimeZone.compare (_TimeZone, newTimeZone);
            }

            

            if (FIELD_TimeZone_Validators.length > 0)
            {
                Object newTimeZoneObj = HELPER_TimeZone.toObject (newTimeZone);

                if (newTimeZoneObj != null)
                {
                    int     loopMax = FIELD_TimeZone_Validators.length;
                    Map     metadata = (Map)ATTRIBUTES_METADATA_Company.get (FIELD_TimeZone);

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

        if (!oldAndNewIdentical)
        {
            assertValid();
            Debug.assertion (getWriteability_TimeZone () != FieldWriteability.FALSE, "Field  TimeZone is not writeable");
            preTimeZoneChange (newTimeZone);
            markFieldChange (FIELD_TimeZone);
            _TimeZone = newTimeZone;            
            postFieldChange (FIELD_TimeZone);
            postTimeZoneChange ();
        }
    }



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

        
        result.add("AddedByUser");
        

        return result;
    }
    
    
    public BaseBusinessClass getSingleAssocReferenceInstance (String assocName)
    {
        if (assocName == null)
        {
            throw new RuntimeException ("Game over == null!");
        }
        else if (assocName.equals (SINGLEREFERENCE_AddedByUser))
        {
            return _AddedByUser.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_AddedByUser))
        {
            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_AddedByUser))
        {
            return getAddedByUser ();
        }
        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_AddedByUser))
        {
            return getAddedByUser (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_AddedByUser))
        {
            return getAddedByUserID ();
        }
        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_AddedByUser))
        {
            setAddedByUser ((CompanyUser)(newValue));
        }
        else
        {
            super.setSingleAssoc (assocName, newValue);
        }
    }



    /**
     * Get the reference AddedByUser
     */
    public CompanyUser getAddedByUser () throws StorageException
    {
        assertValid();
        
        try
        {
            return (CompanyUser)(_AddedByUser.get ());
        }
        catch (ClassCastException e)
        {
            LogMgr.log (BUSINESS_OBJECTS, LogLevel.SYSTEMERROR2, "Cache collision in Company:", this.getObjectID (), ", was trying to get CompanyUser:",  getAddedByUserID ());
            LogMgr.log (BUSINESS_OBJECTS, LogLevel.SYSTEMERROR2, "Instead I got:", _AddedByUser.get ().getClass ());
            throw e;
        }
    }


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


    /**
     * Get the object id for the referenced object.  Does not force a DB access.
     */
    public Long getAddedByUserID ()
    {
        assertValid();
        
        if (_AddedByUser == null)
        {
            return null;
        }
        else
        {
            return _AddedByUser.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 preAddedByUserChange (CompanyUser newAddedByUser) 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 postAddedByUserChange () throws FieldException
    {
    }



    
    public FieldWriteability getWriteability_AddedByUser ()
    {
        return getFieldWritabilityUtil (FieldWriteability.TRUE);
    }
    
    
    /**
     * Set the reference AddedByUser.  Checks to ensure a new value
     * has been supplied.  If so, marks the reference as altered and sets it.
     */
    public void setAddedByUser (CompanyUser newAddedByUser) throws StorageException, FieldException
    {
        BusinessObjectParser.assertFieldCondition (newAddedByUser != null, this, SINGLEREFERENCE_AddedByUser, "mandatory");
        

        if (_AddedByUser.wouldReferencedChange (newAddedByUser))
        {
            assertValid();
            Debug.assertion (getWriteability_AddedByUser () != FieldWriteability.FALSE, "Assoc AddedByUser is not writeable");
            preAddedByUserChange (newAddedByUser);
            
                    _AddedByUser.set (newAddedByUser);
                
            postAddedByUserChange ();
        }
    }

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

        
        result.add("Users");
        
        result.add("Clients");
        

        return result;
    }


    /**
     * Get the reference instance for the multi assoc name.
     */
    public BaseBusinessClass getMultiAssocReferenceInstance(String attribName)
    {
        
        if (MULTIPLEREFERENCE_Users.equals(attribName))
        {
            return CompanyUser.REFERENCE_CompanyUser ;
        }
        
        if (MULTIPLEREFERENCE_Clients.equals(attribName))
        {
            return Client.REFERENCE_Client ;
        }
        

        return super.getMultiAssocReferenceInstance(attribName);
    }


    public String getMultiAssocBackReference(String attribName)
    {
        
        if (MULTIPLEREFERENCE_Users.equals(attribName))
        {
            return CompanyUser.SINGLEREFERENCE_Company ;
        }
        
        if (MULTIPLEREFERENCE_Clients.equals(attribName))
        {
            return Client.SINGLEREFERENCE_Company ;
        }
        

        return super.getMultiAssocBackReference(attribName);
    }


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

        return super.getMultiAssocCount(attribName);
    }


    /**
     * Get the assoc at a particular index
     */
    public BaseBusinessClass getMultiAssocAt(String attribName, int index) throws StorageException
    {
        
        if (MULTIPLEREFERENCE_Users.equals(attribName))
        {
            return this.getUsersAt(index);
        }
        
        if (MULTIPLEREFERENCE_Clients.equals(attribName))
        {
            return this.getClientsAt(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_Users.equals(attribName))
        {
            addToUsers((CompanyUser)newElement);

            return;
        }
        
        if (MULTIPLEREFERENCE_Clients.equals(attribName))
        {
            addToClients((Client)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_Users.equals(attribName))
        {
            removeFromUsers((CompanyUser)oldElement);

            return;
        }
        
        if (MULTIPLEREFERENCE_Clients.equals(attribName))
        {
            removeFromClients((Client)oldElement);

            return;
        }
        

        super.removeFromMultiAssoc(attribName, oldElement);
    }


    protected void __loadMultiAssoc (String attribName, BaseBusinessClass[] elements)
    {
        
        if (MULTIPLEREFERENCE_Users.equals(attribName))
        {
            _Users.__loadAssociation (elements);
            return;
        }
        
        if (MULTIPLEREFERENCE_Clients.equals(attribName))
        {
            _Clients.__loadAssociation (elements);
            return;
        }
        

        super.__loadMultiAssoc(attribName, elements);
    }


    protected boolean __isMultiAssocLoaded (String attribName)
    {
        
        if (MULTIPLEREFERENCE_Users.equals(attribName))
        {
            return _Users.isLoaded ();
        }
        
        if (MULTIPLEREFERENCE_Clients.equals(attribName))
        {
            return _Clients.isLoaded ();
        }
        

        return super.__isMultiAssocLoaded(attribName);
    }

    

    public FieldWriteability getWriteability_Users ()
    {
        return getFieldWritabilityUtil (FieldWriteability.TRUE);
    }
    
    
    public int getUsersCount () throws StorageException
    {
        assertValid();
        return _Users.getReferencedObjectsCount ();
    }


    public void addToUsers (CompanyUser newElement) throws StorageException
    {
        if (_Users.wouldAddChange (newElement))
        {
            assertValid();
            Debug.assertion (getWriteability_Users () != FieldWriteability.FALSE, "MultiAssoc Users is not writeable (add)");
            _Users.appendElement (newElement);

            try
            {
                if (newElement.getCompany () != this)
                {
                    newElement.setCompany ((Company)(this));
                }
            }
            catch (Exception e)
            {
                throw NestedException.wrap(e);
            }
        }
    }


    public void removeFromUsers (CompanyUser elementToRemove) throws StorageException
    {
        if (_Users.wouldRemoveChange (elementToRemove))
        {
            assertValid();
            Debug.assertion (getWriteability_Users () != FieldWriteability.FALSE, "MultiAssoc Users is not writeable (remove)");
            _Users.removeElement (elementToRemove);
            try
            {
                if (elementToRemove.getCompany () != null)
                {
                    elementToRemove.setCompany (null);
                }
            }
            catch (Exception e)
            {
                throw NestedException.wrap(e);
            }
        }
    }


    public CompanyUser getUsersAt (int index) throws StorageException
    {
        return (CompanyUser)(_Users.getElementAt (index));
    }


    public SortedSet<CompanyUser> getUsersSet () throws StorageException
    {
        return _Users.getSet ();
    }

    public FieldWriteability getWriteability_Clients ()
    {
        return getFieldWritabilityUtil (FieldWriteability.TRUE);
    }
    
    
    public int getClientsCount () throws StorageException
    {
        assertValid();
        return _Clients.getReferencedObjectsCount ();
    }


    public void addToClients (Client newElement) throws StorageException
    {
        if (_Clients.wouldAddChange (newElement))
        {
            assertValid();
            Debug.assertion (getWriteability_Clients () != FieldWriteability.FALSE, "MultiAssoc Clients is not writeable (add)");
            _Clients.appendElement (newElement);

            try
            {
                if (newElement.getCompany () != this)
                {
                    newElement.setCompany ((Company)(this));
                }
            }
            catch (Exception e)
            {
                throw NestedException.wrap(e);
            }
        }
    }


    public void removeFromClients (Client elementToRemove) throws StorageException
    {
        if (_Clients.wouldRemoveChange (elementToRemove))
        {
            assertValid();
            Debug.assertion (getWriteability_Clients () != FieldWriteability.FALSE, "MultiAssoc Clients is not writeable (remove)");
            _Clients.removeElement (elementToRemove);
            try
            {
                if (elementToRemove.getCompany () != null)
                {
                    elementToRemove.setCompany (null);
                }
            }
            catch (Exception e)
            {
                throw NestedException.wrap(e);
            }
        }
    }


    public Client getClientsAt (int index) throws StorageException
    {
        return (Client)(_Clients.getElementAt (index));
    }


    public SortedSet<Client> getClientsSet () throws StorageException
    {
        return _Clients.getSet ();
    }



    public void onDelete ()
    {
        try 
        {
            for(CompanyUser referenced : CollectionUtils.reverse(getUsersSet()))
            { 
                LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG1, "Setting backreference to null Company from ", getObjectID (), " to ", referenced.getObjectID ());
                referenced.setCompany(null);
            }

            for(Client referenced : CollectionUtils.reverse(getClientsSet()))
            { 
                LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG1, "Setting backreference to null Company from ", getObjectID (), " to ", referenced.getObjectID ());
                referenced.setCompany(null);
            }

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

        super.onDelete ();
    }


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


    public Company referenceInstance ()
    {
        return REFERENCE_Company;
    }


    public Company getInTransaction (ObjectTransaction t) throws StorageException
    {
        return getCompanyByID (t, getObjectID());
    }
    
    
    public BaseBusinessClass dummyInstance ()
    {
        return DUMMY_Company;
    }


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





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

        tl_companyPSet.setAttrib (FIELD_ObjectID, myID);
        tl_companyPSet.setAttrib (FIELD_CompanyName, HELPER_CompanyName.toObject (_CompanyName)); //
        tl_companyPSet.setAttrib (FIELD_HiringTeamType, HELPER_HiringTeamType.toObject (_HiringTeamType)); //
        tl_companyPSet.setAttrib (FIELD_Industry, HELPER_Industry.toObject (_Industry)); //
        tl_companyPSet.setAttrib (FIELD_TimeZone, HELPER_TimeZone.toObject (_TimeZone)); //
        _AddedByUser.getPersistentSets (allSets);
        
    }


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

        
        PersistentSet   tl_companyPSet = allSets.getPersistentSet (objectID, "tl_company");

        _CompanyName = (String)(HELPER_CompanyName.fromObject (_CompanyName, tl_companyPSet.getAttrib (FIELD_CompanyName))); //
        _HiringTeamType = (HiringTeamType)(HELPER_HiringTeamType.fromObject (_HiringTeamType, tl_companyPSet.getAttrib (FIELD_HiringTeamType))); //
        _Industry = (Industry)(HELPER_Industry.fromObject (_Industry, tl_companyPSet.getAttrib (FIELD_Industry))); //
        _TimeZone = (TimeZone)(HELPER_TimeZone.fromObject (_TimeZone, tl_companyPSet.getAttrib (FIELD_TimeZone))); //
        _AddedByUser.setFromPersistentSets (objectID, allSets);
        
    }





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

        if (other instanceof Company)
        {
            Company otherCompany = (Company)other;
            
            try
            {
                setCompanyName (otherCompany.getCompanyName ());
            }
            catch (FieldException ex)
            {
                e.addException (ex);
            }
            
            try
            {
                setHiringTeamType (otherCompany.getHiringTeamType ());
            }
            catch (FieldException ex)
            {
                e.addException (ex);
            }
            
            try
            {
                setIndustry (otherCompany.getIndustry ());
            }
            catch (FieldException ex)
            {
                e.addException (ex);
            }
            
            try
            {
                setTimeZone (otherCompany.getTimeZone ());
            }
            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 BaseCompany)
        {
            BaseCompany sourceCompany = (BaseCompany)(source);

            _CompanyName = sourceCompany._CompanyName;
            _HiringTeamType = sourceCompany._HiringTeamType;
            _Industry = sourceCompany._Industry;
            _TimeZone = sourceCompany._TimeZone;
            
        }
    }


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

            _AddedByUser.copyFrom (sourceCompany._AddedByUser, 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 BaseCompany)
        {
            BaseCompany sourceCompany = (BaseCompany)(source);

            _Users.copyFrom (sourceCompany._Users, linkToGhosts);
            _Clients.copyFrom (sourceCompany._Clients, linkToGhosts);
            
        }
    }


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

        
        context.check (getAddedByUserID() != null, this, SINGLEREFERENCE_AddedByUser, "mandatory");
        
    }


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

        _CompanyName = (String)(HELPER_CompanyName.readExternal (_CompanyName, vals.get(FIELD_CompanyName))); //
        _HiringTeamType = (HiringTeamType)(HELPER_HiringTeamType.readExternal (_HiringTeamType, vals.get(FIELD_HiringTeamType))); //
        _Industry = (Industry)(HELPER_Industry.readExternal (_Industry, vals.get(FIELD_Industry))); //
        _TimeZone = (TimeZone)(HELPER_TimeZone.readExternal (_TimeZone, vals.get(FIELD_TimeZone))); //
        _AddedByUser.readExternalData(vals.get(SINGLEREFERENCE_AddedByUser));
        _Users.readExternalData(vals.get(MULTIPLEREFERENCE_Users));
        _Clients.readExternalData(vals.get(MULTIPLEREFERENCE_Clients));
        
    }


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

        vals.put (FIELD_CompanyName, HELPER_CompanyName.writeExternal (_CompanyName));
        vals.put (FIELD_HiringTeamType, HELPER_HiringTeamType.writeExternal (_HiringTeamType));
        vals.put (FIELD_Industry, HELPER_Industry.writeExternal (_Industry));
        vals.put (FIELD_TimeZone, HELPER_TimeZone.writeExternal (_TimeZone));
        vals.put (SINGLEREFERENCE_AddedByUser, _AddedByUser.writeExternalData());
        vals.put (MULTIPLEREFERENCE_Users, _Users.writeExternalData());
        vals.put (MULTIPLEREFERENCE_Clients, _Clients.writeExternalData());
        
    }


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

        if (other instanceof BaseCompany)
        {
            BaseCompany otherCompany = (BaseCompany)(other);

            
            if (!HELPER_CompanyName.compare(this._CompanyName, otherCompany._CompanyName))
            {
                listener.notifyFieldChange(this, other, FIELD_CompanyName, HELPER_CompanyName.toObject(this._CompanyName), HELPER_CompanyName.toObject(otherCompany._CompanyName));
            }
            if (!HELPER_HiringTeamType.compare(this._HiringTeamType, otherCompany._HiringTeamType))
            {
                listener.notifyFieldChange(this, other, FIELD_HiringTeamType, HELPER_HiringTeamType.toObject(this._HiringTeamType), HELPER_HiringTeamType.toObject(otherCompany._HiringTeamType));
            }
            if (!HELPER_Industry.compare(this._Industry, otherCompany._Industry))
            {
                listener.notifyFieldChange(this, other, FIELD_Industry, HELPER_Industry.toObject(this._Industry), HELPER_Industry.toObject(otherCompany._Industry));
            }
            if (!HELPER_TimeZone.compare(this._TimeZone, otherCompany._TimeZone))
            {
                listener.notifyFieldChange(this, other, FIELD_TimeZone, HELPER_TimeZone.toObject(this._TimeZone), HELPER_TimeZone.toObject(otherCompany._TimeZone));
            }

            // Compare single assocs
            _AddedByUser.compare (otherCompany._AddedByUser, listener);
            

            // Compare multiple assocs
            _Users.compare (otherCompany._Users, listener);
            _Clients.compare (otherCompany._Clients, listener);
            
        }
    }


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

        
    }


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

        visitor.visitField(this, FIELD_CompanyName, HELPER_CompanyName.toObject(getCompanyName()));
        visitor.visitField(this, FIELD_HiringTeamType, HELPER_HiringTeamType.toObject(getHiringTeamType()));
        visitor.visitField(this, FIELD_Industry, HELPER_Industry.toObject(getIndustry()));
        visitor.visitField(this, FIELD_TimeZone, HELPER_TimeZone.toObject(getTimeZone()));
        visitor.visitAssociation (_AddedByUser);
        visitor.visitAssociation (_Users);
        visitor.visitAssociation (_Clients);
        
    }


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

        if (scope.includes (_AddedByUser))
        {
            visitor.visit (_AddedByUser);
        }
        if (scope.includes (_Users))
        {
            visitor.visit (_Users);
        }
        if (scope.includes (_Clients))
        {
            visitor.visit (_Clients);
        }
        
    }


    public static Company createCompany (ObjectTransaction transaction) throws StorageException
    {
        Company     result = new Company ();

        result.initialiseNewObject (transaction);

        return result;
    }


    public static Company getCompanyByID (ObjectTransaction transaction, Long objectID) throws StorageException
    {
        return (Company)(transaction.getObjectByID (REFERENCE_Company, objectID));
    }

    public boolean testFilter (String attribName, QueryFilter filter) throws StorageException
    {
        if (false)
        {
            throw new RuntimeException ("Game over man!!");
        }
        else if (attribName.equals (FIELD_CompanyName))
        {
            return filter.matches (getCompanyName ());
        }
        else if (attribName.equals (FIELD_HiringTeamType))
        {
            return filter.matches (getHiringTeamType ());
        }
        else if (attribName.equals (FIELD_Industry))
        {
            return filter.matches (getIndustry ());
        }
        else if (attribName.equals (FIELD_TimeZone))
        {
            return filter.matches (getTimeZone ());
        }
        else if (attribName.equals (SINGLEREFERENCE_AddedByUser))
        {
            return filter.matches (getAddedByUser ());
        }
        else
        {
            return super.testFilter (attribName, filter);
        }
    }


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

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

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

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

            
            public SearchAll andCompanyName (QueryFilter<String> filter)
            {
                filter.addFilter (context, "tl_company.company_name", "CompanyName");
                return this;
            }
            
            public SearchAll andHiringTeamType (QueryFilter<HiringTeamType> filter)
            {
                filter.addFilter (context, "tl_company.hiring_team_type", "HiringTeamType");
                return this;
            }
            
            public SearchAll andIndustry (QueryFilter<Industry> filter)
            {
                filter.addFilter (context, "tl_company.industry", "Industry");
                return this;
            }
            
            public SearchAll andTimeZone (QueryFilter<TimeZone> filter)
            {
                filter.addFilter (context, "tl_company.time_zone", "TimeZone");
                return this;
            }
            
            public SearchAll andAddedByUser (QueryFilter<CompanyUser> filter)
            {
                filter.addFilter (context, "tl_company.added_by_user_id", "AddedByUser");
                return this;
            }
            
                public Company[]
             search (ObjectTransaction transaction) throws StorageException
        {
            
            
            BaseBusinessClass[]     results = super.search (transaction, REFERENCE_Company, SEARCH_All, criteria);
            Set<Company>   typedResults = new LinkedHashSet <Company> ();
            for (BaseBusinessClass bbcResult : results)
            {
                Company aResult = (Company)bbcResult;
                
                typedResults.add (aResult);
            }
            
                    return ObjstoreUtils.removeDeleted(transaction, typedResults).toArray (new Company[0]);
                            
        }
    }

        
                public static Company[]
             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_CompanyName))
        {
            return HELPER_CompanyName.toObject (getCompanyName ());
        }
        else if (attribName.equals (FIELD_HiringTeamType))
        {
            return HELPER_HiringTeamType.toObject (getHiringTeamType ());
        }
        else if (attribName.equals (FIELD_Industry))
        {
            return HELPER_Industry.toObject (getIndustry ());
        }
        else if (attribName.equals (FIELD_TimeZone))
        {
            return HELPER_TimeZone.toObject (getTimeZone ());
        }
        else
        {
            return super.getAttribute (attribName);
        }
    }


    public AttributeHelper getAttributeHelper (String attribName)
    {
        if (false)
        {
            throw new RuntimeException ("Game over man!!");
        }
        else if (attribName.equals (FIELD_CompanyName))
        {
            return HELPER_CompanyName;
        }
        else if (attribName.equals (FIELD_HiringTeamType))
        {
            return HELPER_HiringTeamType;
        }
        else if (attribName.equals (FIELD_Industry))
        {
            return HELPER_Industry;
        }
        else if (attribName.equals (FIELD_TimeZone))
        {
            return HELPER_TimeZone;
        }
        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_CompanyName))
        {
            setCompanyName ((String)(HELPER_CompanyName.fromObject (_CompanyName, attribValue)));            
        }
        else if (attribName.equals (FIELD_HiringTeamType))
        {
            setHiringTeamType ((HiringTeamType)(HELPER_HiringTeamType.fromObject (_HiringTeamType, attribValue)));            
        }
        else if (attribName.equals (FIELD_Industry))
        {
            setIndustry ((Industry)(HELPER_Industry.fromObject (_Industry, attribValue)));            
        }
        else if (attribName.equals (FIELD_TimeZone))
        {
            setTimeZone ((TimeZone)(HELPER_TimeZone.fromObject (_TimeZone, 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_CompanyName))
        {
            return getWriteability_CompanyName ();
        }
        else if (fieldName.equals (FIELD_HiringTeamType))
        {
            return getWriteability_HiringTeamType ();
        }
        else if (fieldName.equals (FIELD_Industry))
        {
            return getWriteability_Industry ();
        }
        else if (fieldName.equals (FIELD_TimeZone))
        {
            return getWriteability_TimeZone ();
        }
        else if (fieldName.equals (MULTIPLEREFERENCE_Users))
        {
            return getWriteability_Users ();
        }
        else if (fieldName.equals (MULTIPLEREFERENCE_Clients))
        {
            return getWriteability_Clients ();
        }
        else if (fieldName.equals (SINGLEREFERENCE_AddedByUser))
        {
            return getWriteability_AddedByUser ();
        }
        else
        {
            return super.getWriteable (fieldName);
        }
    }


    public void putUnwriteable (Set<String> fields)
    {
        
            if (getWriteability_CompanyName () != FieldWriteability.TRUE)
            {
                fields.add (FIELD_CompanyName);
            }
        
            if (getWriteability_HiringTeamType () != FieldWriteability.TRUE)
            {
                fields.add (FIELD_HiringTeamType);
            }
        
            if (getWriteability_Industry () != FieldWriteability.TRUE)
            {
                fields.add (FIELD_Industry);
            }
        
            if (getWriteability_TimeZone () != FieldWriteability.TRUE)
            {
                fields.add (FIELD_TimeZone);
            }
        

        super.putUnwriteable (fields);
    }

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

        
        result.add(HELPER_CompanyName.getAttribObject (getClass (), _CompanyName, true, FIELD_CompanyName));
        result.add(HELPER_HiringTeamType.getAttribObject (getClass (), _HiringTeamType, false, FIELD_HiringTeamType));
        result.add(HELPER_Industry.getAttribObject (getClass (), _Industry, false, FIELD_Industry));
        result.add(HELPER_TimeZone.getAttribObject (getClass (), _TimeZone, false, FIELD_TimeZone));

        return result;
    }


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


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

    /**
     * Get the attribute CompanyName
     */
    public String getCompanyName (Company obj, String original)
    {
        return original;
    }

    /**
     * Change the value set for attribute CompanyName.
     * May modify the field beforehand
     * Occurs before validation.
     */
    public String setCompanyName (Company obj, String newCompanyName) throws FieldException
    {
        return newCompanyName;
    }

    /**
     * Get the attribute HiringTeamType
     */
    public HiringTeamType getHiringTeamType (Company obj, HiringTeamType original)
    {
        return original;
    }

    /**
     * Change the value set for attribute HiringTeamType.
     * May modify the field beforehand
     * Occurs before validation.
     */
    public HiringTeamType setHiringTeamType (Company obj, HiringTeamType newHiringTeamType) throws FieldException
    {
        return newHiringTeamType;
    }

    /**
     * Get the attribute Industry
     */
    public Industry getIndustry (Company obj, Industry original)
    {
        return original;
    }

    /**
     * Change the value set for attribute Industry.
     * May modify the field beforehand
     * Occurs before validation.
     */
    public Industry setIndustry (Company obj, Industry newIndustry) throws FieldException
    {
        return newIndustry;
    }

    /**
     * Get the attribute TimeZone
     */
    public TimeZone getTimeZone (Company obj, TimeZone original)
    {
        return original;
    }

    /**
     * Change the value set for attribute TimeZone.
     * May modify the field beforehand
     * Occurs before validation.
     */
    public TimeZone setTimeZone (Company obj, TimeZone newTimeZone) throws FieldException
    {
        return newTimeZone;
    }

    }

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

        public CompanyPipeLineFactory (Collection<From> seed)
        {
            super(seed);
        }
        
        
        public PipeLine<From, ? extends Object> to(String name)
        {
            if (name.equals ("Users"))
            {
                return toUsers ();
            }                
            if (name.equals ("Clients"))
            {
                return toClients ();
            }                
            if (name.equals ("CompanyName"))
            {
                return toCompanyName ();
            }                
            if (name.equals ("HiringTeamType"))
            {
                return toHiringTeamType ();
            }                
            if (name.equals ("Industry"))
            {
                return toIndustry ();
            }                
            if (name.equals ("TimeZone"))
            {
                return toTimeZone ();
            }                
            if (name.equals ("AddedByUser"))
            {
                return toAddedByUser ();
            }                
            
            
            return super.to(name);
        }
        
        
        public PipeLine<From, String> toCompanyName () { return pipe(new ORMAttributePipe<Me, String>(FIELD_CompanyName));  }
        
        public PipeLine<From, HiringTeamType> toHiringTeamType () { return pipe(new ORMAttributePipe<Me, HiringTeamType>(FIELD_HiringTeamType));  }
        
        public PipeLine<From, Industry> toIndustry () { return pipe(new ORMAttributePipe<Me, Industry>(FIELD_Industry));  }
        
        public PipeLine<From, TimeZone> toTimeZone () { return pipe(new ORMAttributePipe<Me, TimeZone>(FIELD_TimeZone));  }
        public CompanyUser.CompanyUserPipeLineFactory<From, CompanyUser> toAddedByUser () { return toAddedByUser (Filter.ALL); }

        public CompanyUser.CompanyUserPipeLineFactory<From, CompanyUser> toAddedByUser (Filter<CompanyUser> filter) 
        { 
            return CompanyUser.REFERENCE_CompanyUser.new CompanyUserPipeLineFactory<From, CompanyUser> (this, new ORMSingleAssocPipe<Me, CompanyUser>(SINGLEREFERENCE_AddedByUser, filter)); 
        }
        public CompanyUser.CompanyUserPipeLineFactory<From, CompanyUser> toUsers () { return toUsers(Filter.ALL); }        

        public CompanyUser.CompanyUserPipeLineFactory<From, CompanyUser> toUsers (Filter<CompanyUser> filter)
        {
            return CompanyUser.REFERENCE_CompanyUser.new CompanyUserPipeLineFactory<From, CompanyUser> (this, new ORMMultiAssocPipe<Me, CompanyUser>(MULTIPLEREFERENCE_Users, filter)); 
        }
        public Client.ClientPipeLineFactory<From, Client> toClients () { return toClients(Filter.ALL); }        

        public Client.ClientPipeLineFactory<From, Client> toClients (Filter<Client> filter)
        {
            return Client.REFERENCE_Client.new ClientPipeLineFactory<From, Client> (this, new ORMMultiAssocPipe<Me, Client>(MULTIPLEREFERENCE_Clients, filter)); 
        }
        
    }
    
    public boolean isTransientAttrib(String attribName)
    {
        

        return super.isTransientAttrib(attribName);
    }

    public boolean isTransientSingleReference(String assocName)
    {
        

        return super.isTransientSingleReference(assocName);
    }
}

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

    public void assertValid ()
    {
    }


    public CompanyUser getAddedByUser () throws StorageException
    {
        return (CompanyUser)(CompanyUser.DUMMY_CompanyUser);
    }


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

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


    public CompanyUser getUsersAt (int index) throws StorageException
    {
        throw new RuntimeException ("No elements in a dummy object in association Users");
    }


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

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


    public Client getClientsAt (int index) throws StorageException
    {
        throw new RuntimeException ("No elements in a dummy object in association Clients");
    }


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

}

    
