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