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