001
014
015 package com.liferay.portlet.tasks.service.persistence;
016
017 import com.liferay.portal.kernel.dao.orm.QueryPos;
018 import com.liferay.portal.kernel.dao.orm.QueryUtil;
019 import com.liferay.portal.kernel.dao.orm.SQLQuery;
020 import com.liferay.portal.kernel.dao.orm.Session;
021 import com.liferay.portal.kernel.dao.orm.Type;
022 import com.liferay.portal.kernel.exception.SystemException;
023 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
024 import com.liferay.portlet.tasks.model.TasksProposal;
025 import com.liferay.portlet.tasks.model.impl.TasksProposalImpl;
026 import com.liferay.util.dao.orm.CustomSQLUtil;
027
028 import java.util.Iterator;
029 import java.util.List;
030
031
034 public class TasksProposalFinderImpl
035 extends BasePersistenceImpl<TasksProposal> implements TasksProposalFinder {
036
037 public static String COUNT_BY_G_U =
038 TasksProposalFinder.class.getName() + ".countByG_U";
039
040 public static String FIND_BY_G_U =
041 TasksProposalFinder.class.getName() + ".findByG_U";
042
043 public int countByG_U(long groupId, long userId)
044 throws SystemException {
045
046 Session session = null;
047
048 try {
049 session = openSession();
050
051 String sql = CustomSQLUtil.get(COUNT_BY_G_U);
052
053 SQLQuery q = session.createSQLQuery(sql);
054
055 q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
056
057 QueryPos qPos = QueryPos.getInstance(q);
058
059 qPos.add(groupId);
060 qPos.add(userId);
061
062 Iterator<Long> itr = q.list().iterator();
063
064 if (itr.hasNext()) {
065 Long count = itr.next();
066
067 if (count != null) {
068 return count.intValue();
069 }
070 }
071
072 return 0;
073 }
074 catch (Exception e) {
075 throw new SystemException(e);
076 }
077 finally {
078 closeSession(session);
079 }
080 }
081
082 public List<TasksProposal> findByG_U(
083 long groupId, long userId, int start, int end)
084 throws SystemException {
085
086 Session session = null;
087
088 try {
089 session = openSession();
090
091 String sql = CustomSQLUtil.get(FIND_BY_G_U);
092
093 SQLQuery q = session.createSQLQuery(sql);
094
095 q.addEntity("TasksProposal", TasksProposalImpl.class);
096
097 QueryPos qPos = QueryPos.getInstance(q);
098
099 qPos.add(groupId);
100 qPos.add(userId);
101
102 return (List<TasksProposal>)QueryUtil.list(
103 q, getDialect(), start, end);
104 }
105 catch (Exception e) {
106 throw new SystemException(e);
107 }
108 finally {
109 closeSession(session);
110 }
111 }
112
113 }