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


    package performa.orm;

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

import performa.orm.types.*;



public abstract class BaseStripeCoupon extends BaseBusinessClass
{
    // Reference instance for the object
    public static final StripeCoupon REFERENCE_StripeCoupon = new StripeCoupon ();

    // Reference instance for the object
    public static final StripeCoupon DUMMY_StripeCoupon = new DummyStripeCoupon ();

    // Static constants corresponding to field names
    
    public static final String FIELD_CouponCode = "CouponCode";
    public static final String FIELD_PercentageOff = "PercentageOff";
    public static final String FIELD_DurationInMonths = "DurationInMonths";

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

    // Static constants corresponding to attribute helpers
    private static final DefaultAttributeHelper<StripeCoupon> HELPER_CouponCode = DefaultAttributeHelper.INSTANCE;
    private static final DefaultAttributeHelper<StripeCoupon> HELPER_PercentageOff = DefaultAttributeHelper.INSTANCE;
    private static final DefaultAttributeHelper<StripeCoupon> HELPER_DurationInMonths = DefaultAttributeHelper.INSTANCE;
    

    // Private attributes corresponding to business object data
    private String _CouponCode;
    private Integer _PercentageOff;
    private Integer _DurationInMonths;
    

    // Private attributes corresponding to single references
    

    // Private attributes corresponding to multiple references
    

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

    // Arrays of validators for each attribute
    private static final AttributeValidator[] FIELD_CouponCode_Validators;
    private static final AttributeValidator[] FIELD_PercentageOff_Validators;
    private static final AttributeValidator[] FIELD_DurationInMonths_Validators;
    

    // Arrays of behaviour decorators
    private static final StripeCouponBehaviourDecorator[] StripeCoupon_BehaviourDecorators;
    
