001
014
015 package com.liferay.portal.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
018 import com.liferay.portal.NoSuchPortletPreferencesException;
019 import com.liferay.portal.kernel.annotation.BeanReference;
020 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
021 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
023 import com.liferay.portal.kernel.dao.orm.FinderPath;
024 import com.liferay.portal.kernel.dao.orm.Query;
025 import com.liferay.portal.kernel.dao.orm.QueryPos;
026 import com.liferay.portal.kernel.dao.orm.QueryUtil;
027 import com.liferay.portal.kernel.dao.orm.Session;
028 import com.liferay.portal.kernel.exception.SystemException;
029 import com.liferay.portal.kernel.log.Log;
030 import com.liferay.portal.kernel.log.LogFactoryUtil;
031 import com.liferay.portal.kernel.util.GetterUtil;
032 import com.liferay.portal.kernel.util.InstanceFactory;
033 import com.liferay.portal.kernel.util.OrderByComparator;
034 import com.liferay.portal.kernel.util.StringBundler;
035 import com.liferay.portal.kernel.util.StringPool;
036 import com.liferay.portal.kernel.util.StringUtil;
037 import com.liferay.portal.kernel.util.Validator;
038 import com.liferay.portal.model.ModelListener;
039 import com.liferay.portal.model.PortletPreferences;
040 import com.liferay.portal.model.impl.PortletPreferencesImpl;
041 import com.liferay.portal.model.impl.PortletPreferencesModelImpl;
042 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
043
044 import java.io.Serializable;
045
046 import java.util.ArrayList;
047 import java.util.Collections;
048 import java.util.List;
049
050
056 public class PortletPreferencesPersistenceImpl extends BasePersistenceImpl<PortletPreferences>
057 implements PortletPreferencesPersistence {
058 public static final String FINDER_CLASS_NAME_ENTITY = PortletPreferencesImpl.class.getName();
059 public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
060 ".List";
061 public static final FinderPath FINDER_PATH_FIND_BY_PLID = new FinderPath(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
062 PortletPreferencesModelImpl.FINDER_CACHE_ENABLED,
063 FINDER_CLASS_NAME_LIST, "findByPlid",
064 new String[] {
065 Long.class.getName(),
066
067 "java.lang.Integer", "java.lang.Integer",
068 "com.liferay.portal.kernel.util.OrderByComparator"
069 });
070 public static final FinderPath FINDER_PATH_COUNT_BY_PLID = new FinderPath(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
071 PortletPreferencesModelImpl.FINDER_CACHE_ENABLED,
072 FINDER_CLASS_NAME_LIST, "countByPlid",
073 new String[] { Long.class.getName() });
074 public static final FinderPath FINDER_PATH_FIND_BY_P_P = new FinderPath(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
075 PortletPreferencesModelImpl.FINDER_CACHE_ENABLED,
076 FINDER_CLASS_NAME_LIST, "findByP_P",
077 new String[] {
078 Long.class.getName(), String.class.getName(),
079
080 "java.lang.Integer", "java.lang.Integer",
081 "com.liferay.portal.kernel.util.OrderByComparator"
082 });
083 public static final FinderPath FINDER_PATH_COUNT_BY_P_P = new FinderPath(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
084 PortletPreferencesModelImpl.FINDER_CACHE_ENABLED,
085 FINDER_CLASS_NAME_LIST, "countByP_P",
086 new String[] { Long.class.getName(), String.class.getName() });
087 public static final FinderPath FINDER_PATH_FIND_BY_O_O_P = new FinderPath(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
088 PortletPreferencesModelImpl.FINDER_CACHE_ENABLED,
089 FINDER_CLASS_NAME_LIST, "findByO_O_P",
090 new String[] {
091 Long.class.getName(), Integer.class.getName(),
092 Long.class.getName(),
093
094 "java.lang.Integer", "java.lang.Integer",
095 "com.liferay.portal.kernel.util.OrderByComparator"
096 });
097 public static final FinderPath FINDER_PATH_COUNT_BY_O_O_P = new FinderPath(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
098 PortletPreferencesModelImpl.FINDER_CACHE_ENABLED,
099 FINDER_CLASS_NAME_LIST, "countByO_O_P",
100 new String[] {
101 Long.class.getName(), Integer.class.getName(),
102 Long.class.getName()
103 });
104 public static final FinderPath FINDER_PATH_FETCH_BY_O_O_P_P = new FinderPath(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
105 PortletPreferencesModelImpl.FINDER_CACHE_ENABLED,
106 FINDER_CLASS_NAME_ENTITY, "fetchByO_O_P_P",
107 new String[] {
108 Long.class.getName(), Integer.class.getName(),
109 Long.class.getName(), String.class.getName()
110 });
111 public static final FinderPath FINDER_PATH_COUNT_BY_O_O_P_P = new FinderPath(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
112 PortletPreferencesModelImpl.FINDER_CACHE_ENABLED,
113 FINDER_CLASS_NAME_LIST, "countByO_O_P_P",
114 new String[] {
115 Long.class.getName(), Integer.class.getName(),
116 Long.class.getName(), String.class.getName()
117 });
118 public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
119 PortletPreferencesModelImpl.FINDER_CACHE_ENABLED,
120 FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
121 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
122 PortletPreferencesModelImpl.FINDER_CACHE_ENABLED,
123 FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
124
125 public void cacheResult(PortletPreferences portletPreferences) {
126 EntityCacheUtil.putResult(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
127 PortletPreferencesImpl.class, portletPreferences.getPrimaryKey(),
128 portletPreferences);
129
130 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_O_O_P_P,
131 new Object[] {
132 new Long(portletPreferences.getOwnerId()),
133 new Integer(portletPreferences.getOwnerType()),
134 new Long(portletPreferences.getPlid()),
135
136 portletPreferences.getPortletId()
137 }, portletPreferences);
138 }
139
140 public void cacheResult(List<PortletPreferences> portletPreferenceses) {
141 for (PortletPreferences portletPreferences : portletPreferenceses) {
142 if (EntityCacheUtil.getResult(
143 PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
144 PortletPreferencesImpl.class,
145 portletPreferences.getPrimaryKey(), this) == null) {
146 cacheResult(portletPreferences);
147 }
148 }
149 }
150
151 public void clearCache() {
152 CacheRegistryUtil.clear(PortletPreferencesImpl.class.getName());
153 EntityCacheUtil.clearCache(PortletPreferencesImpl.class.getName());
154 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
155 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
156 }
157
158 public void clearCache(PortletPreferences portletPreferences) {
159 EntityCacheUtil.removeResult(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
160 PortletPreferencesImpl.class, portletPreferences.getPrimaryKey());
161
162 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_O_O_P_P,
163 new Object[] {
164 new Long(portletPreferences.getOwnerId()),
165 new Integer(portletPreferences.getOwnerType()),
166 new Long(portletPreferences.getPlid()),
167
168 portletPreferences.getPortletId()
169 });
170 }
171
172 public PortletPreferences create(long portletPreferencesId) {
173 PortletPreferences portletPreferences = new PortletPreferencesImpl();
174
175 portletPreferences.setNew(true);
176 portletPreferences.setPrimaryKey(portletPreferencesId);
177
178 return portletPreferences;
179 }
180
181 public PortletPreferences remove(Serializable primaryKey)
182 throws NoSuchModelException, SystemException {
183 return remove(((Long)primaryKey).longValue());
184 }
185
186 public PortletPreferences remove(long portletPreferencesId)
187 throws NoSuchPortletPreferencesException, SystemException {
188 Session session = null;
189
190 try {
191 session = openSession();
192
193 PortletPreferences portletPreferences = (PortletPreferences)session.get(PortletPreferencesImpl.class,
194 new Long(portletPreferencesId));
195
196 if (portletPreferences == null) {
197 if (_log.isWarnEnabled()) {
198 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
199 portletPreferencesId);
200 }
201
202 throw new NoSuchPortletPreferencesException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
203 portletPreferencesId);
204 }
205
206 return remove(portletPreferences);
207 }
208 catch (NoSuchPortletPreferencesException nsee) {
209 throw nsee;
210 }
211 catch (Exception e) {
212 throw processException(e);
213 }
214 finally {
215 closeSession(session);
216 }
217 }
218
219 protected PortletPreferences removeImpl(
220 PortletPreferences portletPreferences) throws SystemException {
221 portletPreferences = toUnwrappedModel(portletPreferences);
222
223 Session session = null;
224
225 try {
226 session = openSession();
227
228 if (portletPreferences.isCachedModel() ||
229 BatchSessionUtil.isEnabled()) {
230 Object staleObject = session.get(PortletPreferencesImpl.class,
231 portletPreferences.getPrimaryKeyObj());
232
233 if (staleObject != null) {
234 session.evict(staleObject);
235 }
236 }
237
238 session.delete(portletPreferences);
239
240 session.flush();
241 }
242 catch (Exception e) {
243 throw processException(e);
244 }
245 finally {
246 closeSession(session);
247 }
248
249 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
250
251 PortletPreferencesModelImpl portletPreferencesModelImpl = (PortletPreferencesModelImpl)portletPreferences;
252
253 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_O_O_P_P,
254 new Object[] {
255 new Long(portletPreferencesModelImpl.getOriginalOwnerId()),
256 new Integer(portletPreferencesModelImpl.getOriginalOwnerType()),
257 new Long(portletPreferencesModelImpl.getOriginalPlid()),
258
259 portletPreferencesModelImpl.getOriginalPortletId()
260 });
261
262 EntityCacheUtil.removeResult(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
263 PortletPreferencesImpl.class, portletPreferences.getPrimaryKey());
264
265 return portletPreferences;
266 }
267
268 public PortletPreferences updateImpl(
269 com.liferay.portal.model.PortletPreferences portletPreferences,
270 boolean merge) throws SystemException {
271 portletPreferences = toUnwrappedModel(portletPreferences);
272
273 boolean isNew = portletPreferences.isNew();
274
275 PortletPreferencesModelImpl portletPreferencesModelImpl = (PortletPreferencesModelImpl)portletPreferences;
276
277 Session session = null;
278
279 try {
280 session = openSession();
281
282 BatchSessionUtil.update(session, portletPreferences, merge);
283
284 portletPreferences.setNew(false);
285 }
286 catch (Exception e) {
287 throw processException(e);
288 }
289 finally {
290 closeSession(session);
291 }
292
293 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
294
295 EntityCacheUtil.putResult(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
296 PortletPreferencesImpl.class, portletPreferences.getPrimaryKey(),
297 portletPreferences);
298
299 if (!isNew &&
300 ((portletPreferences.getOwnerId() != portletPreferencesModelImpl.getOriginalOwnerId()) ||
301 (portletPreferences.getOwnerType() != portletPreferencesModelImpl.getOriginalOwnerType()) ||
302 (portletPreferences.getPlid() != portletPreferencesModelImpl.getOriginalPlid()) ||
303 !Validator.equals(portletPreferences.getPortletId(),
304 portletPreferencesModelImpl.getOriginalPortletId()))) {
305 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_O_O_P_P,
306 new Object[] {
307 new Long(portletPreferencesModelImpl.getOriginalOwnerId()),
308 new Integer(portletPreferencesModelImpl.getOriginalOwnerType()),
309 new Long(portletPreferencesModelImpl.getOriginalPlid()),
310
311 portletPreferencesModelImpl.getOriginalPortletId()
312 });
313 }
314
315 if (isNew ||
316 ((portletPreferences.getOwnerId() != portletPreferencesModelImpl.getOriginalOwnerId()) ||
317 (portletPreferences.getOwnerType() != portletPreferencesModelImpl.getOriginalOwnerType()) ||
318 (portletPreferences.getPlid() != portletPreferencesModelImpl.getOriginalPlid()) ||
319 !Validator.equals(portletPreferences.getPortletId(),
320 portletPreferencesModelImpl.getOriginalPortletId()))) {
321 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_O_O_P_P,
322 new Object[] {
323 new Long(portletPreferences.getOwnerId()),
324 new Integer(portletPreferences.getOwnerType()),
325 new Long(portletPreferences.getPlid()),
326
327 portletPreferences.getPortletId()
328 }, portletPreferences);
329 }
330
331 return portletPreferences;
332 }
333
334 protected PortletPreferences toUnwrappedModel(
335 PortletPreferences portletPreferences) {
336 if (portletPreferences instanceof PortletPreferencesImpl) {
337 return portletPreferences;
338 }
339
340 PortletPreferencesImpl portletPreferencesImpl = new PortletPreferencesImpl();
341
342 portletPreferencesImpl.setNew(portletPreferences.isNew());
343 portletPreferencesImpl.setPrimaryKey(portletPreferences.getPrimaryKey());
344
345 portletPreferencesImpl.setPortletPreferencesId(portletPreferences.getPortletPreferencesId());
346 portletPreferencesImpl.setOwnerId(portletPreferences.getOwnerId());
347 portletPreferencesImpl.setOwnerType(portletPreferences.getOwnerType());
348 portletPreferencesImpl.setPlid(portletPreferences.getPlid());
349 portletPreferencesImpl.setPortletId(portletPreferences.getPortletId());
350 portletPreferencesImpl.setPreferences(portletPreferences.getPreferences());
351
352 return portletPreferencesImpl;
353 }
354
355 public PortletPreferences findByPrimaryKey(Serializable primaryKey)
356 throws NoSuchModelException, SystemException {
357 return findByPrimaryKey(((Long)primaryKey).longValue());
358 }
359
360 public PortletPreferences findByPrimaryKey(long portletPreferencesId)
361 throws NoSuchPortletPreferencesException, SystemException {
362 PortletPreferences portletPreferences = fetchByPrimaryKey(portletPreferencesId);
363
364 if (portletPreferences == null) {
365 if (_log.isWarnEnabled()) {
366 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
367 portletPreferencesId);
368 }
369
370 throw new NoSuchPortletPreferencesException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
371 portletPreferencesId);
372 }
373
374 return portletPreferences;
375 }
376
377 public PortletPreferences fetchByPrimaryKey(Serializable primaryKey)
378 throws SystemException {
379 return fetchByPrimaryKey(((Long)primaryKey).longValue());
380 }
381
382 public PortletPreferences fetchByPrimaryKey(long portletPreferencesId)
383 throws SystemException {
384 PortletPreferences portletPreferences = (PortletPreferences)EntityCacheUtil.getResult(PortletPreferencesModelImpl.ENTITY_CACHE_ENABLED,
385 PortletPreferencesImpl.class, portletPreferencesId, this);
386
387 if (portletPreferences == null) {
388 Session session = null;
389
390 try {
391 session = openSession();
392
393 portletPreferences = (PortletPreferences)session.get(PortletPreferencesImpl.class,
394 new Long(portletPreferencesId));
395 }
396 catch (Exception e) {
397 throw processException(e);
398 }
399 finally {
400 if (portletPreferences != null) {
401 cacheResult(portletPreferences);
402 }
403
404 closeSession(session);
405 }
406 }
407
408 return portletPreferences;
409 }
410
411 public List<PortletPreferences> findByPlid(long plid)
412 throws SystemException {
413 return findByPlid(plid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
414 }
415
416 public List<PortletPreferences> findByPlid(long plid, int start, int end)
417 throws SystemException {
418 return findByPlid(plid, start, end, null);
419 }
420
421 public List<PortletPreferences> findByPlid(long plid, int start, int end,
422 OrderByComparator orderByComparator) throws SystemException {
423 Object[] finderArgs = new Object[] {
424 plid,
425
426 String.valueOf(start), String.valueOf(end),
427 String.valueOf(orderByComparator)
428 };
429
430 List<PortletPreferences> list = (List<PortletPreferences>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_PLID,
431 finderArgs, this);
432
433 if (list == null) {
434 Session session = null;
435
436 try {
437 session = openSession();
438
439 StringBundler query = null;
440
441 if (orderByComparator != null) {
442 query = new StringBundler(3 +
443 (orderByComparator.getOrderByFields().length * 3));
444 }
445 else {
446 query = new StringBundler(2);
447 }
448
449 query.append(_SQL_SELECT_PORTLETPREFERENCES_WHERE);
450
451 query.append(_FINDER_COLUMN_PLID_PLID_2);
452
453 if (orderByComparator != null) {
454 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
455 orderByComparator);
456 }
457
458 String sql = query.toString();
459
460 Query q = session.createQuery(sql);
461
462 QueryPos qPos = QueryPos.getInstance(q);
463
464 qPos.add(plid);
465
466 list = (List<PortletPreferences>)QueryUtil.list(q,
467 getDialect(), start, end);
468 }
469 catch (Exception e) {
470 throw processException(e);
471 }
472 finally {
473 if (list == null) {
474 list = new ArrayList<PortletPreferences>();
475 }
476
477 cacheResult(list);
478
479 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_PLID, finderArgs,
480 list);
481
482 closeSession(session);
483 }
484 }
485
486 return list;
487 }
488
489 public PortletPreferences findByPlid_First(long plid,
490 OrderByComparator orderByComparator)
491 throws NoSuchPortletPreferencesException, SystemException {
492 List<PortletPreferences> list = findByPlid(plid, 0, 1, orderByComparator);
493
494 if (list.isEmpty()) {
495 StringBundler msg = new StringBundler(4);
496
497 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
498
499 msg.append("plid=");
500 msg.append(plid);
501
502 msg.append(StringPool.CLOSE_CURLY_BRACE);
503
504 throw new NoSuchPortletPreferencesException(msg.toString());
505 }
506 else {
507 return list.get(0);
508 }
509 }
510
511 public PortletPreferences findByPlid_Last(long plid,
512 OrderByComparator orderByComparator)
513 throws NoSuchPortletPreferencesException, SystemException {
514 int count = countByPlid(plid);
515
516 List<PortletPreferences> list = findByPlid(plid, count - 1, count,
517 orderByComparator);
518
519 if (list.isEmpty()) {
520 StringBundler msg = new StringBundler(4);
521
522 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
523
524 msg.append("plid=");
525 msg.append(plid);
526
527 msg.append(StringPool.CLOSE_CURLY_BRACE);
528
529 throw new NoSuchPortletPreferencesException(msg.toString());
530 }
531 else {
532 return list.get(0);
533 }
534 }
535
536 public PortletPreferences[] findByPlid_PrevAndNext(
537 long portletPreferencesId, long plid,
538 OrderByComparator orderByComparator)
539 throws NoSuchPortletPreferencesException, SystemException {
540 PortletPreferences portletPreferences = findByPrimaryKey(portletPreferencesId);
541
542 Session session = null;
543
544 try {
545 session = openSession();
546
547 PortletPreferences[] array = new PortletPreferencesImpl[3];
548
549 array[0] = getByPlid_PrevAndNext(session, portletPreferences, plid,
550 orderByComparator, true);
551
552 array[1] = portletPreferences;
553
554 array[2] = getByPlid_PrevAndNext(session, portletPreferences, plid,
555 orderByComparator, false);
556
557 return array;
558 }
559 catch (Exception e) {
560 throw processException(e);
561 }
562 finally {
563 closeSession(session);
564 }
565 }
566
567 protected PortletPreferences getByPlid_PrevAndNext(Session session,
568 PortletPreferences portletPreferences, long plid,
569 OrderByComparator orderByComparator, boolean previous) {
570 StringBundler query = null;
571
572 if (orderByComparator != null) {
573 query = new StringBundler(6 +
574 (orderByComparator.getOrderByFields().length * 6));
575 }
576 else {
577 query = new StringBundler(3);
578 }
579
580 query.append(_SQL_SELECT_PORTLETPREFERENCES_WHERE);
581
582 query.append(_FINDER_COLUMN_PLID_PLID_2);
583
584 if (orderByComparator != null) {
585 String[] orderByFields = orderByComparator.getOrderByFields();
586
587 if (orderByFields.length > 0) {
588 query.append(WHERE_AND);
589 }
590
591 for (int i = 0; i < orderByFields.length; i++) {
592 query.append(_ORDER_BY_ENTITY_ALIAS);
593 query.append(orderByFields[i]);
594
595 if ((i + 1) < orderByFields.length) {
596 if (orderByComparator.isAscending() ^ previous) {
597 query.append(WHERE_GREATER_THAN_HAS_NEXT);
598 }
599 else {
600 query.append(WHERE_LESSER_THAN_HAS_NEXT);
601 }
602 }
603 else {
604 if (orderByComparator.isAscending() ^ previous) {
605 query.append(WHERE_GREATER_THAN);
606 }
607 else {
608 query.append(WHERE_LESSER_THAN);
609 }
610 }
611 }
612
613 query.append(ORDER_BY_CLAUSE);
614
615 for (int i = 0; i < orderByFields.length; i++) {
616 query.append(_ORDER_BY_ENTITY_ALIAS);
617 query.append(orderByFields[i]);
618
619 if ((i + 1) < orderByFields.length) {
620 if (orderByComparator.isAscending() ^ previous) {
621 query.append(ORDER_BY_ASC_HAS_NEXT);
622 }
623 else {
624 query.append(ORDER_BY_DESC_HAS_NEXT);
625 }
626 }
627 else {
628 if (orderByComparator.isAscending() ^ previous) {
629 query.append(ORDER_BY_ASC);
630 }
631 else {
632 query.append(ORDER_BY_DESC);
633 }
634 }
635 }
636 }
637
638 String sql = query.toString();
639
640 Query q = session.createQuery(sql);
641
642 q.setFirstResult(0);
643 q.setMaxResults(2);
644
645 QueryPos qPos = QueryPos.getInstance(q);
646
647 qPos.add(plid);
648
649 if (orderByComparator != null) {
650 Object[] values = orderByComparator.getOrderByValues(portletPreferences);
651
652 for (Object value : values) {
653 qPos.add(value);
654 }
655 }
656
657 List<PortletPreferences> list = q.list();
658
659 if (list.size() == 2) {
660 return list.get(1);
661 }
662 else {
663 return null;
664 }
665 }
666
667 public List<PortletPreferences> findByP_P(long plid, String portletId)
668 throws SystemException {
669 return findByP_P(plid, portletId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
670 null);
671 }
672
673 public List<PortletPreferences> findByP_P(long plid, String portletId,
674 int start, int end) throws SystemException {
675 return findByP_P(plid, portletId, start, end, null);
676 }
677
678 public List<PortletPreferences> findByP_P(long plid, String portletId,
679 int start, int end, OrderByComparator orderByComparator)
680 throws SystemException {
681 Object[] finderArgs = new Object[] {
682 plid, portletId,
683
684 String.valueOf(start), String.valueOf(end),
685 String.valueOf(orderByComparator)
686 };
687
688 List<PortletPreferences> list = (List<PortletPreferences>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_P_P,
689 finderArgs, this);
690
691 if (list == null) {
692 Session session = null;
693
694 try {
695 session = openSession();
696
697 StringBundler query = null;
698
699 if (orderByComparator != null) {
700 query = new StringBundler(4 +
701 (orderByComparator.getOrderByFields().length * 3));
702 }
703 else {
704 query = new StringBundler(3);
705 }
706
707 query.append(_SQL_SELECT_PORTLETPREFERENCES_WHERE);
708
709 query.append(_FINDER_COLUMN_P_P_PLID_2);
710
711 if (portletId == null) {
712 query.append(_FINDER_COLUMN_P_P_PORTLETID_1);
713 }
714 else {
715 if (portletId.equals(StringPool.BLANK)) {
716 query.append(_FINDER_COLUMN_P_P_PORTLETID_3);
717 }
718 else {
719 query.append(_FINDER_COLUMN_P_P_PORTLETID_2);
720 }
721 }
722
723 if (orderByComparator != null) {
724 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
725 orderByComparator);
726 }
727
728 String sql = query.toString();
729
730 Query q = session.createQuery(sql);
731
732 QueryPos qPos = QueryPos.getInstance(q);
733
734 qPos.add(plid);
735
736 if (portletId != null) {
737 qPos.add(portletId);
738 }
739
740 list = (List<PortletPreferences>)QueryUtil.list(q,
741 getDialect(), start, end);
742 }
743 catch (Exception e) {
744 throw processException(e);
745 }
746 finally {
747 if (list == null) {
748 list = new ArrayList<PortletPreferences>();
749 }
750
751 cacheResult(list);
752
753 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_P_P, finderArgs,
754 list);
755
756 closeSession(session);
757 }
758 }
759
760 return list;
761 }
762
763 public PortletPreferences findByP_P_First(long plid, String portletId,
764 OrderByComparator orderByComparator)
765 throws NoSuchPortletPreferencesException, SystemException {
766 List<PortletPreferences> list = findByP_P(plid, portletId, 0, 1,
767 orderByComparator);
768
769 if (list.isEmpty()) {
770 StringBundler msg = new StringBundler(6);
771
772 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
773
774 msg.append("plid=");
775 msg.append(plid);
776
777 msg.append(", portletId=");
778 msg.append(portletId);
779
780 msg.append(StringPool.CLOSE_CURLY_BRACE);
781
782 throw new NoSuchPortletPreferencesException(msg.toString());
783 }
784 else {
785 return list.get(0);
786 }
787 }
788
789 public PortletPreferences findByP_P_Last(long plid, String portletId,
790 OrderByComparator orderByComparator)
791 throws NoSuchPortletPreferencesException, SystemException {
792 int count = countByP_P(plid, portletId);
793
794 List<PortletPreferences> list = findByP_P(plid, portletId, count - 1,
795 count, orderByComparator);
796
797 if (list.isEmpty()) {
798 StringBundler msg = new StringBundler(6);
799
800 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
801
802 msg.append("plid=");
803 msg.append(plid);
804
805 msg.append(", portletId=");
806 msg.append(portletId);
807
808 msg.append(StringPool.CLOSE_CURLY_BRACE);
809
810 throw new NoSuchPortletPreferencesException(msg.toString());
811 }
812 else {
813 return list.get(0);
814 }
815 }
816
817 public PortletPreferences[] findByP_P_PrevAndNext(
818 long portletPreferencesId, long plid, String portletId,
819 OrderByComparator orderByComparator)
820 throws NoSuchPortletPreferencesException, SystemException {
821 PortletPreferences portletPreferences = findByPrimaryKey(portletPreferencesId);
822
823 Session session = null;
824
825 try {
826 session = openSession();
827
828 PortletPreferences[] array = new PortletPreferencesImpl[3];
829
830 array[0] = getByP_P_PrevAndNext(session, portletPreferences, plid,
831 portletId, orderByComparator, true);
832
833 array[1] = portletPreferences;
834
835 array[2] = getByP_P_PrevAndNext(session, portletPreferences, plid,
836 portletId, orderByComparator, false);
837
838 return array;
839 }
840 catch (Exception e) {
841 throw processException(e);
842 }
843 finally {
844 closeSession(session);
845 }
846 }
847
848 protected PortletPreferences getByP_P_PrevAndNext(Session session,
849 PortletPreferences portletPreferences, long plid, String portletId,
850 OrderByComparator orderByComparator, boolean previous) {
851 StringBundler query = null;
852
853 if (orderByComparator != null) {
854 query = new StringBundler(6 +
855 (orderByComparator.getOrderByFields().length * 6));
856 }
857 else {
858 query = new StringBundler(3);
859 }
860
861 query.append(_SQL_SELECT_PORTLETPREFERENCES_WHERE);
862
863 query.append(_FINDER_COLUMN_P_P_PLID_2);
864
865 if (portletId == null) {
866 query.append(_FINDER_COLUMN_P_P_PORTLETID_1);
867 }
868 else {
869 if (portletId.equals(StringPool.BLANK)) {
870 query.append(_FINDER_COLUMN_P_P_PORTLETID_3);
871 }
872 else {
873 query.append(_FINDER_COLUMN_P_P_PORTLETID_2);
874 }
875 }
876
877 if (orderByComparator != null) {
878 String[] orderByFields = orderByComparator.getOrderByFields();
879
880 if (orderByFields.length > 0) {
881 query.append(WHERE_AND);
882 }
883
884 for (int i = 0; i < orderByFields.length; i++) {
885 query.append(_ORDER_BY_ENTITY_ALIAS);
886 query.append(orderByFields[i]);
887
888 if ((i + 1) < orderByFields.length) {
889 if (orderByComparator.isAscending() ^ previous) {
890 query.append(WHERE_GREATER_THAN_HAS_NEXT);
891 }
892 else {
893 query.append(WHERE_LESSER_THAN_HAS_NEXT);
894 }
895 }
896 else {
897 if (orderByComparator.isAscending() ^ previous) {
898 query.append(WHERE_GREATER_THAN);
899 }
900 else {
901 query.append(WHERE_LESSER_THAN);
902 }
903 }
904 }
905
906 query.append(ORDER_BY_CLAUSE);
907
908 for (int i = 0; i < orderByFields.length; i++) {
909 query.append(_ORDER_BY_ENTITY_ALIAS);
910 query.append(orderByFields[i]);
911
912 if ((i + 1) < orderByFields.length) {
913 if (orderByComparator.isAscending() ^ previous) {
914 query.append(ORDER_BY_ASC_HAS_NEXT);
915 }
916 else {
917 query.append(ORDER_BY_DESC_HAS_NEXT);
918 }
919 }
920 else {
921 if (orderByComparator.isAscending() ^ previous) {
922 query.append(ORDER_BY_ASC);
923 }
924 else {
925 query.append(ORDER_BY_DESC);
926 }
927 }
928 }
929 }
930
931 String sql = query.toString();
932
933 Query q = session.createQuery(sql);
934
935 q.setFirstResult(0);
936 q.setMaxResults(2);
937
938 QueryPos qPos = QueryPos.getInstance(q);
939
940 qPos.add(plid);
941
942 if (portletId != null) {
943 qPos.add(portletId);
944 }
945
946 if (orderByComparator != null) {
947 Object[] values = orderByComparator.getOrderByValues(portletPreferences);
948
949 for (Object value : values) {
950 qPos.add(value);
951 }
952 }
953
954 List<PortletPreferences> list = q.list();
955
956 if (list.size() == 2) {
957 return list.get(1);
958 }
959 else {
960 return null;
961 }
962 }
963
964 public List<PortletPreferences> findByO_O_P(long ownerId, int ownerType,
965 long plid) throws SystemException {
966 return findByO_O_P(ownerId, ownerType, plid, QueryUtil.ALL_POS,
967 QueryUtil.ALL_POS, null);
968 }
969
970 public List<PortletPreferences> findByO_O_P(long ownerId, int ownerType,
971 long plid, int start, int end) throws SystemException {
972 return findByO_O_P(ownerId, ownerType, plid, start, end, null);
973 }
974
975 public List<PortletPreferences> findByO_O_P(long ownerId, int ownerType,
976 long plid, int start, int end, OrderByComparator orderByComparator)
977 throws SystemException {
978 Object[] finderArgs = new Object[] {
979 ownerId, ownerType, plid,
980
981 String.valueOf(start), String.valueOf(end),
982 String.valueOf(orderByComparator)
983 };
984
985 List<PortletPreferences> list = (List<PortletPreferences>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_O_O_P,
986 finderArgs, this);
987
988 if (list == null) {
989 Session session = null;
990
991 try {
992 session = openSession();
993
994 StringBundler query = null;
995
996 if (orderByComparator != null) {
997 query = new StringBundler(5 +
998 (orderByComparator.getOrderByFields().length * 3));
999 }
1000 else {
1001 query = new StringBundler(4);
1002 }
1003
1004 query.append(_SQL_SELECT_PORTLETPREFERENCES_WHERE);
1005
1006 query.append(_FINDER_COLUMN_O_O_P_OWNERID_2);
1007
1008 query.append(_FINDER_COLUMN_O_O_P_OWNERTYPE_2);
1009
1010 query.append(_FINDER_COLUMN_O_O_P_PLID_2);
1011
1012 if (orderByComparator != null) {
1013 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1014 orderByComparator);
1015 }
1016
1017 String sql = query.toString();
1018
1019 Query q = session.createQuery(sql);
1020
1021 QueryPos qPos = QueryPos.getInstance(q);
1022
1023 qPos.add(ownerId);
1024
1025 qPos.add(ownerType);
1026
1027 qPos.add(plid);
1028
1029 list = (List<PortletPreferences>)QueryUtil.list(q,
1030 getDialect(), start, end);
1031 }
1032 catch (Exception e) {
1033 throw processException(e);
1034 }
1035 finally {
1036 if (list == null) {
1037 list = new ArrayList<PortletPreferences>();
1038 }
1039
1040 cacheResult(list);
1041
1042 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_O_O_P,
1043 finderArgs, list);
1044
1045 closeSession(session);
1046 }
1047 }
1048
1049 return list;
1050 }
1051
1052 public PortletPreferences findByO_O_P_First(long ownerId, int ownerType,
1053 long plid, OrderByComparator orderByComparator)
1054 throws NoSuchPortletPreferencesException, SystemException {
1055 List<PortletPreferences> list = findByO_O_P(ownerId, ownerType, plid,
1056 0, 1, orderByComparator);
1057
1058 if (list.isEmpty()) {
1059 StringBundler msg = new StringBundler(8);
1060
1061 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1062
1063 msg.append("ownerId=");
1064 msg.append(ownerId);
1065
1066 msg.append(", ownerType=");
1067 msg.append(ownerType);
1068
1069 msg.append(", plid=");
1070 msg.append(plid);
1071
1072 msg.append(StringPool.CLOSE_CURLY_BRACE);
1073
1074 throw new NoSuchPortletPreferencesException(msg.toString());
1075 }
1076 else {
1077 return list.get(0);
1078 }
1079 }
1080
1081 public PortletPreferences findByO_O_P_Last(long ownerId, int ownerType,
1082 long plid, OrderByComparator orderByComparator)
1083 throws NoSuchPortletPreferencesException, SystemException {
1084 int count = countByO_O_P(ownerId, ownerType, plid);
1085
1086 List<PortletPreferences> list = findByO_O_P(ownerId, ownerType, plid,
1087 count - 1, count, orderByComparator);
1088
1089 if (list.isEmpty()) {
1090 StringBundler msg = new StringBundler(8);
1091
1092 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1093
1094 msg.append("ownerId=");
1095 msg.append(ownerId);
1096
1097 msg.append(", ownerType=");
1098 msg.append(ownerType);
1099
1100 msg.append(", plid=");
1101 msg.append(plid);
1102
1103 msg.append(StringPool.CLOSE_CURLY_BRACE);
1104
1105 throw new NoSuchPortletPreferencesException(msg.toString());
1106 }
1107 else {
1108 return list.get(0);
1109 }
1110 }
1111
1112 public PortletPreferences[] findByO_O_P_PrevAndNext(
1113 long portletPreferencesId, long ownerId, int ownerType, long plid,
1114 OrderByComparator orderByComparator)
1115 throws NoSuchPortletPreferencesException, SystemException {
1116 PortletPreferences portletPreferences = findByPrimaryKey(portletPreferencesId);
1117
1118 Session session = null;
1119
1120 try {
1121 session = openSession();
1122
1123 PortletPreferences[] array = new PortletPreferencesImpl[3];
1124
1125 array[0] = getByO_O_P_PrevAndNext(session, portletPreferences,
1126 ownerId, ownerType, plid, orderByComparator, true);
1127
1128 array[1] = portletPreferences;
1129
1130 array[2] = getByO_O_P_PrevAndNext(session, portletPreferences,
1131 ownerId, ownerType, plid, orderByComparator, false);
1132
1133 return array;
1134 }
1135 catch (Exception e) {
1136 throw processException(e);
1137 }
1138 finally {
1139 closeSession(session);
1140 }
1141 }
1142
1143 protected PortletPreferences getByO_O_P_PrevAndNext(Session session,
1144 PortletPreferences portletPreferences, long ownerId, int ownerType,
1145 long plid, OrderByComparator orderByComparator, boolean previous) {
1146 StringBundler query = null;
1147
1148 if (orderByComparator != null) {
1149 query = new StringBundler(6 +
1150 (orderByComparator.getOrderByFields().length * 6));
1151 }
1152 else {
1153 query = new StringBundler(3);
1154 }
1155
1156 query.append(_SQL_SELECT_PORTLETPREFERENCES_WHERE);
1157
1158 query.append(_FINDER_COLUMN_O_O_P_OWNERID_2);
1159
1160 query.append(_FINDER_COLUMN_O_O_P_OWNERTYPE_2);
1161
1162 query.append(_FINDER_COLUMN_O_O_P_PLID_2);
1163
1164 if (orderByComparator != null) {
1165 String[] orderByFields = orderByComparator.getOrderByFields();
1166
1167 if (orderByFields.length > 0) {
1168 query.append(WHERE_AND);
1169 }
1170
1171 for (int i = 0; i < orderByFields.length; i++) {
1172 query.append(_ORDER_BY_ENTITY_ALIAS);
1173 query.append(orderByFields[i]);
1174
1175 if ((i + 1) < orderByFields.length) {
1176 if (orderByComparator.isAscending() ^ previous) {
1177 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1178 }
1179 else {
1180 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1181 }
1182 }
1183 else {
1184 if (orderByComparator.isAscending() ^ previous) {
1185 query.append(WHERE_GREATER_THAN);
1186 }
1187 else {
1188 query.append(WHERE_LESSER_THAN);
1189 }
1190 }
1191 }
1192
1193 query.append(ORDER_BY_CLAUSE);
1194
1195 for (int i = 0; i < orderByFields.length; i++) {
1196 query.append(_ORDER_BY_ENTITY_ALIAS);
1197 query.append(orderByFields[i]);
1198
1199 if ((i + 1) < orderByFields.length) {
1200 if (orderByComparator.isAscending() ^ previous) {
1201 query.append(ORDER_BY_ASC_HAS_NEXT);
1202 }
1203 else {
1204 query.append(ORDER_BY_DESC_HAS_NEXT);
1205 }
1206 }
1207 else {
1208 if (orderByComparator.isAscending() ^ previous) {
1209 query.append(ORDER_BY_ASC);
1210 }
1211 else {
1212 query.append(ORDER_BY_DESC);
1213 }
1214 }
1215 }
1216 }
1217
1218 String sql = query.toString();
1219
1220 Query q = session.createQuery(sql);
1221
1222 q.setFirstResult(0);
1223 q.setMaxResults(2);
1224
1225 QueryPos qPos = QueryPos.getInstance(q);
1226
1227 qPos.add(ownerId);
1228
1229 qPos.add(ownerType);
1230
1231 qPos.add(plid);
1232
1233 if (orderByComparator != null) {
1234 Object[] values = orderByComparator.getOrderByValues(portletPreferences);
1235
1236 for (Object value : values) {
1237 qPos.add(value);
1238 }
1239 }
1240
1241 List<PortletPreferences> list = q.list();
1242
1243 if (list.size() == 2) {
1244 return list.get(1);
1245 }
1246 else {
1247 return null;
1248 }
1249 }
1250
1251 public PortletPreferences findByO_O_P_P(long ownerId, int ownerType,
1252 long plid, String portletId)
1253 throws NoSuchPortletPreferencesException, SystemException {
1254 PortletPreferences portletPreferences = fetchByO_O_P_P(ownerId,
1255 ownerType, plid, portletId);
1256
1257 if (portletPreferences == null) {
1258 StringBundler msg = new StringBundler(10);
1259
1260 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1261
1262 msg.append("ownerId=");
1263 msg.append(ownerId);
1264
1265 msg.append(", ownerType=");
1266 msg.append(ownerType);
1267
1268 msg.append(", plid=");
1269 msg.append(plid);
1270
1271 msg.append(", portletId=");
1272 msg.append(portletId);
1273
1274 msg.append(StringPool.CLOSE_CURLY_BRACE);
1275
1276 if (_log.isWarnEnabled()) {
1277 _log.warn(msg.toString());
1278 }
1279
1280 throw new NoSuchPortletPreferencesException(msg.toString());
1281 }
1282
1283 return portletPreferences;
1284 }
1285
1286 public PortletPreferences fetchByO_O_P_P(long ownerId, int ownerType,
1287 long plid, String portletId) throws SystemException {
1288 return fetchByO_O_P_P(ownerId, ownerType, plid, portletId, true);
1289 }
1290
1291 public PortletPreferences fetchByO_O_P_P(long ownerId, int ownerType,
1292 long plid, String portletId, boolean retrieveFromCache)
1293 throws SystemException {
1294 Object[] finderArgs = new Object[] { ownerId, ownerType, plid, portletId };
1295
1296 Object result = null;
1297
1298 if (retrieveFromCache) {
1299 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_O_O_P_P,
1300 finderArgs, this);
1301 }
1302
1303 if (result == null) {
1304 Session session = null;
1305
1306 try {
1307 session = openSession();
1308
1309 StringBundler query = new StringBundler(5);
1310
1311 query.append(_SQL_SELECT_PORTLETPREFERENCES_WHERE);
1312
1313 query.append(_FINDER_COLUMN_O_O_P_P_OWNERID_2);
1314
1315 query.append(_FINDER_COLUMN_O_O_P_P_OWNERTYPE_2);
1316
1317 query.append(_FINDER_COLUMN_O_O_P_P_PLID_2);
1318
1319 if (portletId == null) {
1320 query.append(_FINDER_COLUMN_O_O_P_P_PORTLETID_1);
1321 }
1322 else {
1323 if (portletId.equals(StringPool.BLANK)) {
1324 query.append(_FINDER_COLUMN_O_O_P_P_PORTLETID_3);
1325 }
1326 else {
1327 query.append(_FINDER_COLUMN_O_O_P_P_PORTLETID_2);
1328 }
1329 }
1330
1331 String sql = query.toString();
1332
1333 Query q = session.createQuery(sql);
1334
1335 QueryPos qPos = QueryPos.getInstance(q);
1336
1337 qPos.add(ownerId);
1338
1339 qPos.add(ownerType);
1340
1341 qPos.add(plid);
1342
1343 if (portletId != null) {
1344 qPos.add(portletId);
1345 }
1346
1347 List<PortletPreferences> list = q.list();
1348
1349 result = list;
1350
1351 PortletPreferences portletPreferences = null;
1352
1353 if (list.isEmpty()) {
1354 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_O_O_P_P,
1355 finderArgs, list);
1356 }
1357 else {
1358 portletPreferences = list.get(0);
1359
1360 cacheResult(portletPreferences);
1361
1362 if ((portletPreferences.getOwnerId() != ownerId) ||
1363 (portletPreferences.getOwnerType() != ownerType) ||
1364 (portletPreferences.getPlid() != plid) ||
1365 (portletPreferences.getPortletId() == null) ||
1366 !portletPreferences.getPortletId().equals(portletId)) {
1367 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_O_O_P_P,
1368 finderArgs, portletPreferences);
1369 }
1370 }
1371
1372 return portletPreferences;
1373 }
1374 catch (Exception e) {
1375 throw processException(e);
1376 }
1377 finally {
1378 if (result == null) {
1379 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_O_O_P_P,
1380 finderArgs, new ArrayList<PortletPreferences>());
1381 }
1382
1383 closeSession(session);
1384 }
1385 }
1386 else {
1387 if (result instanceof List<?>) {
1388 return null;
1389 }
1390 else {
1391 return (PortletPreferences)result;
1392 }
1393 }
1394 }
1395
1396 public List<PortletPreferences> findAll() throws SystemException {
1397 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1398 }
1399
1400 public List<PortletPreferences> findAll(int start, int end)
1401 throws SystemException {
1402 return findAll(start, end, null);
1403 }
1404
1405 public List<PortletPreferences> findAll(int start, int end,
1406 OrderByComparator orderByComparator) throws SystemException {
1407 Object[] finderArgs = new Object[] {
1408 String.valueOf(start), String.valueOf(end),
1409 String.valueOf(orderByComparator)
1410 };
1411
1412 List<PortletPreferences> list = (List<PortletPreferences>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1413 finderArgs, this);
1414
1415 if (list == null) {
1416 Session session = null;
1417
1418 try {
1419 session = openSession();
1420
1421 StringBundler query = null;
1422 String sql = null;
1423
1424 if (orderByComparator != null) {
1425 query = new StringBundler(2 +
1426 (orderByComparator.getOrderByFields().length * 3));
1427
1428 query.append(_SQL_SELECT_PORTLETPREFERENCES);
1429
1430 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1431 orderByComparator);
1432
1433 sql = query.toString();
1434 }
1435 else {
1436 sql = _SQL_SELECT_PORTLETPREFERENCES;
1437 }
1438
1439 Query q = session.createQuery(sql);
1440
1441 if (orderByComparator == null) {
1442 list = (List<PortletPreferences>)QueryUtil.list(q,
1443 getDialect(), start, end, false);
1444
1445 Collections.sort(list);
1446 }
1447 else {
1448 list = (List<PortletPreferences>)QueryUtil.list(q,
1449 getDialect(), start, end);
1450 }
1451 }
1452 catch (Exception e) {
1453 throw processException(e);
1454 }
1455 finally {
1456 if (list == null) {
1457 list = new ArrayList<PortletPreferences>();
1458 }
1459
1460 cacheResult(list);
1461
1462 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1463
1464 closeSession(session);
1465 }
1466 }
1467
1468 return list;
1469 }
1470
1471 public void removeByPlid(long plid) throws SystemException {
1472 for (PortletPreferences portletPreferences : findByPlid(plid)) {
1473 remove(portletPreferences);
1474 }
1475 }
1476
1477 public void removeByP_P(long plid, String portletId)
1478 throws SystemException {
1479 for (PortletPreferences portletPreferences : findByP_P(plid, portletId)) {
1480 remove(portletPreferences);
1481 }
1482 }
1483
1484 public void removeByO_O_P(long ownerId, int ownerType, long plid)
1485 throws SystemException {
1486 for (PortletPreferences portletPreferences : findByO_O_P(ownerId,
1487 ownerType, plid)) {
1488 remove(portletPreferences);
1489 }
1490 }
1491
1492 public void removeByO_O_P_P(long ownerId, int ownerType, long plid,
1493 String portletId)
1494 throws NoSuchPortletPreferencesException, SystemException {
1495 PortletPreferences portletPreferences = findByO_O_P_P(ownerId,
1496 ownerType, plid, portletId);
1497
1498 remove(portletPreferences);
1499 }
1500
1501 public void removeAll() throws SystemException {
1502 for (PortletPreferences portletPreferences : findAll()) {
1503 remove(portletPreferences);
1504 }
1505 }
1506
1507 public int countByPlid(long plid) throws SystemException {
1508 Object[] finderArgs = new Object[] { plid };
1509
1510 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_PLID,
1511 finderArgs, this);
1512
1513 if (count == null) {
1514 Session session = null;
1515
1516 try {
1517 session = openSession();
1518
1519 StringBundler query = new StringBundler(2);
1520
1521 query.append(_SQL_COUNT_PORTLETPREFERENCES_WHERE);
1522
1523 query.append(_FINDER_COLUMN_PLID_PLID_2);
1524
1525 String sql = query.toString();
1526
1527 Query q = session.createQuery(sql);
1528
1529 QueryPos qPos = QueryPos.getInstance(q);
1530
1531 qPos.add(plid);
1532
1533 count = (Long)q.uniqueResult();
1534 }
1535 catch (Exception e) {
1536 throw processException(e);
1537 }
1538 finally {
1539 if (count == null) {
1540 count = Long.valueOf(0);
1541 }
1542
1543 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_PLID,
1544 finderArgs, count);
1545
1546 closeSession(session);
1547 }
1548 }
1549
1550 return count.intValue();
1551 }
1552
1553 public int countByP_P(long plid, String portletId)
1554 throws SystemException {
1555 Object[] finderArgs = new Object[] { plid, portletId };
1556
1557 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_P_P,
1558 finderArgs, this);
1559
1560 if (count == null) {
1561 Session session = null;
1562
1563 try {
1564 session = openSession();
1565
1566 StringBundler query = new StringBundler(3);
1567
1568 query.append(_SQL_COUNT_PORTLETPREFERENCES_WHERE);
1569
1570 query.append(_FINDER_COLUMN_P_P_PLID_2);
1571
1572 if (portletId == null) {
1573 query.append(_FINDER_COLUMN_P_P_PORTLETID_1);
1574 }
1575 else {
1576 if (portletId.equals(StringPool.BLANK)) {
1577 query.append(_FINDER_COLUMN_P_P_PORTLETID_3);
1578 }
1579 else {
1580 query.append(_FINDER_COLUMN_P_P_PORTLETID_2);
1581 }
1582 }
1583
1584 String sql = query.toString();
1585
1586 Query q = session.createQuery(sql);
1587
1588 QueryPos qPos = QueryPos.getInstance(q);
1589
1590 qPos.add(plid);
1591
1592 if (portletId != null) {
1593 qPos.add(portletId);
1594 }
1595
1596 count = (Long)q.uniqueResult();
1597 }
1598 catch (Exception e) {
1599 throw processException(e);
1600 }
1601 finally {
1602 if (count == null) {
1603 count = Long.valueOf(0);
1604 }
1605
1606 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_P_P, finderArgs,
1607 count);
1608
1609 closeSession(session);
1610 }
1611 }
1612
1613 return count.intValue();
1614 }
1615
1616 public int countByO_O_P(long ownerId, int ownerType, long plid)
1617 throws SystemException {
1618 Object[] finderArgs = new Object[] { ownerId, ownerType, plid };
1619
1620 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_O_O_P,
1621 finderArgs, this);
1622
1623 if (count == null) {
1624 Session session = null;
1625
1626 try {
1627 session = openSession();
1628
1629 StringBundler query = new StringBundler(4);
1630
1631 query.append(_SQL_COUNT_PORTLETPREFERENCES_WHERE);
1632
1633 query.append(_FINDER_COLUMN_O_O_P_OWNERID_2);
1634
1635 query.append(_FINDER_COLUMN_O_O_P_OWNERTYPE_2);
1636
1637 query.append(_FINDER_COLUMN_O_O_P_PLID_2);
1638
1639 String sql = query.toString();
1640
1641 Query q = session.createQuery(sql);
1642
1643 QueryPos qPos = QueryPos.getInstance(q);
1644
1645 qPos.add(ownerId);
1646
1647 qPos.add(ownerType);
1648
1649 qPos.add(plid);
1650
1651 count = (Long)q.uniqueResult();
1652 }
1653 catch (Exception e) {
1654 throw processException(e);
1655 }
1656 finally {
1657 if (count == null) {
1658 count = Long.valueOf(0);
1659 }
1660
1661 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_O_O_P,
1662 finderArgs, count);
1663
1664 closeSession(session);
1665 }
1666 }
1667
1668 return count.intValue();
1669 }
1670
1671 public int countByO_O_P_P(long ownerId, int ownerType, long plid,
1672 String portletId) throws SystemException {
1673 Object[] finderArgs = new Object[] { ownerId, ownerType, plid, portletId };
1674
1675 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_O_O_P_P,
1676 finderArgs, this);
1677
1678 if (count == null) {
1679 Session session = null;
1680
1681 try {
1682 session = openSession();
1683
1684 StringBundler query = new StringBundler(5);
1685
1686 query.append(_SQL_COUNT_PORTLETPREFERENCES_WHERE);
1687
1688 query.append(_FINDER_COLUMN_O_O_P_P_OWNERID_2);
1689
1690 query.append(_FINDER_COLUMN_O_O_P_P_OWNERTYPE_2);
1691
1692 query.append(_FINDER_COLUMN_O_O_P_P_PLID_2);
1693
1694 if (portletId == null) {
1695 query.append(_FINDER_COLUMN_O_O_P_P_PORTLETID_1);
1696 }
1697 else {
1698 if (portletId.equals(StringPool.BLANK)) {
1699 query.append(_FINDER_COLUMN_O_O_P_P_PORTLETID_3);
1700 }
1701 else {
1702 query.append(_FINDER_COLUMN_O_O_P_P_PORTLETID_2);
1703 }
1704 }
1705
1706 String sql = query.toString();
1707
1708 Query q = session.createQuery(sql);
1709
1710 QueryPos qPos = QueryPos.getInstance(q);
1711
1712 qPos.add(ownerId);
1713
1714 qPos.add(ownerType);
1715
1716 qPos.add(plid);
1717
1718 if (portletId != null) {
1719 qPos.add(portletId);
1720 }
1721
1722 count = (Long)q.uniqueResult();
1723 }
1724 catch (Exception e) {
1725 throw processException(e);
1726 }
1727 finally {
1728 if (count == null) {
1729 count = Long.valueOf(0);
1730 }
1731
1732 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_O_O_P_P,
1733 finderArgs, count);
1734
1735 closeSession(session);
1736 }
1737 }
1738
1739 return count.intValue();
1740 }
1741
1742 public int countAll() throws SystemException {
1743 Object[] finderArgs = new Object[0];
1744
1745 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1746 finderArgs, this);
1747
1748 if (count == null) {
1749 Session session = null;
1750
1751 try {
1752 session = openSession();
1753
1754 Query q = session.createQuery(_SQL_COUNT_PORTLETPREFERENCES);
1755
1756 count = (Long)q.uniqueResult();
1757 }
1758 catch (Exception e) {
1759 throw processException(e);
1760 }
1761 finally {
1762 if (count == null) {
1763 count = Long.valueOf(0);
1764 }
1765
1766 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1767 count);
1768
1769 closeSession(session);
1770 }
1771 }
1772
1773 return count.intValue();
1774 }
1775
1776 public void afterPropertiesSet() {
1777 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1778 com.liferay.portal.util.PropsUtil.get(
1779 "value.object.listener.com.liferay.portal.model.PortletPreferences")));
1780
1781 if (listenerClassNames.length > 0) {
1782 try {
1783 List<ModelListener<PortletPreferences>> listenersList = new ArrayList<ModelListener<PortletPreferences>>();
1784
1785 for (String listenerClassName : listenerClassNames) {
1786 listenersList.add((ModelListener<PortletPreferences>)InstanceFactory.newInstance(
1787 listenerClassName));
1788 }
1789
1790 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1791 }
1792 catch (Exception e) {
1793 _log.error(e);
1794 }
1795 }
1796 }
1797
1798 @BeanReference(type = AccountPersistence.class)
1799 protected AccountPersistence accountPersistence;
1800 @BeanReference(type = AddressPersistence.class)
1801 protected AddressPersistence addressPersistence;
1802 @BeanReference(type = BrowserTrackerPersistence.class)
1803 protected BrowserTrackerPersistence browserTrackerPersistence;
1804 @BeanReference(type = ClassNamePersistence.class)
1805 protected ClassNamePersistence classNamePersistence;
1806 @BeanReference(type = CompanyPersistence.class)
1807 protected CompanyPersistence companyPersistence;
1808 @BeanReference(type = ContactPersistence.class)
1809 protected ContactPersistence contactPersistence;
1810 @BeanReference(type = CountryPersistence.class)
1811 protected CountryPersistence countryPersistence;
1812 @BeanReference(type = EmailAddressPersistence.class)
1813 protected EmailAddressPersistence emailAddressPersistence;
1814 @BeanReference(type = GroupPersistence.class)
1815 protected GroupPersistence groupPersistence;
1816 @BeanReference(type = ImagePersistence.class)
1817 protected ImagePersistence imagePersistence;
1818 @BeanReference(type = LayoutPersistence.class)
1819 protected LayoutPersistence layoutPersistence;
1820 @BeanReference(type = LayoutPrototypePersistence.class)
1821 protected LayoutPrototypePersistence layoutPrototypePersistence;
1822 @BeanReference(type = LayoutSetPersistence.class)
1823 protected LayoutSetPersistence layoutSetPersistence;
1824 @BeanReference(type = LayoutSetPrototypePersistence.class)
1825 protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
1826 @BeanReference(type = ListTypePersistence.class)
1827 protected ListTypePersistence listTypePersistence;
1828 @BeanReference(type = LockPersistence.class)
1829 protected LockPersistence lockPersistence;
1830 @BeanReference(type = MembershipRequestPersistence.class)
1831 protected MembershipRequestPersistence membershipRequestPersistence;
1832 @BeanReference(type = OrganizationPersistence.class)
1833 protected OrganizationPersistence organizationPersistence;
1834 @BeanReference(type = OrgGroupPermissionPersistence.class)
1835 protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1836 @BeanReference(type = OrgGroupRolePersistence.class)
1837 protected OrgGroupRolePersistence orgGroupRolePersistence;
1838 @BeanReference(type = OrgLaborPersistence.class)
1839 protected OrgLaborPersistence orgLaborPersistence;
1840 @BeanReference(type = PasswordPolicyPersistence.class)
1841 protected PasswordPolicyPersistence passwordPolicyPersistence;
1842 @BeanReference(type = PasswordPolicyRelPersistence.class)
1843 protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1844 @BeanReference(type = PasswordTrackerPersistence.class)
1845 protected PasswordTrackerPersistence passwordTrackerPersistence;
1846 @BeanReference(type = PermissionPersistence.class)
1847 protected PermissionPersistence permissionPersistence;
1848 @BeanReference(type = PhonePersistence.class)
1849 protected PhonePersistence phonePersistence;
1850 @BeanReference(type = PluginSettingPersistence.class)
1851 protected PluginSettingPersistence pluginSettingPersistence;
1852 @BeanReference(type = PortletPersistence.class)
1853 protected PortletPersistence portletPersistence;
1854 @BeanReference(type = PortletItemPersistence.class)
1855 protected PortletItemPersistence portletItemPersistence;
1856 @BeanReference(type = PortletPreferencesPersistence.class)
1857 protected PortletPreferencesPersistence portletPreferencesPersistence;
1858 @BeanReference(type = RegionPersistence.class)
1859 protected RegionPersistence regionPersistence;
1860 @BeanReference(type = ReleasePersistence.class)
1861 protected ReleasePersistence releasePersistence;
1862 @BeanReference(type = ResourcePersistence.class)
1863 protected ResourcePersistence resourcePersistence;
1864 @BeanReference(type = ResourceActionPersistence.class)
1865 protected ResourceActionPersistence resourceActionPersistence;
1866 @BeanReference(type = ResourceCodePersistence.class)
1867 protected ResourceCodePersistence resourceCodePersistence;
1868 @BeanReference(type = ResourcePermissionPersistence.class)
1869 protected ResourcePermissionPersistence resourcePermissionPersistence;
1870 @BeanReference(type = RolePersistence.class)
1871 protected RolePersistence rolePersistence;
1872 @BeanReference(type = ServiceComponentPersistence.class)
1873 protected ServiceComponentPersistence serviceComponentPersistence;
1874 @BeanReference(type = ShardPersistence.class)
1875 protected ShardPersistence shardPersistence;
1876 @BeanReference(type = SubscriptionPersistence.class)
1877 protected SubscriptionPersistence subscriptionPersistence;
1878 @BeanReference(type = TicketPersistence.class)
1879 protected TicketPersistence ticketPersistence;
1880 @BeanReference(type = TeamPersistence.class)
1881 protected TeamPersistence teamPersistence;
1882 @BeanReference(type = UserPersistence.class)
1883 protected UserPersistence userPersistence;
1884 @BeanReference(type = UserGroupPersistence.class)
1885 protected UserGroupPersistence userGroupPersistence;
1886 @BeanReference(type = UserGroupGroupRolePersistence.class)
1887 protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
1888 @BeanReference(type = UserGroupRolePersistence.class)
1889 protected UserGroupRolePersistence userGroupRolePersistence;
1890 @BeanReference(type = UserIdMapperPersistence.class)
1891 protected UserIdMapperPersistence userIdMapperPersistence;
1892 @BeanReference(type = UserTrackerPersistence.class)
1893 protected UserTrackerPersistence userTrackerPersistence;
1894 @BeanReference(type = UserTrackerPathPersistence.class)
1895 protected UserTrackerPathPersistence userTrackerPathPersistence;
1896 @BeanReference(type = WebDAVPropsPersistence.class)
1897 protected WebDAVPropsPersistence webDAVPropsPersistence;
1898 @BeanReference(type = WebsitePersistence.class)
1899 protected WebsitePersistence websitePersistence;
1900 @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
1901 protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
1902 @BeanReference(type = WorkflowInstanceLinkPersistence.class)
1903 protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
1904 private static final String _SQL_SELECT_PORTLETPREFERENCES = "SELECT portletPreferences FROM PortletPreferences portletPreferences";
1905 private static final String _SQL_SELECT_PORTLETPREFERENCES_WHERE = "SELECT portletPreferences FROM PortletPreferences portletPreferences WHERE ";
1906 private static final String _SQL_COUNT_PORTLETPREFERENCES = "SELECT COUNT(portletPreferences) FROM PortletPreferences portletPreferences";
1907 private static final String _SQL_COUNT_PORTLETPREFERENCES_WHERE = "SELECT COUNT(portletPreferences) FROM PortletPreferences portletPreferences WHERE ";
1908 private static final String _FINDER_COLUMN_PLID_PLID_2 = "portletPreferences.plid = ?";
1909 private static final String _FINDER_COLUMN_P_P_PLID_2 = "portletPreferences.plid = ? AND ";
1910 private static final String _FINDER_COLUMN_P_P_PORTLETID_1 = "portletPreferences.portletId IS NULL";
1911 private static final String _FINDER_COLUMN_P_P_PORTLETID_2 = "portletPreferences.portletId = ?";
1912 private static final String _FINDER_COLUMN_P_P_PORTLETID_3 = "(portletPreferences.portletId IS NULL OR portletPreferences.portletId = ?)";
1913 private static final String _FINDER_COLUMN_O_O_P_OWNERID_2 = "portletPreferences.ownerId = ? AND ";
1914 private static final String _FINDER_COLUMN_O_O_P_OWNERTYPE_2 = "portletPreferences.ownerType = ? AND ";
1915 private static final String _FINDER_COLUMN_O_O_P_PLID_2 = "portletPreferences.plid = ?";
1916 private static final String _FINDER_COLUMN_O_O_P_P_OWNERID_2 = "portletPreferences.ownerId = ? AND ";
1917 private static final String _FINDER_COLUMN_O_O_P_P_OWNERTYPE_2 = "portletPreferences.ownerType = ? AND ";
1918 private static final String _FINDER_COLUMN_O_O_P_P_PLID_2 = "portletPreferences.plid = ? AND ";
1919 private static final String _FINDER_COLUMN_O_O_P_P_PORTLETID_1 = "portletPreferences.portletId IS NULL";
1920 private static final String _FINDER_COLUMN_O_O_P_P_PORTLETID_2 = "portletPreferences.portletId = ?";
1921 private static final String _FINDER_COLUMN_O_O_P_P_PORTLETID_3 = "(portletPreferences.portletId IS NULL OR portletPreferences.portletId = ?)";
1922 private static final String _ORDER_BY_ENTITY_ALIAS = "portletPreferences.";
1923 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No PortletPreferences exists with the primary key ";
1924 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No PortletPreferences exists with the key {";
1925 private static Log _log = LogFactoryUtil.getLog(PortletPreferencesPersistenceImpl.class);
1926 }