001package org.andromda.cartridges.hibernate.metafacades;
002
003import org.andromda.cartridges.hibernate.HibernateProfile;
004import org.apache.commons.lang.StringUtils;
005
006/**
007 * MetafacadeLogic implementation for
008 * org.andromda.cartridges.hibernate.metafacades.HibernateAssociation.
009 *
010 * @see org.andromda.cartridges.hibernate.metafacades.HibernateAssociation
011 */
012public class HibernateAssociationLogicImpl
013    extends HibernateAssociationLogic
014{
015    private static final long serialVersionUID = 34L;
016    // ---------------- constructor -------------------------------
017    /**
018     * @param metaObject
019     * @param context
020     */
021    public HibernateAssociationLogicImpl(
022        Object metaObject,
023        String context)
024    {
025        super(metaObject, context);
026    }
027
028    /**
029     * Stores the default cache strategy for associations.
030     */
031    private static final String HIBERNATE_ASSOCIATION_CACHE = "hibernateAssociationCache";
032
033    /**
034     * @see org.andromda.cartridges.hibernate.metafacades.HibernateAssociation#getHibernateCacheType()
035     */
036    @Override
037    protected String handleGetHibernateCacheType()
038    {
039        String cacheType = (String)findTaggedValue(HibernateProfile.TAGGEDVALUE_HIBERNATE_ASSOCIATION_CACHE);
040        if (StringUtils.isBlank(cacheType))
041        {
042            cacheType = String.valueOf(this.getConfiguredProperty(HIBERNATE_ASSOCIATION_CACHE));
043        }
044        return StringUtils.trimToEmpty(cacheType);
045    }
046
047    /**
048     * @see org.andromda.cartridges.hibernate.metafacades.HibernateAssociation#getEhCacheMaxElementsInMemory()
049     */
050    @Override
051    protected int handleGetEhCacheMaxElementsInMemory()
052    {
053        String maxElements = null;
054        maxElements = (String)this.findTaggedValue(HibernateProfile.TAGGEDVALUE_HIBERNATE_EHCACHE_MAX_ELEMENTS);
055        if (StringUtils.isBlank(maxElements))
056        {
057            maxElements = (String)this.getConfiguredProperty(HibernateGlobals.HIBERNATE_EHCACHE_MAX_ELEMENTS);
058        }
059        return Integer.parseInt(maxElements);
060    }
061
062    /**
063     * @see org.andromda.cartridges.hibernate.metafacades.HibernateAssociation#isEhCacheEternal()
064     */
065    @Override
066    protected boolean handleIsEhCacheEternal()
067    {
068        String eternal = (String)this.findTaggedValue(HibernateProfile.TAGGEDVALUE_HIBERNATE_EHCACHE_ETERNAL);
069        if (StringUtils.isBlank(eternal))
070        {
071            eternal = (String)this.getConfiguredProperty(HibernateGlobals.HIBERNATE_EHCACHE_ETERNAL);
072        }
073        return Boolean.valueOf(eternal).booleanValue();
074    }
075
076    /**
077     * @see org.andromda.cartridges.hibernate.metafacades.HibernateAssociation#getEhCacheTimeToIdleSeconds()
078     */
079    @Override
080    protected int handleGetEhCacheTimeToIdleSeconds()
081    {
082        String timeToIdle = null;
083        timeToIdle = (String)this.findTaggedValue(HibernateProfile.TAGGEDVALUE_HIBERNATE_EHCACHE_TIME_TO_IDLE);
084        if (StringUtils.isBlank(timeToIdle))
085        {
086            timeToIdle = (String)this.getConfiguredProperty(HibernateGlobals.HIBERNATE_EHCACHE_TIME_TO_IDLE);
087        }
088        return Integer.parseInt(timeToIdle);
089    }
090
091    /**
092     * @see org.andromda.cartridges.hibernate.metafacades.HibernateAssociation#getEhCacheTimeToLiveSeconds()
093     */
094    @Override
095    protected int handleGetEhCacheTimeToLiveSeconds()
096    {
097        String timeToLive = null;
098        timeToLive = (String)this.findTaggedValue(HibernateProfile.TAGGEDVALUE_HIBERNATE_EHCACHE_TIME_TO_LIVE);
099        if (StringUtils.isBlank(timeToLive))
100        {
101            timeToLive = (String)this.getConfiguredProperty(HibernateGlobals.HIBERNATE_EHCACHE_TIME_TO_LIVE);
102        }
103        return Integer.parseInt(timeToLive);
104    }
105
106    /**
107     * @see org.andromda.cartridges.hibernate.metafacades.HibernateAssociation#isEhCacheOverflowToDisk()
108     */
109    @Override
110    protected boolean handleIsEhCacheOverflowToDisk()
111    {
112        String eternal = (String)this.findTaggedValue(HibernateProfile.TAGGEDVALUE_HIBERNATE_EHCACHE_OVERFLOW_TO_DISK);
113        if (StringUtils.isBlank(eternal))
114        {
115            eternal = (String)this.getConfiguredProperty(HibernateGlobals.HIBERNATE_EHCACHE_OVERFLOW_TO_DISK);
116        }
117        return Boolean.valueOf(eternal).booleanValue();
118    }
119
120    /**
121     * @see org.andromda.cartridges.hibernate.metafacades.HibernateAssociation#isHibernateCacheDistributed()
122     */
123    @Override
124    protected boolean handleIsHibernateCacheDistributed()
125    {
126        {
127            String distributed = (String)this.getConfiguredProperty(HibernateGlobals.HIBERNATE_ENTITYCACHE_DISTRIBUTED);
128            boolean distributedCachingEnabled = Boolean.valueOf(StringUtils.trimToEmpty(distributed)).booleanValue();
129
130            if (distributedCachingEnabled)
131            {
132                String entityCacheDistributed =
133                    (String)this.findTaggedValue(HibernateProfile.TAGGEDVALUE_HIBERNATE_ASSOCIATIONCACHE_DISTRIBUTED);
134                return Boolean.valueOf(StringUtils.trimToEmpty(entityCacheDistributed)).booleanValue();
135            }
136            return false;
137        }
138    }
139}