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.messageboards.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.portal.util.PortalUtil;
027: import com.liferay.portlet.messageboards.model.MBCategory;
028: import com.liferay.portlet.messageboards.model.impl.MBCategoryImpl;
029: import com.liferay.util.dao.hibernate.QueryPos;
030: import com.liferay.util.dao.hibernate.QueryUtil;
031:
032: import java.util.Iterator;
033: import java.util.List;
034:
035: import org.hibernate.Hibernate;
036: import org.hibernate.SQLQuery;
037: import org.hibernate.Session;
038:
039: /**
040: * <a href="MBCategoryFinderImpl.java.html"><b><i>View Source</i></b></a>
041: *
042: * @author Raymond Augé
043: *
044: */
045: public class MBCategoryFinderImpl implements MBCategoryFinder {
046:
047: public static String COUNT_BY_S_G_U = MBCategoryFinder.class
048: .getName()
049: + ".countByS_G_U";
050:
051: public static String FIND_BY_S_G_U = MBCategoryFinder.class
052: .getName()
053: + ".findByS_G_U";
054:
055: public int countByS_G_U(long groupId, long userId)
056: throws SystemException {
057: Session session = null;
058:
059: try {
060: session = HibernateUtil.openSession();
061:
062: String sql = CustomSQLUtil.get(COUNT_BY_S_G_U);
063:
064: SQLQuery q = session.createSQLQuery(sql);
065:
066: q.addScalar(HibernateUtil.getCountColumnName(),
067: Hibernate.LONG);
068:
069: QueryPos qPos = QueryPos.getInstance(q);
070:
071: qPos.add(PortalUtil.getClassNameId(MBCategory.class
072: .getName()));
073: qPos.add(groupId);
074: qPos.add(userId);
075:
076: Iterator itr = q.list().iterator();
077:
078: if (itr.hasNext()) {
079: Long count = (Long) itr.next();
080:
081: if (count != null) {
082: return count.intValue();
083: }
084: }
085:
086: return 0;
087: } catch (Exception e) {
088: throw new SystemException(e);
089: } finally {
090: HibernateUtil.closeSession(session);
091: }
092: }
093:
094: public List findByS_G_U(long groupId, long userId, int begin,
095: int end) throws SystemException {
096:
097: Session session = null;
098:
099: try {
100: session = HibernateUtil.openSession();
101:
102: String sql = CustomSQLUtil.get(FIND_BY_S_G_U);
103:
104: SQLQuery q = session.createSQLQuery(sql);
105:
106: q.addEntity("MBCategory", MBCategoryImpl.class);
107:
108: QueryPos qPos = QueryPos.getInstance(q);
109:
110: qPos.add(PortalUtil.getClassNameId(MBCategory.class
111: .getName()));
112: qPos.add(groupId);
113: qPos.add(userId);
114:
115: return QueryUtil.list(q, HibernateUtil.getDialect(), begin,
116: end);
117: } catch (Exception e) {
118: throw new SystemException(e);
119: } finally {
120: HibernateUtil.closeSession(session);
121: }
122: }
123:
124: }
|