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 "SELECT userIdMapper FROM UserIdMapper userIdMapper WHERE ");
447
448 query.append("userIdMapper.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 "SELECT userIdMapper FROM UserIdMapper userIdMapper WHERE ");
506
507 query.append("userIdMapper.userId = ?");
508
509 query.append(" ");
510
511 if (obc != null) {
512 query.append("ORDER BY ");
513
514 String[] orderByFields = obc.getOrderByFields();
515
516 for (int i = 0; i < orderByFields.length; i++) {
517 query.append("userIdMapper.");
518 query.append(orderByFields[i]);
519
520 if (obc.isAscending()) {
521 query.append(" ASC");
522 }
523 else {
524 query.append(" DESC");
525 }
526
527 if ((i + 1) < orderByFields.length) {
528 query.append(", ");
529 }
530 }
531 }
532
533 Query q = session.createQuery(query.toString());
534
535 QueryPos qPos = QueryPos.getInstance(q);
536
537 qPos.add(userId);
538
539 list = (List<UserIdMapper>)QueryUtil.list(q, getDialect(),
540 start, end);
541 }
542 catch (Exception e) {
543 throw processException(e);
544 }
545 finally {
546 if (list == null) {
547 list = new ArrayList<UserIdMapper>();
548 }
549
550 cacheResult(list);
551
552 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_USERID,
553 finderArgs, list);
554
555 closeSession(session);
556 }
557 }
558
559 return list;
560 }
561
562 public UserIdMapper findByUserId_First(long userId, OrderByComparator obc)
563 throws NoSuchUserIdMapperException, SystemException {
564 List<UserIdMapper> list = findByUserId(userId, 0, 1, obc);
565
566 if (list.isEmpty()) {
567 StringBuilder msg = new StringBuilder();
568
569 msg.append("No UserIdMapper exists with the key {");
570
571 msg.append("userId=" + userId);
572
573 msg.append(StringPool.CLOSE_CURLY_BRACE);
574
575 throw new NoSuchUserIdMapperException(msg.toString());
576 }
577 else {
578 return list.get(0);
579 }
580 }
581
582 public UserIdMapper findByUserId_Last(long userId, OrderByComparator obc)
583 throws NoSuchUserIdMapperException, SystemException {
584 int count = countByUserId(userId);
585
586 List<UserIdMapper> list = findByUserId(userId, count - 1, count, obc);
587
588 if (list.isEmpty()) {
589 StringBuilder msg = new StringBuilder();
590
591 msg.append("No UserIdMapper exists with the key {");
592
593 msg.append("userId=" + userId);
594
595 msg.append(StringPool.CLOSE_CURLY_BRACE);
596
597 throw new NoSuchUserIdMapperException(msg.toString());
598 }
599 else {
600 return list.get(0);
601 }
602 }
603
604 public UserIdMapper[] findByUserId_PrevAndNext(long userIdMapperId,
605 long userId, OrderByComparator obc)
606 throws NoSuchUserIdMapperException, SystemException {
607 UserIdMapper userIdMapper = findByPrimaryKey(userIdMapperId);
608
609 int count = countByUserId(userId);
610
611 Session session = null;
612
613 try {
614 session = openSession();
615
616 StringBuilder query = new StringBuilder();
617
618 query.append(
619 "SELECT userIdMapper FROM UserIdMapper userIdMapper WHERE ");
620
621 query.append("userIdMapper.userId = ?");
622
623 query.append(" ");
624
625 if (obc != null) {
626 query.append("ORDER BY ");
627
628 String[] orderByFields = obc.getOrderByFields();
629
630 for (int i = 0; i < orderByFields.length; i++) {
631 query.append("userIdMapper.");
632 query.append(orderByFields[i]);
633
634 if (obc.isAscending()) {
635 query.append(" ASC");
636 }
637 else {
638 query.append(" DESC");
639 }
640
641 if ((i + 1) < orderByFields.length) {
642 query.append(", ");
643 }
644 }
645 }
646
647 Query q = session.createQuery(query.toString());
648
649 QueryPos qPos = QueryPos.getInstance(q);
650
651 qPos.add(userId);
652
653 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
654 userIdMapper);
655
656 UserIdMapper[] array = new UserIdMapperImpl[3];
657
658 array[0] = (UserIdMapper)objArray[0];
659 array[1] = (UserIdMapper)objArray[1];
660 array[2] = (UserIdMapper)objArray[2];
661
662 return array;
663 }
664 catch (Exception e) {
665 throw processException(e);
666 }
667 finally {
668 closeSession(session);
669 }
670 }
671
672 public UserIdMapper findByU_T(long userId, String type)
673 throws NoSuchUserIdMapperException, SystemException {
674 UserIdMapper userIdMapper = fetchByU_T(userId, type);
675
676 if (userIdMapper == null) {
677 StringBuilder msg = new StringBuilder();
678
679 msg.append("No UserIdMapper exists with the key {");
680
681 msg.append("userId=" + userId);
682
683 msg.append(", ");
684 msg.append("type=" + type);
685
686 msg.append(StringPool.CLOSE_CURLY_BRACE);
687
688 if (_log.isWarnEnabled()) {
689 _log.warn(msg.toString());
690 }
691
692 throw new NoSuchUserIdMapperException(msg.toString());
693 }
694
695 return userIdMapper;
696 }
697
698 public UserIdMapper fetchByU_T(long userId, String type)
699 throws SystemException {
700 return fetchByU_T(userId, type, true);
701 }
702
703 public UserIdMapper fetchByU_T(long userId, String type,
704 boolean retrieveFromCache) throws SystemException {
705 Object[] finderArgs = new Object[] { new Long(userId), type };
706
707 Object result = null;
708
709 if (retrieveFromCache) {
710 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_U_T,
711 finderArgs, this);
712 }
713
714 if (result == null) {
715 Session session = null;
716
717 try {
718 session = openSession();
719
720 StringBuilder query = new StringBuilder();
721
722 query.append(
723 "SELECT userIdMapper FROM UserIdMapper userIdMapper WHERE ");
724
725 query.append("userIdMapper.userId = ?");
726
727 query.append(" AND ");
728
729 if (type == null) {
730 query.append("userIdMapper.type IS NULL");
731 }
732 else {
733 query.append("userIdMapper.type = ?");
734 }
735
736 query.append(" ");
737
738 Query q = session.createQuery(query.toString());
739
740 QueryPos qPos = QueryPos.getInstance(q);
741
742 qPos.add(userId);
743
744 if (type != null) {
745 qPos.add(type);
746 }
747
748 List<UserIdMapper> list = q.list();
749
750 result = list;
751
752 UserIdMapper userIdMapper = null;
753
754 if (list.isEmpty()) {
755 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T,
756 finderArgs, list);
757 }
758 else {
759 userIdMapper = list.get(0);
760
761 cacheResult(userIdMapper);
762
763 if ((userIdMapper.getUserId() != userId) ||
764 (userIdMapper.getType() == null) ||
765 !userIdMapper.getType().equals(type)) {
766 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T,
767 finderArgs, userIdMapper);
768 }
769 }
770
771 return userIdMapper;
772 }
773 catch (Exception e) {
774 throw processException(e);
775 }
776 finally {
777 if (result == null) {
778 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T,
779 finderArgs, new ArrayList<UserIdMapper>());
780 }
781
782 closeSession(session);
783 }
784 }
785 else {
786 if (result instanceof List) {
787 return null;
788 }
789 else {
790 return (UserIdMapper)result;
791 }
792 }
793 }
794
795 public UserIdMapper findByT_E(String type, String externalUserId)
796 throws NoSuchUserIdMapperException, SystemException {
797 UserIdMapper userIdMapper = fetchByT_E(type, externalUserId);
798
799 if (userIdMapper == null) {
800 StringBuilder msg = new StringBuilder();
801
802 msg.append("No UserIdMapper exists with the key {");
803
804 msg.append("type=" + type);
805
806 msg.append(", ");
807 msg.append("externalUserId=" + externalUserId);
808
809 msg.append(StringPool.CLOSE_CURLY_BRACE);
810
811 if (_log.isWarnEnabled()) {
812 _log.warn(msg.toString());
813 }
814
815 throw new NoSuchUserIdMapperException(msg.toString());
816 }
817
818 return userIdMapper;
819 }
820
821 public UserIdMapper fetchByT_E(String type, String externalUserId)
822 throws SystemException {
823 return fetchByT_E(type, externalUserId, true);
824 }
825
826 public UserIdMapper fetchByT_E(String type, String externalUserId,
827 boolean retrieveFromCache) throws SystemException {
828 Object[] finderArgs = new Object[] { type, externalUserId };
829
830 Object result = null;
831
832 if (retrieveFromCache) {
833 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_T_E,
834 finderArgs, this);
835 }
836
837 if (result == null) {
838 Session session = null;
839
840 try {
841 session = openSession();
842
843 StringBuilder query = new StringBuilder();
844
845 query.append(
846 "SELECT userIdMapper FROM UserIdMapper userIdMapper WHERE ");
847
848 if (type == null) {
849 query.append("userIdMapper.type IS NULL");
850 }
851 else {
852 query.append("userIdMapper.type = ?");
853 }
854
855 query.append(" AND ");
856
857 if (externalUserId == null) {
858 query.append("userIdMapper.externalUserId IS NULL");
859 }
860 else {
861 query.append("userIdMapper.externalUserId = ?");
862 }
863
864 query.append(" ");
865
866 Query q = session.createQuery(query.toString());
867
868 QueryPos qPos = QueryPos.getInstance(q);
869
870 if (type != null) {
871 qPos.add(type);
872 }
873
874 if (externalUserId != null) {
875 qPos.add(externalUserId);
876 }
877
878 List<UserIdMapper> list = q.list();
879
880 result = list;
881
882 UserIdMapper userIdMapper = null;
883
884 if (list.isEmpty()) {
885 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_E,
886 finderArgs, list);
887 }
888 else {
889 userIdMapper = list.get(0);
890
891 cacheResult(userIdMapper);
892
893 if ((userIdMapper.getType() == null) ||
894 !userIdMapper.getType().equals(type) ||
895 (userIdMapper.getExternalUserId() == null) ||
896 !userIdMapper.getExternalUserId()
897 .equals(externalUserId)) {
898 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_E,
899 finderArgs, userIdMapper);
900 }
901 }
902
903 return userIdMapper;
904 }
905 catch (Exception e) {
906 throw processException(e);
907 }
908 finally {
909 if (result == null) {
910 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_E,
911 finderArgs, new ArrayList<UserIdMapper>());
912 }
913
914 closeSession(session);
915 }
916 }
917 else {
918 if (result instanceof List) {
919 return null;
920 }
921 else {
922 return (UserIdMapper)result;
923 }
924 }
925 }
926
927 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
928 throws SystemException {
929 Session session = null;
930
931 try {
932 session = openSession();
933
934 dynamicQuery.compile(session);
935
936 return dynamicQuery.list();
937 }
938 catch (Exception e) {
939 throw processException(e);
940 }
941 finally {
942 closeSession(session);
943 }
944 }
945
946 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
947 int start, int end) throws SystemException {
948 Session session = null;
949
950 try {
951 session = openSession();
952
953 dynamicQuery.setLimit(start, end);
954
955 dynamicQuery.compile(session);
956
957 return dynamicQuery.list();
958 }
959 catch (Exception e) {
960 throw processException(e);
961 }
962 finally {
963 closeSession(session);
964 }
965 }
966
967 public List<UserIdMapper> findAll() throws SystemException {
968 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
969 }
970
971 public List<UserIdMapper> findAll(int start, int end)
972 throws SystemException {
973 return findAll(start, end, null);
974 }
975
976 public List<UserIdMapper> findAll(int start, int end, OrderByComparator obc)
977 throws SystemException {
978 Object[] finderArgs = new Object[] {
979 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
980 };
981
982 List<UserIdMapper> list = (List<UserIdMapper>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
983 finderArgs, this);
984
985 if (list == null) {
986 Session session = null;
987
988 try {
989 session = openSession();
990
991 StringBuilder query = new StringBuilder();
992
993 query.append(
994 "SELECT userIdMapper FROM UserIdMapper userIdMapper ");
995
996 if (obc != null) {
997 query.append("ORDER BY ");
998
999 String[] orderByFields = obc.getOrderByFields();
1000
1001 for (int i = 0; i < orderByFields.length; i++) {
1002 query.append("userIdMapper.");
1003 query.append(orderByFields[i]);
1004
1005 if (obc.isAscending()) {
1006 query.append(" ASC");
1007 }
1008 else {
1009 query.append(" DESC");
1010 }
1011
1012 if ((i + 1) < orderByFields.length) {
1013 query.append(", ");
1014 }
1015 }
1016 }
1017
1018 Query q = session.createQuery(query.toString());
1019
1020 if (obc == null) {
1021 list = (List<UserIdMapper>)QueryUtil.list(q, getDialect(),
1022 start, end, false);
1023
1024 Collections.sort(list);
1025 }
1026 else {
1027 list = (List<UserIdMapper>)QueryUtil.list(q, getDialect(),
1028 start, end);
1029 }
1030 }
1031 catch (Exception e) {
1032 throw processException(e);
1033 }
1034 finally {
1035 if (list == null) {
1036 list = new ArrayList<UserIdMapper>();
1037 }
1038
1039 cacheResult(list);
1040
1041 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1042
1043 closeSession(session);
1044 }
1045 }
1046
1047 return list;
1048 }
1049
1050 public void removeByUserId(long userId) throws SystemException {
1051 for (UserIdMapper userIdMapper : findByUserId(userId)) {
1052 remove(userIdMapper);
1053 }
1054 }
1055
1056 public void removeByU_T(long userId, String type)
1057 throws NoSuchUserIdMapperException, SystemException {
1058 UserIdMapper userIdMapper = findByU_T(userId, type);
1059
1060 remove(userIdMapper);
1061 }
1062
1063 public void removeByT_E(String type, String externalUserId)
1064 throws NoSuchUserIdMapperException, SystemException {
1065 UserIdMapper userIdMapper = findByT_E(type, externalUserId);
1066
1067 remove(userIdMapper);
1068 }
1069
1070 public void removeAll() throws SystemException {
1071 for (UserIdMapper userIdMapper : findAll()) {
1072 remove(userIdMapper);
1073 }
1074 }
1075
1076 public int countByUserId(long userId) throws SystemException {
1077 Object[] finderArgs = new Object[] { new Long(userId) };
1078
1079 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID,
1080 finderArgs, this);
1081
1082 if (count == null) {
1083 Session session = null;
1084
1085 try {
1086 session = openSession();
1087
1088 StringBuilder query = new StringBuilder();
1089
1090 query.append("SELECT COUNT(userIdMapper) ");
1091 query.append("FROM UserIdMapper userIdMapper WHERE ");
1092
1093 query.append("userIdMapper.userId = ?");
1094
1095 query.append(" ");
1096
1097 Query q = session.createQuery(query.toString());
1098
1099 QueryPos qPos = QueryPos.getInstance(q);
1100
1101 qPos.add(userId);
1102
1103 count = (Long)q.uniqueResult();
1104 }
1105 catch (Exception e) {
1106 throw processException(e);
1107 }
1108 finally {
1109 if (count == null) {
1110 count = Long.valueOf(0);
1111 }
1112
1113 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID,
1114 finderArgs, count);
1115
1116 closeSession(session);
1117 }
1118 }
1119
1120 return count.intValue();
1121 }
1122
1123 public int countByU_T(long userId, String type) throws SystemException {
1124 Object[] finderArgs = new Object[] { new Long(userId), type };
1125
1126 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U_T,
1127 finderArgs, this);
1128
1129 if (count == null) {
1130 Session session = null;
1131
1132 try {
1133 session = openSession();
1134
1135 StringBuilder query = new StringBuilder();
1136
1137 query.append("SELECT COUNT(userIdMapper) ");
1138 query.append("FROM UserIdMapper userIdMapper WHERE ");
1139
1140 query.append("userIdMapper.userId = ?");
1141
1142 query.append(" AND ");
1143
1144 if (type == null) {
1145 query.append("userIdMapper.type IS NULL");
1146 }
1147 else {
1148 query.append("userIdMapper.type = ?");
1149 }
1150
1151 query.append(" ");
1152
1153 Query q = session.createQuery(query.toString());
1154
1155 QueryPos qPos = QueryPos.getInstance(q);
1156
1157 qPos.add(userId);
1158
1159 if (type != null) {
1160 qPos.add(type);
1161 }
1162
1163 count = (Long)q.uniqueResult();
1164 }
1165 catch (Exception e) {
1166 throw processException(e);
1167 }
1168 finally {
1169 if (count == null) {
1170 count = Long.valueOf(0);
1171 }
1172
1173 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_T, finderArgs,
1174 count);
1175
1176 closeSession(session);
1177 }
1178 }
1179
1180 return count.intValue();
1181 }
1182
1183 public int countByT_E(String type, String externalUserId)
1184 throws SystemException {
1185 Object[] finderArgs = new Object[] { type, externalUserId };
1186
1187 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_T_E,
1188 finderArgs, this);
1189
1190 if (count == null) {
1191 Session session = null;
1192
1193 try {
1194 session = openSession();
1195
1196 StringBuilder query = new StringBuilder();
1197
1198 query.append("SELECT COUNT(userIdMapper) ");
1199 query.append("FROM UserIdMapper userIdMapper WHERE ");
1200
1201 if (type == null) {
1202 query.append("userIdMapper.type IS NULL");
1203 }
1204 else {
1205 query.append("userIdMapper.type = ?");
1206 }
1207
1208 query.append(" AND ");
1209
1210 if (externalUserId == null) {
1211 query.append("userIdMapper.externalUserId IS NULL");
1212 }
1213 else {
1214 query.append("userIdMapper.externalUserId = ?");
1215 }
1216
1217 query.append(" ");
1218
1219 Query q = session.createQuery(query.toString());
1220
1221 QueryPos qPos = QueryPos.getInstance(q);
1222
1223 if (type != null) {
1224 qPos.add(type);
1225 }
1226
1227 if (externalUserId != null) {
1228 qPos.add(externalUserId);
1229 }
1230
1231 count = (Long)q.uniqueResult();
1232 }
1233 catch (Exception e) {
1234 throw processException(e);
1235 }
1236 finally {
1237 if (count == null) {
1238 count = Long.valueOf(0);
1239 }
1240
1241 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_E, finderArgs,
1242 count);
1243
1244 closeSession(session);
1245 }
1246 }
1247
1248 return count.intValue();
1249 }
1250
1251 public int countAll() throws SystemException {
1252 Object[] finderArgs = new Object[0];
1253
1254 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1255 finderArgs, this);
1256
1257 if (count == null) {
1258 Session session = null;
1259
1260 try {
1261 session = openSession();
1262
1263 Query q = session.createQuery(
1264 "SELECT COUNT(userIdMapper) FROM UserIdMapper userIdMapper");
1265
1266 count = (Long)q.uniqueResult();
1267 }
1268 catch (Exception e) {
1269 throw processException(e);
1270 }
1271 finally {
1272 if (count == null) {
1273 count = Long.valueOf(0);
1274 }
1275
1276 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1277 count);
1278
1279 closeSession(session);
1280 }
1281 }
1282
1283 return count.intValue();
1284 }
1285
1286 public void afterPropertiesSet() {
1287 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1288 com.liferay.portal.util.PropsUtil.get(
1289 "value.object.listener.com.liferay.portal.model.UserIdMapper")));
1290
1291 if (listenerClassNames.length > 0) {
1292 try {
1293 List<ModelListener<UserIdMapper>> listenersList = new ArrayList<ModelListener<UserIdMapper>>();
1294
1295 for (String listenerClassName : listenerClassNames) {
1296 listenersList.add((ModelListener<UserIdMapper>)Class.forName(
1297 listenerClassName).newInstance());
1298 }
1299
1300 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1301 }
1302 catch (Exception e) {
1303 _log.error(e);
1304 }
1305 }
1306 }
1307
1308 @BeanReference(name = "com.liferay.portal.service.persistence.AccountPersistence.impl")
1309 protected com.liferay.portal.service.persistence.AccountPersistence accountPersistence;
1310 @BeanReference(name = "com.liferay.portal.service.persistence.AddressPersistence.impl")
1311 protected com.liferay.portal.service.persistence.AddressPersistence addressPersistence;
1312 @BeanReference(name = "com.liferay.portal.service.persistence.BrowserTrackerPersistence.impl")
1313 protected com.liferay.portal.service.persistence.BrowserTrackerPersistence browserTrackerPersistence;
1314 @BeanReference(name = "com.liferay.portal.service.persistence.ClassNamePersistence.impl")
1315 protected com.liferay.portal.service.persistence.ClassNamePersistence classNamePersistence;
1316 @BeanReference(name = "com.liferay.portal.service.persistence.CompanyPersistence.impl")
1317 protected com.liferay.portal.service.persistence.CompanyPersistence companyPersistence;
1318 @BeanReference(name = "com.liferay.portal.service.persistence.ContactPersistence.impl")
1319 protected com.liferay.portal.service.persistence.ContactPersistence contactPersistence;
1320 @BeanReference(name = "com.liferay.portal.service.persistence.CountryPersistence.impl")
1321 protected com.liferay.portal.service.persistence.CountryPersistence countryPersistence;
1322 @BeanReference(name = "com.liferay.portal.service.persistence.EmailAddressPersistence.impl")
1323 protected com.liferay.portal.service.persistence.EmailAddressPersistence emailAddressPersistence;
1324 @BeanReference(name = "com.liferay.portal.service.persistence.GroupPersistence.impl")
1325 protected com.liferay.portal.service.persistence.GroupPersistence groupPersistence;
1326 @BeanReference(name = "com.liferay.portal.service.persistence.ImagePersistence.impl")
1327 protected com.liferay.portal.service.persistence.ImagePersistence imagePersistence;
1328 @BeanReference(name = "com.liferay.portal.service.persistence.LayoutPersistence.impl")
1329 protected com.liferay.portal.service.persistence.LayoutPersistence layoutPersistence;
1330 @BeanReference(name = "com.liferay.portal.service.persistence.LayoutSetPersistence.impl")
1331 protected com.liferay.portal.service.persistence.LayoutSetPersistence layoutSetPersistence;
1332 @BeanReference(name = "com.liferay.portal.service.persistence.ListTypePersistence.impl")
1333 protected com.liferay.portal.service.persistence.ListTypePersistence listTypePersistence;
1334 @BeanReference(name = "com.liferay.portal.service.persistence.MembershipRequestPersistence.impl")
1335 protected com.liferay.portal.service.persistence.MembershipRequestPersistence membershipRequestPersistence;
1336 @BeanReference(name = "com.liferay.portal.service.persistence.OrganizationPersistence.impl")
1337 protected com.liferay.portal.service.persistence.OrganizationPersistence organizationPersistence;
1338 @BeanReference(name = "com.liferay.portal.service.persistence.OrgGroupPermissionPersistence.impl")
1339 protected com.liferay.portal.service.persistence.OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1340 @BeanReference(name = "com.liferay.portal.service.persistence.OrgGroupRolePersistence.impl")
1341 protected com.liferay.portal.service.persistence.OrgGroupRolePersistence orgGroupRolePersistence;
1342 @BeanReference(name = "com.liferay.portal.service.persistence.OrgLaborPersistence.impl")
1343 protected com.liferay.portal.service.persistence.OrgLaborPersistence orgLaborPersistence;
1344 @BeanReference(name = "com.liferay.portal.service.persistence.PasswordPolicyPersistence.impl")
1345 protected com.liferay.portal.service.persistence.PasswordPolicyPersistence passwordPolicyPersistence;
1346 @BeanReference(name = "com.liferay.portal.service.persistence.PasswordPolicyRelPersistence.impl")
1347 protected com.liferay.portal.service.persistence.PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1348 @BeanReference(name = "com.liferay.portal.service.persistence.PasswordTrackerPersistence.impl")
1349 protected com.liferay.portal.service.persistence.PasswordTrackerPersistence passwordTrackerPersistence;
1350 @BeanReference(name = "com.liferay.portal.service.persistence.PermissionPersistence.impl")
1351 protected com.liferay.portal.service.persistence.PermissionPersistence permissionPersistence;
1352 @BeanReference(name = "com.liferay.portal.service.persistence.PhonePersistence.impl")
1353 protected com.liferay.portal.service.persistence.PhonePersistence phonePersistence;
1354 @BeanReference(name = "com.liferay.portal.service.persistence.PluginSettingPersistence.impl")
1355 protected com.liferay.portal.service.persistence.PluginSettingPersistence pluginSettingPersistence;
1356 @BeanReference(name = "com.liferay.portal.service.persistence.PortletPersistence.impl")
1357 protected com.liferay.portal.service.persistence.PortletPersistence portletPersistence;
1358 @BeanReference(name = "com.liferay.portal.service.persistence.PortletItemPersistence.impl")
1359 protected com.liferay.portal.service.persistence.PortletItemPersistence portletItemPersistence;
1360 @BeanReference(name = "com.liferay.portal.service.persistence.PortletPreferencesPersistence.impl")
1361 protected com.liferay.portal.service.persistence.PortletPreferencesPersistence portletPreferencesPersistence;
1362 @BeanReference(name = "com.liferay.portal.service.persistence.RegionPersistence.impl")
1363 protected com.liferay.portal.service.persistence.RegionPersistence regionPersistence;
1364 @BeanReference(name = "com.liferay.portal.service.persistence.ReleasePersistence.impl")
1365 protected com.liferay.portal.service.persistence.ReleasePersistence releasePersistence;
1366 @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePersistence.impl")
1367 protected com.liferay.portal.service.persistence.ResourcePersistence resourcePersistence;
1368 @BeanReference(name = "com.liferay.portal.service.persistence.ResourceActionPersistence.impl")
1369 protected com.liferay.portal.service.persistence.ResourceActionPersistence resourceActionPersistence;
1370 @BeanReference(name = "com.liferay.portal.service.persistence.ResourceCodePersistence.impl")
1371 protected com.liferay.portal.service.persistence.ResourceCodePersistence resourceCodePersistence;
1372 @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePermissionPersistence.impl")
1373 protected com.liferay.portal.service.persistence.ResourcePermissionPersistence resourcePermissionPersistence;
1374 @BeanReference(name = "com.liferay.portal.service.persistence.RolePersistence.impl")
1375 protected com.liferay.portal.service.persistence.RolePersistence rolePersistence;
1376 @BeanReference(name = "com.liferay.portal.service.persistence.ServiceComponentPersistence.impl")
1377 protected com.liferay.portal.service.persistence.ServiceComponentPersistence serviceComponentPersistence;
1378 @BeanReference(name = "com.liferay.portal.service.persistence.ShardPersistence.impl")
1379 protected com.liferay.portal.service.persistence.ShardPersistence shardPersistence;
1380 @BeanReference(name = "com.liferay.portal.service.persistence.SubscriptionPersistence.impl")
1381 protected com.liferay.portal.service.persistence.SubscriptionPersistence subscriptionPersistence;
1382 @BeanReference(name = "com.liferay.portal.service.persistence.UserPersistence.impl")
1383 protected com.liferay.portal.service.persistence.UserPersistence userPersistence;
1384 @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupPersistence.impl")
1385 protected com.liferay.portal.service.persistence.UserGroupPersistence userGroupPersistence;
1386 @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupRolePersistence.impl")
1387 protected com.liferay.portal.service.persistence.UserGroupRolePersistence userGroupRolePersistence;
1388 @BeanReference(name = "com.liferay.portal.service.persistence.UserIdMapperPersistence.impl")
1389 protected com.liferay.portal.service.persistence.UserIdMapperPersistence userIdMapperPersistence;
1390 @BeanReference(name = "com.liferay.portal.service.persistence.UserTrackerPersistence.impl")
1391 protected com.liferay.portal.service.persistence.UserTrackerPersistence userTrackerPersistence;
1392 @BeanReference(name = "com.liferay.portal.service.persistence.UserTrackerPathPersistence.impl")
1393 protected com.liferay.portal.service.persistence.UserTrackerPathPersistence userTrackerPathPersistence;
1394 @BeanReference(name = "com.liferay.portal.service.persistence.WebDAVPropsPersistence.impl")
1395 protected com.liferay.portal.service.persistence.WebDAVPropsPersistence webDAVPropsPersistence;
1396 @BeanReference(name = "com.liferay.portal.service.persistence.WebsitePersistence.impl")
1397 protected com.liferay.portal.service.persistence.WebsitePersistence websitePersistence;
1398 private static Log _log = LogFactoryUtil.getLog(UserIdMapperPersistenceImpl.class);
1399}