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.kernel.dao.orm;
016    
017    import com.liferay.portal.kernel.cache.PortalCache;
018    import com.liferay.portal.kernel.security.pacl.permission.PortalRuntimePermission;
019    
020    import java.io.Serializable;
021    
022    /**
023     * @author Brian Wing Shun Chan
024     */
025    public class EntityCacheUtil {
026    
027            public static void clearCache() {
028                    getEntityCache().clearCache();
029            }
030    
031            public static void clearCache(String className) {
032                    getEntityCache().clearCache(className);
033            }
034    
035            public static void clearLocalCache() {
036                    getEntityCache().clearLocalCache();
037            }
038    
039            public static EntityCache getEntityCache() {
040                    PortalRuntimePermission.checkGetBeanProperty(EntityCacheUtil.class);
041    
042                    return _entityCache;
043            }
044    
045            public static PortalCache<Serializable, Serializable> getPortalCache(
046                    Class<?> clazz) {
047    
048                    return getEntityCache().getPortalCache(clazz);
049            }
050    
051            public static Serializable getResult(
052                    boolean entityCacheEnabled, Class<?> clazz, Serializable primaryKey) {
053    
054                    return getEntityCache().getResult(
055                            entityCacheEnabled, clazz, primaryKey);
056            }
057    
058            public static void invalidate() {
059                    getEntityCache().invalidate();
060            }
061    
062            public static Serializable loadResult(
063                    boolean entityCacheEnabled, Class<?> clazz, Serializable primaryKey,
064                    SessionFactory sessionFactory) {
065    
066                    return getEntityCache().loadResult(
067                            entityCacheEnabled, clazz, primaryKey, sessionFactory);
068            }
069    
070            public static void putResult(
071                    boolean entityCacheEnabled, Class<?> clazz, Serializable primaryKey,
072                    Serializable result) {
073    
074                    getEntityCache().putResult(
075                            entityCacheEnabled, clazz, primaryKey, result);
076            }
077    
078            public static void removeCache(String className) {
079                    getEntityCache().removeCache(className);
080            }
081    
082            public static void removeResult(
083                    boolean entityCacheEnabled, Class<?> clazz, Serializable primaryKey) {
084    
085                    getEntityCache().removeResult(entityCacheEnabled, clazz, primaryKey);
086            }
087    
088            public void setEntityCache(EntityCache entityCache) {
089                    PortalRuntimePermission.checkSetBeanProperty(getClass());
090    
091                    _entityCache = entityCache;
092            }
093    
094            private static EntityCache _entityCache;
095    
096    }