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

import performa.orm.types.*;



public abstract class BaseCurrencyPlanNPO extends NonPersistentBO
{
    // Reference instance for the object
    public static final CurrencyPlanNPO REFERENCE_CurrencyPlanNPO = new CurrencyPlanNPO ();

    // Reference instance for the object
    public static final CurrencyPlanNPO DUMMY_CurrencyPlanNPO = new DummyCurrencyPlanNPO ();

    // Static constants corresponding to field names
    
    public static final String FIELD_Amount = "Amount";
    public static final String FIELD_PerJobAmount = "PerJobAmount";
    public static final String FIELD_CurrencyType = "CurrencyType";
    public static final String SINGLEREFERENCE_Plan = "Plan";
    public static final String BACKREF_Plan = "";

    // Static constants corresponding to searches
    

    // Static constants corresponding to attribute helpers
    private static final DefaultAttributeHelper<CurrencyPlanNPO> HELPER_Amount = DefaultAttributeHelper.INSTANCE;
    private static final DefaultAttributeHelper<CurrencyPlanNPO> HELPER_PerJobAmount = DefaultAttributeHelper.INSTANCE;
    private static final EnumeratedAttributeHelper<CurrencyPlanNPO, CurrencyType> HELPER_CurrencyType =  new EnumeratedAttributeHelper<CurrencyPlanNPO, CurrencyType> (CurrencyType.FACTORY_CurrencyType);
    

    // Private attributes corresponding to business object data
    private Double _Amount;
    private Double _PerJobAmount;
    private CurrencyType _CurrencyType;
    

    // Private attributes corresponding to single references
    private SingleAssociation<CurrencyPlanNPO, StripePlanNPO> _Plan;
    

    // Private attributes corresponding to multiple references
    

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

    // Arrays of validators for each attribute
    private static final AttributeValidator[] FIELD_Amount_Validators;
    private static final AttributeValidator[] FIELD_PerJobAmount_Validators;
    private static final AttributeValidator[] FIELD_CurrencyType_Validators;
    

    // Arrays of behaviour decorators
    private static final CurrencyPlanNPOBehaviourDecorator[] CurrencyPlanNPO_BehaviourDecorators;
    
    static
    {
        try
        {
            
            String tmp_Plan = StripePlanNPO.BACKREF_CurrencyPlans;
            
            Map  validatorMapping = ((Map)ConfigMgr.getConfigObject ("CONFIG.ORMVALIDATOR", "ValidatorMapping"));

            setupAssocMetaData_Plan();
            FIELD_Amount_Validators = (AttributeValidator[])setupAttribMetaData_Amount(validatorMapping).toArray (new AttributeValidator[0]);
            FIELD_PerJobAmount_Validators = (AttributeValidator[])setupAttribMetaData_PerJobAmount(validatorMapping).toArray (new AttributeValidator[0]);
            FIELD_CurrencyType_Validators = (AttributeValidator[])setupAttribMetaData_CurrencyType(validatorMapping).toArray (new AttributeValidator[0]);
            

            REFERENCE_CurrencyPlanNPO.initialiseReference ();
            DUMMY_CurrencyPlanNPO.initialiseReference ();
            CurrencyPlanNPO_BehaviourDecorators = BaseBusinessClass.getBBCBehaviours(CurrencyPlanNPO.class).toArray(new CurrencyPlanNPOBehaviourDecorator[0]);
        }
        catch (RuntimeException e)
        {
            LogMgr.log (BUSINESS_OBJECTS, LogLevel.SYSTEMERROR1, e, "Error initialising");
            throw e;
        }
    }

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

