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