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.log.Log;
018    import com.liferay.portal.kernel.log.LogFactoryUtil;
019    import com.liferay.portal.kernel.security.pacl.permission.PortalRuntimePermission;
020    
021    /**
022     * @author Brian Wing Shun Chan
023     */
024    public class FinderCacheUtil {
025    
026            public static void clearCache() {
027                    getFinderCache().clearCache();
028            }
029    
030            public static void clearCache(String className) {
031                    getFinderCache().clearCache(className);
032            }
033    
034            public static void clearLocalCache() {
035                    getFinderCache().clearLocalCache();
036            }
037    
038            public static FinderCache getFinderCache() {
039                    PortalRuntimePermission.checkGetBeanProperty(FinderCacheUtil.class);
040    
041                    return _finderCache;
042            }
043    
044            public static Object getResult(
045                    FinderPath finderPath, Object[] args, SessionFactory sessionFactory) {
046    
047                    return getFinderCache().getResult(finderPath, args, sessionFactory);
048            }
049    
050            /**
051             * @deprecated As of 6.1.0
052             */
053            public static Object getResult(
054                    String className, String methodName, String[] params, Object[] args,
055                    SessionFactory sessionFactory) {
056    
057                    _log.error(
058                            "Regenerate " + className +
059                                    " via \"ant build-service\" or else caching will not work");
060    
061                    return null;
062            }
063    
064            public static void invalidate() {
065                    getFinderCache().invalidate();
066            }
067    
068            /**
069             * @deprecated As of 6.1.0
070             */
071            public static void putResult(
072                    boolean classNameCacheEnabled, String className, String methodName,
073                    String[] params, Object[] args, Object result) {
074    
075                    _log.error(
076                            "Regenerate " + className +
077                                    " via \"ant build-service\" or else caching will not work");
078            }
079    
080            public static void putResult(
081                    FinderPath finderPath, Object[] args, Object result) {
082    
083                    getFinderCache().putResult(finderPath, args, result);
084            }
085    
086            public static void removeCache(String className) {
087                    getFinderCache().removeCache(className);
088            }
089    
090            public static void removeResult(FinderPath finderPath, Object[] args) {
091                    getFinderCache().removeResult(finderPath, args);
092            }
093    
094            public void setFinderCache(FinderCache finderCache) {
095                    PortalRuntimePermission.checkSetBeanProperty(getClass());
096    
097                    _finderCache = finderCache;
098            }
099    
100            private static Log _log = LogFactoryUtil.getLog(FinderCacheUtil.class);
101    
102            private static FinderCache _finderCache;
103    
104    }