1
14
15 package com.liferay.portlet.tasks.service.persistence;
16
17 import com.liferay.portal.kernel.dao.orm.QueryPos;
18 import com.liferay.portal.kernel.dao.orm.QueryUtil;
19 import com.liferay.portal.kernel.dao.orm.SQLQuery;
20 import com.liferay.portal.kernel.dao.orm.Session;
21 import com.liferay.portal.kernel.dao.orm.Type;
22 import com.liferay.portal.kernel.exception.SystemException;
23 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
24 import com.liferay.portlet.tasks.model.TasksProposal;
25 import com.liferay.portlet.tasks.model.impl.TasksProposalImpl;
26 import com.liferay.util.dao.orm.CustomSQLUtil;
27
28 import java.util.Iterator;
29 import java.util.List;
30
31
36 public class TasksProposalFinderImpl
37 extends BasePersistenceImpl<TasksProposal> implements TasksProposalFinder {
38
39 public static String COUNT_BY_G_U =
40 TasksProposalFinder.class.getName() + ".countByG_U";
41
42 public static String FIND_BY_G_U =
43 TasksProposalFinder.class.getName() + ".findByG_U";
44
45 public int countByG_U(long groupId, long userId)
46 throws SystemException {
47
48 Session session = null;
49
50 try {
51 session = openSession();
52
53 String sql = CustomSQLUtil.get(COUNT_BY_G_U);
54
55 SQLQuery q = session.createSQLQuery(sql);
56
57 q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
58
59 QueryPos qPos = QueryPos.getInstance(q);
60
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<TasksProposal> findByG_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_G_U);
94
95 SQLQuery q = session.createSQLQuery(sql);
96
97 q.addEntity("TasksProposal", TasksProposalImpl.class);
98
99 QueryPos qPos = QueryPos.getInstance(q);
100
101 qPos.add(groupId);
102 qPos.add(userId);
103
104 return (List<TasksProposal>)QueryUtil.list(
105 q, getDialect(), start, end);
106 }
107 catch (Exception e) {
108 throw new SystemException(e);
109 }
110 finally {
111 closeSession(session);
112 }
113 }
114
115 }