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



public abstract class BaseShortenedURL extends BaseBusinessClass
{
    // Reference instance for the object
    public static final ShortenedURL REFERENCE_ShortenedURL = new ShortenedURL ();

    // Reference instance for the object
    public static final ShortenedURL DUMMY_ShortenedURL = new DummyShortenedURL ();

    // Static constants corresponding to field names
    
    public static final String FIELD_Code = "Code";
    public static final String FIELD_UrlLink = "UrlLink";

    // Static constants corresponding to searches
    public static final String SEARCH_all = "all";
    public static final String SEARCH_ByCode = "ByCode";
    

    // Static constants corresponding to attribute helpers
    private static final DefaultAttributeHelper<ShortenedURL> HELPER_Code = DefaultAttributeHelper.INSTANCE;
    private static final DefaultAttributeHelper<ShortenedURL> HELPER_UrlLink = DefaultAttributeHelper.INSTANCE;
    

    // Private attributes corresponding to business object data
    private String _Code;
    private String _UrlLink;
    

    // Private attributes corresponding to single references
    

    // Private attributes corresponding to multiple references
    

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

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

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

            FIELD_Code_Validators = (AttributeValidator[])setupAttribMetaData_Code(validatorMapping).toArray (new AttributeValidator[0]);
            FIELD_UrlLink_Validators = (AttributeValidator[])setupAttribMetaData_UrlLink(validatorMapping).toArray (new AttributeValidator[0]);
            

