001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portlet.documentlibrary.service.persistence;
022:
023: import com.liferay.portal.SystemException;
024: import com.liferay.portal.spring.hibernate.CustomSQLUtil;
025: import com.liferay.portal.spring.hibernate.HibernateUtil;
026: import com.liferay.portlet.documentlibrary.model.impl.DLFileRankImpl;
027: import com.liferay.util.dao.hibernate.QueryPos;
028: import com.liferay.util.dao.hibernate.QueryUtil;
029:
030: import java.util.Iterator;
031: import java.util.List;
032:
033: import org.hibernate.Hibernate;
034: import org.hibernate.SQLQuery;
035: import org.hibernate.Session;
036:
037: /**
038: * <a href="DLFileRankFinderImpl.java.html"><b><i>View Source</i></b></a>
039: *
040: * @author Brian Wing Shun Chan
041: *
042: */
043: public class DLFileRankFinderImpl implements DLFileRankFinder {
044:
045: public static String COUNT_BY_G_U = DLFileRankFinder.class
046: .getName()
047: + ".countByG_U";
048:
049: public static String FIND_BY_G_U = DLFileRankFinder.class.getName()
050: + ".findByG_U";
051:
052: public int countByG_U(long groupId, long userId)
053: throws SystemException {
054: Session session = null;
055:
056: try {
057: session = HibernateUtil.openSession();
058:
059: String sql = CustomSQLUtil.get(COUNT_BY_G_U);
060:
061: SQLQuery q = session.createSQLQuery(sql);
062:
063: q.addScalar(HibernateUtil.getCountColumnName(),
064: Hibernate.LONG);
065:
066: QueryPos qPos = QueryPos.getInstance(q);
067:
068: qPos.add(groupId);
069: qPos.add(userId);
070:
071: Iterator itr = q.list().iterator();
072:
073: if (itr.hasNext()) {
074: Long count = (Long) itr.next();
075:
076: if (count != null) {
077: return count.intValue();
078: }
079: }
080:
081: return 0;
082: } catch (Exception e) {
083: throw new SystemException(e);
084: } finally {
085: HibernateUtil.closeSession(session);
086: }
087: }
088:
089: public List findByG_U(long groupId, long userId)
090: throws SystemException {
091: return findByG_U(groupId, userId, QueryUtil.ALL_POS,
092: QueryUtil.ALL_POS);
093: }
094:
095: public List findByG_U(long groupId, long userId, int begin, int end)
096: throws SystemException {
097:
098: Session session = null;
099:
100: try {
101: session = HibernateUtil.openSession();
102:
103: String sql = CustomSQLUtil.get(FIND_BY_G_U);
104:
105: SQLQuery q = session.createSQLQuery(sql);
106:
107: q.addEntity("DLFileRank", DLFileRankImpl.class);
108:
109: QueryPos qPos = QueryPos.getInstance(q);
110:
111: qPos.add(groupId);
112: qPos.add(userId);
113:
114: return QueryUtil.list(q, HibernateUtil.getDialect(), begin,
115: end);
116: } catch (Exception e) {
117: throw new SystemException(e);
118: } finally {
119: HibernateUtil.closeSession(session);
120: }
121: }
122:
123: }
|