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.cache.CacheRegistryUtil;
021 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
023 import com.liferay.portal.kernel.dao.orm.FinderPath;
024 import com.liferay.portal.kernel.dao.orm.Query;
025 import com.liferay.portal.kernel.dao.orm.QueryPos;
026 import com.liferay.portal.kernel.dao.orm.QueryUtil;
027 import com.liferay.portal.kernel.dao.orm.Session;
028 import com.liferay.portal.kernel.log.Log;
029 import com.liferay.portal.kernel.log.LogFactoryUtil;
030 import com.liferay.portal.kernel.util.OrderByComparator;
031 import com.liferay.portal.kernel.util.SetUtil;
032 import com.liferay.portal.kernel.util.StringBundler;
033 import com.liferay.portal.kernel.util.StringPool;
034 import com.liferay.portal.kernel.util.Validator;
035 import com.liferay.portal.model.CacheModel;
036 import com.liferay.portal.model.MVCCModel;
037 import com.liferay.portal.model.UserIdMapper;
038 import com.liferay.portal.model.impl.UserIdMapperImpl;
039 import com.liferay.portal.model.impl.UserIdMapperModelImpl;
040 import com.liferay.portal.service.persistence.UserIdMapperPersistence;
041
042 import java.io.Serializable;
043
044 import java.util.Collections;
045 import java.util.HashMap;
046 import java.util.HashSet;
047 import java.util.Iterator;
048 import java.util.List;
049 import java.util.Map;
050 import java.util.Set;
051
052
064 @ProviderType
065 public class UserIdMapperPersistenceImpl extends BasePersistenceImpl<UserIdMapper>
066 implements UserIdMapperPersistence {
067
072 public static final String FINDER_CLASS_NAME_ENTITY = UserIdMapperImpl.class.getName();
073 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
074 ".List1";
075 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
076 ".List2";
077 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
078 UserIdMapperModelImpl.FINDER_CACHE_ENABLED, UserIdMapperImpl.class,
079 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
080 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
081 UserIdMapperModelImpl.FINDER_CACHE_ENABLED, UserIdMapperImpl.class,
082 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
083 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
084 UserIdMapperModelImpl.FINDER_CACHE_ENABLED, Long.class,
085 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
086 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID = new FinderPath(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
087 UserIdMapperModelImpl.FINDER_CACHE_ENABLED, UserIdMapperImpl.class,
088 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUserId",
089 new String[] {
090 Long.class.getName(),
091
092 Integer.class.getName(), Integer.class.getName(),
093 OrderByComparator.class.getName()
094 });
095 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID =
096 new FinderPath(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
097 UserIdMapperModelImpl.FINDER_CACHE_ENABLED, UserIdMapperImpl.class,
098 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserId",
099 new String[] { Long.class.getName() },
100 UserIdMapperModelImpl.USERID_COLUMN_BITMASK);
101 public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
102 UserIdMapperModelImpl.FINDER_CACHE_ENABLED, Long.class,
103 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId",
104 new String[] { Long.class.getName() });
105
106
112 @Override
113 public List<UserIdMapper> findByUserId(long userId) {
114 return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
115 }
116
117
129 @Override
130 public List<UserIdMapper> findByUserId(long userId, int start, int end) {
131 return findByUserId(userId, start, end, null);
132 }
133
134
147 @Override
148 public List<UserIdMapper> findByUserId(long userId, int start, int end,
149 OrderByComparator<UserIdMapper> orderByComparator) {
150 boolean pagination = true;
151 FinderPath finderPath = null;
152 Object[] finderArgs = null;
153
154 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
155 (orderByComparator == null)) {
156 pagination = false;
157 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID;
158 finderArgs = new Object[] { userId };
159 }
160 else {
161 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID;
162 finderArgs = new Object[] { userId, start, end, orderByComparator };
163 }
164
165 List<UserIdMapper> list = (List<UserIdMapper>)FinderCacheUtil.getResult(finderPath,
166 finderArgs, this);
167
168 if ((list != null) && !list.isEmpty()) {
169 for (UserIdMapper userIdMapper : list) {
170 if ((userId != userIdMapper.getUserId())) {
171 list = null;
172
173 break;
174 }
175 }
176 }
177
178 if (list == null) {
179 StringBundler query = null;
180
181 if (orderByComparator != null) {
182 query = new StringBundler(3 +
183 (orderByComparator.getOrderByFields().length * 3));
184 }
185 else {
186 query = new StringBundler(3);
187 }
188
189 query.append(_SQL_SELECT_USERIDMAPPER_WHERE);
190
191 query.append(_FINDER_COLUMN_USERID_USERID_2);
192
193 if (orderByComparator != null) {
194 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
195 orderByComparator);
196 }
197 else
198 if (pagination) {
199 query.append(UserIdMapperModelImpl.ORDER_BY_JPQL);
200 }
201
202 String sql = query.toString();
203
204 Session session = null;
205
206 try {
207 session = openSession();
208
209 Query q = session.createQuery(sql);
210
211 QueryPos qPos = QueryPos.getInstance(q);
212
213 qPos.add(userId);
214
215 if (!pagination) {
216 list = (List<UserIdMapper>)QueryUtil.list(q, getDialect(),
217 start, end, false);
218
219 Collections.sort(list);
220
221 list = Collections.unmodifiableList(list);
222 }
223 else {
224 list = (List<UserIdMapper>)QueryUtil.list(q, getDialect(),
225 start, end);
226 }
227
228 cacheResult(list);
229
230 FinderCacheUtil.putResult(finderPath, finderArgs, list);
231 }
232 catch (Exception e) {
233 FinderCacheUtil.removeResult(finderPath, finderArgs);
234
235 throw processException(e);
236 }
237 finally {
238 closeSession(session);
239 }
240 }
241
242 return list;
243 }
244
245
253 @Override
254 public UserIdMapper findByUserId_First(long userId,
255 OrderByComparator<UserIdMapper> orderByComparator)
256 throws NoSuchUserIdMapperException {
257 UserIdMapper userIdMapper = fetchByUserId_First(userId,
258 orderByComparator);
259
260 if (userIdMapper != null) {
261 return userIdMapper;
262 }
263
264 StringBundler msg = new StringBundler(4);
265
266 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
267
268 msg.append("userId=");
269 msg.append(userId);
270
271 msg.append(StringPool.CLOSE_CURLY_BRACE);
272
273 throw new NoSuchUserIdMapperException(msg.toString());
274 }
275
276
283 @Override
284 public UserIdMapper fetchByUserId_First(long userId,
285 OrderByComparator<UserIdMapper> orderByComparator) {
286 List<UserIdMapper> list = findByUserId(userId, 0, 1, orderByComparator);
287
288 if (!list.isEmpty()) {
289 return list.get(0);
290 }
291
292 return null;
293 }
294
295
303 @Override
304 public UserIdMapper findByUserId_Last(long userId,
305 OrderByComparator<UserIdMapper> orderByComparator)
306 throws NoSuchUserIdMapperException {
307 UserIdMapper userIdMapper = fetchByUserId_Last(userId, orderByComparator);
308
309 if (userIdMapper != null) {
310 return userIdMapper;
311 }
312
313 StringBundler msg = new StringBundler(4);
314
315 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
316
317 msg.append("userId=");
318 msg.append(userId);
319
320 msg.append(StringPool.CLOSE_CURLY_BRACE);
321
322 throw new NoSuchUserIdMapperException(msg.toString());
323 }
324
325
332 @Override
333 public UserIdMapper fetchByUserId_Last(long userId,
334 OrderByComparator<UserIdMapper> orderByComparator) {
335 int count = countByUserId(userId);
336
337 if (count == 0) {
338 return null;
339 }
340
341 List<UserIdMapper> list = findByUserId(userId, count - 1, count,
342 orderByComparator);
343
344 if (!list.isEmpty()) {
345 return list.get(0);
346 }
347
348 return null;
349 }
350
351
360 @Override
361 public UserIdMapper[] findByUserId_PrevAndNext(long userIdMapperId,
362 long userId, OrderByComparator<UserIdMapper> orderByComparator)
363 throws NoSuchUserIdMapperException {
364 UserIdMapper userIdMapper = findByPrimaryKey(userIdMapperId);
365
366 Session session = null;
367
368 try {
369 session = openSession();
370
371 UserIdMapper[] array = new UserIdMapperImpl[3];
372
373 array[0] = getByUserId_PrevAndNext(session, userIdMapper, userId,
374 orderByComparator, true);
375
376 array[1] = userIdMapper;
377
378 array[2] = getByUserId_PrevAndNext(session, userIdMapper, userId,
379 orderByComparator, false);
380
381 return array;
382 }
383 catch (Exception e) {
384 throw processException(e);
385 }
386 finally {
387 closeSession(session);
388 }
389 }
390
391 protected UserIdMapper getByUserId_PrevAndNext(Session session,
392 UserIdMapper userIdMapper, long userId,
393 OrderByComparator<UserIdMapper> orderByComparator, boolean previous) {
394 StringBundler query = null;
395
396 if (orderByComparator != null) {
397 query = new StringBundler(6 +
398 (orderByComparator.getOrderByFields().length * 6));
399 }
400 else {
401 query = new StringBundler(3);
402 }
403
404 query.append(_SQL_SELECT_USERIDMAPPER_WHERE);
405
406 query.append(_FINDER_COLUMN_USERID_USERID_2);
407
408 if (orderByComparator != null) {
409 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
410
411 if (orderByConditionFields.length > 0) {
412 query.append(WHERE_AND);
413 }
414
415 for (int i = 0; i < orderByConditionFields.length; i++) {
416 query.append(_ORDER_BY_ENTITY_ALIAS);
417 query.append(orderByConditionFields[i]);
418
419 if ((i + 1) < orderByConditionFields.length) {
420 if (orderByComparator.isAscending() ^ previous) {
421 query.append(WHERE_GREATER_THAN_HAS_NEXT);
422 }
423 else {
424 query.append(WHERE_LESSER_THAN_HAS_NEXT);
425 }
426 }
427 else {
428 if (orderByComparator.isAscending() ^ previous) {
429 query.append(WHERE_GREATER_THAN);
430 }
431 else {
432 query.append(WHERE_LESSER_THAN);
433 }
434 }
435 }
436
437 query.append(ORDER_BY_CLAUSE);
438
439 String[] orderByFields = orderByComparator.getOrderByFields();
440
441 for (int i = 0; i < orderByFields.length; i++) {
442 query.append(_ORDER_BY_ENTITY_ALIAS);
443 query.append(orderByFields[i]);
444
445 if ((i + 1) < orderByFields.length) {
446 if (orderByComparator.isAscending() ^ previous) {
447 query.append(ORDER_BY_ASC_HAS_NEXT);
448 }
449 else {
450 query.append(ORDER_BY_DESC_HAS_NEXT);
451 }
452 }
453 else {
454 if (orderByComparator.isAscending() ^ previous) {
455 query.append(ORDER_BY_ASC);
456 }
457 else {
458 query.append(ORDER_BY_DESC);
459 }
460 }
461 }
462 }
463 else {
464 query.append(UserIdMapperModelImpl.ORDER_BY_JPQL);
465 }
466
467 String sql = query.toString();
468
469 Query q = session.createQuery(sql);
470
471 q.setFirstResult(0);
472 q.setMaxResults(2);
473
474 QueryPos qPos = QueryPos.getInstance(q);
475
476 qPos.add(userId);
477
478 if (orderByComparator != null) {
479 Object[] values = orderByComparator.getOrderByConditionValues(userIdMapper);
480
481 for (Object value : values) {
482 qPos.add(value);
483 }
484 }
485
486 List<UserIdMapper> list = q.list();
487
488 if (list.size() == 2) {
489 return list.get(1);
490 }
491 else {
492 return null;
493 }
494 }
495
496
501 @Override
502 public void removeByUserId(long userId) {
503 for (UserIdMapper userIdMapper : findByUserId(userId,
504 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
505 remove(userIdMapper);
506 }
507 }
508
509
515 @Override
516 public int countByUserId(long userId) {
517 FinderPath finderPath = FINDER_PATH_COUNT_BY_USERID;
518
519 Object[] finderArgs = new Object[] { userId };
520
521 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
522 this);
523
524 if (count == null) {
525 StringBundler query = new StringBundler(2);
526
527 query.append(_SQL_COUNT_USERIDMAPPER_WHERE);
528
529 query.append(_FINDER_COLUMN_USERID_USERID_2);
530
531 String sql = query.toString();
532
533 Session session = null;
534
535 try {
536 session = openSession();
537
538 Query q = session.createQuery(sql);
539
540 QueryPos qPos = QueryPos.getInstance(q);
541
542 qPos.add(userId);
543
544 count = (Long)q.uniqueResult();
545
546 FinderCacheUtil.putResult(finderPath, finderArgs, count);
547 }
548 catch (Exception e) {
549 FinderCacheUtil.removeResult(finderPath, finderArgs);
550
551 throw processException(e);
552 }
553 finally {
554 closeSession(session);
555 }
556 }
557
558 return count.intValue();
559 }
560
561 private static final String _FINDER_COLUMN_USERID_USERID_2 = "userIdMapper.userId = ?";
562 public static final FinderPath FINDER_PATH_FETCH_BY_U_T = new FinderPath(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
563 UserIdMapperModelImpl.FINDER_CACHE_ENABLED, UserIdMapperImpl.class,
564 FINDER_CLASS_NAME_ENTITY, "fetchByU_T",
565 new String[] { Long.class.getName(), String.class.getName() },
566 UserIdMapperModelImpl.USERID_COLUMN_BITMASK |
567 UserIdMapperModelImpl.TYPE_COLUMN_BITMASK);
568 public static final FinderPath FINDER_PATH_COUNT_BY_U_T = new FinderPath(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
569 UserIdMapperModelImpl.FINDER_CACHE_ENABLED, Long.class,
570 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_T",
571 new String[] { Long.class.getName(), String.class.getName() });
572
573
581 @Override
582 public UserIdMapper findByU_T(long userId, String type)
583 throws NoSuchUserIdMapperException {
584 UserIdMapper userIdMapper = fetchByU_T(userId, type);
585
586 if (userIdMapper == null) {
587 StringBundler msg = new StringBundler(6);
588
589 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
590
591 msg.append("userId=");
592 msg.append(userId);
593
594 msg.append(", type=");
595 msg.append(type);
596
597 msg.append(StringPool.CLOSE_CURLY_BRACE);
598
599 if (_log.isWarnEnabled()) {
600 _log.warn(msg.toString());
601 }
602
603 throw new NoSuchUserIdMapperException(msg.toString());
604 }
605
606 return userIdMapper;
607 }
608
609
616 @Override
617 public UserIdMapper fetchByU_T(long userId, String type) {
618 return fetchByU_T(userId, type, true);
619 }
620
621
629 @Override
630 public UserIdMapper fetchByU_T(long userId, String type,
631 boolean retrieveFromCache) {
632 Object[] finderArgs = new Object[] { userId, type };
633
634 Object result = null;
635
636 if (retrieveFromCache) {
637 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_U_T,
638 finderArgs, this);
639 }
640
641 if (result instanceof UserIdMapper) {
642 UserIdMapper userIdMapper = (UserIdMapper)result;
643
644 if ((userId != userIdMapper.getUserId()) ||
645 !Validator.equals(type, userIdMapper.getType())) {
646 result = null;
647 }
648 }
649
650 if (result == null) {
651 StringBundler query = new StringBundler(4);
652
653 query.append(_SQL_SELECT_USERIDMAPPER_WHERE);
654
655 query.append(_FINDER_COLUMN_U_T_USERID_2);
656
657 boolean bindType = false;
658
659 if (type == null) {
660 query.append(_FINDER_COLUMN_U_T_TYPE_1);
661 }
662 else if (type.equals(StringPool.BLANK)) {
663 query.append(_FINDER_COLUMN_U_T_TYPE_3);
664 }
665 else {
666 bindType = true;
667
668 query.append(_FINDER_COLUMN_U_T_TYPE_2);
669 }
670
671 String sql = query.toString();
672
673 Session session = null;
674
675 try {
676 session = openSession();
677
678 Query q = session.createQuery(sql);
679
680 QueryPos qPos = QueryPos.getInstance(q);
681
682 qPos.add(userId);
683
684 if (bindType) {
685 qPos.add(type);
686 }
687
688 List<UserIdMapper> list = q.list();
689
690 if (list.isEmpty()) {
691 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T,
692 finderArgs, list);
693 }
694 else {
695 UserIdMapper userIdMapper = list.get(0);
696
697 result = userIdMapper;
698
699 cacheResult(userIdMapper);
700
701 if ((userIdMapper.getUserId() != userId) ||
702 (userIdMapper.getType() == null) ||
703 !userIdMapper.getType().equals(type)) {
704 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T,
705 finderArgs, userIdMapper);
706 }
707 }
708 }
709 catch (Exception e) {
710 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_T,
711 finderArgs);
712
713 throw processException(e);
714 }
715 finally {
716 closeSession(session);
717 }
718 }
719
720 if (result instanceof List<?>) {
721 return null;
722 }
723 else {
724 return (UserIdMapper)result;
725 }
726 }
727
728
735 @Override
736 public UserIdMapper removeByU_T(long userId, String type)
737 throws NoSuchUserIdMapperException {
738 UserIdMapper userIdMapper = findByU_T(userId, type);
739
740 return remove(userIdMapper);
741 }
742
743
750 @Override
751 public int countByU_T(long userId, String type) {
752 FinderPath finderPath = FINDER_PATH_COUNT_BY_U_T;
753
754 Object[] finderArgs = new Object[] { userId, type };
755
756 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
757 this);
758
759 if (count == null) {
760 StringBundler query = new StringBundler(3);
761
762 query.append(_SQL_COUNT_USERIDMAPPER_WHERE);
763
764 query.append(_FINDER_COLUMN_U_T_USERID_2);
765
766 boolean bindType = false;
767
768 if (type == null) {
769 query.append(_FINDER_COLUMN_U_T_TYPE_1);
770 }
771 else if (type.equals(StringPool.BLANK)) {
772 query.append(_FINDER_COLUMN_U_T_TYPE_3);
773 }
774 else {
775 bindType = true;
776
777 query.append(_FINDER_COLUMN_U_T_TYPE_2);
778 }
779
780 String sql = query.toString();
781
782 Session session = null;
783
784 try {
785 session = openSession();
786
787 Query q = session.createQuery(sql);
788
789 QueryPos qPos = QueryPos.getInstance(q);
790
791 qPos.add(userId);
792
793 if (bindType) {
794 qPos.add(type);
795 }
796
797 count = (Long)q.uniqueResult();
798
799 FinderCacheUtil.putResult(finderPath, finderArgs, count);
800 }
801 catch (Exception e) {
802 FinderCacheUtil.removeResult(finderPath, finderArgs);
803
804 throw processException(e);
805 }
806 finally {
807 closeSession(session);
808 }
809 }
810
811 return count.intValue();
812 }
813
814 private static final String _FINDER_COLUMN_U_T_USERID_2 = "userIdMapper.userId = ? AND ";
815 private static final String _FINDER_COLUMN_U_T_TYPE_1 = "userIdMapper.type IS NULL";
816 private static final String _FINDER_COLUMN_U_T_TYPE_2 = "userIdMapper.type = ?";
817 private static final String _FINDER_COLUMN_U_T_TYPE_3 = "(userIdMapper.type IS NULL OR userIdMapper.type = '')";
818 public static final FinderPath FINDER_PATH_FETCH_BY_T_E = new FinderPath(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
819 UserIdMapperModelImpl.FINDER_CACHE_ENABLED, UserIdMapperImpl.class,
820 FINDER_CLASS_NAME_ENTITY, "fetchByT_E",
821 new String[] { String.class.getName(), String.class.getName() },
822 UserIdMapperModelImpl.TYPE_COLUMN_BITMASK |
823 UserIdMapperModelImpl.EXTERNALUSERID_COLUMN_BITMASK);
824 public static final FinderPath FINDER_PATH_COUNT_BY_T_E = new FinderPath(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
825 UserIdMapperModelImpl.FINDER_CACHE_ENABLED, Long.class,
826 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_E",
827 new String[] { String.class.getName(), String.class.getName() });
828
829
837 @Override
838 public UserIdMapper findByT_E(String type, String externalUserId)
839 throws NoSuchUserIdMapperException {
840 UserIdMapper userIdMapper = fetchByT_E(type, externalUserId);
841
842 if (userIdMapper == null) {
843 StringBundler msg = new StringBundler(6);
844
845 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
846
847 msg.append("type=");
848 msg.append(type);
849
850 msg.append(", externalUserId=");
851 msg.append(externalUserId);
852
853 msg.append(StringPool.CLOSE_CURLY_BRACE);
854
855 if (_log.isWarnEnabled()) {
856 _log.warn(msg.toString());
857 }
858
859 throw new NoSuchUserIdMapperException(msg.toString());
860 }
861
862 return userIdMapper;
863 }
864
865
872 @Override
873 public UserIdMapper fetchByT_E(String type, String externalUserId) {
874 return fetchByT_E(type, externalUserId, true);
875 }
876
877
885 @Override
886 public UserIdMapper fetchByT_E(String type, String externalUserId,
887 boolean retrieveFromCache) {
888 Object[] finderArgs = new Object[] { type, externalUserId };
889
890 Object result = null;
891
892 if (retrieveFromCache) {
893 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_T_E,
894 finderArgs, this);
895 }
896
897 if (result instanceof UserIdMapper) {
898 UserIdMapper userIdMapper = (UserIdMapper)result;
899
900 if (!Validator.equals(type, userIdMapper.getType()) ||
901 !Validator.equals(externalUserId,
902 userIdMapper.getExternalUserId())) {
903 result = null;
904 }
905 }
906
907 if (result == null) {
908 StringBundler query = new StringBundler(4);
909
910 query.append(_SQL_SELECT_USERIDMAPPER_WHERE);
911
912 boolean bindType = false;
913
914 if (type == null) {
915 query.append(_FINDER_COLUMN_T_E_TYPE_1);
916 }
917 else if (type.equals(StringPool.BLANK)) {
918 query.append(_FINDER_COLUMN_T_E_TYPE_3);
919 }
920 else {
921 bindType = true;
922
923 query.append(_FINDER_COLUMN_T_E_TYPE_2);
924 }
925
926 boolean bindExternalUserId = false;
927
928 if (externalUserId == null) {
929 query.append(_FINDER_COLUMN_T_E_EXTERNALUSERID_1);
930 }
931 else if (externalUserId.equals(StringPool.BLANK)) {
932 query.append(_FINDER_COLUMN_T_E_EXTERNALUSERID_3);
933 }
934 else {
935 bindExternalUserId = true;
936
937 query.append(_FINDER_COLUMN_T_E_EXTERNALUSERID_2);
938 }
939
940 String sql = query.toString();
941
942 Session session = null;
943
944 try {
945 session = openSession();
946
947 Query q = session.createQuery(sql);
948
949 QueryPos qPos = QueryPos.getInstance(q);
950
951 if (bindType) {
952 qPos.add(type);
953 }
954
955 if (bindExternalUserId) {
956 qPos.add(externalUserId);
957 }
958
959 List<UserIdMapper> list = q.list();
960
961 if (list.isEmpty()) {
962 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_E,
963 finderArgs, list);
964 }
965 else {
966 UserIdMapper userIdMapper = list.get(0);
967
968 result = userIdMapper;
969
970 cacheResult(userIdMapper);
971
972 if ((userIdMapper.getType() == null) ||
973 !userIdMapper.getType().equals(type) ||
974 (userIdMapper.getExternalUserId() == null) ||
975 !userIdMapper.getExternalUserId()
976 .equals(externalUserId)) {
977 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_E,
978 finderArgs, userIdMapper);
979 }
980 }
981 }
982 catch (Exception e) {
983 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_T_E,
984 finderArgs);
985
986 throw processException(e);
987 }
988 finally {
989 closeSession(session);
990 }
991 }
992
993 if (result instanceof List<?>) {
994 return null;
995 }
996 else {
997 return (UserIdMapper)result;
998 }
999 }
1000
1001
1008 @Override
1009 public UserIdMapper removeByT_E(String type, String externalUserId)
1010 throws NoSuchUserIdMapperException {
1011 UserIdMapper userIdMapper = findByT_E(type, externalUserId);
1012
1013 return remove(userIdMapper);
1014 }
1015
1016
1023 @Override
1024 public int countByT_E(String type, String externalUserId) {
1025 FinderPath finderPath = FINDER_PATH_COUNT_BY_T_E;
1026
1027 Object[] finderArgs = new Object[] { type, externalUserId };
1028
1029 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1030 this);
1031
1032 if (count == null) {
1033 StringBundler query = new StringBundler(3);
1034
1035 query.append(_SQL_COUNT_USERIDMAPPER_WHERE);
1036
1037 boolean bindType = false;
1038
1039 if (type == null) {
1040 query.append(_FINDER_COLUMN_T_E_TYPE_1);
1041 }
1042 else if (type.equals(StringPool.BLANK)) {
1043 query.append(_FINDER_COLUMN_T_E_TYPE_3);
1044 }
1045 else {
1046 bindType = true;
1047
1048 query.append(_FINDER_COLUMN_T_E_TYPE_2);
1049 }
1050
1051 boolean bindExternalUserId = false;
1052
1053 if (externalUserId == null) {
1054 query.append(_FINDER_COLUMN_T_E_EXTERNALUSERID_1);
1055 }
1056 else if (externalUserId.equals(StringPool.BLANK)) {
1057 query.append(_FINDER_COLUMN_T_E_EXTERNALUSERID_3);
1058 }
1059 else {
1060 bindExternalUserId = true;
1061
1062 query.append(_FINDER_COLUMN_T_E_EXTERNALUSERID_2);
1063 }
1064
1065 String sql = query.toString();
1066
1067 Session session = null;
1068
1069 try {
1070 session = openSession();
1071
1072 Query q = session.createQuery(sql);
1073
1074 QueryPos qPos = QueryPos.getInstance(q);
1075
1076 if (bindType) {
1077 qPos.add(type);
1078 }
1079
1080 if (bindExternalUserId) {
1081 qPos.add(externalUserId);
1082 }
1083
1084 count = (Long)q.uniqueResult();
1085
1086 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1087 }
1088 catch (Exception e) {
1089 FinderCacheUtil.removeResult(finderPath, finderArgs);
1090
1091 throw processException(e);
1092 }
1093 finally {
1094 closeSession(session);
1095 }
1096 }
1097
1098 return count.intValue();
1099 }
1100
1101 private static final String _FINDER_COLUMN_T_E_TYPE_1 = "userIdMapper.type IS NULL AND ";
1102 private static final String _FINDER_COLUMN_T_E_TYPE_2 = "userIdMapper.type = ? AND ";
1103 private static final String _FINDER_COLUMN_T_E_TYPE_3 = "(userIdMapper.type IS NULL OR userIdMapper.type = '') AND ";
1104 private static final String _FINDER_COLUMN_T_E_EXTERNALUSERID_1 = "userIdMapper.externalUserId IS NULL";
1105 private static final String _FINDER_COLUMN_T_E_EXTERNALUSERID_2 = "userIdMapper.externalUserId = ?";
1106 private static final String _FINDER_COLUMN_T_E_EXTERNALUSERID_3 = "(userIdMapper.externalUserId IS NULL OR userIdMapper.externalUserId = '')";
1107
1108 public UserIdMapperPersistenceImpl() {
1109 setModelClass(UserIdMapper.class);
1110 }
1111
1112
1117 @Override
1118 public void cacheResult(UserIdMapper userIdMapper) {
1119 EntityCacheUtil.putResult(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
1120 UserIdMapperImpl.class, userIdMapper.getPrimaryKey(), userIdMapper);
1121
1122 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T,
1123 new Object[] { userIdMapper.getUserId(), userIdMapper.getType() },
1124 userIdMapper);
1125
1126 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_E,
1127 new Object[] {
1128 userIdMapper.getType(), userIdMapper.getExternalUserId()
1129 }, userIdMapper);
1130
1131 userIdMapper.resetOriginalValues();
1132 }
1133
1134
1139 @Override
1140 public void cacheResult(List<UserIdMapper> userIdMappers) {
1141 for (UserIdMapper userIdMapper : userIdMappers) {
1142 if (EntityCacheUtil.getResult(
1143 UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
1144 UserIdMapperImpl.class, userIdMapper.getPrimaryKey()) == null) {
1145 cacheResult(userIdMapper);
1146 }
1147 else {
1148 userIdMapper.resetOriginalValues();
1149 }
1150 }
1151 }
1152
1153
1160 @Override
1161 public void clearCache() {
1162 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
1163 CacheRegistryUtil.clear(UserIdMapperImpl.class.getName());
1164 }
1165
1166 EntityCacheUtil.clearCache(UserIdMapperImpl.class);
1167
1168 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
1169 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1170 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1171 }
1172
1173
1180 @Override
1181 public void clearCache(UserIdMapper userIdMapper) {
1182 EntityCacheUtil.removeResult(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
1183 UserIdMapperImpl.class, userIdMapper.getPrimaryKey());
1184
1185 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1186 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1187
1188 clearUniqueFindersCache(userIdMapper);
1189 }
1190
1191 @Override
1192 public void clearCache(List<UserIdMapper> userIdMappers) {
1193 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1194 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1195
1196 for (UserIdMapper userIdMapper : userIdMappers) {
1197 EntityCacheUtil.removeResult(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
1198 UserIdMapperImpl.class, userIdMapper.getPrimaryKey());
1199
1200 clearUniqueFindersCache(userIdMapper);
1201 }
1202 }
1203
1204 protected void cacheUniqueFindersCache(UserIdMapper userIdMapper) {
1205 if (userIdMapper.isNew()) {
1206 Object[] args = new Object[] {
1207 userIdMapper.getUserId(), userIdMapper.getType()
1208 };
1209
1210 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_T, args,
1211 Long.valueOf(1));
1212 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T, args,
1213 userIdMapper);
1214
1215 args = new Object[] {
1216 userIdMapper.getType(), userIdMapper.getExternalUserId()
1217 };
1218
1219 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_E, args,
1220 Long.valueOf(1));
1221 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_E, args,
1222 userIdMapper);
1223 }
1224 else {
1225 UserIdMapperModelImpl userIdMapperModelImpl = (UserIdMapperModelImpl)userIdMapper;
1226
1227 if ((userIdMapperModelImpl.getColumnBitmask() &
1228 FINDER_PATH_FETCH_BY_U_T.getColumnBitmask()) != 0) {
1229 Object[] args = new Object[] {
1230 userIdMapper.getUserId(), userIdMapper.getType()
1231 };
1232
1233 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_T, args,
1234 Long.valueOf(1));
1235 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T, args,
1236 userIdMapper);
1237 }
1238
1239 if ((userIdMapperModelImpl.getColumnBitmask() &
1240 FINDER_PATH_FETCH_BY_T_E.getColumnBitmask()) != 0) {
1241 Object[] args = new Object[] {
1242 userIdMapper.getType(), userIdMapper.getExternalUserId()
1243 };
1244
1245 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_E, args,
1246 Long.valueOf(1));
1247 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_E, args,
1248 userIdMapper);
1249 }
1250 }
1251 }
1252
1253 protected void clearUniqueFindersCache(UserIdMapper userIdMapper) {
1254 UserIdMapperModelImpl userIdMapperModelImpl = (UserIdMapperModelImpl)userIdMapper;
1255
1256 Object[] args = new Object[] {
1257 userIdMapper.getUserId(), userIdMapper.getType()
1258 };
1259
1260 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_T, args);
1261 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_T, args);
1262
1263 if ((userIdMapperModelImpl.getColumnBitmask() &
1264 FINDER_PATH_FETCH_BY_U_T.getColumnBitmask()) != 0) {
1265 args = new Object[] {
1266 userIdMapperModelImpl.getOriginalUserId(),
1267 userIdMapperModelImpl.getOriginalType()
1268 };
1269
1270 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_T, args);
1271 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_T, args);
1272 }
1273
1274 args = new Object[] {
1275 userIdMapper.getType(), userIdMapper.getExternalUserId()
1276 };
1277
1278 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_E, args);
1279 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_T_E, args);
1280
1281 if ((userIdMapperModelImpl.getColumnBitmask() &
1282 FINDER_PATH_FETCH_BY_T_E.getColumnBitmask()) != 0) {
1283 args = new Object[] {
1284 userIdMapperModelImpl.getOriginalType(),
1285 userIdMapperModelImpl.getOriginalExternalUserId()
1286 };
1287
1288 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_E, args);
1289 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_T_E, args);
1290 }
1291 }
1292
1293
1299 @Override
1300 public UserIdMapper create(long userIdMapperId) {
1301 UserIdMapper userIdMapper = new UserIdMapperImpl();
1302
1303 userIdMapper.setNew(true);
1304 userIdMapper.setPrimaryKey(userIdMapperId);
1305
1306 return userIdMapper;
1307 }
1308
1309
1316 @Override
1317 public UserIdMapper remove(long userIdMapperId)
1318 throws NoSuchUserIdMapperException {
1319 return remove((Serializable)userIdMapperId);
1320 }
1321
1322
1329 @Override
1330 public UserIdMapper remove(Serializable primaryKey)
1331 throws NoSuchUserIdMapperException {
1332 Session session = null;
1333
1334 try {
1335 session = openSession();
1336
1337 UserIdMapper userIdMapper = (UserIdMapper)session.get(UserIdMapperImpl.class,
1338 primaryKey);
1339
1340 if (userIdMapper == null) {
1341 if (_log.isWarnEnabled()) {
1342 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1343 }
1344
1345 throw new NoSuchUserIdMapperException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1346 primaryKey);
1347 }
1348
1349 return remove(userIdMapper);
1350 }
1351 catch (NoSuchUserIdMapperException nsee) {
1352 throw nsee;
1353 }
1354 catch (Exception e) {
1355 throw processException(e);
1356 }
1357 finally {
1358 closeSession(session);
1359 }
1360 }
1361
1362 @Override
1363 protected UserIdMapper removeImpl(UserIdMapper userIdMapper) {
1364 userIdMapper = toUnwrappedModel(userIdMapper);
1365
1366 Session session = null;
1367
1368 try {
1369 session = openSession();
1370
1371 if (!session.contains(userIdMapper)) {
1372 userIdMapper = (UserIdMapper)session.get(UserIdMapperImpl.class,
1373 userIdMapper.getPrimaryKeyObj());
1374 }
1375
1376 if (userIdMapper != null) {
1377 session.delete(userIdMapper);
1378 }
1379 }
1380 catch (Exception e) {
1381 throw processException(e);
1382 }
1383 finally {
1384 closeSession(session);
1385 }
1386
1387 if (userIdMapper != null) {
1388 clearCache(userIdMapper);
1389 }
1390
1391 return userIdMapper;
1392 }
1393
1394 @Override
1395 public UserIdMapper updateImpl(
1396 com.liferay.portal.model.UserIdMapper userIdMapper) {
1397 userIdMapper = toUnwrappedModel(userIdMapper);
1398
1399 boolean isNew = userIdMapper.isNew();
1400
1401 UserIdMapperModelImpl userIdMapperModelImpl = (UserIdMapperModelImpl)userIdMapper;
1402
1403 Session session = null;
1404
1405 try {
1406 session = openSession();
1407
1408 if (userIdMapper.isNew()) {
1409 session.save(userIdMapper);
1410
1411 userIdMapper.setNew(false);
1412 }
1413 else {
1414 session.merge(userIdMapper);
1415 }
1416 }
1417 catch (Exception e) {
1418 throw processException(e);
1419 }
1420 finally {
1421 closeSession(session);
1422 }
1423
1424 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1425
1426 if (isNew || !UserIdMapperModelImpl.COLUMN_BITMASK_ENABLED) {
1427 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1428 }
1429
1430 else {
1431 if ((userIdMapperModelImpl.getColumnBitmask() &
1432 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
1433 Object[] args = new Object[] {
1434 userIdMapperModelImpl.getOriginalUserId()
1435 };
1436
1437 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
1438 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
1439 args);
1440
1441 args = new Object[] { userIdMapperModelImpl.getUserId() };
1442
1443 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
1444 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
1445 args);
1446 }
1447 }
1448
1449 EntityCacheUtil.putResult(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
1450 UserIdMapperImpl.class, userIdMapper.getPrimaryKey(), userIdMapper,
1451 false);
1452
1453 clearUniqueFindersCache(userIdMapper);
1454 cacheUniqueFindersCache(userIdMapper);
1455
1456 userIdMapper.resetOriginalValues();
1457
1458 return userIdMapper;
1459 }
1460
1461 protected UserIdMapper toUnwrappedModel(UserIdMapper userIdMapper) {
1462 if (userIdMapper instanceof UserIdMapperImpl) {
1463 return userIdMapper;
1464 }
1465
1466 UserIdMapperImpl userIdMapperImpl = new UserIdMapperImpl();
1467
1468 userIdMapperImpl.setNew(userIdMapper.isNew());
1469 userIdMapperImpl.setPrimaryKey(userIdMapper.getPrimaryKey());
1470
1471 userIdMapperImpl.setMvccVersion(userIdMapper.getMvccVersion());
1472 userIdMapperImpl.setUserIdMapperId(userIdMapper.getUserIdMapperId());
1473 userIdMapperImpl.setUserId(userIdMapper.getUserId());
1474 userIdMapperImpl.setType(userIdMapper.getType());
1475 userIdMapperImpl.setDescription(userIdMapper.getDescription());
1476 userIdMapperImpl.setExternalUserId(userIdMapper.getExternalUserId());
1477
1478 return userIdMapperImpl;
1479 }
1480
1481
1488 @Override
1489 public UserIdMapper findByPrimaryKey(Serializable primaryKey)
1490 throws NoSuchUserIdMapperException {
1491 UserIdMapper userIdMapper = fetchByPrimaryKey(primaryKey);
1492
1493 if (userIdMapper == null) {
1494 if (_log.isWarnEnabled()) {
1495 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1496 }
1497
1498 throw new NoSuchUserIdMapperException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1499 primaryKey);
1500 }
1501
1502 return userIdMapper;
1503 }
1504
1505
1512 @Override
1513 public UserIdMapper findByPrimaryKey(long userIdMapperId)
1514 throws NoSuchUserIdMapperException {
1515 return findByPrimaryKey((Serializable)userIdMapperId);
1516 }
1517
1518
1524 @Override
1525 public UserIdMapper fetchByPrimaryKey(Serializable primaryKey) {
1526 UserIdMapper userIdMapper = (UserIdMapper)EntityCacheUtil.getResult(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
1527 UserIdMapperImpl.class, primaryKey);
1528
1529 if (userIdMapper == _nullUserIdMapper) {
1530 return null;
1531 }
1532
1533 if (userIdMapper == null) {
1534 Session session = null;
1535
1536 try {
1537 session = openSession();
1538
1539 userIdMapper = (UserIdMapper)session.get(UserIdMapperImpl.class,
1540 primaryKey);
1541
1542 if (userIdMapper != null) {
1543 cacheResult(userIdMapper);
1544 }
1545 else {
1546 EntityCacheUtil.putResult(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
1547 UserIdMapperImpl.class, primaryKey, _nullUserIdMapper);
1548 }
1549 }
1550 catch (Exception e) {
1551 EntityCacheUtil.removeResult(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
1552 UserIdMapperImpl.class, primaryKey);
1553
1554 throw processException(e);
1555 }
1556 finally {
1557 closeSession(session);
1558 }
1559 }
1560
1561 return userIdMapper;
1562 }
1563
1564
1570 @Override
1571 public UserIdMapper fetchByPrimaryKey(long userIdMapperId) {
1572 return fetchByPrimaryKey((Serializable)userIdMapperId);
1573 }
1574
1575 @Override
1576 public Map<Serializable, UserIdMapper> fetchByPrimaryKeys(
1577 Set<Serializable> primaryKeys) {
1578 if (primaryKeys.isEmpty()) {
1579 return Collections.emptyMap();
1580 }
1581
1582 Map<Serializable, UserIdMapper> map = new HashMap<Serializable, UserIdMapper>();
1583
1584 if (primaryKeys.size() == 1) {
1585 Iterator<Serializable> iterator = primaryKeys.iterator();
1586
1587 Serializable primaryKey = iterator.next();
1588
1589 UserIdMapper userIdMapper = fetchByPrimaryKey(primaryKey);
1590
1591 if (userIdMapper != null) {
1592 map.put(primaryKey, userIdMapper);
1593 }
1594
1595 return map;
1596 }
1597
1598 Set<Serializable> uncachedPrimaryKeys = null;
1599
1600 for (Serializable primaryKey : primaryKeys) {
1601 UserIdMapper userIdMapper = (UserIdMapper)EntityCacheUtil.getResult(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
1602 UserIdMapperImpl.class, primaryKey);
1603
1604 if (userIdMapper == null) {
1605 if (uncachedPrimaryKeys == null) {
1606 uncachedPrimaryKeys = new HashSet<Serializable>();
1607 }
1608
1609 uncachedPrimaryKeys.add(primaryKey);
1610 }
1611 else {
1612 map.put(primaryKey, userIdMapper);
1613 }
1614 }
1615
1616 if (uncachedPrimaryKeys == null) {
1617 return map;
1618 }
1619
1620 StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
1621 1);
1622
1623 query.append(_SQL_SELECT_USERIDMAPPER_WHERE_PKS_IN);
1624
1625 for (Serializable primaryKey : uncachedPrimaryKeys) {
1626 query.append(String.valueOf(primaryKey));
1627
1628 query.append(StringPool.COMMA);
1629 }
1630
1631 query.setIndex(query.index() - 1);
1632
1633 query.append(StringPool.CLOSE_PARENTHESIS);
1634
1635 String sql = query.toString();
1636
1637 Session session = null;
1638
1639 try {
1640 session = openSession();
1641
1642 Query q = session.createQuery(sql);
1643
1644 for (UserIdMapper userIdMapper : (List<UserIdMapper>)q.list()) {
1645 map.put(userIdMapper.getPrimaryKeyObj(), userIdMapper);
1646
1647 cacheResult(userIdMapper);
1648
1649 uncachedPrimaryKeys.remove(userIdMapper.getPrimaryKeyObj());
1650 }
1651
1652 for (Serializable primaryKey : uncachedPrimaryKeys) {
1653 EntityCacheUtil.putResult(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
1654 UserIdMapperImpl.class, primaryKey, _nullUserIdMapper);
1655 }
1656 }
1657 catch (Exception e) {
1658 throw processException(e);
1659 }
1660 finally {
1661 closeSession(session);
1662 }
1663
1664 return map;
1665 }
1666
1667
1672 @Override
1673 public List<UserIdMapper> findAll() {
1674 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1675 }
1676
1677
1688 @Override
1689 public List<UserIdMapper> findAll(int start, int end) {
1690 return findAll(start, end, null);
1691 }
1692
1693
1705 @Override
1706 public List<UserIdMapper> findAll(int start, int end,
1707 OrderByComparator<UserIdMapper> orderByComparator) {
1708 boolean pagination = true;
1709 FinderPath finderPath = null;
1710 Object[] finderArgs = null;
1711
1712 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1713 (orderByComparator == null)) {
1714 pagination = false;
1715 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1716 finderArgs = FINDER_ARGS_EMPTY;
1717 }
1718 else {
1719 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1720 finderArgs = new Object[] { start, end, orderByComparator };
1721 }
1722
1723 List<UserIdMapper> list = (List<UserIdMapper>)FinderCacheUtil.getResult(finderPath,
1724 finderArgs, this);
1725
1726 if (list == null) {
1727 StringBundler query = null;
1728 String sql = null;
1729
1730 if (orderByComparator != null) {
1731 query = new StringBundler(2 +
1732 (orderByComparator.getOrderByFields().length * 3));
1733
1734 query.append(_SQL_SELECT_USERIDMAPPER);
1735
1736 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1737 orderByComparator);
1738
1739 sql = query.toString();
1740 }
1741 else {
1742 sql = _SQL_SELECT_USERIDMAPPER;
1743
1744 if (pagination) {
1745 sql = sql.concat(UserIdMapperModelImpl.ORDER_BY_JPQL);
1746 }
1747 }
1748
1749 Session session = null;
1750
1751 try {
1752 session = openSession();
1753
1754 Query q = session.createQuery(sql);
1755
1756 if (!pagination) {
1757 list = (List<UserIdMapper>)QueryUtil.list(q, getDialect(),
1758 start, end, false);
1759
1760 Collections.sort(list);
1761
1762 list = Collections.unmodifiableList(list);
1763 }
1764 else {
1765 list = (List<UserIdMapper>)QueryUtil.list(q, getDialect(),
1766 start, end);
1767 }
1768
1769 cacheResult(list);
1770
1771 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1772 }
1773 catch (Exception e) {
1774 FinderCacheUtil.removeResult(finderPath, finderArgs);
1775
1776 throw processException(e);
1777 }
1778 finally {
1779 closeSession(session);
1780 }
1781 }
1782
1783 return list;
1784 }
1785
1786
1790 @Override
1791 public void removeAll() {
1792 for (UserIdMapper userIdMapper : findAll()) {
1793 remove(userIdMapper);
1794 }
1795 }
1796
1797
1802 @Override
1803 public int countAll() {
1804 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1805 FINDER_ARGS_EMPTY, this);
1806
1807 if (count == null) {
1808 Session session = null;
1809
1810 try {
1811 session = openSession();
1812
1813 Query q = session.createQuery(_SQL_COUNT_USERIDMAPPER);
1814
1815 count = (Long)q.uniqueResult();
1816
1817 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1818 FINDER_ARGS_EMPTY, count);
1819 }
1820 catch (Exception e) {
1821 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
1822 FINDER_ARGS_EMPTY);
1823
1824 throw processException(e);
1825 }
1826 finally {
1827 closeSession(session);
1828 }
1829 }
1830
1831 return count.intValue();
1832 }
1833
1834 @Override
1835 protected Set<String> getBadColumnNames() {
1836 return _badColumnNames;
1837 }
1838
1839
1842 public void afterPropertiesSet() {
1843 }
1844
1845 public void destroy() {
1846 EntityCacheUtil.removeCache(UserIdMapperImpl.class.getName());
1847 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1848 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1849 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1850 }
1851
1852 private static final String _SQL_SELECT_USERIDMAPPER = "SELECT userIdMapper FROM UserIdMapper userIdMapper";
1853 private static final String _SQL_SELECT_USERIDMAPPER_WHERE_PKS_IN = "SELECT userIdMapper FROM UserIdMapper userIdMapper WHERE userIdMapperId IN (";
1854 private static final String _SQL_SELECT_USERIDMAPPER_WHERE = "SELECT userIdMapper FROM UserIdMapper userIdMapper WHERE ";
1855 private static final String _SQL_COUNT_USERIDMAPPER = "SELECT COUNT(userIdMapper) FROM UserIdMapper userIdMapper";
1856 private static final String _SQL_COUNT_USERIDMAPPER_WHERE = "SELECT COUNT(userIdMapper) FROM UserIdMapper userIdMapper WHERE ";
1857 private static final String _ORDER_BY_ENTITY_ALIAS = "userIdMapper.";
1858 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No UserIdMapper exists with the primary key ";
1859 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No UserIdMapper exists with the key {";
1860 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1861 private static final Log _log = LogFactoryUtil.getLog(UserIdMapperPersistenceImpl.class);
1862 private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
1863 "type"
1864 });
1865 private static final UserIdMapper _nullUserIdMapper = new UserIdMapperImpl() {
1866 @Override
1867 public Object clone() {
1868 return this;
1869 }
1870
1871 @Override
1872 public CacheModel<UserIdMapper> toCacheModel() {
1873 return _nullUserIdMapperCacheModel;
1874 }
1875 };
1876
1877 private static final CacheModel<UserIdMapper> _nullUserIdMapperCacheModel = new NullCacheModel();
1878
1879 private static class NullCacheModel implements CacheModel<UserIdMapper>,
1880 MVCCModel {
1881 @Override
1882 public long getMvccVersion() {
1883 return -1;
1884 }
1885
1886 @Override
1887 public void setMvccVersion(long mvccVersion) {
1888 }
1889
1890 @Override
1891 public UserIdMapper toEntityModel() {
1892 return _nullUserIdMapper;
1893 }
1894 }
1895 }