001
014
015 package com.liferay.portal.service.persistence.impl;
016
017 import aQute.bnd.annotation.ProviderType;
018
019 import com.liferay.portal.NoSuchUserIdMapperException;
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.SetUtil;
033 import com.liferay.portal.kernel.util.StringBundler;
034 import com.liferay.portal.kernel.util.StringPool;
035 import com.liferay.portal.kernel.util.Validator;
036 import com.liferay.portal.model.CacheModel;
037 import com.liferay.portal.model.MVCCModel;
038 import com.liferay.portal.model.UserIdMapper;
039 import com.liferay.portal.model.impl.UserIdMapperImpl;
040 import com.liferay.portal.model.impl.UserIdMapperModelImpl;
041 import com.liferay.portal.service.persistence.UserIdMapperPersistence;
042
043 import java.io.Serializable;
044
045 import java.util.Collections;
046 import java.util.HashMap;
047 import java.util.HashSet;
048 import java.util.Iterator;
049 import java.util.List;
050 import java.util.Map;
051 import java.util.Set;
052
053
065 @ProviderType
066 public class UserIdMapperPersistenceImpl extends BasePersistenceImpl<UserIdMapper>
067 implements UserIdMapperPersistence {
068
073 public static final String FINDER_CLASS_NAME_ENTITY = UserIdMapperImpl.class.getName();
074 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
075 ".List1";
076 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
077 ".List2";
078 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
079 UserIdMapperModelImpl.FINDER_CACHE_ENABLED, UserIdMapperImpl.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(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
082 UserIdMapperModelImpl.FINDER_CACHE_ENABLED, UserIdMapperImpl.class,
083 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
084 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
085 UserIdMapperModelImpl.FINDER_CACHE_ENABLED, Long.class,
086 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
087 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID = new FinderPath(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
088 UserIdMapperModelImpl.FINDER_CACHE_ENABLED, UserIdMapperImpl.class,
089 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUserId",
090 new String[] {
091 Long.class.getName(),
092
093 Integer.class.getName(), Integer.class.getName(),
094 OrderByComparator.class.getName()
095 });
096 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID =
097 new FinderPath(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
098 UserIdMapperModelImpl.FINDER_CACHE_ENABLED, UserIdMapperImpl.class,
099 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserId",
100 new String[] { Long.class.getName() },
101 UserIdMapperModelImpl.USERID_COLUMN_BITMASK);
102 public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
103 UserIdMapperModelImpl.FINDER_CACHE_ENABLED, Long.class,
104 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId",
105 new String[] { Long.class.getName() });
106
107
113 @Override
114 public List<UserIdMapper> findByUserId(long userId) {
115 return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
116 }
117
118
130 @Override
131 public List<UserIdMapper> findByUserId(long userId, int start, int end) {
132 return findByUserId(userId, start, end, null);
133 }
134
135
148 @Override
149 public List<UserIdMapper> findByUserId(long userId, int start, int end,
150 OrderByComparator<UserIdMapper> orderByComparator) {
151 return findByUserId(userId, start, end, orderByComparator, true);
152 }
153
154
168 @Override
169 public List<UserIdMapper> findByUserId(long userId, int start, int end,
170 OrderByComparator<UserIdMapper> orderByComparator,
171 boolean retrieveFromCache) {
172 boolean pagination = true;
173 FinderPath finderPath = null;
174 Object[] finderArgs = null;
175
176 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
177 (orderByComparator == null)) {
178 pagination = false;
179 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID;
180 finderArgs = new Object[] { userId };
181 }
182 else {
183 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID;
184 finderArgs = new Object[] { userId, start, end, orderByComparator };
185 }
186
187 List<UserIdMapper> list = null;
188
189 if (retrieveFromCache) {
190 list = (List<UserIdMapper>)finderCache.getResult(finderPath,
191 finderArgs, this);
192
193 if ((list != null) && !list.isEmpty()) {
194 for (UserIdMapper userIdMapper : list) {
195 if ((userId != userIdMapper.getUserId())) {
196 list = null;
197
198 break;
199 }
200 }
201 }
202 }
203
204 if (list == null) {
205 StringBundler query = null;
206
207 if (orderByComparator != null) {
208 query = new StringBundler(3 +
209 (orderByComparator.getOrderByFields().length * 3));
210 }
211 else {
212 query = new StringBundler(3);
213 }
214
215 query.append(_SQL_SELECT_USERIDMAPPER_WHERE);
216
217 query.append(_FINDER_COLUMN_USERID_USERID_2);
218
219 if (orderByComparator != null) {
220 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
221 orderByComparator);
222 }
223 else
224 if (pagination) {
225 query.append(UserIdMapperModelImpl.ORDER_BY_JPQL);
226 }
227
228 String sql = query.toString();
229
230 Session session = null;
231
232 try {
233 session = openSession();
234
235 Query q = session.createQuery(sql);
236
237 QueryPos qPos = QueryPos.getInstance(q);
238
239 qPos.add(userId);
240
241 if (!pagination) {
242 list = (List<UserIdMapper>)QueryUtil.list(q, getDialect(),
243 start, end, false);
244
245 Collections.sort(list);
246
247 list = Collections.unmodifiableList(list);
248 }
249 else {
250 list = (List<UserIdMapper>)QueryUtil.list(q, getDialect(),
251 start, end);
252 }
253
254 cacheResult(list);
255
256 finderCache.putResult(finderPath, finderArgs, list);
257 }
258 catch (Exception e) {
259 finderCache.removeResult(finderPath, finderArgs);
260
261 throw processException(e);
262 }
263 finally {
264 closeSession(session);
265 }
266 }
267
268 return list;
269 }
270
271
279 @Override
280 public UserIdMapper findByUserId_First(long userId,
281 OrderByComparator<UserIdMapper> orderByComparator)
282 throws NoSuchUserIdMapperException {
283 UserIdMapper userIdMapper = fetchByUserId_First(userId,
284 orderByComparator);
285
286 if (userIdMapper != null) {
287 return userIdMapper;
288 }
289
290 StringBundler msg = new StringBundler(4);
291
292 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
293
294 msg.append("userId=");
295 msg.append(userId);
296
297 msg.append(StringPool.CLOSE_CURLY_BRACE);
298
299 throw new NoSuchUserIdMapperException(msg.toString());
300 }
301
302
309 @Override
310 public UserIdMapper fetchByUserId_First(long userId,
311 OrderByComparator<UserIdMapper> orderByComparator) {
312 List<UserIdMapper> list = findByUserId(userId, 0, 1, orderByComparator);
313
314 if (!list.isEmpty()) {
315 return list.get(0);
316 }
317
318 return null;
319 }
320
321
329 @Override
330 public UserIdMapper findByUserId_Last(long userId,
331 OrderByComparator<UserIdMapper> orderByComparator)
332 throws NoSuchUserIdMapperException {
333 UserIdMapper userIdMapper = fetchByUserId_Last(userId, orderByComparator);
334
335 if (userIdMapper != null) {
336 return userIdMapper;
337 }
338
339 StringBundler msg = new StringBundler(4);
340
341 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
342
343 msg.append("userId=");
344 msg.append(userId);
345
346 msg.append(StringPool.CLOSE_CURLY_BRACE);
347
348 throw new NoSuchUserIdMapperException(msg.toString());
349 }
350
351
358 @Override
359 public UserIdMapper fetchByUserId_Last(long userId,
360 OrderByComparator<UserIdMapper> orderByComparator) {
361 int count = countByUserId(userId);
362
363 if (count == 0) {
364 return null;
365 }
366
367 List<UserIdMapper> list = findByUserId(userId, count - 1, count,
368 orderByComparator);
369
370 if (!list.isEmpty()) {
371 return list.get(0);
372 }
373
374 return null;
375 }
376
377
386 @Override
387 public UserIdMapper[] findByUserId_PrevAndNext(long userIdMapperId,
388 long userId, OrderByComparator<UserIdMapper> orderByComparator)
389 throws NoSuchUserIdMapperException {
390 UserIdMapper userIdMapper = findByPrimaryKey(userIdMapperId);
391
392 Session session = null;
393
394 try {
395 session = openSession();
396
397 UserIdMapper[] array = new UserIdMapperImpl[3];
398
399 array[0] = getByUserId_PrevAndNext(session, userIdMapper, userId,
400 orderByComparator, true);
401
402 array[1] = userIdMapper;
403
404 array[2] = getByUserId_PrevAndNext(session, userIdMapper, userId,
405 orderByComparator, false);
406
407 return array;
408 }
409 catch (Exception e) {
410 throw processException(e);
411 }
412 finally {
413 closeSession(session);
414 }
415 }
416
417 protected UserIdMapper getByUserId_PrevAndNext(Session session,
418 UserIdMapper userIdMapper, long userId,
419 OrderByComparator<UserIdMapper> orderByComparator, boolean previous) {
420 StringBundler query = null;
421
422 if (orderByComparator != null) {
423 query = new StringBundler(6 +
424 (orderByComparator.getOrderByFields().length * 6));
425 }
426 else {
427 query = new StringBundler(3);
428 }
429
430 query.append(_SQL_SELECT_USERIDMAPPER_WHERE);
431
432 query.append(_FINDER_COLUMN_USERID_USERID_2);
433
434 if (orderByComparator != null) {
435 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
436
437 if (orderByConditionFields.length > 0) {
438 query.append(WHERE_AND);
439 }
440
441 for (int i = 0; i < orderByConditionFields.length; i++) {
442 query.append(_ORDER_BY_ENTITY_ALIAS);
443 query.append(orderByConditionFields[i]);
444
445 if ((i + 1) < orderByConditionFields.length) {
446 if (orderByComparator.isAscending() ^ previous) {
447 query.append(WHERE_GREATER_THAN_HAS_NEXT);
448 }
449 else {
450 query.append(WHERE_LESSER_THAN_HAS_NEXT);
451 }
452 }
453 else {
454 if (orderByComparator.isAscending() ^ previous) {
455 query.append(WHERE_GREATER_THAN);
456 }
457 else {
458 query.append(WHERE_LESSER_THAN);
459 }
460 }
461 }
462
463 query.append(ORDER_BY_CLAUSE);
464
465 String[] orderByFields = orderByComparator.getOrderByFields();
466
467 for (int i = 0; i < orderByFields.length; i++) {
468 query.append(_ORDER_BY_ENTITY_ALIAS);
469 query.append(orderByFields[i]);
470
471 if ((i + 1) < orderByFields.length) {
472 if (orderByComparator.isAscending() ^ previous) {
473 query.append(ORDER_BY_ASC_HAS_NEXT);
474 }
475 else {
476 query.append(ORDER_BY_DESC_HAS_NEXT);
477 }
478 }
479 else {
480 if (orderByComparator.isAscending() ^ previous) {
481 query.append(ORDER_BY_ASC);
482 }
483 else {
484 query.append(ORDER_BY_DESC);
485 }
486 }
487 }
488 }
489 else {
490 query.append(UserIdMapperModelImpl.ORDER_BY_JPQL);
491 }
492
493 String sql = query.toString();
494
495 Query q = session.createQuery(sql);
496
497 q.setFirstResult(0);
498 q.setMaxResults(2);
499
500 QueryPos qPos = QueryPos.getInstance(q);
501
502 qPos.add(userId);
503
504 if (orderByComparator != null) {
505 Object[] values = orderByComparator.getOrderByConditionValues(userIdMapper);
506
507 for (Object value : values) {
508 qPos.add(value);
509 }
510 }
511
512 List<UserIdMapper> list = q.list();
513
514 if (list.size() == 2) {
515 return list.get(1);
516 }
517 else {
518 return null;
519 }
520 }
521
522
527 @Override
528 public void removeByUserId(long userId) {
529 for (UserIdMapper userIdMapper : findByUserId(userId,
530 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
531 remove(userIdMapper);
532 }
533 }
534
535
541 @Override
542 public int countByUserId(long userId) {
543 FinderPath finderPath = FINDER_PATH_COUNT_BY_USERID;
544
545 Object[] finderArgs = new Object[] { userId };
546
547 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
548
549 if (count == null) {
550 StringBundler query = new StringBundler(2);
551
552 query.append(_SQL_COUNT_USERIDMAPPER_WHERE);
553
554 query.append(_FINDER_COLUMN_USERID_USERID_2);
555
556 String sql = query.toString();
557
558 Session session = null;
559
560 try {
561 session = openSession();
562
563 Query q = session.createQuery(sql);
564
565 QueryPos qPos = QueryPos.getInstance(q);
566
567 qPos.add(userId);
568
569 count = (Long)q.uniqueResult();
570
571 finderCache.putResult(finderPath, finderArgs, count);
572 }
573 catch (Exception e) {
574 finderCache.removeResult(finderPath, finderArgs);
575
576 throw processException(e);
577 }
578 finally {
579 closeSession(session);
580 }
581 }
582
583 return count.intValue();
584 }
585
586 private static final String _FINDER_COLUMN_USERID_USERID_2 = "userIdMapper.userId = ?";
587 public static final FinderPath FINDER_PATH_FETCH_BY_U_T = new FinderPath(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
588 UserIdMapperModelImpl.FINDER_CACHE_ENABLED, UserIdMapperImpl.class,
589 FINDER_CLASS_NAME_ENTITY, "fetchByU_T",
590 new String[] { Long.class.getName(), String.class.getName() },
591 UserIdMapperModelImpl.USERID_COLUMN_BITMASK |
592 UserIdMapperModelImpl.TYPE_COLUMN_BITMASK);
593 public static final FinderPath FINDER_PATH_COUNT_BY_U_T = new FinderPath(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
594 UserIdMapperModelImpl.FINDER_CACHE_ENABLED, Long.class,
595 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_T",
596 new String[] { Long.class.getName(), String.class.getName() });
597
598
606 @Override
607 public UserIdMapper findByU_T(long userId, String type)
608 throws NoSuchUserIdMapperException {
609 UserIdMapper userIdMapper = fetchByU_T(userId, type);
610
611 if (userIdMapper == null) {
612 StringBundler msg = new StringBundler(6);
613
614 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
615
616 msg.append("userId=");
617 msg.append(userId);
618
619 msg.append(", type=");
620 msg.append(type);
621
622 msg.append(StringPool.CLOSE_CURLY_BRACE);
623
624 if (_log.isWarnEnabled()) {
625 _log.warn(msg.toString());
626 }
627
628 throw new NoSuchUserIdMapperException(msg.toString());
629 }
630
631 return userIdMapper;
632 }
633
634
641 @Override
642 public UserIdMapper fetchByU_T(long userId, String type) {
643 return fetchByU_T(userId, type, true);
644 }
645
646
654 @Override
655 public UserIdMapper fetchByU_T(long userId, String type,
656 boolean retrieveFromCache) {
657 Object[] finderArgs = new Object[] { userId, type };
658
659 Object result = null;
660
661 if (retrieveFromCache) {
662 result = finderCache.getResult(FINDER_PATH_FETCH_BY_U_T,
663 finderArgs, this);
664 }
665
666 if (result instanceof UserIdMapper) {
667 UserIdMapper userIdMapper = (UserIdMapper)result;
668
669 if ((userId != userIdMapper.getUserId()) ||
670 !Validator.equals(type, userIdMapper.getType())) {
671 result = null;
672 }
673 }
674
675 if (result == null) {
676 StringBundler query = new StringBundler(4);
677
678 query.append(_SQL_SELECT_USERIDMAPPER_WHERE);
679
680 query.append(_FINDER_COLUMN_U_T_USERID_2);
681
682 boolean bindType = false;
683
684 if (type == null) {
685 query.append(_FINDER_COLUMN_U_T_TYPE_1);
686 }
687 else if (type.equals(StringPool.BLANK)) {
688 query.append(_FINDER_COLUMN_U_T_TYPE_3);
689 }
690 else {
691 bindType = true;
692
693 query.append(_FINDER_COLUMN_U_T_TYPE_2);
694 }
695
696 String sql = query.toString();
697
698 Session session = null;
699
700 try {
701 session = openSession();
702
703 Query q = session.createQuery(sql);
704
705 QueryPos qPos = QueryPos.getInstance(q);
706
707 qPos.add(userId);
708
709 if (bindType) {
710 qPos.add(type);
711 }
712
713 List<UserIdMapper> list = q.list();
714
715 if (list.isEmpty()) {
716 finderCache.putResult(FINDER_PATH_FETCH_BY_U_T, finderArgs,
717 list);
718 }
719 else {
720 UserIdMapper userIdMapper = list.get(0);
721
722 result = userIdMapper;
723
724 cacheResult(userIdMapper);
725
726 if ((userIdMapper.getUserId() != userId) ||
727 (userIdMapper.getType() == null) ||
728 !userIdMapper.getType().equals(type)) {
729 finderCache.putResult(FINDER_PATH_FETCH_BY_U_T,
730 finderArgs, userIdMapper);
731 }
732 }
733 }
734 catch (Exception e) {
735 finderCache.removeResult(FINDER_PATH_FETCH_BY_U_T, finderArgs);
736
737 throw processException(e);
738 }
739 finally {
740 closeSession(session);
741 }
742 }
743
744 if (result instanceof List<?>) {
745 return null;
746 }
747 else {
748 return (UserIdMapper)result;
749 }
750 }
751
752
759 @Override
760 public UserIdMapper removeByU_T(long userId, String type)
761 throws NoSuchUserIdMapperException {
762 UserIdMapper userIdMapper = findByU_T(userId, type);
763
764 return remove(userIdMapper);
765 }
766
767
774 @Override
775 public int countByU_T(long userId, String type) {
776 FinderPath finderPath = FINDER_PATH_COUNT_BY_U_T;
777
778 Object[] finderArgs = new Object[] { userId, type };
779
780 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
781
782 if (count == null) {
783 StringBundler query = new StringBundler(3);
784
785 query.append(_SQL_COUNT_USERIDMAPPER_WHERE);
786
787 query.append(_FINDER_COLUMN_U_T_USERID_2);
788
789 boolean bindType = false;
790
791 if (type == null) {
792 query.append(_FINDER_COLUMN_U_T_TYPE_1);
793 }
794 else if (type.equals(StringPool.BLANK)) {
795 query.append(_FINDER_COLUMN_U_T_TYPE_3);
796 }
797 else {
798 bindType = true;
799
800 query.append(_FINDER_COLUMN_U_T_TYPE_2);
801 }
802
803 String sql = query.toString();
804
805 Session session = null;
806
807 try {
808 session = openSession();
809
810 Query q = session.createQuery(sql);
811
812 QueryPos qPos = QueryPos.getInstance(q);
813
814 qPos.add(userId);
815
816 if (bindType) {
817 qPos.add(type);
818 }
819
820 count = (Long)q.uniqueResult();
821
822 finderCache.putResult(finderPath, finderArgs, count);
823 }
824 catch (Exception e) {
825 finderCache.removeResult(finderPath, finderArgs);
826
827 throw processException(e);
828 }
829 finally {
830 closeSession(session);
831 }
832 }
833
834 return count.intValue();
835 }
836
837 private static final String _FINDER_COLUMN_U_T_USERID_2 = "userIdMapper.userId = ? AND ";
838 private static final String _FINDER_COLUMN_U_T_TYPE_1 = "userIdMapper.type IS NULL";
839 private static final String _FINDER_COLUMN_U_T_TYPE_2 = "userIdMapper.type = ?";
840 private static final String _FINDER_COLUMN_U_T_TYPE_3 = "(userIdMapper.type IS NULL OR userIdMapper.type = '')";
841 public static final FinderPath FINDER_PATH_FETCH_BY_T_E = new FinderPath(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
842 UserIdMapperModelImpl.FINDER_CACHE_ENABLED, UserIdMapperImpl.class,
843 FINDER_CLASS_NAME_ENTITY, "fetchByT_E",
844 new String[] { String.class.getName(), String.class.getName() },
845 UserIdMapperModelImpl.TYPE_COLUMN_BITMASK |
846 UserIdMapperModelImpl.EXTERNALUSERID_COLUMN_BITMASK);
847 public static final FinderPath FINDER_PATH_COUNT_BY_T_E = new FinderPath(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
848 UserIdMapperModelImpl.FINDER_CACHE_ENABLED, Long.class,
849 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_E",
850 new String[] { String.class.getName(), String.class.getName() });
851
852
860 @Override
861 public UserIdMapper findByT_E(String type, String externalUserId)
862 throws NoSuchUserIdMapperException {
863 UserIdMapper userIdMapper = fetchByT_E(type, externalUserId);
864
865 if (userIdMapper == null) {
866 StringBundler msg = new StringBundler(6);
867
868 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
869
870 msg.append("type=");
871 msg.append(type);
872
873 msg.append(", externalUserId=");
874 msg.append(externalUserId);
875
876 msg.append(StringPool.CLOSE_CURLY_BRACE);
877
878 if (_log.isWarnEnabled()) {
879 _log.warn(msg.toString());
880 }
881
882 throw new NoSuchUserIdMapperException(msg.toString());
883 }
884
885 return userIdMapper;
886 }
887
888
895 @Override
896 public UserIdMapper fetchByT_E(String type, String externalUserId) {
897 return fetchByT_E(type, externalUserId, true);
898 }
899
900
908 @Override
909 public UserIdMapper fetchByT_E(String type, String externalUserId,
910 boolean retrieveFromCache) {
911 Object[] finderArgs = new Object[] { type, externalUserId };
912
913 Object result = null;
914
915 if (retrieveFromCache) {
916 result = finderCache.getResult(FINDER_PATH_FETCH_BY_T_E,
917 finderArgs, this);
918 }
919
920 if (result instanceof UserIdMapper) {
921 UserIdMapper userIdMapper = (UserIdMapper)result;
922
923 if (!Validator.equals(type, userIdMapper.getType()) ||
924 !Validator.equals(externalUserId,
925 userIdMapper.getExternalUserId())) {
926 result = null;
927 }
928 }
929
930 if (result == null) {
931 StringBundler query = new StringBundler(4);
932
933 query.append(_SQL_SELECT_USERIDMAPPER_WHERE);
934
935 boolean bindType = false;
936
937 if (type == null) {
938 query.append(_FINDER_COLUMN_T_E_TYPE_1);
939 }
940 else if (type.equals(StringPool.BLANK)) {
941 query.append(_FINDER_COLUMN_T_E_TYPE_3);
942 }
943 else {
944 bindType = true;
945
946 query.append(_FINDER_COLUMN_T_E_TYPE_2);
947 }
948
949 boolean bindExternalUserId = false;
950
951 if (externalUserId == null) {
952 query.append(_FINDER_COLUMN_T_E_EXTERNALUSERID_1);
953 }
954 else if (externalUserId.equals(StringPool.BLANK)) {
955 query.append(_FINDER_COLUMN_T_E_EXTERNALUSERID_3);
956 }
957 else {
958 bindExternalUserId = true;
959
960 query.append(_FINDER_COLUMN_T_E_EXTERNALUSERID_2);
961 }
962
963 String sql = query.toString();
964
965 Session session = null;
966
967 try {
968 session = openSession();
969
970 Query q = session.createQuery(sql);
971
972 QueryPos qPos = QueryPos.getInstance(q);
973
974 if (bindType) {
975 qPos.add(type);
976 }
977
978 if (bindExternalUserId) {
979 qPos.add(externalUserId);
980 }
981
982 List<UserIdMapper> list = q.list();
983
984 if (list.isEmpty()) {
985 finderCache.putResult(FINDER_PATH_FETCH_BY_T_E, finderArgs,
986 list);
987 }
988 else {
989 UserIdMapper userIdMapper = list.get(0);
990
991 result = userIdMapper;
992
993 cacheResult(userIdMapper);
994
995 if ((userIdMapper.getType() == null) ||
996 !userIdMapper.getType().equals(type) ||
997 (userIdMapper.getExternalUserId() == null) ||
998 !userIdMapper.getExternalUserId()
999 .equals(externalUserId)) {
1000 finderCache.putResult(FINDER_PATH_FETCH_BY_T_E,
1001 finderArgs, userIdMapper);
1002 }
1003 }
1004 }
1005 catch (Exception e) {
1006 finderCache.removeResult(FINDER_PATH_FETCH_BY_T_E, finderArgs);
1007
1008 throw processException(e);
1009 }
1010 finally {
1011 closeSession(session);
1012 }
1013 }
1014
1015 if (result instanceof List<?>) {
1016 return null;
1017 }
1018 else {
1019 return (UserIdMapper)result;
1020 }
1021 }
1022
1023
1030 @Override
1031 public UserIdMapper removeByT_E(String type, String externalUserId)
1032 throws NoSuchUserIdMapperException {
1033 UserIdMapper userIdMapper = findByT_E(type, externalUserId);
1034
1035 return remove(userIdMapper);
1036 }
1037
1038
1045 @Override
1046 public int countByT_E(String type, String externalUserId) {
1047 FinderPath finderPath = FINDER_PATH_COUNT_BY_T_E;
1048
1049 Object[] finderArgs = new Object[] { type, externalUserId };
1050
1051 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1052
1053 if (count == null) {
1054 StringBundler query = new StringBundler(3);
1055
1056 query.append(_SQL_COUNT_USERIDMAPPER_WHERE);
1057
1058 boolean bindType = false;
1059
1060 if (type == null) {
1061 query.append(_FINDER_COLUMN_T_E_TYPE_1);
1062 }
1063 else if (type.equals(StringPool.BLANK)) {
1064 query.append(_FINDER_COLUMN_T_E_TYPE_3);
1065 }
1066 else {
1067 bindType = true;
1068
1069 query.append(_FINDER_COLUMN_T_E_TYPE_2);
1070 }
1071
1072 boolean bindExternalUserId = false;
1073
1074 if (externalUserId == null) {
1075 query.append(_FINDER_COLUMN_T_E_EXTERNALUSERID_1);
1076 }
1077 else if (externalUserId.equals(StringPool.BLANK)) {
1078 query.append(_FINDER_COLUMN_T_E_EXTERNALUSERID_3);
1079 }
1080 else {
1081 bindExternalUserId = true;
1082
1083 query.append(_FINDER_COLUMN_T_E_EXTERNALUSERID_2);
1084 }
1085
1086 String sql = query.toString();
1087
1088 Session session = null;
1089
1090 try {
1091 session = openSession();
1092
1093 Query q = session.createQuery(sql);
1094
1095 QueryPos qPos = QueryPos.getInstance(q);
1096
1097 if (bindType) {
1098 qPos.add(type);
1099 }
1100
1101 if (bindExternalUserId) {
1102 qPos.add(externalUserId);
1103 }
1104
1105 count = (Long)q.uniqueResult();
1106
1107 finderCache.putResult(finderPath, finderArgs, count);
1108 }
1109 catch (Exception e) {
1110 finderCache.removeResult(finderPath, finderArgs);
1111
1112 throw processException(e);
1113 }
1114 finally {
1115 closeSession(session);
1116 }
1117 }
1118
1119 return count.intValue();
1120 }
1121
1122 private static final String _FINDER_COLUMN_T_E_TYPE_1 = "userIdMapper.type IS NULL AND ";
1123 private static final String _FINDER_COLUMN_T_E_TYPE_2 = "userIdMapper.type = ? AND ";
1124 private static final String _FINDER_COLUMN_T_E_TYPE_3 = "(userIdMapper.type IS NULL OR userIdMapper.type = '') AND ";
1125 private static final String _FINDER_COLUMN_T_E_EXTERNALUSERID_1 = "userIdMapper.externalUserId IS NULL";
1126 private static final String _FINDER_COLUMN_T_E_EXTERNALUSERID_2 = "userIdMapper.externalUserId = ?";
1127 private static final String _FINDER_COLUMN_T_E_EXTERNALUSERID_3 = "(userIdMapper.externalUserId IS NULL OR userIdMapper.externalUserId = '')";
1128
1129 public UserIdMapperPersistenceImpl() {
1130 setModelClass(UserIdMapper.class);
1131 }
1132
1133
1138 @Override
1139 public void cacheResult(UserIdMapper userIdMapper) {
1140 entityCache.putResult(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
1141 UserIdMapperImpl.class, userIdMapper.getPrimaryKey(), userIdMapper);
1142
1143 finderCache.putResult(FINDER_PATH_FETCH_BY_U_T,
1144 new Object[] { userIdMapper.getUserId(), userIdMapper.getType() },
1145 userIdMapper);
1146
1147 finderCache.putResult(FINDER_PATH_FETCH_BY_T_E,
1148 new Object[] {
1149 userIdMapper.getType(), userIdMapper.getExternalUserId()
1150 }, userIdMapper);
1151
1152 userIdMapper.resetOriginalValues();
1153 }
1154
1155
1160 @Override
1161 public void cacheResult(List<UserIdMapper> userIdMappers) {
1162 for (UserIdMapper userIdMapper : userIdMappers) {
1163 if (entityCache.getResult(
1164 UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
1165 UserIdMapperImpl.class, userIdMapper.getPrimaryKey()) == null) {
1166 cacheResult(userIdMapper);
1167 }
1168 else {
1169 userIdMapper.resetOriginalValues();
1170 }
1171 }
1172 }
1173
1174
1181 @Override
1182 public void clearCache() {
1183 entityCache.clearCache(UserIdMapperImpl.class);
1184
1185 finderCache.clearCache(FINDER_CLASS_NAME_ENTITY);
1186 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1187 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1188 }
1189
1190
1197 @Override
1198 public void clearCache(UserIdMapper userIdMapper) {
1199 entityCache.removeResult(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
1200 UserIdMapperImpl.class, userIdMapper.getPrimaryKey());
1201
1202 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1203 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1204
1205 clearUniqueFindersCache((UserIdMapperModelImpl)userIdMapper);
1206 }
1207
1208 @Override
1209 public void clearCache(List<UserIdMapper> userIdMappers) {
1210 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1211 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1212
1213 for (UserIdMapper userIdMapper : userIdMappers) {
1214 entityCache.removeResult(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
1215 UserIdMapperImpl.class, userIdMapper.getPrimaryKey());
1216
1217 clearUniqueFindersCache((UserIdMapperModelImpl)userIdMapper);
1218 }
1219 }
1220
1221 protected void cacheUniqueFindersCache(
1222 UserIdMapperModelImpl userIdMapperModelImpl, boolean isNew) {
1223 if (isNew) {
1224 Object[] args = new Object[] {
1225 userIdMapperModelImpl.getUserId(),
1226 userIdMapperModelImpl.getType()
1227 };
1228
1229 finderCache.putResult(FINDER_PATH_COUNT_BY_U_T, args,
1230 Long.valueOf(1));
1231 finderCache.putResult(FINDER_PATH_FETCH_BY_U_T, args,
1232 userIdMapperModelImpl);
1233
1234 args = new Object[] {
1235 userIdMapperModelImpl.getType(),
1236 userIdMapperModelImpl.getExternalUserId()
1237 };
1238
1239 finderCache.putResult(FINDER_PATH_COUNT_BY_T_E, args,
1240 Long.valueOf(1));
1241 finderCache.putResult(FINDER_PATH_FETCH_BY_T_E, args,
1242 userIdMapperModelImpl);
1243 }
1244 else {
1245 if ((userIdMapperModelImpl.getColumnBitmask() &
1246 FINDER_PATH_FETCH_BY_U_T.getColumnBitmask()) != 0) {
1247 Object[] args = new Object[] {
1248 userIdMapperModelImpl.getUserId(),
1249 userIdMapperModelImpl.getType()
1250 };
1251
1252 finderCache.putResult(FINDER_PATH_COUNT_BY_U_T, args,
1253 Long.valueOf(1));
1254 finderCache.putResult(FINDER_PATH_FETCH_BY_U_T, args,
1255 userIdMapperModelImpl);
1256 }
1257
1258 if ((userIdMapperModelImpl.getColumnBitmask() &
1259 FINDER_PATH_FETCH_BY_T_E.getColumnBitmask()) != 0) {
1260 Object[] args = new Object[] {
1261 userIdMapperModelImpl.getType(),
1262 userIdMapperModelImpl.getExternalUserId()
1263 };
1264
1265 finderCache.putResult(FINDER_PATH_COUNT_BY_T_E, args,
1266 Long.valueOf(1));
1267 finderCache.putResult(FINDER_PATH_FETCH_BY_T_E, args,
1268 userIdMapperModelImpl);
1269 }
1270 }
1271 }
1272
1273 protected void clearUniqueFindersCache(
1274 UserIdMapperModelImpl userIdMapperModelImpl) {
1275 Object[] args = new Object[] {
1276 userIdMapperModelImpl.getUserId(),
1277 userIdMapperModelImpl.getType()
1278 };
1279
1280 finderCache.removeResult(FINDER_PATH_COUNT_BY_U_T, args);
1281 finderCache.removeResult(FINDER_PATH_FETCH_BY_U_T, args);
1282
1283 if ((userIdMapperModelImpl.getColumnBitmask() &
1284 FINDER_PATH_FETCH_BY_U_T.getColumnBitmask()) != 0) {
1285 args = new Object[] {
1286 userIdMapperModelImpl.getOriginalUserId(),
1287 userIdMapperModelImpl.getOriginalType()
1288 };
1289
1290 finderCache.removeResult(FINDER_PATH_COUNT_BY_U_T, args);
1291 finderCache.removeResult(FINDER_PATH_FETCH_BY_U_T, args);
1292 }
1293
1294 args = new Object[] {
1295 userIdMapperModelImpl.getType(),
1296 userIdMapperModelImpl.getExternalUserId()
1297 };
1298
1299 finderCache.removeResult(FINDER_PATH_COUNT_BY_T_E, args);
1300 finderCache.removeResult(FINDER_PATH_FETCH_BY_T_E, args);
1301
1302 if ((userIdMapperModelImpl.getColumnBitmask() &
1303 FINDER_PATH_FETCH_BY_T_E.getColumnBitmask()) != 0) {
1304 args = new Object[] {
1305 userIdMapperModelImpl.getOriginalType(),
1306 userIdMapperModelImpl.getOriginalExternalUserId()
1307 };
1308
1309 finderCache.removeResult(FINDER_PATH_COUNT_BY_T_E, args);
1310 finderCache.removeResult(FINDER_PATH_FETCH_BY_T_E, args);
1311 }
1312 }
1313
1314
1320 @Override
1321 public UserIdMapper create(long userIdMapperId) {
1322 UserIdMapper userIdMapper = new UserIdMapperImpl();
1323
1324 userIdMapper.setNew(true);
1325 userIdMapper.setPrimaryKey(userIdMapperId);
1326
1327 return userIdMapper;
1328 }
1329
1330
1337 @Override
1338 public UserIdMapper remove(long userIdMapperId)
1339 throws NoSuchUserIdMapperException {
1340 return remove((Serializable)userIdMapperId);
1341 }
1342
1343
1350 @Override
1351 public UserIdMapper remove(Serializable primaryKey)
1352 throws NoSuchUserIdMapperException {
1353 Session session = null;
1354
1355 try {
1356 session = openSession();
1357
1358 UserIdMapper userIdMapper = (UserIdMapper)session.get(UserIdMapperImpl.class,
1359 primaryKey);
1360
1361 if (userIdMapper == null) {
1362 if (_log.isWarnEnabled()) {
1363 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1364 }
1365
1366 throw new NoSuchUserIdMapperException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1367 primaryKey);
1368 }
1369
1370 return remove(userIdMapper);
1371 }
1372 catch (NoSuchUserIdMapperException nsee) {
1373 throw nsee;
1374 }
1375 catch (Exception e) {
1376 throw processException(e);
1377 }
1378 finally {
1379 closeSession(session);
1380 }
1381 }
1382
1383 @Override
1384 protected UserIdMapper removeImpl(UserIdMapper userIdMapper) {
1385 userIdMapper = toUnwrappedModel(userIdMapper);
1386
1387 Session session = null;
1388
1389 try {
1390 session = openSession();
1391
1392 if (!session.contains(userIdMapper)) {
1393 userIdMapper = (UserIdMapper)session.get(UserIdMapperImpl.class,
1394 userIdMapper.getPrimaryKeyObj());
1395 }
1396
1397 if (userIdMapper != null) {
1398 session.delete(userIdMapper);
1399 }
1400 }
1401 catch (Exception e) {
1402 throw processException(e);
1403 }
1404 finally {
1405 closeSession(session);
1406 }
1407
1408 if (userIdMapper != null) {
1409 clearCache(userIdMapper);
1410 }
1411
1412 return userIdMapper;
1413 }
1414
1415 @Override
1416 public UserIdMapper updateImpl(UserIdMapper userIdMapper) {
1417 userIdMapper = toUnwrappedModel(userIdMapper);
1418
1419 boolean isNew = userIdMapper.isNew();
1420
1421 UserIdMapperModelImpl userIdMapperModelImpl = (UserIdMapperModelImpl)userIdMapper;
1422
1423 Session session = null;
1424
1425 try {
1426 session = openSession();
1427
1428 if (userIdMapper.isNew()) {
1429 session.save(userIdMapper);
1430
1431 userIdMapper.setNew(false);
1432 }
1433 else {
1434 userIdMapper = (UserIdMapper)session.merge(userIdMapper);
1435 }
1436 }
1437 catch (Exception e) {
1438 throw processException(e);
1439 }
1440 finally {
1441 closeSession(session);
1442 }
1443
1444 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1445
1446 if (isNew || !UserIdMapperModelImpl.COLUMN_BITMASK_ENABLED) {
1447 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1448 }
1449
1450 else {
1451 if ((userIdMapperModelImpl.getColumnBitmask() &
1452 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
1453 Object[] args = new Object[] {
1454 userIdMapperModelImpl.getOriginalUserId()
1455 };
1456
1457 finderCache.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
1458 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
1459 args);
1460
1461 args = new Object[] { userIdMapperModelImpl.getUserId() };
1462
1463 finderCache.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
1464 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
1465 args);
1466 }
1467 }
1468
1469 entityCache.putResult(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
1470 UserIdMapperImpl.class, userIdMapper.getPrimaryKey(), userIdMapper,
1471 false);
1472
1473 clearUniqueFindersCache(userIdMapperModelImpl);
1474 cacheUniqueFindersCache(userIdMapperModelImpl, isNew);
1475
1476 userIdMapper.resetOriginalValues();
1477
1478 return userIdMapper;
1479 }
1480
1481 protected UserIdMapper toUnwrappedModel(UserIdMapper userIdMapper) {
1482 if (userIdMapper instanceof UserIdMapperImpl) {
1483 return userIdMapper;
1484 }
1485
1486 UserIdMapperImpl userIdMapperImpl = new UserIdMapperImpl();
1487
1488 userIdMapperImpl.setNew(userIdMapper.isNew());
1489 userIdMapperImpl.setPrimaryKey(userIdMapper.getPrimaryKey());
1490
1491 userIdMapperImpl.setMvccVersion(userIdMapper.getMvccVersion());
1492 userIdMapperImpl.setUserIdMapperId(userIdMapper.getUserIdMapperId());
1493 userIdMapperImpl.setCompanyId(userIdMapper.getCompanyId());
1494 userIdMapperImpl.setUserId(userIdMapper.getUserId());
1495 userIdMapperImpl.setType(userIdMapper.getType());
1496 userIdMapperImpl.setDescription(userIdMapper.getDescription());
1497 userIdMapperImpl.setExternalUserId(userIdMapper.getExternalUserId());
1498
1499 return userIdMapperImpl;
1500 }
1501
1502
1509 @Override
1510 public UserIdMapper findByPrimaryKey(Serializable primaryKey)
1511 throws NoSuchUserIdMapperException {
1512 UserIdMapper userIdMapper = fetchByPrimaryKey(primaryKey);
1513
1514 if (userIdMapper == null) {
1515 if (_log.isWarnEnabled()) {
1516 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1517 }
1518
1519 throw new NoSuchUserIdMapperException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1520 primaryKey);
1521 }
1522
1523 return userIdMapper;
1524 }
1525
1526
1533 @Override
1534 public UserIdMapper findByPrimaryKey(long userIdMapperId)
1535 throws NoSuchUserIdMapperException {
1536 return findByPrimaryKey((Serializable)userIdMapperId);
1537 }
1538
1539
1545 @Override
1546 public UserIdMapper fetchByPrimaryKey(Serializable primaryKey) {
1547 UserIdMapper userIdMapper = (UserIdMapper)entityCache.getResult(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
1548 UserIdMapperImpl.class, primaryKey);
1549
1550 if (userIdMapper == _nullUserIdMapper) {
1551 return null;
1552 }
1553
1554 if (userIdMapper == null) {
1555 Session session = null;
1556
1557 try {
1558 session = openSession();
1559
1560 userIdMapper = (UserIdMapper)session.get(UserIdMapperImpl.class,
1561 primaryKey);
1562
1563 if (userIdMapper != null) {
1564 cacheResult(userIdMapper);
1565 }
1566 else {
1567 entityCache.putResult(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
1568 UserIdMapperImpl.class, primaryKey, _nullUserIdMapper);
1569 }
1570 }
1571 catch (Exception e) {
1572 entityCache.removeResult(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
1573 UserIdMapperImpl.class, primaryKey);
1574
1575 throw processException(e);
1576 }
1577 finally {
1578 closeSession(session);
1579 }
1580 }
1581
1582 return userIdMapper;
1583 }
1584
1585
1591 @Override
1592 public UserIdMapper fetchByPrimaryKey(long userIdMapperId) {
1593 return fetchByPrimaryKey((Serializable)userIdMapperId);
1594 }
1595
1596 @Override
1597 public Map<Serializable, UserIdMapper> fetchByPrimaryKeys(
1598 Set<Serializable> primaryKeys) {
1599 if (primaryKeys.isEmpty()) {
1600 return Collections.emptyMap();
1601 }
1602
1603 Map<Serializable, UserIdMapper> map = new HashMap<Serializable, UserIdMapper>();
1604
1605 if (primaryKeys.size() == 1) {
1606 Iterator<Serializable> iterator = primaryKeys.iterator();
1607
1608 Serializable primaryKey = iterator.next();
1609
1610 UserIdMapper userIdMapper = fetchByPrimaryKey(primaryKey);
1611
1612 if (userIdMapper != null) {
1613 map.put(primaryKey, userIdMapper);
1614 }
1615
1616 return map;
1617 }
1618
1619 Set<Serializable> uncachedPrimaryKeys = null;
1620
1621 for (Serializable primaryKey : primaryKeys) {
1622 UserIdMapper userIdMapper = (UserIdMapper)entityCache.getResult(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
1623 UserIdMapperImpl.class, primaryKey);
1624
1625 if (userIdMapper == null) {
1626 if (uncachedPrimaryKeys == null) {
1627 uncachedPrimaryKeys = new HashSet<Serializable>();
1628 }
1629
1630 uncachedPrimaryKeys.add(primaryKey);
1631 }
1632 else {
1633 map.put(primaryKey, userIdMapper);
1634 }
1635 }
1636
1637 if (uncachedPrimaryKeys == null) {
1638 return map;
1639 }
1640
1641 StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
1642 1);
1643
1644 query.append(_SQL_SELECT_USERIDMAPPER_WHERE_PKS_IN);
1645
1646 for (Serializable primaryKey : uncachedPrimaryKeys) {
1647 query.append(String.valueOf(primaryKey));
1648
1649 query.append(StringPool.COMMA);
1650 }
1651
1652 query.setIndex(query.index() - 1);
1653
1654 query.append(StringPool.CLOSE_PARENTHESIS);
1655
1656 String sql = query.toString();
1657
1658 Session session = null;
1659
1660 try {
1661 session = openSession();
1662
1663 Query q = session.createQuery(sql);
1664
1665 for (UserIdMapper userIdMapper : (List<UserIdMapper>)q.list()) {
1666 map.put(userIdMapper.getPrimaryKeyObj(), userIdMapper);
1667
1668 cacheResult(userIdMapper);
1669
1670 uncachedPrimaryKeys.remove(userIdMapper.getPrimaryKeyObj());
1671 }
1672
1673 for (Serializable primaryKey : uncachedPrimaryKeys) {
1674 entityCache.putResult(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
1675 UserIdMapperImpl.class, primaryKey, _nullUserIdMapper);
1676 }
1677 }
1678 catch (Exception e) {
1679 throw processException(e);
1680 }
1681 finally {
1682 closeSession(session);
1683 }
1684
1685 return map;
1686 }
1687
1688
1693 @Override
1694 public List<UserIdMapper> findAll() {
1695 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1696 }
1697
1698
1709 @Override
1710 public List<UserIdMapper> findAll(int start, int end) {
1711 return findAll(start, end, null);
1712 }
1713
1714
1726 @Override
1727 public List<UserIdMapper> findAll(int start, int end,
1728 OrderByComparator<UserIdMapper> orderByComparator) {
1729 return findAll(start, end, orderByComparator, true);
1730 }
1731
1732
1745 @Override
1746 public List<UserIdMapper> findAll(int start, int end,
1747 OrderByComparator<UserIdMapper> orderByComparator,
1748 boolean retrieveFromCache) {
1749 boolean pagination = true;
1750 FinderPath finderPath = null;
1751 Object[] finderArgs = null;
1752
1753 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1754 (orderByComparator == null)) {
1755 pagination = false;
1756 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1757 finderArgs = FINDER_ARGS_EMPTY;
1758 }
1759 else {
1760 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1761 finderArgs = new Object[] { start, end, orderByComparator };
1762 }
1763
1764 List<UserIdMapper> list = null;
1765
1766 if (retrieveFromCache) {
1767 list = (List<UserIdMapper>)finderCache.getResult(finderPath,
1768 finderArgs, this);
1769 }
1770
1771 if (list == null) {
1772 StringBundler query = null;
1773 String sql = null;
1774
1775 if (orderByComparator != null) {
1776 query = new StringBundler(2 +
1777 (orderByComparator.getOrderByFields().length * 3));
1778
1779 query.append(_SQL_SELECT_USERIDMAPPER);
1780
1781 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1782 orderByComparator);
1783
1784 sql = query.toString();
1785 }
1786 else {
1787 sql = _SQL_SELECT_USERIDMAPPER;
1788
1789 if (pagination) {
1790 sql = sql.concat(UserIdMapperModelImpl.ORDER_BY_JPQL);
1791 }
1792 }
1793
1794 Session session = null;
1795
1796 try {
1797 session = openSession();
1798
1799 Query q = session.createQuery(sql);
1800
1801 if (!pagination) {
1802 list = (List<UserIdMapper>)QueryUtil.list(q, getDialect(),
1803 start, end, false);
1804
1805 Collections.sort(list);
1806
1807 list = Collections.unmodifiableList(list);
1808 }
1809 else {
1810 list = (List<UserIdMapper>)QueryUtil.list(q, getDialect(),
1811 start, end);
1812 }
1813
1814 cacheResult(list);
1815
1816 finderCache.putResult(finderPath, finderArgs, list);
1817 }
1818 catch (Exception e) {
1819 finderCache.removeResult(finderPath, finderArgs);
1820
1821 throw processException(e);
1822 }
1823 finally {
1824 closeSession(session);
1825 }
1826 }
1827
1828 return list;
1829 }
1830
1831
1835 @Override
1836 public void removeAll() {
1837 for (UserIdMapper userIdMapper : findAll()) {
1838 remove(userIdMapper);
1839 }
1840 }
1841
1842
1847 @Override
1848 public int countAll() {
1849 Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL,
1850 FINDER_ARGS_EMPTY, this);
1851
1852 if (count == null) {
1853 Session session = null;
1854
1855 try {
1856 session = openSession();
1857
1858 Query q = session.createQuery(_SQL_COUNT_USERIDMAPPER);
1859
1860 count = (Long)q.uniqueResult();
1861
1862 finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY,
1863 count);
1864 }
1865 catch (Exception e) {
1866 finderCache.removeResult(FINDER_PATH_COUNT_ALL,
1867 FINDER_ARGS_EMPTY);
1868
1869 throw processException(e);
1870 }
1871 finally {
1872 closeSession(session);
1873 }
1874 }
1875
1876 return count.intValue();
1877 }
1878
1879 @Override
1880 public Set<String> getBadColumnNames() {
1881 return _badColumnNames;
1882 }
1883
1884 @Override
1885 protected Map<String, Integer> getTableColumnsMap() {
1886 return UserIdMapperModelImpl.TABLE_COLUMNS_MAP;
1887 }
1888
1889
1892 public void afterPropertiesSet() {
1893 }
1894
1895 public void destroy() {
1896 entityCache.removeCache(UserIdMapperImpl.class.getName());
1897 finderCache.removeCache(FINDER_CLASS_NAME_ENTITY);
1898 finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1899 finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1900 }
1901
1902 protected EntityCache entityCache = EntityCacheUtil.getEntityCache();
1903 protected FinderCache finderCache = FinderCacheUtil.getFinderCache();
1904 private static final String _SQL_SELECT_USERIDMAPPER = "SELECT userIdMapper FROM UserIdMapper userIdMapper";
1905 private static final String _SQL_SELECT_USERIDMAPPER_WHERE_PKS_IN = "SELECT userIdMapper FROM UserIdMapper userIdMapper WHERE userIdMapperId IN (";
1906 private static final String _SQL_SELECT_USERIDMAPPER_WHERE = "SELECT userIdMapper FROM UserIdMapper userIdMapper WHERE ";
1907 private static final String _SQL_COUNT_USERIDMAPPER = "SELECT COUNT(userIdMapper) FROM UserIdMapper userIdMapper";
1908 private static final String _SQL_COUNT_USERIDMAPPER_WHERE = "SELECT COUNT(userIdMapper) FROM UserIdMapper userIdMapper WHERE ";
1909 private static final String _ORDER_BY_ENTITY_ALIAS = "userIdMapper.";
1910 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No UserIdMapper exists with the primary key ";
1911 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No UserIdMapper exists with the key {";
1912 private static final Log _log = LogFactoryUtil.getLog(UserIdMapperPersistenceImpl.class);
1913 private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
1914 "type"
1915 });
1916 private static final UserIdMapper _nullUserIdMapper = new UserIdMapperImpl() {
1917 @Override
1918 public Object clone() {
1919 return this;
1920 }
1921
1922 @Override
1923 public CacheModel<UserIdMapper> toCacheModel() {
1924 return _nullUserIdMapperCacheModel;
1925 }
1926 };
1927
1928 private static final CacheModel<UserIdMapper> _nullUserIdMapperCacheModel = new NullCacheModel();
1929
1930 private static class NullCacheModel implements CacheModel<UserIdMapper>,
1931 MVCCModel {
1932 @Override
1933 public long getMvccVersion() {
1934 return -1;
1935 }
1936
1937 @Override
1938 public void setMvccVersion(long mvccVersion) {
1939 }
1940
1941 @Override
1942 public UserIdMapper toEntityModel() {
1943 return _nullUserIdMapper;
1944 }
1945 }
1946 }