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