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.portal.service.persistence;
022:
023: import com.liferay.portal.SystemException;
024: import com.liferay.portal.model.impl.ActivityTrackerImpl;
025: import com.liferay.portal.spring.hibernate.CustomSQLUtil;
026: import com.liferay.portal.spring.hibernate.HibernateUtil;
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="ActivityTrackerFinderImpl.java.html"><b><i>View Source</i></b></a>
039: *
040: * @author Brian Wing Shun Chan
041: *
042: */
043: public class ActivityTrackerFinderImpl implements ActivityTrackerFinder {
044:
045: public static String COUNT_BY_U_R = ActivityTrackerFinder.class
046: .getName()
047: + ".countByU_R";
048:
049: public static String FIND_BY_U_R = ActivityTrackerFinder.class
050: .getName()
051: + ".findByU_R";
052:
053: public int countByU_R(long userId, long receiverUserId)
054: throws SystemException {
055:
056: Session session = null;
057:
058: try {
059: session = HibernateUtil.openSession();
060:
061: String sql = CustomSQLUtil.get(COUNT_BY_U_R);
062:
063: SQLQuery q = session.createSQLQuery(sql);
064:
065: q.addScalar(HibernateUtil.getCountColumnName(),
066: Hibernate.LONG);
067:
068: QueryPos qPos = QueryPos.getInstance(q);
069:
070: qPos.add(userId);
071: qPos.add(receiverUserId);
072:
073: Iterator itr = q.list().iterator();
074:
075: if (itr.hasNext()) {
076: Long count = (Long) itr.next();
077:
078: if (count != null) {
079: return count.intValue();
080: }
081: }
082:
083: return 0;
084: } catch (Exception e) {
085: throw new SystemException(e);
086: } finally {
087: HibernateUtil.closeSession(session);
088: }
089: }
090:
091: public List findByU_R(long userId, long receiverUserId, int begin,
092: int end) throws SystemException {
093:
094: Session session = null;
095:
096: try {
097: session = HibernateUtil.openSession();
098:
099: String sql = CustomSQLUtil.get(FIND_BY_U_R);
100:
101: SQLQuery q = session.createSQLQuery(sql);
102:
103: q.addEntity("ActivityTracker", ActivityTrackerImpl.class);
104:
105: QueryPos qPos = QueryPos.getInstance(q);
106:
107: qPos.add(userId);
108: qPos.add(receiverUserId);
109:
110: return QueryUtil.list(q, HibernateUtil.getDialect(), begin,
111: end);
112: } catch (Exception e) {
113: throw new SystemException(e);
114: } finally {
115: HibernateUtil.closeSession(session);
116: }
117: }
118:
119: }
|