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