1
22
23 package com.liferay.portlet.polls.service.persistence;
24
25 import com.liferay.portal.SystemException;
26 import com.liferay.portal.kernel.util.StringMaker;
27 import com.liferay.portal.spring.hibernate.CustomSQLUtil;
28 import com.liferay.portal.spring.hibernate.HibernateUtil;
29 import com.liferay.portlet.polls.NoSuchChoiceException;
30 import com.liferay.portlet.polls.model.PollsChoice;
31 import com.liferay.portlet.polls.model.impl.PollsChoiceImpl;
32 import com.liferay.util.dao.hibernate.QueryPos;
33
34 import java.util.List;
35
36 import org.hibernate.SQLQuery;
37 import org.hibernate.Session;
38
39
45 public class PollsChoiceFinderImpl implements PollsChoiceFinder {
46
47 public static String FIND_BY_UUID_G =
48 PollsChoiceFinder.class.getName() + ".findByUuid_G";
49
50 public PollsChoice findByUuid_G(String uuid, long groupId)
51 throws NoSuchChoiceException, SystemException {
52
53 Session session = null;
54
55 try {
56 session = HibernateUtil.openSession();
57
58 String sql = CustomSQLUtil.get(FIND_BY_UUID_G);
59
60 SQLQuery q = session.createSQLQuery(sql);
61
62 q.addEntity("PollsChoice", PollsChoiceImpl.class);
63
64 QueryPos qPos = QueryPos.getInstance(q);
65
66 qPos.add(uuid);
67 qPos.add(groupId);
68
69 List<PollsChoice> list = q.list();
70
71 if (list.size() == 0) {
72 StringMaker sm = new StringMaker();
73
74 sm.append("No PollsChoice exists with the key {uuid=");
75 sm.append(uuid);
76 sm.append(", groupId=");
77 sm.append(groupId);
78 sm.append("}");
79
80 throw new NoSuchChoiceException(sm.toString());
81 }
82 else {
83 return list.get(0);
84 }
85 }
86 catch (NoSuchChoiceException nsce) {
87 throw nsce;
88 }
89 catch (Exception e) {
90 throw new SystemException(e);
91 }
92 finally {
93 HibernateUtil.closeSession(session);
94 }
95 }
96
97 }