1
19
20 package com.liferay.portlet.documentlibrary.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.documentlibrary.model.DLFileRank;
30 import com.liferay.portlet.documentlibrary.model.impl.DLFileRankImpl;
31 import com.liferay.util.dao.orm.CustomSQLUtil;
32
33 import java.util.Iterator;
34 import java.util.List;
35
36
42 public class DLFileRankFinderImpl
43 extends BasePersistenceImpl implements DLFileRankFinder {
44
45 public static String COUNT_BY_G_U =
46 DLFileRankFinder.class.getName() + ".countByG_U";
47
48 public static String FIND_BY_G_U =
49 DLFileRankFinder.class.getName() + ".findByG_U";
50
51 public int countByG_U(long groupId, long userId) throws SystemException {
52 Session session = null;
53
54 try {
55 session = openSession();
56
57 String sql = CustomSQLUtil.get(COUNT_BY_G_U);
58
59 SQLQuery q = session.createSQLQuery(sql);
60
61 q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
62
63 QueryPos qPos = QueryPos.getInstance(q);
64
65 qPos.add(groupId);
66 qPos.add(userId);
67
68 Iterator<Long> itr = q.list().iterator();
69
70 if (itr.hasNext()) {
71 Long count = itr.next();
72
73 if (count != null) {
74 return count.intValue();
75 }
76 }
77
78 return 0;
79 }
80 catch (Exception e) {
81 throw new SystemException(e);
82 }
83 finally {
84 closeSession(session);
85 }
86 }
87
88 public List<DLFileRank> findByG_U(long groupId, long userId)
89 throws SystemException {
90
91 return findByG_U(groupId, userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
92 }
93
94 public List<DLFileRank> findByG_U(
95 long groupId, long userId, int start, int end)
96 throws SystemException {
97
98 Session session = null;
99
100 try {
101 session = openSession();
102
103 String sql = CustomSQLUtil.get(FIND_BY_G_U);
104
105 SQLQuery q = session.createSQLQuery(sql);
106
107 q.addEntity("DLFileRank", DLFileRankImpl.class);
108
109 QueryPos qPos = QueryPos.getInstance(q);
110
111 qPos.add(groupId);
112 qPos.add(userId);
113
114 return (List<DLFileRank>)QueryUtil.list(
115 q, getDialect(), start, end);
116 }
117 catch (Exception e) {
118 throw new SystemException(e);
119 }
120 finally {
121 closeSession(session);
122 }
123 }
124
125 }