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