1
19
20 package com.liferay.portal.service.persistence;
21
22 import com.liferay.portal.NoSuchUserIdMapperException;
23 import com.liferay.portal.SystemException;
24 import com.liferay.portal.kernel.dao.orm.DynamicQuery;
25 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
26 import com.liferay.portal.kernel.dao.orm.Query;
27 import com.liferay.portal.kernel.dao.orm.QueryPos;
28 import com.liferay.portal.kernel.dao.orm.QueryUtil;
29 import com.liferay.portal.kernel.dao.orm.Session;
30 import com.liferay.portal.kernel.log.Log;
31 import com.liferay.portal.kernel.log.LogFactoryUtil;
32 import com.liferay.portal.kernel.util.GetterUtil;
33 import com.liferay.portal.kernel.util.OrderByComparator;
34 import com.liferay.portal.kernel.util.StringPool;
35 import com.liferay.portal.kernel.util.StringUtil;
36 import com.liferay.portal.model.ModelListener;
37 import com.liferay.portal.model.UserIdMapper;
38 import com.liferay.portal.model.impl.UserIdMapperImpl;
39 import com.liferay.portal.model.impl.UserIdMapperModelImpl;
40 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
41
42 import java.util.ArrayList;
43 import java.util.Collections;
44 import java.util.Iterator;
45 import java.util.List;
46
47
53 public class UserIdMapperPersistenceImpl extends BasePersistenceImpl
54 implements UserIdMapperPersistence {
55 public UserIdMapper create(long userIdMapperId) {
56 UserIdMapper userIdMapper = new UserIdMapperImpl();
57
58 userIdMapper.setNew(true);
59 userIdMapper.setPrimaryKey(userIdMapperId);
60
61 return userIdMapper;
62 }
63
64 public UserIdMapper remove(long userIdMapperId)
65 throws NoSuchUserIdMapperException, SystemException {
66 Session session = null;
67
68 try {
69 session = openSession();
70
71 UserIdMapper userIdMapper = (UserIdMapper)session.get(UserIdMapperImpl.class,
72 new Long(userIdMapperId));
73
74 if (userIdMapper == null) {
75 if (_log.isWarnEnabled()) {
76 _log.warn("No UserIdMapper exists with the primary key " +
77 userIdMapperId);
78 }
79
80 throw new NoSuchUserIdMapperException(
81 "No UserIdMapper exists with the primary key " +
82 userIdMapperId);
83 }
84
85 return remove(userIdMapper);
86 }
87 catch (NoSuchUserIdMapperException nsee) {
88 throw nsee;
89 }
90 catch (Exception e) {
91 throw processException(e);
92 }
93 finally {
94 closeSession(session);
95 }
96 }
97
98 public UserIdMapper remove(UserIdMapper userIdMapper)
99 throws SystemException {
100 for (ModelListener listener : listeners) {
101 listener.onBeforeRemove(userIdMapper);
102 }
103
104 userIdMapper = removeImpl(userIdMapper);
105
106 for (ModelListener listener : listeners) {
107 listener.onAfterRemove(userIdMapper);
108 }
109
110 return userIdMapper;
111 }
112
113 protected UserIdMapper removeImpl(UserIdMapper userIdMapper)
114 throws SystemException {
115 Session session = null;
116
117 try {
118 session = openSession();
119
120 if (BatchSessionUtil.isEnabled()) {
121 Object staleObject = session.get(UserIdMapperImpl.class,
122 userIdMapper.getPrimaryKeyObj());
123
124 if (staleObject != null) {
125 session.evict(staleObject);
126 }
127 }
128
129 session.delete(userIdMapper);
130
131 session.flush();
132
133 return userIdMapper;
134 }
135 catch (Exception e) {
136 throw processException(e);
137 }
138 finally {
139 closeSession(session);
140
141 FinderCacheUtil.clearCache(UserIdMapper.class.getName());
142 }
143 }
144
145
148 public UserIdMapper update(UserIdMapper userIdMapper)
149 throws SystemException {
150 if (_log.isWarnEnabled()) {
151 _log.warn(
152 "Using the deprecated update(UserIdMapper userIdMapper) method. Use update(UserIdMapper userIdMapper, boolean merge) instead.");
153 }
154
155 return update(userIdMapper, false);
156 }
157
158
171 public UserIdMapper update(UserIdMapper userIdMapper, boolean merge)
172 throws SystemException {
173 boolean isNew = userIdMapper.isNew();
174
175 for (ModelListener listener : listeners) {
176 if (isNew) {
177 listener.onBeforeCreate(userIdMapper);
178 }
179 else {
180 listener.onBeforeUpdate(userIdMapper);
181 }
182 }
183
184 userIdMapper = updateImpl(userIdMapper, merge);
185
186 for (ModelListener listener : listeners) {
187 if (isNew) {
188 listener.onAfterCreate(userIdMapper);
189 }
190 else {
191 listener.onAfterUpdate(userIdMapper);
192 }
193 }
194
195 return userIdMapper;
196 }
197
198 public UserIdMapper updateImpl(
199 com.liferay.portal.model.UserIdMapper userIdMapper, boolean merge)
200 throws SystemException {
201 Session session = null;
202
203 try {
204 session = openSession();
205
206 BatchSessionUtil.update(session, userIdMapper, merge);
207
208 userIdMapper.setNew(false);
209
210 return userIdMapper;
211 }
212 catch (Exception e) {
213 throw processException(e);
214 }
215 finally {
216 closeSession(session);
217
218 FinderCacheUtil.clearCache(UserIdMapper.class.getName());
219 }
220 }
221
222 public UserIdMapper findByPrimaryKey(long userIdMapperId)
223 throws NoSuchUserIdMapperException, SystemException {
224 UserIdMapper userIdMapper = fetchByPrimaryKey(userIdMapperId);
225
226 if (userIdMapper == null) {
227 if (_log.isWarnEnabled()) {
228 _log.warn("No UserIdMapper exists with the primary key " +
229 userIdMapperId);
230 }
231
232 throw new NoSuchUserIdMapperException(
233 "No UserIdMapper exists with the primary key " +
234 userIdMapperId);
235 }
236
237 return userIdMapper;
238 }
239
240 public UserIdMapper fetchByPrimaryKey(long userIdMapperId)
241 throws SystemException {
242 Session session = null;
243
244 try {
245 session = openSession();
246
247 return (UserIdMapper)session.get(UserIdMapperImpl.class,
248 new Long(userIdMapperId));
249 }
250 catch (Exception e) {
251 throw processException(e);
252 }
253 finally {
254 closeSession(session);
255 }
256 }
257
258 public List<UserIdMapper> findByUserId(long userId)
259 throws SystemException {
260 boolean finderClassNameCacheEnabled = UserIdMapperModelImpl.CACHE_ENABLED;
261 String finderClassName = UserIdMapper.class.getName();
262 String finderMethodName = "findByUserId";
263 String[] finderParams = new String[] { Long.class.getName() };
264 Object[] finderArgs = new Object[] { new Long(userId) };
265
266 Object result = null;
267
268 if (finderClassNameCacheEnabled) {
269 result = FinderCacheUtil.getResult(finderClassName,
270 finderMethodName, finderParams, finderArgs, this);
271 }
272
273 if (result == null) {
274 Session session = null;
275
276 try {
277 session = openSession();
278
279 StringBuilder query = new StringBuilder();
280
281 query.append(
282 "FROM com.liferay.portal.model.UserIdMapper WHERE ");
283
284 query.append("userId = ?");
285
286 query.append(" ");
287
288 Query q = session.createQuery(query.toString());
289
290 QueryPos qPos = QueryPos.getInstance(q);
291
292 qPos.add(userId);
293
294 List<UserIdMapper> list = q.list();
295
296 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
297 finderClassName, finderMethodName, finderParams,
298 finderArgs, list);
299
300 return list;
301 }
302 catch (Exception e) {
303 throw processException(e);
304 }
305 finally {
306 closeSession(session);
307 }
308 }
309 else {
310 return (List<UserIdMapper>)result;
311 }
312 }
313
314 public List<UserIdMapper> findByUserId(long userId, int start, int end)
315 throws SystemException {
316 return findByUserId(userId, start, end, null);
317 }
318
319 public List<UserIdMapper> findByUserId(long userId, int start, int end,
320 OrderByComparator obc) throws SystemException {
321 boolean finderClassNameCacheEnabled = UserIdMapperModelImpl.CACHE_ENABLED;
322 String finderClassName = UserIdMapper.class.getName();
323 String finderMethodName = "findByUserId";
324 String[] finderParams = new String[] {
325 Long.class.getName(),
326
327 "java.lang.Integer", "java.lang.Integer",
328 "com.liferay.portal.kernel.util.OrderByComparator"
329 };
330 Object[] finderArgs = new Object[] {
331 new Long(userId),
332
333 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
334 };
335
336 Object result = null;
337
338 if (finderClassNameCacheEnabled) {
339 result = FinderCacheUtil.getResult(finderClassName,
340 finderMethodName, finderParams, finderArgs, this);
341 }
342
343 if (result == null) {
344 Session session = null;
345
346 try {
347 session = openSession();
348
349 StringBuilder query = new StringBuilder();
350
351 query.append(
352 "FROM com.liferay.portal.model.UserIdMapper WHERE ");
353
354 query.append("userId = ?");
355
356 query.append(" ");
357
358 if (obc != null) {
359 query.append("ORDER BY ");
360 query.append(obc.getOrderBy());
361 }
362
363 Query q = session.createQuery(query.toString());
364
365 QueryPos qPos = QueryPos.getInstance(q);
366
367 qPos.add(userId);
368
369 List<UserIdMapper> list = (List<UserIdMapper>)QueryUtil.list(q,
370 getDialect(), start, end);
371
372 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
373 finderClassName, finderMethodName, finderParams,
374 finderArgs, list);
375
376 return list;
377 }
378 catch (Exception e) {
379 throw processException(e);
380 }
381 finally {
382 closeSession(session);
383 }
384 }
385 else {
386 return (List<UserIdMapper>)result;
387 }
388 }
389
390 public UserIdMapper findByUserId_First(long userId, OrderByComparator obc)
391 throws NoSuchUserIdMapperException, SystemException {
392 List<UserIdMapper> list = findByUserId(userId, 0, 1, obc);
393
394 if (list.size() == 0) {
395 StringBuilder msg = new StringBuilder();
396
397 msg.append("No UserIdMapper exists with the key {");
398
399 msg.append("userId=" + userId);
400
401 msg.append(StringPool.CLOSE_CURLY_BRACE);
402
403 throw new NoSuchUserIdMapperException(msg.toString());
404 }
405 else {
406 return list.get(0);
407 }
408 }
409
410 public UserIdMapper findByUserId_Last(long userId, OrderByComparator obc)
411 throws NoSuchUserIdMapperException, SystemException {
412 int count = countByUserId(userId);
413
414 List<UserIdMapper> list = findByUserId(userId, count - 1, count, obc);
415
416 if (list.size() == 0) {
417 StringBuilder msg = new StringBuilder();
418
419 msg.append("No UserIdMapper exists with the key {");
420
421 msg.append("userId=" + userId);
422
423 msg.append(StringPool.CLOSE_CURLY_BRACE);
424
425 throw new NoSuchUserIdMapperException(msg.toString());
426 }
427 else {
428 return list.get(0);
429 }
430 }
431
432 public UserIdMapper[] findByUserId_PrevAndNext(long userIdMapperId,
433 long userId, OrderByComparator obc)
434 throws NoSuchUserIdMapperException, SystemException {
435 UserIdMapper userIdMapper = findByPrimaryKey(userIdMapperId);
436
437 int count = countByUserId(userId);
438
439 Session session = null;
440
441 try {
442 session = openSession();
443
444 StringBuilder query = new StringBuilder();
445
446 query.append("FROM com.liferay.portal.model.UserIdMapper WHERE ");
447
448 query.append("userId = ?");
449
450 query.append(" ");
451
452 if (obc != null) {
453 query.append("ORDER BY ");
454 query.append(obc.getOrderBy());
455 }
456
457 Query q = session.createQuery(query.toString());
458
459 QueryPos qPos = QueryPos.getInstance(q);
460
461 qPos.add(userId);
462
463 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
464 userIdMapper);
465
466 UserIdMapper[] array = new UserIdMapperImpl[3];
467
468 array[0] = (UserIdMapper)objArray[0];
469 array[1] = (UserIdMapper)objArray[1];
470 array[2] = (UserIdMapper)objArray[2];
471
472 return array;
473 }
474 catch (Exception e) {
475 throw processException(e);
476 }
477 finally {
478 closeSession(session);
479 }
480 }
481
482 public UserIdMapper findByU_T(long userId, String type)
483 throws NoSuchUserIdMapperException, SystemException {
484 UserIdMapper userIdMapper = fetchByU_T(userId, type);
485
486 if (userIdMapper == null) {
487 StringBuilder msg = new StringBuilder();
488
489 msg.append("No UserIdMapper exists with the key {");
490
491 msg.append("userId=" + userId);
492
493 msg.append(", ");
494 msg.append("type=" + type);
495
496 msg.append(StringPool.CLOSE_CURLY_BRACE);
497
498 if (_log.isWarnEnabled()) {
499 _log.warn(msg.toString());
500 }
501
502 throw new NoSuchUserIdMapperException(msg.toString());
503 }
504
505 return userIdMapper;
506 }
507
508 public UserIdMapper fetchByU_T(long userId, String type)
509 throws SystemException {
510 boolean finderClassNameCacheEnabled = UserIdMapperModelImpl.CACHE_ENABLED;
511 String finderClassName = UserIdMapper.class.getName();
512 String finderMethodName = "fetchByU_T";
513 String[] finderParams = new String[] {
514 Long.class.getName(), String.class.getName()
515 };
516 Object[] finderArgs = new Object[] { new Long(userId), type };
517
518 Object result = null;
519
520 if (finderClassNameCacheEnabled) {
521 result = FinderCacheUtil.getResult(finderClassName,
522 finderMethodName, finderParams, finderArgs, this);
523 }
524
525 if (result == null) {
526 Session session = null;
527
528 try {
529 session = openSession();
530
531 StringBuilder query = new StringBuilder();
532
533 query.append(
534 "FROM com.liferay.portal.model.UserIdMapper WHERE ");
535
536 query.append("userId = ?");
537
538 query.append(" AND ");
539
540 if (type == null) {
541 query.append("type_ IS NULL");
542 }
543 else {
544 query.append("type_ = ?");
545 }
546
547 query.append(" ");
548
549 Query q = session.createQuery(query.toString());
550
551 QueryPos qPos = QueryPos.getInstance(q);
552
553 qPos.add(userId);
554
555 if (type != null) {
556 qPos.add(type);
557 }
558
559 List<UserIdMapper> list = q.list();
560
561 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
562 finderClassName, finderMethodName, finderParams,
563 finderArgs, list);
564
565 if (list.size() == 0) {
566 return null;
567 }
568 else {
569 return list.get(0);
570 }
571 }
572 catch (Exception e) {
573 throw processException(e);
574 }
575 finally {
576 closeSession(session);
577 }
578 }
579 else {
580 List<UserIdMapper> list = (List<UserIdMapper>)result;
581
582 if (list.size() == 0) {
583 return null;
584 }
585 else {
586 return list.get(0);
587 }
588 }
589 }
590
591 public UserIdMapper findByT_E(String type, String externalUserId)
592 throws NoSuchUserIdMapperException, SystemException {
593 UserIdMapper userIdMapper = fetchByT_E(type, externalUserId);
594
595 if (userIdMapper == null) {
596 StringBuilder msg = new StringBuilder();
597
598 msg.append("No UserIdMapper exists with the key {");
599
600 msg.append("type=" + type);
601
602 msg.append(", ");
603 msg.append("externalUserId=" + externalUserId);
604
605 msg.append(StringPool.CLOSE_CURLY_BRACE);
606
607 if (_log.isWarnEnabled()) {
608 _log.warn(msg.toString());
609 }
610
611 throw new NoSuchUserIdMapperException(msg.toString());
612 }
613
614 return userIdMapper;
615 }
616
617 public UserIdMapper fetchByT_E(String type, String externalUserId)
618 throws SystemException {
619 boolean finderClassNameCacheEnabled = UserIdMapperModelImpl.CACHE_ENABLED;
620 String finderClassName = UserIdMapper.class.getName();
621 String finderMethodName = "fetchByT_E";
622 String[] finderParams = new String[] {
623 String.class.getName(), String.class.getName()
624 };
625 Object[] finderArgs = new Object[] { type, externalUserId };
626
627 Object result = null;
628
629 if (finderClassNameCacheEnabled) {
630 result = FinderCacheUtil.getResult(finderClassName,
631 finderMethodName, finderParams, finderArgs, this);
632 }
633
634 if (result == null) {
635 Session session = null;
636
637 try {
638 session = openSession();
639
640 StringBuilder query = new StringBuilder();
641
642 query.append(
643 "FROM com.liferay.portal.model.UserIdMapper WHERE ");
644
645 if (type == null) {
646 query.append("type_ IS NULL");
647 }
648 else {
649 query.append("type_ = ?");
650 }
651
652 query.append(" AND ");
653
654 if (externalUserId == null) {
655 query.append("externalUserId IS NULL");
656 }
657 else {
658 query.append("externalUserId = ?");
659 }
660
661 query.append(" ");
662
663 Query q = session.createQuery(query.toString());
664
665 QueryPos qPos = QueryPos.getInstance(q);
666
667 if (type != null) {
668 qPos.add(type);
669 }
670
671 if (externalUserId != null) {
672 qPos.add(externalUserId);
673 }
674
675 List<UserIdMapper> list = q.list();
676
677 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
678 finderClassName, finderMethodName, finderParams,
679 finderArgs, list);
680
681 if (list.size() == 0) {
682 return null;
683 }
684 else {
685 return list.get(0);
686 }
687 }
688 catch (Exception e) {
689 throw processException(e);
690 }
691 finally {
692 closeSession(session);
693 }
694 }
695 else {
696 List<UserIdMapper> list = (List<UserIdMapper>)result;
697
698 if (list.size() == 0) {
699 return null;
700 }
701 else {
702 return list.get(0);
703 }
704 }
705 }
706
707 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
708 throws SystemException {
709 Session session = null;
710
711 try {
712 session = openSession();
713
714 dynamicQuery.compile(session);
715
716 return dynamicQuery.list();
717 }
718 catch (Exception e) {
719 throw processException(e);
720 }
721 finally {
722 closeSession(session);
723 }
724 }
725
726 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
727 int start, int end) throws SystemException {
728 Session session = null;
729
730 try {
731 session = openSession();
732
733 dynamicQuery.setLimit(start, end);
734
735 dynamicQuery.compile(session);
736
737 return dynamicQuery.list();
738 }
739 catch (Exception e) {
740 throw processException(e);
741 }
742 finally {
743 closeSession(session);
744 }
745 }
746
747 public List<UserIdMapper> findAll() throws SystemException {
748 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
749 }
750
751 public List<UserIdMapper> findAll(int start, int end)
752 throws SystemException {
753 return findAll(start, end, null);
754 }
755
756 public List<UserIdMapper> findAll(int start, int end, OrderByComparator obc)
757 throws SystemException {
758 boolean finderClassNameCacheEnabled = UserIdMapperModelImpl.CACHE_ENABLED;
759 String finderClassName = UserIdMapper.class.getName();
760 String finderMethodName = "findAll";
761 String[] finderParams = new String[] {
762 "java.lang.Integer", "java.lang.Integer",
763 "com.liferay.portal.kernel.util.OrderByComparator"
764 };
765 Object[] finderArgs = new Object[] {
766 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
767 };
768
769 Object result = null;
770
771 if (finderClassNameCacheEnabled) {
772 result = FinderCacheUtil.getResult(finderClassName,
773 finderMethodName, finderParams, finderArgs, this);
774 }
775
776 if (result == null) {
777 Session session = null;
778
779 try {
780 session = openSession();
781
782 StringBuilder query = new StringBuilder();
783
784 query.append("FROM com.liferay.portal.model.UserIdMapper ");
785
786 if (obc != null) {
787 query.append("ORDER BY ");
788 query.append(obc.getOrderBy());
789 }
790
791 Query q = session.createQuery(query.toString());
792
793 List<UserIdMapper> list = null;
794
795 if (obc == null) {
796 list = (List<UserIdMapper>)QueryUtil.list(q, getDialect(),
797 start, end, false);
798
799 Collections.sort(list);
800 }
801 else {
802 list = (List<UserIdMapper>)QueryUtil.list(q, getDialect(),
803 start, end);
804 }
805
806 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
807 finderClassName, finderMethodName, finderParams,
808 finderArgs, list);
809
810 return list;
811 }
812 catch (Exception e) {
813 throw processException(e);
814 }
815 finally {
816 closeSession(session);
817 }
818 }
819 else {
820 return (List<UserIdMapper>)result;
821 }
822 }
823
824 public void removeByUserId(long userId) throws SystemException {
825 for (UserIdMapper userIdMapper : findByUserId(userId)) {
826 remove(userIdMapper);
827 }
828 }
829
830 public void removeByU_T(long userId, String type)
831 throws NoSuchUserIdMapperException, SystemException {
832 UserIdMapper userIdMapper = findByU_T(userId, type);
833
834 remove(userIdMapper);
835 }
836
837 public void removeByT_E(String type, String externalUserId)
838 throws NoSuchUserIdMapperException, SystemException {
839 UserIdMapper userIdMapper = findByT_E(type, externalUserId);
840
841 remove(userIdMapper);
842 }
843
844 public void removeAll() throws SystemException {
845 for (UserIdMapper userIdMapper : findAll()) {
846 remove(userIdMapper);
847 }
848 }
849
850 public int countByUserId(long userId) throws SystemException {
851 boolean finderClassNameCacheEnabled = UserIdMapperModelImpl.CACHE_ENABLED;
852 String finderClassName = UserIdMapper.class.getName();
853 String finderMethodName = "countByUserId";
854 String[] finderParams = new String[] { Long.class.getName() };
855 Object[] finderArgs = new Object[] { new Long(userId) };
856
857 Object result = null;
858
859 if (finderClassNameCacheEnabled) {
860 result = FinderCacheUtil.getResult(finderClassName,
861 finderMethodName, finderParams, finderArgs, this);
862 }
863
864 if (result == null) {
865 Session session = null;
866
867 try {
868 session = openSession();
869
870 StringBuilder query = new StringBuilder();
871
872 query.append("SELECT COUNT(*) ");
873 query.append(
874 "FROM com.liferay.portal.model.UserIdMapper WHERE ");
875
876 query.append("userId = ?");
877
878 query.append(" ");
879
880 Query q = session.createQuery(query.toString());
881
882 QueryPos qPos = QueryPos.getInstance(q);
883
884 qPos.add(userId);
885
886 Long count = null;
887
888 Iterator<Long> itr = q.list().iterator();
889
890 if (itr.hasNext()) {
891 count = itr.next();
892 }
893
894 if (count == null) {
895 count = new Long(0);
896 }
897
898 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
899 finderClassName, finderMethodName, finderParams,
900 finderArgs, count);
901
902 return count.intValue();
903 }
904 catch (Exception e) {
905 throw processException(e);
906 }
907 finally {
908 closeSession(session);
909 }
910 }
911 else {
912 return ((Long)result).intValue();
913 }
914 }
915
916 public int countByU_T(long userId, String type) throws SystemException {
917 boolean finderClassNameCacheEnabled = UserIdMapperModelImpl.CACHE_ENABLED;
918 String finderClassName = UserIdMapper.class.getName();
919 String finderMethodName = "countByU_T";
920 String[] finderParams = new String[] {
921 Long.class.getName(), String.class.getName()
922 };
923 Object[] finderArgs = new Object[] { new Long(userId), type };
924
925 Object result = null;
926
927 if (finderClassNameCacheEnabled) {
928 result = FinderCacheUtil.getResult(finderClassName,
929 finderMethodName, finderParams, finderArgs, this);
930 }
931
932 if (result == null) {
933 Session session = null;
934
935 try {
936 session = openSession();
937
938 StringBuilder query = new StringBuilder();
939
940 query.append("SELECT COUNT(*) ");
941 query.append(
942 "FROM com.liferay.portal.model.UserIdMapper WHERE ");
943
944 query.append("userId = ?");
945
946 query.append(" AND ");
947
948 if (type == null) {
949 query.append("type_ IS NULL");
950 }
951 else {
952 query.append("type_ = ?");
953 }
954
955 query.append(" ");
956
957 Query q = session.createQuery(query.toString());
958
959 QueryPos qPos = QueryPos.getInstance(q);
960
961 qPos.add(userId);
962
963 if (type != null) {
964 qPos.add(type);
965 }
966
967 Long count = null;
968
969 Iterator<Long> itr = q.list().iterator();
970
971 if (itr.hasNext()) {
972 count = itr.next();
973 }
974
975 if (count == null) {
976 count = new Long(0);
977 }
978
979 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
980 finderClassName, finderMethodName, finderParams,
981 finderArgs, count);
982
983 return count.intValue();
984 }
985 catch (Exception e) {
986 throw processException(e);
987 }
988 finally {
989 closeSession(session);
990 }
991 }
992 else {
993 return ((Long)result).intValue();
994 }
995 }
996
997 public int countByT_E(String type, String externalUserId)
998 throws SystemException {
999 boolean finderClassNameCacheEnabled = UserIdMapperModelImpl.CACHE_ENABLED;
1000 String finderClassName = UserIdMapper.class.getName();
1001 String finderMethodName = "countByT_E";
1002 String[] finderParams = new String[] {
1003 String.class.getName(), String.class.getName()
1004 };
1005 Object[] finderArgs = new Object[] { type, externalUserId };
1006
1007 Object result = null;
1008
1009 if (finderClassNameCacheEnabled) {
1010 result = FinderCacheUtil.getResult(finderClassName,
1011 finderMethodName, finderParams, finderArgs, this);
1012 }
1013
1014 if (result == null) {
1015 Session session = null;
1016
1017 try {
1018 session = openSession();
1019
1020 StringBuilder query = new StringBuilder();
1021
1022 query.append("SELECT COUNT(*) ");
1023 query.append(
1024 "FROM com.liferay.portal.model.UserIdMapper WHERE ");
1025
1026 if (type == null) {
1027 query.append("type_ IS NULL");
1028 }
1029 else {
1030 query.append("type_ = ?");
1031 }
1032
1033 query.append(" AND ");
1034
1035 if (externalUserId == null) {
1036 query.append("externalUserId IS NULL");
1037 }
1038 else {
1039 query.append("externalUserId = ?");
1040 }
1041
1042 query.append(" ");
1043
1044 Query q = session.createQuery(query.toString());
1045
1046 QueryPos qPos = QueryPos.getInstance(q);
1047
1048 if (type != null) {
1049 qPos.add(type);
1050 }
1051
1052 if (externalUserId != null) {
1053 qPos.add(externalUserId);
1054 }
1055
1056 Long count = null;
1057
1058 Iterator<Long> itr = q.list().iterator();
1059
1060 if (itr.hasNext()) {
1061 count = itr.next();
1062 }
1063
1064 if (count == null) {
1065 count = new Long(0);
1066 }
1067
1068 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1069 finderClassName, finderMethodName, finderParams,
1070 finderArgs, count);
1071
1072 return count.intValue();
1073 }
1074 catch (Exception e) {
1075 throw processException(e);
1076 }
1077 finally {
1078 closeSession(session);
1079 }
1080 }
1081 else {
1082 return ((Long)result).intValue();
1083 }
1084 }
1085
1086 public int countAll() throws SystemException {
1087 boolean finderClassNameCacheEnabled = UserIdMapperModelImpl.CACHE_ENABLED;
1088 String finderClassName = UserIdMapper.class.getName();
1089 String finderMethodName = "countAll";
1090 String[] finderParams = new String[] { };
1091 Object[] finderArgs = new Object[] { };
1092
1093 Object result = null;
1094
1095 if (finderClassNameCacheEnabled) {
1096 result = FinderCacheUtil.getResult(finderClassName,
1097 finderMethodName, finderParams, finderArgs, this);
1098 }
1099
1100 if (result == null) {
1101 Session session = null;
1102
1103 try {
1104 session = openSession();
1105
1106 Query q = session.createQuery(
1107 "SELECT COUNT(*) FROM com.liferay.portal.model.UserIdMapper");
1108
1109 Long count = null;
1110
1111 Iterator<Long> itr = q.list().iterator();
1112
1113 if (itr.hasNext()) {
1114 count = itr.next();
1115 }
1116
1117 if (count == null) {
1118 count = new Long(0);
1119 }
1120
1121 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1122 finderClassName, finderMethodName, finderParams,
1123 finderArgs, count);
1124
1125 return count.intValue();
1126 }
1127 catch (Exception e) {
1128 throw processException(e);
1129 }
1130 finally {
1131 closeSession(session);
1132 }
1133 }
1134 else {
1135 return ((Long)result).intValue();
1136 }
1137 }
1138
1139 public void afterPropertiesSet() {
1140 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1141 com.liferay.portal.util.PropsUtil.get(
1142 "value.object.listener.com.liferay.portal.model.UserIdMapper")));
1143
1144 if (listenerClassNames.length > 0) {
1145 try {
1146 List<ModelListener> listenersList = new ArrayList<ModelListener>();
1147
1148 for (String listenerClassName : listenerClassNames) {
1149 listenersList.add((ModelListener)Class.forName(
1150 listenerClassName).newInstance());
1151 }
1152
1153 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1154 }
1155 catch (Exception e) {
1156 _log.error(e);
1157 }
1158 }
1159 }
1160
1161 private static Log _log = LogFactoryUtil.getLog(UserIdMapperPersistenceImpl.class);
1162}