    static
    {
        try
        {
            
            
            Map  validatorMapping = ((Map)ConfigMgr.getConfigObject ("CONFIG.ORMVALIDATOR", "ValidatorMapping"));

            FIELD_CouponCode_Validators = (AttributeValidator[])setupAttribMetaData_CouponCode(validatorMapping).toArray (new AttributeValidator[0]);
            FIELD_PercentageOff_Validators = (AttributeValidator[])setupAttribMetaData_PercentageOff(validatorMapping).toArray (new AttributeValidator[0]);
            FIELD_DurationInMonths_Validators = (AttributeValidator[])setupAttribMetaData_DurationInMonths(validatorMapping).toArray (new AttributeValidator[0]);
            

            REFERENCE_StripeCoupon.initialiseReference ();
            DUMMY_StripeCoupon.initialiseReference ();
            StripeCoupon_BehaviourDecorators = BaseBusinessClass.getBBCBehaviours(StripeCoupon.class).toArray(new StripeCouponBehaviourDecorator[0]);
        }
        catch (RuntimeException e)
        {
            LogMgr.log (BUSINESS_OBJECTS, LogLevel.SYSTEMERROR1, e, "Error initialising");
            throw e;
        }
    }

    
    // Meta Info setup
    private static List setupAttribMetaData_CouponCode(Map validatorMapping)
    {
        Map  metaInfo   = new HashMap ();

        metaInfo.put ("dbcol", "coupon_code");
        metaInfo.put ("length", "100");
        metaInfo.put ("mandatory", "true");
        metaInfo.put ("name", "CouponCode");
        metaInfo.put ("type", "String");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for StripeCoupon.CouponCode:", metaInfo);
        ATTRIBUTES_METADATA_StripeCoupon.put (FIELD_CouponCode, Collections.unmodifiableMap (metaInfo));

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

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

        metaInfo.put ("dbcol", "percentage_off");
        metaInfo.put ("name", "PercentageOff");
        metaInfo.put ("type", "Integer");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for StripeCoupon.PercentageOff:", metaInfo);
        ATTRIBUTES_METADATA_StripeCoupon.put (FIELD_PercentageOff, Collections.unmodifiableMap (metaInfo));

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

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

        metaInfo.put ("dbcol", "duration_in_months");
        metaInfo.put ("name", "DurationInMonths");
        metaInfo.put ("type", "Integer");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for StripeCoupon.DurationInMonths:", metaInfo);
        ATTRIBUTES_METADATA_StripeCoupon.put (FIELD_DurationInMonths, Collections.unmodifiableMap (metaInfo));

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

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


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


    


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

        
        _CouponCode = (String)(HELPER_CouponCode.initialise (_CouponCode));
        _PercentageOff = (Integer)(HELPER_PercentageOff.initialise (_PercentageOff));
        _DurationInMonths = (Integer)(HELPER_DurationInMonths.initialise (_DurationInMonths));
    }


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

        
    }


    // Initialise the associations
    protected BaseBusinessClass initialiseReference ()
    {
        super.initialiseReference ();
        
        
        
        return this;
    }

    

    /**
     * Get the attribute CouponCode
     */
    public String getCouponCode ()
    {
        assertValid();
        String valToReturn = _CouponCode;

            for (StripeCouponBehaviourDecorator bhd : StripeCoupon_BehaviourDecorators)
            {
                valToReturn = bhd.getCouponCode ((StripeCoupon)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 preCouponCodeChange (String newCouponCode) 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 postCouponCodeChange () throws FieldException
    {
    }

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

    /**
     * Set the attribute CouponCode.  Checks to ensure a new value
     * has been supplied.  If so, marks the field as altered and sets the attribute.
     */
    public void setCouponCode (String newCouponCode) throws FieldException
    {
        boolean oldAndNewIdentical = HELPER_CouponCode.compare (_CouponCode, newCouponCode);
        
        try
        {
            for (StripeCouponBehaviourDecorator bhd : StripeCoupon_BehaviourDecorators)
            {
                newCouponCode = bhd.setCouponCode ((StripeCoupon)this, newCouponCode);
                oldAndNewIdentical = HELPER_CouponCode.compare (_CouponCode, newCouponCode);
            }

            BusinessObjectParser.assertFieldCondition (newCouponCode != null, this, FIELD_CouponCode, "mandatory");
            

            if (FIELD_CouponCode_Validators.length > 0)
            {
                Object newCouponCodeObj = HELPER_CouponCode.toObject (newCouponCode);

                if (newCouponCodeObj != null)
                {
                    int     loopMax = FIELD_CouponCode_Validators.length;
                    Map     metadata = (Map)ATTRIBUTES_METADATA_StripeCoupon.get (FIELD_CouponCode);

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

        if (!oldAndNewIdentical)
        {
            assertValid();
            Debug.assertion (getWriteability_CouponCode () != FieldWriteability.FALSE, "Field  CouponCode is not writeable");
            preCouponCodeChange (newCouponCode);
            markFieldChange (FIELD_CouponCode);
            _CouponCode = newCouponCode;            
            postFieldChange (FIELD_CouponCode);
            postCouponCodeChange ();
        }
    }

    /**
     * Get the attribute PercentageOff
     */
    public Integer getPercentageOff ()
    {
        assertValid();
        Integer valToReturn = _PercentageOff;

            for (StripeCouponBehaviourDecorator bhd : StripeCoupon_BehaviourDecorators)
            {
                valToReturn = bhd.getPercentageOff ((StripeCoupon)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 prePercentageOffChange (Integer newPercentageOff) 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 postPercentageOffChange () throws FieldException
    {
    }

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

    /**
     * Set the attribute PercentageOff.  Checks to ensure a new value
     * has been supplied.  If so, marks the field as altered and sets the attribute.
     */
    public void setPercentageOff (Integer newPercentageOff) throws FieldException
    {
        boolean oldAndNewIdentical = HELPER_PercentageOff.compare (_PercentageOff, newPercentageOff);
        
        try
        {
            for (StripeCouponBehaviourDecorator bhd : StripeCoupon_BehaviourDecorators)
            {
                newPercentageOff = bhd.setPercentageOff ((StripeCoupon)this, newPercentageOff);
                oldAndNewIdentical = HELPER_PercentageOff.compare (_PercentageOff, newPercentageOff);
            }

            

            if (FIELD_PercentageOff_Validators.length > 0)
            {
                Object newPercentageOffObj = HELPER_PercentageOff.toObject (newPercentageOff);

                if (newPercentageOffObj != null)
                {
                    int     loopMax = FIELD_PercentageOff_Validators.length;
                    Map     metadata = (Map)ATTRIBUTES_METADATA_StripeCoupon.get (FIELD_PercentageOff);

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

        if (!oldAndNewIdentical)
        {
            assertValid();
            Debug.assertion (getWriteability_PercentageOff () != FieldWriteability.FALSE, "Field  PercentageOff is not writeable");
            prePercentageOffChange (newPercentageOff);
            markFieldChange (FIELD_PercentageOff);
            _PercentageOff = newPercentageOff;            
            postFieldChange (FIELD_PercentageOff);
            postPercentageOffChange ();
        }
    }

    /**
     * Get the attribute DurationInMonths
     */
    public Integer getDurationInMonths ()
    {
        assertValid();
        Integer valToReturn = _DurationInMonths;

            for (StripeCouponBehaviourDecorator bhd : StripeCoupon_BehaviourDecorators)
            {
                valToReturn = bhd.getDurationInMonths ((StripeCoupon)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 preDurationInMonthsChange (Integer newDurationInMonths) 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 postDurationInMonthsChange () throws FieldException
    {
    }

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

    /**
     * Set the attribute DurationInMonths.  Checks to ensure a new value
     * has been supplied.  If so, marks the field as altered and sets the attribute.
     */
    public void setDurationInMonths (Integer newDurationInMonths) throws FieldException
    {
        boolean oldAndNewIdentical = HELPER_DurationInMonths.compare (_DurationInMonths, newDurationInMonths);
        
        try
        {
            for (StripeCouponBehaviourDecorator bhd : StripeCoupon_BehaviourDecorators)
            {
                newDurationInMonths = bhd.setDurationInMonths ((StripeCoupon)this, newDurationInMonths);
                oldAndNewIdentical = HELPER_DurationInMonths.compare (_DurationInMonths, newDurationInMonths);
            }

            

            if (FIELD_DurationInMonths_Validators.length > 0)
            {
                Object newDurationInMonthsObj = HELPER_DurationInMonths.toObject (newDurationInMonths);

                if (newDurationInMonthsObj != null)
                {
                    int     loopMax = FIELD_DurationInMonths_Validators.length;
                    Map     metadata = (Map)ATTRIBUTES_METADATA_StripeCoupon.get (FIELD_DurationInMonths);

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

        if (!oldAndNewIdentical)
        {
            assertValid();
            Debug.assertion (getWriteability_DurationInMonths () != FieldWriteability.FALSE, "Field  DurationInMonths is not writeable");
            preDurationInMonthsChange (newDurationInMonths);
            markFieldChange (FIELD_DurationInMonths);
            _DurationInMonths = newDurationInMonths;            
            postFieldChange (FIELD_DurationInMonths);
            postDurationInMonthsChange ();
        }
    }



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

        

        return result;
    }
    
    
    public BaseBusinessClass getSingleAssocReferenceInstance (String assocName)
    {
        if (assocName == null)
        {
            throw new RuntimeException ("Game over == null!");
        }
        
        else
        {
            return super.getSingleAssocReferenceInstance (assocName);
        }
    }


    public String getSingleAssocBackReference(String assocName)
    {
        if (assocName == null)
        {
            throw new RuntimeException ("Game over == null!");
        }
        
        else
        {
            return super.getSingleAssocBackReference (assocName);
        }
    }
    
    
    public BaseBusinessClass getSingleAssoc (String assocName) throws StorageException
    {
        if (assocName == null)
        {
            throw new RuntimeException ("Game over == null!");
        }
        
        else
        {
            return super.getSingleAssoc (assocName);
        }
    }


    public BaseBusinessClass getSingleAssoc (String assocName, Get getType) throws StorageException
    {
        if (assocName == null)
        {
            throw new RuntimeException ("Game over == null!");
        }
        
        else
        {
            return super.getSingleAssoc (assocName, getType);
        }
    }


    public Long getSingleAssocID (String assocName) throws StorageException
    {
        if (assocName == null)
        {
            throw new RuntimeException ("Game over == null!");
        }
        
        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
        {
            super.setSingleAssoc (assocName, newValue);
        }
    }



    /**
     * 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 
        {
        }
        catch (Exception e)
        {
            throw NestedException.wrap(e);
        }

        super.onDelete ();
    }


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


    public StripeCoupon referenceInstance ()
    {
        return REFERENCE_StripeCoupon;
    }


    public StripeCoupon getInTransaction (ObjectTransaction t) throws StorageException
    {
        return getStripeCouponByID (t, getObjectID());
    }
    
    
    public BaseBusinessClass dummyInstance ()
    {
        return DUMMY_StripeCoupon;
    }


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





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

        tl_couponPSet.setAttrib (FIELD_ObjectID, myID);
        tl_couponPSet.setAttrib (FIELD_CouponCode, HELPER_CouponCode.toObject (_CouponCode)); //
        tl_couponPSet.setAttrib (FIELD_PercentageOff, HELPER_PercentageOff.toObject (_PercentageOff)); //
        tl_couponPSet.setAttrib (FIELD_DurationInMonths, HELPER_DurationInMonths.toObject (_DurationInMonths)); //
        
    }


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

        
        PersistentSet   tl_couponPSet = allSets.getPersistentSet (objectID, "tl_coupon");

        _CouponCode = (String)(HELPER_CouponCode.fromObject (_CouponCode, tl_couponPSet.getAttrib (FIELD_CouponCode))); //
        _PercentageOff = (Integer)(HELPER_PercentageOff.fromObject (_PercentageOff, tl_couponPSet.getAttrib (FIELD_PercentageOff))); //
        _DurationInMonths = (Integer)(HELPER_DurationInMonths.fromObject (_DurationInMonths, tl_couponPSet.getAttrib (FIELD_DurationInMonths))); //
        
    }





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

        if (other instanceof StripeCoupon)
        {
            StripeCoupon otherStripeCoupon = (StripeCoupon)other;
            
            try
            {
                setCouponCode (otherStripeCoupon.getCouponCode ());
            }
            catch (FieldException ex)
            {
                e.addException (ex);
            }
            
            try
            {
                setPercentageOff (otherStripeCoupon.getPercentageOff ());
            }
            catch (FieldException ex)
            {
                e.addException (ex);
            }
            
            try
            {
                setDurationInMonths (otherStripeCoupon.getDurationInMonths ());
            }
            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 BaseStripeCoupon)
        {
            BaseStripeCoupon sourceStripeCoupon = (BaseStripeCoupon)(source);

            _CouponCode = sourceStripeCoupon._CouponCode;
            _PercentageOff = sourceStripeCoupon._PercentageOff;
            _DurationInMonths = sourceStripeCoupon._DurationInMonths;
            
        }
    }


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

            
        }
    }


    /**
     * 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 BaseStripeCoupon)
        {
            BaseStripeCoupon sourceStripeCoupon = (BaseStripeCoupon)(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);

        _CouponCode = (String)(HELPER_CouponCode.readExternal (_CouponCode, vals.get(FIELD_CouponCode))); //
        _PercentageOff = (Integer)(HELPER_PercentageOff.readExternal (_PercentageOff, vals.get(FIELD_PercentageOff))); //
        _DurationInMonths = (Integer)(HELPER_DurationInMonths.readExternal (_DurationInMonths, vals.get(FIELD_DurationInMonths))); //
        
    }


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

        vals.put (FIELD_CouponCode, HELPER_CouponCode.writeExternal (_CouponCode));
        vals.put (FIELD_PercentageOff, HELPER_PercentageOff.writeExternal (_PercentageOff));
        vals.put (FIELD_DurationInMonths, HELPER_DurationInMonths.writeExternal (_DurationInMonths));
        
    }


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

        if (other instanceof BaseStripeCoupon)
        {
            BaseStripeCoupon otherStripeCoupon = (BaseStripeCoupon)(other);

            
            if (!HELPER_CouponCode.compare(this._CouponCode, otherStripeCoupon._CouponCode))
            {
                listener.notifyFieldChange(this, other, FIELD_CouponCode, HELPER_CouponCode.toObject(this._CouponCode), HELPER_CouponCode.toObject(otherStripeCoupon._CouponCode));
            }
            if (!HELPER_PercentageOff.compare(this._PercentageOff, otherStripeCoupon._PercentageOff))
            {
                listener.notifyFieldChange(this, other, FIELD_PercentageOff, HELPER_PercentageOff.toObject(this._PercentageOff), HELPER_PercentageOff.toObject(otherStripeCoupon._PercentageOff));
            }
            if (!HELPER_DurationInMonths.compare(this._DurationInMonths, otherStripeCoupon._DurationInMonths))
            {
                listener.notifyFieldChange(this, other, FIELD_DurationInMonths, HELPER_DurationInMonths.toObject(this._DurationInMonths), HELPER_DurationInMonths.toObject(otherStripeCoupon._DurationInMonths));
            }

            // Compare single assocs
            

            // 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_CouponCode, HELPER_CouponCode.toObject(getCouponCode()));
        visitor.visitField(this, FIELD_PercentageOff, HELPER_PercentageOff.toObject(getPercentageOff()));
        visitor.visitField(this, FIELD_DurationInMonths, HELPER_DurationInMonths.toObject(getDurationInMonths()));
        
    }


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

        
    }


    public static StripeCoupon createStripeCoupon (ObjectTransaction transaction) throws StorageException
    {
        StripeCoupon     result = new StripeCoupon ();

        result.initialiseNewObject (transaction);

        return result;
    }


    public static StripeCoupon getStripeCouponByID (ObjectTransaction transaction, Long objectID) throws StorageException
    {
        return (StripeCoupon)(transaction.getObjectByID (REFERENCE_StripeCoupon, objectID));
    }

    public boolean testFilter (String attribName, QueryFilter filter) throws StorageException
    {
        if (false)
        {
            throw new RuntimeException ("Game over man!!");
        }
        else if (attribName.equals (FIELD_CouponCode))
        {
            return filter.matches (getCouponCode ());
        }
        else if (attribName.equals (FIELD_PercentageOff))
        {
            return filter.matches (getPercentageOff ());
        }
        else if (attribName.equals (FIELD_DurationInMonths))
        {
            return filter.matches (getDurationInMonths ());
        }
        else
        {
            return super.testFilter (attribName, filter);
        }
    }


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

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

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

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

            
            public SearchAll andCouponCode (QueryFilter<String> filter)
            {
                filter.addFilter (context, "tl_coupon.coupon_code", "CouponCode");
                return this;
            }
            
            public SearchAll andPercentageOff (QueryFilter<Integer> filter)
            {
                filter.addFilter (context, "tl_coupon.percentage_off", "PercentageOff");
                return this;
            }
            
            public SearchAll andDurationInMonths (QueryFilter<Integer> filter)
            {
                filter.addFilter (context, "tl_coupon.duration_in_months", "DurationInMonths");
                return this;
            }
            
                public StripeCoupon[]
             search (ObjectTransaction transaction) throws StorageException
        {
            
            
            BaseBusinessClass[]     results = super.search (transaction, REFERENCE_StripeCoupon, SEARCH_All, criteria);
            Set<StripeCoupon>   typedResults = new LinkedHashSet <StripeCoupon> ();
            for (BaseBusinessClass bbcResult : results)
            {
                StripeCoupon aResult = (StripeCoupon)bbcResult;
                
                typedResults.add (aResult);
            }
            
                    return ObjstoreUtils.removeDeleted(transaction, typedResults).toArray (new StripeCoupon[0]);
                            
        }
    }

        
                public static StripeCoupon[]
             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_CouponCode))
        {
            return HELPER_CouponCode.toObject (getCouponCode ());
        }
        else if (attribName.equals (FIELD_PercentageOff))
        {
            return HELPER_PercentageOff.toObject (getPercentageOff ());
        }
        else if (attribName.equals (FIELD_DurationInMonths))
        {
            return HELPER_DurationInMonths.toObject (getDurationInMonths ());
        }
        else
        {
            return super.getAttribute (attribName);
        }
    }


    public AttributeHelper getAttributeHelper (String attribName)
    {
        if (false)
        {
            throw new RuntimeException ("Game over man!!");
        }
        else if (attribName.equals (FIELD_CouponCode))
        {
            return HELPER_CouponCode;
        }
        else if (attribName.equals (FIELD_PercentageOff))
        {
            return HELPER_PercentageOff;
        }
        else if (attribName.equals (FIELD_DurationInMonths))
        {
            return HELPER_DurationInMonths;
        }
        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_CouponCode))
        {
            setCouponCode ((String)(HELPER_CouponCode.fromObject (_CouponCode, attribValue)));            
        }
        else if (attribName.equals (FIELD_PercentageOff))
        {
            setPercentageOff ((Integer)(HELPER_PercentageOff.fromObject (_PercentageOff, attribValue)));            
        }
        else if (attribName.equals (FIELD_DurationInMonths))
        {
            setDurationInMonths ((Integer)(HELPER_DurationInMonths.fromObject (_DurationInMonths, 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_CouponCode))
        {
            return getWriteability_CouponCode ();
        }
        else if (fieldName.equals (FIELD_PercentageOff))
        {
            return getWriteability_PercentageOff ();
        }
        else if (fieldName.equals (FIELD_DurationInMonths))
        {
            return getWriteability_DurationInMonths ();
        }
        else
        {
            return super.getWriteable (fieldName);
        }
    }


    public void putUnwriteable (Set<String> fields)
    {
        
            if (getWriteability_CouponCode () != FieldWriteability.TRUE)
            {
                fields.add (FIELD_CouponCode);
            }
        
            if (getWriteability_PercentageOff () != FieldWriteability.TRUE)
            {
                fields.add (FIELD_PercentageOff);
            }
        
            if (getWriteability_DurationInMonths () != FieldWriteability.TRUE)
            {
                fields.add (FIELD_DurationInMonths);
            }
        

        super.putUnwriteable (fields);
    }

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

        
        result.add(HELPER_CouponCode.getAttribObject (getClass (), _CouponCode, true, FIELD_CouponCode));
        result.add(HELPER_PercentageOff.getAttribObject (getClass (), _PercentageOff, false, FIELD_PercentageOff));
        result.add(HELPER_DurationInMonths.getAttribObject (getClass (), _DurationInMonths, false, FIELD_DurationInMonths));

        return result;
    }


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


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

    /**
     * Get the attribute CouponCode
     */
    public String getCouponCode (StripeCoupon obj, String original)
    {
        return original;
    }

    /**
     * Change the value set for attribute CouponCode.
     * May modify the field beforehand
     * Occurs before validation.
     */
    public String setCouponCode (StripeCoupon obj, String newCouponCode) throws FieldException
    {
        return newCouponCode;
    }

    /**
     * Get the attribute PercentageOff
     */
    public Integer getPercentageOff (StripeCoupon obj, Integer original)
    {
        return original;
    }

    /**
     * Change the value set for attribute PercentageOff.
     * May modify the field beforehand
     * Occurs before validation.
     */
    public Integer setPercentageOff (StripeCoupon obj, Integer newPercentageOff) throws FieldException
    {
        return newPercentageOff;
    }

    /**
     * Get the attribute DurationInMonths
     */
    public Integer getDurationInMonths (StripeCoupon obj, Integer original)
    {
        return original;
    }

    /**
     * Change the value set for attribute DurationInMonths.
     * May modify the field beforehand
     * Occurs before validation.
     */
    public Integer setDurationInMonths (StripeCoupon obj, Integer newDurationInMonths) throws FieldException
    {
        return newDurationInMonths;
    }

    }

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

        public StripeCouponPipeLineFactory (Collection<From> seed)
        {
            super(seed);
        }
        
        
        public PipeLine<From, ? extends Object> to(String name)
        {
            if (name.equals ("CouponCode"))
            {
                return toCouponCode ();
            }                
            if (name.equals ("PercentageOff"))
            {
                return toPercentageOff ();
            }                
            if (name.equals ("DurationInMonths"))
            {
                return toDurationInMonths ();
            }                
            
            
            return super.to(name);
        }
        
        
        public PipeLine<From, String> toCouponCode () { return pipe(new ORMAttributePipe<Me, String>(FIELD_CouponCode));  }
        
        public PipeLine<From, Integer> toPercentageOff () { return pipe(new ORMAttributePipe<Me, Integer>(FIELD_PercentageOff));  }
        
        public PipeLine<From, Integer> toDurationInMonths () { return pipe(new ORMAttributePipe<Me, Integer>(FIELD_DurationInMonths));  }
        
    }
    
    public boolean isTransientAttrib(String attribName)
    {
        

        return super.isTransientAttrib(attribName);
    }

    public boolean isTransientSingleReference(String assocName)
    {
        

        return super.isTransientSingleReference(assocName);
    }
}

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

    public void assertValid ()
    {
    }


}

    
