001
014
015 package com.liferay.portal.service.persistence;
016
017 import com.liferay.portal.NoSuchPreferencesException;
018 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
019 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
020 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderPath;
022 import com.liferay.portal.kernel.dao.orm.Query;
023 import com.liferay.portal.kernel.dao.orm.QueryPos;
024 import com.liferay.portal.kernel.dao.orm.QueryUtil;
025 import com.liferay.portal.kernel.dao.orm.Session;
026 import com.liferay.portal.kernel.exception.SystemException;
027 import com.liferay.portal.kernel.log.Log;
028 import com.liferay.portal.kernel.log.LogFactoryUtil;
029 import com.liferay.portal.kernel.util.GetterUtil;
030 import com.liferay.portal.kernel.util.InstanceFactory;
031 import com.liferay.portal.kernel.util.OrderByComparator;
032 import com.liferay.portal.kernel.util.StringBundler;
033 import com.liferay.portal.kernel.util.StringPool;
034 import com.liferay.portal.kernel.util.StringUtil;
035 import com.liferay.portal.kernel.util.UnmodifiableList;
036 import com.liferay.portal.model.CacheModel;
037 import com.liferay.portal.model.ModelListener;
038 import com.liferay.portal.model.PortalPreferences;
039 import com.liferay.portal.model.impl.PortalPreferencesImpl;
040 import com.liferay.portal.model.impl.PortalPreferencesModelImpl;
041 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
042
043 import java.io.Serializable;
044
045 import java.util.ArrayList;
046 import java.util.Collections;
047 import java.util.List;
048
049
061 public class PortalPreferencesPersistenceImpl extends BasePersistenceImpl<PortalPreferences>
062 implements PortalPreferencesPersistence {
063
068 public static final String FINDER_CLASS_NAME_ENTITY = PortalPreferencesImpl.class.getName();
069 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
070 ".List1";
071 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
072 ".List2";
073 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
074 PortalPreferencesModelImpl.FINDER_CACHE_ENABLED,
075 PortalPreferencesImpl.class,
076 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
077 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
078 PortalPreferencesModelImpl.FINDER_CACHE_ENABLED,
079 PortalPreferencesImpl.class,
080 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
081 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
082 PortalPreferencesModelImpl.FINDER_CACHE_ENABLED, Long.class,
083 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
084 public static final FinderPath FINDER_PATH_FETCH_BY_O_O = new FinderPath(PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
085 PortalPreferencesModelImpl.FINDER_CACHE_ENABLED,
086 PortalPreferencesImpl.class, FINDER_CLASS_NAME_ENTITY,
087 "fetchByO_O",
088 new String[] { Long.class.getName(), Integer.class.getName() },
089 PortalPreferencesModelImpl.OWNERID_COLUMN_BITMASK |
090 PortalPreferencesModelImpl.OWNERTYPE_COLUMN_BITMASK);
091 public static final FinderPath FINDER_PATH_COUNT_BY_O_O = new FinderPath(PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
092 PortalPreferencesModelImpl.FINDER_CACHE_ENABLED, Long.class,
093 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByO_O",
094 new String[] { Long.class.getName(), Integer.class.getName() });
095
096
105 @Override
106 public PortalPreferences findByO_O(long ownerId, int ownerType)
107 throws NoSuchPreferencesException, SystemException {
108 PortalPreferences portalPreferences = fetchByO_O(ownerId, ownerType);
109
110 if (portalPreferences == null) {
111 StringBundler msg = new StringBundler(6);
112
113 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
114
115 msg.append("ownerId=");
116 msg.append(ownerId);
117
118 msg.append(", ownerType=");
119 msg.append(ownerType);
120
121 msg.append(StringPool.CLOSE_CURLY_BRACE);
122
123 if (_log.isWarnEnabled()) {
124 _log.warn(msg.toString());
125 }
126
127 throw new NoSuchPreferencesException(msg.toString());
128 }
129
130 return portalPreferences;
131 }
132
133
141 @Override
142 public PortalPreferences fetchByO_O(long ownerId, int ownerType)
143 throws SystemException {
144 return fetchByO_O(ownerId, ownerType, true);
145 }
146
147
156 @Override
157 public PortalPreferences fetchByO_O(long ownerId, int ownerType,
158 boolean retrieveFromCache) throws SystemException {
159 Object[] finderArgs = new Object[] { ownerId, ownerType };
160
161 Object result = null;
162
163 if (retrieveFromCache) {
164 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_O_O,
165 finderArgs, this);
166 }
167
168 if (result instanceof PortalPreferences) {
169 PortalPreferences portalPreferences = (PortalPreferences)result;
170
171 if ((ownerId != portalPreferences.getOwnerId()) ||
172 (ownerType != portalPreferences.getOwnerType())) {
173 result = null;
174 }
175 }
176
177 if (result == null) {
178 StringBundler query = new StringBundler(4);
179
180 query.append(_SQL_SELECT_PORTALPREFERENCES_WHERE);
181
182 query.append(_FINDER_COLUMN_O_O_OWNERID_2);
183
184 query.append(_FINDER_COLUMN_O_O_OWNERTYPE_2);
185
186 String sql = query.toString();
187
188 Session session = null;
189
190 try {
191 session = openSession();
192
193 Query q = session.createQuery(sql);
194
195 QueryPos qPos = QueryPos.getInstance(q);
196
197 qPos.add(ownerId);
198
199 qPos.add(ownerType);
200
201 List<PortalPreferences> list = q.list();
202
203 if (list.isEmpty()) {
204 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_O_O,
205 finderArgs, list);
206 }
207 else {
208 if ((list.size() > 1) && _log.isWarnEnabled()) {
209 _log.warn(
210 "PortalPreferencesPersistenceImpl.fetchByO_O(long, int, boolean) with parameters (" +
211 StringUtil.merge(finderArgs) +
212 ") yields a result set with more than 1 result. This violates the logical unique restriction. There is no order guarantee on which result is returned by this finder.");
213 }
214
215 PortalPreferences portalPreferences = list.get(0);
216
217 result = portalPreferences;
218
219 cacheResult(portalPreferences);
220
221 if ((portalPreferences.getOwnerId() != ownerId) ||
222 (portalPreferences.getOwnerType() != ownerType)) {
223 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_O_O,
224 finderArgs, portalPreferences);
225 }
226 }
227 }
228 catch (Exception e) {
229 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_O_O,
230 finderArgs);
231
232 throw processException(e);
233 }
234 finally {
235 closeSession(session);
236 }
237 }
238
239 if (result instanceof List<?>) {
240 return null;
241 }
242 else {
243 return (PortalPreferences)result;
244 }
245 }
246
247
255 @Override
256 public PortalPreferences removeByO_O(long ownerId, int ownerType)
257 throws NoSuchPreferencesException, SystemException {
258 PortalPreferences portalPreferences = findByO_O(ownerId, ownerType);
259
260 return remove(portalPreferences);
261 }
262
263
271 @Override
272 public int countByO_O(long ownerId, int ownerType)
273 throws SystemException {
274 FinderPath finderPath = FINDER_PATH_COUNT_BY_O_O;
275
276 Object[] finderArgs = new Object[] { ownerId, ownerType };
277
278 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
279 this);
280
281 if (count == null) {
282 StringBundler query = new StringBundler(3);
283
284 query.append(_SQL_COUNT_PORTALPREFERENCES_WHERE);
285
286 query.append(_FINDER_COLUMN_O_O_OWNERID_2);
287
288 query.append(_FINDER_COLUMN_O_O_OWNERTYPE_2);
289
290 String sql = query.toString();
291
292 Session session = null;
293
294 try {
295 session = openSession();
296
297 Query q = session.createQuery(sql);
298
299 QueryPos qPos = QueryPos.getInstance(q);
300
301 qPos.add(ownerId);
302
303 qPos.add(ownerType);
304
305 count = (Long)q.uniqueResult();
306
307 FinderCacheUtil.putResult(finderPath, finderArgs, count);
308 }
309 catch (Exception e) {
310 FinderCacheUtil.removeResult(finderPath, finderArgs);
311
312 throw processException(e);
313 }
314 finally {
315 closeSession(session);
316 }
317 }
318
319 return count.intValue();
320 }
321
322 private static final String _FINDER_COLUMN_O_O_OWNERID_2 = "portalPreferences.ownerId = ? AND ";
323 private static final String _FINDER_COLUMN_O_O_OWNERTYPE_2 = "portalPreferences.ownerType = ?";
324
325
330 @Override
331 public void cacheResult(PortalPreferences portalPreferences) {
332 EntityCacheUtil.putResult(PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
333 PortalPreferencesImpl.class, portalPreferences.getPrimaryKey(),
334 portalPreferences);
335
336 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_O_O,
337 new Object[] {
338 portalPreferences.getOwnerId(), portalPreferences.getOwnerType()
339 }, portalPreferences);
340
341 portalPreferences.resetOriginalValues();
342 }
343
344
349 @Override
350 public void cacheResult(List<PortalPreferences> portalPreferenceses) {
351 for (PortalPreferences portalPreferences : portalPreferenceses) {
352 if (EntityCacheUtil.getResult(
353 PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
354 PortalPreferencesImpl.class,
355 portalPreferences.getPrimaryKey()) == null) {
356 cacheResult(portalPreferences);
357 }
358 else {
359 portalPreferences.resetOriginalValues();
360 }
361 }
362 }
363
364
371 @Override
372 public void clearCache() {
373 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
374 CacheRegistryUtil.clear(PortalPreferencesImpl.class.getName());
375 }
376
377 EntityCacheUtil.clearCache(PortalPreferencesImpl.class.getName());
378
379 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
380 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
381 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
382 }
383
384
391 @Override
392 public void clearCache(PortalPreferences portalPreferences) {
393 EntityCacheUtil.removeResult(PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
394 PortalPreferencesImpl.class, portalPreferences.getPrimaryKey());
395
396 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
397 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
398
399 clearUniqueFindersCache(portalPreferences);
400 }
401
402 @Override
403 public void clearCache(List<PortalPreferences> portalPreferenceses) {
404 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
405 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
406
407 for (PortalPreferences portalPreferences : portalPreferenceses) {
408 EntityCacheUtil.removeResult(PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
409 PortalPreferencesImpl.class, portalPreferences.getPrimaryKey());
410
411 clearUniqueFindersCache(portalPreferences);
412 }
413 }
414
415 protected void cacheUniqueFindersCache(PortalPreferences portalPreferences) {
416 if (portalPreferences.isNew()) {
417 Object[] args = new Object[] {
418 portalPreferences.getOwnerId(),
419 portalPreferences.getOwnerType()
420 };
421
422 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_O_O, args,
423 Long.valueOf(1));
424 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_O_O, args,
425 portalPreferences);
426 }
427 else {
428 PortalPreferencesModelImpl portalPreferencesModelImpl = (PortalPreferencesModelImpl)portalPreferences;
429
430 if ((portalPreferencesModelImpl.getColumnBitmask() &
431 FINDER_PATH_FETCH_BY_O_O.getColumnBitmask()) != 0) {
432 Object[] args = new Object[] {
433 portalPreferences.getOwnerId(),
434 portalPreferences.getOwnerType()
435 };
436
437 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_O_O, args,
438 Long.valueOf(1));
439 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_O_O, args,
440 portalPreferences);
441 }
442 }
443 }
444
445 protected void clearUniqueFindersCache(PortalPreferences portalPreferences) {
446 PortalPreferencesModelImpl portalPreferencesModelImpl = (PortalPreferencesModelImpl)portalPreferences;
447
448 Object[] args = new Object[] {
449 portalPreferences.getOwnerId(), portalPreferences.getOwnerType()
450 };
451
452 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_O_O, args);
453 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_O_O, args);
454
455 if ((portalPreferencesModelImpl.getColumnBitmask() &
456 FINDER_PATH_FETCH_BY_O_O.getColumnBitmask()) != 0) {
457 args = new Object[] {
458 portalPreferencesModelImpl.getOriginalOwnerId(),
459 portalPreferencesModelImpl.getOriginalOwnerType()
460 };
461
462 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_O_O, args);
463 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_O_O, args);
464 }
465 }
466
467
473 @Override
474 public PortalPreferences create(long portalPreferencesId) {
475 PortalPreferences portalPreferences = new PortalPreferencesImpl();
476
477 portalPreferences.setNew(true);
478 portalPreferences.setPrimaryKey(portalPreferencesId);
479
480 return portalPreferences;
481 }
482
483
491 @Override
492 public PortalPreferences remove(long portalPreferencesId)
493 throws NoSuchPreferencesException, SystemException {
494 return remove((Serializable)portalPreferencesId);
495 }
496
497
505 @Override
506 public PortalPreferences remove(Serializable primaryKey)
507 throws NoSuchPreferencesException, SystemException {
508 Session session = null;
509
510 try {
511 session = openSession();
512
513 PortalPreferences portalPreferences = (PortalPreferences)session.get(PortalPreferencesImpl.class,
514 primaryKey);
515
516 if (portalPreferences == null) {
517 if (_log.isWarnEnabled()) {
518 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
519 }
520
521 throw new NoSuchPreferencesException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
522 primaryKey);
523 }
524
525 return remove(portalPreferences);
526 }
527 catch (NoSuchPreferencesException nsee) {
528 throw nsee;
529 }
530 catch (Exception e) {
531 throw processException(e);
532 }
533 finally {
534 closeSession(session);
535 }
536 }
537
538 @Override
539 protected PortalPreferences removeImpl(PortalPreferences portalPreferences)
540 throws SystemException {
541 portalPreferences = toUnwrappedModel(portalPreferences);
542
543 Session session = null;
544
545 try {
546 session = openSession();
547
548 if (!session.contains(portalPreferences)) {
549 portalPreferences = (PortalPreferences)session.get(PortalPreferencesImpl.class,
550 portalPreferences.getPrimaryKeyObj());
551 }
552
553 if (portalPreferences != null) {
554 session.delete(portalPreferences);
555 }
556 }
557 catch (Exception e) {
558 throw processException(e);
559 }
560 finally {
561 closeSession(session);
562 }
563
564 if (portalPreferences != null) {
565 clearCache(portalPreferences);
566 }
567
568 return portalPreferences;
569 }
570
571 @Override
572 public PortalPreferences updateImpl(
573 com.liferay.portal.model.PortalPreferences portalPreferences)
574 throws SystemException {
575 portalPreferences = toUnwrappedModel(portalPreferences);
576
577 boolean isNew = portalPreferences.isNew();
578
579 Session session = null;
580
581 try {
582 session = openSession();
583
584 if (portalPreferences.isNew()) {
585 session.save(portalPreferences);
586
587 portalPreferences.setNew(false);
588 }
589 else {
590 session.merge(portalPreferences);
591 }
592 }
593 catch (Exception e) {
594 throw processException(e);
595 }
596 finally {
597 closeSession(session);
598 }
599
600 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
601
602 if (isNew || !PortalPreferencesModelImpl.COLUMN_BITMASK_ENABLED) {
603 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
604 }
605
606 EntityCacheUtil.putResult(PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
607 PortalPreferencesImpl.class, portalPreferences.getPrimaryKey(),
608 portalPreferences);
609
610 clearUniqueFindersCache(portalPreferences);
611 cacheUniqueFindersCache(portalPreferences);
612
613 return portalPreferences;
614 }
615
616 protected PortalPreferences toUnwrappedModel(
617 PortalPreferences portalPreferences) {
618 if (portalPreferences instanceof PortalPreferencesImpl) {
619 return portalPreferences;
620 }
621
622 PortalPreferencesImpl portalPreferencesImpl = new PortalPreferencesImpl();
623
624 portalPreferencesImpl.setNew(portalPreferences.isNew());
625 portalPreferencesImpl.setPrimaryKey(portalPreferences.getPrimaryKey());
626
627 portalPreferencesImpl.setPortalPreferencesId(portalPreferences.getPortalPreferencesId());
628 portalPreferencesImpl.setOwnerId(portalPreferences.getOwnerId());
629 portalPreferencesImpl.setOwnerType(portalPreferences.getOwnerType());
630 portalPreferencesImpl.setPreferences(portalPreferences.getPreferences());
631
632 return portalPreferencesImpl;
633 }
634
635
643 @Override
644 public PortalPreferences findByPrimaryKey(Serializable primaryKey)
645 throws NoSuchPreferencesException, SystemException {
646 PortalPreferences portalPreferences = fetchByPrimaryKey(primaryKey);
647
648 if (portalPreferences == null) {
649 if (_log.isWarnEnabled()) {
650 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
651 }
652
653 throw new NoSuchPreferencesException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
654 primaryKey);
655 }
656
657 return portalPreferences;
658 }
659
660
668 @Override
669 public PortalPreferences findByPrimaryKey(long portalPreferencesId)
670 throws NoSuchPreferencesException, SystemException {
671 return findByPrimaryKey((Serializable)portalPreferencesId);
672 }
673
674
681 @Override
682 public PortalPreferences fetchByPrimaryKey(Serializable primaryKey)
683 throws SystemException {
684 PortalPreferences portalPreferences = (PortalPreferences)EntityCacheUtil.getResult(PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
685 PortalPreferencesImpl.class, primaryKey);
686
687 if (portalPreferences == _nullPortalPreferences) {
688 return null;
689 }
690
691 if (portalPreferences == null) {
692 Session session = null;
693
694 try {
695 session = openSession();
696
697 portalPreferences = (PortalPreferences)session.get(PortalPreferencesImpl.class,
698 primaryKey);
699
700 if (portalPreferences != null) {
701 cacheResult(portalPreferences);
702 }
703 else {
704 EntityCacheUtil.putResult(PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
705 PortalPreferencesImpl.class, primaryKey,
706 _nullPortalPreferences);
707 }
708 }
709 catch (Exception e) {
710 EntityCacheUtil.removeResult(PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
711 PortalPreferencesImpl.class, primaryKey);
712
713 throw processException(e);
714 }
715 finally {
716 closeSession(session);
717 }
718 }
719
720 return portalPreferences;
721 }
722
723
730 @Override
731 public PortalPreferences fetchByPrimaryKey(long portalPreferencesId)
732 throws SystemException {
733 return fetchByPrimaryKey((Serializable)portalPreferencesId);
734 }
735
736
742 @Override
743 public List<PortalPreferences> findAll() throws SystemException {
744 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
745 }
746
747
759 @Override
760 public List<PortalPreferences> findAll(int start, int end)
761 throws SystemException {
762 return findAll(start, end, null);
763 }
764
765
778 @Override
779 public List<PortalPreferences> findAll(int start, int end,
780 OrderByComparator orderByComparator) throws SystemException {
781 boolean pagination = true;
782 FinderPath finderPath = null;
783 Object[] finderArgs = null;
784
785 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
786 (orderByComparator == null)) {
787 pagination = false;
788 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
789 finderArgs = FINDER_ARGS_EMPTY;
790 }
791 else {
792 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
793 finderArgs = new Object[] { start, end, orderByComparator };
794 }
795
796 List<PortalPreferences> list = (List<PortalPreferences>)FinderCacheUtil.getResult(finderPath,
797 finderArgs, this);
798
799 if (list == null) {
800 StringBundler query = null;
801 String sql = null;
802
803 if (orderByComparator != null) {
804 query = new StringBundler(2 +
805 (orderByComparator.getOrderByFields().length * 3));
806
807 query.append(_SQL_SELECT_PORTALPREFERENCES);
808
809 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
810 orderByComparator);
811
812 sql = query.toString();
813 }
814 else {
815 sql = _SQL_SELECT_PORTALPREFERENCES;
816
817 if (pagination) {
818 sql = sql.concat(PortalPreferencesModelImpl.ORDER_BY_JPQL);
819 }
820 }
821
822 Session session = null;
823
824 try {
825 session = openSession();
826
827 Query q = session.createQuery(sql);
828
829 if (!pagination) {
830 list = (List<PortalPreferences>)QueryUtil.list(q,
831 getDialect(), start, end, false);
832
833 Collections.sort(list);
834
835 list = new UnmodifiableList<PortalPreferences>(list);
836 }
837 else {
838 list = (List<PortalPreferences>)QueryUtil.list(q,
839 getDialect(), start, end);
840 }
841
842 cacheResult(list);
843
844 FinderCacheUtil.putResult(finderPath, finderArgs, list);
845 }
846 catch (Exception e) {
847 FinderCacheUtil.removeResult(finderPath, finderArgs);
848
849 throw processException(e);
850 }
851 finally {
852 closeSession(session);
853 }
854 }
855
856 return list;
857 }
858
859
864 @Override
865 public void removeAll() throws SystemException {
866 for (PortalPreferences portalPreferences : findAll()) {
867 remove(portalPreferences);
868 }
869 }
870
871
877 @Override
878 public int countAll() throws SystemException {
879 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
880 FINDER_ARGS_EMPTY, this);
881
882 if (count == null) {
883 Session session = null;
884
885 try {
886 session = openSession();
887
888 Query q = session.createQuery(_SQL_COUNT_PORTALPREFERENCES);
889
890 count = (Long)q.uniqueResult();
891
892 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
893 FINDER_ARGS_EMPTY, count);
894 }
895 catch (Exception e) {
896 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
897 FINDER_ARGS_EMPTY);
898
899 throw processException(e);
900 }
901 finally {
902 closeSession(session);
903 }
904 }
905
906 return count.intValue();
907 }
908
909
912 public void afterPropertiesSet() {
913 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
914 com.liferay.portal.util.PropsUtil.get(
915 "value.object.listener.com.liferay.portal.model.PortalPreferences")));
916
917 if (listenerClassNames.length > 0) {
918 try {
919 List<ModelListener<PortalPreferences>> listenersList = new ArrayList<ModelListener<PortalPreferences>>();
920
921 for (String listenerClassName : listenerClassNames) {
922 listenersList.add((ModelListener<PortalPreferences>)InstanceFactory.newInstance(
923 getClassLoader(), listenerClassName));
924 }
925
926 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
927 }
928 catch (Exception e) {
929 _log.error(e);
930 }
931 }
932 }
933
934 public void destroy() {
935 EntityCacheUtil.removeCache(PortalPreferencesImpl.class.getName());
936 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
937 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
938 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
939 }
940
941 private static final String _SQL_SELECT_PORTALPREFERENCES = "SELECT portalPreferences FROM PortalPreferences portalPreferences";
942 private static final String _SQL_SELECT_PORTALPREFERENCES_WHERE = "SELECT portalPreferences FROM PortalPreferences portalPreferences WHERE ";
943 private static final String _SQL_COUNT_PORTALPREFERENCES = "SELECT COUNT(portalPreferences) FROM PortalPreferences portalPreferences";
944 private static final String _SQL_COUNT_PORTALPREFERENCES_WHERE = "SELECT COUNT(portalPreferences) FROM PortalPreferences portalPreferences WHERE ";
945 private static final String _ORDER_BY_ENTITY_ALIAS = "portalPreferences.";
946 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No PortalPreferences exists with the primary key ";
947 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No PortalPreferences exists with the key {";
948 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
949 private static Log _log = LogFactoryUtil.getLog(PortalPreferencesPersistenceImpl.class);
950 private static PortalPreferences _nullPortalPreferences = new PortalPreferencesImpl() {
951 @Override
952 public Object clone() {
953 return this;
954 }
955
956 @Override
957 public CacheModel<PortalPreferences> toCacheModel() {
958 return _nullPortalPreferencesCacheModel;
959 }
960 };
961
962 private static CacheModel<PortalPreferences> _nullPortalPreferencesCacheModel =
963 new CacheModel<PortalPreferences>() {
964 @Override
965 public PortalPreferences toEntityModel() {
966 return _nullPortalPreferences;
967 }
968 };
969 }