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