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 if (portlet.isCachedModel() || BatchSessionUtil.isEnabled()) {
240 Object staleObject = session.get(PortletImpl.class,
241 portlet.getPrimaryKeyObj());
242
243 if (staleObject != null) {
244 session.evict(staleObject);
245 }
246 }
247
248 session.delete(portlet);
249
250 session.flush();
251 }
252 catch (Exception e) {
253 throw processException(e);
254 }
255 finally {
256 closeSession(session);
257 }
258
259 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
260
261 PortletModelImpl portletModelImpl = (PortletModelImpl)portlet;
262
263 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_P,
264 new Object[] {
265 new Long(portletModelImpl.getOriginalCompanyId()),
266
267 portletModelImpl.getOriginalPortletId()
268 });
269
270 EntityCacheUtil.removeResult(PortletModelImpl.ENTITY_CACHE_ENABLED,
271 PortletImpl.class, portlet.getPrimaryKey());
272
273 return portlet;
274 }
275
276 public Portlet updateImpl(com.liferay.portal.model.Portlet portlet,
277 boolean merge) throws SystemException {
278 portlet = toUnwrappedModel(portlet);
279
280 boolean isNew = portlet.isNew();
281
282 PortletModelImpl portletModelImpl = (PortletModelImpl)portlet;
283
284 Session session = null;
285
286 try {
287 session = openSession();
288
289 BatchSessionUtil.update(session, portlet, merge);
290
291 portlet.setNew(false);
292 }
293 catch (Exception e) {
294 throw processException(e);
295 }
296 finally {
297 closeSession(session);
298 }
299
300 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
301
302 EntityCacheUtil.putResult(PortletModelImpl.ENTITY_CACHE_ENABLED,
303 PortletImpl.class, portlet.getPrimaryKey(), portlet);
304
305 if (!isNew &&
306 ((portlet.getCompanyId() != portletModelImpl.getOriginalCompanyId()) ||
307 !Validator.equals(portlet.getPortletId(),
308 portletModelImpl.getOriginalPortletId()))) {
309 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_P,
310 new Object[] {
311 new Long(portletModelImpl.getOriginalCompanyId()),
312
313 portletModelImpl.getOriginalPortletId()
314 });
315 }
316
317 if (isNew ||
318 ((portlet.getCompanyId() != portletModelImpl.getOriginalCompanyId()) ||
319 !Validator.equals(portlet.getPortletId(),
320 portletModelImpl.getOriginalPortletId()))) {
321 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_P,
322 new Object[] {
323 new Long(portlet.getCompanyId()),
324
325 portlet.getPortletId()
326 }, portlet);
327 }
328
329 return portlet;
330 }
331
332 protected Portlet toUnwrappedModel(Portlet portlet) {
333 if (portlet instanceof PortletImpl) {
334 return portlet;
335 }
336
337 PortletImpl portletImpl = new PortletImpl();
338
339 portletImpl.setNew(portlet.isNew());
340 portletImpl.setPrimaryKey(portlet.getPrimaryKey());
341
342 portletImpl.setId(portlet.getId());
343 portletImpl.setCompanyId(portlet.getCompanyId());
344 portletImpl.setPortletId(portlet.getPortletId());
345 portletImpl.setRoles(portlet.getRoles());
346 portletImpl.setActive(portlet.isActive());
347
348 return portletImpl;
349 }
350
351
359 public Portlet findByPrimaryKey(Serializable primaryKey)
360 throws NoSuchModelException, SystemException {
361 return findByPrimaryKey(((Long)primaryKey).longValue());
362 }
363
364
372 public Portlet findByPrimaryKey(long id)
373 throws NoSuchPortletException, SystemException {
374 Portlet portlet = fetchByPrimaryKey(id);
375
376 if (portlet == null) {
377 if (_log.isWarnEnabled()) {
378 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + id);
379 }
380
381 throw new NoSuchPortletException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
382 id);
383 }
384
385 return portlet;
386 }
387
388
395 public Portlet fetchByPrimaryKey(Serializable primaryKey)
396 throws SystemException {
397 return fetchByPrimaryKey(((Long)primaryKey).longValue());
398 }
399
400
407 public Portlet fetchByPrimaryKey(long id) throws SystemException {
408 Portlet portlet = (Portlet)EntityCacheUtil.getResult(PortletModelImpl.ENTITY_CACHE_ENABLED,
409 PortletImpl.class, id, this);
410
411 if (portlet == null) {
412 Session session = null;
413
414 try {
415 session = openSession();
416
417 portlet = (Portlet)session.get(PortletImpl.class, new Long(id));
418 }
419 catch (Exception e) {
420 throw processException(e);
421 }
422 finally {
423 if (portlet != null) {
424 cacheResult(portlet);
425 }
426
427 closeSession(session);
428 }
429 }
430
431 return portlet;
432 }
433
434
441 public List<Portlet> findByCompanyId(long companyId)
442 throws SystemException {
443 return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
444 null);
445 }
446
447
460 public List<Portlet> findByCompanyId(long companyId, int start, int end)
461 throws SystemException {
462 return findByCompanyId(companyId, start, end, null);
463 }
464
465
479 public List<Portlet> findByCompanyId(long companyId, int start, int end,
480 OrderByComparator orderByComparator) throws SystemException {
481 Object[] finderArgs = new Object[] {
482 companyId,
483
484 String.valueOf(start), String.valueOf(end),
485 String.valueOf(orderByComparator)
486 };
487
488 List<Portlet> list = (List<Portlet>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_COMPANYID,
489 finderArgs, this);
490
491 if (list == null) {
492 Session session = null;
493
494 try {
495 session = openSession();
496
497 StringBundler query = null;
498
499 if (orderByComparator != null) {
500 query = new StringBundler(3 +
501 (orderByComparator.getOrderByFields().length * 3));
502 }
503 else {
504 query = new StringBundler(2);
505 }
506
507 query.append(_SQL_SELECT_PORTLET_WHERE);
508
509 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
510
511 if (orderByComparator != null) {
512 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
513 orderByComparator);
514 }
515
516 String sql = query.toString();
517
518 Query q = session.createQuery(sql);
519
520 QueryPos qPos = QueryPos.getInstance(q);
521
522 qPos.add(companyId);
523
524 list = (List<Portlet>)QueryUtil.list(q, getDialect(), start, end);
525 }
526 catch (Exception e) {
527 throw processException(e);
528 }
529 finally {
530 if (list == null) {
531 list = new ArrayList<Portlet>();
532 }
533
534 cacheResult(list);
535
536 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_COMPANYID,
537 finderArgs, list);
538
539 closeSession(session);
540 }
541 }
542
543 return list;
544 }
545
546
559 public Portlet findByCompanyId_First(long companyId,
560 OrderByComparator orderByComparator)
561 throws NoSuchPortletException, SystemException {
562 List<Portlet> list = findByCompanyId(companyId, 0, 1, orderByComparator);
563
564 if (list.isEmpty()) {
565 StringBundler msg = new StringBundler(4);
566
567 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
568
569 msg.append("companyId=");
570 msg.append(companyId);
571
572 msg.append(StringPool.CLOSE_CURLY_BRACE);
573
574 throw new NoSuchPortletException(msg.toString());
575 }
576 else {
577 return list.get(0);
578 }
579 }
580
581
594 public Portlet findByCompanyId_Last(long companyId,
595 OrderByComparator orderByComparator)
596 throws NoSuchPortletException, SystemException {
597 int count = countByCompanyId(companyId);
598
599 List<Portlet> list = findByCompanyId(companyId, count - 1, count,
600 orderByComparator);
601
602 if (list.isEmpty()) {
603 StringBundler msg = new StringBundler(4);
604
605 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
606
607 msg.append("companyId=");
608 msg.append(companyId);
609
610 msg.append(StringPool.CLOSE_CURLY_BRACE);
611
612 throw new NoSuchPortletException(msg.toString());
613 }
614 else {
615 return list.get(0);
616 }
617 }
618
619
633 public Portlet[] findByCompanyId_PrevAndNext(long id, long companyId,
634 OrderByComparator orderByComparator)
635 throws NoSuchPortletException, SystemException {
636 Portlet portlet = findByPrimaryKey(id);
637
638 Session session = null;
639
640 try {
641 session = openSession();
642
643 Portlet[] array = new PortletImpl[3];
644
645 array[0] = getByCompanyId_PrevAndNext(session, portlet, companyId,
646 orderByComparator, true);
647
648 array[1] = portlet;
649
650 array[2] = getByCompanyId_PrevAndNext(session, portlet, companyId,
651 orderByComparator, false);
652
653 return array;
654 }
655 catch (Exception e) {
656 throw processException(e);
657 }
658 finally {
659 closeSession(session);
660 }
661 }
662
663 protected Portlet getByCompanyId_PrevAndNext(Session session,
664 Portlet portlet, long companyId, OrderByComparator orderByComparator,
665 boolean previous) {
666 StringBundler query = null;
667
668 if (orderByComparator != null) {
669 query = new StringBundler(6 +
670 (orderByComparator.getOrderByFields().length * 6));
671 }
672 else {
673 query = new StringBundler(3);
674 }
675
676 query.append(_SQL_SELECT_PORTLET_WHERE);
677
678 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
679
680 if (orderByComparator != null) {
681 String[] orderByFields = orderByComparator.getOrderByFields();
682
683 if (orderByFields.length > 0) {
684 query.append(WHERE_AND);
685 }
686
687 for (int i = 0; i < orderByFields.length; i++) {
688 query.append(_ORDER_BY_ENTITY_ALIAS);
689 query.append(orderByFields[i]);
690
691 if ((i + 1) < orderByFields.length) {
692 if (orderByComparator.isAscending() ^ previous) {
693 query.append(WHERE_GREATER_THAN_HAS_NEXT);
694 }
695 else {
696 query.append(WHERE_LESSER_THAN_HAS_NEXT);
697 }
698 }
699 else {
700 if (orderByComparator.isAscending() ^ previous) {
701 query.append(WHERE_GREATER_THAN);
702 }
703 else {
704 query.append(WHERE_LESSER_THAN);
705 }
706 }
707 }
708
709 query.append(ORDER_BY_CLAUSE);
710
711 for (int i = 0; i < orderByFields.length; i++) {
712 query.append(_ORDER_BY_ENTITY_ALIAS);
713 query.append(orderByFields[i]);
714
715 if ((i + 1) < orderByFields.length) {
716 if (orderByComparator.isAscending() ^ previous) {
717 query.append(ORDER_BY_ASC_HAS_NEXT);
718 }
719 else {
720 query.append(ORDER_BY_DESC_HAS_NEXT);
721 }
722 }
723 else {
724 if (orderByComparator.isAscending() ^ previous) {
725 query.append(ORDER_BY_ASC);
726 }
727 else {
728 query.append(ORDER_BY_DESC);
729 }
730 }
731 }
732 }
733
734 String sql = query.toString();
735
736 Query q = session.createQuery(sql);
737
738 q.setFirstResult(0);
739 q.setMaxResults(2);
740
741 QueryPos qPos = QueryPos.getInstance(q);
742
743 qPos.add(companyId);
744
745 if (orderByComparator != null) {
746 Object[] values = orderByComparator.getOrderByValues(portlet);
747
748 for (Object value : values) {
749 qPos.add(value);
750 }
751 }
752
753 List<Portlet> list = q.list();
754
755 if (list.size() == 2) {
756 return list.get(1);
757 }
758 else {
759 return null;
760 }
761 }
762
763
772 public Portlet findByC_P(long companyId, String portletId)
773 throws NoSuchPortletException, SystemException {
774 Portlet portlet = fetchByC_P(companyId, portletId);
775
776 if (portlet == null) {
777 StringBundler msg = new StringBundler(6);
778
779 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
780
781 msg.append("companyId=");
782 msg.append(companyId);
783
784 msg.append(", portletId=");
785 msg.append(portletId);
786
787 msg.append(StringPool.CLOSE_CURLY_BRACE);
788
789 if (_log.isWarnEnabled()) {
790 _log.warn(msg.toString());
791 }
792
793 throw new NoSuchPortletException(msg.toString());
794 }
795
796 return portlet;
797 }
798
799
807 public Portlet fetchByC_P(long companyId, String portletId)
808 throws SystemException {
809 return fetchByC_P(companyId, portletId, true);
810 }
811
812
820 public Portlet fetchByC_P(long companyId, String portletId,
821 boolean retrieveFromCache) throws SystemException {
822 Object[] finderArgs = new Object[] { companyId, portletId };
823
824 Object result = null;
825
826 if (retrieveFromCache) {
827 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_P,
828 finderArgs, this);
829 }
830
831 if (result == null) {
832 Session session = null;
833
834 try {
835 session = openSession();
836
837 StringBundler query = new StringBundler(3);
838
839 query.append(_SQL_SELECT_PORTLET_WHERE);
840
841 query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
842
843 if (portletId == null) {
844 query.append(_FINDER_COLUMN_C_P_PORTLETID_1);
845 }
846 else {
847 if (portletId.equals(StringPool.BLANK)) {
848 query.append(_FINDER_COLUMN_C_P_PORTLETID_3);
849 }
850 else {
851 query.append(_FINDER_COLUMN_C_P_PORTLETID_2);
852 }
853 }
854
855 String sql = query.toString();
856
857 Query q = session.createQuery(sql);
858
859 QueryPos qPos = QueryPos.getInstance(q);
860
861 qPos.add(companyId);
862
863 if (portletId != null) {
864 qPos.add(portletId);
865 }
866
867 List<Portlet> list = q.list();
868
869 result = list;
870
871 Portlet portlet = null;
872
873 if (list.isEmpty()) {
874 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_P,
875 finderArgs, list);
876 }
877 else {
878 portlet = list.get(0);
879
880 cacheResult(portlet);
881
882 if ((portlet.getCompanyId() != companyId) ||
883 (portlet.getPortletId() == null) ||
884 !portlet.getPortletId().equals(portletId)) {
885 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_P,
886 finderArgs, portlet);
887 }
888 }
889
890 return portlet;
891 }
892 catch (Exception e) {
893 throw processException(e);
894 }
895 finally {
896 if (result == null) {
897 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_P,
898 finderArgs, new ArrayList<Portlet>());
899 }
900
901 closeSession(session);
902 }
903 }
904 else {
905 if (result instanceof List<?>) {
906 return null;
907 }
908 else {
909 return (Portlet)result;
910 }
911 }
912 }
913
914
920 public List<Portlet> findAll() throws SystemException {
921 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
922 }
923
924
936 public List<Portlet> findAll(int start, int end) throws SystemException {
937 return findAll(start, end, null);
938 }
939
940
953 public List<Portlet> findAll(int start, int end,
954 OrderByComparator orderByComparator) throws SystemException {
955 Object[] finderArgs = new Object[] {
956 String.valueOf(start), String.valueOf(end),
957 String.valueOf(orderByComparator)
958 };
959
960 List<Portlet> list = (List<Portlet>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
961 finderArgs, this);
962
963 if (list == null) {
964 Session session = null;
965
966 try {
967 session = openSession();
968
969 StringBundler query = null;
970 String sql = null;
971
972 if (orderByComparator != null) {
973 query = new StringBundler(2 +
974 (orderByComparator.getOrderByFields().length * 3));
975
976 query.append(_SQL_SELECT_PORTLET);
977
978 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
979 orderByComparator);
980
981 sql = query.toString();
982 }
983 else {
984 sql = _SQL_SELECT_PORTLET;
985 }
986
987 Query q = session.createQuery(sql);
988
989 if (orderByComparator == null) {
990 list = (List<Portlet>)QueryUtil.list(q, getDialect(),
991 start, end, false);
992
993 Collections.sort(list);
994 }
995 else {
996 list = (List<Portlet>)QueryUtil.list(q, getDialect(),
997 start, end);
998 }
999 }
1000 catch (Exception e) {
1001 throw processException(e);
1002 }
1003 finally {
1004 if (list == null) {
1005 list = new ArrayList<Portlet>();
1006 }
1007
1008 cacheResult(list);
1009
1010 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1011
1012 closeSession(session);
1013 }
1014 }
1015
1016 return list;
1017 }
1018
1019
1025 public void removeByCompanyId(long companyId) throws SystemException {
1026 for (Portlet portlet : findByCompanyId(companyId)) {
1027 remove(portlet);
1028 }
1029 }
1030
1031
1038 public void removeByC_P(long companyId, String portletId)
1039 throws NoSuchPortletException, SystemException {
1040 Portlet portlet = findByC_P(companyId, portletId);
1041
1042 remove(portlet);
1043 }
1044
1045
1050 public void removeAll() throws SystemException {
1051 for (Portlet portlet : findAll()) {
1052 remove(portlet);
1053 }
1054 }
1055
1056
1063 public int countByCompanyId(long companyId) throws SystemException {
1064 Object[] finderArgs = new Object[] { companyId };
1065
1066 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
1067 finderArgs, this);
1068
1069 if (count == null) {
1070 Session session = null;
1071
1072 try {
1073 session = openSession();
1074
1075 StringBundler query = new StringBundler(2);
1076
1077 query.append(_SQL_COUNT_PORTLET_WHERE);
1078
1079 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1080
1081 String sql = query.toString();
1082
1083 Query q = session.createQuery(sql);
1084
1085 QueryPos qPos = QueryPos.getInstance(q);
1086
1087 qPos.add(companyId);
1088
1089 count = (Long)q.uniqueResult();
1090 }
1091 catch (Exception e) {
1092 throw processException(e);
1093 }
1094 finally {
1095 if (count == null) {
1096 count = Long.valueOf(0);
1097 }
1098
1099 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
1100 finderArgs, count);
1101
1102 closeSession(session);
1103 }
1104 }
1105
1106 return count.intValue();
1107 }
1108
1109
1117 public int countByC_P(long companyId, String portletId)
1118 throws SystemException {
1119 Object[] finderArgs = new Object[] { companyId, portletId };
1120
1121 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_P,
1122 finderArgs, this);
1123
1124 if (count == null) {
1125 Session session = null;
1126
1127 try {
1128 session = openSession();
1129
1130 StringBundler query = new StringBundler(3);
1131
1132 query.append(_SQL_COUNT_PORTLET_WHERE);
1133
1134 query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
1135
1136 if (portletId == null) {
1137 query.append(_FINDER_COLUMN_C_P_PORTLETID_1);
1138 }
1139 else {
1140 if (portletId.equals(StringPool.BLANK)) {
1141 query.append(_FINDER_COLUMN_C_P_PORTLETID_3);
1142 }
1143 else {
1144 query.append(_FINDER_COLUMN_C_P_PORTLETID_2);
1145 }
1146 }
1147
1148 String sql = query.toString();
1149
1150 Query q = session.createQuery(sql);
1151
1152 QueryPos qPos = QueryPos.getInstance(q);
1153
1154 qPos.add(companyId);
1155
1156 if (portletId != null) {
1157 qPos.add(portletId);
1158 }
1159
1160 count = (Long)q.uniqueResult();
1161 }
1162 catch (Exception e) {
1163 throw processException(e);
1164 }
1165 finally {
1166 if (count == null) {
1167 count = Long.valueOf(0);
1168 }
1169
1170 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_P, finderArgs,
1171 count);
1172
1173 closeSession(session);
1174 }
1175 }
1176
1177 return count.intValue();
1178 }
1179
1180
1186 public int countAll() throws SystemException {
1187 Object[] finderArgs = new Object[0];
1188
1189 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1190 finderArgs, this);
1191
1192 if (count == null) {
1193 Session session = null;
1194
1195 try {
1196 session = openSession();
1197
1198 Query q = session.createQuery(_SQL_COUNT_PORTLET);
1199
1200 count = (Long)q.uniqueResult();
1201 }
1202 catch (Exception e) {
1203 throw processException(e);
1204 }
1205 finally {
1206 if (count == null) {
1207 count = Long.valueOf(0);
1208 }
1209
1210 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1211 count);
1212
1213 closeSession(session);
1214 }
1215 }
1216
1217 return count.intValue();
1218 }
1219
1220
1223 public void afterPropertiesSet() {
1224 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1225 com.liferay.portal.util.PropsUtil.get(
1226 "value.object.listener.com.liferay.portal.model.Portlet")));
1227
1228 if (listenerClassNames.length > 0) {
1229 try {
1230 List<ModelListener<Portlet>> listenersList = new ArrayList<ModelListener<Portlet>>();
1231
1232 for (String listenerClassName : listenerClassNames) {
1233 listenersList.add((ModelListener<Portlet>)InstanceFactory.newInstance(
1234 listenerClassName));
1235 }
1236
1237 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1238 }
1239 catch (Exception e) {
1240 _log.error(e);
1241 }
1242 }
1243 }
1244
1245 @BeanReference(type = AccountPersistence.class)
1246 protected AccountPersistence accountPersistence;
1247 @BeanReference(type = AddressPersistence.class)
1248 protected AddressPersistence addressPersistence;
1249 @BeanReference(type = BrowserTrackerPersistence.class)
1250 protected BrowserTrackerPersistence browserTrackerPersistence;
1251 @BeanReference(type = ClassNamePersistence.class)
1252 protected ClassNamePersistence classNamePersistence;
1253 @BeanReference(type = CompanyPersistence.class)
1254 protected CompanyPersistence companyPersistence;
1255 @BeanReference(type = ContactPersistence.class)
1256 protected ContactPersistence contactPersistence;
1257 @BeanReference(type = CountryPersistence.class)
1258 protected CountryPersistence countryPersistence;
1259 @BeanReference(type = EmailAddressPersistence.class)
1260 protected EmailAddressPersistence emailAddressPersistence;
1261 @BeanReference(type = GroupPersistence.class)
1262 protected GroupPersistence groupPersistence;
1263 @BeanReference(type = ImagePersistence.class)
1264 protected ImagePersistence imagePersistence;
1265 @BeanReference(type = LayoutPersistence.class)
1266 protected LayoutPersistence layoutPersistence;
1267 @BeanReference(type = LayoutPrototypePersistence.class)
1268 protected LayoutPrototypePersistence layoutPrototypePersistence;
1269 @BeanReference(type = LayoutSetPersistence.class)
1270 protected LayoutSetPersistence layoutSetPersistence;
1271 @BeanReference(type = LayoutSetPrototypePersistence.class)
1272 protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
1273 @BeanReference(type = ListTypePersistence.class)
1274 protected ListTypePersistence listTypePersistence;
1275 @BeanReference(type = LockPersistence.class)
1276 protected LockPersistence lockPersistence;
1277 @BeanReference(type = MembershipRequestPersistence.class)
1278 protected MembershipRequestPersistence membershipRequestPersistence;
1279 @BeanReference(type = OrganizationPersistence.class)
1280 protected OrganizationPersistence organizationPersistence;
1281 @BeanReference(type = OrgGroupPermissionPersistence.class)
1282 protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1283 @BeanReference(type = OrgGroupRolePersistence.class)
1284 protected OrgGroupRolePersistence orgGroupRolePersistence;
1285 @BeanReference(type = OrgLaborPersistence.class)
1286 protected OrgLaborPersistence orgLaborPersistence;
1287 @BeanReference(type = PasswordPolicyPersistence.class)
1288 protected PasswordPolicyPersistence passwordPolicyPersistence;
1289 @BeanReference(type = PasswordPolicyRelPersistence.class)
1290 protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1291 @BeanReference(type = PasswordTrackerPersistence.class)
1292 protected PasswordTrackerPersistence passwordTrackerPersistence;
1293 @BeanReference(type = PermissionPersistence.class)
1294 protected PermissionPersistence permissionPersistence;
1295 @BeanReference(type = PhonePersistence.class)
1296 protected PhonePersistence phonePersistence;
1297 @BeanReference(type = PluginSettingPersistence.class)
1298 protected PluginSettingPersistence pluginSettingPersistence;
1299 @BeanReference(type = PortletPersistence.class)
1300 protected PortletPersistence portletPersistence;
1301 @BeanReference(type = PortletItemPersistence.class)
1302 protected PortletItemPersistence portletItemPersistence;
1303 @BeanReference(type = PortletPreferencesPersistence.class)
1304 protected PortletPreferencesPersistence portletPreferencesPersistence;
1305 @BeanReference(type = RegionPersistence.class)
1306 protected RegionPersistence regionPersistence;
1307 @BeanReference(type = ReleasePersistence.class)
1308 protected ReleasePersistence releasePersistence;
1309 @BeanReference(type = ResourcePersistence.class)
1310 protected ResourcePersistence resourcePersistence;
1311 @BeanReference(type = ResourceActionPersistence.class)
1312 protected ResourceActionPersistence resourceActionPersistence;
1313 @BeanReference(type = ResourceCodePersistence.class)
1314 protected ResourceCodePersistence resourceCodePersistence;
1315 @BeanReference(type = ResourcePermissionPersistence.class)
1316 protected ResourcePermissionPersistence resourcePermissionPersistence;
1317 @BeanReference(type = RolePersistence.class)
1318 protected RolePersistence rolePersistence;
1319 @BeanReference(type = ServiceComponentPersistence.class)
1320 protected ServiceComponentPersistence serviceComponentPersistence;
1321 @BeanReference(type = ShardPersistence.class)
1322 protected ShardPersistence shardPersistence;
1323 @BeanReference(type = SubscriptionPersistence.class)
1324 protected SubscriptionPersistence subscriptionPersistence;
1325 @BeanReference(type = TicketPersistence.class)
1326 protected TicketPersistence ticketPersistence;
1327 @BeanReference(type = TeamPersistence.class)
1328 protected TeamPersistence teamPersistence;
1329 @BeanReference(type = UserPersistence.class)
1330 protected UserPersistence userPersistence;
1331 @BeanReference(type = UserGroupPersistence.class)
1332 protected UserGroupPersistence userGroupPersistence;
1333 @BeanReference(type = UserGroupGroupRolePersistence.class)
1334 protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
1335 @BeanReference(type = UserGroupRolePersistence.class)
1336 protected UserGroupRolePersistence userGroupRolePersistence;
1337 @BeanReference(type = UserIdMapperPersistence.class)
1338 protected UserIdMapperPersistence userIdMapperPersistence;
1339 @BeanReference(type = UserTrackerPersistence.class)
1340 protected UserTrackerPersistence userTrackerPersistence;
1341 @BeanReference(type = UserTrackerPathPersistence.class)
1342 protected UserTrackerPathPersistence userTrackerPathPersistence;
1343 @BeanReference(type = WebDAVPropsPersistence.class)
1344 protected WebDAVPropsPersistence webDAVPropsPersistence;
1345 @BeanReference(type = WebsitePersistence.class)
1346 protected WebsitePersistence websitePersistence;
1347 @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
1348 protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
1349 @BeanReference(type = WorkflowInstanceLinkPersistence.class)
1350 protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
1351 private static final String _SQL_SELECT_PORTLET = "SELECT portlet FROM Portlet portlet";
1352 private static final String _SQL_SELECT_PORTLET_WHERE = "SELECT portlet FROM Portlet portlet WHERE ";
1353 private static final String _SQL_COUNT_PORTLET = "SELECT COUNT(portlet) FROM Portlet portlet";
1354 private static final String _SQL_COUNT_PORTLET_WHERE = "SELECT COUNT(portlet) FROM Portlet portlet WHERE ";
1355 private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "portlet.companyId = ?";
1356 private static final String _FINDER_COLUMN_C_P_COMPANYID_2 = "portlet.companyId = ? AND ";
1357 private static final String _FINDER_COLUMN_C_P_PORTLETID_1 = "portlet.portletId IS NULL";
1358 private static final String _FINDER_COLUMN_C_P_PORTLETID_2 = "portlet.portletId = ?";
1359 private static final String _FINDER_COLUMN_C_P_PORTLETID_3 = "(portlet.portletId IS NULL OR portlet.portletId = ?)";
1360 private static final String _ORDER_BY_ENTITY_ALIAS = "portlet.";
1361 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Portlet exists with the primary key ";
1362 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Portlet exists with the key {";
1363 private static Log _log = LogFactoryUtil.getLog(PortletPersistenceImpl.class);
1364 }