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