            REFERENCE_ShortenedURL.initialiseReference ();
            DUMMY_ShortenedURL.initialiseReference ();
            ShortenedURL_BehaviourDecorators = BaseBusinessClass.getBBCBehaviours(ShortenedURL.class).toArray(new ShortenedURLBehaviourDecorator[0]);
        }
        catch (RuntimeException e)
        {
            LogMgr.log (BUSINESS_OBJECTS, LogLevel.SYSTEMERROR1, e, "Error initialising");
            throw e;
        }
    }

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

        metaInfo.put ("dbcol", "code");
        metaInfo.put ("length", "8");
        metaInfo.put ("mandatory", "true");
        metaInfo.put ("name", "Code");
        metaInfo.put ("type", "String");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for ShortenedURL.Code:", metaInfo);
        ATTRIBUTES_METADATA_ShortenedURL.put (FIELD_Code, Collections.unmodifiableMap (metaInfo));

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

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

        metaInfo.put ("dbcol", "url_link");
        metaInfo.put ("mandatory", "true");
        metaInfo.put ("name", "UrlLink");
        metaInfo.put ("type", "String");
        
        LogMgr.log (BUSINESS_OBJECTS, LogLevel.DEBUG2, "Metadata for ShortenedURL.UrlLink:", metaInfo);
        ATTRIBUTES_METADATA_ShortenedURL.put (FIELD_UrlLink, Collections.unmodifiableMap (metaInfo));

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

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


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


    


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

        
        _Code = (String)(HELPER_Code.initialise (_Code));
        _UrlLink = (String)(HELPER_UrlLink.initialise (_UrlLink));
    }


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

        
    }


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

    

    /**
     * Get the attribute Code
     */
    public String getCode ()
    {
        assertValid();
        String valToReturn = _Code;

            for (ShortenedURLBehaviourDecorator bhd : ShortenedURL_BehaviourDecorators)
            {
                valToReturn = bhd.getCode ((ShortenedURL)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 preCodeChange (String newCode) 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 postCodeChange () throws FieldException
    {
    }

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

    /**
     * Set the attribute Code.  Checks to ensure a new value
     * has been supplied.  If so, marks the field as altered and sets the attribute.
     */
    public void setCode (String newCode) throws FieldException
    {
        boolean oldAndNewIdentical = HELPER_Code.compare (_Code, newCode);
        
        try
        {
            for (ShortenedURLBehaviourDecorator bhd : ShortenedURL_BehaviourDecorators)
            {
                newCode = bhd.setCode ((ShortenedURL)this, newCode);
                oldAndNewIdentical = HELPER_Code.compare (_Code, newCode);
            }

            BusinessObjectParser.assertFieldCondition (newCode != null, this, FIELD_Code, "mandatory");
            

            if (FIELD_Code_Validators.length > 0)
            {
                Object newCodeObj = HELPER_Code.toObject (newCode);

                if (newCodeObj != null)
                {
                    int     loopMax = FIELD_Code_Validators.length;
                    Map     metadata = (Map)ATTRIBUTES_METADATA_ShortenedURL.get (FIELD_Code);

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

        if (!oldAndNewIdentical)
        {
            assertValid();
            Debug.assertion (getWriteability_Code () != FieldWriteability.FALSE, "Field  Code is not writeable");
            preCodeChange (newCode);
            markFieldChange (FIELD_Code);
            _Code = newCode;            
            postFieldChange (FIELD_Code);
            postCodeChange ();
        }
    }

    /**
     * Get the attribute UrlLink
     */
    public String getUrlLink ()
    {
        assertValid();
        String valToReturn = _UrlLink;

            for (ShortenedURLBehaviourDecorator bhd : ShortenedURL_BehaviourDecorators)
            {
                valToReturn = bhd.getUrlLink ((ShortenedURL)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 preUrlLinkChange (String newUrlLink) 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 postUrlLinkChange () throws FieldException
    {
    }

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

    /**
     * Set the attribute UrlLink.  Checks to ensure a new value
     * has been supplied.  If so, marks the field as altered and sets the attribute.
     */
    public void setUrlLink (String newUrlLink) throws FieldException
    {
        boolean oldAndNewIdentical = HELPER_UrlLink.compare (_UrlLink, newUrlLink);
        
        try
        {
            for (ShortenedURLBehaviourDecorator bhd : ShortenedURL_BehaviourDecorators)
            {
                newUrlLink = bhd.setUrlLink ((ShortenedURL)this, newUrlLink);
                oldAndNewIdentical = HELPER_UrlLink.compare (_UrlLink, newUrlLink);
            }

            BusinessObjectParser.assertFieldCondition (newUrlLink != null, this, FIELD_UrlLink, "mandatory");
            

            if (FIELD_UrlLink_Validators.length > 0)
            {
                Object newUrlLinkObj = HELPER_UrlLink.toObject (newUrlLink);

                if (newUrlLinkObj != null)
                {
                    int     loopMax = FIELD_UrlLink_Validators.length;
                    Map     metadata = (Map)ATTRIBUTES_METADATA_ShortenedURL.get (FIELD_UrlLink);

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

        if (!oldAndNewIdentical)
        {
            assertValid();
            Debug.assertion (getWriteability_UrlLink () != FieldWriteability.FALSE, "Field  UrlLink is not writeable");
            preUrlLinkChange (newUrlLink);
            markFieldChange (FIELD_UrlLink);
            _UrlLink = newUrlLink;            
            postFieldChange (FIELD_UrlLink);
            postUrlLinkChange ();
        }
    }



    /**
     * 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 ShortenedURL newInstance ()
    {
        return new ShortenedURL ();
    }


    public ShortenedURL referenceInstance ()
    {
        return REFERENCE_ShortenedURL;
    }


    public ShortenedURL getInTransaction (ObjectTransaction t) throws StorageException
    {
        return getShortenedURLByID (t, getObjectID());
    }
    
    
    public BaseBusinessClass dummyInstance ()
    {
        return DUMMY_ShortenedURL;
    }


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





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

        tl_shortened_urlPSet.setAttrib (FIELD_ObjectID, myID);
        tl_shortened_urlPSet.setAttrib (FIELD_Code, HELPER_Code.toObject (_Code)); //
        tl_shortened_urlPSet.setAttrib (FIELD_UrlLink, HELPER_UrlLink.toObject (_UrlLink)); //
        
    }


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

        
        PersistentSet   tl_shortened_urlPSet = allSets.getPersistentSet (objectID, "tl_shortened_url");

        _Code = (String)(HELPER_Code.fromObject (_Code, tl_shortened_urlPSet.getAttrib (FIELD_Code))); //
        _UrlLink = (String)(HELPER_UrlLink.fromObject (_UrlLink, tl_shortened_urlPSet.getAttrib (FIELD_UrlLink))); //
        
    }





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

        if (other instanceof ShortenedURL)
        {
            ShortenedURL otherShortenedURL = (ShortenedURL)other;
            
            try
            {
                setCode (otherShortenedURL.getCode ());
            }
            catch (FieldException ex)
            {
                e.addException (ex);
            }
            
            try
            {
                setUrlLink (otherShortenedURL.getUrlLink ());
            }
            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 BaseShortenedURL)
        {
            BaseShortenedURL sourceShortenedURL = (BaseShortenedURL)(source);

            _Code = sourceShortenedURL._Code;
            _UrlLink = sourceShortenedURL._UrlLink;
            
        }
    }


    /**
     * 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 BaseShortenedURL)
        {
            BaseShortenedURL sourceShortenedURL = (BaseShortenedURL)(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 BaseShortenedURL)
        {
            BaseShortenedURL sourceShortenedURL = (BaseShortenedURL)(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);

        _Code = (String)(HELPER_Code.readExternal (_Code, vals.get(FIELD_Code))); //
        _UrlLink = (String)(HELPER_UrlLink.readExternal (_UrlLink, vals.get(FIELD_UrlLink))); //
        
    }


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

        vals.put (FIELD_Code, HELPER_Code.writeExternal (_Code));
        vals.put (FIELD_UrlLink, HELPER_UrlLink.writeExternal (_UrlLink));
        
    }


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

        if (other instanceof BaseShortenedURL)
        {
            BaseShortenedURL otherShortenedURL = (BaseShortenedURL)(other);

            
            if (!HELPER_Code.compare(this._Code, otherShortenedURL._Code))
            {
                listener.notifyFieldChange(this, other, FIELD_Code, HELPER_Code.toObject(this._Code), HELPER_Code.toObject(otherShortenedURL._Code));
            }
            if (!HELPER_UrlLink.compare(this._UrlLink, otherShortenedURL._UrlLink))
            {
                listener.notifyFieldChange(this, other, FIELD_UrlLink, HELPER_UrlLink.toObject(this._UrlLink), HELPER_UrlLink.toObject(otherShortenedURL._UrlLink));
            }

            // 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_Code, HELPER_Code.toObject(getCode()));
        visitor.visitField(this, FIELD_UrlLink, HELPER_UrlLink.toObject(getUrlLink()));
        
    }


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

        
    }


    public static ShortenedURL createShortenedURL (ObjectTransaction transaction) throws StorageException
    {
        ShortenedURL     result = new ShortenedURL ();

        result.initialiseNewObject (transaction);

        return result;
    }


    public static ShortenedURL getShortenedURLByID (ObjectTransaction transaction, Long objectID) throws StorageException
    {
        return (ShortenedURL)(transaction.getObjectByID (REFERENCE_ShortenedURL, objectID));
    }

    public boolean testFilter (String attribName, QueryFilter filter) throws StorageException
    {
        if (false)
        {
            throw new RuntimeException ("Game over man!!");
        }
        else if (attribName.equals (FIELD_Code))
        {
            return filter.matches (getCode ());
        }
        else if (attribName.equals (FIELD_UrlLink))
        {
            return filter.matches (getUrlLink ());
        }
        else
        {
            return super.testFilter (attribName, filter);
        }
    }


    public static Searchall SearchByall () { return new Searchall (); }

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

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

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

            
            public Searchall andCode (QueryFilter<String> filter)
            {
                filter.addFilter (context, "tl_shortened_url.code", "Code");
                return this;
            }
            
            public Searchall andUrlLink (QueryFilter<String> filter)
            {
                filter.addFilter (context, "tl_shortened_url.url_link", "UrlLink");
                return this;
            }
            
                public ShortenedURL[]
             search (ObjectTransaction transaction) throws StorageException
        {
            
            
            BaseBusinessClass[]     results = super.search (transaction, REFERENCE_ShortenedURL, SEARCH_all, criteria);
            Set<ShortenedURL>   typedResults = new LinkedHashSet <ShortenedURL> ();
            for (BaseBusinessClass bbcResult : results)
            {
                ShortenedURL aResult = (ShortenedURL)bbcResult;
                
                typedResults.add (aResult);
            }
            
                    return ObjstoreUtils.removeDeleted(transaction, typedResults).toArray (new ShortenedURL[0]);
                            
        }
    }

        
                public static ShortenedURL[]
             searchall (ObjectTransaction transaction) throws StorageException
        {
            return SearchByall ()
            .search (transaction);
        }

        public abstract boolean filterByCode(String Code) throws StorageException;
    
    public static SearchByCode SearchByByCode () { return new SearchByCode (); }

    public static class SearchByCode extends SearchObject<ShortenedURL>
    {
        
        public SearchByCode byCode (String Code)
        {
            by ("Code", Code);
            return this;
        }
        
            public SearchByCode andObjectID (QueryFilter<Long> filter)
            {
                filter.addFilter (context, "tl_shortened_url.object_id", FIELD_ObjectID);
                return this;
            }

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

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

            
            public SearchByCode andCode (QueryFilter<String> filter)
            {
                filter.addFilter (context, "tl_shortened_url.code", "Code");
                return this;
            }
            
            public SearchByCode andUrlLink (QueryFilter<String> filter)
            {
                filter.addFilter (context, "tl_shortened_url.url_link", "UrlLink");
                return this;
            }
            
                public ShortenedURL[]
             search (ObjectTransaction transaction) throws StorageException
        {
            String Code = (String)criteria.get ("Code");
                
            
            BaseBusinessClass[]     results = super.search (transaction, REFERENCE_ShortenedURL, SEARCH_ByCode, criteria);
            Set<ShortenedURL>   typedResults = new LinkedHashSet <ShortenedURL> ();
            for (BaseBusinessClass bbcResult : results)
            {
                ShortenedURL aResult = (ShortenedURL)bbcResult;
                
                    // Check in case in memory objects should be excluded
                    if (!aResult.filterByCode(Code) || !filterAndsInMemory (aResult))
                    {
                        continue;
                    }
                
                typedResults.add (aResult);
            }
            
            // Check in memory objects for matches
            for (BaseBusinessClass bbcInMemory : transaction.getObjectsToStore ())
            {
                if (bbcInMemory instanceof ShortenedURL)
                {
                    ShortenedURL aInMemory = (ShortenedURL)bbcInMemory;

                    if (!aInMemory.filterByCode(Code) || !filterAndsInMemory (aInMemory))
                    {
                        continue;
                    }

                    typedResults.add (aInMemory);
                }
            }
            
                    return ObjstoreUtils.removeDeleted(transaction, typedResults).toArray (new ShortenedURL[0]);
                            
        }
    }

        
                public static ShortenedURL[]
             searchByCode (ObjectTransaction transaction, String Code) throws StorageException
        {
            return SearchByByCode ()
            .byCode  (Code)
            .search (transaction);
        }



    public Object getAttribute (String attribName)
    {
        if (false)
        {
            throw new RuntimeException ("Game over man!!");
        }
        else if (attribName.equals (FIELD_Code))
        {
            return HELPER_Code.toObject (getCode ());
        }
        else if (attribName.equals (FIELD_UrlLink))
        {
            return HELPER_UrlLink.toObject (getUrlLink ());
        }
        else
        {
            return super.getAttribute (attribName);
        }
    }


    public AttributeHelper getAttributeHelper (String attribName)
    {
        if (false)
        {
            throw new RuntimeException ("Game over man!!");
        }
        else if (attribName.equals (FIELD_Code))
        {
            return HELPER_Code;
        }
        else if (attribName.equals (FIELD_UrlLink))
        {
            return HELPER_UrlLink;
        }
        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_Code))
        {
            setCode ((String)(HELPER_Code.fromObject (_Code, attribValue)));            
        }
        else if (attribName.equals (FIELD_UrlLink))
        {
            setUrlLink ((String)(HELPER_UrlLink.fromObject (_UrlLink, 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_Code))
        {
            return getWriteability_Code ();
        }
        else if (fieldName.equals (FIELD_UrlLink))
        {
            return getWriteability_UrlLink ();
        }
        else
        {
            return super.getWriteable (fieldName);
        }
    }


    public void putUnwriteable (Set<String> fields)
    {
        
            if (getWriteability_Code () != FieldWriteability.TRUE)
            {
                fields.add (FIELD_Code);
            }
        
            if (getWriteability_UrlLink () != FieldWriteability.TRUE)
            {
                fields.add (FIELD_UrlLink);
            }
        

        super.putUnwriteable (fields);
    }

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

        
        result.add(HELPER_Code.getAttribObject (getClass (), _Code, true, FIELD_Code));
        result.add(HELPER_UrlLink.getAttribObject (getClass (), _UrlLink, true, FIELD_UrlLink));

        return result;
    }


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


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

    /**
     * Get the attribute Code
     */
    public String getCode (ShortenedURL obj, String original)
    {
        return original;
    }

    /**
     * Change the value set for attribute Code.
     * May modify the field beforehand
     * Occurs before validation.
     */
    public String setCode (ShortenedURL obj, String newCode) throws FieldException
    {
        return newCode;
    }

    /**
     * Get the attribute UrlLink
     */
    public String getUrlLink (ShortenedURL obj, String original)
    {
        return original;
    }

    /**
     * Change the value set for attribute UrlLink.
     * May modify the field beforehand
     * Occurs before validation.
     */
    public String setUrlLink (ShortenedURL obj, String newUrlLink) throws FieldException
    {
        return newUrlLink;
    }

    }

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

        public ShortenedURLPipeLineFactory (Collection<From> seed)
        {
            super(seed);
        }
        
        
        public PipeLine<From, ? extends Object> to(String name)
        {
            if (name.equals ("Code"))
            {
                return toCode ();
            }                
            if (name.equals ("UrlLink"))
            {
                return toUrlLink ();
            }                
            
            
            return super.to(name);
        }
        
        
        public PipeLine<From, String> toCode () { return pipe(new ORMAttributePipe<Me, String>(FIELD_Code));  }
        
        public PipeLine<From, String> toUrlLink () { return pipe(new ORMAttributePipe<Me, String>(FIELD_UrlLink));  }
        
    }
    
    public boolean isTransientAttrib(String attribName)
    {
        

        return super.isTransientAttrib(attribName);
    }

    public boolean isTransientSingleReference(String assocName)
    {
        

        return super.isTransientSingleReference(assocName);
    }
}

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

    public void assertValid ()
    {
    }


}

