1
19
20 package com.liferay.portlet.messageboards.service.persistence;
21
22 import com.liferay.portal.SystemException;
23 import com.liferay.portal.kernel.dao.orm.QueryPos;
24 import com.liferay.portal.kernel.dao.orm.QueryUtil;
25 import com.liferay.portal.kernel.dao.orm.SQLQuery;
26 import com.liferay.portal.kernel.dao.orm.Session;
27 import com.liferay.portal.kernel.dao.orm.Type;
28 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
29 import com.liferay.portal.util.PortalUtil;
30 import com.liferay.portlet.messageboards.model.MBThread;
31 import com.liferay.portlet.messageboards.model.impl.MBThreadImpl;
32 import com.liferay.util.dao.orm.CustomSQLUtil;
33
34 import java.util.Iterator;
35 import java.util.List;
36
37
43 public class MBThreadFinderImpl
44 extends BasePersistenceImpl implements MBThreadFinder {
45
46 public static String COUNT_BY_S_G_U =
47 MBThreadFinder.class.getName() + ".countByS_G_U";
48
49 public static String FIND_BY_S_G_U =
50 MBThreadFinder.class.getName() + ".findByS_G_U";
51
52 public int countByS_G_U(long groupId, long userId) throws SystemException {
53 Session session = null;
54
55 try {
56 session = openSession();
57
58 String sql = CustomSQLUtil.get(COUNT_BY_S_G_U);
59
60 SQLQuery q = session.createSQLQuery(sql);
61
62 q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
63
64 QueryPos qPos = QueryPos.getInstance(q);
65
66 qPos.add(PortalUtil.getClassNameId(MBThread.class.getName()));
67 qPos.add(groupId);
68 qPos.add(userId);
69
70 Iterator<Long> itr = q.list().iterator();
71
72 if (itr.hasNext()) {
73 Long count = itr.next();
74
75 if (count != null) {
76 return count.intValue();
77 }
78 }
79
80 return 0;
81 }
82 catch (Exception e) {
83 throw new SystemException(e);
84 }
85 finally {
86 closeSession(session);
87 }
88 }
89
90 public List<MBThread> findByS_G_U(
91 long groupId, long userId, int start, int end)
92 throws SystemException {
93
94 Session session = null;
95
96 try {
97 session = openSession();
98
99 String sql = CustomSQLUtil.get(FIND_BY_S_G_U);
100
101 SQLQuery q = session.createSQLQuery(sql);
102
103 q.addEntity("MBThread", MBThreadImpl.class);
104
105 QueryPos qPos = QueryPos.getInstance(q);
106
107 qPos.add(PortalUtil.getClassNameId(MBThread.class.getName()));
108 qPos.add(groupId);
109 qPos.add(userId);
110
111 return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
112 }
113 catch (Exception e) {
114 throw new SystemException(e);
115 }
116 finally {
117 closeSession(session);
118 }
119 }
120
121 }