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.Layout;
025: import com.liferay.portal.model.LayoutReference;
026: import com.liferay.portal.model.LayoutSoap;
027: import com.liferay.portal.spring.hibernate.CustomSQLUtil;
028: import com.liferay.portal.spring.hibernate.HibernateUtil;
029: import com.liferay.util.dao.hibernate.QueryPos;
030:
031: import java.util.ArrayList;
032: import java.util.Iterator;
033: import java.util.List;
034:
035: import org.hibernate.Hibernate;
036: import org.hibernate.SQLQuery;
037: import org.hibernate.Session;
038:
039: /**
040: * <a href="LayoutFinderImpl.java.html"><b><i>View Source</i></b></a>
041: *
042: * @author Brian Wing Shun Chan
043: *
044: */
045: public class LayoutFinderImpl implements LayoutFinder {
046:
047: public static String FIND_BY_C_P_P = LayoutFinder.class.getName()
048: + ".findByC_P_P";
049:
050: public List findByC_P_P(long companyId, String portletId,
051: String prefsKey, String prefsValue) throws SystemException {
052:
053: String prefs = "%<preference><name>" + prefsKey
054: + "</name><value>" + prefsValue + "</value>%";
055:
056: Session session = null;
057:
058: try {
059: session = HibernateUtil.openSession();
060:
061: String sql = CustomSQLUtil.get(FIND_BY_C_P_P);
062:
063: SQLQuery q = session.createSQLQuery(sql);
064:
065: q.addScalar("layoutPlid", Hibernate.LONG);
066: q.addScalar("prefsPortletId", Hibernate.STRING);
067:
068: QueryPos qPos = QueryPos.getInstance(q);
069:
070: qPos.add(companyId);
071: qPos.add(portletId);
072: qPos.add(portletId + "_INSTANCE_%");
073: qPos.add(prefs);
074:
075: List list = new ArrayList();
076:
077: Iterator itr = q.list().iterator();
078:
079: while (itr.hasNext()) {
080: Object[] array = (Object[]) itr.next();
081:
082: Long layoutPlid = (Long) array[0];
083: String prefsPortletId = (String) array[1];
084:
085: Layout layout = LayoutUtil.findByPrimaryKey(layoutPlid
086: .longValue());
087:
088: list.add(new LayoutReference(LayoutSoap
089: .toSoapModel(layout), prefsPortletId));
090: }
091:
092: return list;
093: } catch (Exception e) {
094: throw new SystemException(e);
095: } finally {
096: HibernateUtil.closeSession(session);
097: }
098: }
099:
100: }
|