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 if (BatchSessionUtil.isEnabled()) {
130 Object staleObject = session.get(UserIdMapperImpl.class,
131 userIdMapper.getPrimaryKeyObj());
132
133 if (staleObject != null) {
134 session.evict(staleObject);
135 }
136 }
137
138 session.delete(userIdMapper);
139
140 session.flush();
141
142 return userIdMapper;
143 }
144 catch (Exception e) {
145 throw processException(e);
146 }
147 finally {
148 closeSession(session);
149
150 FinderCacheUtil.clearCache(UserIdMapper.class.getName());
151 }
152 }
153
154
157 public UserIdMapper update(UserIdMapper userIdMapper)
158 throws SystemException {
159 if (_log.isWarnEnabled()) {
160 _log.warn(
161 "Using the deprecated update(UserIdMapper userIdMapper) method. Use update(UserIdMapper userIdMapper, boolean merge) instead.");
162 }
163
164 return update(userIdMapper, false);
165 }
166
167
180 public UserIdMapper update(UserIdMapper userIdMapper, boolean merge)
181 throws SystemException {
182 boolean isNew = userIdMapper.isNew();
183
184 if (_listeners.length > 0) {
185 for (ModelListener listener : _listeners) {
186 if (isNew) {
187 listener.onBeforeCreate(userIdMapper);
188 }
189 else {
190 listener.onBeforeUpdate(userIdMapper);
191 }
192 }
193 }
194
195 userIdMapper = updateImpl(userIdMapper, merge);
196
197 if (_listeners.length > 0) {
198 for (ModelListener listener : _listeners) {
199 if (isNew) {
200 listener.onAfterCreate(userIdMapper);
201 }
202 else {
203 listener.onAfterUpdate(userIdMapper);
204 }
205 }
206 }
207
208 return userIdMapper;
209 }
210
211 public UserIdMapper updateImpl(
212 com.liferay.portal.model.UserIdMapper userIdMapper, boolean merge)
213 throws SystemException {
214 Session session = null;
215
216 try {
217 session = openSession();
218
219 BatchSessionUtil.update(session, userIdMapper, merge);
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 = null;
807
808 if (obc == null) {
809 list = (List<UserIdMapper>)QueryUtil.list(q, getDialect(),
810 start, end, false);
811
812 Collections.sort(list);
813 }
814 else {
815 list = (List<UserIdMapper>)QueryUtil.list(q, getDialect(),
816 start, end);
817 }
818
819 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
820 finderClassName, finderMethodName, finderParams,
821 finderArgs, list);
822
823 return list;
824 }
825 catch (Exception e) {
826 throw processException(e);
827 }
828 finally {
829 closeSession(session);
830 }
831 }
832 else {
833 return (List<UserIdMapper>)result;
834 }
835 }
836
837 public void removeByUserId(long userId) throws SystemException {
838 for (UserIdMapper userIdMapper : findByUserId(userId)) {
839 remove(userIdMapper);
840 }
841 }
842
843 public void removeByU_T(long userId, String type)
844 throws NoSuchUserIdMapperException, SystemException {
845 UserIdMapper userIdMapper = findByU_T(userId, type);
846
847 remove(userIdMapper);
848 }
849
850 public void removeByT_E(String type, String externalUserId)
851 throws NoSuchUserIdMapperException, SystemException {
852 UserIdMapper userIdMapper = findByT_E(type, externalUserId);
853
854 remove(userIdMapper);
855 }
856
857 public void removeAll() throws SystemException {
858 for (UserIdMapper userIdMapper : findAll()) {
859 remove(userIdMapper);
860 }
861 }
862
863 public int countByUserId(long userId) throws SystemException {
864 boolean finderClassNameCacheEnabled = UserIdMapperModelImpl.CACHE_ENABLED;
865 String finderClassName = UserIdMapper.class.getName();
866 String finderMethodName = "countByUserId";
867 String[] finderParams = new String[] { Long.class.getName() };
868 Object[] finderArgs = new Object[] { new Long(userId) };
869
870 Object result = null;
871
872 if (finderClassNameCacheEnabled) {
873 result = FinderCacheUtil.getResult(finderClassName,
874 finderMethodName, finderParams, finderArgs, this);
875 }
876
877 if (result == null) {
878 Session session = null;
879
880 try {
881 session = openSession();
882
883 StringBuilder query = new StringBuilder();
884
885 query.append("SELECT COUNT(*) ");
886 query.append(
887 "FROM com.liferay.portal.model.UserIdMapper WHERE ");
888
889 query.append("userId = ?");
890
891 query.append(" ");
892
893 Query q = session.createQuery(query.toString());
894
895 QueryPos qPos = QueryPos.getInstance(q);
896
897 qPos.add(userId);
898
899 Long count = null;
900
901 Iterator<Long> itr = q.list().iterator();
902
903 if (itr.hasNext()) {
904 count = itr.next();
905 }
906
907 if (count == null) {
908 count = new Long(0);
909 }
910
911 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
912 finderClassName, finderMethodName, finderParams,
913 finderArgs, count);
914
915 return count.intValue();
916 }
917 catch (Exception e) {
918 throw processException(e);
919 }
920 finally {
921 closeSession(session);
922 }
923 }
924 else {
925 return ((Long)result).intValue();
926 }
927 }
928
929 public int countByU_T(long userId, String type) throws SystemException {
930 boolean finderClassNameCacheEnabled = UserIdMapperModelImpl.CACHE_ENABLED;
931 String finderClassName = UserIdMapper.class.getName();
932 String finderMethodName = "countByU_T";
933 String[] finderParams = new String[] {
934 Long.class.getName(), String.class.getName()
935 };
936 Object[] finderArgs = new Object[] { new Long(userId), type };
937
938 Object result = null;
939
940 if (finderClassNameCacheEnabled) {
941 result = FinderCacheUtil.getResult(finderClassName,
942 finderMethodName, finderParams, finderArgs, this);
943 }
944
945 if (result == null) {
946 Session session = null;
947
948 try {
949 session = openSession();
950
951 StringBuilder query = new StringBuilder();
952
953 query.append("SELECT COUNT(*) ");
954 query.append(
955 "FROM com.liferay.portal.model.UserIdMapper WHERE ");
956
957 query.append("userId = ?");
958
959 query.append(" AND ");
960
961 if (type == null) {
962 query.append("type_ IS NULL");
963 }
964 else {
965 query.append("type_ = ?");
966 }
967
968 query.append(" ");
969
970 Query q = session.createQuery(query.toString());
971
972 QueryPos qPos = QueryPos.getInstance(q);
973
974 qPos.add(userId);
975
976 if (type != null) {
977 qPos.add(type);
978 }
979
980 Long count = null;
981
982 Iterator<Long> itr = q.list().iterator();
983
984 if (itr.hasNext()) {
985 count = itr.next();
986 }
987
988 if (count == null) {
989 count = new Long(0);
990 }
991
992 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
993 finderClassName, finderMethodName, finderParams,
994 finderArgs, count);
995
996 return count.intValue();
997 }
998 catch (Exception e) {
999 throw processException(e);
1000 }
1001 finally {
1002 closeSession(session);
1003 }
1004 }
1005 else {
1006 return ((Long)result).intValue();
1007 }
1008 }
1009
1010 public int countByT_E(String type, String externalUserId)
1011 throws SystemException {
1012 boolean finderClassNameCacheEnabled = UserIdMapperModelImpl.CACHE_ENABLED;
1013 String finderClassName = UserIdMapper.class.getName();
1014 String finderMethodName = "countByT_E";
1015 String[] finderParams = new String[] {
1016 String.class.getName(), String.class.getName()
1017 };
1018 Object[] finderArgs = new Object[] { type, externalUserId };
1019
1020 Object result = null;
1021
1022 if (finderClassNameCacheEnabled) {
1023 result = FinderCacheUtil.getResult(finderClassName,
1024 finderMethodName, finderParams, finderArgs, this);
1025 }
1026
1027 if (result == null) {
1028 Session session = null;
1029
1030 try {
1031 session = openSession();
1032
1033 StringBuilder query = new StringBuilder();
1034
1035 query.append("SELECT COUNT(*) ");
1036 query.append(
1037 "FROM com.liferay.portal.model.UserIdMapper WHERE ");
1038
1039 if (type == null) {
1040 query.append("type_ IS NULL");
1041 }
1042 else {
1043 query.append("type_ = ?");
1044 }
1045
1046 query.append(" AND ");
1047
1048 if (externalUserId == null) {
1049 query.append("externalUserId IS NULL");
1050 }
1051 else {
1052 query.append("externalUserId = ?");
1053 }
1054
1055 query.append(" ");
1056
1057 Query q = session.createQuery(query.toString());
1058
1059 QueryPos qPos = QueryPos.getInstance(q);
1060
1061 if (type != null) {
1062 qPos.add(type);
1063 }
1064
1065 if (externalUserId != null) {
1066 qPos.add(externalUserId);
1067 }
1068
1069 Long count = null;
1070
1071 Iterator<Long> itr = q.list().iterator();
1072
1073 if (itr.hasNext()) {
1074 count = itr.next();
1075 }
1076
1077 if (count == null) {
1078 count = new Long(0);
1079 }
1080
1081 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1082 finderClassName, finderMethodName, finderParams,
1083 finderArgs, count);
1084
1085 return count.intValue();
1086 }
1087 catch (Exception e) {
1088 throw processException(e);
1089 }
1090 finally {
1091 closeSession(session);
1092 }
1093 }
1094 else {
1095 return ((Long)result).intValue();
1096 }
1097 }
1098
1099 public int countAll() throws SystemException {
1100 boolean finderClassNameCacheEnabled = UserIdMapperModelImpl.CACHE_ENABLED;
1101 String finderClassName = UserIdMapper.class.getName();
1102 String finderMethodName = "countAll";
1103 String[] finderParams = new String[] { };
1104 Object[] finderArgs = new Object[] { };
1105
1106 Object result = null;
1107
1108 if (finderClassNameCacheEnabled) {
1109 result = FinderCacheUtil.getResult(finderClassName,
1110 finderMethodName, finderParams, finderArgs, this);
1111 }
1112
1113 if (result == null) {
1114 Session session = null;
1115
1116 try {
1117 session = openSession();
1118
1119 Query q = session.createQuery(
1120 "SELECT COUNT(*) FROM com.liferay.portal.model.UserIdMapper");
1121
1122 Long count = null;
1123
1124 Iterator<Long> itr = q.list().iterator();
1125
1126 if (itr.hasNext()) {
1127 count = itr.next();
1128 }
1129
1130 if (count == null) {
1131 count = new Long(0);
1132 }
1133
1134 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1135 finderClassName, finderMethodName, finderParams,
1136 finderArgs, count);
1137
1138 return count.intValue();
1139 }
1140 catch (Exception e) {
1141 throw processException(e);
1142 }
1143 finally {
1144 closeSession(session);
1145 }
1146 }
1147 else {
1148 return ((Long)result).intValue();
1149 }
1150 }
1151
1152 public void registerListener(ModelListener listener) {
1153 List<ModelListener> listeners = ListUtil.fromArray(_listeners);
1154
1155 listeners.add(listener);
1156
1157 _listeners = listeners.toArray(new ModelListener[listeners.size()]);
1158 }
1159
1160 public void unregisterListener(ModelListener listener) {
1161 List<ModelListener> listeners = ListUtil.fromArray(_listeners);
1162
1163 listeners.remove(listener);
1164
1165 _listeners = listeners.toArray(new ModelListener[listeners.size()]);
1166 }
1167
1168 public void afterPropertiesSet() {
1169 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1170 com.liferay.portal.util.PropsUtil.get(
1171 "value.object.listener.com.liferay.portal.model.UserIdMapper")));
1172
1173 if (listenerClassNames.length > 0) {
1174 try {
1175 List<ModelListener> listeners = new ArrayList<ModelListener>();
1176
1177 for (String listenerClassName : listenerClassNames) {
1178 listeners.add((ModelListener)Class.forName(
1179 listenerClassName).newInstance());
1180 }
1181
1182 _listeners = listeners.toArray(new ModelListener[listeners.size()]);
1183 }
1184 catch (Exception e) {
1185 _log.error(e);
1186 }
1187 }
1188 }
1189
1190 private static Log _log = LogFactory.getLog(UserIdMapperPersistenceImpl.class);
1191 private ModelListener[] _listeners = new ModelListener[0];
1192}