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.NoSuchUserTrackerException;
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.UserTracker;
42  import com.liferay.portal.model.impl.UserTrackerImpl;
43  import com.liferay.portal.model.impl.UserTrackerModelImpl;
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="UserTrackerPersistenceImpl.java.html"><b><i>View Source</i></b></a>
53   *
54   * @author Brian Wing Shun Chan
55   *
56   */
57  public class UserTrackerPersistenceImpl extends BasePersistenceImpl
58      implements UserTrackerPersistence {
59      public UserTracker create(long userTrackerId) {
60          UserTracker userTracker = new UserTrackerImpl();
61  
62          userTracker.setNew(true);
63          userTracker.setPrimaryKey(userTrackerId);
64  
65          return userTracker;
66      }
67  
68      public UserTracker remove(long userTrackerId)
69          throws NoSuchUserTrackerException, SystemException {
70          Session session = null;
71  
72          try {
73              session = openSession();
74  
75              UserTracker userTracker = (UserTracker)session.get(UserTrackerImpl.class,
76                      new Long(userTrackerId));
77  
78              if (userTracker == null) {
79                  if (_log.isWarnEnabled()) {
80                      _log.warn("No UserTracker exists with the primary key " +
81                          userTrackerId);
82                  }
83  
84                  throw new NoSuchUserTrackerException(
85                      "No UserTracker exists with the primary key " +
86                      userTrackerId);
87              }
88  
89              return remove(userTracker);
90          }
91          catch (NoSuchUserTrackerException nsee) {
92              throw nsee;
93          }
94          catch (Exception e) {
95              throw processException(e);
96          }
97          finally {
98              closeSession(session);
99          }
100     }
101 
102     public UserTracker remove(UserTracker userTracker)
103         throws SystemException {
104         for (ModelListener listener : listeners) {
105             listener.onBeforeRemove(userTracker);
106         }
107 
108         userTracker = removeImpl(userTracker);
109 
110         for (ModelListener listener : listeners) {
111             listener.onAfterRemove(userTracker);
112         }
113 
114         return userTracker;
115     }
116 
117     protected UserTracker removeImpl(UserTracker userTracker)
118         throws SystemException {
119         Session session = null;
120 
121         try {
122             session = openSession();
123 
124             if (BatchSessionUtil.isEnabled()) {
125                 Object staleObject = session.get(UserTrackerImpl.class,
126                         userTracker.getPrimaryKeyObj());
127 
128                 if (staleObject != null) {
129                     session.evict(staleObject);
130                 }
131             }
132 
133             session.delete(userTracker);
134 
135             session.flush();
136 
137             return userTracker;
138         }
139         catch (Exception e) {
140             throw processException(e);
141         }
142         finally {
143             closeSession(session);
144 
145             FinderCacheUtil.clearCache(UserTracker.class.getName());
146         }
147     }
148 
149     /**
150      * @deprecated Use <code>update(UserTracker userTracker, boolean merge)</code>.
151      */
152     public UserTracker update(UserTracker userTracker)
153         throws SystemException {
154         if (_log.isWarnEnabled()) {
155             _log.warn(
156                 "Using the deprecated update(UserTracker userTracker) method. Use update(UserTracker userTracker, boolean merge) instead.");
157         }
158 
159         return update(userTracker, 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        userTracker 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 userTracker 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 UserTracker update(UserTracker userTracker, boolean merge)
176         throws SystemException {
177         boolean isNew = userTracker.isNew();
178 
179         for (ModelListener listener : listeners) {
180             if (isNew) {
181                 listener.onBeforeCreate(userTracker);
182             }
183             else {
184                 listener.onBeforeUpdate(userTracker);
185             }
186         }
187 
188         userTracker = updateImpl(userTracker, merge);
189 
190         for (ModelListener listener : listeners) {
191             if (isNew) {
192                 listener.onAfterCreate(userTracker);
193             }
194             else {
195                 listener.onAfterUpdate(userTracker);
196             }
197         }
198 
199         return userTracker;
200     }
201 
202     public UserTracker updateImpl(
203         com.liferay.portal.model.UserTracker userTracker, boolean merge)
204         throws SystemException {
205         Session session = null;
206 
207         try {
208             session = openSession();
209 
210             BatchSessionUtil.update(session, userTracker, merge);
211 
212             userTracker.setNew(false);
213 
214             return userTracker;
215         }
216         catch (Exception e) {
217             throw processException(e);
218         }
219         finally {
220             closeSession(session);
221 
222             FinderCacheUtil.clearCache(UserTracker.class.getName());
223         }
224     }
225 
226     public UserTracker findByPrimaryKey(long userTrackerId)
227         throws NoSuchUserTrackerException, SystemException {
228         UserTracker userTracker = fetchByPrimaryKey(userTrackerId);
229 
230         if (userTracker == null) {
231             if (_log.isWarnEnabled()) {
232                 _log.warn("No UserTracker exists with the primary key " +
233                     userTrackerId);
234             }
235 
236             throw new NoSuchUserTrackerException(
237                 "No UserTracker exists with the primary key " + userTrackerId);
238         }
239 
240         return userTracker;
241     }
242 
243     public UserTracker fetchByPrimaryKey(long userTrackerId)
244         throws SystemException {
245         Session session = null;
246 
247         try {
248             session = openSession();
249 
250             return (UserTracker)session.get(UserTrackerImpl.class,
251                 new Long(userTrackerId));
252         }
253         catch (Exception e) {
254             throw processException(e);
255         }
256         finally {
257             closeSession(session);
258         }
259     }
260 
261     public List<UserTracker> findByCompanyId(long companyId)
262         throws SystemException {
263         boolean finderClassNameCacheEnabled = UserTrackerModelImpl.CACHE_ENABLED;
264         String finderClassName = UserTracker.class.getName();
265         String finderMethodName = "findByCompanyId";
266         String[] finderParams = new String[] { Long.class.getName() };
267         Object[] finderArgs = new Object[] { new Long(companyId) };
268 
269         Object result = null;
270 
271         if (finderClassNameCacheEnabled) {
272             result = FinderCacheUtil.getResult(finderClassName,
273                     finderMethodName, finderParams, finderArgs, this);
274         }
275 
276         if (result == null) {
277             Session session = null;
278 
279             try {
280                 session = openSession();
281 
282                 StringBuilder query = new StringBuilder();
283 
284                 query.append("FROM com.liferay.portal.model.UserTracker WHERE ");
285 
286                 query.append("companyId = ?");
287 
288                 query.append(" ");
289 
290                 Query q = session.createQuery(query.toString());
291 
292                 QueryPos qPos = QueryPos.getInstance(q);
293 
294                 qPos.add(companyId);
295 
296                 List<UserTracker> list = q.list();
297 
298                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
299                     finderClassName, finderMethodName, finderParams,
300                     finderArgs, list);
301 
302                 return list;
303             }
304             catch (Exception e) {
305                 throw processException(e);
306             }
307             finally {
308                 closeSession(session);
309             }
310         }
311         else {
312             return (List<UserTracker>)result;
313         }
314     }
315 
316     public List<UserTracker> findByCompanyId(long companyId, int start, int end)
317         throws SystemException {
318         return findByCompanyId(companyId, start, end, null);
319     }
320 
321     public List<UserTracker> findByCompanyId(long companyId, int start,
322         int end, OrderByComparator obc) throws SystemException {
323         boolean finderClassNameCacheEnabled = UserTrackerModelImpl.CACHE_ENABLED;
324         String finderClassName = UserTracker.class.getName();
325         String finderMethodName = "findByCompanyId";
326         String[] finderParams = new String[] {
327                 Long.class.getName(),
328                 
329                 "java.lang.Integer", "java.lang.Integer",
330                 "com.liferay.portal.kernel.util.OrderByComparator"
331             };
332         Object[] finderArgs = new Object[] {
333                 new Long(companyId),
334                 
335                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
336             };
337 
338         Object result = null;
339 
340         if (finderClassNameCacheEnabled) {
341             result = FinderCacheUtil.getResult(finderClassName,
342                     finderMethodName, finderParams, finderArgs, this);
343         }
344 
345         if (result == null) {
346             Session session = null;
347 
348             try {
349                 session = openSession();
350 
351                 StringBuilder query = new StringBuilder();
352 
353                 query.append("FROM com.liferay.portal.model.UserTracker WHERE ");
354 
355                 query.append("companyId = ?");
356 
357                 query.append(" ");
358 
359                 if (obc != null) {
360                     query.append("ORDER BY ");
361                     query.append(obc.getOrderBy());
362                 }
363 
364                 Query q = session.createQuery(query.toString());
365 
366                 QueryPos qPos = QueryPos.getInstance(q);
367 
368                 qPos.add(companyId);
369 
370                 List<UserTracker> list = (List<UserTracker>)QueryUtil.list(q,
371                         getDialect(), start, end);
372 
373                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
374                     finderClassName, finderMethodName, finderParams,
375                     finderArgs, list);
376 
377                 return list;
378             }
379             catch (Exception e) {
380                 throw processException(e);
381             }
382             finally {
383                 closeSession(session);
384             }
385         }
386         else {
387             return (List<UserTracker>)result;
388         }
389     }
390 
391     public UserTracker findByCompanyId_First(long companyId,
392         OrderByComparator obc)
393         throws NoSuchUserTrackerException, SystemException {
394         List<UserTracker> list = findByCompanyId(companyId, 0, 1, obc);
395 
396         if (list.size() == 0) {
397             StringBuilder msg = new StringBuilder();
398 
399             msg.append("No UserTracker exists with the key {");
400 
401             msg.append("companyId=" + companyId);
402 
403             msg.append(StringPool.CLOSE_CURLY_BRACE);
404 
405             throw new NoSuchUserTrackerException(msg.toString());
406         }
407         else {
408             return list.get(0);
409         }
410     }
411 
412     public UserTracker findByCompanyId_Last(long companyId,
413         OrderByComparator obc)
414         throws NoSuchUserTrackerException, SystemException {
415         int count = countByCompanyId(companyId);
416 
417         List<UserTracker> list = findByCompanyId(companyId, count - 1, count,
418                 obc);
419 
420         if (list.size() == 0) {
421             StringBuilder msg = new StringBuilder();
422 
423             msg.append("No UserTracker exists with the key {");
424 
425             msg.append("companyId=" + companyId);
426 
427             msg.append(StringPool.CLOSE_CURLY_BRACE);
428 
429             throw new NoSuchUserTrackerException(msg.toString());
430         }
431         else {
432             return list.get(0);
433         }
434     }
435 
436     public UserTracker[] findByCompanyId_PrevAndNext(long userTrackerId,
437         long companyId, OrderByComparator obc)
438         throws NoSuchUserTrackerException, SystemException {
439         UserTracker userTracker = findByPrimaryKey(userTrackerId);
440 
441         int count = countByCompanyId(companyId);
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.UserTracker WHERE ");
451 
452             query.append("companyId = ?");
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(companyId);
466 
467             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
468                     userTracker);
469 
470             UserTracker[] array = new UserTrackerImpl[3];
471 
472             array[0] = (UserTracker)objArray[0];
473             array[1] = (UserTracker)objArray[1];
474             array[2] = (UserTracker)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 List<UserTracker> findByUserId(long userId)
487         throws SystemException {
488         boolean finderClassNameCacheEnabled = UserTrackerModelImpl.CACHE_ENABLED;
489         String finderClassName = UserTracker.class.getName();
490         String finderMethodName = "findByUserId";
491         String[] finderParams = new String[] { Long.class.getName() };
492         Object[] finderArgs = new Object[] { new Long(userId) };
493 
494         Object result = null;
495 
496         if (finderClassNameCacheEnabled) {
497             result = FinderCacheUtil.getResult(finderClassName,
498                     finderMethodName, finderParams, finderArgs, this);
499         }
500 
501         if (result == null) {
502             Session session = null;
503 
504             try {
505                 session = openSession();
506 
507                 StringBuilder query = new StringBuilder();
508 
509                 query.append("FROM com.liferay.portal.model.UserTracker WHERE ");
510 
511                 query.append("userId = ?");
512 
513                 query.append(" ");
514 
515                 Query q = session.createQuery(query.toString());
516 
517                 QueryPos qPos = QueryPos.getInstance(q);
518 
519                 qPos.add(userId);
520 
521                 List<UserTracker> list = q.list();
522 
523                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
524                     finderClassName, finderMethodName, finderParams,
525                     finderArgs, list);
526 
527                 return list;
528             }
529             catch (Exception e) {
530                 throw processException(e);
531             }
532             finally {
533                 closeSession(session);
534             }
535         }
536         else {
537             return (List<UserTracker>)result;
538         }
539     }
540 
541     public List<UserTracker> findByUserId(long userId, int start, int end)
542         throws SystemException {
543         return findByUserId(userId, start, end, null);
544     }
545 
546     public List<UserTracker> findByUserId(long userId, int start, int end,
547         OrderByComparator obc) throws SystemException {
548         boolean finderClassNameCacheEnabled = UserTrackerModelImpl.CACHE_ENABLED;
549         String finderClassName = UserTracker.class.getName();
550         String finderMethodName = "findByUserId";
551         String[] finderParams = new String[] {
552                 Long.class.getName(),
553                 
554                 "java.lang.Integer", "java.lang.Integer",
555                 "com.liferay.portal.kernel.util.OrderByComparator"
556             };
557         Object[] finderArgs = new Object[] {
558                 new Long(userId),
559                 
560                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
561             };
562 
563         Object result = null;
564 
565         if (finderClassNameCacheEnabled) {
566             result = FinderCacheUtil.getResult(finderClassName,
567                     finderMethodName, finderParams, finderArgs, this);
568         }
569 
570         if (result == null) {
571             Session session = null;
572 
573             try {
574                 session = openSession();
575 
576                 StringBuilder query = new StringBuilder();
577 
578                 query.append("FROM com.liferay.portal.model.UserTracker WHERE ");
579 
580                 query.append("userId = ?");
581 
582                 query.append(" ");
583 
584                 if (obc != null) {
585                     query.append("ORDER BY ");
586                     query.append(obc.getOrderBy());
587                 }
588 
589                 Query q = session.createQuery(query.toString());
590 
591                 QueryPos qPos = QueryPos.getInstance(q);
592 
593                 qPos.add(userId);
594 
595                 List<UserTracker> list = (List<UserTracker>)QueryUtil.list(q,
596                         getDialect(), start, end);
597 
598                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
599                     finderClassName, finderMethodName, finderParams,
600                     finderArgs, list);
601 
602                 return list;
603             }
604             catch (Exception e) {
605                 throw processException(e);
606             }
607             finally {
608                 closeSession(session);
609             }
610         }
611         else {
612             return (List<UserTracker>)result;
613         }
614     }
615 
616     public UserTracker findByUserId_First(long userId, OrderByComparator obc)
617         throws NoSuchUserTrackerException, SystemException {
618         List<UserTracker> list = findByUserId(userId, 0, 1, obc);
619 
620         if (list.size() == 0) {
621             StringBuilder msg = new StringBuilder();
622 
623             msg.append("No UserTracker exists with the key {");
624 
625             msg.append("userId=" + userId);
626 
627             msg.append(StringPool.CLOSE_CURLY_BRACE);
628 
629             throw new NoSuchUserTrackerException(msg.toString());
630         }
631         else {
632             return list.get(0);
633         }
634     }
635 
636     public UserTracker findByUserId_Last(long userId, OrderByComparator obc)
637         throws NoSuchUserTrackerException, SystemException {
638         int count = countByUserId(userId);
639 
640         List<UserTracker> list = findByUserId(userId, count - 1, count, obc);
641 
642         if (list.size() == 0) {
643             StringBuilder msg = new StringBuilder();
644 
645             msg.append("No UserTracker exists with the key {");
646 
647             msg.append("userId=" + userId);
648 
649             msg.append(StringPool.CLOSE_CURLY_BRACE);
650 
651             throw new NoSuchUserTrackerException(msg.toString());
652         }
653         else {
654             return list.get(0);
655         }
656     }
657 
658     public UserTracker[] findByUserId_PrevAndNext(long userTrackerId,
659         long userId, OrderByComparator obc)
660         throws NoSuchUserTrackerException, SystemException {
661         UserTracker userTracker = findByPrimaryKey(userTrackerId);
662 
663         int count = countByUserId(userId);
664 
665         Session session = null;
666 
667         try {
668             session = openSession();
669 
670             StringBuilder query = new StringBuilder();
671 
672             query.append("FROM com.liferay.portal.model.UserTracker WHERE ");
673 
674             query.append("userId = ?");
675 
676             query.append(" ");
677 
678             if (obc != null) {
679                 query.append("ORDER BY ");
680                 query.append(obc.getOrderBy());
681             }
682 
683             Query q = session.createQuery(query.toString());
684 
685             QueryPos qPos = QueryPos.getInstance(q);
686 
687             qPos.add(userId);
688 
689             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
690                     userTracker);
691 
692             UserTracker[] array = new UserTrackerImpl[3];
693 
694             array[0] = (UserTracker)objArray[0];
695             array[1] = (UserTracker)objArray[1];
696             array[2] = (UserTracker)objArray[2];
697 
698             return array;
699         }
700         catch (Exception e) {
701             throw processException(e);
702         }
703         finally {
704             closeSession(session);
705         }
706     }
707 
708     public List<UserTracker> findBySessionId(String sessionId)
709         throws SystemException {
710         boolean finderClassNameCacheEnabled = UserTrackerModelImpl.CACHE_ENABLED;
711         String finderClassName = UserTracker.class.getName();
712         String finderMethodName = "findBySessionId";
713         String[] finderParams = new String[] { String.class.getName() };
714         Object[] finderArgs = new Object[] { sessionId };
715 
716         Object result = null;
717 
718         if (finderClassNameCacheEnabled) {
719             result = FinderCacheUtil.getResult(finderClassName,
720                     finderMethodName, finderParams, finderArgs, this);
721         }
722 
723         if (result == null) {
724             Session session = null;
725 
726             try {
727                 session = openSession();
728 
729                 StringBuilder query = new StringBuilder();
730 
731                 query.append("FROM com.liferay.portal.model.UserTracker WHERE ");
732 
733                 if (sessionId == null) {
734                     query.append("sessionId IS NULL");
735                 }
736                 else {
737                     query.append("sessionId = ?");
738                 }
739 
740                 query.append(" ");
741 
742                 Query q = session.createQuery(query.toString());
743 
744                 QueryPos qPos = QueryPos.getInstance(q);
745 
746                 if (sessionId != null) {
747                     qPos.add(sessionId);
748                 }
749 
750                 List<UserTracker> list = q.list();
751 
752                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
753                     finderClassName, finderMethodName, finderParams,
754                     finderArgs, list);
755 
756                 return list;
757             }
758             catch (Exception e) {
759                 throw processException(e);
760             }
761             finally {
762                 closeSession(session);
763             }
764         }
765         else {
766             return (List<UserTracker>)result;
767         }
768     }
769 
770     public List<UserTracker> findBySessionId(String sessionId, int start,
771         int end) throws SystemException {
772         return findBySessionId(sessionId, start, end, null);
773     }
774 
775     public List<UserTracker> findBySessionId(String sessionId, int start,
776         int end, OrderByComparator obc) throws SystemException {
777         boolean finderClassNameCacheEnabled = UserTrackerModelImpl.CACHE_ENABLED;
778         String finderClassName = UserTracker.class.getName();
779         String finderMethodName = "findBySessionId";
780         String[] finderParams = new String[] {
781                 String.class.getName(),
782                 
783                 "java.lang.Integer", "java.lang.Integer",
784                 "com.liferay.portal.kernel.util.OrderByComparator"
785             };
786         Object[] finderArgs = new Object[] {
787                 sessionId,
788                 
789                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
790             };
791 
792         Object result = null;
793 
794         if (finderClassNameCacheEnabled) {
795             result = FinderCacheUtil.getResult(finderClassName,
796                     finderMethodName, finderParams, finderArgs, this);
797         }
798 
799         if (result == null) {
800             Session session = null;
801 
802             try {
803                 session = openSession();
804 
805                 StringBuilder query = new StringBuilder();
806 
807                 query.append("FROM com.liferay.portal.model.UserTracker WHERE ");
808 
809                 if (sessionId == null) {
810                     query.append("sessionId IS NULL");
811                 }
812                 else {
813                     query.append("sessionId = ?");
814                 }
815 
816                 query.append(" ");
817 
818                 if (obc != null) {
819                     query.append("ORDER BY ");
820                     query.append(obc.getOrderBy());
821                 }
822 
823                 Query q = session.createQuery(query.toString());
824 
825                 QueryPos qPos = QueryPos.getInstance(q);
826 
827                 if (sessionId != null) {
828                     qPos.add(sessionId);
829                 }
830 
831                 List<UserTracker> list = (List<UserTracker>)QueryUtil.list(q,
832                         getDialect(), start, end);
833 
834                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
835                     finderClassName, finderMethodName, finderParams,
836                     finderArgs, list);
837 
838                 return list;
839             }
840             catch (Exception e) {
841                 throw processException(e);
842             }
843             finally {
844                 closeSession(session);
845             }
846         }
847         else {
848             return (List<UserTracker>)result;
849         }
850     }
851 
852     public UserTracker findBySessionId_First(String sessionId,
853         OrderByComparator obc)
854         throws NoSuchUserTrackerException, SystemException {
855         List<UserTracker> list = findBySessionId(sessionId, 0, 1, obc);
856 
857         if (list.size() == 0) {
858             StringBuilder msg = new StringBuilder();
859 
860             msg.append("No UserTracker exists with the key {");
861 
862             msg.append("sessionId=" + sessionId);
863 
864             msg.append(StringPool.CLOSE_CURLY_BRACE);
865 
866             throw new NoSuchUserTrackerException(msg.toString());
867         }
868         else {
869             return list.get(0);
870         }
871     }
872 
873     public UserTracker findBySessionId_Last(String sessionId,
874         OrderByComparator obc)
875         throws NoSuchUserTrackerException, SystemException {
876         int count = countBySessionId(sessionId);
877 
878         List<UserTracker> list = findBySessionId(sessionId, count - 1, count,
879                 obc);
880 
881         if (list.size() == 0) {
882             StringBuilder msg = new StringBuilder();
883 
884             msg.append("No UserTracker exists with the key {");
885 
886             msg.append("sessionId=" + sessionId);
887 
888             msg.append(StringPool.CLOSE_CURLY_BRACE);
889 
890             throw new NoSuchUserTrackerException(msg.toString());
891         }
892         else {
893             return list.get(0);
894         }
895     }
896 
897     public UserTracker[] findBySessionId_PrevAndNext(long userTrackerId,
898         String sessionId, OrderByComparator obc)
899         throws NoSuchUserTrackerException, SystemException {
900         UserTracker userTracker = findByPrimaryKey(userTrackerId);
901 
902         int count = countBySessionId(sessionId);
903 
904         Session session = null;
905 
906         try {
907             session = openSession();
908 
909             StringBuilder query = new StringBuilder();
910 
911             query.append("FROM com.liferay.portal.model.UserTracker WHERE ");
912 
913             if (sessionId == null) {
914                 query.append("sessionId IS NULL");
915             }
916             else {
917                 query.append("sessionId = ?");
918             }
919 
920             query.append(" ");
921 
922             if (obc != null) {
923                 query.append("ORDER BY ");
924                 query.append(obc.getOrderBy());
925             }
926 
927             Query q = session.createQuery(query.toString());
928 
929             QueryPos qPos = QueryPos.getInstance(q);
930 
931             if (sessionId != null) {
932                 qPos.add(sessionId);
933             }
934 
935             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
936                     userTracker);
937 
938             UserTracker[] array = new UserTrackerImpl[3];
939 
940             array[0] = (UserTracker)objArray[0];
941             array[1] = (UserTracker)objArray[1];
942             array[2] = (UserTracker)objArray[2];
943 
944             return array;
945         }
946         catch (Exception e) {
947             throw processException(e);
948         }
949         finally {
950             closeSession(session);
951         }
952     }
953 
954     public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
955         throws SystemException {
956         Session session = null;
957 
958         try {
959             session = openSession();
960 
961             dynamicQuery.compile(session);
962 
963             return dynamicQuery.list();
964         }
965         catch (Exception e) {
966             throw processException(e);
967         }
968         finally {
969             closeSession(session);
970         }
971     }
972 
973     public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
974         int start, int end) throws SystemException {
975         Session session = null;
976 
977         try {
978             session = openSession();
979 
980             dynamicQuery.setLimit(start, end);
981 
982             dynamicQuery.compile(session);
983 
984             return dynamicQuery.list();
985         }
986         catch (Exception e) {
987             throw processException(e);
988         }
989         finally {
990             closeSession(session);
991         }
992     }
993 
994     public List<UserTracker> findAll() throws SystemException {
995         return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
996     }
997 
998     public List<UserTracker> findAll(int start, int end)
999         throws SystemException {
1000        return findAll(start, end, null);
1001    }
1002
1003    public List<UserTracker> findAll(int start, int end, OrderByComparator obc)
1004        throws SystemException {
1005        boolean finderClassNameCacheEnabled = UserTrackerModelImpl.CACHE_ENABLED;
1006        String finderClassName = UserTracker.class.getName();
1007        String finderMethodName = "findAll";
1008        String[] finderParams = new String[] {
1009                "java.lang.Integer", "java.lang.Integer",
1010                "com.liferay.portal.kernel.util.OrderByComparator"
1011            };
1012        Object[] finderArgs = new Object[] {
1013                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1014            };
1015
1016        Object result = null;
1017
1018        if (finderClassNameCacheEnabled) {
1019            result = FinderCacheUtil.getResult(finderClassName,
1020                    finderMethodName, finderParams, finderArgs, this);
1021        }
1022
1023        if (result == null) {
1024            Session session = null;
1025
1026            try {
1027                session = openSession();
1028
1029                StringBuilder query = new StringBuilder();
1030
1031                query.append("FROM com.liferay.portal.model.UserTracker ");
1032
1033                if (obc != null) {
1034                    query.append("ORDER BY ");
1035                    query.append(obc.getOrderBy());
1036                }
1037
1038                Query q = session.createQuery(query.toString());
1039
1040                List<UserTracker> list = null;
1041
1042                if (obc == null) {
1043                    list = (List<UserTracker>)QueryUtil.list(q, getDialect(),
1044                            start, end, false);
1045
1046                    Collections.sort(list);
1047                }
1048                else {
1049                    list = (List<UserTracker>)QueryUtil.list(q, getDialect(),
1050                            start, end);
1051                }
1052
1053                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1054                    finderClassName, finderMethodName, finderParams,
1055                    finderArgs, list);
1056
1057                return list;
1058            }
1059            catch (Exception e) {
1060                throw processException(e);
1061            }
1062            finally {
1063                closeSession(session);
1064            }
1065        }
1066        else {
1067            return (List<UserTracker>)result;
1068        }
1069    }
1070
1071    public void removeByCompanyId(long companyId) throws SystemException {
1072        for (UserTracker userTracker : findByCompanyId(companyId)) {
1073            remove(userTracker);
1074        }
1075    }
1076
1077    public void removeByUserId(long userId) throws SystemException {
1078        for (UserTracker userTracker : findByUserId(userId)) {
1079            remove(userTracker);
1080        }
1081    }
1082
1083    public void removeBySessionId(String sessionId) throws SystemException {
1084        for (UserTracker userTracker : findBySessionId(sessionId)) {
1085            remove(userTracker);
1086        }
1087    }
1088
1089    public void removeAll() throws SystemException {
1090        for (UserTracker userTracker : findAll()) {
1091            remove(userTracker);
1092        }
1093    }
1094
1095    public int countByCompanyId(long companyId) throws SystemException {
1096        boolean finderClassNameCacheEnabled = UserTrackerModelImpl.CACHE_ENABLED;
1097        String finderClassName = UserTracker.class.getName();
1098        String finderMethodName = "countByCompanyId";
1099        String[] finderParams = new String[] { Long.class.getName() };
1100        Object[] finderArgs = new Object[] { new Long(companyId) };
1101
1102        Object result = null;
1103
1104        if (finderClassNameCacheEnabled) {
1105            result = FinderCacheUtil.getResult(finderClassName,
1106                    finderMethodName, finderParams, finderArgs, this);
1107        }
1108
1109        if (result == null) {
1110            Session session = null;
1111
1112            try {
1113                session = openSession();
1114
1115                StringBuilder query = new StringBuilder();
1116
1117                query.append("SELECT COUNT(*) ");
1118                query.append("FROM com.liferay.portal.model.UserTracker WHERE ");
1119
1120                query.append("companyId = ?");
1121
1122                query.append(" ");
1123
1124                Query q = session.createQuery(query.toString());
1125
1126                QueryPos qPos = QueryPos.getInstance(q);
1127
1128                qPos.add(companyId);
1129
1130                Long count = null;
1131
1132                Iterator<Long> itr = q.list().iterator();
1133
1134                if (itr.hasNext()) {
1135                    count = itr.next();
1136                }
1137
1138                if (count == null) {
1139                    count = new Long(0);
1140                }
1141
1142                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1143                    finderClassName, finderMethodName, finderParams,
1144                    finderArgs, count);
1145
1146                return count.intValue();
1147            }
1148            catch (Exception e) {
1149                throw processException(e);
1150            }
1151            finally {
1152                closeSession(session);
1153            }
1154        }
1155        else {
1156            return ((Long)result).intValue();
1157        }
1158    }
1159
1160    public int countByUserId(long userId) throws SystemException {
1161        boolean finderClassNameCacheEnabled = UserTrackerModelImpl.CACHE_ENABLED;
1162        String finderClassName = UserTracker.class.getName();
1163        String finderMethodName = "countByUserId";
1164        String[] finderParams = new String[] { Long.class.getName() };
1165        Object[] finderArgs = new Object[] { new Long(userId) };
1166
1167        Object result = null;
1168
1169        if (finderClassNameCacheEnabled) {
1170            result = FinderCacheUtil.getResult(finderClassName,
1171                    finderMethodName, finderParams, finderArgs, this);
1172        }
1173
1174        if (result == null) {
1175            Session session = null;
1176
1177            try {
1178                session = openSession();
1179
1180                StringBuilder query = new StringBuilder();
1181
1182                query.append("SELECT COUNT(*) ");
1183                query.append("FROM com.liferay.portal.model.UserTracker WHERE ");
1184
1185                query.append("userId = ?");
1186
1187                query.append(" ");
1188
1189                Query q = session.createQuery(query.toString());
1190
1191                QueryPos qPos = QueryPos.getInstance(q);
1192
1193                qPos.add(userId);
1194
1195                Long count = null;
1196
1197                Iterator<Long> itr = q.list().iterator();
1198
1199                if (itr.hasNext()) {
1200                    count = itr.next();
1201                }
1202
1203                if (count == null) {
1204                    count = new Long(0);
1205                }
1206
1207                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1208                    finderClassName, finderMethodName, finderParams,
1209                    finderArgs, count);
1210
1211                return count.intValue();
1212            }
1213            catch (Exception e) {
1214                throw processException(e);
1215            }
1216            finally {
1217                closeSession(session);
1218            }
1219        }
1220        else {
1221            return ((Long)result).intValue();
1222        }
1223    }
1224
1225    public int countBySessionId(String sessionId) throws SystemException {
1226        boolean finderClassNameCacheEnabled = UserTrackerModelImpl.CACHE_ENABLED;
1227        String finderClassName = UserTracker.class.getName();
1228        String finderMethodName = "countBySessionId";
1229        String[] finderParams = new String[] { String.class.getName() };
1230        Object[] finderArgs = new Object[] { sessionId };
1231
1232        Object result = null;
1233
1234        if (finderClassNameCacheEnabled) {
1235            result = FinderCacheUtil.getResult(finderClassName,
1236                    finderMethodName, finderParams, finderArgs, this);
1237        }
1238
1239        if (result == null) {
1240            Session session = null;
1241
1242            try {
1243                session = openSession();
1244
1245                StringBuilder query = new StringBuilder();
1246
1247                query.append("SELECT COUNT(*) ");
1248                query.append("FROM com.liferay.portal.model.UserTracker WHERE ");
1249
1250                if (sessionId == null) {
1251                    query.append("sessionId IS NULL");
1252                }
1253                else {
1254                    query.append("sessionId = ?");
1255                }
1256
1257                query.append(" ");
1258
1259                Query q = session.createQuery(query.toString());
1260
1261                QueryPos qPos = QueryPos.getInstance(q);
1262
1263                if (sessionId != null) {
1264                    qPos.add(sessionId);
1265                }
1266
1267                Long count = null;
1268
1269                Iterator<Long> itr = q.list().iterator();
1270
1271                if (itr.hasNext()) {
1272                    count = itr.next();
1273                }
1274
1275                if (count == null) {
1276                    count = new Long(0);
1277                }
1278
1279                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1280                    finderClassName, finderMethodName, finderParams,
1281                    finderArgs, count);
1282
1283                return count.intValue();
1284            }
1285            catch (Exception e) {
1286                throw processException(e);
1287            }
1288            finally {
1289                closeSession(session);
1290            }
1291        }
1292        else {
1293            return ((Long)result).intValue();
1294        }
1295    }
1296
1297    public int countAll() throws SystemException {
1298        boolean finderClassNameCacheEnabled = UserTrackerModelImpl.CACHE_ENABLED;
1299        String finderClassName = UserTracker.class.getName();
1300        String finderMethodName = "countAll";
1301        String[] finderParams = new String[] {  };
1302        Object[] finderArgs = new Object[] {  };
1303
1304        Object result = null;
1305
1306        if (finderClassNameCacheEnabled) {
1307            result = FinderCacheUtil.getResult(finderClassName,
1308                    finderMethodName, finderParams, finderArgs, this);
1309        }
1310
1311        if (result == null) {
1312            Session session = null;
1313
1314            try {
1315                session = openSession();
1316
1317                Query q = session.createQuery(
1318                        "SELECT COUNT(*) FROM com.liferay.portal.model.UserTracker");
1319
1320                Long count = null;
1321
1322                Iterator<Long> itr = q.list().iterator();
1323
1324                if (itr.hasNext()) {
1325                    count = itr.next();
1326                }
1327
1328                if (count == null) {
1329                    count = new Long(0);
1330                }
1331
1332                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1333                    finderClassName, finderMethodName, finderParams,
1334                    finderArgs, count);
1335
1336                return count.intValue();
1337            }
1338            catch (Exception e) {
1339                throw processException(e);
1340            }
1341            finally {
1342                closeSession(session);
1343            }
1344        }
1345        else {
1346            return ((Long)result).intValue();
1347        }
1348    }
1349
1350    public void afterPropertiesSet() {
1351        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1352                    com.liferay.portal.util.PropsUtil.get(
1353                        "value.object.listener.com.liferay.portal.model.UserTracker")));
1354
1355        if (listenerClassNames.length > 0) {
1356            try {
1357                List<ModelListener> listenersList = new ArrayList<ModelListener>();
1358
1359                for (String listenerClassName : listenerClassNames) {
1360                    listenersList.add((ModelListener)Class.forName(
1361                            listenerClassName).newInstance());
1362                }
1363
1364                listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1365            }
1366            catch (Exception e) {
1367                _log.error(e);
1368            }
1369        }
1370    }
1371
1372    @BeanReference(name = "com.liferay.portal.service.persistence.AccountPersistence.impl")
1373    protected com.liferay.portal.service.persistence.AccountPersistence accountPersistence;
1374    @BeanReference(name = "com.liferay.portal.service.persistence.AddressPersistence.impl")
1375    protected com.liferay.portal.service.persistence.AddressPersistence addressPersistence;
1376    @BeanReference(name = "com.liferay.portal.service.persistence.ClassNamePersistence.impl")
1377    protected com.liferay.portal.service.persistence.ClassNamePersistence classNamePersistence;
1378    @BeanReference(name = "com.liferay.portal.service.persistence.CompanyPersistence.impl")
1379    protected com.liferay.portal.service.persistence.CompanyPersistence companyPersistence;
1380    @BeanReference(name = "com.liferay.portal.service.persistence.ContactPersistence.impl")
1381    protected com.liferay.portal.service.persistence.ContactPersistence contactPersistence;
1382    @BeanReference(name = "com.liferay.portal.service.persistence.CountryPersistence.impl")
1383    protected com.liferay.portal.service.persistence.CountryPersistence countryPersistence;
1384    @BeanReference(name = "com.liferay.portal.service.persistence.EmailAddressPersistence.impl")
1385    protected com.liferay.portal.service.persistence.EmailAddressPersistence emailAddressPersistence;
1386    @BeanReference(name = "com.liferay.portal.service.persistence.GroupPersistence.impl")
1387    protected com.liferay.portal.service.persistence.GroupPersistence groupPersistence;
1388    @BeanReference(name = "com.liferay.portal.service.persistence.ImagePersistence.impl")
1389    protected com.liferay.portal.service.persistence.ImagePersistence imagePersistence;
1390    @BeanReference(name = "com.liferay.portal.service.persistence.LayoutPersistence.impl")
1391    protected com.liferay.portal.service.persistence.LayoutPersistence layoutPersistence;
1392    @BeanReference(name = "com.liferay.portal.service.persistence.LayoutSetPersistence.impl")
1393    protected com.liferay.portal.service.persistence.LayoutSetPersistence layoutSetPersistence;
1394    @BeanReference(name = "com.liferay.portal.service.persistence.ListTypePersistence.impl")
1395    protected com.liferay.portal.service.persistence.ListTypePersistence listTypePersistence;
1396    @BeanReference(name = "com.liferay.portal.service.persistence.MembershipRequestPersistence.impl")
1397    protected com.liferay.portal.service.persistence.MembershipRequestPersistence membershipRequestPersistence;
1398    @BeanReference(name = "com.liferay.portal.service.persistence.OrganizationPersistence.impl")
1399    protected com.liferay.portal.service.persistence.OrganizationPersistence organizationPersistence;
1400    @BeanReference(name = "com.liferay.portal.service.persistence.OrgGroupPermissionPersistence.impl")
1401    protected com.liferay.portal.service.persistence.OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1402    @BeanReference(name = "com.liferay.portal.service.persistence.OrgGroupRolePersistence.impl")
1403    protected com.liferay.portal.service.persistence.OrgGroupRolePersistence orgGroupRolePersistence;
1404    @BeanReference(name = "com.liferay.portal.service.persistence.OrgLaborPersistence.impl")
1405    protected com.liferay.portal.service.persistence.OrgLaborPersistence orgLaborPersistence;
1406    @BeanReference(name = "com.liferay.portal.service.persistence.PasswordPolicyPersistence.impl")
1407    protected com.liferay.portal.service.persistence.PasswordPolicyPersistence passwordPolicyPersistence;
1408    @BeanReference(name = "com.liferay.portal.service.persistence.PasswordPolicyRelPersistence.impl")
1409    protected com.liferay.portal.service.persistence.PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1410    @BeanReference(name = "com.liferay.portal.service.persistence.PasswordTrackerPersistence.impl")
1411    protected com.liferay.portal.service.persistence.PasswordTrackerPersistence passwordTrackerPersistence;
1412    @BeanReference(name = "com.liferay.portal.service.persistence.PermissionPersistence.impl")
1413    protected com.liferay.portal.service.persistence.PermissionPersistence permissionPersistence;
1414    @BeanReference(name = "com.liferay.portal.service.persistence.PhonePersistence.impl")
1415    protected com.liferay.portal.service.persistence.PhonePersistence phonePersistence;
1416    @BeanReference(name = "com.liferay.portal.service.persistence.PluginSettingPersistence.impl")
1417    protected com.liferay.portal.service.persistence.PluginSettingPersistence pluginSettingPersistence;
1418    @BeanReference(name = "com.liferay.portal.service.persistence.PortletPersistence.impl")
1419    protected com.liferay.portal.service.persistence.PortletPersistence portletPersistence;
1420    @BeanReference(name = "com.liferay.portal.service.persistence.PortletPreferencesPersistence.impl")
1421    protected com.liferay.portal.service.persistence.PortletPreferencesPersistence portletPreferencesPersistence;
1422    @BeanReference(name = "com.liferay.portal.service.persistence.RegionPersistence.impl")
1423    protected com.liferay.portal.service.persistence.RegionPersistence regionPersistence;
1424    @BeanReference(name = "com.liferay.portal.service.persistence.ReleasePersistence.impl")
1425    protected com.liferay.portal.service.persistence.ReleasePersistence releasePersistence;
1426    @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePersistence.impl")
1427    protected com.liferay.portal.service.persistence.ResourcePersistence resourcePersistence;
1428    @BeanReference(name = "com.liferay.portal.service.persistence.ResourceCodePersistence.impl")
1429    protected com.liferay.portal.service.persistence.ResourceCodePersistence resourceCodePersistence;
1430    @BeanReference(name = "com.liferay.portal.service.persistence.RolePersistence.impl")
1431    protected com.liferay.portal.service.persistence.RolePersistence rolePersistence;
1432    @BeanReference(name = "com.liferay.portal.service.persistence.ServiceComponentPersistence.impl")
1433    protected com.liferay.portal.service.persistence.ServiceComponentPersistence serviceComponentPersistence;
1434    @BeanReference(name = "com.liferay.portal.service.persistence.PortletItemPersistence.impl")
1435    protected com.liferay.portal.service.persistence.PortletItemPersistence portletItemPersistence;
1436    @BeanReference(name = "com.liferay.portal.service.persistence.SubscriptionPersistence.impl")
1437    protected com.liferay.portal.service.persistence.SubscriptionPersistence subscriptionPersistence;
1438    @BeanReference(name = "com.liferay.portal.service.persistence.UserPersistence.impl")
1439    protected com.liferay.portal.service.persistence.UserPersistence userPersistence;
1440    @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupPersistence.impl")
1441    protected com.liferay.portal.service.persistence.UserGroupPersistence userGroupPersistence;
1442    @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupRolePersistence.impl")
1443    protected com.liferay.portal.service.persistence.UserGroupRolePersistence userGroupRolePersistence;
1444    @BeanReference(name = "com.liferay.portal.service.persistence.UserIdMapperPersistence.impl")
1445    protected com.liferay.portal.service.persistence.UserIdMapperPersistence userIdMapperPersistence;
1446    @BeanReference(name = "com.liferay.portal.service.persistence.UserTrackerPersistence.impl")
1447    protected com.liferay.portal.service.persistence.UserTrackerPersistence userTrackerPersistence;
1448    @BeanReference(name = "com.liferay.portal.service.persistence.UserTrackerPathPersistence.impl")
1449    protected com.liferay.portal.service.persistence.UserTrackerPathPersistence userTrackerPathPersistence;
1450    @BeanReference(name = "com.liferay.portal.service.persistence.WebDAVPropsPersistence.impl")
1451    protected com.liferay.portal.service.persistence.WebDAVPropsPersistence webDAVPropsPersistence;
1452    @BeanReference(name = "com.liferay.portal.service.persistence.WebsitePersistence.impl")
1453    protected com.liferay.portal.service.persistence.WebsitePersistence websitePersistence;
1454    private static Log _log = LogFactoryUtil.getLog(UserTrackerPersistenceImpl.class);
1455}