001
014
015 package com.liferay.portal.service.persistence.impl;
016
017 import aQute.bnd.annotation.ProviderType;
018
019 import com.liferay.portal.exception.NoSuchPreferencesException;
020 import com.liferay.portal.kernel.dao.orm.EntityCache;
021 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderCache;
023 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
024 import com.liferay.portal.kernel.dao.orm.FinderPath;
025 import com.liferay.portal.kernel.dao.orm.Query;
026 import com.liferay.portal.kernel.dao.orm.QueryPos;
027 import com.liferay.portal.kernel.dao.orm.QueryUtil;
028 import com.liferay.portal.kernel.dao.orm.Session;
029 import com.liferay.portal.kernel.log.Log;
030 import com.liferay.portal.kernel.log.LogFactoryUtil;
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.model.CacheModel;
036 import com.liferay.portal.model.MVCCModel;
037 import com.liferay.portal.model.PortalPreferences;
038 import com.liferay.portal.model.impl.PortalPreferencesImpl;
039 import com.liferay.portal.model.impl.PortalPreferencesModelImpl;
040 import com.liferay.portal.service.persistence.PortalPreferencesPersistence;
041
042 import java.io.Serializable;
043
044 import java.util.Collections;
045 import java.util.HashMap;
046 import java.util.HashSet;
047 import java.util.Iterator;
048 import java.util.List;
049 import java.util.Map;
050 import java.util.Set;
051
052
064 @ProviderType
065 public class PortalPreferencesPersistenceImpl extends BasePersistenceImpl<PortalPreferences>
066 implements PortalPreferencesPersistence {
067
072 public static final String FINDER_CLASS_NAME_ENTITY = PortalPreferencesImpl.class.getName();
073 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
074 ".List1";
075 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
076 ".List2";
077 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
078 PortalPreferencesModelImpl.FINDER_CACHE_ENABLED,
079 PortalPreferencesImpl.class,
080 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
081 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
082 PortalPreferencesModelImpl.FINDER_CACHE_ENABLED,
083 PortalPreferencesImpl.class,
084 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
085 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
086 PortalPreferencesModelImpl.FINDER_CACHE_ENABLED, Long.class,
087 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
088 public static final FinderPath FINDER_PATH_FETCH_BY_O_O = new FinderPath(PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
089 PortalPreferencesModelImpl.FINDER_CACHE_ENABLED,
090 PortalPreferencesImpl.class, FINDER_CLASS_NAME_ENTITY,
091 "fetchByO_O",
092 new String[] { Long.class.getName(), Integer.class.getName() },
093 PortalPreferencesModelImpl.OWNERID_COLUMN_BITMASK |
094 PortalPreferencesModelImpl.OWNERTYPE_COLUMN_BITMASK);
095 public static final FinderPath FINDER_PATH_COUNT_BY_O_O = new FinderPath(PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
096 PortalPreferencesModelImpl.FINDER_CACHE_ENABLED, Long.class,
097 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByO_O",
098 new String[] { Long.class.getName(), Integer.class.getName() });
099
100
108 @Override
109 public PortalPreferences findByO_O(long ownerId, int ownerType)
110 throws NoSuchPreferencesException {
111 PortalPreferences portalPreferences = fetchByO_O(ownerId, ownerType);
112
113 if (portalPreferences == null) {
114 StringBundler msg = new StringBundler(6);
115
116 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
117
118 msg.append("ownerId=");
119 msg.append(ownerId);
120
121 msg.append(", ownerType=");
122 msg.append(ownerType);
123
124 msg.append(StringPool.CLOSE_CURLY_BRACE);
125
126 if (_log.isWarnEnabled()) {
127 _log.warn(msg.toString());
128 }
129
130 throw new NoSuchPreferencesException(msg.toString());
131 }
132
133 return portalPreferences;
134 }
135
136
143 @Override
144 public PortalPreferences fetchByO_O(long ownerId, int ownerType) {
145 return fetchByO_O(ownerId, ownerType, true);
146 }
147
148
156 @Override
157 public PortalPreferences fetchByO_O(long ownerId, int ownerType,
158 boolean retrieveFromCache) {
159 Object[] finderArgs = new Object[] { ownerId, ownerType };
160
161 Object result = null;
162
163 if (retrieveFromCache) {
164 result = finderCache.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 finderCache.putResult(FINDER_PATH_FETCH_BY_O_O, finderArgs,
205 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 finderCache.putResult(FINDER_PATH_FETCH_BY_O_O,
224 finderArgs, portalPreferences);
225 }
226 }
227 }
228 catch (Exception e) {
229 finderCache.removeResult(FINDER_PATH_FETCH_BY_O_O, 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)finderCache.getResult(finderPath, finderArgs, 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 finderCache.putResult(finderPath, finderArgs, count);
303 }
304 catch (Exception e) {
305 finderCache.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 public PortalPreferencesPersistenceImpl() {
321 setModelClass(PortalPreferences.class);
322 }
323
324
329 @Override
330 public void cacheResult(PortalPreferences portalPreferences) {
331 entityCache.putResult(PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
332 PortalPreferencesImpl.class, portalPreferences.getPrimaryKey(),
333 portalPreferences);
334
335 finderCache.putResult(FINDER_PATH_FETCH_BY_O_O,
336 new Object[] {
337 portalPreferences.getOwnerId(), portalPreferences.getOwnerType()
338 }, portalPreferences);
339
340 portalPreferences.resetOriginalValues();
341 }
342
343
348 @Override
349 public void cacheResult(List<PortalPreferences> portalPreferenceses) {
350 for (PortalPreferences portalPreferences : portalPreferenceses) {
351 if (entityCache.getResult(
352 PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
353 PortalPreferencesImpl.class,
354 portalPreferences.getPrimaryKey()) == null) {
355 cacheResult(portalPreferences);
356 }
357 else {
358 portalPreferences.resetOriginalValues();
359 }
360 }
361 }
362
363
370 @Override
371 public void clearCache() {
372 entityCache.clearCache(PortalPreferencesImpl.class);
373
374 finderCache.clearCache(FINDER_CLASS_NAME_ENTITY);
375 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
376 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
377 }
378
379
386 @Override
387 public void clearCache(PortalPreferences portalPreferences) {
388 entityCache.removeResult(PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
389 PortalPreferencesImpl.class, portalPreferences.getPrimaryKey());
390
391 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
392 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
393
394 clearUniqueFindersCache((PortalPreferencesModelImpl)portalPreferences);
395 }
396
397 @Override
398 public void clearCache(List<PortalPreferences> portalPreferenceses) {
399 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
400 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
401
402 for (PortalPreferences portalPreferences : portalPreferenceses) {
403 entityCache.removeResult(PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
404 PortalPreferencesImpl.class, portalPreferences.getPrimaryKey());
405
406 clearUniqueFindersCache((PortalPreferencesModelImpl)portalPreferences);
407 }
408 }
409
410 protected void cacheUniqueFindersCache(
411 PortalPreferencesModelImpl portalPreferencesModelImpl, boolean isNew) {
412 if (isNew) {
413 Object[] args = new Object[] {
414 portalPreferencesModelImpl.getOwnerId(),
415 portalPreferencesModelImpl.getOwnerType()
416 };
417
418 finderCache.putResult(FINDER_PATH_COUNT_BY_O_O, args,
419 Long.valueOf(1));
420 finderCache.putResult(FINDER_PATH_FETCH_BY_O_O, args,
421 portalPreferencesModelImpl);
422 }
423 else {
424 if ((portalPreferencesModelImpl.getColumnBitmask() &
425 FINDER_PATH_FETCH_BY_O_O.getColumnBitmask()) != 0) {
426 Object[] args = new Object[] {
427 portalPreferencesModelImpl.getOwnerId(),
428 portalPreferencesModelImpl.getOwnerType()
429 };
430
431 finderCache.putResult(FINDER_PATH_COUNT_BY_O_O, args,
432 Long.valueOf(1));
433 finderCache.putResult(FINDER_PATH_FETCH_BY_O_O, args,
434 portalPreferencesModelImpl);
435 }
436 }
437 }
438
439 protected void clearUniqueFindersCache(
440 PortalPreferencesModelImpl portalPreferencesModelImpl) {
441 Object[] args = new Object[] {
442 portalPreferencesModelImpl.getOwnerId(),
443 portalPreferencesModelImpl.getOwnerType()
444 };
445
446 finderCache.removeResult(FINDER_PATH_COUNT_BY_O_O, args);
447 finderCache.removeResult(FINDER_PATH_FETCH_BY_O_O, args);
448
449 if ((portalPreferencesModelImpl.getColumnBitmask() &
450 FINDER_PATH_FETCH_BY_O_O.getColumnBitmask()) != 0) {
451 args = new Object[] {
452 portalPreferencesModelImpl.getOriginalOwnerId(),
453 portalPreferencesModelImpl.getOriginalOwnerType()
454 };
455
456 finderCache.removeResult(FINDER_PATH_COUNT_BY_O_O, args);
457 finderCache.removeResult(FINDER_PATH_FETCH_BY_O_O, args);
458 }
459 }
460
461
467 @Override
468 public PortalPreferences create(long portalPreferencesId) {
469 PortalPreferences portalPreferences = new PortalPreferencesImpl();
470
471 portalPreferences.setNew(true);
472 portalPreferences.setPrimaryKey(portalPreferencesId);
473
474 return portalPreferences;
475 }
476
477
484 @Override
485 public PortalPreferences remove(long portalPreferencesId)
486 throws NoSuchPreferencesException {
487 return remove((Serializable)portalPreferencesId);
488 }
489
490
497 @Override
498 public PortalPreferences remove(Serializable primaryKey)
499 throws NoSuchPreferencesException {
500 Session session = null;
501
502 try {
503 session = openSession();
504
505 PortalPreferences portalPreferences = (PortalPreferences)session.get(PortalPreferencesImpl.class,
506 primaryKey);
507
508 if (portalPreferences == null) {
509 if (_log.isWarnEnabled()) {
510 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
511 }
512
513 throw new NoSuchPreferencesException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
514 primaryKey);
515 }
516
517 return remove(portalPreferences);
518 }
519 catch (NoSuchPreferencesException nsee) {
520 throw nsee;
521 }
522 catch (Exception e) {
523 throw processException(e);
524 }
525 finally {
526 closeSession(session);
527 }
528 }
529
530 @Override
531 protected PortalPreferences removeImpl(PortalPreferences portalPreferences) {
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(PortalPreferences portalPreferences) {
564 portalPreferences = toUnwrappedModel(portalPreferences);
565
566 boolean isNew = portalPreferences.isNew();
567
568 PortalPreferencesModelImpl portalPreferencesModelImpl = (PortalPreferencesModelImpl)portalPreferences;
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 portalPreferences = (PortalPreferences)session.merge(portalPreferences);
582 }
583 }
584 catch (Exception e) {
585 throw processException(e);
586 }
587 finally {
588 closeSession(session);
589 }
590
591 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
592
593 if (isNew || !PortalPreferencesModelImpl.COLUMN_BITMASK_ENABLED) {
594 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
595 }
596
597 entityCache.putResult(PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
598 PortalPreferencesImpl.class, portalPreferences.getPrimaryKey(),
599 portalPreferences, false);
600
601 clearUniqueFindersCache(portalPreferencesModelImpl);
602 cacheUniqueFindersCache(portalPreferencesModelImpl, isNew);
603
604 portalPreferences.resetOriginalValues();
605
606 return portalPreferences;
607 }
608
609 protected PortalPreferences toUnwrappedModel(
610 PortalPreferences portalPreferences) {
611 if (portalPreferences instanceof PortalPreferencesImpl) {
612 return portalPreferences;
613 }
614
615 PortalPreferencesImpl portalPreferencesImpl = new PortalPreferencesImpl();
616
617 portalPreferencesImpl.setNew(portalPreferences.isNew());
618 portalPreferencesImpl.setPrimaryKey(portalPreferences.getPrimaryKey());
619
620 portalPreferencesImpl.setMvccVersion(portalPreferences.getMvccVersion());
621 portalPreferencesImpl.setPortalPreferencesId(portalPreferences.getPortalPreferencesId());
622 portalPreferencesImpl.setOwnerId(portalPreferences.getOwnerId());
623 portalPreferencesImpl.setOwnerType(portalPreferences.getOwnerType());
624 portalPreferencesImpl.setPreferences(portalPreferences.getPreferences());
625
626 return portalPreferencesImpl;
627 }
628
629
636 @Override
637 public PortalPreferences findByPrimaryKey(Serializable primaryKey)
638 throws NoSuchPreferencesException {
639 PortalPreferences portalPreferences = fetchByPrimaryKey(primaryKey);
640
641 if (portalPreferences == null) {
642 if (_log.isWarnEnabled()) {
643 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
644 }
645
646 throw new NoSuchPreferencesException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
647 primaryKey);
648 }
649
650 return portalPreferences;
651 }
652
653
660 @Override
661 public PortalPreferences findByPrimaryKey(long portalPreferencesId)
662 throws NoSuchPreferencesException {
663 return findByPrimaryKey((Serializable)portalPreferencesId);
664 }
665
666
672 @Override
673 public PortalPreferences fetchByPrimaryKey(Serializable primaryKey) {
674 PortalPreferences portalPreferences = (PortalPreferences)entityCache.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 entityCache.putResult(PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
695 PortalPreferencesImpl.class, primaryKey,
696 _nullPortalPreferences);
697 }
698 }
699 catch (Exception e) {
700 entityCache.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
719 @Override
720 public PortalPreferences fetchByPrimaryKey(long portalPreferencesId) {
721 return fetchByPrimaryKey((Serializable)portalPreferencesId);
722 }
723
724 @Override
725 public Map<Serializable, PortalPreferences> fetchByPrimaryKeys(
726 Set<Serializable> primaryKeys) {
727 if (primaryKeys.isEmpty()) {
728 return Collections.emptyMap();
729 }
730
731 Map<Serializable, PortalPreferences> map = new HashMap<Serializable, PortalPreferences>();
732
733 if (primaryKeys.size() == 1) {
734 Iterator<Serializable> iterator = primaryKeys.iterator();
735
736 Serializable primaryKey = iterator.next();
737
738 PortalPreferences portalPreferences = fetchByPrimaryKey(primaryKey);
739
740 if (portalPreferences != null) {
741 map.put(primaryKey, portalPreferences);
742 }
743
744 return map;
745 }
746
747 Set<Serializable> uncachedPrimaryKeys = null;
748
749 for (Serializable primaryKey : primaryKeys) {
750 PortalPreferences portalPreferences = (PortalPreferences)entityCache.getResult(PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
751 PortalPreferencesImpl.class, primaryKey);
752
753 if (portalPreferences == null) {
754 if (uncachedPrimaryKeys == null) {
755 uncachedPrimaryKeys = new HashSet<Serializable>();
756 }
757
758 uncachedPrimaryKeys.add(primaryKey);
759 }
760 else {
761 map.put(primaryKey, portalPreferences);
762 }
763 }
764
765 if (uncachedPrimaryKeys == null) {
766 return map;
767 }
768
769 StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
770 1);
771
772 query.append(_SQL_SELECT_PORTALPREFERENCES_WHERE_PKS_IN);
773
774 for (Serializable primaryKey : uncachedPrimaryKeys) {
775 query.append(String.valueOf(primaryKey));
776
777 query.append(StringPool.COMMA);
778 }
779
780 query.setIndex(query.index() - 1);
781
782 query.append(StringPool.CLOSE_PARENTHESIS);
783
784 String sql = query.toString();
785
786 Session session = null;
787
788 try {
789 session = openSession();
790
791 Query q = session.createQuery(sql);
792
793 for (PortalPreferences portalPreferences : (List<PortalPreferences>)q.list()) {
794 map.put(portalPreferences.getPrimaryKeyObj(), portalPreferences);
795
796 cacheResult(portalPreferences);
797
798 uncachedPrimaryKeys.remove(portalPreferences.getPrimaryKeyObj());
799 }
800
801 for (Serializable primaryKey : uncachedPrimaryKeys) {
802 entityCache.putResult(PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
803 PortalPreferencesImpl.class, primaryKey,
804 _nullPortalPreferences);
805 }
806 }
807 catch (Exception e) {
808 throw processException(e);
809 }
810 finally {
811 closeSession(session);
812 }
813
814 return map;
815 }
816
817
822 @Override
823 public List<PortalPreferences> findAll() {
824 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
825 }
826
827
838 @Override
839 public List<PortalPreferences> findAll(int start, int end) {
840 return findAll(start, end, null);
841 }
842
843
855 @Override
856 public List<PortalPreferences> findAll(int start, int end,
857 OrderByComparator<PortalPreferences> orderByComparator) {
858 return findAll(start, end, orderByComparator, true);
859 }
860
861
874 @Override
875 public List<PortalPreferences> findAll(int start, int end,
876 OrderByComparator<PortalPreferences> orderByComparator,
877 boolean retrieveFromCache) {
878 boolean pagination = true;
879 FinderPath finderPath = null;
880 Object[] finderArgs = null;
881
882 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
883 (orderByComparator == null)) {
884 pagination = false;
885 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
886 finderArgs = FINDER_ARGS_EMPTY;
887 }
888 else {
889 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
890 finderArgs = new Object[] { start, end, orderByComparator };
891 }
892
893 List<PortalPreferences> list = null;
894
895 if (retrieveFromCache) {
896 list = (List<PortalPreferences>)finderCache.getResult(finderPath,
897 finderArgs, this);
898 }
899
900 if (list == null) {
901 StringBundler query = null;
902 String sql = null;
903
904 if (orderByComparator != null) {
905 query = new StringBundler(2 +
906 (orderByComparator.getOrderByFields().length * 3));
907
908 query.append(_SQL_SELECT_PORTALPREFERENCES);
909
910 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
911 orderByComparator);
912
913 sql = query.toString();
914 }
915 else {
916 sql = _SQL_SELECT_PORTALPREFERENCES;
917
918 if (pagination) {
919 sql = sql.concat(PortalPreferencesModelImpl.ORDER_BY_JPQL);
920 }
921 }
922
923 Session session = null;
924
925 try {
926 session = openSession();
927
928 Query q = session.createQuery(sql);
929
930 if (!pagination) {
931 list = (List<PortalPreferences>)QueryUtil.list(q,
932 getDialect(), start, end, false);
933
934 Collections.sort(list);
935
936 list = Collections.unmodifiableList(list);
937 }
938 else {
939 list = (List<PortalPreferences>)QueryUtil.list(q,
940 getDialect(), start, end);
941 }
942
943 cacheResult(list);
944
945 finderCache.putResult(finderPath, finderArgs, list);
946 }
947 catch (Exception e) {
948 finderCache.removeResult(finderPath, finderArgs);
949
950 throw processException(e);
951 }
952 finally {
953 closeSession(session);
954 }
955 }
956
957 return list;
958 }
959
960
964 @Override
965 public void removeAll() {
966 for (PortalPreferences portalPreferences : findAll()) {
967 remove(portalPreferences);
968 }
969 }
970
971
976 @Override
977 public int countAll() {
978 Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL,
979 FINDER_ARGS_EMPTY, this);
980
981 if (count == null) {
982 Session session = null;
983
984 try {
985 session = openSession();
986
987 Query q = session.createQuery(_SQL_COUNT_PORTALPREFERENCES);
988
989 count = (Long)q.uniqueResult();
990
991 finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY,
992 count);
993 }
994 catch (Exception e) {
995 finderCache.removeResult(FINDER_PATH_COUNT_ALL,
996 FINDER_ARGS_EMPTY);
997
998 throw processException(e);
999 }
1000 finally {
1001 closeSession(session);
1002 }
1003 }
1004
1005 return count.intValue();
1006 }
1007
1008 @Override
1009 protected Map<String, Integer> getTableColumnsMap() {
1010 return PortalPreferencesModelImpl.TABLE_COLUMNS_MAP;
1011 }
1012
1013
1016 public void afterPropertiesSet() {
1017 }
1018
1019 public void destroy() {
1020 entityCache.removeCache(PortalPreferencesImpl.class.getName());
1021 finderCache.removeCache(FINDER_CLASS_NAME_ENTITY);
1022 finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1023 finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1024 }
1025
1026 protected EntityCache entityCache = EntityCacheUtil.getEntityCache();
1027 protected FinderCache finderCache = FinderCacheUtil.getFinderCache();
1028 private static final String _SQL_SELECT_PORTALPREFERENCES = "SELECT portalPreferences FROM PortalPreferences portalPreferences";
1029 private static final String _SQL_SELECT_PORTALPREFERENCES_WHERE_PKS_IN = "SELECT portalPreferences FROM PortalPreferences portalPreferences WHERE portalPreferencesId IN (";
1030 private static final String _SQL_SELECT_PORTALPREFERENCES_WHERE = "SELECT portalPreferences FROM PortalPreferences portalPreferences WHERE ";
1031 private static final String _SQL_COUNT_PORTALPREFERENCES = "SELECT COUNT(portalPreferences) FROM PortalPreferences portalPreferences";
1032 private static final String _SQL_COUNT_PORTALPREFERENCES_WHERE = "SELECT COUNT(portalPreferences) FROM PortalPreferences portalPreferences WHERE ";
1033 private static final String _ORDER_BY_ENTITY_ALIAS = "portalPreferences.";
1034 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No PortalPreferences exists with the primary key ";
1035 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No PortalPreferences exists with the key {";
1036 private static final Log _log = LogFactoryUtil.getLog(PortalPreferencesPersistenceImpl.class);
1037 private static final PortalPreferences _nullPortalPreferences = new PortalPreferencesImpl() {
1038 @Override
1039 public Object clone() {
1040 return this;
1041 }
1042
1043 @Override
1044 public CacheModel<PortalPreferences> toCacheModel() {
1045 return _nullPortalPreferencesCacheModel;
1046 }
1047 };
1048
1049 private static final CacheModel<PortalPreferences> _nullPortalPreferencesCacheModel =
1050 new NullCacheModel();
1051
1052 private static class NullCacheModel implements CacheModel<PortalPreferences>,
1053 MVCCModel {
1054 @Override
1055 public long getMvccVersion() {
1056 return -1;
1057 }
1058
1059 @Override
1060 public void setMvccVersion(long mvccVersion) {
1061 }
1062
1063 @Override
1064 public PortalPreferences toEntityModel() {
1065 return _nullPortalPreferences;
1066 }
1067 }
1068 }