001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.dao.orm.hibernate.region;
016    
017    import net.sf.ehcache.hibernate.regions.EhcacheCollectionRegion;
018    
019    import org.hibernate.cache.CacheDataDescription;
020    import org.hibernate.cache.CacheException;
021    import org.hibernate.cache.CollectionRegion;
022    import org.hibernate.cache.access.AccessType;
023    import org.hibernate.cache.access.CollectionRegionAccessStrategy;
024    
025    /**
026     * @author Edward Han
027     */
028    public class CollectionRegionWrapper
029            extends BaseRegionWrapper implements CollectionRegion {
030    
031            public CollectionRegionWrapper(
032                    EhcacheCollectionRegion ehcacheCollectionRegion) {
033    
034                    super(ehcacheCollectionRegion);
035            }
036    
037            @Override
038            public CollectionRegionAccessStrategy buildAccessStrategy(
039                            AccessType accessType)
040                    throws CacheException {
041    
042                    EhcacheCollectionRegion ehcacheCollectionRegion =
043                            getEhcacheCollectionRegion();
044    
045                    return ehcacheCollectionRegion.buildAccessStrategy(accessType);
046            }
047    
048            @Override
049            public CacheDataDescription getCacheDataDescription() {
050                    EhcacheCollectionRegion ehcacheCollectionRegion =
051                            getEhcacheCollectionRegion();
052    
053                    return ehcacheCollectionRegion.getCacheDataDescription();
054            }
055    
056            @Override
057            public void invalidate() {
058                    EhcacheCollectionRegion ehcacheCollectionRegion =
059                            getEhcacheCollectionRegion();
060    
061                    ehcacheCollectionRegion.clear();
062            }
063    
064            @Override
065            public boolean isTransactionAware() {
066                    EhcacheCollectionRegion ehcacheCollectionRegion =
067                            getEhcacheCollectionRegion();
068    
069                    return ehcacheCollectionRegion.isTransactionAware();
070            }
071    
072            protected EhcacheCollectionRegion getEhcacheCollectionRegion() {
073                    return (EhcacheCollectionRegion)getEhcacheDataRegion();
074            }
075    
076    }