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.portlet.messageboards.model.MBMessage;
30 import com.liferay.portlet.messageboards.model.impl.MBMessageImpl;
31 import com.liferay.util.dao.orm.CustomSQLUtil;
32
33 import java.util.Iterator;
34 import java.util.List;
35
36
42 public class MBMessageFinderImpl
43 extends BasePersistenceImpl implements MBMessageFinder {
44
45 public static String COUNT_BY_G_U =
46 MBMessageFinder.class.getName() + ".countByG_U";
47
48 public static String COUNT_BY_G_U_A =
49 MBMessageFinder.class.getName() + ".countByG_U_A";
50
51 public static String FIND_BY_NO_ASSETS =
52 MBMessageFinder.class.getName() + ".findByNoAssets";
53
54 public static String FIND_BY_G_U =
55 MBMessageFinder.class.getName() + ".findByG_U";
56
57 public static String FIND_BY_G_U_A =
58 MBMessageFinder.class.getName() + ".findByG_U_A";
59
60 public int countByG_U(long groupId, long userId) throws SystemException {
61 Session session = null;
62
63 try {
64 session = openSession();
65
66 String sql = CustomSQLUtil.get(COUNT_BY_G_U);
67
68 SQLQuery q = session.createSQLQuery(sql);
69
70 q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
71
72 QueryPos qPos = QueryPos.getInstance(q);
73
74 qPos.add(groupId);
75 qPos.add(userId);
76
77 Iterator<Long> itr = q.list().iterator();
78
79 if (itr.hasNext()) {
80 Long count = itr.next();
81
82 if (count != null) {
83 return count.intValue();
84 }
85 }
86
87 return 0;
88 }
89 catch (Exception e) {
90 throw new SystemException(e);
91 }
92 finally {
93 closeSession(session);
94 }
95 }
96
97 public int countByG_U_A(
98 long groupId, long userId, boolean anonymous)
99 throws SystemException {
100
101 Session session = null;
102
103 try {
104 session = openSession();
105
106 String sql = CustomSQLUtil.get(COUNT_BY_G_U_A);
107
108 SQLQuery q = session.createSQLQuery(sql);
109
110 q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
111
112 QueryPos qPos = QueryPos.getInstance(q);
113
114 qPos.add(groupId);
115 qPos.add(userId);
116 qPos.add(anonymous);
117
118 Iterator<Long> itr = q.list().iterator();
119
120 if (itr.hasNext()) {
121 Long count = itr.next();
122
123 if (count != null) {
124 return count.intValue();
125 }
126 }
127
128 return 0;
129 }
130 catch (Exception e) {
131 throw new SystemException(e);
132 }
133 finally {
134 closeSession(session);
135 }
136 }
137
138 public List<MBMessage> findByNoAssets() throws SystemException {
139 Session session = null;
140
141 try {
142 session = openSession();
143
144 String sql = CustomSQLUtil.get(FIND_BY_NO_ASSETS);
145
146 SQLQuery q = session.createSQLQuery(sql);
147
148 q.addEntity("MBMessage", MBMessageImpl.class);
149
150 return q.list();
151 }
152 catch (Exception e) {
153 throw new SystemException(e);
154 }
155 finally {
156 closeSession(session);
157 }
158 }
159
160 public List<Long> findByG_U(
161 long groupId, long userId, int start, int end)
162 throws SystemException {
163
164 Session session = null;
165
166 try {
167 session = openSession();
168
169 String sql = CustomSQLUtil.get(FIND_BY_G_U);
170
171 SQLQuery q = session.createSQLQuery(sql);
172
173 q.addScalar("threadId", Type.LONG);
174
175 QueryPos qPos = QueryPos.getInstance(q);
176
177 qPos.add(groupId);
178 qPos.add(userId);
179
180 return (List<Long>)QueryUtil.list(q, getDialect(), start, end);
181 }
182 catch (Exception e) {
183 throw new SystemException(e);
184 }
185 finally {
186 closeSession(session);
187 }
188 }
189
190 public List<Long> findByG_U_A(
191 long groupId, long userId, boolean anonymous, int start, int end)
192 throws SystemException {
193
194 Session session = null;
195
196 try {
197 session = openSession();
198
199 String sql = CustomSQLUtil.get(FIND_BY_G_U_A);
200
201 SQLQuery q = session.createSQLQuery(sql);
202
203 q.addScalar("threadId", Type.LONG);
204
205 QueryPos qPos = QueryPos.getInstance(q);
206
207 qPos.add(groupId);
208 qPos.add(userId);
209 qPos.add(anonymous);
210
211 return (List<Long>)QueryUtil.list(q, getDialect(), start, end);
212 }
213 catch (Exception e) {
214 throw new SystemException(e);
215 }
216 finally {
217 closeSession(session);
218 }
219 }
220
221 }