001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portal.service.persistence;
022:
023: import com.liferay.portal.SystemException;
024: import com.liferay.portal.model.impl.ResourceImpl;
025: import com.liferay.portal.spring.hibernate.CustomSQLUtil;
026: import com.liferay.portal.spring.hibernate.HibernateUtil;
027: import com.liferay.util.dao.hibernate.QueryPos;
028:
029: import java.util.List;
030:
031: import org.hibernate.SQLQuery;
032: import org.hibernate.Session;
033:
034: /**
035: * <a href="ResourceFinderImpl.java.html"><b><i>View Source</i></b></a>
036: *
037: * @author Brian Wing Shun Chan
038: * @author Alexander Chow
039: *
040: */
041: public class ResourceFinderImpl implements ResourceFinder {
042:
043: public static String FIND_BY_NAME = ResourceFinder.class.getName()
044: + ".findByName";
045:
046: public static String FIND_BY_C_P = ResourceFinder.class.getName()
047: + ".findByC_P";
048:
049: public List findByName(String name) throws SystemException {
050: Session session = null;
051:
052: try {
053: session = HibernateUtil.openSession();
054:
055: String sql = CustomSQLUtil.get(FIND_BY_NAME);
056:
057: SQLQuery q = session.createSQLQuery(sql);
058:
059: q.addEntity("Resource_", ResourceImpl.class);
060:
061: QueryPos qPos = QueryPos.getInstance(q);
062:
063: qPos.add(name);
064:
065: return q.list();
066: } catch (Exception e) {
067: throw new SystemException(e);
068: } finally {
069: HibernateUtil.closeSession(session);
070: }
071: }
072:
073: public List findByC_P(long companyId, String primKey)
074: throws SystemException {
075:
076: Session session = null;
077:
078: try {
079: session = HibernateUtil.openSession();
080:
081: String sql = CustomSQLUtil.get(FIND_BY_C_P);
082:
083: SQLQuery q = session.createSQLQuery(sql);
084:
085: q.addEntity("Resource_", ResourceImpl.class);
086:
087: QueryPos qPos = QueryPos.getInstance(q);
088:
089: qPos.add(companyId);
090: qPos.add(primKey);
091:
092: return q.list();
093: } catch (Exception e) {
094: throw new SystemException(e);
095: } finally {
096: HibernateUtil.closeSession(session);
097: }
098: }
099:
100: }
|