001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portlet.documentlibrary.service.persistence;
016    
017    import com.liferay.portal.kernel.dao.orm.QueryPos;
018    import com.liferay.portal.kernel.dao.orm.SQLQuery;
019    import com.liferay.portal.kernel.dao.orm.Session;
020    import com.liferay.portal.kernel.dao.orm.Type;
021    import com.liferay.portal.kernel.exception.SystemException;
022    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
023    import com.liferay.portlet.documentlibrary.model.DLFileRank;
024    import com.liferay.util.dao.orm.CustomSQLUtil;
025    
026    import java.util.List;
027    
028    /**
029     * @author Alexander Chow
030     */
031    public class DLFileRankFinderImpl
032            extends BasePersistenceImpl<DLFileRank> implements DLFileRankFinder {
033    
034            public static String FIND_BY_STALE_RANKS =
035                    DLFileRankFinder.class.getName() + ".findByStaleRanks";
036    
037            public List<Object[]> findByStaleRanks(int count) throws SystemException {
038                    Session session = null;
039    
040                    try {
041                            session = openSession();
042    
043                            String sql = CustomSQLUtil.get(FIND_BY_STALE_RANKS);
044    
045                            SQLQuery q = session.createSQLQuery(sql);
046    
047                            q.addScalar("groupId", Type.LONG);
048                            q.addScalar("userId", Type.LONG);
049    
050                            QueryPos qPos = QueryPos.getInstance(q);
051    
052                            qPos.add(count);
053    
054                            return q.list(true);
055                    }
056                    catch (Exception e) {
057                            throw new SystemException(e);
058                    }
059                    finally {
060                            closeSession(session);
061                    }
062            }
063    
064    }