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