1
22
23 package com.liferay.portal.service.persistence;
24
25 import com.liferay.portal.SystemException;
26 import com.liferay.portal.model.Layout;
27 import com.liferay.portal.model.LayoutReference;
28 import com.liferay.portal.model.LayoutSoap;
29 import com.liferay.portal.spring.hibernate.CustomSQLUtil;
30 import com.liferay.portal.spring.hibernate.HibernateUtil;
31 import com.liferay.util.dao.hibernate.QueryPos;
32
33 import java.util.ArrayList;
34 import java.util.Iterator;
35 import java.util.List;
36
37 import org.hibernate.Hibernate;
38 import org.hibernate.SQLQuery;
39 import org.hibernate.Session;
40
41
47 public class LayoutFinder {
48
49 public static String FIND_BY_C_P_P =
50 LayoutFinder.class.getName() + ".findByC_P_P";
51
52 public static List findByC_P_P(
53 long companyId, String portletId, String prefsKey,
54 String prefsValue)
55 throws SystemException {
56
57 String prefs =
58 "%<preference><name>" + prefsKey + "</name><value>" + prefsValue +
59 "</value>%";
60
61 Session session = null;
62
63 try {
64 session = HibernateUtil.openSession();
65
66 String sql = CustomSQLUtil.get(FIND_BY_C_P_P);
67
68 SQLQuery q = session.createSQLQuery(sql);
69
70 q.addScalar("layoutPlid", Hibernate.LONG);
71 q.addScalar("prefsPortletId", Hibernate.STRING);
72
73 QueryPos qPos = QueryPos.getInstance(q);
74
75 qPos.add(companyId);
76 qPos.add(portletId);
77 qPos.add(portletId + "_INSTANCE_%");
78 qPos.add(prefs);
79
80 List list = new ArrayList();
81
82 Iterator itr = q.list().iterator();
83
84 while (itr.hasNext()) {
85 Object[] array = (Object[])itr.next();
86
87 Long layoutPlid = (Long)array[0];
88 String prefsPortletId = (String)array[1];
89
90 Layout layout = LayoutUtil.findByPrimaryKey(
91 layoutPlid.longValue());
92
93 list.add(
94 new LayoutReference(
95 LayoutSoap.toSoapModel(layout), prefsPortletId));
96 }
97
98 return list;
99 }
100 catch (Exception e) {
101 throw new SystemException(e);
102 }
103 finally {
104 HibernateUtil.closeSession(session);
105 }
106 }
107
108 }