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