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.portal.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.model.Resource;
22  import com.liferay.portal.model.impl.ResourceImpl;
23  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
24  import com.liferay.util.dao.orm.CustomSQLUtil;
25  
26  import java.util.List;
27  
28  /**
29   * <a href="ResourceFinderImpl.java.html"><b><i>View Source</i></b></a>
30   *
31   * @author Brian Wing Shun Chan
32   * @author Alexander Chow
33   */
34  public class ResourceFinderImpl
35      extends BasePersistenceImpl<Resource> implements ResourceFinder {
36  
37      public static String FIND_BY_NAME =
38          ResourceFinder.class.getName() + ".findByName";
39  
40      public static String FIND_BY_C_P =
41          ResourceFinder.class.getName() + ".findByC_P";
42  
43      public List<Resource> findByName(String name) throws SystemException {
44          Session session = null;
45  
46          try {
47              session = openSession();
48  
49              String sql = CustomSQLUtil.get(FIND_BY_NAME);
50  
51              SQLQuery q = session.createSQLQuery(sql);
52  
53              q.addEntity("Resource_", ResourceImpl.class);
54  
55              QueryPos qPos = QueryPos.getInstance(q);
56  
57              qPos.add(name);
58  
59              return q.list();
60          }
61          catch (Exception e) {
62              throw new SystemException(e);
63          }
64          finally {
65              closeSession(session);
66          }
67      }
68  
69      public List<Resource> findByC_P(long companyId, String primKey)
70          throws SystemException {
71  
72          Session session = null;
73  
74          try {
75              session = openSession();
76  
77              String sql = CustomSQLUtil.get(FIND_BY_C_P);
78  
79              SQLQuery q = session.createSQLQuery(sql);
80  
81              q.addEntity("Resource_", ResourceImpl.class);
82  
83              QueryPos qPos = QueryPos.getInstance(q);
84  
85              qPos.add(companyId);
86              qPos.add(primKey);
87  
88              return q.list();
89          }
90          catch (Exception e) {
91              throw new SystemException(e);
92          }
93          finally {
94              closeSession(session);
95          }
96      }
97  
98  }