001    /**
002     * Copyright (c) 2000-2012 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.portlet.ratings.service.persistence;
016    
017    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
018    import com.liferay.portal.kernel.dao.orm.FinderPath;
019    import com.liferay.portal.kernel.dao.orm.QueryPos;
020    import com.liferay.portal.kernel.dao.orm.SQLQuery;
021    import com.liferay.portal.kernel.dao.orm.Session;
022    import com.liferay.portal.kernel.exception.SystemException;
023    import com.liferay.portal.kernel.util.StringUtil;
024    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
025    import com.liferay.portlet.ratings.model.RatingsStats;
026    import com.liferay.portlet.ratings.model.impl.RatingsStatsImpl;
027    import com.liferay.portlet.ratings.model.impl.RatingsStatsModelImpl;
028    import com.liferay.util.dao.orm.CustomSQLUtil;
029    
030    import java.util.ArrayList;
031    import java.util.List;
032    
033    /**
034     * @author Shuyang Zhou
035     * @author Brian Wing Shun Chan
036     */
037    public class RatingsStatsFinderImpl
038            extends BasePersistenceImpl<RatingsStats> implements RatingsStatsFinder {
039    
040            public static String FIND_BY_C_C =
041                    RatingsStatsFinder.class.getName() + ".findByC_C";
042    
043            public static final FinderPath FINDER_PATH_FIND_BY_C_C = new FinderPath(
044                    RatingsStatsModelImpl.ENTITY_CACHE_ENABLED,
045                    RatingsStatsModelImpl.FINDER_CACHE_ENABLED, RatingsStatsImpl.class,
046                    RatingsStatsPersistenceImpl.FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
047                    "findByC_C",
048                    new String[] {Long.class.getName(), List.class.getName()});
049    
050            public List<RatingsStats> findByC_C(long classNameId, List<Long> classPKs)
051                    throws SystemException {
052    
053                    Object[] finderArgs = new Object[] {
054                            classNameId,
055                            StringUtil.merge(classPKs.toArray(new Long[classPKs.size()]))
056                    };
057    
058                    List<RatingsStats> list = (List<RatingsStats>)FinderCacheUtil.getResult(
059                            FINDER_PATH_FIND_BY_C_C, finderArgs, this);
060    
061                    if (list != null) {
062                            return list;
063                    }
064    
065                    Session session = null;
066    
067                    try {
068                            session = openSession();
069    
070                            String sql = CustomSQLUtil.get(FIND_BY_C_C);
071    
072                            sql = StringUtil.replace(
073                                    sql, "[$CLASS_PKS$]", StringUtil.merge(classPKs));
074    
075                            SQLQuery q = session.createSQLQuery(sql);
076    
077                            q.addEntity("RatingsStats", RatingsStatsImpl.class);
078    
079                            QueryPos qPos = QueryPos.getInstance(q);
080    
081                            qPos.add(classNameId);
082    
083                            list = q.list(true);
084                    }
085                    catch (Exception e) {
086                            throw new SystemException(e);
087                    }
088                    finally {
089                            if (list == null) {
090                                    list = new ArrayList<RatingsStats>();
091                            }
092    
093                            FinderCacheUtil.putResult(
094                                    FINDER_PATH_FIND_BY_C_C, finderArgs, list);
095    
096                            closeSession(session);
097                    }
098    
099                    return list;
100            }
101    
102    }