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 public PortalPreferences findByO_O(long ownerId, int ownerType)
106 throws NoSuchPreferencesException, SystemException {
107 PortalPreferences portalPreferences = fetchByO_O(ownerId, ownerType);
108
109 if (portalPreferences == null) {
110 StringBundler msg = new StringBundler(6);
111
112 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
113
114 msg.append("ownerId=");
115 msg.append(ownerId);
116
117 msg.append(", ownerType=");
118 msg.append(ownerType);
119
120 msg.append(StringPool.CLOSE_CURLY_BRACE);
121
122 if (_log.isWarnEnabled()) {
123 _log.warn(msg.toString());
124 }
125
126 throw new NoSuchPreferencesException(msg.toString());
127 }
128
129 return portalPreferences;
130 }
131
132
140 public PortalPreferences fetchByO_O(long ownerId, int ownerType)
141 throws SystemException {
142 return fetchByO_O(ownerId, ownerType, true);
143 }
144
145
154 public PortalPreferences fetchByO_O(long ownerId, int ownerType,
155 boolean retrieveFromCache) throws SystemException {
156 Object[] finderArgs = new Object[] { ownerId, ownerType };
157
158 Object result = null;
159
160 if (retrieveFromCache) {
161 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_O_O,
162 finderArgs, this);
163 }
164
165 if (result instanceof PortalPreferences) {
166 PortalPreferences portalPreferences = (PortalPreferences)result;
167
168 if ((ownerId != portalPreferences.getOwnerId()) ||
169 (ownerType != portalPreferences.getOwnerType())) {
170 result = null;
171 }
172 }
173
174 if (result == null) {
175 StringBundler query = new StringBundler(4);
176
177 query.append(_SQL_SELECT_PORTALPREFERENCES_WHERE);
178
179 query.append(_FINDER_COLUMN_O_O_OWNERID_2);
180
181 query.append(_FINDER_COLUMN_O_O_OWNERTYPE_2);
182
183 String sql = query.toString();
184
185 Session session = null;
186
187 try {
188 session = openSession();
189
190 Query q = session.createQuery(sql);
191
192 QueryPos qPos = QueryPos.getInstance(q);
193
194 qPos.add(ownerId);
195
196 qPos.add(ownerType);
197
198 List<PortalPreferences> list = q.list();
199
200 if (list.isEmpty()) {
201 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_O_O,
202 finderArgs, list);
203 }
204 else {
205 if ((list.size() > 1) && _log.isWarnEnabled()) {
206 _log.warn(
207 "PortalPreferencesPersistenceImpl.fetchByO_O(long, int, boolean) with parameters (" +
208 StringUtil.merge(finderArgs) +
209 ") 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.");
210 }
211
212 PortalPreferences portalPreferences = list.get(0);
213
214 result = portalPreferences;
215
216 cacheResult(portalPreferences);
217
218 if ((portalPreferences.getOwnerId() != ownerId) ||
219 (portalPreferences.getOwnerType() != ownerType)) {
220 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_O_O,
221 finderArgs, portalPreferences);
222 }
223 }
224 }
225 catch (Exception e) {
226 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_O_O,
227 finderArgs);
228
229 throw processException(e);
230 }
231 finally {
232 closeSession(session);
233 }
234 }
235
236 if (result instanceof List<?>) {
237 return null;
238 }
239 else {
240 return (PortalPreferences)result;
241 }
242 }
243
244
252 public PortalPreferences removeByO_O(long ownerId, int ownerType)
253 throws NoSuchPreferencesException, SystemException {
254 PortalPreferences portalPreferences = findByO_O(ownerId, ownerType);
255
256 return remove(portalPreferences);
257 }
258
259
267 public int countByO_O(long ownerId, int ownerType)
268 throws SystemException {
269 FinderPath finderPath = FINDER_PATH_COUNT_BY_O_O;
270
271 Object[] finderArgs = new Object[] { ownerId, ownerType };
272
273 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
274 this);
275
276 if (count == null) {
277 StringBundler query = new StringBundler(3);
278
279 query.append(_SQL_COUNT_PORTALPREFERENCES_WHERE);
280
281 query.append(_FINDER_COLUMN_O_O_OWNERID_2);
282
283 query.append(_FINDER_COLUMN_O_O_OWNERTYPE_2);
284
285 String sql = query.toString();
286
287 Session session = null;
288
289 try {
290 session = openSession();
291
292 Query q = session.createQuery(sql);
293
294 QueryPos qPos = QueryPos.getInstance(q);
295
296 qPos.add(ownerId);
297
298 qPos.add(ownerType);
299
300 count = (Long)q.uniqueResult();
301
302 FinderCacheUtil.putResult(finderPath, finderArgs, count);
303 }
304 catch (Exception e) {
305 FinderCacheUtil.removeResult(finderPath, finderArgs);
306
307 throw processException(e);
308 }
309 finally {
310 closeSession(session);
311 }
312 }
313
314 return count.intValue();
315 }
316
317 private static final String _FINDER_COLUMN_O_O_OWNERID_2 = "portalPreferences.ownerId = ? AND ";
318 private static final String _FINDER_COLUMN_O_O_OWNERTYPE_2 = "portalPreferences.ownerType = ?";
319
320
325 public void cacheResult(PortalPreferences portalPreferences) {
326 EntityCacheUtil.putResult(PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
327 PortalPreferencesImpl.class, portalPreferences.getPrimaryKey(),
328 portalPreferences);
329
330 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_O_O,
331 new Object[] {
332 portalPreferences.getOwnerId(), portalPreferences.getOwnerType()
333 }, portalPreferences);
334
335 portalPreferences.resetOriginalValues();
336 }
337
338
343 public void cacheResult(List<PortalPreferences> portalPreferenceses) {
344 for (PortalPreferences portalPreferences : portalPreferenceses) {
345 if (EntityCacheUtil.getResult(
346 PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
347 PortalPreferencesImpl.class,
348 portalPreferences.getPrimaryKey()) == null) {
349 cacheResult(portalPreferences);
350 }
351 else {
352 portalPreferences.resetOriginalValues();
353 }
354 }
355 }
356
357
364 @Override
365 public void clearCache() {
366 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
367 CacheRegistryUtil.clear(PortalPreferencesImpl.class.getName());
368 }
369
370 EntityCacheUtil.clearCache(PortalPreferencesImpl.class.getName());
371
372 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
373 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
374 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
375 }
376
377
384 @Override
385 public void clearCache(PortalPreferences portalPreferences) {
386 EntityCacheUtil.removeResult(PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
387 PortalPreferencesImpl.class, portalPreferences.getPrimaryKey());
388
389 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
390 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
391
392 clearUniqueFindersCache(portalPreferences);
393 }
394
395 @Override
396 public void clearCache(List<PortalPreferences> portalPreferenceses) {
397 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
398 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
399
400 for (PortalPreferences portalPreferences : portalPreferenceses) {
401 EntityCacheUtil.removeResult(PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
402 PortalPreferencesImpl.class, portalPreferences.getPrimaryKey());
403
404 clearUniqueFindersCache(portalPreferences);
405 }
406 }
407
408 protected void cacheUniqueFindersCache(PortalPreferences portalPreferences) {
409 if (portalPreferences.isNew()) {
410 Object[] args = new Object[] {
411 portalPreferences.getOwnerId(),
412 portalPreferences.getOwnerType()
413 };
414
415 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_O_O, args,
416 Long.valueOf(1));
417 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_O_O, args,
418 portalPreferences);
419 }
420 else {
421 PortalPreferencesModelImpl portalPreferencesModelImpl = (PortalPreferencesModelImpl)portalPreferences;
422
423 if ((portalPreferencesModelImpl.getColumnBitmask() &
424 FINDER_PATH_FETCH_BY_O_O.getColumnBitmask()) != 0) {
425 Object[] args = new Object[] {
426 portalPreferences.getOwnerId(),
427 portalPreferences.getOwnerType()
428 };
429
430 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_O_O, args,
431 Long.valueOf(1));
432 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_O_O, args,
433 portalPreferences);
434 }
435 }
436 }
437
438 protected void clearUniqueFindersCache(PortalPreferences portalPreferences) {
439 PortalPreferencesModelImpl portalPreferencesModelImpl = (PortalPreferencesModelImpl)portalPreferences;
440
441 Object[] args = new Object[] {
442 portalPreferences.getOwnerId(), portalPreferences.getOwnerType()
443 };
444
445 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_O_O, args);
446 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_O_O, args);
447
448 if ((portalPreferencesModelImpl.getColumnBitmask() &
449 FINDER_PATH_FETCH_BY_O_O.getColumnBitmask()) != 0) {
450 args = new Object[] {
451 portalPreferencesModelImpl.getOriginalOwnerId(),
452 portalPreferencesModelImpl.getOriginalOwnerType()
453 };
454
455 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_O_O, args);
456 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_O_O, args);
457 }
458 }
459
460
466 public PortalPreferences create(long portalPreferencesId) {
467 PortalPreferences portalPreferences = new PortalPreferencesImpl();
468
469 portalPreferences.setNew(true);
470 portalPreferences.setPrimaryKey(portalPreferencesId);
471
472 return portalPreferences;
473 }
474
475
483 public PortalPreferences remove(long portalPreferencesId)
484 throws NoSuchPreferencesException, SystemException {
485 return remove((Serializable)portalPreferencesId);
486 }
487
488
496 @Override
497 public PortalPreferences remove(Serializable primaryKey)
498 throws NoSuchPreferencesException, SystemException {
499 Session session = null;
500
501 try {
502 session = openSession();
503
504 PortalPreferences portalPreferences = (PortalPreferences)session.get(PortalPreferencesImpl.class,
505 primaryKey);
506
507 if (portalPreferences == null) {
508 if (_log.isWarnEnabled()) {
509 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
510 }
511
512 throw new NoSuchPreferencesException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
513 primaryKey);
514 }
515
516 return remove(portalPreferences);
517 }
518 catch (NoSuchPreferencesException nsee) {
519 throw nsee;
520 }
521 catch (Exception e) {
522 throw processException(e);
523 }
524 finally {
525 closeSession(session);
526 }
527 }
528
529 @Override
530 protected PortalPreferences removeImpl(PortalPreferences portalPreferences)
531 throws SystemException {
532 portalPreferences = toUnwrappedModel(portalPreferences);
533
534 Session session = null;
535
536 try {
537 session = openSession();
538
539 if (!session.contains(portalPreferences)) {
540 portalPreferences = (PortalPreferences)session.get(PortalPreferencesImpl.class,
541 portalPreferences.getPrimaryKeyObj());
542 }
543
544 if (portalPreferences != null) {
545 session.delete(portalPreferences);
546 }
547 }
548 catch (Exception e) {
549 throw processException(e);
550 }
551 finally {
552 closeSession(session);
553 }
554
555 if (portalPreferences != null) {
556 clearCache(portalPreferences);
557 }
558
559 return portalPreferences;
560 }
561
562 @Override
563 public PortalPreferences updateImpl(
564 com.liferay.portal.model.PortalPreferences portalPreferences)
565 throws SystemException {
566 portalPreferences = toUnwrappedModel(portalPreferences);
567
568 boolean isNew = portalPreferences.isNew();
569
570 Session session = null;
571
572 try {
573 session = openSession();
574
575 if (portalPreferences.isNew()) {
576 session.save(portalPreferences);
577
578 portalPreferences.setNew(false);
579 }
580 else {
581 session.merge(portalPreferences);
582 }
583 }
584 catch (Exception e) {
585 throw processException(e);
586 }
587 finally {
588 closeSession(session);
589 }
590
591 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
592
593 if (isNew || !PortalPreferencesModelImpl.COLUMN_BITMASK_ENABLED) {
594 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
595 }
596
597 EntityCacheUtil.putResult(PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
598 PortalPreferencesImpl.class, portalPreferences.getPrimaryKey(),
599 portalPreferences);
600
601 clearUniqueFindersCache(portalPreferences);
602 cacheUniqueFindersCache(portalPreferences);
603
604 return portalPreferences;
605 }
606
607 protected PortalPreferences toUnwrappedModel(
608 PortalPreferences portalPreferences) {
609 if (portalPreferences instanceof PortalPreferencesImpl) {
610 return portalPreferences;
611 }
612
613 PortalPreferencesImpl portalPreferencesImpl = new PortalPreferencesImpl();
614
615 portalPreferencesImpl.setNew(portalPreferences.isNew());
616 portalPreferencesImpl.setPrimaryKey(portalPreferences.getPrimaryKey());
617
618 portalPreferencesImpl.setPortalPreferencesId(portalPreferences.getPortalPreferencesId());
619 portalPreferencesImpl.setOwnerId(portalPreferences.getOwnerId());
620 portalPreferencesImpl.setOwnerType(portalPreferences.getOwnerType());
621 portalPreferencesImpl.setPreferences(portalPreferences.getPreferences());
622
623 return portalPreferencesImpl;
624 }
625
626
634 @Override
635 public PortalPreferences findByPrimaryKey(Serializable primaryKey)
636 throws NoSuchPreferencesException, SystemException {
637 PortalPreferences portalPreferences = fetchByPrimaryKey(primaryKey);
638
639 if (portalPreferences == null) {
640 if (_log.isWarnEnabled()) {
641 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
642 }
643
644 throw new NoSuchPreferencesException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
645 primaryKey);
646 }
647
648 return portalPreferences;
649 }
650
651
659 public PortalPreferences findByPrimaryKey(long portalPreferencesId)
660 throws NoSuchPreferencesException, SystemException {
661 return findByPrimaryKey((Serializable)portalPreferencesId);
662 }
663
664
671 @Override
672 public PortalPreferences fetchByPrimaryKey(Serializable primaryKey)
673 throws SystemException {
674 PortalPreferences portalPreferences = (PortalPreferences)EntityCacheUtil.getResult(PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
675 PortalPreferencesImpl.class, primaryKey);
676
677 if (portalPreferences == _nullPortalPreferences) {
678 return null;
679 }
680
681 if (portalPreferences == null) {
682 Session session = null;
683
684 try {
685 session = openSession();
686
687 portalPreferences = (PortalPreferences)session.get(PortalPreferencesImpl.class,
688 primaryKey);
689
690 if (portalPreferences != null) {
691 cacheResult(portalPreferences);
692 }
693 else {
694 EntityCacheUtil.putResult(PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
695 PortalPreferencesImpl.class, primaryKey,
696 _nullPortalPreferences);
697 }
698 }
699 catch (Exception e) {
700 EntityCacheUtil.removeResult(PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
701 PortalPreferencesImpl.class, primaryKey);
702
703 throw processException(e);
704 }
705 finally {
706 closeSession(session);
707 }
708 }
709
710 return portalPreferences;
711 }
712
713
720 public PortalPreferences fetchByPrimaryKey(long portalPreferencesId)
721 throws SystemException {
722 return fetchByPrimaryKey((Serializable)portalPreferencesId);
723 }
724
725
731 public List<PortalPreferences> findAll() throws SystemException {
732 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
733 }
734
735
747 public List<PortalPreferences> findAll(int start, int end)
748 throws SystemException {
749 return findAll(start, end, null);
750 }
751
752
765 public List<PortalPreferences> findAll(int start, int end,
766 OrderByComparator orderByComparator) throws SystemException {
767 boolean pagination = true;
768 FinderPath finderPath = null;
769 Object[] finderArgs = null;
770
771 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
772 (orderByComparator == null)) {
773 pagination = false;
774 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
775 finderArgs = FINDER_ARGS_EMPTY;
776 }
777 else {
778 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
779 finderArgs = new Object[] { start, end, orderByComparator };
780 }
781
782 List<PortalPreferences> list = (List<PortalPreferences>)FinderCacheUtil.getResult(finderPath,
783 finderArgs, this);
784
785 if (list == null) {
786 StringBundler query = null;
787 String sql = null;
788
789 if (orderByComparator != null) {
790 query = new StringBundler(2 +
791 (orderByComparator.getOrderByFields().length * 3));
792
793 query.append(_SQL_SELECT_PORTALPREFERENCES);
794
795 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
796 orderByComparator);
797
798 sql = query.toString();
799 }
800 else {
801 sql = _SQL_SELECT_PORTALPREFERENCES;
802
803 if (pagination) {
804 sql = sql.concat(PortalPreferencesModelImpl.ORDER_BY_JPQL);
805 }
806 }
807
808 Session session = null;
809
810 try {
811 session = openSession();
812
813 Query q = session.createQuery(sql);
814
815 if (!pagination) {
816 list = (List<PortalPreferences>)QueryUtil.list(q,
817 getDialect(), start, end, false);
818
819 Collections.sort(list);
820
821 list = new UnmodifiableList<PortalPreferences>(list);
822 }
823 else {
824 list = (List<PortalPreferences>)QueryUtil.list(q,
825 getDialect(), start, end);
826 }
827
828 cacheResult(list);
829
830 FinderCacheUtil.putResult(finderPath, finderArgs, list);
831 }
832 catch (Exception e) {
833 FinderCacheUtil.removeResult(finderPath, finderArgs);
834
835 throw processException(e);
836 }
837 finally {
838 closeSession(session);
839 }
840 }
841
842 return list;
843 }
844
845
850 public void removeAll() throws SystemException {
851 for (PortalPreferences portalPreferences : findAll()) {
852 remove(portalPreferences);
853 }
854 }
855
856
862 public int countAll() throws SystemException {
863 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
864 FINDER_ARGS_EMPTY, this);
865
866 if (count == null) {
867 Session session = null;
868
869 try {
870 session = openSession();
871
872 Query q = session.createQuery(_SQL_COUNT_PORTALPREFERENCES);
873
874 count = (Long)q.uniqueResult();
875
876 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
877 FINDER_ARGS_EMPTY, count);
878 }
879 catch (Exception e) {
880 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
881 FINDER_ARGS_EMPTY);
882
883 throw processException(e);
884 }
885 finally {
886 closeSession(session);
887 }
888 }
889
890 return count.intValue();
891 }
892
893
896 public void afterPropertiesSet() {
897 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
898 com.liferay.portal.util.PropsUtil.get(
899 "value.object.listener.com.liferay.portal.model.PortalPreferences")));
900
901 if (listenerClassNames.length > 0) {
902 try {
903 List<ModelListener<PortalPreferences>> listenersList = new ArrayList<ModelListener<PortalPreferences>>();
904
905 for (String listenerClassName : listenerClassNames) {
906 listenersList.add((ModelListener<PortalPreferences>)InstanceFactory.newInstance(
907 getClassLoader(), listenerClassName));
908 }
909
910 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
911 }
912 catch (Exception e) {
913 _log.error(e);
914 }
915 }
916 }
917
918 public void destroy() {
919 EntityCacheUtil.removeCache(PortalPreferencesImpl.class.getName());
920 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
921 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
922 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
923 }
924
925 private static final String _SQL_SELECT_PORTALPREFERENCES = "SELECT portalPreferences FROM PortalPreferences portalPreferences";
926 private static final String _SQL_SELECT_PORTALPREFERENCES_WHERE = "SELECT portalPreferences FROM PortalPreferences portalPreferences WHERE ";
927 private static final String _SQL_COUNT_PORTALPREFERENCES = "SELECT COUNT(portalPreferences) FROM PortalPreferences portalPreferences";
928 private static final String _SQL_COUNT_PORTALPREFERENCES_WHERE = "SELECT COUNT(portalPreferences) FROM PortalPreferences portalPreferences WHERE ";
929 private static final String _ORDER_BY_ENTITY_ALIAS = "portalPreferences.";
930 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No PortalPreferences exists with the primary key ";
931 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No PortalPreferences exists with the key {";
932 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
933 private static Log _log = LogFactoryUtil.getLog(PortalPreferencesPersistenceImpl.class);
934 private static PortalPreferences _nullPortalPreferences = new PortalPreferencesImpl() {
935 @Override
936 public Object clone() {
937 return this;
938 }
939
940 @Override
941 public CacheModel<PortalPreferences> toCacheModel() {
942 return _nullPortalPreferencesCacheModel;
943 }
944 };
945
946 private static CacheModel<PortalPreferences> _nullPortalPreferencesCacheModel =
947 new CacheModel<PortalPreferences>() {
948 public PortalPreferences toEntityModel() {
949 return _nullPortalPreferences;
950 }
951 };
952 }