1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portlet.polls.service.persistence;
16  
17  import com.liferay.portal.kernel.dao.orm.QueryPos;
18  import com.liferay.portal.kernel.dao.orm.SQLQuery;
19  import com.liferay.portal.kernel.dao.orm.Session;
20  import com.liferay.portal.kernel.exception.SystemException;
21  import com.liferay.portal.kernel.util.StringBundler;
22  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
23  import com.liferay.portlet.polls.NoSuchChoiceException;
24  import com.liferay.portlet.polls.model.PollsChoice;
25  import com.liferay.portlet.polls.model.impl.PollsChoiceImpl;
26  import com.liferay.util.dao.orm.CustomSQLUtil;
27  
28  import java.util.List;
29  
30  /**
31   * <a href="PollsChoiceFinderImpl.java.html"><b><i>View Source</i></b></a>
32   *
33   * @author Bruno Farache
34   */
35  public class PollsChoiceFinderImpl
36      extends BasePersistenceImpl<PollsChoice> implements PollsChoiceFinder {
37  
38      public static String FIND_BY_UUID_G =
39          PollsChoiceFinder.class.getName() + ".findByUuid_G";
40  
41      public PollsChoice findByUuid_G(String uuid, long groupId)
42          throws NoSuchChoiceException, SystemException {
43  
44          Session session = null;
45  
46          try {
47              session = openSession();
48  
49              String sql = CustomSQLUtil.get(FIND_BY_UUID_G);
50  
51              SQLQuery q = session.createSQLQuery(sql);
52  
53              q.addEntity("PollsChoice", PollsChoiceImpl.class);
54  
55              QueryPos qPos = QueryPos.getInstance(q);
56  
57              qPos.add(uuid);
58              qPos.add(groupId);
59  
60              List<PollsChoice> list = q.list();
61  
62              if (list.size() == 0) {
63                  StringBundler sb = new StringBundler(5);
64  
65                  sb.append("No PollsChoice exists with the key {uuid=");
66                  sb.append(uuid);
67                  sb.append(", groupId=");
68                  sb.append(groupId);
69                  sb.append("}");
70  
71                  throw new NoSuchChoiceException(sb.toString());
72              }
73              else {
74                  return list.get(0);
75              }
76          }
77          catch (NoSuchChoiceException nsce) {
78              throw nsce;
79          }
80          catch (Exception e) {
81              throw new SystemException(e);
82          }
83          finally {
84              closeSession(session);
85          }
86      }
87  
88  }