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