1
14
15 package com.liferay.portal.service.persistence;
16
17 import com.liferay.portal.NoSuchModelException;
18 import com.liferay.portal.NoSuchPortletException;
19 import com.liferay.portal.SystemException;
20 import com.liferay.portal.kernel.annotation.BeanReference;
21 import com.liferay.portal.kernel.cache.CacheRegistry;
22 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
23 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
24 import com.liferay.portal.kernel.dao.orm.FinderPath;
25 import com.liferay.portal.kernel.dao.orm.Query;
26 import com.liferay.portal.kernel.dao.orm.QueryPos;
27 import com.liferay.portal.kernel.dao.orm.QueryUtil;
28 import com.liferay.portal.kernel.dao.orm.Session;
29 import com.liferay.portal.kernel.log.Log;
30 import com.liferay.portal.kernel.log.LogFactoryUtil;
31 import com.liferay.portal.kernel.util.GetterUtil;
32 import com.liferay.portal.kernel.util.InstanceFactory;
33 import com.liferay.portal.kernel.util.OrderByComparator;
34 import com.liferay.portal.kernel.util.StringBundler;
35 import com.liferay.portal.kernel.util.StringPool;
36 import com.liferay.portal.kernel.util.StringUtil;
37 import com.liferay.portal.kernel.util.Validator;
38 import com.liferay.portal.model.ModelListener;
39 import com.liferay.portal.model.Portlet;
40 import com.liferay.portal.model.impl.PortletImpl;
41 import com.liferay.portal.model.impl.PortletModelImpl;
42 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
43
44 import java.io.Serializable;
45
46 import java.util.ArrayList;
47 import java.util.Collections;
48 import java.util.List;
49
50
63 public class PortletPersistenceImpl extends BasePersistenceImpl<Portlet>
64 implements PortletPersistence {
65 public static final String FINDER_CLASS_NAME_ENTITY = PortletImpl.class.getName();
66 public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
67 ".List";
68 public static final FinderPath FINDER_PATH_FIND_BY_COMPANYID = new FinderPath(PortletModelImpl.ENTITY_CACHE_ENABLED,
69 PortletModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
70 "findByCompanyId",
71 new String[] {
72 Long.class.getName(),
73
74 "java.lang.Integer", "java.lang.Integer",
75 "com.liferay.portal.kernel.util.OrderByComparator"
76 });
77 public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(PortletModelImpl.ENTITY_CACHE_ENABLED,
78 PortletModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
79 "countByCompanyId", new String[] { Long.class.getName() });
80 public static final FinderPath FINDER_PATH_FETCH_BY_C_P = new FinderPath(PortletModelImpl.ENTITY_CACHE_ENABLED,
81 PortletModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
82 "fetchByC_P",
83 new String[] { Long.class.getName(), String.class.getName() });
84 public static final FinderPath FINDER_PATH_COUNT_BY_C_P = new FinderPath(PortletModelImpl.ENTITY_CACHE_ENABLED,
85 PortletModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
86 "countByC_P",
87 new String[] { Long.class.getName(), String.class.getName() });
88 public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(PortletModelImpl.ENTITY_CACHE_ENABLED,
89 PortletModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
90 "findAll", new String[0]);
91 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(PortletModelImpl.ENTITY_CACHE_ENABLED,
92 PortletModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
93 "countAll", new String[0]);
94
95 public void cacheResult(Portlet portlet) {
96 EntityCacheUtil.putResult(PortletModelImpl.ENTITY_CACHE_ENABLED,
97 PortletImpl.class, portlet.getPrimaryKey(), portlet);
98
99 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_P,
100 new Object[] {
101 new Long(portlet.getCompanyId()),
102
103 portlet.getPortletId()
104 }, portlet);
105 }
106
107 public void cacheResult(List<Portlet> portlets) {
108 for (Portlet portlet : portlets) {
109 if (EntityCacheUtil.getResult(
110 PortletModelImpl.ENTITY_CACHE_ENABLED,
111 PortletImpl.class, portlet.getPrimaryKey(), this) == null) {
112 cacheResult(portlet);
113 }
114 }
115 }
116
117 public void clearCache() {
118 CacheRegistry.clear(PortletImpl.class.getName());
119 EntityCacheUtil.clearCache(PortletImpl.class.getName());
120 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
121 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
122 }
123
124 public void clearCache(Portlet portlet) {
125 EntityCacheUtil.removeResult(PortletModelImpl.ENTITY_CACHE_ENABLED,
126 PortletImpl.class, portlet.getPrimaryKey());
127
128 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_P,
129 new Object[] {
130 new Long(portlet.getCompanyId()),
131
132 portlet.getPortletId()
133 });
134 }
135
136 public Portlet create(long id) {
137 Portlet portlet = new PortletImpl();
138
139 portlet.setNew(true);
140 portlet.setPrimaryKey(id);
141
142 return portlet;
143 }
144
145 public Portlet remove(Serializable primaryKey)
146 throws NoSuchModelException, SystemException {
147 return remove(((Long)primaryKey).longValue());
148 }
149
150 public Portlet remove(long id)
151 throws NoSuchPortletException, SystemException {
152 Session session = null;
153
154 try {
155 session = openSession();
156
157 Portlet portlet = (Portlet)session.get(PortletImpl.class,
158 new Long(id));
159
160 if (portlet == null) {
161 if (_log.isWarnEnabled()) {
162 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + id);
163 }
164
165 throw new NoSuchPortletException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
166 id);
167 }
168
169 return remove(portlet);
170 }
171 catch (NoSuchPortletException nsee) {
172 throw nsee;
173 }
174 catch (Exception e) {
175 throw processException(e);
176 }
177 finally {
178 closeSession(session);
179 }
180 }
181
182 protected Portlet removeImpl(Portlet portlet) throws SystemException {
183 portlet = toUnwrappedModel(portlet);
184
185 Session session = null;
186
187 try {
188 session = openSession();
189
190 BatchSessionUtil.delete(session, portlet);
191 }
192 catch (Exception e) {
193 throw processException(e);
194 }
195 finally {
196 closeSession(session);
197 }
198
199 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
200
201 PortletModelImpl portletModelImpl = (PortletModelImpl)portlet;
202
203 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_P,
204 new Object[] {
205 new Long(portletModelImpl.getOriginalCompanyId()),
206
207 portletModelImpl.getOriginalPortletId()
208 });
209
210 EntityCacheUtil.removeResult(PortletModelImpl.ENTITY_CACHE_ENABLED,
211 PortletImpl.class, portlet.getPrimaryKey());
212
213 return portlet;
214 }
215
216
219 public Portlet update(Portlet portlet) throws SystemException {
220 if (_log.isWarnEnabled()) {
221 _log.warn(
222 "Using the deprecated update(Portlet portlet) method. Use update(Portlet portlet, boolean merge) instead.");
223 }
224
225 return update(portlet, false);
226 }
227
228 public Portlet updateImpl(com.liferay.portal.model.Portlet portlet,
229 boolean merge) throws SystemException {
230 portlet = toUnwrappedModel(portlet);
231
232 boolean isNew = portlet.isNew();
233
234 PortletModelImpl portletModelImpl = (PortletModelImpl)portlet;
235
236 Session session = null;
237
238 try {
239 session = openSession();
240
241 BatchSessionUtil.update(session, portlet, merge);
242
243 portlet.setNew(false);
244 }
245 catch (Exception e) {
246 throw processException(e);
247 }
248 finally {
249 closeSession(session);
250 }
251
252 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
253
254 EntityCacheUtil.putResult(PortletModelImpl.ENTITY_CACHE_ENABLED,
255 PortletImpl.class, portlet.getPrimaryKey(), portlet);
256
257 if (!isNew &&
258 ((portlet.getCompanyId() != portletModelImpl.getOriginalCompanyId()) ||
259 !Validator.equals(portlet.getPortletId(),
260 portletModelImpl.getOriginalPortletId()))) {
261 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_P,
262 new Object[] {
263 new Long(portletModelImpl.getOriginalCompanyId()),
264
265 portletModelImpl.getOriginalPortletId()
266 });
267 }
268
269 if (isNew ||
270 ((portlet.getCompanyId() != portletModelImpl.getOriginalCompanyId()) ||
271 !Validator.equals(portlet.getPortletId(),
272 portletModelImpl.getOriginalPortletId()))) {
273 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_P,
274 new Object[] {
275 new Long(portlet.getCompanyId()),
276
277 portlet.getPortletId()
278 }, portlet);
279 }
280
281 return portlet;
282 }
283
284 protected Portlet toUnwrappedModel(Portlet portlet) {
285 if (portlet instanceof PortletImpl) {
286 return portlet;
287 }
288
289 PortletImpl portletImpl = new PortletImpl();
290
291 portletImpl.setNew(portlet.isNew());
292 portletImpl.setPrimaryKey(portlet.getPrimaryKey());
293
294 portletImpl.setId(portlet.getId());
295 portletImpl.setCompanyId(portlet.getCompanyId());
296 portletImpl.setPortletId(portlet.getPortletId());
297 portletImpl.setRoles(portlet.getRoles());
298 portletImpl.setActive(portlet.isActive());
299
300 return portletImpl;
301 }
302
303 public Portlet findByPrimaryKey(Serializable primaryKey)
304 throws NoSuchModelException, SystemException {
305 return findByPrimaryKey(((Long)primaryKey).longValue());
306 }
307
308 public Portlet findByPrimaryKey(long id)
309 throws NoSuchPortletException, SystemException {
310 Portlet portlet = fetchByPrimaryKey(id);
311
312 if (portlet == null) {
313 if (_log.isWarnEnabled()) {
314 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + id);
315 }
316
317 throw new NoSuchPortletException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
318 id);
319 }
320
321 return portlet;
322 }
323
324 public Portlet fetchByPrimaryKey(Serializable primaryKey)
325 throws SystemException {
326 return fetchByPrimaryKey(((Long)primaryKey).longValue());
327 }
328
329 public Portlet fetchByPrimaryKey(long id) throws SystemException {
330 Portlet portlet = (Portlet)EntityCacheUtil.getResult(PortletModelImpl.ENTITY_CACHE_ENABLED,
331 PortletImpl.class, id, this);
332
333 if (portlet == null) {
334 Session session = null;
335
336 try {
337 session = openSession();
338
339 portlet = (Portlet)session.get(PortletImpl.class, new Long(id));
340 }
341 catch (Exception e) {
342 throw processException(e);
343 }
344 finally {
345 if (portlet != null) {
346 cacheResult(portlet);
347 }
348
349 closeSession(session);
350 }
351 }
352
353 return portlet;
354 }
355
356 public List<Portlet> findByCompanyId(long companyId)
357 throws SystemException {
358 return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
359 null);
360 }
361
362 public List<Portlet> findByCompanyId(long companyId, int start, int end)
363 throws SystemException {
364 return findByCompanyId(companyId, start, end, null);
365 }
366
367 public List<Portlet> findByCompanyId(long companyId, int start, int end,
368 OrderByComparator orderByComparator) throws SystemException {
369 Object[] finderArgs = new Object[] {
370 companyId,
371
372 String.valueOf(start), String.valueOf(end),
373 String.valueOf(orderByComparator)
374 };
375
376 List<Portlet> list = (List<Portlet>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_COMPANYID,
377 finderArgs, this);
378
379 if (list == null) {
380 StringBundler query = null;
381
382 if (orderByComparator != null) {
383 query = new StringBundler(3 +
384 (orderByComparator.getOrderByFields().length * 3));
385 }
386 else {
387 query = new StringBundler(2);
388 }
389
390 query.append(_SQL_SELECT_PORTLET_WHERE);
391
392 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
393
394 if (orderByComparator != null) {
395 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
396 orderByComparator);
397 }
398
399 String sql = query.toString();
400
401 Session session = null;
402
403 try {
404 session = openSession();
405
406 Query q = session.createQuery(sql);
407
408 QueryPos qPos = QueryPos.getInstance(q);
409
410 qPos.add(companyId);
411
412 list = (List<Portlet>)QueryUtil.list(q, getDialect(), start, end);
413 }
414 catch (Exception e) {
415 throw processException(e);
416 }
417 finally {
418 if (list == null) {
419 list = new ArrayList<Portlet>();
420 }
421
422 cacheResult(list);
423
424 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_COMPANYID,
425 finderArgs, list);
426
427 closeSession(session);
428 }
429 }
430
431 return list;
432 }
433
434 public Portlet findByCompanyId_First(long companyId,
435 OrderByComparator orderByComparator)
436 throws NoSuchPortletException, SystemException {
437 List<Portlet> list = findByCompanyId(companyId, 0, 1, orderByComparator);
438
439 if (list.isEmpty()) {
440 StringBundler msg = new StringBundler(4);
441
442 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
443
444 msg.append("companyId=");
445 msg.append(companyId);
446
447 msg.append(StringPool.CLOSE_CURLY_BRACE);
448
449 throw new NoSuchPortletException(msg.toString());
450 }
451 else {
452 return list.get(0);
453 }
454 }
455
456 public Portlet findByCompanyId_Last(long companyId,
457 OrderByComparator orderByComparator)
458 throws NoSuchPortletException, SystemException {
459 int count = countByCompanyId(companyId);
460
461 List<Portlet> list = findByCompanyId(companyId, count - 1, count,
462 orderByComparator);
463
464 if (list.isEmpty()) {
465 StringBundler msg = new StringBundler(4);
466
467 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
468
469 msg.append("companyId=");
470 msg.append(companyId);
471
472 msg.append(StringPool.CLOSE_CURLY_BRACE);
473
474 throw new NoSuchPortletException(msg.toString());
475 }
476 else {
477 return list.get(0);
478 }
479 }
480
481 public Portlet[] findByCompanyId_PrevAndNext(long id, long companyId,
482 OrderByComparator orderByComparator)
483 throws NoSuchPortletException, SystemException {
484 Portlet portlet = findByPrimaryKey(id);
485
486 Session session = null;
487
488 try {
489 session = openSession();
490
491 Portlet[] array = new PortletImpl[3];
492
493 array[0] = getByCompanyId_PrevAndNext(session, portlet, companyId,
494 orderByComparator, true);
495
496 array[1] = portlet;
497
498 array[2] = getByCompanyId_PrevAndNext(session, portlet, companyId,
499 orderByComparator, false);
500
501 return array;
502 }
503 catch (Exception e) {
504 throw processException(e);
505 }
506 finally {
507 closeSession(session);
508 }
509 }
510
511 protected Portlet getByCompanyId_PrevAndNext(Session session,
512 Portlet portlet, long companyId, OrderByComparator orderByComparator,
513 boolean previous) {
514 StringBundler query = null;
515
516 if (orderByComparator != null) {
517 query = new StringBundler(6 +
518 (orderByComparator.getOrderByFields().length * 6));
519 }
520 else {
521 query = new StringBundler(3);
522 }
523
524 query.append(_SQL_SELECT_PORTLET_WHERE);
525
526 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
527
528 if (orderByComparator != null) {
529 String[] orderByFields = orderByComparator.getOrderByFields();
530
531 if (orderByFields.length > 0) {
532 query.append(WHERE_AND);
533 }
534
535 for (int i = 0; i < orderByFields.length; i++) {
536 query.append(_ORDER_BY_ENTITY_ALIAS);
537 query.append(orderByFields[i]);
538
539 if ((i + 1) < orderByFields.length) {
540 if (orderByComparator.isAscending() ^ previous) {
541 query.append(WHERE_GREATER_THAN_HAS_NEXT);
542 }
543 else {
544 query.append(WHERE_LESSER_THAN_HAS_NEXT);
545 }
546 }
547 else {
548 if (orderByComparator.isAscending() ^ previous) {
549 query.append(WHERE_GREATER_THAN);
550 }
551 else {
552 query.append(WHERE_LESSER_THAN);
553 }
554 }
555 }
556
557 query.append(ORDER_BY_CLAUSE);
558
559 for (int i = 0; i < orderByFields.length; i++) {
560 query.append(_ORDER_BY_ENTITY_ALIAS);
561 query.append(orderByFields[i]);
562
563 if ((i + 1) < orderByFields.length) {
564 if (orderByComparator.isAscending() ^ previous) {
565 query.append(ORDER_BY_ASC_HAS_NEXT);
566 }
567 else {
568 query.append(ORDER_BY_DESC_HAS_NEXT);
569 }
570 }
571 else {
572 if (orderByComparator.isAscending() ^ previous) {
573 query.append(ORDER_BY_ASC);
574 }
575 else {
576 query.append(ORDER_BY_DESC);
577 }
578 }
579 }
580 }
581
582 String sql = query.toString();
583
584 Query q = session.createQuery(sql);
585
586 q.setFirstResult(0);
587 q.setMaxResults(2);
588
589 QueryPos qPos = QueryPos.getInstance(q);
590
591 qPos.add(companyId);
592
593 if (orderByComparator != null) {
594 Object[] values = orderByComparator.getOrderByValues(portlet);
595
596 for (Object value : values) {
597 qPos.add(value);
598 }
599 }
600
601 List<Portlet> list = q.list();
602
603 if (list.size() == 2) {
604 return list.get(1);
605 }
606 else {
607 return null;
608 }
609 }
610
611 public Portlet findByC_P(long companyId, String portletId)
612 throws NoSuchPortletException, SystemException {
613 Portlet portlet = fetchByC_P(companyId, portletId);
614
615 if (portlet == null) {
616 StringBundler msg = new StringBundler(6);
617
618 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
619
620 msg.append("companyId=");
621 msg.append(companyId);
622
623 msg.append(", portletId=");
624 msg.append(portletId);
625
626 msg.append(StringPool.CLOSE_CURLY_BRACE);
627
628 if (_log.isWarnEnabled()) {
629 _log.warn(msg.toString());
630 }
631
632 throw new NoSuchPortletException(msg.toString());
633 }
634
635 return portlet;
636 }
637
638 public Portlet fetchByC_P(long companyId, String portletId)
639 throws SystemException {
640 return fetchByC_P(companyId, portletId, true);
641 }
642
643 public Portlet fetchByC_P(long companyId, String portletId,
644 boolean retrieveFromCache) throws SystemException {
645 Object[] finderArgs = new Object[] { companyId, portletId };
646
647 Object result = null;
648
649 if (retrieveFromCache) {
650 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_P,
651 finderArgs, this);
652 }
653
654 if (result == null) {
655 StringBundler query = new StringBundler(3);
656
657 query.append(_SQL_SELECT_PORTLET_WHERE);
658
659 query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
660
661 if (portletId == null) {
662 query.append(_FINDER_COLUMN_C_P_PORTLETID_1);
663 }
664 else {
665 if (portletId.equals(StringPool.BLANK)) {
666 query.append(_FINDER_COLUMN_C_P_PORTLETID_3);
667 }
668 else {
669 query.append(_FINDER_COLUMN_C_P_PORTLETID_2);
670 }
671 }
672
673 String sql = query.toString();
674
675 Session session = null;
676
677 try {
678 session = openSession();
679
680 Query q = session.createQuery(sql);
681
682 QueryPos qPos = QueryPos.getInstance(q);
683
684 qPos.add(companyId);
685
686 if (portletId != null) {
687 qPos.add(portletId);
688 }
689
690 List<Portlet> list = q.list();
691
692 result = list;
693
694 Portlet portlet = null;
695
696 if (list.isEmpty()) {
697 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_P,
698 finderArgs, list);
699 }
700 else {
701 portlet = list.get(0);
702
703 cacheResult(portlet);
704
705 if ((portlet.getCompanyId() != companyId) ||
706 (portlet.getPortletId() == null) ||
707 !portlet.getPortletId().equals(portletId)) {
708 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_P,
709 finderArgs, portlet);
710 }
711 }
712
713 return portlet;
714 }
715 catch (Exception e) {
716 throw processException(e);
717 }
718 finally {
719 if (result == null) {
720 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_P,
721 finderArgs, new ArrayList<Portlet>());
722 }
723
724 closeSession(session);
725 }
726 }
727 else {
728 if (result instanceof List<?>) {
729 return null;
730 }
731 else {
732 return (Portlet)result;
733 }
734 }
735 }
736
737 public List<Portlet> findAll() throws SystemException {
738 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
739 }
740
741 public List<Portlet> findAll(int start, int end) throws SystemException {
742 return findAll(start, end, null);
743 }
744
745 public List<Portlet> findAll(int start, int end,
746 OrderByComparator orderByComparator) throws SystemException {
747 Object[] finderArgs = new Object[] {
748 String.valueOf(start), String.valueOf(end),
749 String.valueOf(orderByComparator)
750 };
751
752 List<Portlet> list = (List<Portlet>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
753 finderArgs, this);
754
755 if (list == null) {
756 StringBundler query = null;
757 String sql = null;
758
759 if (orderByComparator != null) {
760 query = new StringBundler(2 +
761 (orderByComparator.getOrderByFields().length * 3));
762
763 query.append(_SQL_SELECT_PORTLET);
764
765 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
766 orderByComparator);
767
768 sql = query.toString();
769 }
770 else {
771 sql = _SQL_SELECT_PORTLET;
772 }
773
774 Session session = null;
775
776 try {
777 session = openSession();
778
779 Query q = session.createQuery(sql);
780
781 if (orderByComparator == null) {
782 list = (List<Portlet>)QueryUtil.list(q, getDialect(),
783 start, end, false);
784
785 Collections.sort(list);
786 }
787 else {
788 list = (List<Portlet>)QueryUtil.list(q, getDialect(),
789 start, end);
790 }
791 }
792 catch (Exception e) {
793 throw processException(e);
794 }
795 finally {
796 if (list == null) {
797 list = new ArrayList<Portlet>();
798 }
799
800 cacheResult(list);
801
802 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
803
804 closeSession(session);
805 }
806 }
807
808 return list;
809 }
810
811 public void removeByCompanyId(long companyId) throws SystemException {
812 for (Portlet portlet : findByCompanyId(companyId)) {
813 remove(portlet);
814 }
815 }
816
817 public void removeByC_P(long companyId, String portletId)
818 throws NoSuchPortletException, SystemException {
819 Portlet portlet = findByC_P(companyId, portletId);
820
821 remove(portlet);
822 }
823
824 public void removeAll() throws SystemException {
825 for (Portlet portlet : findAll()) {
826 remove(portlet);
827 }
828 }
829
830 public int countByCompanyId(long companyId) throws SystemException {
831 Object[] finderArgs = new Object[] { companyId };
832
833 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
834 finderArgs, this);
835
836 if (count == null) {
837 StringBundler query = new StringBundler(2);
838
839 query.append(_SQL_COUNT_PORTLET_WHERE);
840
841 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
842
843 String sql = query.toString();
844
845 Session session = null;
846
847 try {
848 session = openSession();
849
850 Query q = session.createQuery(sql);
851
852 QueryPos qPos = QueryPos.getInstance(q);
853
854 qPos.add(companyId);
855
856 count = (Long)q.uniqueResult();
857 }
858 catch (Exception e) {
859 throw processException(e);
860 }
861 finally {
862 if (count == null) {
863 count = Long.valueOf(0);
864 }
865
866 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
867 finderArgs, count);
868
869 closeSession(session);
870 }
871 }
872
873 return count.intValue();
874 }
875
876 public int countByC_P(long companyId, String portletId)
877 throws SystemException {
878 Object[] finderArgs = new Object[] { companyId, portletId };
879
880 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_P,
881 finderArgs, this);
882
883 if (count == null) {
884 StringBundler query = new StringBundler(3);
885
886 query.append(_SQL_COUNT_PORTLET_WHERE);
887
888 query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
889
890 if (portletId == null) {
891 query.append(_FINDER_COLUMN_C_P_PORTLETID_1);
892 }
893 else {
894 if (portletId.equals(StringPool.BLANK)) {
895 query.append(_FINDER_COLUMN_C_P_PORTLETID_3);
896 }
897 else {
898 query.append(_FINDER_COLUMN_C_P_PORTLETID_2);
899 }
900 }
901
902 String sql = query.toString();
903
904 Session session = null;
905
906 try {
907 session = openSession();
908
909 Query q = session.createQuery(sql);
910
911 QueryPos qPos = QueryPos.getInstance(q);
912
913 qPos.add(companyId);
914
915 if (portletId != null) {
916 qPos.add(portletId);
917 }
918
919 count = (Long)q.uniqueResult();
920 }
921 catch (Exception e) {
922 throw processException(e);
923 }
924 finally {
925 if (count == null) {
926 count = Long.valueOf(0);
927 }
928
929 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_P, finderArgs,
930 count);
931
932 closeSession(session);
933 }
934 }
935
936 return count.intValue();
937 }
938
939 public int countAll() throws SystemException {
940 Object[] finderArgs = new Object[0];
941
942 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
943 finderArgs, this);
944
945 if (count == null) {
946 Session session = null;
947
948 try {
949 session = openSession();
950
951 Query q = session.createQuery(_SQL_COUNT_PORTLET);
952
953 count = (Long)q.uniqueResult();
954 }
955 catch (Exception e) {
956 throw processException(e);
957 }
958 finally {
959 if (count == null) {
960 count = Long.valueOf(0);
961 }
962
963 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
964 count);
965
966 closeSession(session);
967 }
968 }
969
970 return count.intValue();
971 }
972
973 public void afterPropertiesSet() {
974 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
975 com.liferay.portal.util.PropsUtil.get(
976 "value.object.listener.com.liferay.portal.model.Portlet")));
977
978 if (listenerClassNames.length > 0) {
979 try {
980 List<ModelListener<Portlet>> listenersList = new ArrayList<ModelListener<Portlet>>();
981
982 for (String listenerClassName : listenerClassNames) {
983 listenersList.add((ModelListener<Portlet>)InstanceFactory.newInstance(
984 listenerClassName));
985 }
986
987 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
988 }
989 catch (Exception e) {
990 _log.error(e);
991 }
992 }
993 }
994
995 public void destroy() {
996 EntityCacheUtil.removeCache(PortletImpl.class.getName());
997 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
998 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
999 }
1000
1001 @BeanReference(type = AccountPersistence.class)
1002 protected AccountPersistence accountPersistence;
1003 @BeanReference(type = AddressPersistence.class)
1004 protected AddressPersistence addressPersistence;
1005 @BeanReference(type = BrowserTrackerPersistence.class)
1006 protected BrowserTrackerPersistence browserTrackerPersistence;
1007 @BeanReference(type = ClassNamePersistence.class)
1008 protected ClassNamePersistence classNamePersistence;
1009 @BeanReference(type = CompanyPersistence.class)
1010 protected CompanyPersistence companyPersistence;
1011 @BeanReference(type = ContactPersistence.class)
1012 protected ContactPersistence contactPersistence;
1013 @BeanReference(type = CountryPersistence.class)
1014 protected CountryPersistence countryPersistence;
1015 @BeanReference(type = EmailAddressPersistence.class)
1016 protected EmailAddressPersistence emailAddressPersistence;
1017 @BeanReference(type = GroupPersistence.class)
1018 protected GroupPersistence groupPersistence;
1019 @BeanReference(type = ImagePersistence.class)
1020 protected ImagePersistence imagePersistence;
1021 @BeanReference(type = LayoutPersistence.class)
1022 protected LayoutPersistence layoutPersistence;
1023 @BeanReference(type = LayoutSetPersistence.class)
1024 protected LayoutSetPersistence layoutSetPersistence;
1025 @BeanReference(type = ListTypePersistence.class)
1026 protected ListTypePersistence listTypePersistence;
1027 @BeanReference(type = LockPersistence.class)
1028 protected LockPersistence lockPersistence;
1029 @BeanReference(type = MembershipRequestPersistence.class)
1030 protected MembershipRequestPersistence membershipRequestPersistence;
1031 @BeanReference(type = OrganizationPersistence.class)
1032 protected OrganizationPersistence organizationPersistence;
1033 @BeanReference(type = OrgGroupPermissionPersistence.class)
1034 protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1035 @BeanReference(type = OrgGroupRolePersistence.class)
1036 protected OrgGroupRolePersistence orgGroupRolePersistence;
1037 @BeanReference(type = OrgLaborPersistence.class)
1038 protected OrgLaborPersistence orgLaborPersistence;
1039 @BeanReference(type = PasswordPolicyPersistence.class)
1040 protected PasswordPolicyPersistence passwordPolicyPersistence;
1041 @BeanReference(type = PasswordPolicyRelPersistence.class)
1042 protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1043 @BeanReference(type = PasswordTrackerPersistence.class)
1044 protected PasswordTrackerPersistence passwordTrackerPersistence;
1045 @BeanReference(type = PermissionPersistence.class)
1046 protected PermissionPersistence permissionPersistence;
1047 @BeanReference(type = PhonePersistence.class)
1048 protected PhonePersistence phonePersistence;
1049 @BeanReference(type = PluginSettingPersistence.class)
1050 protected PluginSettingPersistence pluginSettingPersistence;
1051 @BeanReference(type = PortletPersistence.class)
1052 protected PortletPersistence portletPersistence;
1053 @BeanReference(type = PortletItemPersistence.class)
1054 protected PortletItemPersistence portletItemPersistence;
1055 @BeanReference(type = PortletPreferencesPersistence.class)
1056 protected PortletPreferencesPersistence portletPreferencesPersistence;
1057 @BeanReference(type = RegionPersistence.class)
1058 protected RegionPersistence regionPersistence;
1059 @BeanReference(type = ReleasePersistence.class)
1060 protected ReleasePersistence releasePersistence;
1061 @BeanReference(type = ResourcePersistence.class)
1062 protected ResourcePersistence resourcePersistence;
1063 @BeanReference(type = ResourceActionPersistence.class)
1064 protected ResourceActionPersistence resourceActionPersistence;
1065 @BeanReference(type = ResourceCodePersistence.class)
1066 protected ResourceCodePersistence resourceCodePersistence;
1067 @BeanReference(type = ResourcePermissionPersistence.class)
1068 protected ResourcePermissionPersistence resourcePermissionPersistence;
1069 @BeanReference(type = RolePersistence.class)
1070 protected RolePersistence rolePersistence;
1071 @BeanReference(type = ServiceComponentPersistence.class)
1072 protected ServiceComponentPersistence serviceComponentPersistence;
1073 @BeanReference(type = ShardPersistence.class)
1074 protected ShardPersistence shardPersistence;
1075 @BeanReference(type = SubscriptionPersistence.class)
1076 protected SubscriptionPersistence subscriptionPersistence;
1077 @BeanReference(type = UserPersistence.class)
1078 protected UserPersistence userPersistence;
1079 @BeanReference(type = UserGroupPersistence.class)
1080 protected UserGroupPersistence userGroupPersistence;
1081 @BeanReference(type = UserGroupGroupRolePersistence.class)
1082 protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
1083 @BeanReference(type = UserGroupRolePersistence.class)
1084 protected UserGroupRolePersistence userGroupRolePersistence;
1085 @BeanReference(type = UserIdMapperPersistence.class)
1086 protected UserIdMapperPersistence userIdMapperPersistence;
1087 @BeanReference(type = UserTrackerPersistence.class)
1088 protected UserTrackerPersistence userTrackerPersistence;
1089 @BeanReference(type = UserTrackerPathPersistence.class)
1090 protected UserTrackerPathPersistence userTrackerPathPersistence;
1091 @BeanReference(type = WebDAVPropsPersistence.class)
1092 protected WebDAVPropsPersistence webDAVPropsPersistence;
1093 @BeanReference(type = WebsitePersistence.class)
1094 protected WebsitePersistence websitePersistence;
1095 private static final String _SQL_SELECT_PORTLET = "SELECT portlet FROM Portlet portlet";
1096 private static final String _SQL_SELECT_PORTLET_WHERE = "SELECT portlet FROM Portlet portlet WHERE ";
1097 private static final String _SQL_COUNT_PORTLET = "SELECT COUNT(portlet) FROM Portlet portlet";
1098 private static final String _SQL_COUNT_PORTLET_WHERE = "SELECT COUNT(portlet) FROM Portlet portlet WHERE ";
1099 private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "portlet.companyId = ?";
1100 private static final String _FINDER_COLUMN_C_P_COMPANYID_2 = "portlet.companyId = ? AND ";
1101 private static final String _FINDER_COLUMN_C_P_PORTLETID_1 = "portlet.portletId IS NULL";
1102 private static final String _FINDER_COLUMN_C_P_PORTLETID_2 = "portlet.portletId = ?";
1103 private static final String _FINDER_COLUMN_C_P_PORTLETID_3 = "(portlet.portletId IS NULL OR portlet.portletId = ?)";
1104 private static final String _ORDER_BY_ENTITY_ALIAS = "portlet.";
1105 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Portlet exists with the primary key ";
1106 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Portlet exists with the key {";
1107 private static Log _log = LogFactoryUtil.getLog(PortletPersistenceImpl.class);
1108}