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.dao.orm.EntityCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderPath;
023 import com.liferay.portal.kernel.dao.orm.Query;
024 import com.liferay.portal.kernel.dao.orm.QueryPos;
025 import com.liferay.portal.kernel.dao.orm.QueryUtil;
026 import com.liferay.portal.kernel.dao.orm.Session;
027 import com.liferay.portal.kernel.log.Log;
028 import com.liferay.portal.kernel.log.LogFactoryUtil;
029 import com.liferay.portal.kernel.util.OrderByComparator;
030 import com.liferay.portal.kernel.util.StringBundler;
031 import com.liferay.portal.kernel.util.StringPool;
032 import com.liferay.portal.kernel.util.StringUtil;
033 import com.liferay.portal.model.CacheModel;
034 import com.liferay.portal.model.MVCCModel;
035 import com.liferay.portal.model.PortalPreferences;
036 import com.liferay.portal.model.impl.PortalPreferencesImpl;
037 import com.liferay.portal.model.impl.PortalPreferencesModelImpl;
038 import com.liferay.portal.service.persistence.PortalPreferencesPersistence;
039
040 import java.io.Serializable;
041
042 import java.util.Collections;
043 import java.util.HashMap;
044 import java.util.HashSet;
045 import java.util.Iterator;
046 import java.util.List;
047 import java.util.Map;
048 import java.util.Set;
049
050
062 @ProviderType
063 public class PortalPreferencesPersistenceImpl extends BasePersistenceImpl<PortalPreferences>
064 implements PortalPreferencesPersistence {
065
070 public static final String FINDER_CLASS_NAME_ENTITY = PortalPreferencesImpl.class.getName();
071 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
072 ".List1";
073 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
074 ".List2";
075 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
076 PortalPreferencesModelImpl.FINDER_CACHE_ENABLED,
077 PortalPreferencesImpl.class,
078 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
079 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
080 PortalPreferencesModelImpl.FINDER_CACHE_ENABLED,
081 PortalPreferencesImpl.class,
082 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
083 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
084 PortalPreferencesModelImpl.FINDER_CACHE_ENABLED, Long.class,
085 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
086 public static final FinderPath FINDER_PATH_FETCH_BY_O_O = new FinderPath(PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
087 PortalPreferencesModelImpl.FINDER_CACHE_ENABLED,
088 PortalPreferencesImpl.class, FINDER_CLASS_NAME_ENTITY,
089 "fetchByO_O",
090 new String[] { Long.class.getName(), Integer.class.getName() },
091 PortalPreferencesModelImpl.OWNERID_COLUMN_BITMASK |
092 PortalPreferencesModelImpl.OWNERTYPE_COLUMN_BITMASK);
093 public static final FinderPath FINDER_PATH_COUNT_BY_O_O = new FinderPath(PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
094 PortalPreferencesModelImpl.FINDER_CACHE_ENABLED, Long.class,
095 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByO_O",
096 new String[] { Long.class.getName(), Integer.class.getName() });
097
098
106 @Override
107 public PortalPreferences findByO_O(long ownerId, int ownerType)
108 throws NoSuchPreferencesException {
109 PortalPreferences portalPreferences = fetchByO_O(ownerId, ownerType);
110
111 if (portalPreferences == null) {
112 StringBundler msg = new StringBundler(6);
113
114 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
115
116 msg.append("ownerId=");
117 msg.append(ownerId);
118
119 msg.append(", ownerType=");
120 msg.append(ownerType);
121
122 msg.append(StringPool.CLOSE_CURLY_BRACE);
123
124 if (_log.isWarnEnabled()) {
125 _log.warn(msg.toString());
126 }
127
128 throw new NoSuchPreferencesException(msg.toString());
129 }
130
131 return portalPreferences;
132 }
133
134
141 @Override
142 public PortalPreferences fetchByO_O(long ownerId, int ownerType) {
143 return fetchByO_O(ownerId, ownerType, true);
144 }
145
146
154 @Override
155 public PortalPreferences fetchByO_O(long ownerId, int ownerType,
156 boolean retrieveFromCache) {
157 Object[] finderArgs = new Object[] { ownerId, ownerType };
158
159 Object result = null;
160
161 if (retrieveFromCache) {
162 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_O_O,
163 finderArgs, this);
164 }
165
166 if (result instanceof PortalPreferences) {
167 PortalPreferences portalPreferences = (PortalPreferences)result;
168
169 if ((ownerId != portalPreferences.getOwnerId()) ||
170 (ownerType != portalPreferences.getOwnerType())) {
171 result = null;
172 }
173 }
174
175 if (result == null) {
176 StringBundler query = new StringBundler(4);
177
178 query.append(_SQL_SELECT_PORTALPREFERENCES_WHERE);
179
180 query.append(_FINDER_COLUMN_O_O_OWNERID_2);
181
182 query.append(_FINDER_COLUMN_O_O_OWNERTYPE_2);
183
184 String sql = query.toString();
185
186 Session session = null;
187
188 try {
189 session = openSession();
190
191 Query q = session.createQuery(sql);
192
193 QueryPos qPos = QueryPos.getInstance(q);
194
195 qPos.add(ownerId);
196
197 qPos.add(ownerType);
198
199 List<PortalPreferences> list = q.list();
200
201 if (list.isEmpty()) {
202 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_O_O,
203 finderArgs, list);
204 }
205 else {
206 if ((list.size() > 1) && _log.isWarnEnabled()) {
207 _log.warn(
208 "PortalPreferencesPersistenceImpl.fetchByO_O(long, int, boolean) with parameters (" +
209 StringUtil.merge(finderArgs) +
210 ") 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.");
211 }
212
213 PortalPreferences portalPreferences = list.get(0);
214
215 result = portalPreferences;
216
217 cacheResult(portalPreferences);
218
219 if ((portalPreferences.getOwnerId() != ownerId) ||
220 (portalPreferences.getOwnerType() != ownerType)) {
221 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_O_O,
222 finderArgs, portalPreferences);
223 }
224 }
225 }
226 catch (Exception e) {
227 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_O_O,
228 finderArgs);
229
230 throw processException(e);
231 }
232 finally {
233 closeSession(session);
234 }
235 }
236
237 if (result instanceof List<?>) {
238 return null;
239 }
240 else {
241 return (PortalPreferences)result;
242 }
243 }
244
245
252 @Override
253 public PortalPreferences removeByO_O(long ownerId, int ownerType)
254 throws NoSuchPreferencesException {
255 PortalPreferences portalPreferences = findByO_O(ownerId, ownerType);
256
257 return remove(portalPreferences);
258 }
259
260
267 @Override
268 public int countByO_O(long ownerId, int ownerType) {
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 public PortalPreferencesPersistenceImpl() {
321 setModelClass(PortalPreferences.class);
322 }
323
324
329 @Override
330 public void cacheResult(PortalPreferences portalPreferences) {
331 EntityCacheUtil.putResult(PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
332 PortalPreferencesImpl.class, portalPreferences.getPrimaryKey(),
333 portalPreferences);
334
335 FinderCacheUtil.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 (EntityCacheUtil.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 EntityCacheUtil.clearCache(PortalPreferencesImpl.class);
373
374 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
375 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
376 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
377 }
378
379
386 @Override
387 public void clearCache(PortalPreferences portalPreferences) {
388 EntityCacheUtil.removeResult(PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
389 PortalPreferencesImpl.class, portalPreferences.getPrimaryKey());
390
391 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
392 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
393
394 clearUniqueFindersCache(portalPreferences);
395 }
396
397 @Override
398 public void clearCache(List<PortalPreferences> portalPreferenceses) {
399 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
400 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
401
402 for (PortalPreferences portalPreferences : portalPreferenceses) {
403 EntityCacheUtil.removeResult(PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
404 PortalPreferencesImpl.class, portalPreferences.getPrimaryKey());
405
406 clearUniqueFindersCache(portalPreferences);
407 }
408 }
409
410 protected void cacheUniqueFindersCache(PortalPreferences portalPreferences) {
411 if (portalPreferences.isNew()) {
412 Object[] args = new Object[] {
413 portalPreferences.getOwnerId(),
414 portalPreferences.getOwnerType()
415 };
416
417 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_O_O, args,
418 Long.valueOf(1));
419 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_O_O, args,
420 portalPreferences);
421 }
422 else {
423 PortalPreferencesModelImpl portalPreferencesModelImpl = (PortalPreferencesModelImpl)portalPreferences;
424
425 if ((portalPreferencesModelImpl.getColumnBitmask() &
426 FINDER_PATH_FETCH_BY_O_O.getColumnBitmask()) != 0) {
427 Object[] args = new Object[] {
428 portalPreferences.getOwnerId(),
429 portalPreferences.getOwnerType()
430 };
431
432 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_O_O, args,
433 Long.valueOf(1));
434 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_O_O, args,
435 portalPreferences);
436 }
437 }
438 }
439
440 protected void clearUniqueFindersCache(PortalPreferences portalPreferences) {
441 PortalPreferencesModelImpl portalPreferencesModelImpl = (PortalPreferencesModelImpl)portalPreferences;
442
443 Object[] args = new Object[] {
444 portalPreferences.getOwnerId(), portalPreferences.getOwnerType()
445 };
446
447 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_O_O, args);
448 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_O_O, args);
449
450 if ((portalPreferencesModelImpl.getColumnBitmask() &
451 FINDER_PATH_FETCH_BY_O_O.getColumnBitmask()) != 0) {
452 args = new Object[] {
453 portalPreferencesModelImpl.getOriginalOwnerId(),
454 portalPreferencesModelImpl.getOriginalOwnerType()
455 };
456
457 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_O_O, args);
458 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_O_O, args);
459 }
460 }
461
462
468 @Override
469 public PortalPreferences create(long portalPreferencesId) {
470 PortalPreferences portalPreferences = new PortalPreferencesImpl();
471
472 portalPreferences.setNew(true);
473 portalPreferences.setPrimaryKey(portalPreferencesId);
474
475 return portalPreferences;
476 }
477
478
485 @Override
486 public PortalPreferences remove(long portalPreferencesId)
487 throws NoSuchPreferencesException {
488 return remove((Serializable)portalPreferencesId);
489 }
490
491
498 @Override
499 public PortalPreferences remove(Serializable primaryKey)
500 throws NoSuchPreferencesException {
501 Session session = null;
502
503 try {
504 session = openSession();
505
506 PortalPreferences portalPreferences = (PortalPreferences)session.get(PortalPreferencesImpl.class,
507 primaryKey);
508
509 if (portalPreferences == null) {
510 if (_log.isWarnEnabled()) {
511 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
512 }
513
514 throw new NoSuchPreferencesException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
515 primaryKey);
516 }
517
518 return remove(portalPreferences);
519 }
520 catch (NoSuchPreferencesException nsee) {
521 throw nsee;
522 }
523 catch (Exception e) {
524 throw processException(e);
525 }
526 finally {
527 closeSession(session);
528 }
529 }
530
531 @Override
532 protected PortalPreferences removeImpl(PortalPreferences portalPreferences) {
533 portalPreferences = toUnwrappedModel(portalPreferences);
534
535 Session session = null;
536
537 try {
538 session = openSession();
539
540 if (!session.contains(portalPreferences)) {
541 portalPreferences = (PortalPreferences)session.get(PortalPreferencesImpl.class,
542 portalPreferences.getPrimaryKeyObj());
543 }
544
545 if (portalPreferences != null) {
546 session.delete(portalPreferences);
547 }
548 }
549 catch (Exception e) {
550 throw processException(e);
551 }
552 finally {
553 closeSession(session);
554 }
555
556 if (portalPreferences != null) {
557 clearCache(portalPreferences);
558 }
559
560 return portalPreferences;
561 }
562
563 @Override
564 public PortalPreferences updateImpl(PortalPreferences portalPreferences) {
565 portalPreferences = toUnwrappedModel(portalPreferences);
566
567 boolean isNew = portalPreferences.isNew();
568
569 Session session = null;
570
571 try {
572 session = openSession();
573
574 if (portalPreferences.isNew()) {
575 session.save(portalPreferences);
576
577 portalPreferences.setNew(false);
578 }
579 else {
580 session.merge(portalPreferences);
581 }
582 }
583 catch (Exception e) {
584 throw processException(e);
585 }
586 finally {
587 closeSession(session);
588 }
589
590 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
591
592 if (isNew || !PortalPreferencesModelImpl.COLUMN_BITMASK_ENABLED) {
593 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
594 }
595
596 EntityCacheUtil.putResult(PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
597 PortalPreferencesImpl.class, portalPreferences.getPrimaryKey(),
598 portalPreferences, false);
599
600 clearUniqueFindersCache(portalPreferences);
601 cacheUniqueFindersCache(portalPreferences);
602
603 portalPreferences.resetOriginalValues();
604
605 return portalPreferences;
606 }
607
608 protected PortalPreferences toUnwrappedModel(
609 PortalPreferences portalPreferences) {
610 if (portalPreferences instanceof PortalPreferencesImpl) {
611 return portalPreferences;
612 }
613
614 PortalPreferencesImpl portalPreferencesImpl = new PortalPreferencesImpl();
615
616 portalPreferencesImpl.setNew(portalPreferences.isNew());
617 portalPreferencesImpl.setPrimaryKey(portalPreferences.getPrimaryKey());
618
619 portalPreferencesImpl.setMvccVersion(portalPreferences.getMvccVersion());
620 portalPreferencesImpl.setPortalPreferencesId(portalPreferences.getPortalPreferencesId());
621 portalPreferencesImpl.setOwnerId(portalPreferences.getOwnerId());
622 portalPreferencesImpl.setOwnerType(portalPreferences.getOwnerType());
623 portalPreferencesImpl.setPreferences(portalPreferences.getPreferences());
624
625 return portalPreferencesImpl;
626 }
627
628
635 @Override
636 public PortalPreferences findByPrimaryKey(Serializable primaryKey)
637 throws NoSuchPreferencesException {
638 PortalPreferences portalPreferences = fetchByPrimaryKey(primaryKey);
639
640 if (portalPreferences == null) {
641 if (_log.isWarnEnabled()) {
642 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
643 }
644
645 throw new NoSuchPreferencesException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
646 primaryKey);
647 }
648
649 return portalPreferences;
650 }
651
652
659 @Override
660 public PortalPreferences findByPrimaryKey(long portalPreferencesId)
661 throws NoSuchPreferencesException {
662 return findByPrimaryKey((Serializable)portalPreferencesId);
663 }
664
665
671 @Override
672 public PortalPreferences fetchByPrimaryKey(Serializable primaryKey) {
673 PortalPreferences portalPreferences = (PortalPreferences)EntityCacheUtil.getResult(PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
674 PortalPreferencesImpl.class, primaryKey);
675
676 if (portalPreferences == _nullPortalPreferences) {
677 return null;
678 }
679
680 if (portalPreferences == null) {
681 Session session = null;
682
683 try {
684 session = openSession();
685
686 portalPreferences = (PortalPreferences)session.get(PortalPreferencesImpl.class,
687 primaryKey);
688
689 if (portalPreferences != null) {
690 cacheResult(portalPreferences);
691 }
692 else {
693 EntityCacheUtil.putResult(PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
694 PortalPreferencesImpl.class, primaryKey,
695 _nullPortalPreferences);
696 }
697 }
698 catch (Exception e) {
699 EntityCacheUtil.removeResult(PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
700 PortalPreferencesImpl.class, primaryKey);
701
702 throw processException(e);
703 }
704 finally {
705 closeSession(session);
706 }
707 }
708
709 return portalPreferences;
710 }
711
712
718 @Override
719 public PortalPreferences fetchByPrimaryKey(long portalPreferencesId) {
720 return fetchByPrimaryKey((Serializable)portalPreferencesId);
721 }
722
723 @Override
724 public Map<Serializable, PortalPreferences> fetchByPrimaryKeys(
725 Set<Serializable> primaryKeys) {
726 if (primaryKeys.isEmpty()) {
727 return Collections.emptyMap();
728 }
729
730 Map<Serializable, PortalPreferences> map = new HashMap<Serializable, PortalPreferences>();
731
732 if (primaryKeys.size() == 1) {
733 Iterator<Serializable> iterator = primaryKeys.iterator();
734
735 Serializable primaryKey = iterator.next();
736
737 PortalPreferences portalPreferences = fetchByPrimaryKey(primaryKey);
738
739 if (portalPreferences != null) {
740 map.put(primaryKey, portalPreferences);
741 }
742
743 return map;
744 }
745
746 Set<Serializable> uncachedPrimaryKeys = null;
747
748 for (Serializable primaryKey : primaryKeys) {
749 PortalPreferences portalPreferences = (PortalPreferences)EntityCacheUtil.getResult(PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
750 PortalPreferencesImpl.class, primaryKey);
751
752 if (portalPreferences == null) {
753 if (uncachedPrimaryKeys == null) {
754 uncachedPrimaryKeys = new HashSet<Serializable>();
755 }
756
757 uncachedPrimaryKeys.add(primaryKey);
758 }
759 else {
760 map.put(primaryKey, portalPreferences);
761 }
762 }
763
764 if (uncachedPrimaryKeys == null) {
765 return map;
766 }
767
768 StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
769 1);
770
771 query.append(_SQL_SELECT_PORTALPREFERENCES_WHERE_PKS_IN);
772
773 for (Serializable primaryKey : uncachedPrimaryKeys) {
774 query.append(String.valueOf(primaryKey));
775
776 query.append(StringPool.COMMA);
777 }
778
779 query.setIndex(query.index() - 1);
780
781 query.append(StringPool.CLOSE_PARENTHESIS);
782
783 String sql = query.toString();
784
785 Session session = null;
786
787 try {
788 session = openSession();
789
790 Query q = session.createQuery(sql);
791
792 for (PortalPreferences portalPreferences : (List<PortalPreferences>)q.list()) {
793 map.put(portalPreferences.getPrimaryKeyObj(), portalPreferences);
794
795 cacheResult(portalPreferences);
796
797 uncachedPrimaryKeys.remove(portalPreferences.getPrimaryKeyObj());
798 }
799
800 for (Serializable primaryKey : uncachedPrimaryKeys) {
801 EntityCacheUtil.putResult(PortalPreferencesModelImpl.ENTITY_CACHE_ENABLED,
802 PortalPreferencesImpl.class, primaryKey,
803 _nullPortalPreferences);
804 }
805 }
806 catch (Exception e) {
807 throw processException(e);
808 }
809 finally {
810 closeSession(session);
811 }
812
813 return map;
814 }
815
816
821 @Override
822 public List<PortalPreferences> findAll() {
823 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
824 }
825
826
837 @Override
838 public List<PortalPreferences> findAll(int start, int end) {
839 return findAll(start, end, null);
840 }
841
842
854 @Override
855 public List<PortalPreferences> findAll(int start, int end,
856 OrderByComparator<PortalPreferences> orderByComparator) {
857 boolean pagination = true;
858 FinderPath finderPath = null;
859 Object[] finderArgs = null;
860
861 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
862 (orderByComparator == null)) {
863 pagination = false;
864 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
865 finderArgs = FINDER_ARGS_EMPTY;
866 }
867 else {
868 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
869 finderArgs = new Object[] { start, end, orderByComparator };
870 }
871
872 List<PortalPreferences> list = (List<PortalPreferences>)FinderCacheUtil.getResult(finderPath,
873 finderArgs, this);
874
875 if (list == null) {
876 StringBundler query = null;
877 String sql = null;
878
879 if (orderByComparator != null) {
880 query = new StringBundler(2 +
881 (orderByComparator.getOrderByFields().length * 3));
882
883 query.append(_SQL_SELECT_PORTALPREFERENCES);
884
885 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
886 orderByComparator);
887
888 sql = query.toString();
889 }
890 else {
891 sql = _SQL_SELECT_PORTALPREFERENCES;
892
893 if (pagination) {
894 sql = sql.concat(PortalPreferencesModelImpl.ORDER_BY_JPQL);
895 }
896 }
897
898 Session session = null;
899
900 try {
901 session = openSession();
902
903 Query q = session.createQuery(sql);
904
905 if (!pagination) {
906 list = (List<PortalPreferences>)QueryUtil.list(q,
907 getDialect(), start, end, false);
908
909 Collections.sort(list);
910
911 list = Collections.unmodifiableList(list);
912 }
913 else {
914 list = (List<PortalPreferences>)QueryUtil.list(q,
915 getDialect(), start, end);
916 }
917
918 cacheResult(list);
919
920 FinderCacheUtil.putResult(finderPath, finderArgs, list);
921 }
922 catch (Exception e) {
923 FinderCacheUtil.removeResult(finderPath, finderArgs);
924
925 throw processException(e);
926 }
927 finally {
928 closeSession(session);
929 }
930 }
931
932 return list;
933 }
934
935
939 @Override
940 public void removeAll() {
941 for (PortalPreferences portalPreferences : findAll()) {
942 remove(portalPreferences);
943 }
944 }
945
946
951 @Override
952 public int countAll() {
953 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
954 FINDER_ARGS_EMPTY, this);
955
956 if (count == null) {
957 Session session = null;
958
959 try {
960 session = openSession();
961
962 Query q = session.createQuery(_SQL_COUNT_PORTALPREFERENCES);
963
964 count = (Long)q.uniqueResult();
965
966 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
967 FINDER_ARGS_EMPTY, count);
968 }
969 catch (Exception e) {
970 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
971 FINDER_ARGS_EMPTY);
972
973 throw processException(e);
974 }
975 finally {
976 closeSession(session);
977 }
978 }
979
980 return count.intValue();
981 }
982
983
986 public void afterPropertiesSet() {
987 }
988
989 public void destroy() {
990 EntityCacheUtil.removeCache(PortalPreferencesImpl.class.getName());
991 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
992 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
993 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
994 }
995
996 private static final String _SQL_SELECT_PORTALPREFERENCES = "SELECT portalPreferences FROM PortalPreferences portalPreferences";
997 private static final String _SQL_SELECT_PORTALPREFERENCES_WHERE_PKS_IN = "SELECT portalPreferences FROM PortalPreferences portalPreferences WHERE portalPreferencesId IN (";
998 private static final String _SQL_SELECT_PORTALPREFERENCES_WHERE = "SELECT portalPreferences FROM PortalPreferences portalPreferences WHERE ";
999 private static final String _SQL_COUNT_PORTALPREFERENCES = "SELECT COUNT(portalPreferences) FROM PortalPreferences portalPreferences";
1000 private static final String _SQL_COUNT_PORTALPREFERENCES_WHERE = "SELECT COUNT(portalPreferences) FROM PortalPreferences portalPreferences WHERE ";
1001 private static final String _ORDER_BY_ENTITY_ALIAS = "portalPreferences.";
1002 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No PortalPreferences exists with the primary key ";
1003 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No PortalPreferences exists with the key {";
1004 private static final Log _log = LogFactoryUtil.getLog(PortalPreferencesPersistenceImpl.class);
1005 private static final PortalPreferences _nullPortalPreferences = new PortalPreferencesImpl() {
1006 @Override
1007 public Object clone() {
1008 return this;
1009 }
1010
1011 @Override
1012 public CacheModel<PortalPreferences> toCacheModel() {
1013 return _nullPortalPreferencesCacheModel;
1014 }
1015 };
1016
1017 private static final CacheModel<PortalPreferences> _nullPortalPreferencesCacheModel =
1018 new NullCacheModel();
1019
1020 private static class NullCacheModel implements CacheModel<PortalPreferences>,
1021 MVCCModel {
1022 @Override
1023 public long getMvccVersion() {
1024 return -1;
1025 }
1026
1027 @Override
1028 public void setMvccVersion(long mvccVersion) {
1029 }
1030
1031 @Override
1032 public PortalPreferences toEntityModel() {
1033 return _nullPortalPreferences;
1034 }
1035 }
1036 }