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.ratings.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.StringUtil;
22  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
23  import com.liferay.portlet.ratings.model.RatingsEntry;
24  import com.liferay.portlet.ratings.model.impl.RatingsEntryImpl;
25  import com.liferay.util.dao.orm.CustomSQLUtil;
26  
27  import java.util.List;
28  
29  /**
30   * <a href="RatingsEntryFinderImpl.java.html"><b><i>View Source</i></b></a>
31   *
32   * @author Shuyang Zhou
33   */
34  public class RatingsEntryFinderImpl extends BasePersistenceImpl<RatingsEntry>
35          implements RatingsEntryFinder {
36  
37      public static String FIND_BY_U_C_C =
38          RatingsEntryFinder.class.getName() + ".findByU_C_C";
39  
40      public List<RatingsEntry> findByU_C_C(
41              long userId, long classNameId, List<Long> classPKs)
42          throws SystemException {
43  
44          Session session = null;
45  
46          try {
47              session = openSession();
48  
49              String sql = CustomSQLUtil.get(FIND_BY_U_C_C);
50  
51              sql = StringUtil.replace(
52                  sql, "[$CLASS_PKS$]", StringUtil.merge(classPKs));
53  
54              SQLQuery q = session.createSQLQuery(sql);
55  
56              q.addEntity("RatingsEntry", RatingsEntryImpl.class);
57  
58              QueryPos qPos = QueryPos.getInstance(q);
59  
60              qPos.add(userId);
61              qPos.add(classNameId);
62  
63              return q.list();
64          }
65          catch (Exception e) {
66              throw new SystemException(e);
67          }
68          finally {
69              closeSession(session);
70          }
71      }
72  
73  }