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.kernel.util.ProxyFactory;
021    import com.liferay.portal.model.BaseModel;
022    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
023    
024    /**
025     * @author Brian Wing Shun Chan
026     */
027    public class FinderCacheUtil {
028    
029            public static void clearCache() {
030                    _finderCache.clearCache();
031            }
032    
033            public static void clearCache(String className) {
034                    _finderCache.clearCache(className);
035            }
036    
037            public static void clearLocalCache() {
038                    _finderCache.clearLocalCache();
039            }
040    
041            public static FinderCache getFinderCache() {
042                    PortalRuntimePermission.checkGetBeanProperty(FinderCacheUtil.class);
043    
044                    return _finderCache;
045            }
046    
047            public static Object getResult(
048                    FinderPath finderPath, Object[] args,
049                    BasePersistenceImpl<? extends BaseModel<?>> basePersistenceImpl) {
050    
051                    return _finderCache.getResult(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                    _finderCache.putResult(finderPath, args, result);
090            }
091    
092            public static void putResult(
093                    FinderPath finderPath, Object[] args, Object result, boolean quiet) {
094    
095                    _finderCache.putResult(finderPath, args, result, quiet);
096            }
097    
098            public static void removeCache(String className) {
099                    _finderCache.removeCache(className);
100            }
101    
102            public static void removeResult(FinderPath finderPath, Object[] args) {
103                    _finderCache.removeResult(finderPath, args);
104            }
105    
106            private static final Log _log = LogFactoryUtil.getLog(
107                    FinderCacheUtil.class);
108    
109            private static final FinderCache _finderCache =
110                    ProxyFactory.newServiceTrackedInstance(FinderCache.class);
111    
112    }