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