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
47 public class LayoutFinderImpl
48 extends BasePersistenceImpl implements LayoutFinder {
49
50 public static String FIND_BY_NULL_FRIENDLY_URL =
51 LayoutFinder.class.getName() + ".findByNullFriendlyURL";
52
53 public static String FIND_BY_C_P_P =
54 LayoutFinder.class.getName() + ".findByC_P_P";
55
56 public List<Layout> findByNullFriendlyURL() throws SystemException {
57 Session session = null;
58
59 try {
60 session = openSession();
61
62 String sql = CustomSQLUtil.get(FIND_BY_NULL_FRIENDLY_URL);
63
64 SQLQuery q = session.createSQLQuery(sql);
65
66 q.addEntity("Layout", LayoutImpl.class);
67
68 return q.list();
69 }
70 catch (Exception e) {
71 throw new SystemException(e);
72 }
73 finally {
74 closeSession(session);
75 }
76 }
77
78 public List<LayoutReference> findByC_P_P(
79 long companyId, String portletId, String preferencesKey,
80 String preferencesValue)
81 throws SystemException {
82
83 String preferences =
84 "%<preference><name>" + preferencesKey + "</name><value>" +
85 preferencesValue + "</value>%";
86
87 Session session = null;
88
89 try {
90 session = openSession();
91
92 String sql = CustomSQLUtil.get(FIND_BY_C_P_P);
93
94 SQLQuery q = session.createSQLQuery(sql);
95
96 q.addScalar("layoutPlid", Type.LONG);
97 q.addScalar("preferencesPortletId", Type.STRING);
98
99 QueryPos qPos = QueryPos.getInstance(q);
100
101 qPos.add(companyId);
102 qPos.add(portletId);
103 qPos.add(portletId + "_INSTANCE_%");
104 qPos.add(preferences);
105
106 List<LayoutReference> layoutReferences =
107 new ArrayList<LayoutReference>();
108
109 Iterator<Object[]> itr = q.list().iterator();
110
111 while (itr.hasNext()) {
112 Object[] array = itr.next();
113
114 Long layoutPlid = (Long)array[0];
115 String preferencesPortletId = (String)array[1];
116
117 Layout layout = LayoutUtil.findByPrimaryKey(
118 layoutPlid.longValue());
119
120 layoutReferences.add(
121 new LayoutReference(
122 LayoutSoap.toSoapModel(layout), preferencesPortletId));
123 }
124
125 return layoutReferences;
126 }
127 catch (Exception e) {
128 throw new SystemException(e);
129 }
130 finally {
131 closeSession(session);
132 }
133 }
134
135 }