1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
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.annotation.BeanReference;
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.log.Log;
35  import com.liferay.portal.kernel.log.LogFactoryUtil;
36  import com.liferay.portal.kernel.util.GetterUtil;
37  import com.liferay.portal.kernel.util.OrderByComparator;
38  import com.liferay.portal.kernel.util.StringPool;
39  import com.liferay.portal.kernel.util.StringUtil;
40  import com.liferay.portal.model.ModelListener;
41  import com.liferay.portal.model.UserIdMapper;
42  import com.liferay.portal.model.impl.UserIdMapperImpl;
43  import com.liferay.portal.model.impl.UserIdMapperModelImpl;
44  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
45  
46  import java.util.ArrayList;
47  import java.util.Collections;
48  import java.util.Iterator;
49  import java.util.List;
50  
51  /**
52   * <a href="UserIdMapperPersistenceImpl.java.html"><b><i>View Source</i></b></a>
53   *
54   * @author Brian Wing Shun Chan
55   *
56   */
57  public class UserIdMapperPersistenceImpl extends BasePersistenceImpl
58      implements UserIdMapperPersistence {
59      public UserIdMapper create(long userIdMapperId) {
60          UserIdMapper userIdMapper = new UserIdMapperImpl();
61  
62          userIdMapper.setNew(true);
63          userIdMapper.setPrimaryKey(userIdMapperId);
64  
65          return userIdMapper;
66      }
67  
68      public UserIdMapper remove(long userIdMapperId)
69          throws NoSuchUserIdMapperException, SystemException {
70          Session session = null;
71  
72          try {
73              session = openSession();
74  
75              UserIdMapper userIdMapper = (UserIdMapper)session.get(UserIdMapperImpl.class,
76                      new Long(userIdMapperId));
77  
78              if (userIdMapper == null) {
79                  if (_log.isWarnEnabled()) {
80                      _log.warn("No UserIdMapper exists with the primary key " +
81                          userIdMapperId);
82                  }
83  
84                  throw new NoSuchUserIdMapperException(
85                      "No UserIdMapper exists with the primary key " +
86                      userIdMapperId);
87              }
88  
89              return remove(userIdMapper);
90          }
91          catch (NoSuchUserIdMapperException nsee) {
92              throw nsee;
93          }
94          catch (Exception e) {
95              throw processException(e);
96          }
97          finally {
98              closeSession(session);
99          }
100     }
101 
102     public UserIdMapper remove(UserIdMapper userIdMapper)
103         throws SystemException {
104         for (ModelListener listener : listeners) {
105             listener.onBeforeRemove(userIdMapper);
106         }
107 
108         userIdMapper = removeImpl(userIdMapper);
109 
110         for (ModelListener listener : listeners) {
111             listener.onAfterRemove(userIdMapper);
112         }
113 
114         return userIdMapper;
115     }
116 
117     protected UserIdMapper removeImpl(UserIdMapper userIdMapper)
118         throws SystemException {
119         Session session = null;
120 
121         try {
122             session = openSession();
123 
124             if (BatchSessionUtil.isEnabled()) {
125                 Object staleObject = session.get(UserIdMapperImpl.class,
126                         userIdMapper.getPrimaryKeyObj());
127 
128                 if (staleObject != null) {
129                     session.evict(staleObject);
130                 }
131             }
132 
133             session.delete(userIdMapper);
134 
135             session.flush();
136 
137             return userIdMapper;
138         }
139         catch (Exception e) {
140             throw processException(e);
141         }
142         finally {
143             closeSession(session);
144 
145             FinderCacheUtil.clearCache(UserIdMapper.class.getName());
146         }
147     }
148 
149     /**
150      * @deprecated Use <code>update(UserIdMapper userIdMapper, boolean merge)</code>.
151      */
152     public UserIdMapper update(UserIdMapper userIdMapper)
153         throws SystemException {
154         if (_log.isWarnEnabled()) {
155             _log.warn(
156                 "Using the deprecated update(UserIdMapper userIdMapper) method. Use update(UserIdMapper userIdMapper, boolean merge) instead.");
157         }
158 
159         return update(userIdMapper, false);
160     }
161 
162     /**
163      * Add, update, or merge, the entity. This method also calls the model
164      * listeners to trigger the proper events associated with adding, deleting,
165      * or updating an entity.
166      *
167      * @param        userIdMapper the entity to add, update, or merge
168      * @param        merge boolean value for whether to merge the entity. The
169      *                default value is false. Setting merge to true is more
170      *                expensive and should only be true when userIdMapper is
171      *                transient. See LEP-5473 for a detailed discussion of this
172      *                method.
173      * @return        true if the portlet can be displayed via Ajax
174      */
175     public UserIdMapper update(UserIdMapper userIdMapper, boolean merge)
176         throws SystemException {
177         boolean isNew = userIdMapper.isNew();
178 
179         for (ModelListener listener : listeners) {
180             if (isNew) {
181                 listener.onBeforeCreate(userIdMapper);
182             }
183             else {
184                 listener.onBeforeUpdate(userIdMapper);
185             }
186         }
187 
188         userIdMapper = updateImpl(userIdMapper, merge);
189 
190         for (ModelListener listener : listeners) {
191             if (isNew) {
192                 listener.onAfterCreate(userIdMapper);
193             }
194             else {
195                 listener.onAfterUpdate(userIdMapper);
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             BatchSessionUtil.update(session, userIdMapper, merge);
211 
212             userIdMapper.setNew(false);
213 
214             return userIdMapper;
215         }
216         catch (Exception e) {
217             throw processException(e);
218         }
219         finally {
220             closeSession(session);
221 
222             FinderCacheUtil.clearCache(UserIdMapper.class.getName());
223         }
224     }
225 
226     public UserIdMapper findByPrimaryKey(long userIdMapperId)
227         throws NoSuchUserIdMapperException, SystemException {
228         UserIdMapper userIdMapper = fetchByPrimaryKey(userIdMapperId);
229 
230         if (userIdMapper == null) {
231             if (_log.isWarnEnabled()) {
232                 _log.warn("No UserIdMapper exists with the primary key " +
233                     userIdMapperId);
234             }
235 
236             throw new NoSuchUserIdMapperException(
237                 "No UserIdMapper exists with the primary key " +
238                 userIdMapperId);
239         }
240 
241         return userIdMapper;
242     }
243 
244     public UserIdMapper fetchByPrimaryKey(long userIdMapperId)
245         throws SystemException {
246         Session session = null;
247 
248         try {
249             session = openSession();
250 
251             return (UserIdMapper)session.get(UserIdMapperImpl.class,
252                 new Long(userIdMapperId));
253         }
254         catch (Exception e) {
255             throw processException(e);
256         }
257         finally {
258             closeSession(session);
259         }
260     }
261 
262     public List<UserIdMapper> findByUserId(long userId)
263         throws SystemException {
264         boolean finderClassNameCacheEnabled = UserIdMapperModelImpl.CACHE_ENABLED;
265         String finderClassName = UserIdMapper.class.getName();
266         String finderMethodName = "findByUserId";
267         String[] finderParams = new String[] { Long.class.getName() };
268         Object[] finderArgs = new Object[] { new Long(userId) };
269 
270         Object result = null;
271 
272         if (finderClassNameCacheEnabled) {
273             result = FinderCacheUtil.getResult(finderClassName,
274                     finderMethodName, finderParams, finderArgs, this);
275         }
276 
277         if (result == null) {
278             Session session = null;
279 
280             try {
281                 session = openSession();
282 
283                 StringBuilder query = new StringBuilder();
284 
285                 query.append(
286                     "FROM com.liferay.portal.model.UserIdMapper WHERE ");
287 
288                 query.append("userId = ?");
289 
290                 query.append(" ");
291 
292                 Query q = session.createQuery(query.toString());
293 
294                 QueryPos qPos = QueryPos.getInstance(q);
295 
296                 qPos.add(userId);
297 
298                 List<UserIdMapper> list = q.list();
299 
300                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
301                     finderClassName, finderMethodName, finderParams,
302                     finderArgs, list);
303 
304                 return list;
305             }
306             catch (Exception e) {
307                 throw processException(e);
308             }
309             finally {
310                 closeSession(session);
311             }
312         }
313         else {
314             return (List<UserIdMapper>)result;
315         }
316     }
317 
318     public List<UserIdMapper> findByUserId(long userId, int start, int end)
319         throws SystemException {
320         return findByUserId(userId, start, end, null);
321     }
322 
323     public List<UserIdMapper> findByUserId(long userId, int start, int end,
324         OrderByComparator obc) throws SystemException {
325         boolean finderClassNameCacheEnabled = UserIdMapperModelImpl.CACHE_ENABLED;
326         String finderClassName = UserIdMapper.class.getName();
327         String finderMethodName = "findByUserId";
328         String[] finderParams = new String[] {
329                 Long.class.getName(),
330                 
331                 "java.lang.Integer", "java.lang.Integer",
332                 "com.liferay.portal.kernel.util.OrderByComparator"
333             };
334         Object[] finderArgs = new Object[] {
335                 new Long(userId),
336                 
337                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
338             };
339 
340         Object result = null;
341 
342         if (finderClassNameCacheEnabled) {
343             result = FinderCacheUtil.getResult(finderClassName,
344                     finderMethodName, finderParams, finderArgs, this);
345         }
346 
347         if (result == null) {
348             Session session = null;
349 
350             try {
351                 session = openSession();
352 
353                 StringBuilder query = new StringBuilder();
354 
355                 query.append(
356                     "FROM com.liferay.portal.model.UserIdMapper WHERE ");
357 
358                 query.append("userId = ?");
359 
360                 query.append(" ");
361 
362                 if (obc != null) {
363                     query.append("ORDER BY ");
364                     query.append(obc.getOrderBy());
365                 }
366 
367                 Query q = session.createQuery(query.toString());
368 
369                 QueryPos qPos = QueryPos.getInstance(q);
370 
371                 qPos.add(userId);
372 
373                 List<UserIdMapper> list = (List<UserIdMapper>)QueryUtil.list(q,
374                         getDialect(), start, end);
375 
376                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
377                     finderClassName, finderMethodName, finderParams,
378                     finderArgs, list);
379 
380                 return list;
381             }
382             catch (Exception e) {
383                 throw processException(e);
384             }
385             finally {
386                 closeSession(session);
387             }
388         }
389         else {
390             return (List<UserIdMapper>)result;
391         }
392     }
393 
394     public UserIdMapper findByUserId_First(long userId, OrderByComparator obc)
395         throws NoSuchUserIdMapperException, SystemException {
396         List<UserIdMapper> list = findByUserId(userId, 0, 1, obc);
397 
398         if (list.size() == 0) {
399             StringBuilder msg = new StringBuilder();
400 
401             msg.append("No UserIdMapper exists with the key {");
402 
403             msg.append("userId=" + userId);
404 
405             msg.append(StringPool.CLOSE_CURLY_BRACE);
406 
407             throw new NoSuchUserIdMapperException(msg.toString());
408         }
409         else {
410             return list.get(0);
411         }
412     }
413 
414     public UserIdMapper findByUserId_Last(long userId, OrderByComparator obc)
415         throws NoSuchUserIdMapperException, SystemException {
416         int count = countByUserId(userId);
417 
418         List<UserIdMapper> list = findByUserId(userId, count - 1, count, obc);
419 
420         if (list.size() == 0) {
421             StringBuilder msg = new StringBuilder();
422 
423             msg.append("No UserIdMapper exists with the key {");
424 
425             msg.append("userId=" + userId);
426 
427             msg.append(StringPool.CLOSE_CURLY_BRACE);
428 
429             throw new NoSuchUserIdMapperException(msg.toString());
430         }
431         else {
432             return list.get(0);
433         }
434     }
435 
436     public UserIdMapper[] findByUserId_PrevAndNext(long userIdMapperId,
437         long userId, OrderByComparator obc)
438         throws NoSuchUserIdMapperException, SystemException {
439         UserIdMapper userIdMapper = findByPrimaryKey(userIdMapperId);
440 
441         int count = countByUserId(userId);
442 
443         Session session = null;
444 
445         try {
446             session = openSession();
447 
448             StringBuilder query = new StringBuilder();
449 
450             query.append("FROM com.liferay.portal.model.UserIdMapper WHERE ");
451 
452             query.append("userId = ?");
453 
454             query.append(" ");
455 
456             if (obc != null) {
457                 query.append("ORDER BY ");
458                 query.append(obc.getOrderBy());
459             }
460 
461             Query q = session.createQuery(query.toString());
462 
463             QueryPos qPos = QueryPos.getInstance(q);
464 
465             qPos.add(userId);
466 
467             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
468                     userIdMapper);
469 
470             UserIdMapper[] array = new UserIdMapperImpl[3];
471 
472             array[0] = (UserIdMapper)objArray[0];
473             array[1] = (UserIdMapper)objArray[1];
474             array[2] = (UserIdMapper)objArray[2];
475 
476             return array;
477         }
478         catch (Exception e) {
479             throw processException(e);
480         }
481         finally {
482             closeSession(session);
483         }
484     }
485 
486     public UserIdMapper findByU_T(long userId, String type)
487         throws NoSuchUserIdMapperException, SystemException {
488         UserIdMapper userIdMapper = fetchByU_T(userId, type);
489 
490         if (userIdMapper == null) {
491             StringBuilder msg = new StringBuilder();
492 
493             msg.append("No UserIdMapper exists with the key {");
494 
495             msg.append("userId=" + userId);
496 
497             msg.append(", ");
498             msg.append("type=" + type);
499 
500             msg.append(StringPool.CLOSE_CURLY_BRACE);
501 
502             if (_log.isWarnEnabled()) {
503                 _log.warn(msg.toString());
504             }
505 
506             throw new NoSuchUserIdMapperException(msg.toString());
507         }
508 
509         return userIdMapper;
510     }
511 
512     public UserIdMapper fetchByU_T(long userId, String type)
513         throws SystemException {
514         boolean finderClassNameCacheEnabled = UserIdMapperModelImpl.CACHE_ENABLED;
515         String finderClassName = UserIdMapper.class.getName();
516         String finderMethodName = "fetchByU_T";
517         String[] finderParams = new String[] {
518                 Long.class.getName(), String.class.getName()
519             };
520         Object[] finderArgs = new Object[] { new Long(userId), type };
521 
522         Object result = null;
523 
524         if (finderClassNameCacheEnabled) {
525             result = FinderCacheUtil.getResult(finderClassName,
526                     finderMethodName, finderParams, finderArgs, this);
527         }
528 
529         if (result == null) {
530             Session session = null;
531 
532             try {
533                 session = openSession();
534 
535                 StringBuilder query = new StringBuilder();
536 
537                 query.append(
538                     "FROM com.liferay.portal.model.UserIdMapper WHERE ");
539 
540                 query.append("userId = ?");
541 
542                 query.append(" AND ");
543 
544                 if (type == null) {
545                     query.append("type_ IS NULL");
546                 }
547                 else {
548                     query.append("type_ = ?");
549                 }
550 
551                 query.append(" ");
552 
553                 Query q = session.createQuery(query.toString());
554 
555                 QueryPos qPos = QueryPos.getInstance(q);
556 
557                 qPos.add(userId);
558 
559                 if (type != null) {
560                     qPos.add(type);
561                 }
562 
563                 List<UserIdMapper> list = q.list();
564 
565                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
566                     finderClassName, finderMethodName, finderParams,
567                     finderArgs, list);
568 
569                 if (list.size() == 0) {
570                     return null;
571                 }
572                 else {
573                     return list.get(0);
574                 }
575             }
576             catch (Exception e) {
577                 throw processException(e);
578             }
579             finally {
580                 closeSession(session);
581             }
582         }
583         else {
584             List<UserIdMapper> list = (List<UserIdMapper>)result;
585 
586             if (list.size() == 0) {
587                 return null;
588             }
589             else {
590                 return list.get(0);
591             }
592         }
593     }
594 
595     public UserIdMapper findByT_E(String type, String externalUserId)
596         throws NoSuchUserIdMapperException, SystemException {
597         UserIdMapper userIdMapper = fetchByT_E(type, externalUserId);
598 
599         if (userIdMapper == null) {
600             StringBuilder msg = new StringBuilder();
601 
602             msg.append("No UserIdMapper exists with the key {");
603 
604             msg.append("type=" + type);
605 
606             msg.append(", ");
607             msg.append("externalUserId=" + externalUserId);
608 
609             msg.append(StringPool.CLOSE_CURLY_BRACE);
610 
611             if (_log.isWarnEnabled()) {
612                 _log.warn(msg.toString());
613             }
614 
615             throw new NoSuchUserIdMapperException(msg.toString());
616         }
617 
618         return userIdMapper;
619     }
620 
621     public UserIdMapper fetchByT_E(String type, String externalUserId)
622         throws SystemException {
623         boolean finderClassNameCacheEnabled = UserIdMapperModelImpl.CACHE_ENABLED;
624         String finderClassName = UserIdMapper.class.getName();
625         String finderMethodName = "fetchByT_E";
626         String[] finderParams = new String[] {
627                 String.class.getName(), String.class.getName()
628             };
629         Object[] finderArgs = new Object[] { type, externalUserId };
630 
631         Object result = null;
632 
633         if (finderClassNameCacheEnabled) {
634             result = FinderCacheUtil.getResult(finderClassName,
635                     finderMethodName, finderParams, finderArgs, this);
636         }
637 
638         if (result == null) {
639             Session session = null;
640 
641             try {
642                 session = openSession();
643 
644                 StringBuilder query = new StringBuilder();
645 
646                 query.append(
647                     "FROM com.liferay.portal.model.UserIdMapper WHERE ");
648 
649                 if (type == null) {
650                     query.append("type_ IS NULL");
651                 }
652                 else {
653                     query.append("type_ = ?");
654                 }
655 
656                 query.append(" AND ");
657 
658                 if (externalUserId == null) {
659                     query.append("externalUserId IS NULL");
660                 }
661                 else {
662                     query.append("externalUserId = ?");
663                 }
664 
665                 query.append(" ");
666 
667                 Query q = session.createQuery(query.toString());
668 
669                 QueryPos qPos = QueryPos.getInstance(q);
670 
671                 if (type != null) {
672                     qPos.add(type);
673                 }
674 
675                 if (externalUserId != null) {
676                     qPos.add(externalUserId);
677                 }
678 
679                 List<UserIdMapper> list = q.list();
680 
681                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
682                     finderClassName, finderMethodName, finderParams,
683                     finderArgs, list);
684 
685                 if (list.size() == 0) {
686                     return null;
687                 }
688                 else {
689                     return list.get(0);
690                 }
691             }
692             catch (Exception e) {
693                 throw processException(e);
694             }
695             finally {
696                 closeSession(session);
697             }
698         }
699         else {
700             List<UserIdMapper> list = (List<UserIdMapper>)result;
701 
702             if (list.size() == 0) {
703                 return null;
704             }
705             else {
706                 return list.get(0);
707             }
708         }
709     }
710 
711     public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
712         throws SystemException {
713         Session session = null;
714 
715         try {
716             session = openSession();
717 
718             dynamicQuery.compile(session);
719 
720             return dynamicQuery.list();
721         }
722         catch (Exception e) {
723             throw processException(e);
724         }
725         finally {
726             closeSession(session);
727         }
728     }
729 
730     public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
731         int start, int end) throws SystemException {
732         Session session = null;
733 
734         try {
735             session = openSession();
736 
737             dynamicQuery.setLimit(start, end);
738 
739             dynamicQuery.compile(session);
740 
741             return dynamicQuery.list();
742         }
743         catch (Exception e) {
744             throw processException(e);
745         }
746         finally {
747             closeSession(session);
748         }
749     }
750 
751     public List<UserIdMapper> findAll() throws SystemException {
752         return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
753     }
754 
755     public List<UserIdMapper> findAll(int start, int end)
756         throws SystemException {
757         return findAll(start, end, null);
758     }
759 
760     public List<UserIdMapper> findAll(int start, int end, OrderByComparator obc)
761         throws SystemException {
762         boolean finderClassNameCacheEnabled = UserIdMapperModelImpl.CACHE_ENABLED;
763         String finderClassName = UserIdMapper.class.getName();
764         String finderMethodName = "findAll";
765         String[] finderParams = new String[] {
766                 "java.lang.Integer", "java.lang.Integer",
767                 "com.liferay.portal.kernel.util.OrderByComparator"
768             };
769         Object[] finderArgs = new Object[] {
770                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
771             };
772 
773         Object result = null;
774 
775         if (finderClassNameCacheEnabled) {
776             result = FinderCacheUtil.getResult(finderClassName,
777                     finderMethodName, finderParams, finderArgs, this);
778         }
779 
780         if (result == null) {
781             Session session = null;
782 
783             try {
784                 session = openSession();
785 
786                 StringBuilder query = new StringBuilder();
787 
788                 query.append("FROM com.liferay.portal.model.UserIdMapper ");
789 
790                 if (obc != null) {
791                     query.append("ORDER BY ");
792                     query.append(obc.getOrderBy());
793                 }
794 
795                 Query q = session.createQuery(query.toString());
796 
797                 List<UserIdMapper> list = null;
798 
799                 if (obc == null) {
800                     list = (List<UserIdMapper>)QueryUtil.list(q, getDialect(),
801                             start, end, false);
802 
803                     Collections.sort(list);
804                 }
805                 else {
806                     list = (List<UserIdMapper>)QueryUtil.list(q, getDialect(),
807                             start, end);
808                 }
809 
810                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
811                     finderClassName, finderMethodName, finderParams,
812                     finderArgs, list);
813 
814                 return list;
815             }
816             catch (Exception e) {
817                 throw processException(e);
818             }
819             finally {
820                 closeSession(session);
821             }
822         }
823         else {
824             return (List<UserIdMapper>)result;
825         }
826     }
827 
828     public void removeByUserId(long userId) throws SystemException {
829         for (UserIdMapper userIdMapper : findByUserId(userId)) {
830             remove(userIdMapper);
831         }
832     }
833 
834     public void removeByU_T(long userId, String type)
835         throws NoSuchUserIdMapperException, SystemException {
836         UserIdMapper userIdMapper = findByU_T(userId, type);
837 
838         remove(userIdMapper);
839     }
840 
841     public void removeByT_E(String type, String externalUserId)
842         throws NoSuchUserIdMapperException, SystemException {
843         UserIdMapper userIdMapper = findByT_E(type, externalUserId);
844 
845         remove(userIdMapper);
846     }
847 
848     public void removeAll() throws SystemException {
849         for (UserIdMapper userIdMapper : findAll()) {
850             remove(userIdMapper);
851         }
852     }
853 
854     public int countByUserId(long userId) throws SystemException {
855         boolean finderClassNameCacheEnabled = UserIdMapperModelImpl.CACHE_ENABLED;
856         String finderClassName = UserIdMapper.class.getName();
857         String finderMethodName = "countByUserId";
858         String[] finderParams = new String[] { Long.class.getName() };
859         Object[] finderArgs = new Object[] { new Long(userId) };
860 
861         Object result = null;
862 
863         if (finderClassNameCacheEnabled) {
864             result = FinderCacheUtil.getResult(finderClassName,
865                     finderMethodName, finderParams, finderArgs, this);
866         }
867 
868         if (result == null) {
869             Session session = null;
870 
871             try {
872                 session = openSession();
873 
874                 StringBuilder query = new StringBuilder();
875 
876                 query.append("SELECT COUNT(*) ");
877                 query.append(
878                     "FROM com.liferay.portal.model.UserIdMapper WHERE ");
879 
880                 query.append("userId = ?");
881 
882                 query.append(" ");
883 
884                 Query q = session.createQuery(query.toString());
885 
886                 QueryPos qPos = QueryPos.getInstance(q);
887 
888                 qPos.add(userId);
889 
890                 Long count = null;
891 
892                 Iterator<Long> itr = q.list().iterator();
893 
894                 if (itr.hasNext()) {
895                     count = itr.next();
896                 }
897 
898                 if (count == null) {
899                     count = new Long(0);
900                 }
901 
902                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
903                     finderClassName, finderMethodName, finderParams,
904                     finderArgs, count);
905 
906                 return count.intValue();
907             }
908             catch (Exception e) {
909                 throw processException(e);
910             }
911             finally {
912                 closeSession(session);
913             }
914         }
915         else {
916             return ((Long)result).intValue();
917         }
918     }
919 
920     public int countByU_T(long userId, String type) throws SystemException {
921         boolean finderClassNameCacheEnabled = UserIdMapperModelImpl.CACHE_ENABLED;
922         String finderClassName = UserIdMapper.class.getName();
923         String finderMethodName = "countByU_T";
924         String[] finderParams = new String[] {
925                 Long.class.getName(), String.class.getName()
926             };
927         Object[] finderArgs = new Object[] { new Long(userId), type };
928 
929         Object result = null;
930 
931         if (finderClassNameCacheEnabled) {
932             result = FinderCacheUtil.getResult(finderClassName,
933                     finderMethodName, finderParams, finderArgs, this);
934         }
935 
936         if (result == null) {
937             Session session = null;
938 
939             try {
940                 session = openSession();
941 
942                 StringBuilder query = new StringBuilder();
943 
944                 query.append("SELECT COUNT(*) ");
945                 query.append(
946                     "FROM com.liferay.portal.model.UserIdMapper WHERE ");
947 
948                 query.append("userId = ?");
949 
950                 query.append(" AND ");
951 
952                 if (type == null) {
953                     query.append("type_ IS NULL");
954                 }
955                 else {
956                     query.append("type_ = ?");
957                 }
958 
959                 query.append(" ");
960 
961                 Query q = session.createQuery(query.toString());
962 
963                 QueryPos qPos = QueryPos.getInstance(q);
964 
965                 qPos.add(userId);
966 
967                 if (type != null) {
968                     qPos.add(type);
969                 }
970 
971                 Long count = null;
972 
973                 Iterator<Long> itr = q.list().iterator();
974 
975                 if (itr.hasNext()) {
976                     count = itr.next();
977                 }
978 
979                 if (count == null) {
980                     count = new Long(0);
981                 }
982 
983                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
984                     finderClassName, finderMethodName, finderParams,
985                     finderArgs, count);
986 
987                 return count.intValue();
988             }
989             catch (Exception e) {
990                 throw processException(e);
991             }
992             finally {
993                 closeSession(session);
994             }
995         }
996         else {
997             return ((Long)result).intValue();
998         }
999     }
1000
1001    public int countByT_E(String type, String externalUserId)
1002        throws SystemException {
1003        boolean finderClassNameCacheEnabled = UserIdMapperModelImpl.CACHE_ENABLED;
1004        String finderClassName = UserIdMapper.class.getName();
1005        String finderMethodName = "countByT_E";
1006        String[] finderParams = new String[] {
1007                String.class.getName(), String.class.getName()
1008            };
1009        Object[] finderArgs = new Object[] { type, externalUserId };
1010
1011        Object result = null;
1012
1013        if (finderClassNameCacheEnabled) {
1014            result = FinderCacheUtil.getResult(finderClassName,
1015                    finderMethodName, finderParams, finderArgs, this);
1016        }
1017
1018        if (result == null) {
1019            Session session = null;
1020
1021            try {
1022                session = openSession();
1023
1024                StringBuilder query = new StringBuilder();
1025
1026                query.append("SELECT COUNT(*) ");
1027                query.append(
1028                    "FROM com.liferay.portal.model.UserIdMapper WHERE ");
1029
1030                if (type == null) {
1031                    query.append("type_ IS NULL");
1032                }
1033                else {
1034                    query.append("type_ = ?");
1035                }
1036
1037                query.append(" AND ");
1038
1039                if (externalUserId == null) {
1040                    query.append("externalUserId IS NULL");
1041                }
1042                else {
1043                    query.append("externalUserId = ?");
1044                }
1045
1046                query.append(" ");
1047
1048                Query q = session.createQuery(query.toString());
1049
1050                QueryPos qPos = QueryPos.getInstance(q);
1051
1052                if (type != null) {
1053                    qPos.add(type);
1054                }
1055
1056                if (externalUserId != null) {
1057                    qPos.add(externalUserId);
1058                }
1059
1060                Long count = null;
1061
1062                Iterator<Long> itr = q.list().iterator();
1063
1064                if (itr.hasNext()) {
1065                    count = itr.next();
1066                }
1067
1068                if (count == null) {
1069                    count = new Long(0);
1070                }
1071
1072                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1073                    finderClassName, finderMethodName, finderParams,
1074                    finderArgs, count);
1075
1076                return count.intValue();
1077            }
1078            catch (Exception e) {
1079                throw processException(e);
1080            }
1081            finally {
1082                closeSession(session);
1083            }
1084        }
1085        else {
1086            return ((Long)result).intValue();
1087        }
1088    }
1089
1090    public int countAll() throws SystemException {
1091        boolean finderClassNameCacheEnabled = UserIdMapperModelImpl.CACHE_ENABLED;
1092        String finderClassName = UserIdMapper.class.getName();
1093        String finderMethodName = "countAll";
1094        String[] finderParams = new String[] {  };
1095        Object[] finderArgs = new Object[] {  };
1096
1097        Object result = null;
1098
1099        if (finderClassNameCacheEnabled) {
1100            result = FinderCacheUtil.getResult(finderClassName,
1101                    finderMethodName, finderParams, finderArgs, this);
1102        }
1103
1104        if (result == null) {
1105            Session session = null;
1106
1107            try {
1108                session = openSession();
1109
1110                Query q = session.createQuery(
1111                        "SELECT COUNT(*) FROM com.liferay.portal.model.UserIdMapper");
1112
1113                Long count = null;
1114
1115                Iterator<Long> itr = q.list().iterator();
1116
1117                if (itr.hasNext()) {
1118                    count = itr.next();
1119                }
1120
1121                if (count == null) {
1122                    count = new Long(0);
1123                }
1124
1125                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1126                    finderClassName, finderMethodName, finderParams,
1127                    finderArgs, count);
1128
1129                return count.intValue();
1130            }
1131            catch (Exception e) {
1132                throw processException(e);
1133            }
1134            finally {
1135                closeSession(session);
1136            }
1137        }
1138        else {
1139            return ((Long)result).intValue();
1140        }
1141    }
1142
1143    public void afterPropertiesSet() {
1144        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1145                    com.liferay.portal.util.PropsUtil.get(
1146                        "value.object.listener.com.liferay.portal.model.UserIdMapper")));
1147
1148        if (listenerClassNames.length > 0) {
1149            try {
1150                List<ModelListener> listenersList = new ArrayList<ModelListener>();
1151
1152                for (String listenerClassName : listenerClassNames) {
1153                    listenersList.add((ModelListener)Class.forName(
1154                            listenerClassName).newInstance());
1155                }
1156
1157                listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1158            }
1159            catch (Exception e) {
1160                _log.error(e);
1161            }
1162        }
1163    }
1164
1165    @BeanReference(name = "com.liferay.portal.service.persistence.AccountPersistence.impl")
1166    protected com.liferay.portal.service.persistence.AccountPersistence accountPersistence;
1167    @BeanReference(name = "com.liferay.portal.service.persistence.AddressPersistence.impl")
1168    protected com.liferay.portal.service.persistence.AddressPersistence addressPersistence;
1169    @BeanReference(name = "com.liferay.portal.service.persistence.ClassNamePersistence.impl")
1170    protected com.liferay.portal.service.persistence.ClassNamePersistence classNamePersistence;
1171    @BeanReference(name = "com.liferay.portal.service.persistence.CompanyPersistence.impl")
1172    protected com.liferay.portal.service.persistence.CompanyPersistence companyPersistence;
1173    @BeanReference(name = "com.liferay.portal.service.persistence.ContactPersistence.impl")
1174    protected com.liferay.portal.service.persistence.ContactPersistence contactPersistence;
1175    @BeanReference(name = "com.liferay.portal.service.persistence.CountryPersistence.impl")
1176    protected com.liferay.portal.service.persistence.CountryPersistence countryPersistence;
1177    @BeanReference(name = "com.liferay.portal.service.persistence.EmailAddressPersistence.impl")
1178    protected com.liferay.portal.service.persistence.EmailAddressPersistence emailAddressPersistence;
1179    @BeanReference(name = "com.liferay.portal.service.persistence.GroupPersistence.impl")
1180    protected com.liferay.portal.service.persistence.GroupPersistence groupPersistence;
1181    @BeanReference(name = "com.liferay.portal.service.persistence.ImagePersistence.impl")
1182    protected com.liferay.portal.service.persistence.ImagePersistence imagePersistence;
1183    @BeanReference(name = "com.liferay.portal.service.persistence.LayoutPersistence.impl")
1184    protected com.liferay.portal.service.persistence.LayoutPersistence layoutPersistence;
1185    @BeanReference(name = "com.liferay.portal.service.persistence.LayoutSetPersistence.impl")
1186    protected com.liferay.portal.service.persistence.LayoutSetPersistence layoutSetPersistence;
1187    @BeanReference(name = "com.liferay.portal.service.persistence.ListTypePersistence.impl")
1188    protected com.liferay.portal.service.persistence.ListTypePersistence listTypePersistence;
1189    @BeanReference(name = "com.liferay.portal.service.persistence.MembershipRequestPersistence.impl")
1190    protected com.liferay.portal.service.persistence.MembershipRequestPersistence membershipRequestPersistence;
1191    @BeanReference(name = "com.liferay.portal.service.persistence.OrganizationPersistence.impl")
1192    protected com.liferay.portal.service.persistence.OrganizationPersistence organizationPersistence;
1193    @BeanReference(name = "com.liferay.portal.service.persistence.OrgGroupPermissionPersistence.impl")
1194    protected com.liferay.portal.service.persistence.OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1195    @BeanReference(name = "com.liferay.portal.service.persistence.OrgGroupRolePersistence.impl")
1196    protected com.liferay.portal.service.persistence.OrgGroupRolePersistence orgGroupRolePersistence;
1197    @BeanReference(name = "com.liferay.portal.service.persistence.OrgLaborPersistence.impl")
1198    protected com.liferay.portal.service.persistence.OrgLaborPersistence orgLaborPersistence;
1199    @BeanReference(name = "com.liferay.portal.service.persistence.PasswordPolicyPersistence.impl")
1200    protected com.liferay.portal.service.persistence.PasswordPolicyPersistence passwordPolicyPersistence;
1201    @BeanReference(name = "com.liferay.portal.service.persistence.PasswordPolicyRelPersistence.impl")
1202    protected com.liferay.portal.service.persistence.PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1203    @BeanReference(name = "com.liferay.portal.service.persistence.PasswordTrackerPersistence.impl")
1204    protected com.liferay.portal.service.persistence.PasswordTrackerPersistence passwordTrackerPersistence;
1205    @BeanReference(name = "com.liferay.portal.service.persistence.PermissionPersistence.impl")
1206    protected com.liferay.portal.service.persistence.PermissionPersistence permissionPersistence;
1207    @BeanReference(name = "com.liferay.portal.service.persistence.PhonePersistence.impl")
1208    protected com.liferay.portal.service.persistence.PhonePersistence phonePersistence;
1209    @BeanReference(name = "com.liferay.portal.service.persistence.PluginSettingPersistence.impl")
1210    protected com.liferay.portal.service.persistence.PluginSettingPersistence pluginSettingPersistence;
1211    @BeanReference(name = "com.liferay.portal.service.persistence.PortletPersistence.impl")
1212    protected com.liferay.portal.service.persistence.PortletPersistence portletPersistence;
1213    @BeanReference(name = "com.liferay.portal.service.persistence.PortletPreferencesPersistence.impl")
1214    protected com.liferay.portal.service.persistence.PortletPreferencesPersistence portletPreferencesPersistence;
1215    @BeanReference(name = "com.liferay.portal.service.persistence.RegionPersistence.impl")
1216    protected com.liferay.portal.service.persistence.RegionPersistence regionPersistence;
1217    @BeanReference(name = "com.liferay.portal.service.persistence.ReleasePersistence.impl")
1218    protected com.liferay.portal.service.persistence.ReleasePersistence releasePersistence;
1219    @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePersistence.impl")
1220    protected com.liferay.portal.service.persistence.ResourcePersistence resourcePersistence;
1221    @BeanReference(name = "com.liferay.portal.service.persistence.ResourceCodePersistence.impl")
1222    protected com.liferay.portal.service.persistence.ResourceCodePersistence resourceCodePersistence;
1223    @BeanReference(name = "com.liferay.portal.service.persistence.RolePersistence.impl")
1224    protected com.liferay.portal.service.persistence.RolePersistence rolePersistence;
1225    @BeanReference(name = "com.liferay.portal.service.persistence.ServiceComponentPersistence.impl")
1226    protected com.liferay.portal.service.persistence.ServiceComponentPersistence serviceComponentPersistence;
1227    @BeanReference(name = "com.liferay.portal.service.persistence.PortletItemPersistence.impl")
1228    protected com.liferay.portal.service.persistence.PortletItemPersistence portletItemPersistence;
1229    @BeanReference(name = "com.liferay.portal.service.persistence.SubscriptionPersistence.impl")
1230    protected com.liferay.portal.service.persistence.SubscriptionPersistence subscriptionPersistence;
1231    @BeanReference(name = "com.liferay.portal.service.persistence.UserPersistence.impl")
1232    protected com.liferay.portal.service.persistence.UserPersistence userPersistence;
1233    @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupPersistence.impl")
1234    protected com.liferay.portal.service.persistence.UserGroupPersistence userGroupPersistence;
1235    @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupRolePersistence.impl")
1236    protected com.liferay.portal.service.persistence.UserGroupRolePersistence userGroupRolePersistence;
1237    @BeanReference(name = "com.liferay.portal.service.persistence.UserIdMapperPersistence.impl")
1238    protected com.liferay.portal.service.persistence.UserIdMapperPersistence userIdMapperPersistence;
1239    @BeanReference(name = "com.liferay.portal.service.persistence.UserTrackerPersistence.impl")
1240    protected com.liferay.portal.service.persistence.UserTrackerPersistence userTrackerPersistence;
1241    @BeanReference(name = "com.liferay.portal.service.persistence.UserTrackerPathPersistence.impl")
1242    protected com.liferay.portal.service.persistence.UserTrackerPathPersistence userTrackerPathPersistence;
1243    @BeanReference(name = "com.liferay.portal.service.persistence.WebDAVPropsPersistence.impl")
1244    protected com.liferay.portal.service.persistence.WebDAVPropsPersistence webDAVPropsPersistence;
1245    @BeanReference(name = "com.liferay.portal.service.persistence.WebsitePersistence.impl")
1246    protected com.liferay.portal.service.persistence.WebsitePersistence websitePersistence;
1247    private static Log _log = LogFactoryUtil.getLog(UserIdMapperPersistenceImpl.class);
1248}