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