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