1
22
23 package com.liferay.portal.service.persistence;
24
25 import com.liferay.portal.kernel.util.GetterUtil;
26 import com.liferay.portal.kernel.util.Validator;
27 import com.liferay.portal.model.ModelListener;
28 import com.liferay.portal.util.PropsUtil;
29
30 import org.apache.commons.logging.Log;
31 import org.apache.commons.logging.LogFactory;
32
33
39 public class PortletUtil {
40 public static com.liferay.portal.model.Portlet create(long id) {
41 return getPersistence().create(id);
42 }
43
44 public static com.liferay.portal.model.Portlet remove(long id)
45 throws com.liferay.portal.SystemException,
46 com.liferay.portal.NoSuchPortletException {
47 ModelListener listener = _getListener();
48
49 if (listener != null) {
50 listener.onBeforeRemove(findByPrimaryKey(id));
51 }
52
53 com.liferay.portal.model.Portlet portlet = getPersistence().remove(id);
54
55 if (listener != null) {
56 listener.onAfterRemove(portlet);
57 }
58
59 return portlet;
60 }
61
62 public static com.liferay.portal.model.Portlet remove(
63 com.liferay.portal.model.Portlet portlet)
64 throws com.liferay.portal.SystemException {
65 ModelListener listener = _getListener();
66
67 if (listener != null) {
68 listener.onBeforeRemove(portlet);
69 }
70
71 portlet = getPersistence().remove(portlet);
72
73 if (listener != null) {
74 listener.onAfterRemove(portlet);
75 }
76
77 return portlet;
78 }
79
80 public static com.liferay.portal.model.Portlet update(
81 com.liferay.portal.model.Portlet portlet)
82 throws com.liferay.portal.SystemException {
83 ModelListener listener = _getListener();
84 boolean isNew = portlet.isNew();
85
86 if (listener != null) {
87 if (isNew) {
88 listener.onBeforeCreate(portlet);
89 }
90 else {
91 listener.onBeforeUpdate(portlet);
92 }
93 }
94
95 portlet = getPersistence().update(portlet);
96
97 if (listener != null) {
98 if (isNew) {
99 listener.onAfterCreate(portlet);
100 }
101 else {
102 listener.onAfterUpdate(portlet);
103 }
104 }
105
106 return portlet;
107 }
108
109 public static com.liferay.portal.model.Portlet update(
110 com.liferay.portal.model.Portlet portlet, boolean merge)
111 throws com.liferay.portal.SystemException {
112 ModelListener listener = _getListener();
113 boolean isNew = portlet.isNew();
114
115 if (listener != null) {
116 if (isNew) {
117 listener.onBeforeCreate(portlet);
118 }
119 else {
120 listener.onBeforeUpdate(portlet);
121 }
122 }
123
124 portlet = getPersistence().update(portlet, merge);
125
126 if (listener != null) {
127 if (isNew) {
128 listener.onAfterCreate(portlet);
129 }
130 else {
131 listener.onAfterUpdate(portlet);
132 }
133 }
134
135 return portlet;
136 }
137
138 public static com.liferay.portal.model.Portlet findByPrimaryKey(long id)
139 throws com.liferay.portal.SystemException,
140 com.liferay.portal.NoSuchPortletException {
141 return getPersistence().findByPrimaryKey(id);
142 }
143
144 public static com.liferay.portal.model.Portlet fetchByPrimaryKey(long id)
145 throws com.liferay.portal.SystemException {
146 return getPersistence().fetchByPrimaryKey(id);
147 }
148
149 public static java.util.List findByCompanyId(long companyId)
150 throws com.liferay.portal.SystemException {
151 return getPersistence().findByCompanyId(companyId);
152 }
153
154 public static java.util.List findByCompanyId(long companyId, int begin,
155 int end) throws com.liferay.portal.SystemException {
156 return getPersistence().findByCompanyId(companyId, begin, end);
157 }
158
159 public static java.util.List findByCompanyId(long companyId, int begin,
160 int end, com.liferay.portal.kernel.util.OrderByComparator obc)
161 throws com.liferay.portal.SystemException {
162 return getPersistence().findByCompanyId(companyId, begin, end, obc);
163 }
164
165 public static com.liferay.portal.model.Portlet findByCompanyId_First(
166 long companyId, com.liferay.portal.kernel.util.OrderByComparator obc)
167 throws com.liferay.portal.SystemException,
168 com.liferay.portal.NoSuchPortletException {
169 return getPersistence().findByCompanyId_First(companyId, obc);
170 }
171
172 public static com.liferay.portal.model.Portlet findByCompanyId_Last(
173 long companyId, com.liferay.portal.kernel.util.OrderByComparator obc)
174 throws com.liferay.portal.SystemException,
175 com.liferay.portal.NoSuchPortletException {
176 return getPersistence().findByCompanyId_Last(companyId, obc);
177 }
178
179 public static com.liferay.portal.model.Portlet[] findByCompanyId_PrevAndNext(
180 long id, long companyId,
181 com.liferay.portal.kernel.util.OrderByComparator obc)
182 throws com.liferay.portal.SystemException,
183 com.liferay.portal.NoSuchPortletException {
184 return getPersistence().findByCompanyId_PrevAndNext(id, companyId, obc);
185 }
186
187 public static com.liferay.portal.model.Portlet findByC_P(long companyId,
188 java.lang.String portletId)
189 throws com.liferay.portal.SystemException,
190 com.liferay.portal.NoSuchPortletException {
191 return getPersistence().findByC_P(companyId, portletId);
192 }
193
194 public static com.liferay.portal.model.Portlet fetchByC_P(long companyId,
195 java.lang.String portletId) throws com.liferay.portal.SystemException {
196 return getPersistence().fetchByC_P(companyId, portletId);
197 }
198
199 public static java.util.List findWithDynamicQuery(
200 com.liferay.portal.kernel.dao.DynamicQueryInitializer queryInitializer)
201 throws com.liferay.portal.SystemException {
202 return getPersistence().findWithDynamicQuery(queryInitializer);
203 }
204
205 public static java.util.List findWithDynamicQuery(
206 com.liferay.portal.kernel.dao.DynamicQueryInitializer queryInitializer,
207 int begin, int end) throws com.liferay.portal.SystemException {
208 return getPersistence().findWithDynamicQuery(queryInitializer, begin,
209 end);
210 }
211
212 public static java.util.List findAll()
213 throws com.liferay.portal.SystemException {
214 return getPersistence().findAll();
215 }
216
217 public static java.util.List findAll(int begin, int end)
218 throws com.liferay.portal.SystemException {
219 return getPersistence().findAll(begin, end);
220 }
221
222 public static java.util.List findAll(int begin, int end,
223 com.liferay.portal.kernel.util.OrderByComparator obc)
224 throws com.liferay.portal.SystemException {
225 return getPersistence().findAll(begin, end, obc);
226 }
227
228 public static void removeByCompanyId(long companyId)
229 throws com.liferay.portal.SystemException {
230 getPersistence().removeByCompanyId(companyId);
231 }
232
233 public static void removeByC_P(long companyId, java.lang.String portletId)
234 throws com.liferay.portal.SystemException,
235 com.liferay.portal.NoSuchPortletException {
236 getPersistence().removeByC_P(companyId, portletId);
237 }
238
239 public static void removeAll() throws com.liferay.portal.SystemException {
240 getPersistence().removeAll();
241 }
242
243 public static int countByCompanyId(long companyId)
244 throws com.liferay.portal.SystemException {
245 return getPersistence().countByCompanyId(companyId);
246 }
247
248 public static int countByC_P(long companyId, java.lang.String portletId)
249 throws com.liferay.portal.SystemException {
250 return getPersistence().countByC_P(companyId, portletId);
251 }
252
253 public static int countAll() throws com.liferay.portal.SystemException {
254 return getPersistence().countAll();
255 }
256
257 public static PortletPersistence getPersistence() {
258 return _getUtil()._persistence;
259 }
260
261 public void setPersistence(PortletPersistence persistence) {
262 _persistence = persistence;
263 }
264
265 private static PortletUtil _getUtil() {
266 if (_util == null) {
267 _util = (PortletUtil)com.liferay.portal.kernel.bean.BeanLocatorUtil.locate(_UTIL);
268 }
269
270 return _util;
271 }
272
273 private static ModelListener _getListener() {
274 if (Validator.isNotNull(_LISTENER)) {
275 try {
276 return (ModelListener)Class.forName(_LISTENER).newInstance();
277 }
278 catch (Exception e) {
279 _log.error(e);
280 }
281 }
282
283 return null;
284 }
285
286 private static final String _UTIL = PortletUtil.class.getName();
287 private static final String _LISTENER = GetterUtil.getString(PropsUtil.get(
288 "value.object.listener.com.liferay.portal.model.Portlet"));
289 private static Log _log = LogFactory.getLog(PortletUtil.class);
290 private static PortletUtil _util;
291 private PortletPersistence _persistence;
292 }