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