1
19
20 package com.liferay.portal.service.persistence;
21
22 import com.liferay.portal.SystemException;
23 import com.liferay.portal.kernel.dao.orm.QueryPos;
24 import com.liferay.portal.kernel.dao.orm.SQLQuery;
25 import com.liferay.portal.kernel.dao.orm.Session;
26 import com.liferay.portal.kernel.dao.orm.Type;
27 import com.liferay.portal.model.Layout;
28 import com.liferay.portal.model.LayoutReference;
29 import com.liferay.portal.model.LayoutSoap;
30 import com.liferay.portal.model.impl.LayoutImpl;
31 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
32 import com.liferay.util.dao.orm.CustomSQLUtil;
33
34 import java.util.ArrayList;
35 import java.util.Iterator;
36 import java.util.List;
37
38
44 public class LayoutFinderImpl
45 extends BasePersistenceImpl implements LayoutFinder {
46
47 public static String FIND_BY_NULL_FRIENDLY_URL =
48 LayoutFinder.class.getName() + ".findByNullFriendlyURL";
49
50 public static String FIND_BY_C_P_P =
51 LayoutFinder.class.getName() + ".findByC_P_P";
52
53 public List<Layout> findByNullFriendlyURL() throws SystemException {
54 Session session = null;
55
56 try {
57 session = openSession();
58
59 String sql = CustomSQLUtil.get(FIND_BY_NULL_FRIENDLY_URL);
60
61 SQLQuery q = session.createSQLQuery(sql);
62
63 q.addEntity("Layout", LayoutImpl.class);
64
65 return q.list();
66 }
67 catch (Exception e) {
68 throw new SystemException(e);
69 }
70 finally {
71 closeSession(session);
72 }
73 }
74
75 public List<LayoutReference> findByC_P_P(
76 long companyId, String portletId, String prefsKey,
77 String prefsValue)
78 throws SystemException {
79
80 String prefs =
81 "%<preference><name>" + prefsKey + "</name><value>" + prefsValue +
82 "</value>%";
83
84 Session session = null;
85
86 try {
87 session = openSession();
88
89 String sql = CustomSQLUtil.get(FIND_BY_C_P_P);
90
91 SQLQuery q = session.createSQLQuery(sql);
92
93 q.addScalar("layoutPlid", Type.LONG);
94 q.addScalar("prefsPortletId", Type.STRING);
95
96 QueryPos qPos = QueryPos.getInstance(q);
97
98 qPos.add(companyId);
99 qPos.add(portletId);
100 qPos.add(portletId + "_INSTANCE_%");
101 qPos.add(prefs);
102
103 List<LayoutReference> layoutReferences =
104 new ArrayList<LayoutReference>();
105
106 Iterator<Object[]> itr = q.list().iterator();
107
108 while (itr.hasNext()) {
109 Object[] array = itr.next();
110
111 Long layoutPlid = (Long)array[0];
112 String prefsPortletId = (String)array[1];
113
114 Layout layout = LayoutUtil.findByPrimaryKey(
115 layoutPlid.longValue());
116
117 layoutReferences.add(
118 new LayoutReference(
119 LayoutSoap.toSoapModel(layout), prefsPortletId));
120 }
121
122 return layoutReferences;
123 }
124 catch (Exception e) {
125 throw new SystemException(e);
126 }
127 finally {
128 closeSession(session);
129 }
130 }
131
132 }