001
014
015 package com.liferay.portal.service.persistence.impl;
016
017 import aQute.bnd.annotation.ProviderType;
018
019 import com.liferay.portal.NoSuchPreferencesException;
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.log.Log;
029 import com.liferay.portal.kernel.log.LogFactoryUtil;
030 import com.liferay.portal.kernel.util.OrderByComparator;
031 import com.liferay.portal.kernel.util.StringBundler;
032 import com.liferay.portal.kernel.util.StringPool;
033 import com.liferay.portal.kernel.util.StringUtil;
034 import com.liferay.portal.model.CacheModel;
035 import com.liferay.portal.model.MVCCModel;
036 import com.liferay.portal.model.PortalPreferences;
037 import com.liferay.portal.model.impl.PortalPreferencesImpl;
038 import com.liferay.portal.model.impl.PortalPreferencesModelImpl;
039 import com.liferay.portal.service.persistence.PortalPreferencesPersistence;
040
041 import java.io.Serializable;
042
043 import java.util.Collections;
044 import java.util.HashMap;
045 import java.util.HashSet;
046 import java.util.Iterator;
047 import java.util.List;
048 import java.util.Map;
049 import java.util.Set;
050
051
063 @ProviderType
064 public class PortalPreferencesPersistenceImpl extends BasePersistenceImpl<PortalPreferences>
065 implements PortalPreferencesPersistence {
066
071 public static final String FINDER_CLASS_NAME_ENTITY = PortalPreferencesImpl.class.getName();
072 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
073 ".List1";
074 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
075 ".List2";
076 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
077 PortalPreferencesModelImpl.FINDER_CACHE_ENABLED,
078 PortalPreferencesImpl.class,
079 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
080 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
081 PortalPreferencesModelImpl.FINDER_CACHE_ENABLED,
082 PortalPreferencesImpl.class,
083 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
084 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
085 PortalPreferencesModelImpl.FINDER_CACHE_ENABLED, Long.class,
086 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
087 public static final FinderPath FINDER_PATH_FETCH_BY_O_O = new FinderPath(PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
088 PortalPreferencesModelImpl.FINDER_CACHE_ENABLED,
089 PortalPreferencesImpl.class, FINDER_CLASS_NAME_ENTITY,
090 "fetchByO_O",
091 new String[] { Long.class.getName(), Integer.class.getName() },
092 PortalPreferencesModelImpl.OWNERID_COLUMN_BITMASK |
093 PortalPreferencesModelImpl.OWNERTYPE_COLUMN_BITMASK);
094 public static final FinderPath FINDER_PATH_COUNT_BY_O_O = new FinderPath(PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
095 PortalPreferencesModelImpl.FINDER_CACHE_ENABLED, Long.class,
096 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByO_O",
097 new String[] { Long.class.getName(), Integer.class.getName() });
098
099
107 @Override
108 public PortalPreferences findByO_O(long ownerId, int ownerType)
109 throws NoSuchPreferencesException {
110 PortalPreferences portalPreferences = fetchByO_O(ownerId, ownerType);
111
112 if (portalPreferences == null) {
113 StringBundler msg = new StringBundler(6);
114
115 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
116
117 msg.append("ownerId=");
118 msg.append(ownerId);
119
120 msg.append(", ownerType=");
121 msg.append(ownerType);
122
123 msg.append(StringPool.CLOSE_CURLY_BRACE);
124
125 if (_log.isWarnEnabled()) {
126 _log.warn(msg.toString());
127 }
128
129 throw new NoSuchPreferencesException(msg.toString());
130 }
131
132 return portalPreferences;
133 }
134
135
142 @Override
143 public PortalPreferences fetchByO_O(long ownerId, int ownerType) {
144 return fetchByO_O(ownerId, ownerType, true);
145 }
146
147
155 @Override
156 public PortalPreferences fetchByO_O(long ownerId, int ownerType,
157 boolean retrieveFromCache) {
158 Object[] finderArgs = new Object[] { ownerId, ownerType };
159
160 Object result = null;
161
162 if (retrieveFromCache) {
163 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_O_O,
164 finderArgs, this);
165 }
166
167 if (result instanceof PortalPreferences) {
168 PortalPreferences portalPreferences = (PortalPreferences)result;
169
170 if ((ownerId != portalPreferences.getOwnerId()) ||
171 (ownerType != portalPreferences.getOwnerType())) {
172 result = null;
173 }
174 }
175
176 if (result == null) {
177 StringBundler query = new StringBundler(4);
178
179 query.append(_SQL_SELECT_PORTALPREFERENCES_WHERE);
180
181 query.append(_FINDER_COLUMN_O_O_OWNERID_2);
182
183 query.append(_FINDER_COLUMN_O_O_OWNERTYPE_2);
184
185 String sql = query.toString();
186
187 Session session = null;
188
189 try {
190 session = openSession();
191
192 Query q = session.createQuery(sql);
193
194 QueryPos qPos = QueryPos.getInstance(q);
195
196 qPos.add(ownerId);
197
198 qPos.add(ownerType);
199
200 List<PortalPreferences> list = q.list();
201
202 if (list.isEmpty()) {
203 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_O_O,
204 finderArgs, list);
205 }
206 else {
207 if ((list.size() > 1) && _log.isWarnEnabled()) {
208 _log.warn(
209 "PortalPreferencesPersistenceImpl.fetchByO_O(long, int, boolean) with parameters (" +
210 StringUtil.merge(finderArgs) +
211 ") 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.");
212 }
213
214 PortalPreferences portalPreferences = list.get(0);
215
216 result = portalPreferences;
217
218 cacheResult(portalPreferences);
219
220 if ((portalPreferences.getOwnerId() != ownerId) ||
221 (portalPreferences.getOwnerType() != ownerType)) {
222 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_O_O,
223 finderArgs, portalPreferences);
224 }
225 }
226 }
227 catch (Exception e) {
228 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_O_O,
229 finderArgs);
230
231 throw processException(e);
232 }
233 finally {
234 closeSession(session);
235 }
236 }
237
238 if (result instanceof List<?>) {
239 return null;
240 }
241 else {
242 return (PortalPreferences)result;
243 }
244 }
245
246
253 @Override
254 public PortalPreferences removeByO_O(long ownerId, int ownerType)
255 throws NoSuchPreferencesException {
256 PortalPreferences portalPreferences = findByO_O(ownerId, ownerType);
257
258 return remove(portalPreferences);
259 }
260
261
268 @Override
269 public int countByO_O(long ownerId, int ownerType) {
270 FinderPath finderPath = FINDER_PATH_COUNT_BY_O_O;
271
272 Object[] finderArgs = new Object[] { ownerId, ownerType };
273
274 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
275 this);
276
277 if (count == null) {
278 StringBundler query = new StringBundler(3);
279
280 query.append(_SQL_COUNT_PORTALPREFERENCES_WHERE);
281
282 query.append(_FINDER_COLUMN_O_O_OWNERID_2);
283
284 query.append(_FINDER_COLUMN_O_O_OWNERTYPE_2);
285
286 String sql = query.toString();
287
288 Session session = null;
289
290 try {
291 session = openSession();
292
293 Query q = session.createQuery(sql);
294
295 QueryPos qPos = QueryPos.getInstance(q);
296
297 qPos.add(ownerId);
298
299 qPos.add(ownerType);
300
301 count = (Long)q.uniqueResult();
302
303 FinderCacheUtil.putResult(finderPath, finderArgs, count);
304 }
305 catch (Exception e) {
306 FinderCacheUtil.removeResult(finderPath, finderArgs);
307
308 throw processException(e);
309 }
310 finally {
311 closeSession(session);
312 }
313 }
314
315 return count.intValue();
316 }
317
318 private static final String _FINDER_COLUMN_O_O_OWNERID_2 = "portalPreferences.ownerId = ? AND ";
319 private static final String _FINDER_COLUMN_O_O_OWNERTYPE_2 = "portalPreferences.ownerType = ?";
320
321 public PortalPreferencesPersistenceImpl() {
322 setModelClass(PortalPreferences.class);
323 }
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);
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
490 @Override
491 public PortalPreferences remove(long portalPreferencesId)
492 throws NoSuchPreferencesException {
493 return remove((Serializable)portalPreferencesId);
494 }
495
496
503 @Override
504 public PortalPreferences remove(Serializable primaryKey)
505 throws NoSuchPreferencesException {
506 Session session = null;
507
508 try {
509 session = openSession();
510
511 PortalPreferences portalPreferences = (PortalPreferences)session.get(PortalPreferencesImpl.class,
512 primaryKey);
513
514 if (portalPreferences == null) {
515 if (_log.isWarnEnabled()) {
516 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
517 }
518
519 throw new NoSuchPreferencesException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
520 primaryKey);
521 }
522
523 return remove(portalPreferences);
524 }
525 catch (NoSuchPreferencesException nsee) {
526 throw nsee;
527 }
528 catch (Exception e) {
529 throw processException(e);
530 }
531 finally {
532 closeSession(session);
533 }
534 }
535
536 @Override
537 protected PortalPreferences removeImpl(PortalPreferences portalPreferences) {
538 portalPreferences = toUnwrappedModel(portalPreferences);
539
540 Session session = null;
541
542 try {
543 session = openSession();
544
545 if (!session.contains(portalPreferences)) {
546 portalPreferences = (PortalPreferences)session.get(PortalPreferencesImpl.class,
547 portalPreferences.getPrimaryKeyObj());
548 }
549
550 if (portalPreferences != null) {
551 session.delete(portalPreferences);
552 }
553 }
554 catch (Exception e) {
555 throw processException(e);
556 }
557 finally {
558 closeSession(session);
559 }
560
561 if (portalPreferences != null) {
562 clearCache(portalPreferences);
563 }
564
565 return portalPreferences;
566 }
567
568 @Override
569 public PortalPreferences updateImpl(
570 com.liferay.portal.model.PortalPreferences portalPreferences) {
571 portalPreferences = toUnwrappedModel(portalPreferences);
572
573 boolean isNew = portalPreferences.isNew();
574
575 Session session = null;
576
577 try {
578 session = openSession();
579
580 if (portalPreferences.isNew()) {
581 session.save(portalPreferences);
582
583 portalPreferences.setNew(false);
584 }
585 else {
586 session.merge(portalPreferences);
587 }
588 }
589 catch (Exception e) {
590 throw processException(e);
591 }
592 finally {
593 closeSession(session);
594 }
595
596 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
597
598 if (isNew || !PortalPreferencesModelImpl.COLUMN_BITMASK_ENABLED) {
599 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
600 }
601
602 EntityCacheUtil.putResult(PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
603 PortalPreferencesImpl.class, portalPreferences.getPrimaryKey(),
604 portalPreferences, false);
605
606 clearUniqueFindersCache(portalPreferences);
607 cacheUniqueFindersCache(portalPreferences);
608
609 portalPreferences.resetOriginalValues();
610
611 return portalPreferences;
612 }
613
614 protected PortalPreferences toUnwrappedModel(
615 PortalPreferences portalPreferences) {
616 if (portalPreferences instanceof PortalPreferencesImpl) {
617 return portalPreferences;
618 }
619
620 PortalPreferencesImpl portalPreferencesImpl = new PortalPreferencesImpl();
621
622 portalPreferencesImpl.setNew(portalPreferences.isNew());
623 portalPreferencesImpl.setPrimaryKey(portalPreferences.getPrimaryKey());
624
625 portalPreferencesImpl.setMvccVersion(portalPreferences.getMvccVersion());
626 portalPreferencesImpl.setPortalPreferencesId(portalPreferences.getPortalPreferencesId());
627 portalPreferencesImpl.setOwnerId(portalPreferences.getOwnerId());
628 portalPreferencesImpl.setOwnerType(portalPreferences.getOwnerType());
629 portalPreferencesImpl.setPreferences(portalPreferences.getPreferences());
630
631 return portalPreferencesImpl;
632 }
633
634
641 @Override
642 public PortalPreferences findByPrimaryKey(Serializable primaryKey)
643 throws NoSuchPreferencesException {
644 PortalPreferences portalPreferences = fetchByPrimaryKey(primaryKey);
645
646 if (portalPreferences == null) {
647 if (_log.isWarnEnabled()) {
648 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
649 }
650
651 throw new NoSuchPreferencesException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
652 primaryKey);
653 }
654
655 return portalPreferences;
656 }
657
658
665 @Override
666 public PortalPreferences findByPrimaryKey(long portalPreferencesId)
667 throws NoSuchPreferencesException {
668 return findByPrimaryKey((Serializable)portalPreferencesId);
669 }
670
671
677 @Override
678 public PortalPreferences fetchByPrimaryKey(Serializable primaryKey) {
679 PortalPreferences portalPreferences = (PortalPreferences)EntityCacheUtil.getResult(PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
680 PortalPreferencesImpl.class, primaryKey);
681
682 if (portalPreferences == _nullPortalPreferences) {
683 return null;
684 }
685
686 if (portalPreferences == null) {
687 Session session = null;
688
689 try {
690 session = openSession();
691
692 portalPreferences = (PortalPreferences)session.get(PortalPreferencesImpl.class,
693 primaryKey);
694
695 if (portalPreferences != null) {
696 cacheResult(portalPreferences);
697 }
698 else {
699 EntityCacheUtil.putResult(PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
700 PortalPreferencesImpl.class, primaryKey,
701 _nullPortalPreferences);
702 }
703 }
704 catch (Exception e) {
705 EntityCacheUtil.removeResult(PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
706 PortalPreferencesImpl.class, primaryKey);
707
708 throw processException(e);
709 }
710 finally {
711 closeSession(session);
712 }
713 }
714
715 return portalPreferences;
716 }
717
718
724 @Override
725 public PortalPreferences fetchByPrimaryKey(long portalPreferencesId) {
726 return fetchByPrimaryKey((Serializable)portalPreferencesId);
727 }
728
729 @Override
730 public Map<Serializable, PortalPreferences> fetchByPrimaryKeys(
731 Set<Serializable> primaryKeys) {
732 if (primaryKeys.isEmpty()) {
733 return Collections.emptyMap();
734 }
735
736 Map<Serializable, PortalPreferences> map = new HashMap<Serializable, PortalPreferences>();
737
738 if (primaryKeys.size() == 1) {
739 Iterator<Serializable> iterator = primaryKeys.iterator();
740
741 Serializable primaryKey = iterator.next();
742
743 PortalPreferences portalPreferences = fetchByPrimaryKey(primaryKey);
744
745 if (portalPreferences != null) {
746 map.put(primaryKey, portalPreferences);
747 }
748
749 return map;
750 }
751
752 Set<Serializable> uncachedPrimaryKeys = null;
753
754 for (Serializable primaryKey : primaryKeys) {
755 PortalPreferences portalPreferences = (PortalPreferences)EntityCacheUtil.getResult(PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
756 PortalPreferencesImpl.class, primaryKey);
757
758 if (portalPreferences == null) {
759 if (uncachedPrimaryKeys == null) {
760 uncachedPrimaryKeys = new HashSet<Serializable>();
761 }
762
763 uncachedPrimaryKeys.add(primaryKey);
764 }
765 else {
766 map.put(primaryKey, portalPreferences);
767 }
768 }
769
770 if (uncachedPrimaryKeys == null) {
771 return map;
772 }
773
774 StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
775 1);
776
777 query.append(_SQL_SELECT_PORTALPREFERENCES_WHERE_PKS_IN);
778
779 for (Serializable primaryKey : uncachedPrimaryKeys) {
780 query.append(String.valueOf(primaryKey));
781
782 query.append(StringPool.COMMA);
783 }
784
785 query.setIndex(query.index() - 1);
786
787 query.append(StringPool.CLOSE_PARENTHESIS);
788
789 String sql = query.toString();
790
791 Session session = null;
792
793 try {
794 session = openSession();
795
796 Query q = session.createQuery(sql);
797
798 for (PortalPreferences portalPreferences : (List<PortalPreferences>)q.list()) {
799 map.put(portalPreferences.getPrimaryKeyObj(), portalPreferences);
800
801 cacheResult(portalPreferences);
802
803 uncachedPrimaryKeys.remove(portalPreferences.getPrimaryKeyObj());
804 }
805
806 for (Serializable primaryKey : uncachedPrimaryKeys) {
807 EntityCacheUtil.putResult(PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
808 PortalPreferencesImpl.class, primaryKey,
809 _nullPortalPreferences);
810 }
811 }
812 catch (Exception e) {
813 throw processException(e);
814 }
815 finally {
816 closeSession(session);
817 }
818
819 return map;
820 }
821
822
827 @Override
828 public List<PortalPreferences> findAll() {
829 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
830 }
831
832
843 @Override
844 public List<PortalPreferences> findAll(int start, int end) {
845 return findAll(start, end, null);
846 }
847
848
860 @Override
861 public List<PortalPreferences> findAll(int start, int end,
862 OrderByComparator<PortalPreferences> orderByComparator) {
863 boolean pagination = true;
864 FinderPath finderPath = null;
865 Object[] finderArgs = null;
866
867 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
868 (orderByComparator == null)) {
869 pagination = false;
870 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
871 finderArgs = FINDER_ARGS_EMPTY;
872 }
873 else {
874 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
875 finderArgs = new Object[] { start, end, orderByComparator };
876 }
877
878 List<PortalPreferences> list = (List<PortalPreferences>)FinderCacheUtil.getResult(finderPath,
879 finderArgs, this);
880
881 if (list == null) {
882 StringBundler query = null;
883 String sql = null;
884
885 if (orderByComparator != null) {
886 query = new StringBundler(2 +
887 (orderByComparator.getOrderByFields().length * 3));
888
889 query.append(_SQL_SELECT_PORTALPREFERENCES);
890
891 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
892 orderByComparator);
893
894 sql = query.toString();
895 }
896 else {
897 sql = _SQL_SELECT_PORTALPREFERENCES;
898
899 if (pagination) {
900 sql = sql.concat(PortalPreferencesModelImpl.ORDER_BY_JPQL);
901 }
902 }
903
904 Session session = null;
905
906 try {
907 session = openSession();
908
909 Query q = session.createQuery(sql);
910
911 if (!pagination) {
912 list = (List<PortalPreferences>)QueryUtil.list(q,
913 getDialect(), start, end, false);
914
915 Collections.sort(list);
916
917 list = Collections.unmodifiableList(list);
918 }
919 else {
920 list = (List<PortalPreferences>)QueryUtil.list(q,
921 getDialect(), start, end);
922 }
923
924 cacheResult(list);
925
926 FinderCacheUtil.putResult(finderPath, finderArgs, list);
927 }
928 catch (Exception e) {
929 FinderCacheUtil.removeResult(finderPath, finderArgs);
930
931 throw processException(e);
932 }
933 finally {
934 closeSession(session);
935 }
936 }
937
938 return list;
939 }
940
941
945 @Override
946 public void removeAll() {
947 for (PortalPreferences portalPreferences : findAll()) {
948 remove(portalPreferences);
949 }
950 }
951
952
957 @Override
958 public int countAll() {
959 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
960 FINDER_ARGS_EMPTY, this);
961
962 if (count == null) {
963 Session session = null;
964
965 try {
966 session = openSession();
967
968 Query q = session.createQuery(_SQL_COUNT_PORTALPREFERENCES);
969
970 count = (Long)q.uniqueResult();
971
972 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
973 FINDER_ARGS_EMPTY, count);
974 }
975 catch (Exception e) {
976 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
977 FINDER_ARGS_EMPTY);
978
979 throw processException(e);
980 }
981 finally {
982 closeSession(session);
983 }
984 }
985
986 return count.intValue();
987 }
988
989
992 public void afterPropertiesSet() {
993 }
994
995 public void destroy() {
996 EntityCacheUtil.removeCache(PortalPreferencesImpl.class.getName());
997 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
998 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
999 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1000 }
1001
1002 private static final String _SQL_SELECT_PORTALPREFERENCES = "SELECT portalPreferences FROM PortalPreferences portalPreferences";
1003 private static final String _SQL_SELECT_PORTALPREFERENCES_WHERE_PKS_IN = "SELECT portalPreferences FROM PortalPreferences portalPreferences WHERE portalPreferencesId IN (";
1004 private static final String _SQL_SELECT_PORTALPREFERENCES_WHERE = "SELECT portalPreferences FROM PortalPreferences portalPreferences WHERE ";
1005 private static final String _SQL_COUNT_PORTALPREFERENCES = "SELECT COUNT(portalPreferences) FROM PortalPreferences portalPreferences";
1006 private static final String _SQL_COUNT_PORTALPREFERENCES_WHERE = "SELECT COUNT(portalPreferences) FROM PortalPreferences portalPreferences WHERE ";
1007 private static final String _ORDER_BY_ENTITY_ALIAS = "portalPreferences.";
1008 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No PortalPreferences exists with the primary key ";
1009 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No PortalPreferences exists with the key {";
1010 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1011 private static final Log _log = LogFactoryUtil.getLog(PortalPreferencesPersistenceImpl.class);
1012 private static final PortalPreferences _nullPortalPreferences = new PortalPreferencesImpl() {
1013 @Override
1014 public Object clone() {
1015 return this;
1016 }
1017
1018 @Override
1019 public CacheModel<PortalPreferences> toCacheModel() {
1020 return _nullPortalPreferencesCacheModel;
1021 }
1022 };
1023
1024 private static final CacheModel<PortalPreferences> _nullPortalPreferencesCacheModel =
1025 new NullCacheModel();
1026
1027 private static class NullCacheModel implements CacheModel<PortalPreferences>,
1028 MVCCModel {
1029 @Override
1030 public long getMvccVersion() {
1031 return -1;
1032 }
1033
1034 @Override
1035 public void setMvccVersion(long mvccVersion) {
1036 }
1037
1038 @Override
1039 public PortalPreferences toEntityModel() {
1040 return _nullPortalPreferences;
1041 }
1042 }
1043 }