        metaInfo.put ("backreferenceName", "CurrencyPlans");
        metaInfo.put ("name", "Plan");
        metaInfo.put ("type", "StripePlanNPO");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for CurrencyPlanNPO.Plan:", metaInfo);
        ATTRIBUTES_METADATA_CurrencyPlanNPO.put (SINGLEREFERENCE_Plan, Collections.unmodifiableMap (metaInfo));
    }
    
    
    // Meta Info setup
    private static List setupAttribMetaData_Amount(Map validatorMapping)
    {
        Map  metaInfo   = new HashMap ();

        
        metaInfo.putAll ((Map)ConfigMgr.getConfigObject ("CONFIG.SUBTYPE_ATTRIBS", "Currency", new HashMap ()));
        metaInfo.put ("Formatter", "Currency");
        metaInfo.put ("name", "Amount");
        metaInfo.put ("SubType", "Currency");
        metaInfo.put ("type", "Double");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for CurrencyPlanNPO.Amount:", metaInfo);
        ATTRIBUTES_METADATA_CurrencyPlanNPO.put (FIELD_Amount, Collections.unmodifiableMap (metaInfo));

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

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

        
        metaInfo.putAll ((Map)ConfigMgr.getConfigObject ("CONFIG.SUBTYPE_ATTRIBS", "Currency", new HashMap ()));
        metaInfo.put ("Formatter", "Currency");
        metaInfo.put ("name", "PerJobAmount");
        metaInfo.put ("SubType", "Currency");
        metaInfo.put ("type", "Double");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for CurrencyPlanNPO.PerJobAmount:", metaInfo);
        ATTRIBUTES_METADATA_CurrencyPlanNPO.put (FIELD_PerJobAmount, Collections.unmodifiableMap (metaInfo));

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

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

        metaInfo.put ("attribHelper", "EnumeratedAttributeHelper");
        metaInfo.put ("name", "CurrencyType");
        metaInfo.put ("type", "CurrencyType");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for CurrencyPlanNPO.CurrencyType:", metaInfo);
        ATTRIBUTES_METADATA_CurrencyPlanNPO.put (FIELD_CurrencyType, Collections.unmodifiableMap (metaInfo));

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

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


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


    


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

        
        _Amount = (Double)(HELPER_Amount.initialise (_Amount));
        _PerJobAmount = (Double)(HELPER_PerJobAmount.initialise (_PerJobAmount));
        _CurrencyType = (CurrencyType)(HELPER_CurrencyType.initialise (_CurrencyType));
    }


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

        _Plan = new SingleAssociation<CurrencyPlanNPO, StripePlanNPO> (this, SINGLEREFERENCE_Plan, StripePlanNPO.MULTIPLEREFERENCE_CurrencyPlans, StripePlanNPO.REFERENCE_StripePlanNPO, "it_does_not_matter");
        
    }


    // Initialise the associations
    protected BaseBusinessClass initialiseReference ()
    {
        super.initialiseReference ();
        
        _Plan = new SingleAssociation<CurrencyPlanNPO, StripePlanNPO> (this, SINGLEREFERENCE_Plan, StripePlanNPO.MULTIPLEREFERENCE_CurrencyPlans, StripePlanNPO.REFERENCE_StripePlanNPO, "it_does_not_matter");
        
        
        return this;
    }

    

    /**
     * Get the attribute Amount
     */
    public Double getAmount ()
    {
        assertValid();
        Double valToReturn = _Amount;

            for (CurrencyPlanNPOBehaviourDecorator bhd : CurrencyPlanNPO_BehaviourDecorators)
            {
                valToReturn = bhd.getAmount ((CurrencyPlanNPO)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 preAmountChange (Double newAmount) 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 postAmountChange () throws FieldException
    {
    }

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

    /**
     * Set the attribute Amount.  Checks to ensure a new value
     * has been supplied.  If so, marks the field as altered and sets the attribute.
     */
    public void setAmount (Double newAmount) throws FieldException
    {
        boolean oldAndNewIdentical = HELPER_Amount.compare (_Amount, newAmount);
        
        try
        {
            for (CurrencyPlanNPOBehaviourDecorator bhd : CurrencyPlanNPO_BehaviourDecorators)
            {
                newAmount = bhd.setAmount ((CurrencyPlanNPO)this, newAmount);
                oldAndNewIdentical = HELPER_Amount.compare (_Amount, newAmount);
            }

            

            if (FIELD_Amount_Validators.length > 0)
            {
                Object newAmountObj = HELPER_Amount.toObject (newAmount);

                if (newAmountObj != null)
                {
                    int     loopMax = FIELD_Amount_Validators.length;
                    Map     metadata = (Map)ATTRIBUTES_METADATA_CurrencyPlanNPO.get (FIELD_Amount);

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

        if (!oldAndNewIdentical)
        {
            assertValid();
            Debug.assertion (getWriteability_Amount () != FieldWriteability.FALSE, "Field  Amount is not writeable");
            preAmountChange (newAmount);
            markFieldChange (FIELD_Amount);
            _Amount = newAmount;            
            postFieldChange (FIELD_Amount);
            postAmountChange ();
        }
    }

    /**
     * Get the attribute PerJobAmount
     */
    public Double getPerJobAmount ()
    {
        assertValid();
        Double valToReturn = _PerJobAmount;

            for (CurrencyPlanNPOBehaviourDecorator bhd : CurrencyPlanNPO_BehaviourDecorators)
            {
                valToReturn = bhd.getPerJobAmount ((CurrencyPlanNPO)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 prePerJobAmountChange (Double newPerJobAmount) 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 postPerJobAmountChange () throws FieldException
    {
    }

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

    /**
     * Set the attribute PerJobAmount.  Checks to ensure a new value
     * has been supplied.  If so, marks the field as altered and sets the attribute.
     */
    public void setPerJobAmount (Double newPerJobAmount) throws FieldException
    {
        boolean oldAndNewIdentical = HELPER_PerJobAmount.compare (_PerJobAmount, newPerJobAmount);
        
        try
        {
            for (CurrencyPlanNPOBehaviourDecorator bhd : CurrencyPlanNPO_BehaviourDecorators)
            {
                newPerJobAmount = bhd.setPerJobAmount ((CurrencyPlanNPO)this, newPerJobAmount);
                oldAndNewIdentical = HELPER_PerJobAmount.compare (_PerJobAmount, newPerJobAmount);
            }

            

            if (FIELD_PerJobAmount_Validators.length > 0)
            {
                Object newPerJobAmountObj = HELPER_PerJobAmount.toObject (newPerJobAmount);

                if (newPerJobAmountObj != null)
                {
                    int     loopMax = FIELD_PerJobAmount_Validators.length;
                    Map     metadata = (Map)ATTRIBUTES_METADATA_CurrencyPlanNPO.get (FIELD_PerJobAmount);

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

        if (!oldAndNewIdentical)
        {
            assertValid();
            Debug.assertion (getWriteability_PerJobAmount () != FieldWriteability.FALSE, "Field  PerJobAmount is not writeable");
            prePerJobAmountChange (newPerJobAmount);
            markFieldChange (FIELD_PerJobAmount);
            _PerJobAmount = newPerJobAmount;            
            postFieldChange (FIELD_PerJobAmount);
            postPerJobAmountChange ();
        }
    }

    /**
     * Get the attribute CurrencyType
     */
    public CurrencyType getCurrencyType ()
    {
        assertValid();
        CurrencyType valToReturn = _CurrencyType;

            for (CurrencyPlanNPOBehaviourDecorator bhd : CurrencyPlanNPO_BehaviourDecorators)
            {
                valToReturn = bhd.getCurrencyType ((CurrencyPlanNPO)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 preCurrencyTypeChange (CurrencyType newCurrencyType) 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 postCurrencyTypeChange () throws FieldException
    {
    }

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

    /**
     * Set the attribute CurrencyType.  Checks to ensure a new value
     * has been supplied.  If so, marks the field as altered and sets the attribute.
     */
    public void setCurrencyType (CurrencyType newCurrencyType) throws FieldException
    {
        boolean oldAndNewIdentical = HELPER_CurrencyType.compare (_CurrencyType, newCurrencyType);
        
        try
        {
            for (CurrencyPlanNPOBehaviourDecorator bhd : CurrencyPlanNPO_BehaviourDecorators)
            {
                newCurrencyType = bhd.setCurrencyType ((CurrencyPlanNPO)this, newCurrencyType);
                oldAndNewIdentical = HELPER_CurrencyType.compare (_CurrencyType, newCurrencyType);
            }

            

            if (FIELD_CurrencyType_Validators.length > 0)
            {
                Object newCurrencyTypeObj = HELPER_CurrencyType.toObject (newCurrencyType);

                if (newCurrencyTypeObj != null)
                {
                    int     loopMax = FIELD_CurrencyType_Validators.length;
                    Map     metadata = (Map)ATTRIBUTES_METADATA_CurrencyPlanNPO.get (FIELD_CurrencyType);

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

        if (!oldAndNewIdentical)
        {
            assertValid();
            Debug.assertion (getWriteability_CurrencyType () != FieldWriteability.FALSE, "Field  CurrencyType is not writeable");
            preCurrencyTypeChange (newCurrencyType);
            markFieldChange (FIELD_CurrencyType);
            _CurrencyType = newCurrencyType;            
            postFieldChange (FIELD_CurrencyType);
            postCurrencyTypeChange ();
        }
    }



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

        
        result.add("Plan");
        

        return result;
    }
    
    
    public BaseBusinessClass getSingleAssocReferenceInstance (String assocName)
    {
        if (assocName == null)
        {
            throw new RuntimeException ("Game over == null!");
        }
        else if (assocName.equals (SINGLEREFERENCE_Plan))
        {
            return _Plan.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_Plan))
        {
            return StripePlanNPO.MULTIPLEREFERENCE_CurrencyPlans ;
        }
        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_Plan))
        {
            return getPlan ();
        }
        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_Plan))
        {
            return getPlan (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_Plan))
        {
            return getPlanID ();
        }
        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_Plan))
        {
            setPlan ((StripePlanNPO)(newValue));
        }
        else
        {
            super.setSingleAssoc (assocName, newValue);
        }
    }



    /**
     * Get the reference Plan
     */
    public StripePlanNPO getPlan () throws StorageException
    {
        assertValid();
        
        try
        {
            return (StripePlanNPO)(_Plan.get ());
        }
        catch (ClassCastException e)
        {
            LogMgr.log (BUSINESS_OBJECTS, LogLevel.SYSTEMERROR2, "Cache collision in CurrencyPlanNPO:", this.getObjectID (), ", was trying to get StripePlanNPO:",  getPlanID ());
            LogMgr.log (BUSINESS_OBJECTS, LogLevel.SYSTEMERROR2, "Instead I got:", _Plan.get ().getClass ());
            throw e;
        }
    }


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


    /**
     * Get the object id for the referenced object.  Does not force a DB access.
     */
    public Long getPlanID ()
    {
        assertValid();
        
        if (_Plan == null)
        {
            return null;
        }
        else
        {
            return _Plan.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 prePlanChange (StripePlanNPO newPlan) 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 postPlanChange () throws FieldException
    {
    }



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

        if (_Plan.wouldReferencedChange (newPlan))
        {
            assertValid();
            Debug.assertion (getWriteability_Plan () != FieldWriteability.FALSE, "Assoc Plan is not writeable");
            prePlanChange (newPlan);
            StripePlanNPO oldPlan = getPlan ();

                    if (oldPlan != null)
                    {
                        // This is to stop validation from triggering when we are removed
                        _Plan.set (null);
                        oldPlan.removeFromCurrencyPlans ((CurrencyPlanNPO)(this));
                    }

                    _Plan.set (newPlan);

                    if (newPlan != null)
                    {
                        newPlan.addToCurrencyPlans ((CurrencyPlanNPO)(this));
                    }
                
            postPlanChange ();
        }
    }

    /**
     * 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 (_Plan.isLoaded () || getTransaction ().isObjectLoaded (_Plan.getReferencedType (), getPlanID ()))
            {
                StripePlanNPO  referenced = getPlan ();

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

        super.onDelete ();
    }


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


    public CurrencyPlanNPO referenceInstance ()
    {
        return REFERENCE_CurrencyPlanNPO;
    }


    public CurrencyPlanNPO getInTransaction (ObjectTransaction t) throws StorageException
    {
        return getCurrencyPlanNPOByID (t, getObjectID());
    }
    
    
    public BaseBusinessClass dummyInstance ()
    {
        return DUMMY_CurrencyPlanNPO;
    }


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





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

        it_does_not_matterPSet.setAttrib (FIELD_ObjectID, myID);
        it_does_not_matterPSet.setAttrib (FIELD_Amount, HELPER_Amount.toObject (_Amount)); //
        it_does_not_matterPSet.setAttrib (FIELD_PerJobAmount, HELPER_PerJobAmount.toObject (_PerJobAmount)); //
        it_does_not_matterPSet.setAttrib (FIELD_CurrencyType, HELPER_CurrencyType.toObject (_CurrencyType)); //
        _Plan.getPersistentSets (allSets);
        
    }


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

        
        PersistentSet   it_does_not_matterPSet = allSets.getPersistentSet (objectID, "it_does_not_matter");

        _Amount = (Double)(HELPER_Amount.fromObject (_Amount, it_does_not_matterPSet.getAttrib (FIELD_Amount))); //
        _PerJobAmount = (Double)(HELPER_PerJobAmount.fromObject (_PerJobAmount, it_does_not_matterPSet.getAttrib (FIELD_PerJobAmount))); //
        _CurrencyType = (CurrencyType)(HELPER_CurrencyType.fromObject (_CurrencyType, it_does_not_matterPSet.getAttrib (FIELD_CurrencyType))); //
        _Plan.setFromPersistentSets (objectID, allSets);
        
    }





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

        if (other instanceof CurrencyPlanNPO)
        {
            CurrencyPlanNPO otherCurrencyPlanNPO = (CurrencyPlanNPO)other;
            
            try
            {
                setAmount (otherCurrencyPlanNPO.getAmount ());
            }
            catch (FieldException ex)
            {
                e.addException (ex);
            }
            
            try
            {
                setPerJobAmount (otherCurrencyPlanNPO.getPerJobAmount ());
            }
            catch (FieldException ex)
            {
                e.addException (ex);
            }
            
            try
            {
                setCurrencyType (otherCurrencyPlanNPO.getCurrencyType ());
            }
            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 BaseCurrencyPlanNPO)
        {
            BaseCurrencyPlanNPO sourceCurrencyPlanNPO = (BaseCurrencyPlanNPO)(source);

            _Amount = sourceCurrencyPlanNPO._Amount;
            _PerJobAmount = sourceCurrencyPlanNPO._PerJobAmount;
            _CurrencyType = sourceCurrencyPlanNPO._CurrencyType;
            
        }
    }


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

            _Plan.copyFrom (sourceCurrencyPlanNPO._Plan, 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 BaseCurrencyPlanNPO)
        {
            BaseCurrencyPlanNPO sourceCurrencyPlanNPO = (BaseCurrencyPlanNPO)(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);

        _Amount = (Double)(HELPER_Amount.readExternal (_Amount, vals.get(FIELD_Amount))); //
        _PerJobAmount = (Double)(HELPER_PerJobAmount.readExternal (_PerJobAmount, vals.get(FIELD_PerJobAmount))); //
        _CurrencyType = (CurrencyType)(HELPER_CurrencyType.readExternal (_CurrencyType, vals.get(FIELD_CurrencyType))); //
        _Plan.readExternalData(vals.get(SINGLEREFERENCE_Plan));
        
    }


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

        vals.put (FIELD_Amount, HELPER_Amount.writeExternal (_Amount));
        vals.put (FIELD_PerJobAmount, HELPER_PerJobAmount.writeExternal (_PerJobAmount));
        vals.put (FIELD_CurrencyType, HELPER_CurrencyType.writeExternal (_CurrencyType));
        vals.put (SINGLEREFERENCE_Plan, _Plan.writeExternalData());
        
    }


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

        if (other instanceof BaseCurrencyPlanNPO)
        {
            BaseCurrencyPlanNPO otherCurrencyPlanNPO = (BaseCurrencyPlanNPO)(other);

            
            if (!HELPER_Amount.compare(this._Amount, otherCurrencyPlanNPO._Amount))
            {
                listener.notifyFieldChange(this, other, FIELD_Amount, HELPER_Amount.toObject(this._Amount), HELPER_Amount.toObject(otherCurrencyPlanNPO._Amount));
            }
            if (!HELPER_PerJobAmount.compare(this._PerJobAmount, otherCurrencyPlanNPO._PerJobAmount))
            {
                listener.notifyFieldChange(this, other, FIELD_PerJobAmount, HELPER_PerJobAmount.toObject(this._PerJobAmount), HELPER_PerJobAmount.toObject(otherCurrencyPlanNPO._PerJobAmount));
            }
            if (!HELPER_CurrencyType.compare(this._CurrencyType, otherCurrencyPlanNPO._CurrencyType))
            {
                listener.notifyFieldChange(this, other, FIELD_CurrencyType, HELPER_CurrencyType.toObject(this._CurrencyType), HELPER_CurrencyType.toObject(otherCurrencyPlanNPO._CurrencyType));
            }

            // Compare single assocs
            _Plan.compare (otherCurrencyPlanNPO._Plan, 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_Amount, HELPER_Amount.toObject(getAmount()));
        visitor.visitField(this, FIELD_PerJobAmount, HELPER_PerJobAmount.toObject(getPerJobAmount()));
        visitor.visitField(this, FIELD_CurrencyType, HELPER_CurrencyType.toObject(getCurrencyType()));
        visitor.visitAssociation (_Plan);
        
    }


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

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


    public static CurrencyPlanNPO createCurrencyPlanNPO (ObjectTransaction transaction) throws StorageException
    {
        CurrencyPlanNPO     result = new CurrencyPlanNPO ();

        result.initialiseNewObject (transaction);

        return result;
    }


    public static CurrencyPlanNPO getCurrencyPlanNPOByID (ObjectTransaction transaction, Long objectID) throws StorageException
    {
        return (CurrencyPlanNPO)(transaction.getObjectByID (REFERENCE_CurrencyPlanNPO, objectID));
    }

    public boolean testFilter (String attribName, QueryFilter filter) throws StorageException
    {
        if (false)
        {
            throw new RuntimeException ("Game over man!!");
        }
        else if (attribName.equals (FIELD_Amount))
        {
            return filter.matches (getAmount ());
        }
        else if (attribName.equals (FIELD_PerJobAmount))
        {
            return filter.matches (getPerJobAmount ());
        }
        else if (attribName.equals (FIELD_CurrencyType))
        {
            return filter.matches (getCurrencyType ());
        }
        else if (attribName.equals (SINGLEREFERENCE_Plan))
        {
            return filter.matches (getPlan ());
        }
        else
        {
            return super.testFilter (attribName, filter);
        }
    }




    public Object getAttribute (String attribName)
    {
        if (false)
        {
            throw new RuntimeException ("Game over man!!");
        }
        else if (attribName.equals (FIELD_Amount))
        {
            return HELPER_Amount.toObject (getAmount ());
        }
        else if (attribName.equals (FIELD_PerJobAmount))
        {
            return HELPER_PerJobAmount.toObject (getPerJobAmount ());
        }
        else if (attribName.equals (FIELD_CurrencyType))
        {
            return HELPER_CurrencyType.toObject (getCurrencyType ());
        }
        else
        {
            return super.getAttribute (attribName);
        }
    }


    public AttributeHelper getAttributeHelper (String attribName)
    {
        if (false)
        {
            throw new RuntimeException ("Game over man!!");
        }
        else if (attribName.equals (FIELD_Amount))
        {
            return HELPER_Amount;
        }
        else if (attribName.equals (FIELD_PerJobAmount))
        {
            return HELPER_PerJobAmount;
        }
        else if (attribName.equals (FIELD_CurrencyType))
        {
            return HELPER_CurrencyType;
        }
        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_Amount))
        {
            setAmount ((Double)(HELPER_Amount.fromObject (_Amount, attribValue)));            
        }
        else if (attribName.equals (FIELD_PerJobAmount))
        {
            setPerJobAmount ((Double)(HELPER_PerJobAmount.fromObject (_PerJobAmount, attribValue)));            
        }
        else if (attribName.equals (FIELD_CurrencyType))
        {
            setCurrencyType ((CurrencyType)(HELPER_CurrencyType.fromObject (_CurrencyType, 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_Amount))
        {
            return getWriteability_Amount ();
        }
        else if (fieldName.equals (FIELD_PerJobAmount))
        {
            return getWriteability_PerJobAmount ();
        }
        else if (fieldName.equals (FIELD_CurrencyType))
        {
            return getWriteability_CurrencyType ();
        }
        else if (fieldName.equals (SINGLEREFERENCE_Plan))
        {
            return getWriteability_Plan ();
        }
        else
        {
            return super.getWriteable (fieldName);
        }
    }


    public void putUnwriteable (Set<String> fields)
    {
        
            if (getWriteability_Amount () != FieldWriteability.TRUE)
            {
                fields.add (FIELD_Amount);
            }
        
            if (getWriteability_PerJobAmount () != FieldWriteability.TRUE)
            {
                fields.add (FIELD_PerJobAmount);
            }
        
            if (getWriteability_CurrencyType () != FieldWriteability.TRUE)
            {
                fields.add (FIELD_CurrencyType);
            }
        

        super.putUnwriteable (fields);
    }

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

        
        result.add(HELPER_Amount.getAttribObject (getClass (), _Amount, false, FIELD_Amount));
        result.add(HELPER_PerJobAmount.getAttribObject (getClass (), _PerJobAmount, false, FIELD_PerJobAmount));
        result.add(HELPER_CurrencyType.getAttribObject (getClass (), _CurrencyType, false, FIELD_CurrencyType));

        return result;
    }


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


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

    /**
     * Get the attribute Amount
     */
    public Double getAmount (CurrencyPlanNPO obj, Double original)
    {
        return original;
    }

    /**
     * Change the value set for attribute Amount.
     * May modify the field beforehand
     * Occurs before validation.
     */
    public Double setAmount (CurrencyPlanNPO obj, Double newAmount) throws FieldException
    {
        return newAmount;
    }

    /**
     * Get the attribute PerJobAmount
     */
    public Double getPerJobAmount (CurrencyPlanNPO obj, Double original)
    {
        return original;
    }

    /**
     * Change the value set for attribute PerJobAmount.
     * May modify the field beforehand
     * Occurs before validation.
     */
    public Double setPerJobAmount (CurrencyPlanNPO obj, Double newPerJobAmount) throws FieldException
    {
        return newPerJobAmount;
    }

    /**
     * Get the attribute CurrencyType
     */
    public CurrencyType getCurrencyType (CurrencyPlanNPO obj, CurrencyType original)
    {
        return original;
    }

    /**
     * Change the value set for attribute CurrencyType.
     * May modify the field beforehand
     * Occurs before validation.
     */
    public CurrencyType setCurrencyType (CurrencyPlanNPO obj, CurrencyType newCurrencyType) throws FieldException
    {
        return newCurrencyType;
    }

    }

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

        public CurrencyPlanNPOPipeLineFactory (Collection<From> seed)
        {
            super(seed);
        }
        
        
        public PipeLine<From, ? extends Object> to(String name)
        {
            if (name.equals ("Amount"))
            {
                return toAmount ();
            }                
            if (name.equals ("PerJobAmount"))
            {
                return toPerJobAmount ();
            }                
            if (name.equals ("CurrencyType"))
            {
                return toCurrencyType ();
            }                
            if (name.equals ("Plan"))
            {
                return toPlan ();
            }                
            
            
            return super.to(name);
        }
        
        
        public PipeLine<From, Double> toAmount () { return pipe(new ORMAttributePipe<Me, Double>(FIELD_Amount));  }
        
        public PipeLine<From, Double> toPerJobAmount () { return pipe(new ORMAttributePipe<Me, Double>(FIELD_PerJobAmount));  }
        
        public PipeLine<From, CurrencyType> toCurrencyType () { return pipe(new ORMAttributePipe<Me, CurrencyType>(FIELD_CurrencyType));  }
        public StripePlanNPO.StripePlanNPOPipeLineFactory<From, StripePlanNPO> toPlan () { return toPlan (Filter.ALL); }

        public StripePlanNPO.StripePlanNPOPipeLineFactory<From, StripePlanNPO> toPlan (Filter<StripePlanNPO> filter) 
        { 
            return StripePlanNPO.REFERENCE_StripePlanNPO.new StripePlanNPOPipeLineFactory<From, StripePlanNPO> (this, new ORMSingleAssocPipe<Me, StripePlanNPO>(SINGLEREFERENCE_Plan, filter)); 
        }
        
    }
    
    public boolean isTransientAttrib(String attribName)
    {
        

        return super.isTransientAttrib(attribName);
    }

    public boolean isTransientSingleReference(String assocName)
    {
        

        return super.isTransientSingleReference(assocName);
    }
}

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

    public void assertValid ()
    {
    }


    public StripePlanNPO getPlan () throws StorageException
    {
        return (StripePlanNPO)(StripePlanNPO.DUMMY_StripePlanNPO);
    }


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

}

    
