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