1
22
23 package com.liferay.portal.service.persistence;
24
25 import com.liferay.portal.NoSuchUserIdMapperException;
26 import com.liferay.portal.SystemException;
27 import com.liferay.portal.kernel.annotation.BeanReference;
28 import com.liferay.portal.kernel.cache.CacheRegistry;
29 import com.liferay.portal.kernel.dao.orm.DynamicQuery;
30 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
31 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
32 import com.liferay.portal.kernel.dao.orm.FinderPath;
33 import com.liferay.portal.kernel.dao.orm.Query;
34 import com.liferay.portal.kernel.dao.orm.QueryPos;
35 import com.liferay.portal.kernel.dao.orm.QueryUtil;
36 import com.liferay.portal.kernel.dao.orm.Session;
37 import com.liferay.portal.kernel.log.Log;
38 import com.liferay.portal.kernel.log.LogFactoryUtil;
39 import com.liferay.portal.kernel.util.GetterUtil;
40 import com.liferay.portal.kernel.util.OrderByComparator;
41 import com.liferay.portal.kernel.util.StringPool;
42 import com.liferay.portal.kernel.util.StringUtil;
43 import com.liferay.portal.kernel.util.Validator;
44 import com.liferay.portal.model.ModelListener;
45 import com.liferay.portal.model.UserIdMapper;
46 import com.liferay.portal.model.impl.UserIdMapperImpl;
47 import com.liferay.portal.model.impl.UserIdMapperModelImpl;
48 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
49
50 import java.util.ArrayList;
51 import java.util.Collections;
52 import java.util.List;
53
54
60 public class UserIdMapperPersistenceImpl extends BasePersistenceImpl
61 implements UserIdMapperPersistence {
62 public static final String FINDER_CLASS_NAME_ENTITY = UserIdMapperImpl.class.getName();
63 public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
64 ".List";
65 public static final FinderPath FINDER_PATH_FIND_BY_USERID = new FinderPath(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
66 UserIdMapperModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
67 "findByUserId", new String[] { Long.class.getName() });
68 public static final FinderPath FINDER_PATH_FIND_BY_OBC_USERID = new FinderPath(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
69 UserIdMapperModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
70 "findByUserId",
71 new String[] {
72 Long.class.getName(),
73
74 "java.lang.Integer", "java.lang.Integer",
75 "com.liferay.portal.kernel.util.OrderByComparator"
76 });
77 public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
78 UserIdMapperModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
79 "countByUserId", new String[] { Long.class.getName() });
80 public static final FinderPath FINDER_PATH_FETCH_BY_U_T = new FinderPath(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
81 UserIdMapperModelImpl.FINDER_CACHE_ENABLED,
82 FINDER_CLASS_NAME_ENTITY, "fetchByU_T",
83 new String[] { Long.class.getName(), String.class.getName() });
84 public static final FinderPath FINDER_PATH_COUNT_BY_U_T = new FinderPath(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
85 UserIdMapperModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
86 "countByU_T",
87 new String[] { Long.class.getName(), String.class.getName() });
88 public static final FinderPath FINDER_PATH_FETCH_BY_T_E = new FinderPath(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
89 UserIdMapperModelImpl.FINDER_CACHE_ENABLED,
90 FINDER_CLASS_NAME_ENTITY, "fetchByT_E",
91 new String[] { String.class.getName(), String.class.getName() });
92 public static final FinderPath FINDER_PATH_COUNT_BY_T_E = new FinderPath(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
93 UserIdMapperModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
94 "countByT_E",
95 new String[] { String.class.getName(), String.class.getName() });
96 public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
97 UserIdMapperModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
98 "findAll", new String[0]);
99 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
100 UserIdMapperModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
101 "countAll", new String[0]);
102
103 public void cacheResult(UserIdMapper userIdMapper) {
104 EntityCacheUtil.putResult(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
105 UserIdMapperImpl.class, userIdMapper.getPrimaryKey(), userIdMapper);
106
107 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T,
108 new Object[] {
109 new Long(userIdMapper.getUserId()),
110
111 userIdMapper.getType()
112 }, userIdMapper);
113
114 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_E,
115 new Object[] {
116 userIdMapper.getType(),
117
118 userIdMapper.getExternalUserId()
119 }, userIdMapper);
120 }
121
122 public void cacheResult(List<UserIdMapper> userIdMappers) {
123 for (UserIdMapper userIdMapper : userIdMappers) {
124 if (EntityCacheUtil.getResult(
125 UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
126 UserIdMapperImpl.class, userIdMapper.getPrimaryKey(),
127 this) == null) {
128 cacheResult(userIdMapper);
129 }
130 }
131 }
132
133 public void clearCache() {
134 CacheRegistry.clear(UserIdMapperImpl.class.getName());
135 EntityCacheUtil.clearCache(UserIdMapperImpl.class.getName());
136 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
137 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
138 }
139
140 public UserIdMapper create(long userIdMapperId) {
141 UserIdMapper userIdMapper = new UserIdMapperImpl();
142
143 userIdMapper.setNew(true);
144 userIdMapper.setPrimaryKey(userIdMapperId);
145
146 return userIdMapper;
147 }
148
149 public UserIdMapper remove(long userIdMapperId)
150 throws NoSuchUserIdMapperException, SystemException {
151 Session session = null;
152
153 try {
154 session = openSession();
155
156 UserIdMapper userIdMapper = (UserIdMapper)session.get(UserIdMapperImpl.class,
157 new Long(userIdMapperId));
158
159 if (userIdMapper == null) {
160 if (_log.isWarnEnabled()) {
161 _log.warn("No UserIdMapper exists with the primary key " +
162 userIdMapperId);
163 }
164
165 throw new NoSuchUserIdMapperException(
166 "No UserIdMapper exists with the primary key " +
167 userIdMapperId);
168 }
169
170 return remove(userIdMapper);
171 }
172 catch (NoSuchUserIdMapperException nsee) {
173 throw nsee;
174 }
175 catch (Exception e) {
176 throw processException(e);
177 }
178 finally {
179 closeSession(session);
180 }
181 }
182
183 public UserIdMapper remove(UserIdMapper userIdMapper)
184 throws SystemException {
185 for (ModelListener<UserIdMapper> listener : listeners) {
186 listener.onBeforeRemove(userIdMapper);
187 }
188
189 userIdMapper = removeImpl(userIdMapper);
190
191 for (ModelListener<UserIdMapper> listener : listeners) {
192 listener.onAfterRemove(userIdMapper);
193 }
194
195 return userIdMapper;
196 }
197
198 protected UserIdMapper removeImpl(UserIdMapper userIdMapper)
199 throws SystemException {
200 Session session = null;
201
202 try {
203 session = openSession();
204
205 if (userIdMapper.isCachedModel() || BatchSessionUtil.isEnabled()) {
206 Object staleObject = session.get(UserIdMapperImpl.class,
207 userIdMapper.getPrimaryKeyObj());
208
209 if (staleObject != null) {
210 session.evict(staleObject);
211 }
212 }
213
214 session.delete(userIdMapper);
215
216 session.flush();
217 }
218 catch (Exception e) {
219 throw processException(e);
220 }
221 finally {
222 closeSession(session);
223 }
224
225 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
226
227 UserIdMapperModelImpl userIdMapperModelImpl = (UserIdMapperModelImpl)userIdMapper;
228
229 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_T,
230 new Object[] {
231 new Long(userIdMapperModelImpl.getOriginalUserId()),
232
233 userIdMapperModelImpl.getOriginalType()
234 });
235
236 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_T_E,
237 new Object[] {
238 userIdMapperModelImpl.getOriginalType(),
239
240 userIdMapperModelImpl.getOriginalExternalUserId()
241 });
242
243 EntityCacheUtil.removeResult(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
244 UserIdMapperImpl.class, userIdMapper.getPrimaryKey());
245
246 return userIdMapper;
247 }
248
249
252 public UserIdMapper update(UserIdMapper userIdMapper)
253 throws SystemException {
254 if (_log.isWarnEnabled()) {
255 _log.warn(
256 "Using the deprecated update(UserIdMapper userIdMapper) method. Use update(UserIdMapper userIdMapper, boolean merge) instead.");
257 }
258
259 return update(userIdMapper, false);
260 }
261
262
275 public UserIdMapper update(UserIdMapper userIdMapper, boolean merge)
276 throws SystemException {
277 boolean isNew = userIdMapper.isNew();
278
279 for (ModelListener<UserIdMapper> listener : listeners) {
280 if (isNew) {
281 listener.onBeforeCreate(userIdMapper);
282 }
283 else {
284 listener.onBeforeUpdate(userIdMapper);
285 }
286 }
287
288 userIdMapper = updateImpl(userIdMapper, merge);
289
290 for (ModelListener<UserIdMapper> listener : listeners) {
291 if (isNew) {
292 listener.onAfterCreate(userIdMapper);
293 }
294 else {
295 listener.onAfterUpdate(userIdMapper);
296 }
297 }
298
299 return userIdMapper;
300 }
301
302 public UserIdMapper updateImpl(
303 com.liferay.portal.model.UserIdMapper userIdMapper, boolean merge)
304 throws SystemException {
305 boolean isNew = userIdMapper.isNew();
306
307 UserIdMapperModelImpl userIdMapperModelImpl = (UserIdMapperModelImpl)userIdMapper;
308
309 Session session = null;
310
311 try {
312 session = openSession();
313
314 BatchSessionUtil.update(session, userIdMapper, merge);
315
316 userIdMapper.setNew(false);
317 }
318 catch (Exception e) {
319 throw processException(e);
320 }
321 finally {
322 closeSession(session);
323 }
324
325 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
326
327 EntityCacheUtil.putResult(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
328 UserIdMapperImpl.class, userIdMapper.getPrimaryKey(), userIdMapper);
329
330 if (!isNew &&
331 ((userIdMapper.getUserId() != userIdMapperModelImpl.getOriginalUserId()) ||
332 !Validator.equals(userIdMapper.getType(),
333 userIdMapperModelImpl.getOriginalType()))) {
334 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_T,
335 new Object[] {
336 new Long(userIdMapperModelImpl.getOriginalUserId()),
337
338 userIdMapperModelImpl.getOriginalType()
339 });
340 }
341
342 if (isNew ||
343 ((userIdMapper.getUserId() != userIdMapperModelImpl.getOriginalUserId()) ||
344 !Validator.equals(userIdMapper.getType(),
345 userIdMapperModelImpl.getOriginalType()))) {
346 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T,
347 new Object[] {
348 new Long(userIdMapper.getUserId()),
349
350 userIdMapper.getType()
351 }, userIdMapper);
352 }
353
354 if (!isNew &&
355 (!Validator.equals(userIdMapper.getType(),
356 userIdMapperModelImpl.getOriginalType()) ||
357 !Validator.equals(userIdMapper.getExternalUserId(),
358 userIdMapperModelImpl.getOriginalExternalUserId()))) {
359 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_T_E,
360 new Object[] {
361 userIdMapperModelImpl.getOriginalType(),
362
363 userIdMapperModelImpl.getOriginalExternalUserId()
364 });
365 }
366
367 if (isNew ||
368 (!Validator.equals(userIdMapper.getType(),
369 userIdMapperModelImpl.getOriginalType()) ||
370 !Validator.equals(userIdMapper.getExternalUserId(),
371 userIdMapperModelImpl.getOriginalExternalUserId()))) {
372 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_E,
373 new Object[] {
374 userIdMapper.getType(),
375
376 userIdMapper.getExternalUserId()
377 }, userIdMapper);
378 }
379
380 return userIdMapper;
381 }
382
383 public UserIdMapper findByPrimaryKey(long userIdMapperId)
384 throws NoSuchUserIdMapperException, SystemException {
385 UserIdMapper userIdMapper = fetchByPrimaryKey(userIdMapperId);
386
387 if (userIdMapper == null) {
388 if (_log.isWarnEnabled()) {
389 _log.warn("No UserIdMapper exists with the primary key " +
390 userIdMapperId);
391 }
392
393 throw new NoSuchUserIdMapperException(
394 "No UserIdMapper exists with the primary key " +
395 userIdMapperId);
396 }
397
398 return userIdMapper;
399 }
400
401 public UserIdMapper fetchByPrimaryKey(long userIdMapperId)
402 throws SystemException {
403 UserIdMapper userIdMapper = (UserIdMapper)EntityCacheUtil.getResult(UserIdMapperModelImpl.ENTITY_CACHE_ENABLED,
404 UserIdMapperImpl.class, userIdMapperId, this);
405
406 if (userIdMapper == null) {
407 Session session = null;
408
409 try {
410 session = openSession();
411
412 userIdMapper = (UserIdMapper)session.get(UserIdMapperImpl.class,
413 new Long(userIdMapperId));
414 }
415 catch (Exception e) {
416 throw processException(e);
417 }
418 finally {
419 if (userIdMapper != null) {
420 cacheResult(userIdMapper);
421 }
422
423 closeSession(session);
424 }
425 }
426
427 return userIdMapper;
428 }
429
430 public List<UserIdMapper> findByUserId(long userId)
431 throws SystemException {
432 Object[] finderArgs = new Object[] { new Long(userId) };
433
434 List<UserIdMapper> list = (List<UserIdMapper>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_USERID,
435 finderArgs, this);
436
437 if (list == null) {
438 Session session = null;
439
440 try {
441 session = openSession();
442
443 StringBuilder query = new StringBuilder();
444
445 query.append(
446 "FROM com.liferay.portal.model.UserIdMapper WHERE ");
447
448 query.append("userId = ?");
449
450 query.append(" ");
451
452 Query q = session.createQuery(query.toString());
453
454 QueryPos qPos = QueryPos.getInstance(q);
455
456 qPos.add(userId);
457
458 list = q.list();
459 }
460 catch (Exception e) {
461 throw processException(e);
462 }
463 finally {
464 if (list == null) {
465 list = new ArrayList<UserIdMapper>();
466 }
467
468 cacheResult(list);
469
470 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_USERID,
471 finderArgs, list);
472
473 closeSession(session);
474 }
475 }
476
477 return list;
478 }
479
480 public List<UserIdMapper> findByUserId(long userId, int start, int end)
481 throws SystemException {
482 return findByUserId(userId, start, end, null);
483 }
484
485 public List<UserIdMapper> findByUserId(long userId, int start, int end,
486 OrderByComparator obc) throws SystemException {
487 Object[] finderArgs = new Object[] {
488 new Long(userId),
489
490 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
491 };
492
493 List<UserIdMapper> list = (List<UserIdMapper>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_USERID,
494 finderArgs, this);
495
496 if (list == null) {
497 Session session = null;
498
499 try {
500 session = openSession();
501
502 StringBuilder query = new StringBuilder();
503
504 query.append(
505 "FROM com.liferay.portal.model.UserIdMapper WHERE ");
506
507 query.append("userId = ?");
508
509 query.append(" ");
510
511 if (obc != null) {
512 query.append("ORDER BY ");
513 query.append(obc.getOrderBy());
514 }
515
516 Query q = session.createQuery(query.toString());
517
518 QueryPos qPos = QueryPos.getInstance(q);
519
520 qPos.add(userId);
521
522 list = (List<UserIdMapper>)QueryUtil.list(q, getDialect(),
523 start, end);
524 }
525 catch (Exception e) {
526 throw processException(e);
527 }
528 finally {
529 if (list == null) {
530 list = new ArrayList<UserIdMapper>();
531 }
532
533 cacheResult(list);
534
535 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_USERID,
536 finderArgs, list);
537
538 closeSession(session);
539 }
540 }
541
542 return list;
543 }
544
545 public UserIdMapper findByUserId_First(long userId, OrderByComparator obc)
546 throws NoSuchUserIdMapperException, SystemException {
547 List<UserIdMapper> list = findByUserId(userId, 0, 1, obc);
548
549 if (list.isEmpty()) {
550 StringBuilder msg = new StringBuilder();
551
552 msg.append("No UserIdMapper exists with the key {");
553
554 msg.append("userId=" + userId);
555
556 msg.append(StringPool.CLOSE_CURLY_BRACE);
557
558 throw new NoSuchUserIdMapperException(msg.toString());
559 }
560 else {
561 return list.get(0);
562 }
563 }
564
565 public UserIdMapper findByUserId_Last(long userId, OrderByComparator obc)
566 throws NoSuchUserIdMapperException, SystemException {
567 int count = countByUserId(userId);
568
569 List<UserIdMapper> list = findByUserId(userId, count - 1, count, obc);
570
571 if (list.isEmpty()) {
572 StringBuilder msg = new StringBuilder();
573
574 msg.append("No UserIdMapper exists with the key {");
575
576 msg.append("userId=" + userId);
577
578 msg.append(StringPool.CLOSE_CURLY_BRACE);
579
580 throw new NoSuchUserIdMapperException(msg.toString());
581 }
582 else {
583 return list.get(0);
584 }
585 }
586
587 public UserIdMapper[] findByUserId_PrevAndNext(long userIdMapperId,
588 long userId, OrderByComparator obc)
589 throws NoSuchUserIdMapperException, SystemException {
590 UserIdMapper userIdMapper = findByPrimaryKey(userIdMapperId);
591
592 int count = countByUserId(userId);
593
594 Session session = null;
595
596 try {
597 session = openSession();
598
599 StringBuilder query = new StringBuilder();
600
601 query.append("FROM com.liferay.portal.model.UserIdMapper WHERE ");
602
603 query.append("userId = ?");
604
605 query.append(" ");
606
607 if (obc != null) {
608 query.append("ORDER BY ");
609 query.append(obc.getOrderBy());
610 }
611
612 Query q = session.createQuery(query.toString());
613
614 QueryPos qPos = QueryPos.getInstance(q);
615
616 qPos.add(userId);
617
618 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
619 userIdMapper);
620
621 UserIdMapper[] array = new UserIdMapperImpl[3];
622
623 array[0] = (UserIdMapper)objArray[0];
624 array[1] = (UserIdMapper)objArray[1];
625 array[2] = (UserIdMapper)objArray[2];
626
627 return array;
628 }
629 catch (Exception e) {
630 throw processException(e);
631 }
632 finally {
633 closeSession(session);
634 }
635 }
636
637 public UserIdMapper findByU_T(long userId, String type)
638 throws NoSuchUserIdMapperException, SystemException {
639 UserIdMapper userIdMapper = fetchByU_T(userId, type);
640
641 if (userIdMapper == null) {
642 StringBuilder msg = new StringBuilder();
643
644 msg.append("No UserIdMapper exists with the key {");
645
646 msg.append("userId=" + userId);
647
648 msg.append(", ");
649 msg.append("type=" + type);
650
651 msg.append(StringPool.CLOSE_CURLY_BRACE);
652
653 if (_log.isWarnEnabled()) {
654 _log.warn(msg.toString());
655 }
656
657 throw new NoSuchUserIdMapperException(msg.toString());
658 }
659
660 return userIdMapper;
661 }
662
663 public UserIdMapper fetchByU_T(long userId, String type)
664 throws SystemException {
665 return fetchByU_T(userId, type, true);
666 }
667
668 public UserIdMapper fetchByU_T(long userId, String type,
669 boolean retrieveFromCache) throws SystemException {
670 Object[] finderArgs = new Object[] { new Long(userId), type };
671
672 Object result = null;
673
674 if (retrieveFromCache) {
675 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_U_T,
676 finderArgs, this);
677 }
678
679 if (result == null) {
680 Session session = null;
681
682 try {
683 session = openSession();
684
685 StringBuilder query = new StringBuilder();
686
687 query.append(
688 "FROM com.liferay.portal.model.UserIdMapper WHERE ");
689
690 query.append("userId = ?");
691
692 query.append(" AND ");
693
694 if (type == null) {
695 query.append("type_ IS NULL");
696 }
697 else {
698 query.append("type_ = ?");
699 }
700
701 query.append(" ");
702
703 Query q = session.createQuery(query.toString());
704
705 QueryPos qPos = QueryPos.getInstance(q);
706
707 qPos.add(userId);
708
709 if (type != null) {
710 qPos.add(type);
711 }
712
713 List<UserIdMapper> list = q.list();
714
715 result = list;
716
717 UserIdMapper userIdMapper = null;
718
719 if (list.isEmpty()) {
720 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T,
721 finderArgs, list);
722 }
723 else {
724 userIdMapper = list.get(0);
725
726 cacheResult(userIdMapper);
727
728 if ((userIdMapper.getUserId() != userId) ||
729 (userIdMapper.getType() == null) ||
730 !userIdMapper.getType().equals(type)) {
731 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T,
732 finderArgs, userIdMapper);
733 }
734 }
735
736 return userIdMapper;
737 }
738 catch (Exception e) {
739 throw processException(e);
740 }
741 finally {
742 if (result == null) {
743 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T,
744 finderArgs, new ArrayList<UserIdMapper>());
745 }
746
747 closeSession(session);
748 }
749 }
750 else {
751 if (result instanceof List) {
752 return null;
753 }
754 else {
755 return (UserIdMapper)result;
756 }
757 }
758 }
759
760 public UserIdMapper findByT_E(String type, String externalUserId)
761 throws NoSuchUserIdMapperException, SystemException {
762 UserIdMapper userIdMapper = fetchByT_E(type, externalUserId);
763
764 if (userIdMapper == null) {
765 StringBuilder msg = new StringBuilder();
766
767 msg.append("No UserIdMapper exists with the key {");
768
769 msg.append("type=" + type);
770
771 msg.append(", ");
772 msg.append("externalUserId=" + externalUserId);
773
774 msg.append(StringPool.CLOSE_CURLY_BRACE);
775
776 if (_log.isWarnEnabled()) {
777 _log.warn(msg.toString());
778 }
779
780 throw new NoSuchUserIdMapperException(msg.toString());
781 }
782
783 return userIdMapper;
784 }
785
786 public UserIdMapper fetchByT_E(String type, String externalUserId)
787 throws SystemException {
788 return fetchByT_E(type, externalUserId, true);
789 }
790
791 public UserIdMapper fetchByT_E(String type, String externalUserId,
792 boolean retrieveFromCache) throws SystemException {
793 Object[] finderArgs = new Object[] { type, externalUserId };
794
795 Object result = null;
796
797 if (retrieveFromCache) {
798 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_T_E,
799 finderArgs, this);
800 }
801
802 if (result == null) {
803 Session session = null;
804
805 try {
806 session = openSession();
807
808 StringBuilder query = new StringBuilder();
809
810 query.append(
811 "FROM com.liferay.portal.model.UserIdMapper WHERE ");
812
813 if (type == null) {
814 query.append("type_ IS NULL");
815 }
816 else {
817 query.append("type_ = ?");
818 }
819
820 query.append(" AND ");
821
822 if (externalUserId == null) {
823 query.append("externalUserId IS NULL");
824 }
825 else {
826 query.append("externalUserId = ?");
827 }
828
829 query.append(" ");
830
831 Query q = session.createQuery(query.toString());
832
833 QueryPos qPos = QueryPos.getInstance(q);
834
835 if (type != null) {
836 qPos.add(type);
837 }
838
839 if (externalUserId != null) {
840 qPos.add(externalUserId);
841 }
842
843 List<UserIdMapper> list = q.list();
844
845 result = list;
846
847 UserIdMapper userIdMapper = null;
848
849 if (list.isEmpty()) {
850 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_E,
851 finderArgs, list);
852 }
853 else {
854 userIdMapper = list.get(0);
855
856 cacheResult(userIdMapper);
857
858 if ((userIdMapper.getType() == null) ||
859 !userIdMapper.getType().equals(type) ||
860 (userIdMapper.getExternalUserId() == null) ||
861 !userIdMapper.getExternalUserId()
862 .equals(externalUserId)) {
863 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_E,
864 finderArgs, userIdMapper);
865 }
866 }
867
868 return userIdMapper;
869 }
870 catch (Exception e) {
871 throw processException(e);
872 }
873 finally {
874 if (result == null) {
875 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_E,
876 finderArgs, new ArrayList<UserIdMapper>());
877 }
878
879 closeSession(session);
880 }
881 }
882 else {
883 if (result instanceof List) {
884 return null;
885 }
886 else {
887 return (UserIdMapper)result;
888 }
889 }
890 }
891
892 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
893 throws SystemException {
894 Session session = null;
895
896 try {
897 session = openSession();
898
899 dynamicQuery.compile(session);
900
901 return dynamicQuery.list();
902 }
903 catch (Exception e) {
904 throw processException(e);
905 }
906 finally {
907 closeSession(session);
908 }
909 }
910
911 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
912 int start, int end) throws SystemException {
913 Session session = null;
914
915 try {
916 session = openSession();
917
918 dynamicQuery.setLimit(start, end);
919
920 dynamicQuery.compile(session);
921
922 return dynamicQuery.list();
923 }
924 catch (Exception e) {
925 throw processException(e);
926 }
927 finally {
928 closeSession(session);
929 }
930 }
931
932 public List<UserIdMapper> findAll() throws SystemException {
933 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
934 }
935
936 public List<UserIdMapper> findAll(int start, int end)
937 throws SystemException {
938 return findAll(start, end, null);
939 }
940
941 public List<UserIdMapper> findAll(int start, int end, OrderByComparator obc)
942 throws SystemException {
943 Object[] finderArgs = new Object[] {
944 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
945 };
946
947 List<UserIdMapper> list = (List<UserIdMapper>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
948 finderArgs, this);
949
950 if (list == null) {
951 Session session = null;
952
953 try {
954 session = openSession();
955
956 StringBuilder query = new StringBuilder();
957
958 query.append("FROM com.liferay.portal.model.UserIdMapper ");
959
960 if (obc != null) {
961 query.append("ORDER BY ");
962 query.append(obc.getOrderBy());
963 }
964
965 Query q = session.createQuery(query.toString());
966
967 if (obc == null) {
968 list = (List<UserIdMapper>)QueryUtil.list(q, getDialect(),
969 start, end, false);
970
971 Collections.sort(list);
972 }
973 else {
974 list = (List<UserIdMapper>)QueryUtil.list(q, getDialect(),
975 start, end);
976 }
977 }
978 catch (Exception e) {
979 throw processException(e);
980 }
981 finally {
982 if (list == null) {
983 list = new ArrayList<UserIdMapper>();
984 }
985
986 cacheResult(list);
987
988 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
989
990 closeSession(session);
991 }
992 }
993
994 return list;
995 }
996
997 public void removeByUserId(long userId) throws SystemException {
998 for (UserIdMapper userIdMapper : findByUserId(userId)) {
999 remove(userIdMapper);
1000 }
1001 }
1002
1003 public void removeByU_T(long userId, String type)
1004 throws NoSuchUserIdMapperException, SystemException {
1005 UserIdMapper userIdMapper = findByU_T(userId, type);
1006
1007 remove(userIdMapper);
1008 }
1009
1010 public void removeByT_E(String type, String externalUserId)
1011 throws NoSuchUserIdMapperException, SystemException {
1012 UserIdMapper userIdMapper = findByT_E(type, externalUserId);
1013
1014 remove(userIdMapper);
1015 }
1016
1017 public void removeAll() throws SystemException {
1018 for (UserIdMapper userIdMapper : findAll()) {
1019 remove(userIdMapper);
1020 }
1021 }
1022
1023 public int countByUserId(long userId) throws SystemException {
1024 Object[] finderArgs = new Object[] { new Long(userId) };
1025
1026 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID,
1027 finderArgs, this);
1028
1029 if (count == null) {
1030 Session session = null;
1031
1032 try {
1033 session = openSession();
1034
1035 StringBuilder query = new StringBuilder();
1036
1037 query.append("SELECT COUNT(*) ");
1038 query.append(
1039 "FROM com.liferay.portal.model.UserIdMapper WHERE ");
1040
1041 query.append("userId = ?");
1042
1043 query.append(" ");
1044
1045 Query q = session.createQuery(query.toString());
1046
1047 QueryPos qPos = QueryPos.getInstance(q);
1048
1049 qPos.add(userId);
1050
1051 count = (Long)q.uniqueResult();
1052 }
1053 catch (Exception e) {
1054 throw processException(e);
1055 }
1056 finally {
1057 if (count == null) {
1058 count = Long.valueOf(0);
1059 }
1060
1061 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID,
1062 finderArgs, count);
1063
1064 closeSession(session);
1065 }
1066 }
1067
1068 return count.intValue();
1069 }
1070
1071 public int countByU_T(long userId, String type) throws SystemException {
1072 Object[] finderArgs = new Object[] { new Long(userId), type };
1073
1074 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U_T,
1075 finderArgs, this);
1076
1077 if (count == null) {
1078 Session session = null;
1079
1080 try {
1081 session = openSession();
1082
1083 StringBuilder query = new StringBuilder();
1084
1085 query.append("SELECT COUNT(*) ");
1086 query.append(
1087 "FROM com.liferay.portal.model.UserIdMapper WHERE ");
1088
1089 query.append("userId = ?");
1090
1091 query.append(" AND ");
1092
1093 if (type == null) {
1094 query.append("type_ IS NULL");
1095 }
1096 else {
1097 query.append("type_ = ?");
1098 }
1099
1100 query.append(" ");
1101
1102 Query q = session.createQuery(query.toString());
1103
1104 QueryPos qPos = QueryPos.getInstance(q);
1105
1106 qPos.add(userId);
1107
1108 if (type != null) {
1109 qPos.add(type);
1110 }
1111
1112 count = (Long)q.uniqueResult();
1113 }
1114 catch (Exception e) {
1115 throw processException(e);
1116 }
1117 finally {
1118 if (count == null) {
1119 count = Long.valueOf(0);
1120 }
1121
1122 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_T, finderArgs,
1123 count);
1124
1125 closeSession(session);
1126 }
1127 }
1128
1129 return count.intValue();
1130 }
1131
1132 public int countByT_E(String type, String externalUserId)
1133 throws SystemException {
1134 Object[] finderArgs = new Object[] { type, externalUserId };
1135
1136 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_T_E,
1137 finderArgs, this);
1138
1139 if (count == null) {
1140 Session session = null;
1141
1142 try {
1143 session = openSession();
1144
1145 StringBuilder query = new StringBuilder();
1146
1147 query.append("SELECT COUNT(*) ");
1148 query.append(
1149 "FROM com.liferay.portal.model.UserIdMapper WHERE ");
1150
1151 if (type == null) {
1152 query.append("type_ IS NULL");
1153 }
1154 else {
1155 query.append("type_ = ?");
1156 }
1157
1158 query.append(" AND ");
1159
1160 if (externalUserId == null) {
1161 query.append("externalUserId IS NULL");
1162 }
1163 else {
1164 query.append("externalUserId = ?");
1165 }
1166
1167 query.append(" ");
1168
1169 Query q = session.createQuery(query.toString());
1170
1171 QueryPos qPos = QueryPos.getInstance(q);
1172
1173 if (type != null) {
1174 qPos.add(type);
1175 }
1176
1177 if (externalUserId != null) {
1178 qPos.add(externalUserId);
1179 }
1180
1181 count = (Long)q.uniqueResult();
1182 }
1183 catch (Exception e) {
1184 throw processException(e);
1185 }
1186 finally {
1187 if (count == null) {
1188 count = Long.valueOf(0);
1189 }
1190
1191 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_E, finderArgs,
1192 count);
1193
1194 closeSession(session);
1195 }
1196 }
1197
1198 return count.intValue();
1199 }
1200
1201 public int countAll() throws SystemException {
1202 Object[] finderArgs = new Object[0];
1203
1204 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1205 finderArgs, this);
1206
1207 if (count == null) {
1208 Session session = null;
1209
1210 try {
1211 session = openSession();
1212
1213 Query q = session.createQuery(
1214 "SELECT COUNT(*) FROM com.liferay.portal.model.UserIdMapper");
1215
1216 count = (Long)q.uniqueResult();
1217 }
1218 catch (Exception e) {
1219 throw processException(e);
1220 }
1221 finally {
1222 if (count == null) {
1223 count = Long.valueOf(0);
1224 }
1225
1226 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1227 count);
1228
1229 closeSession(session);
1230 }
1231 }
1232
1233 return count.intValue();
1234 }
1235
1236 public void afterPropertiesSet() {
1237 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1238 com.liferay.portal.util.PropsUtil.get(
1239 "value.object.listener.com.liferay.portal.model.UserIdMapper")));
1240
1241 if (listenerClassNames.length > 0) {
1242 try {
1243 List<ModelListener<UserIdMapper>> listenersList = new ArrayList<ModelListener<UserIdMapper>>();
1244
1245 for (String listenerClassName : listenerClassNames) {
1246 listenersList.add((ModelListener<UserIdMapper>)Class.forName(
1247 listenerClassName).newInstance());
1248 }
1249
1250 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1251 }
1252 catch (Exception e) {
1253 _log.error(e);
1254 }
1255 }
1256 }
1257
1258 @BeanReference(name = "com.liferay.portal.service.persistence.AccountPersistence.impl")
1259 protected com.liferay.portal.service.persistence.AccountPersistence accountPersistence;
1260 @BeanReference(name = "com.liferay.portal.service.persistence.AddressPersistence.impl")
1261 protected com.liferay.portal.service.persistence.AddressPersistence addressPersistence;
1262 @BeanReference(name = "com.liferay.portal.service.persistence.BrowserTrackerPersistence.impl")
1263 protected com.liferay.portal.service.persistence.BrowserTrackerPersistence browserTrackerPersistence;
1264 @BeanReference(name = "com.liferay.portal.service.persistence.ClassNamePersistence.impl")
1265 protected com.liferay.portal.service.persistence.ClassNamePersistence classNamePersistence;
1266 @BeanReference(name = "com.liferay.portal.service.persistence.CompanyPersistence.impl")
1267 protected com.liferay.portal.service.persistence.CompanyPersistence companyPersistence;
1268 @BeanReference(name = "com.liferay.portal.service.persistence.ContactPersistence.impl")
1269 protected com.liferay.portal.service.persistence.ContactPersistence contactPersistence;
1270 @BeanReference(name = "com.liferay.portal.service.persistence.CountryPersistence.impl")
1271 protected com.liferay.portal.service.persistence.CountryPersistence countryPersistence;
1272 @BeanReference(name = "com.liferay.portal.service.persistence.EmailAddressPersistence.impl")
1273 protected com.liferay.portal.service.persistence.EmailAddressPersistence emailAddressPersistence;
1274 @BeanReference(name = "com.liferay.portal.service.persistence.GroupPersistence.impl")
1275 protected com.liferay.portal.service.persistence.GroupPersistence groupPersistence;
1276 @BeanReference(name = "com.liferay.portal.service.persistence.ImagePersistence.impl")
1277 protected com.liferay.portal.service.persistence.ImagePersistence imagePersistence;
1278 @BeanReference(name = "com.liferay.portal.service.persistence.LayoutPersistence.impl")
1279 protected com.liferay.portal.service.persistence.LayoutPersistence layoutPersistence;
1280 @BeanReference(name = "com.liferay.portal.service.persistence.LayoutSetPersistence.impl")
1281 protected com.liferay.portal.service.persistence.LayoutSetPersistence layoutSetPersistence;
1282 @BeanReference(name = "com.liferay.portal.service.persistence.ListTypePersistence.impl")
1283 protected com.liferay.portal.service.persistence.ListTypePersistence listTypePersistence;
1284 @BeanReference(name = "com.liferay.portal.service.persistence.MembershipRequestPersistence.impl")
1285 protected com.liferay.portal.service.persistence.MembershipRequestPersistence membershipRequestPersistence;
1286 @BeanReference(name = "com.liferay.portal.service.persistence.OrganizationPersistence.impl")
1287 protected com.liferay.portal.service.persistence.OrganizationPersistence organizationPersistence;
1288 @BeanReference(name = "com.liferay.portal.service.persistence.OrgGroupPermissionPersistence.impl")
1289 protected com.liferay.portal.service.persistence.OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1290 @BeanReference(name = "com.liferay.portal.service.persistence.OrgGroupRolePersistence.impl")
1291 protected com.liferay.portal.service.persistence.OrgGroupRolePersistence orgGroupRolePersistence;
1292 @BeanReference(name = "com.liferay.portal.service.persistence.OrgLaborPersistence.impl")
1293 protected com.liferay.portal.service.persistence.OrgLaborPersistence orgLaborPersistence;
1294 @BeanReference(name = "com.liferay.portal.service.persistence.PasswordPolicyPersistence.impl")
1295 protected com.liferay.portal.service.persistence.PasswordPolicyPersistence passwordPolicyPersistence;
1296 @BeanReference(name = "com.liferay.portal.service.persistence.PasswordPolicyRelPersistence.impl")
1297 protected com.liferay.portal.service.persistence.PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1298 @BeanReference(name = "com.liferay.portal.service.persistence.PasswordTrackerPersistence.impl")
1299 protected com.liferay.portal.service.persistence.PasswordTrackerPersistence passwordTrackerPersistence;
1300 @BeanReference(name = "com.liferay.portal.service.persistence.PermissionPersistence.impl")
1301 protected com.liferay.portal.service.persistence.PermissionPersistence permissionPersistence;
1302 @BeanReference(name = "com.liferay.portal.service.persistence.PhonePersistence.impl")
1303 protected com.liferay.portal.service.persistence.PhonePersistence phonePersistence;
1304 @BeanReference(name = "com.liferay.portal.service.persistence.PluginSettingPersistence.impl")
1305 protected com.liferay.portal.service.persistence.PluginSettingPersistence pluginSettingPersistence;
1306 @BeanReference(name = "com.liferay.portal.service.persistence.PortletPersistence.impl")
1307 protected com.liferay.portal.service.persistence.PortletPersistence portletPersistence;
1308 @BeanReference(name = "com.liferay.portal.service.persistence.PortletItemPersistence.impl")
1309 protected com.liferay.portal.service.persistence.PortletItemPersistence portletItemPersistence;
1310 @BeanReference(name = "com.liferay.portal.service.persistence.PortletPreferencesPersistence.impl")
1311 protected com.liferay.portal.service.persistence.PortletPreferencesPersistence portletPreferencesPersistence;
1312 @BeanReference(name = "com.liferay.portal.service.persistence.RegionPersistence.impl")
1313 protected com.liferay.portal.service.persistence.RegionPersistence regionPersistence;
1314 @BeanReference(name = "com.liferay.portal.service.persistence.ReleasePersistence.impl")
1315 protected com.liferay.portal.service.persistence.ReleasePersistence releasePersistence;
1316 @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePersistence.impl")
1317 protected com.liferay.portal.service.persistence.ResourcePersistence resourcePersistence;
1318 @BeanReference(name = "com.liferay.portal.service.persistence.ResourceActionPersistence.impl")
1319 protected com.liferay.portal.service.persistence.ResourceActionPersistence resourceActionPersistence;
1320 @BeanReference(name = "com.liferay.portal.service.persistence.ResourceCodePersistence.impl")
1321 protected com.liferay.portal.service.persistence.ResourceCodePersistence resourceCodePersistence;
1322 @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePermissionPersistence.impl")
1323 protected com.liferay.portal.service.persistence.ResourcePermissionPersistence resourcePermissionPersistence;
1324 @BeanReference(name = "com.liferay.portal.service.persistence.RolePersistence.impl")
1325 protected com.liferay.portal.service.persistence.RolePersistence rolePersistence;
1326 @BeanReference(name = "com.liferay.portal.service.persistence.ServiceComponentPersistence.impl")
1327 protected com.liferay.portal.service.persistence.ServiceComponentPersistence serviceComponentPersistence;
1328 @BeanReference(name = "com.liferay.portal.service.persistence.ShardPersistence.impl")
1329 protected com.liferay.portal.service.persistence.ShardPersistence shardPersistence;
1330 @BeanReference(name = "com.liferay.portal.service.persistence.SubscriptionPersistence.impl")
1331 protected com.liferay.portal.service.persistence.SubscriptionPersistence subscriptionPersistence;
1332 @BeanReference(name = "com.liferay.portal.service.persistence.UserPersistence.impl")
1333 protected com.liferay.portal.service.persistence.UserPersistence userPersistence;
1334 @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupPersistence.impl")
1335 protected com.liferay.portal.service.persistence.UserGroupPersistence userGroupPersistence;
1336 @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupRolePersistence.impl")
1337 protected com.liferay.portal.service.persistence.UserGroupRolePersistence userGroupRolePersistence;
1338 @BeanReference(name = "com.liferay.portal.service.persistence.UserIdMapperPersistence.impl")
1339 protected com.liferay.portal.service.persistence.UserIdMapperPersistence userIdMapperPersistence;
1340 @BeanReference(name = "com.liferay.portal.service.persistence.UserTrackerPersistence.impl")
1341 protected com.liferay.portal.service.persistence.UserTrackerPersistence userTrackerPersistence;
1342 @BeanReference(name = "com.liferay.portal.service.persistence.UserTrackerPathPersistence.impl")
1343 protected com.liferay.portal.service.persistence.UserTrackerPathPersistence userTrackerPathPersistence;
1344 @BeanReference(name = "com.liferay.portal.service.persistence.WebDAVPropsPersistence.impl")
1345 protected com.liferay.portal.service.persistence.WebDAVPropsPersistence webDAVPropsPersistence;
1346 @BeanReference(name = "com.liferay.portal.service.persistence.WebsitePersistence.impl")
1347 protected com.liferay.portal.service.persistence.WebsitePersistence websitePersistence;
1348 private static Log _log = LogFactoryUtil.getLog(UserIdMapperPersistenceImpl.class);
1349}