/*
 * 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";
    public static final String FIELD_CouponDuration = "CouponDuration";
    public static final String FIELD_RedeemBy = "RedeemBy";
    public static final String FIELD_MaxRedemptions = "MaxRedemptions";
    public static final String FIELD_TimesRedeemed = "TimesRedeemed";

    // 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 static final EnumeratedAttributeHelper<StripeCoupon, CouponDuration> HELPER_CouponDuration =  new EnumeratedAttributeHelper<StripeCoupon, CouponDuration> (CouponDuration.FACTORY_CouponDuration);
    private static final DefaultAttributeHelper<StripeCoupon> HELPER_RedeemBy = DefaultAttributeHelper.INSTANCE;
    private static final DefaultAttributeHelper<StripeCoupon> HELPER_MaxRedemptions = DefaultAttributeHelper.INSTANCE;
    private static final DefaultAttributeHelper<StripeCoupon> HELPER_TimesRedeemed = DefaultAttributeHelper.INSTANCE;
    

    // Private attributes corresponding to business object data
    private String _CouponCode;
    private Double _PercentageOff;
    private Integer _DurationInMonths;
    private CouponDuration _CouponDuration;
    private Date _RedeemBy;
    private Integer _MaxRedemptions;
    private Integer _TimesRedeemed;
    

    // 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;
    private static final AttributeValidator[] FIELD_CouponDuration_Validators;
    private static final AttributeValidator[] FIELD_RedeemBy_Validators;
    private static final AttributeValidator[] FIELD_MaxRedemptions_Validators;
    private static final AttributeValidator[] FIELD_TimesRedeemed_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]);
            FIELD_CouponDuration_Validators = (AttributeValidator[])setupAttribMetaData_CouponDuration(validatorMapping).toArray (new AttributeValidator[0]);
            FIELD_RedeemBy_Validators = (AttributeValidator[])setupAttribMetaData_RedeemBy(validatorMapping).toArray (new AttributeValidator[0]);
            FIELD_MaxRedemptions_Validators = (AttributeValidator[])setupAttribMetaData_MaxRedemptions(validatorMapping).toArray (new AttributeValidator[0]);
            FIELD_TimesRedeemed_Validators = (AttributeValidator[])setupAttribMetaData_TimesRedeemed(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", "Double");
        
        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;
    }
    
    // Meta Info setup
    private static List setupAttribMetaData_CouponDuration(Map validatorMapping)
    {
        Map  metaInfo   = new HashMap ();

        metaInfo.put ("attribHelper", "EnumeratedAttributeHelper");
        metaInfo.put ("dbcol", "coupon_duration");
        metaInfo.put ("name", "CouponDuration");
        metaInfo.put ("type", "CouponDuration");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for StripeCoupon.CouponDuration:", metaInfo);
        ATTRIBUTES_METADATA_StripeCoupon.put (FIELD_CouponDuration, Collections.unmodifiableMap (metaInfo));

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

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

        metaInfo.put ("dbcol", "redeem_by");
        metaInfo.put ("name", "RedeemBy");
        metaInfo.put ("type", "Date");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for StripeCoupon.RedeemBy:", metaInfo);
        ATTRIBUTES_METADATA_StripeCoupon.put (FIELD_RedeemBy, Collections.unmodifiableMap (metaInfo));

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

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

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

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

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

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

        List validators = BaseBusinessClass.getAttribValidators(StripeCoupon.class, "TimesRedeemed", metaInfo, validatorMapping);
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG1, "Validators for StripeCoupon.TimesRedeemed:", 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 = (Double)(HELPER_PercentageOff.initialise (_PercentageOff));
        _DurationInMonths = (Integer)(HELPER_DurationInMonths.initialise (_DurationInMonths));
        _CouponDuration = (CouponDuration)(HELPER_CouponDuration.initialise (_CouponDuration));
        _RedeemBy = (Date)(HELPER_RedeemBy.initialise (_RedeemBy));
        _MaxRedemptions = (Integer)(HELPER_MaxRedemptions.initialise (_MaxRedemptions));
        _TimesRedeemed = (Integer)(HELPER_TimesRedeemed.initialise (_TimesRedeemed));
    }


    // 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 Double getPercentageOff ()
    {
        assertValid();
        Double 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 (Double 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 (Double 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 ();
        }
    }

    /**
     * Get the attribute CouponDuration
     */
    public CouponDuration getCouponDuration ()
    {
        assertValid();
        CouponDuration valToReturn = _CouponDuration;

            for (StripeCouponBehaviourDecorator bhd : StripeCoupon_BehaviourDecorators)
            {
                valToReturn = bhd.getCouponDuration ((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 preCouponDurationChange (CouponDuration newCouponDuration) 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 postCouponDurationChange () throws FieldException
    {
    }

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

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

            

            if (FIELD_CouponDuration_Validators.length > 0)
            {
                Object newCouponDurationObj = HELPER_CouponDuration.toObject (newCouponDuration);

                if (newCouponDurationObj != null)
                {
                    int     loopMax = FIELD_CouponDuration_Validators.length;
                    Map     metadata = (Map)ATTRIBUTES_METADATA_StripeCoupon.get (FIELD_CouponDuration);

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

        if (!oldAndNewIdentical)
        {
            assertValid();
            Debug.assertion (getWriteability_CouponDuration () != FieldWriteability.FALSE, "Field  CouponDuration is not writeable");
            preCouponDurationChange (newCouponDuration);
            markFieldChange (FIELD_CouponDuration);
            _CouponDuration = newCouponDuration;            
            postFieldChange (FIELD_CouponDuration);
            postCouponDurationChange ();
        }
    }

    /**
     * Get the attribute RedeemBy
     */
    public Date getRedeemBy ()
    {
        assertValid();
        Date valToReturn = _RedeemBy;

            for (StripeCouponBehaviourDecorator bhd : StripeCoupon_BehaviourDecorators)
            {
                valToReturn = bhd.getRedeemBy ((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 preRedeemByChange (Date newRedeemBy) 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 postRedeemByChange () throws FieldException
    {
    }

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

    /**
     * Set the attribute RedeemBy.  Checks to ensure a new value
     * has been supplied.  If so, marks the field as altered and sets the attribute.
     */
    public void setRedeemBy (Date newRedeemBy) throws FieldException
    {
        boolean oldAndNewIdentical = HELPER_RedeemBy.compare (_RedeemBy, newRedeemBy);
        
        try
        {
            for (StripeCouponBehaviourDecorator bhd : StripeCoupon_BehaviourDecorators)
            {
                newRedeemBy = bhd.setRedeemBy ((StripeCoupon)this, newRedeemBy);
                oldAndNewIdentical = HELPER_RedeemBy.compare (_RedeemBy, newRedeemBy);
            }

            

            if (FIELD_RedeemBy_Validators.length > 0)
            {
                Object newRedeemByObj = HELPER_RedeemBy.toObject (newRedeemBy);

                if (newRedeemByObj != null)
                {
                    int     loopMax = FIELD_RedeemBy_Validators.length;
                    Map     metadata = (Map)ATTRIBUTES_METADATA_StripeCoupon.get (FIELD_RedeemBy);

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

        if (!oldAndNewIdentical)
        {
            assertValid();
            Debug.assertion (getWriteability_RedeemBy () != FieldWriteability.FALSE, "Field  RedeemBy is not writeable");
            preRedeemByChange (newRedeemBy);
            markFieldChange (FIELD_RedeemBy);
            _RedeemBy = newRedeemBy;            
            postFieldChange (FIELD_RedeemBy);
            postRedeemByChange ();
        }
    }

    /**
     * Get the attribute MaxRedemptions
     */
    public Integer getMaxRedemptions ()
    {
        assertValid();
        Integer valToReturn = _MaxRedemptions;

            for (StripeCouponBehaviourDecorator bhd : StripeCoupon_BehaviourDecorators)
            {
                valToReturn = bhd.getMaxRedemptions ((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 preMaxRedemptionsChange (Integer newMaxRedemptions) 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 postMaxRedemptionsChange () throws FieldException
    {
    }

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

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

            

            if (FIELD_MaxRedemptions_Validators.length > 0)
            {
                Object newMaxRedemptionsObj = HELPER_MaxRedemptions.toObject (newMaxRedemptions);

                if (newMaxRedemptionsObj != null)
                {
                    int     loopMax = FIELD_MaxRedemptions_Validators.length;
                    Map     metadata = (Map)ATTRIBUTES_METADATA_StripeCoupon.get (FIELD_MaxRedemptions);

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

        if (!oldAndNewIdentical)
        {
            assertValid();
            Debug.assertion (getWriteability_MaxRedemptions () != FieldWriteability.FALSE, "Field  MaxRedemptions is not writeable");
            preMaxRedemptionsChange (newMaxRedemptions);
            markFieldChange (FIELD_MaxRedemptions);
            _MaxRedemptions = newMaxRedemptions;            
            postFieldChange (FIELD_MaxRedemptions);
            postMaxRedemptionsChange ();
        }
    }

    /**
     * Get the attribute TimesRedeemed
     */
    public Integer getTimesRedeemed ()
    {
        assertValid();
        Integer valToReturn = _TimesRedeemed;

            for (StripeCouponBehaviourDecorator bhd : StripeCoupon_BehaviourDecorators)
            {
                valToReturn = bhd.getTimesRedeemed ((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 preTimesRedeemedChange (Integer newTimesRedeemed) 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 postTimesRedeemedChange () throws FieldException
    {
    }

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

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

            

            if (FIELD_TimesRedeemed_Validators.length > 0)
            {
                Object newTimesRedeemedObj = HELPER_TimesRedeemed.toObject (newTimesRedeemed);

                if (newTimesRedeemedObj != null)
                {
                    int     loopMax = FIELD_TimesRedeemed_Validators.length;
                    Map     metadata = (Map)ATTRIBUTES_METADATA_StripeCoupon.get (FIELD_TimesRedeemed);

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

        if (!oldAndNewIdentical)
        {
            assertValid();
            Debug.assertion (getWriteability_TimesRedeemed () != FieldWriteability.FALSE, "Field  TimesRedeemed is not writeable");
            preTimesRedeemedChange (newTimesRedeemed);
            markFieldChange (FIELD_TimesRedeemed);
            _TimesRedeemed = newTimesRedeemed;            
            postFieldChange (FIELD_TimesRedeemed);
            postTimesRedeemedChange ();
        }
    }



    /**
     * 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)); //
        tl_couponPSet.setAttrib (FIELD_CouponDuration, HELPER_CouponDuration.toObject (_CouponDuration)); //
        tl_couponPSet.setAttrib (FIELD_RedeemBy, HELPER_RedeemBy.toObject (_RedeemBy)); //
        tl_couponPSet.setAttrib (FIELD_MaxRedemptions, HELPER_MaxRedemptions.toObject (_MaxRedemptions)); //
        tl_couponPSet.setAttrib (FIELD_TimesRedeemed, HELPER_TimesRedeemed.toObject (_TimesRedeemed)); //
        
    }


    /**
     * 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 = (Double)(HELPER_PercentageOff.fromObject (_PercentageOff, tl_couponPSet.getAttrib (FIELD_PercentageOff))); //
        _DurationInMonths = (Integer)(HELPER_DurationInMonths.fromObject (_DurationInMonths, tl_couponPSet.getAttrib (FIELD_DurationInMonths))); //
        _CouponDuration = (CouponDuration)(HELPER_CouponDuration.fromObject (_CouponDuration, tl_couponPSet.getAttrib (FIELD_CouponDuration))); //
        _RedeemBy = (Date)(HELPER_RedeemBy.fromObject (_RedeemBy, tl_couponPSet.getAttrib (FIELD_RedeemBy))); //
        _MaxRedemptions = (Integer)(HELPER_MaxRedemptions.fromObject (_MaxRedemptions, tl_couponPSet.getAttrib (FIELD_MaxRedemptions))); //
        _TimesRedeemed = (Integer)(HELPER_TimesRedeemed.fromObject (_TimesRedeemed, tl_couponPSet.getAttrib (FIELD_TimesRedeemed))); //
        
    }





    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);
            }
            
            try
            {
                setCouponDuration (otherStripeCoupon.getCouponDuration ());
            }
            catch (FieldException ex)
            {
                e.addException (ex);
            }
            
            try
            {
                setRedeemBy (otherStripeCoupon.getRedeemBy ());
            }
            catch (FieldException ex)
            {
                e.addException (ex);
            }
            
            try
            {
                setMaxRedemptions (otherStripeCoupon.getMaxRedemptions ());
            }
            catch (FieldException ex)
            {
                e.addException (ex);
            }
            
            try
            {
                setTimesRedeemed (otherStripeCoupon.getTimesRedeemed ());
            }
            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;
            _CouponDuration = sourceStripeCoupon._CouponDuration;
            _RedeemBy = sourceStripeCoupon._RedeemBy;
            _MaxRedemptions = sourceStripeCoupon._MaxRedemptions;
            _TimesRedeemed = sourceStripeCoupon._TimesRedeemed;
            
        }
    }


    /**
     * 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 = (Double)(HELPER_PercentageOff.readExternal (_PercentageOff, vals.get(FIELD_PercentageOff))); //
        _DurationInMonths = (Integer)(HELPER_DurationInMonths.readExternal (_DurationInMonths, vals.get(FIELD_DurationInMonths))); //
        _CouponDuration = (CouponDuration)(HELPER_CouponDuration.readExternal (_CouponDuration, vals.get(FIELD_CouponDuration))); //
        _RedeemBy = (Date)(HELPER_RedeemBy.readExternal (_RedeemBy, vals.get(FIELD_RedeemBy))); //
        _MaxRedemptions = (Integer)(HELPER_MaxRedemptions.readExternal (_MaxRedemptions, vals.get(FIELD_MaxRedemptions))); //
        _TimesRedeemed = (Integer)(HELPER_TimesRedeemed.readExternal (_TimesRedeemed, vals.get(FIELD_TimesRedeemed))); //
        
    }


    /**
     * 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));
        vals.put (FIELD_CouponDuration, HELPER_CouponDuration.writeExternal (_CouponDuration));
        vals.put (FIELD_RedeemBy, HELPER_RedeemBy.writeExternal (_RedeemBy));
        vals.put (FIELD_MaxRedemptions, HELPER_MaxRedemptions.writeExternal (_MaxRedemptions));
        vals.put (FIELD_TimesRedeemed, HELPER_TimesRedeemed.writeExternal (_TimesRedeemed));
        
    }


    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));
            }
            if (!HELPER_CouponDuration.compare(this._CouponDuration, otherStripeCoupon._CouponDuration))
            {
                listener.notifyFieldChange(this, other, FIELD_CouponDuration, HELPER_CouponDuration.toObject(this._CouponDuration), HELPER_CouponDuration.toObject(otherStripeCoupon._CouponDuration));
            }
            if (!HELPER_RedeemBy.compare(this._RedeemBy, otherStripeCoupon._RedeemBy))
            {
                listener.notifyFieldChange(this, other, FIELD_RedeemBy, HELPER_RedeemBy.toObject(this._RedeemBy), HELPER_RedeemBy.toObject(otherStripeCoupon._RedeemBy));
            }
            if (!HELPER_MaxRedemptions.compare(this._MaxRedemptions, otherStripeCoupon._MaxRedemptions))
            {
                listener.notifyFieldChange(this, other, FIELD_MaxRedemptions, HELPER_MaxRedemptions.toObject(this._MaxRedemptions), HELPER_MaxRedemptions.toObject(otherStripeCoupon._MaxRedemptions));
            }
            if (!HELPER_TimesRedeemed.compare(this._TimesRedeemed, otherStripeCoupon._TimesRedeemed))
            {
                listener.notifyFieldChange(this, other, FIELD_TimesRedeemed, HELPER_TimesRedeemed.toObject(this._TimesRedeemed), HELPER_TimesRedeemed.toObject(otherStripeCoupon._TimesRedeemed));
            }

            // 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()));
        visitor.visitField(this, FIELD_CouponDuration, HELPER_CouponDuration.toObject(getCouponDuration()));
        visitor.visitField(this, FIELD_RedeemBy, HELPER_RedeemBy.toObject(getRedeemBy()));
        visitor.visitField(this, FIELD_MaxRedemptions, HELPER_MaxRedemptions.toObject(getMaxRedemptions()));
        visitor.visitField(this, FIELD_TimesRedeemed, HELPER_TimesRedeemed.toObject(getTimesRedeemed()));
        
    }


    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 if (attribName.equals (FIELD_CouponDuration))
        {
            return filter.matches (getCouponDuration ());
        }
        else if (attribName.equals (FIELD_RedeemBy))
        {
            return filter.matches (getRedeemBy ());
        }
        else if (attribName.equals (FIELD_MaxRedemptions))
        {
            return filter.matches (getMaxRedemptions ());
        }
        else if (attribName.equals (FIELD_TimesRedeemed))
        {
            return filter.matches (getTimesRedeemed ());
        }
        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<Double> 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 SearchAll andCouponDuration (QueryFilter<CouponDuration> filter)
            {
                filter.addFilter (context, "tl_coupon.coupon_duration", "CouponDuration");
                return this;
            }
            
            public SearchAll andRedeemBy (QueryFilter<Date> filter)
            {
                filter.addFilter (context, "tl_coupon.redeem_by", "RedeemBy");
                return this;
            }
            
            public SearchAll andMaxRedemptions (QueryFilter<Integer> filter)
            {
                filter.addFilter (context, "tl_coupon.max_redemptions", "MaxRedemptions");
                return this;
            }
            
            public SearchAll andTimesRedeemed (QueryFilter<Integer> filter)
            {
                filter.addFilter (context, "tl_coupon.times_redeemed", "TimesRedeemed");
                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 if (attribName.equals (FIELD_CouponDuration))
        {
            return HELPER_CouponDuration.toObject (getCouponDuration ());
        }
        else if (attribName.equals (FIELD_RedeemBy))
        {
            return HELPER_RedeemBy.toObject (getRedeemBy ());
        }
        else if (attribName.equals (FIELD_MaxRedemptions))
        {
            return HELPER_MaxRedemptions.toObject (getMaxRedemptions ());
        }
        else if (attribName.equals (FIELD_TimesRedeemed))
        {
            return HELPER_TimesRedeemed.toObject (getTimesRedeemed ());
        }
        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 if (attribName.equals (FIELD_CouponDuration))
        {
            return HELPER_CouponDuration;
        }
        else if (attribName.equals (FIELD_RedeemBy))
        {
            return HELPER_RedeemBy;
        }
        else if (attribName.equals (FIELD_MaxRedemptions))
        {
            return HELPER_MaxRedemptions;
        }
        else if (attribName.equals (FIELD_TimesRedeemed))
        {
            return HELPER_TimesRedeemed;
        }
        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 ((Double)(HELPER_PercentageOff.fromObject (_PercentageOff, attribValue)));            
        }
        else if (attribName.equals (FIELD_DurationInMonths))
        {
            setDurationInMonths ((Integer)(HELPER_DurationInMonths.fromObject (_DurationInMonths, attribValue)));            
        }
        else if (attribName.equals (FIELD_CouponDuration))
        {
            setCouponDuration ((CouponDuration)(HELPER_CouponDuration.fromObject (_CouponDuration, attribValue)));            
        }
        else if (attribName.equals (FIELD_RedeemBy))
        {
            setRedeemBy ((Date)(HELPER_RedeemBy.fromObject (_RedeemBy, attribValue)));            
        }
        else if (attribName.equals (FIELD_MaxRedemptions))
        {
            setMaxRedemptions ((Integer)(HELPER_MaxRedemptions.fromObject (_MaxRedemptions, attribValue)));            
        }
        else if (attribName.equals (FIELD_TimesRedeemed))
        {
            setTimesRedeemed ((Integer)(HELPER_TimesRedeemed.fromObject (_TimesRedeemed, 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 if (fieldName.equals (FIELD_CouponDuration))
        {
            return getWriteability_CouponDuration ();
        }
        else if (fieldName.equals (FIELD_RedeemBy))
        {
            return getWriteability_RedeemBy ();
        }
        else if (fieldName.equals (FIELD_MaxRedemptions))
        {
            return getWriteability_MaxRedemptions ();
        }
        else if (fieldName.equals (FIELD_TimesRedeemed))
        {
            return getWriteability_TimesRedeemed ();
        }
        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);
            }
        
            if (getWriteability_CouponDuration () != FieldWriteability.TRUE)
            {
                fields.add (FIELD_CouponDuration);
            }
        
            if (getWriteability_RedeemBy () != FieldWriteability.TRUE)
            {
                fields.add (FIELD_RedeemBy);
            }
        
            if (getWriteability_MaxRedemptions () != FieldWriteability.TRUE)
            {
                fields.add (FIELD_MaxRedemptions);
            }
        
            if (getWriteability_TimesRedeemed () != FieldWriteability.TRUE)
            {
                fields.add (FIELD_TimesRedeemed);
            }
        

        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));
        result.add(HELPER_CouponDuration.getAttribObject (getClass (), _CouponDuration, false, FIELD_CouponDuration));
        result.add(HELPER_RedeemBy.getAttribObject (getClass (), _RedeemBy, false, FIELD_RedeemBy));
        result.add(HELPER_MaxRedemptions.getAttribObject (getClass (), _MaxRedemptions, false, FIELD_MaxRedemptions));
        result.add(HELPER_TimesRedeemed.getAttribObject (getClass (), _TimesRedeemed, false, FIELD_TimesRedeemed));

        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 Double getPercentageOff (StripeCoupon obj, Double original)
    {
        return original;
    }

    /**
     * Change the value set for attribute PercentageOff.
     * May modify the field beforehand
     * Occurs before validation.
     */
    public Double setPercentageOff (StripeCoupon obj, Double 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;
    }

    /**
     * Get the attribute CouponDuration
     */
    public CouponDuration getCouponDuration (StripeCoupon obj, CouponDuration original)
    {
        return original;
    }

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

    /**
     * Get the attribute RedeemBy
     */
    public Date getRedeemBy (StripeCoupon obj, Date original)
    {
        return original;
    }

    /**
     * Change the value set for attribute RedeemBy.
     * May modify the field beforehand
     * Occurs before validation.
     */
    public Date setRedeemBy (StripeCoupon obj, Date newRedeemBy) throws FieldException
    {
        return newRedeemBy;
    }

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

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

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

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

    }

    
    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 ();
            }                
            if (name.equals ("CouponDuration"))
            {
                return toCouponDuration ();
            }                
            if (name.equals ("RedeemBy"))
            {
                return toRedeemBy ();
            }                
            if (name.equals ("MaxRedemptions"))
            {
                return toMaxRedemptions ();
            }                
            if (name.equals ("TimesRedeemed"))
            {
                return toTimesRedeemed ();
            }                
            
            
            return super.to(name);
        }
        
        
        public PipeLine<From, String> toCouponCode () { return pipe(new ORMAttributePipe<Me, String>(FIELD_CouponCode));  }
        
        public PipeLine<From, Double> toPercentageOff () { return pipe(new ORMAttributePipe<Me, Double>(FIELD_PercentageOff));  }
        
        public PipeLine<From, Integer> toDurationInMonths () { return pipe(new ORMAttributePipe<Me, Integer>(FIELD_DurationInMonths));  }
        
        public PipeLine<From, CouponDuration> toCouponDuration () { return pipe(new ORMAttributePipe<Me, CouponDuration>(FIELD_CouponDuration));  }
        
        public PipeLine<From, Date> toRedeemBy () { return pipe(new ORMAttributePipe<Me, Date>(FIELD_RedeemBy));  }
        
        public PipeLine<From, Integer> toMaxRedemptions () { return pipe(new ORMAttributePipe<Me, Integer>(FIELD_MaxRedemptions));  }
        
        public PipeLine<From, Integer> toTimesRedeemed () { return pipe(new ORMAttributePipe<Me, Integer>(FIELD_TimesRedeemed));  }
        
    }
    
    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 ()
    {
    }


}

    
