001
014
015 package com.liferay.portlet.polls.service.persistence;
016
017 import com.liferay.portal.kernel.dao.orm.QueryPos;
018 import com.liferay.portal.kernel.dao.orm.SQLQuery;
019 import com.liferay.portal.kernel.dao.orm.Session;
020 import com.liferay.portal.kernel.exception.SystemException;
021 import com.liferay.portal.kernel.util.StringBundler;
022 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
023 import com.liferay.portlet.polls.NoSuchChoiceException;
024 import com.liferay.portlet.polls.model.PollsChoice;
025 import com.liferay.portlet.polls.model.impl.PollsChoiceImpl;
026 import com.liferay.util.dao.orm.CustomSQLUtil;
027
028 import java.util.List;
029
030
033 public class PollsChoiceFinderImpl
034 extends BasePersistenceImpl<PollsChoice> implements PollsChoiceFinder {
035
036 public static final String FIND_BY_UUID_G =
037 PollsChoiceFinder.class.getName() + ".findByUUID_G";
038
039 @Override
040 public PollsChoice fetchByUUID_G(String uuid, long groupId)
041 throws SystemException {
042
043 Session session = null;
044
045 try {
046 session = openSession();
047
048 String sql = CustomSQLUtil.get(FIND_BY_UUID_G);
049
050 SQLQuery q = session.createSQLQuery(sql);
051
052 q.addEntity("PollsChoice", PollsChoiceImpl.class);
053
054 QueryPos qPos = QueryPos.getInstance(q);
055
056 qPos.add(uuid);
057 qPos.add(groupId);
058
059 List<PollsChoice> choices = q.list();
060
061 if (!choices.isEmpty()) {
062 return choices.get(0);
063 }
064
065 return null;
066 }
067 catch (Exception e) {
068 throw new SystemException(e);
069 }
070 finally {
071 closeSession(session);
072 }
073 }
074
075 @Override
076 public PollsChoice findByUUID_G(String uuid, long groupId)
077 throws NoSuchChoiceException, SystemException {
078
079 PollsChoice choice = fetchByUUID_G(uuid, groupId);
080
081 if (choice != null) {
082 return choice;
083 }
084
085 StringBundler sb = new StringBundler(5);
086
087 sb.append("No PollsChoice exists with the key {uuid=");
088 sb.append(uuid);
089 sb.append(", groupId=");
090 sb.append(groupId);
091 sb.append("}");
092
093 throw new NoSuchChoiceException(sb.toString());
094 }
095
096 }