001
014
015 package com.liferay.portal.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
018 import com.liferay.portal.NoSuchPortletException;
019 import com.liferay.portal.kernel.annotation.BeanReference;
020 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
021 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
023 import com.liferay.portal.kernel.dao.orm.FinderPath;
024 import com.liferay.portal.kernel.dao.orm.Query;
025 import com.liferay.portal.kernel.dao.orm.QueryPos;
026 import com.liferay.portal.kernel.dao.orm.QueryUtil;
027 import com.liferay.portal.kernel.dao.orm.Session;
028 import com.liferay.portal.kernel.exception.SystemException;
029 import com.liferay.portal.kernel.log.Log;
030 import com.liferay.portal.kernel.log.LogFactoryUtil;
031 import com.liferay.portal.kernel.util.GetterUtil;
032 import com.liferay.portal.kernel.util.InstanceFactory;
033 import com.liferay.portal.kernel.util.OrderByComparator;
034 import com.liferay.portal.kernel.util.StringBundler;
035 import com.liferay.portal.kernel.util.StringPool;
036 import com.liferay.portal.kernel.util.StringUtil;
037 import com.liferay.portal.kernel.util.Validator;
038 import com.liferay.portal.model.ModelListener;
039 import com.liferay.portal.model.Portlet;
040 import com.liferay.portal.model.impl.PortletImpl;
041 import com.liferay.portal.model.impl.PortletModelImpl;
042 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
043
044 import java.io.Serializable;
045
046 import java.util.ArrayList;
047 import java.util.Collections;
048 import java.util.List;
049
050
066 public class PortletPersistenceImpl extends BasePersistenceImpl<Portlet>
067 implements PortletPersistence {
068 public static final String FINDER_CLASS_NAME_ENTITY = PortletImpl.class.getName();
069 public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
070 ".List";
071 public static final FinderPath FINDER_PATH_FIND_BY_COMPANYID = new FinderPath(PortletModelImpl.ENTITY_CACHE_ENABLED,
072 PortletModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
073 "findByCompanyId",
074 new String[] {
075 Long.class.getName(),
076
077 "java.lang.Integer", "java.lang.Integer",
078 "com.liferay.portal.kernel.util.OrderByComparator"
079 });
080 public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(PortletModelImpl.ENTITY_CACHE_ENABLED,
081 PortletModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
082 "countByCompanyId", new String[] { Long.class.getName() });
083 public static final FinderPath FINDER_PATH_FETCH_BY_C_P = new FinderPath(PortletModelImpl.ENTITY_CACHE_ENABLED,
084 PortletModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
085 "fetchByC_P",
086 new String[] { Long.class.getName(), String.class.getName() });
087 public static final FinderPath FINDER_PATH_COUNT_BY_C_P = new FinderPath(PortletModelImpl.ENTITY_CACHE_ENABLED,
088 PortletModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
089 "countByC_P",
090 new String[] { Long.class.getName(), String.class.getName() });
091 public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(PortletModelImpl.ENTITY_CACHE_ENABLED,
092 PortletModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
093 "findAll", new String[0]);
094 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(PortletModelImpl.ENTITY_CACHE_ENABLED,
095 PortletModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
096 "countAll", new String[0]);
097
098
103 public void cacheResult(Portlet portlet) {
104 EntityCacheUtil.putResult(PortletModelImpl.ENTITY_CACHE_ENABLED,
105 PortletImpl.class, portlet.getPrimaryKey(), portlet);
106
107 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_P,
108 new Object[] {
109 new Long(portlet.getCompanyId()),
110
111 portlet.getPortletId()
112 }, portlet);
113 }
114
115
120 public void cacheResult(List<Portlet> portlets) {
121 for (Portlet portlet : portlets) {
122 if (EntityCacheUtil.getResult(
123 PortletModelImpl.ENTITY_CACHE_ENABLED,
124 PortletImpl.class, portlet.getPrimaryKey(), this) == null) {
125 cacheResult(portlet);
126 }
127 }
128 }
129
130
137 public void clearCache() {
138 CacheRegistryUtil.clear(PortletImpl.class.getName());
139 EntityCacheUtil.clearCache(PortletImpl.class.getName());
140 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
141 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
142 }
143
144
151 public void clearCache(Portlet portlet) {
152 EntityCacheUtil.removeResult(PortletModelImpl.ENTITY_CACHE_ENABLED,
153 PortletImpl.class, portlet.getPrimaryKey());
154
155 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_P,
156 new Object[] {
157 new Long(portlet.getCompanyId()),
158
159 portlet.getPortletId()
160 });
161 }
162
163
169 public Portlet create(long id) {
170 Portlet portlet = new PortletImpl();
171
172 portlet.setNew(true);
173 portlet.setPrimaryKey(id);
174
175 return portlet;
176 }
177
178
186 public Portlet remove(Serializable primaryKey)
187 throws NoSuchModelException, SystemException {
188 return remove(((Long)primaryKey).longValue());
189 }
190
191
199 public Portlet remove(long id)
200 throws NoSuchPortletException, SystemException {
201 Session session = null;
202
203 try {
204 session = openSession();
205
206 Portlet portlet = (Portlet)session.get(PortletImpl.class,
207 new Long(id));
208
209 if (portlet == null) {
210 if (_log.isWarnEnabled()) {
211 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + id);
212 }
213
214 throw new NoSuchPortletException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
215 id);
216 }
217
218 return remove(portlet);
219 }
220 catch (NoSuchPortletException nsee) {
221 throw nsee;
222 }
223 catch (Exception e) {
224 throw processException(e);
225 }
226 finally {
227 closeSession(session);
228 }
229 }
230
231 protected Portlet removeImpl(Portlet portlet) throws SystemException {
232 portlet = toUnwrappedModel(portlet);
233
234 Session session = null;
235
236 try {
237 session = openSession();
238
239 BatchSessionUtil.delete(session, portlet);
240 }
241 catch (Exception e) {
242 throw processException(e);
243 }
244 finally {
245 closeSession(session);
246 }
247
248 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
249
250 PortletModelImpl portletModelImpl = (PortletModelImpl)portlet;
251
252 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_P,
253 new Object[] {
254 new Long(portletModelImpl.getOriginalCompanyId()),
255
256 portletModelImpl.getOriginalPortletId()
257 });
258
259 EntityCacheUtil.removeResult(PortletModelImpl.ENTITY_CACHE_ENABLED,
260 PortletImpl.class, portlet.getPrimaryKey());
261
262 return portlet;
263 }
264
265 public Portlet updateImpl(com.liferay.portal.model.Portlet portlet,
266 boolean merge) throws SystemException {
267 portlet = toUnwrappedModel(portlet);
268
269 boolean isNew = portlet.isNew();
270
271 PortletModelImpl portletModelImpl = (PortletModelImpl)portlet;
272
273 Session session = null;
274
275 try {
276 session = openSession();
277
278 BatchSessionUtil.update(session, portlet, merge);
279
280 portlet.setNew(false);
281 }
282 catch (Exception e) {
283 throw processException(e);
284 }
285 finally {
286 closeSession(session);
287 }
288
289 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
290
291 EntityCacheUtil.putResult(PortletModelImpl.ENTITY_CACHE_ENABLED,
292 PortletImpl.class, portlet.getPrimaryKey(), portlet);
293
294 if (!isNew &&
295 ((portlet.getCompanyId() != portletModelImpl.getOriginalCompanyId()) ||
296 !Validator.equals(portlet.getPortletId(),
297 portletModelImpl.getOriginalPortletId()))) {
298 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_P,
299 new Object[] {
300 new Long(portletModelImpl.getOriginalCompanyId()),
301
302 portletModelImpl.getOriginalPortletId()
303 });
304 }
305
306 if (isNew ||
307 ((portlet.getCompanyId() != portletModelImpl.getOriginalCompanyId()) ||
308 !Validator.equals(portlet.getPortletId(),
309 portletModelImpl.getOriginalPortletId()))) {
310 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_P,
311 new Object[] {
312 new Long(portlet.getCompanyId()),
313
314 portlet.getPortletId()
315 }, portlet);
316 }
317
318 return portlet;
319 }
320
321 protected Portlet toUnwrappedModel(Portlet portlet) {
322 if (portlet instanceof PortletImpl) {
323 return portlet;
324 }
325
326 PortletImpl portletImpl = new PortletImpl();
327
328 portletImpl.setNew(portlet.isNew());
329 portletImpl.setPrimaryKey(portlet.getPrimaryKey());
330
331 portletImpl.setId(portlet.getId());
332 portletImpl.setCompanyId(portlet.getCompanyId());
333 portletImpl.setPortletId(portlet.getPortletId());
334 portletImpl.setRoles(portlet.getRoles());
335 portletImpl.setActive(portlet.isActive());
336
337 return portletImpl;
338 }
339
340
348 public Portlet findByPrimaryKey(Serializable primaryKey)
349 throws NoSuchModelException, SystemException {
350 return findByPrimaryKey(((Long)primaryKey).longValue());
351 }
352
353
361 public Portlet findByPrimaryKey(long id)
362 throws NoSuchPortletException, SystemException {
363 Portlet portlet = fetchByPrimaryKey(id);
364
365 if (portlet == null) {
366 if (_log.isWarnEnabled()) {
367 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + id);
368 }
369
370 throw new NoSuchPortletException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
371 id);
372 }
373
374 return portlet;
375 }
376
377
384 public Portlet fetchByPrimaryKey(Serializable primaryKey)
385 throws SystemException {
386 return fetchByPrimaryKey(((Long)primaryKey).longValue());
387 }
388
389
396 public Portlet fetchByPrimaryKey(long id) throws SystemException {
397 Portlet portlet = (Portlet)EntityCacheUtil.getResult(PortletModelImpl.ENTITY_CACHE_ENABLED,
398 PortletImpl.class, id, this);
399
400 if (portlet == null) {
401 Session session = null;
402
403 try {
404 session = openSession();
405
406 portlet = (Portlet)session.get(PortletImpl.class, new Long(id));
407 }
408 catch (Exception e) {
409 throw processException(e);
410 }
411 finally {
412 if (portlet != null) {
413 cacheResult(portlet);
414 }
415
416 closeSession(session);
417 }
418 }
419
420 return portlet;
421 }
422
423
430 public List<Portlet> findByCompanyId(long companyId)
431 throws SystemException {
432 return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
433 null);
434 }
435
436
449 public List<Portlet> findByCompanyId(long companyId, int start, int end)
450 throws SystemException {
451 return findByCompanyId(companyId, start, end, null);
452 }
453
454
468 public List<Portlet> findByCompanyId(long companyId, int start, int end,
469 OrderByComparator orderByComparator) throws SystemException {
470 Object[] finderArgs = new Object[] {
471 companyId,
472
473 String.valueOf(start), String.valueOf(end),
474 String.valueOf(orderByComparator)
475 };
476
477 List<Portlet> list = (List<Portlet>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_COMPANYID,
478 finderArgs, this);
479
480 if (list == null) {
481 Session session = null;
482
483 try {
484 session = openSession();
485
486 StringBundler query = null;
487
488 if (orderByComparator != null) {
489 query = new StringBundler(3 +
490 (orderByComparator.getOrderByFields().length * 3));
491 }
492 else {
493 query = new StringBundler(2);
494 }
495
496 query.append(_SQL_SELECT_PORTLET_WHERE);
497
498 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
499
500 if (orderByComparator != null) {
501 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
502 orderByComparator);
503 }
504
505 String sql = query.toString();
506
507 Query q = session.createQuery(sql);
508
509 QueryPos qPos = QueryPos.getInstance(q);
510
511 qPos.add(companyId);
512
513 list = (List<Portlet>)QueryUtil.list(q, getDialect(), start, end);
514 }
515 catch (Exception e) {
516 throw processException(e);
517 }
518 finally {
519 if (list == null) {
520 list = new ArrayList<Portlet>();
521 }
522
523 cacheResult(list);
524
525 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_COMPANYID,
526 finderArgs, list);
527
528 closeSession(session);
529 }
530 }
531
532 return list;
533 }
534
535
548 public Portlet findByCompanyId_First(long companyId,
549 OrderByComparator orderByComparator)
550 throws NoSuchPortletException, SystemException {
551 List<Portlet> list = findByCompanyId(companyId, 0, 1, orderByComparator);
552
553 if (list.isEmpty()) {
554 StringBundler msg = new StringBundler(4);
555
556 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
557
558 msg.append("companyId=");
559 msg.append(companyId);
560
561 msg.append(StringPool.CLOSE_CURLY_BRACE);
562
563 throw new NoSuchPortletException(msg.toString());
564 }
565 else {
566 return list.get(0);
567 }
568 }
569
570
583 public Portlet findByCompanyId_Last(long companyId,
584 OrderByComparator orderByComparator)
585 throws NoSuchPortletException, SystemException {
586 int count = countByCompanyId(companyId);
587
588 List<Portlet> list = findByCompanyId(companyId, count - 1, count,
589 orderByComparator);
590
591 if (list.isEmpty()) {
592 StringBundler msg = new StringBundler(4);
593
594 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
595
596 msg.append("companyId=");
597 msg.append(companyId);
598
599 msg.append(StringPool.CLOSE_CURLY_BRACE);
600
601 throw new NoSuchPortletException(msg.toString());
602 }
603 else {
604 return list.get(0);
605 }
606 }
607
608
622 public Portlet[] findByCompanyId_PrevAndNext(long id, long companyId,
623 OrderByComparator orderByComparator)
624 throws NoSuchPortletException, SystemException {
625 Portlet portlet = findByPrimaryKey(id);
626
627 Session session = null;
628
629 try {
630 session = openSession();
631
632 Portlet[] array = new PortletImpl[3];
633
634 array[0] = getByCompanyId_PrevAndNext(session, portlet, companyId,
635 orderByComparator, true);
636
637 array[1] = portlet;
638
639 array[2] = getByCompanyId_PrevAndNext(session, portlet, companyId,
640 orderByComparator, false);
641
642 return array;
643 }
644 catch (Exception e) {
645 throw processException(e);
646 }
647 finally {
648 closeSession(session);
649 }
650 }
651
652 protected Portlet getByCompanyId_PrevAndNext(Session session,
653 Portlet portlet, long companyId, OrderByComparator orderByComparator,
654 boolean previous) {
655 StringBundler query = null;
656
657 if (orderByComparator != null) {
658 query = new StringBundler(6 +
659 (orderByComparator.getOrderByFields().length * 6));
660 }
661 else {
662 query = new StringBundler(3);
663 }
664
665 query.append(_SQL_SELECT_PORTLET_WHERE);
666
667 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
668
669 if (orderByComparator != null) {
670 String[] orderByFields = orderByComparator.getOrderByFields();
671
672 if (orderByFields.length > 0) {
673 query.append(WHERE_AND);
674 }
675
676 for (int i = 0; i < orderByFields.length; i++) {
677 query.append(_ORDER_BY_ENTITY_ALIAS);
678 query.append(orderByFields[i]);
679
680 if ((i + 1) < orderByFields.length) {
681 if (orderByComparator.isAscending() ^ previous) {
682 query.append(WHERE_GREATER_THAN_HAS_NEXT);
683 }
684 else {
685 query.append(WHERE_LESSER_THAN_HAS_NEXT);
686 }
687 }
688 else {
689 if (orderByComparator.isAscending() ^ previous) {
690 query.append(WHERE_GREATER_THAN);
691 }
692 else {
693 query.append(WHERE_LESSER_THAN);
694 }
695 }
696 }
697
698 query.append(ORDER_BY_CLAUSE);
699
700 for (int i = 0; i < orderByFields.length; i++) {
701 query.append(_ORDER_BY_ENTITY_ALIAS);
702 query.append(orderByFields[i]);
703
704 if ((i + 1) < orderByFields.length) {
705 if (orderByComparator.isAscending() ^ previous) {
706 query.append(ORDER_BY_ASC_HAS_NEXT);
707 }
708 else {
709 query.append(ORDER_BY_DESC_HAS_NEXT);
710 }
711 }
712 else {
713 if (orderByComparator.isAscending() ^ previous) {
714 query.append(ORDER_BY_ASC);
715 }
716 else {
717 query.append(ORDER_BY_DESC);
718 }
719 }
720 }
721 }
722
723 String sql = query.toString();
724
725 Query q = session.createQuery(sql);
726
727 q.setFirstResult(0);
728 q.setMaxResults(2);
729
730 QueryPos qPos = QueryPos.getInstance(q);
731
732 qPos.add(companyId);
733
734 if (orderByComparator != null) {
735 Object[] values = orderByComparator.getOrderByValues(portlet);
736
737 for (Object value : values) {
738 qPos.add(value);
739 }
740 }
741
742 List<Portlet> list = q.list();
743
744 if (list.size() == 2) {
745 return list.get(1);
746 }
747 else {
748 return null;
749 }
750 }
751
752
761 public Portlet findByC_P(long companyId, String portletId)
762 throws NoSuchPortletException, SystemException {
763 Portlet portlet = fetchByC_P(companyId, portletId);
764
765 if (portlet == null) {
766 StringBundler msg = new StringBundler(6);
767
768 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
769
770 msg.append("companyId=");
771 msg.append(companyId);
772
773 msg.append(", portletId=");
774 msg.append(portletId);
775
776 msg.append(StringPool.CLOSE_CURLY_BRACE);
777
778 if (_log.isWarnEnabled()) {
779 _log.warn(msg.toString());
780 }
781
782 throw new NoSuchPortletException(msg.toString());
783 }
784
785 return portlet;
786 }
787
788
796 public Portlet fetchByC_P(long companyId, String portletId)
797 throws SystemException {
798 return fetchByC_P(companyId, portletId, true);
799 }
800
801
809 public Portlet fetchByC_P(long companyId, String portletId,
810 boolean retrieveFromCache) throws SystemException {
811 Object[] finderArgs = new Object[] { companyId, portletId };
812
813 Object result = null;
814
815 if (retrieveFromCache) {
816 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_P,
817 finderArgs, this);
818 }
819
820 if (result == null) {
821 Session session = null;
822
823 try {
824 session = openSession();
825
826 StringBundler query = new StringBundler(3);
827
828 query.append(_SQL_SELECT_PORTLET_WHERE);
829
830 query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
831
832 if (portletId == null) {
833 query.append(_FINDER_COLUMN_C_P_PORTLETID_1);
834 }
835 else {
836 if (portletId.equals(StringPool.BLANK)) {
837 query.append(_FINDER_COLUMN_C_P_PORTLETID_3);
838 }
839 else {
840 query.append(_FINDER_COLUMN_C_P_PORTLETID_2);
841 }
842 }
843
844 String sql = query.toString();
845
846 Query q = session.createQuery(sql);
847
848 QueryPos qPos = QueryPos.getInstance(q);
849
850 qPos.add(companyId);
851
852 if (portletId != null) {
853 qPos.add(portletId);
854 }
855
856 List<Portlet> list = q.list();
857
858 result = list;
859
860 Portlet portlet = null;
861
862 if (list.isEmpty()) {
863 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_P,
864 finderArgs, list);
865 }
866 else {
867 portlet = list.get(0);
868
869 cacheResult(portlet);
870
871 if ((portlet.getCompanyId() != companyId) ||
872 (portlet.getPortletId() == null) ||
873 !portlet.getPortletId().equals(portletId)) {
874 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_P,
875 finderArgs, portlet);
876 }
877 }
878
879 return portlet;
880 }
881 catch (Exception e) {
882 throw processException(e);
883 }
884 finally {
885 if (result == null) {
886 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_P,
887 finderArgs, new ArrayList<Portlet>());
888 }
889
890 closeSession(session);
891 }
892 }
893 else {
894 if (result instanceof List<?>) {
895 return null;
896 }
897 else {
898 return (Portlet)result;
899 }
900 }
901 }
902
903
909 public List<Portlet> findAll() throws SystemException {
910 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
911 }
912
913
925 public List<Portlet> findAll(int start, int end) throws SystemException {
926 return findAll(start, end, null);
927 }
928
929
942 public List<Portlet> findAll(int start, int end,
943 OrderByComparator orderByComparator) throws SystemException {
944 Object[] finderArgs = new Object[] {
945 String.valueOf(start), String.valueOf(end),
946 String.valueOf(orderByComparator)
947 };
948
949 List<Portlet> list = (List<Portlet>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
950 finderArgs, this);
951
952 if (list == null) {
953 Session session = null;
954
955 try {
956 session = openSession();
957
958 StringBundler query = null;
959 String sql = null;
960
961 if (orderByComparator != null) {
962 query = new StringBundler(2 +
963 (orderByComparator.getOrderByFields().length * 3));
964
965 query.append(_SQL_SELECT_PORTLET);
966
967 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
968 orderByComparator);
969
970 sql = query.toString();
971 }
972 else {
973 sql = _SQL_SELECT_PORTLET;
974 }
975
976 Query q = session.createQuery(sql);
977
978 if (orderByComparator == null) {
979 list = (List<Portlet>)QueryUtil.list(q, getDialect(),
980 start, end, false);
981
982 Collections.sort(list);
983 }
984 else {
985 list = (List<Portlet>)QueryUtil.list(q, getDialect(),
986 start, end);
987 }
988 }
989 catch (Exception e) {
990 throw processException(e);
991 }
992 finally {
993 if (list == null) {
994 list = new ArrayList<Portlet>();
995 }
996
997 cacheResult(list);
998
999 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1000
1001 closeSession(session);
1002 }
1003 }
1004
1005 return list;
1006 }
1007
1008
1014 public void removeByCompanyId(long companyId) throws SystemException {
1015 for (Portlet portlet : findByCompanyId(companyId)) {
1016 remove(portlet);
1017 }
1018 }
1019
1020
1027 public void removeByC_P(long companyId, String portletId)
1028 throws NoSuchPortletException, SystemException {
1029 Portlet portlet = findByC_P(companyId, portletId);
1030
1031 remove(portlet);
1032 }
1033
1034
1039 public void removeAll() throws SystemException {
1040 for (Portlet portlet : findAll()) {
1041 remove(portlet);
1042 }
1043 }
1044
1045
1052 public int countByCompanyId(long companyId) throws SystemException {
1053 Object[] finderArgs = new Object[] { companyId };
1054
1055 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
1056 finderArgs, this);
1057
1058 if (count == null) {
1059 Session session = null;
1060
1061 try {
1062 session = openSession();
1063
1064 StringBundler query = new StringBundler(2);
1065
1066 query.append(_SQL_COUNT_PORTLET_WHERE);
1067
1068 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1069
1070 String sql = query.toString();
1071
1072 Query q = session.createQuery(sql);
1073
1074 QueryPos qPos = QueryPos.getInstance(q);
1075
1076 qPos.add(companyId);
1077
1078 count = (Long)q.uniqueResult();
1079 }
1080 catch (Exception e) {
1081 throw processException(e);
1082 }
1083 finally {
1084 if (count == null) {
1085 count = Long.valueOf(0);
1086 }
1087
1088 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
1089 finderArgs, count);
1090
1091 closeSession(session);
1092 }
1093 }
1094
1095 return count.intValue();
1096 }
1097
1098
1106 public int countByC_P(long companyId, String portletId)
1107 throws SystemException {
1108 Object[] finderArgs = new Object[] { companyId, portletId };
1109
1110 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_P,
1111 finderArgs, this);
1112
1113 if (count == null) {
1114 Session session = null;
1115
1116 try {
1117 session = openSession();
1118
1119 StringBundler query = new StringBundler(3);
1120
1121 query.append(_SQL_COUNT_PORTLET_WHERE);
1122
1123 query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
1124
1125 if (portletId == null) {
1126 query.append(_FINDER_COLUMN_C_P_PORTLETID_1);
1127 }
1128 else {
1129 if (portletId.equals(StringPool.BLANK)) {
1130 query.append(_FINDER_COLUMN_C_P_PORTLETID_3);
1131 }
1132 else {
1133 query.append(_FINDER_COLUMN_C_P_PORTLETID_2);
1134 }
1135 }
1136
1137 String sql = query.toString();
1138
1139 Query q = session.createQuery(sql);
1140
1141 QueryPos qPos = QueryPos.getInstance(q);
1142
1143 qPos.add(companyId);
1144
1145 if (portletId != null) {
1146 qPos.add(portletId);
1147 }
1148
1149 count = (Long)q.uniqueResult();
1150 }
1151 catch (Exception e) {
1152 throw processException(e);
1153 }
1154 finally {
1155 if (count == null) {
1156 count = Long.valueOf(0);
1157 }
1158
1159 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_P, finderArgs,
1160 count);
1161
1162 closeSession(session);
1163 }
1164 }
1165
1166 return count.intValue();
1167 }
1168
1169
1175 public int countAll() throws SystemException {
1176 Object[] finderArgs = new Object[0];
1177
1178 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1179 finderArgs, this);
1180
1181 if (count == null) {
1182 Session session = null;
1183
1184 try {
1185 session = openSession();
1186
1187 Query q = session.createQuery(_SQL_COUNT_PORTLET);
1188
1189 count = (Long)q.uniqueResult();
1190 }
1191 catch (Exception e) {
1192 throw processException(e);
1193 }
1194 finally {
1195 if (count == null) {
1196 count = Long.valueOf(0);
1197 }
1198
1199 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1200 count);
1201
1202 closeSession(session);
1203 }
1204 }
1205
1206 return count.intValue();
1207 }
1208
1209
1212 public void afterPropertiesSet() {
1213 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1214 com.liferay.portal.util.PropsUtil.get(
1215 "value.object.listener.com.liferay.portal.model.Portlet")));
1216
1217 if (listenerClassNames.length > 0) {
1218 try {
1219 List<ModelListener<Portlet>> listenersList = new ArrayList<ModelListener<Portlet>>();
1220
1221 for (String listenerClassName : listenerClassNames) {
1222 listenersList.add((ModelListener<Portlet>)InstanceFactory.newInstance(
1223 listenerClassName));
1224 }
1225
1226 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1227 }
1228 catch (Exception e) {
1229 _log.error(e);
1230 }
1231 }
1232 }
1233
1234 public void destroy() {
1235 EntityCacheUtil.removeCache(PortletImpl.class.getName());
1236 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1237 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
1238 }
1239
1240 @BeanReference(type = AccountPersistence.class)
1241 protected AccountPersistence accountPersistence;
1242 @BeanReference(type = AddressPersistence.class)
1243 protected AddressPersistence addressPersistence;
1244 @BeanReference(type = BrowserTrackerPersistence.class)
1245 protected BrowserTrackerPersistence browserTrackerPersistence;
1246 @BeanReference(type = ClassNamePersistence.class)
1247 protected ClassNamePersistence classNamePersistence;
1248 @BeanReference(type = ClusterGroupPersistence.class)
1249 protected ClusterGroupPersistence clusterGroupPersistence;
1250 @BeanReference(type = CompanyPersistence.class)
1251 protected CompanyPersistence companyPersistence;
1252 @BeanReference(type = ContactPersistence.class)
1253 protected ContactPersistence contactPersistence;
1254 @BeanReference(type = CountryPersistence.class)
1255 protected CountryPersistence countryPersistence;
1256 @BeanReference(type = EmailAddressPersistence.class)
1257 protected EmailAddressPersistence emailAddressPersistence;
1258 @BeanReference(type = GroupPersistence.class)
1259 protected GroupPersistence groupPersistence;
1260 @BeanReference(type = ImagePersistence.class)
1261 protected ImagePersistence imagePersistence;
1262 @BeanReference(type = LayoutPersistence.class)
1263 protected LayoutPersistence layoutPersistence;
1264 @BeanReference(type = LayoutPrototypePersistence.class)
1265 protected LayoutPrototypePersistence layoutPrototypePersistence;
1266 @BeanReference(type = LayoutSetPersistence.class)
1267 protected LayoutSetPersistence layoutSetPersistence;
1268 @BeanReference(type = LayoutSetPrototypePersistence.class)
1269 protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
1270 @BeanReference(type = ListTypePersistence.class)
1271 protected ListTypePersistence listTypePersistence;
1272 @BeanReference(type = LockPersistence.class)
1273 protected LockPersistence lockPersistence;
1274 @BeanReference(type = MembershipRequestPersistence.class)
1275 protected MembershipRequestPersistence membershipRequestPersistence;
1276 @BeanReference(type = OrganizationPersistence.class)
1277 protected OrganizationPersistence organizationPersistence;
1278 @BeanReference(type = OrgGroupPermissionPersistence.class)
1279 protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1280 @BeanReference(type = OrgGroupRolePersistence.class)
1281 protected OrgGroupRolePersistence orgGroupRolePersistence;
1282 @BeanReference(type = OrgLaborPersistence.class)
1283 protected OrgLaborPersistence orgLaborPersistence;
1284 @BeanReference(type = PasswordPolicyPersistence.class)
1285 protected PasswordPolicyPersistence passwordPolicyPersistence;
1286 @BeanReference(type = PasswordPolicyRelPersistence.class)
1287 protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1288 @BeanReference(type = PasswordTrackerPersistence.class)
1289 protected PasswordTrackerPersistence passwordTrackerPersistence;
1290 @BeanReference(type = PermissionPersistence.class)
1291 protected PermissionPersistence permissionPersistence;
1292 @BeanReference(type = PhonePersistence.class)
1293 protected PhonePersistence phonePersistence;
1294 @BeanReference(type = PluginSettingPersistence.class)
1295 protected PluginSettingPersistence pluginSettingPersistence;
1296 @BeanReference(type = PortletPersistence.class)
1297 protected PortletPersistence portletPersistence;
1298 @BeanReference(type = PortletItemPersistence.class)
1299 protected PortletItemPersistence portletItemPersistence;
1300 @BeanReference(type = PortletPreferencesPersistence.class)
1301 protected PortletPreferencesPersistence portletPreferencesPersistence;
1302 @BeanReference(type = RegionPersistence.class)
1303 protected RegionPersistence regionPersistence;
1304 @BeanReference(type = ReleasePersistence.class)
1305 protected ReleasePersistence releasePersistence;
1306 @BeanReference(type = ResourcePersistence.class)
1307 protected ResourcePersistence resourcePersistence;
1308 @BeanReference(type = ResourceActionPersistence.class)
1309 protected ResourceActionPersistence resourceActionPersistence;
1310 @BeanReference(type = ResourceCodePersistence.class)
1311 protected ResourceCodePersistence resourceCodePersistence;
1312 @BeanReference(type = ResourcePermissionPersistence.class)
1313 protected ResourcePermissionPersistence resourcePermissionPersistence;
1314 @BeanReference(type = RolePersistence.class)
1315 protected RolePersistence rolePersistence;
1316 @BeanReference(type = ServiceComponentPersistence.class)
1317 protected ServiceComponentPersistence serviceComponentPersistence;
1318 @BeanReference(type = ShardPersistence.class)
1319 protected ShardPersistence shardPersistence;
1320 @BeanReference(type = SubscriptionPersistence.class)
1321 protected SubscriptionPersistence subscriptionPersistence;
1322 @BeanReference(type = TicketPersistence.class)
1323 protected TicketPersistence ticketPersistence;
1324 @BeanReference(type = TeamPersistence.class)
1325 protected TeamPersistence teamPersistence;
1326 @BeanReference(type = UserPersistence.class)
1327 protected UserPersistence userPersistence;
1328 @BeanReference(type = UserGroupPersistence.class)
1329 protected UserGroupPersistence userGroupPersistence;
1330 @BeanReference(type = UserGroupGroupRolePersistence.class)
1331 protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
1332 @BeanReference(type = UserGroupRolePersistence.class)
1333 protected UserGroupRolePersistence userGroupRolePersistence;
1334 @BeanReference(type = UserIdMapperPersistence.class)
1335 protected UserIdMapperPersistence userIdMapperPersistence;
1336 @BeanReference(type = UserTrackerPersistence.class)
1337 protected UserTrackerPersistence userTrackerPersistence;
1338 @BeanReference(type = UserTrackerPathPersistence.class)
1339 protected UserTrackerPathPersistence userTrackerPathPersistence;
1340 @BeanReference(type = WebDAVPropsPersistence.class)
1341 protected WebDAVPropsPersistence webDAVPropsPersistence;
1342 @BeanReference(type = WebsitePersistence.class)
1343 protected WebsitePersistence websitePersistence;
1344 @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
1345 protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
1346 @BeanReference(type = WorkflowInstanceLinkPersistence.class)
1347 protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
1348 private static final String _SQL_SELECT_PORTLET = "SELECT portlet FROM Portlet portlet";
1349 private static final String _SQL_SELECT_PORTLET_WHERE = "SELECT portlet FROM Portlet portlet WHERE ";
1350 private static final String _SQL_COUNT_PORTLET = "SELECT COUNT(portlet) FROM Portlet portlet";
1351 private static final String _SQL_COUNT_PORTLET_WHERE = "SELECT COUNT(portlet) FROM Portlet portlet WHERE ";
1352 private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "portlet.companyId = ?";
1353 private static final String _FINDER_COLUMN_C_P_COMPANYID_2 = "portlet.companyId = ? AND ";
1354 private static final String _FINDER_COLUMN_C_P_PORTLETID_1 = "portlet.portletId IS NULL";
1355 private static final String _FINDER_COLUMN_C_P_PORTLETID_2 = "portlet.portletId = ?";
1356 private static final String _FINDER_COLUMN_C_P_PORTLETID_3 = "(portlet.portletId IS NULL OR portlet.portletId = ?)";
1357 private static final String _ORDER_BY_ENTITY_ALIAS = "portlet.";
1358 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Portlet exists with the primary key ";
1359 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Portlet exists with the key {";
1360 private static Log _log = LogFactoryUtil.getLog(PortletPersistenceImpl.class);
1361 }