001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.service.persistence;
016    
017    import com.liferay.portal.NoSuchUserTrackerException;
018    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
019    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
020    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderPath;
022    import com.liferay.portal.kernel.dao.orm.Query;
023    import com.liferay.portal.kernel.dao.orm.QueryPos;
024    import com.liferay.portal.kernel.dao.orm.QueryUtil;
025    import com.liferay.portal.kernel.dao.orm.Session;
026    import com.liferay.portal.kernel.exception.SystemException;
027    import com.liferay.portal.kernel.log.Log;
028    import com.liferay.portal.kernel.log.LogFactoryUtil;
029    import com.liferay.portal.kernel.util.GetterUtil;
030    import com.liferay.portal.kernel.util.InstanceFactory;
031    import com.liferay.portal.kernel.util.OrderByComparator;
032    import com.liferay.portal.kernel.util.StringBundler;
033    import com.liferay.portal.kernel.util.StringPool;
034    import com.liferay.portal.kernel.util.StringUtil;
035    import com.liferay.portal.kernel.util.UnmodifiableList;
036    import com.liferay.portal.kernel.util.Validator;
037    import com.liferay.portal.model.CacheModel;
038    import com.liferay.portal.model.ModelListener;
039    import com.liferay.portal.model.UserTracker;
040    import com.liferay.portal.model.impl.UserTrackerImpl;
041    import com.liferay.portal.model.impl.UserTrackerModelImpl;
042    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
043    
044    import java.io.Serializable;
045    
046    import java.util.ArrayList;
047    import java.util.Collections;
048    import java.util.List;
049    
050    /**
051     * The persistence implementation for the user tracker service.
052     *
053     * <p>
054     * Caching information and settings can be found in <code>portal.properties</code>
055     * </p>
056     *
057     * @author Brian Wing Shun Chan
058     * @see UserTrackerPersistence
059     * @see UserTrackerUtil
060     * @generated
061     */
062    public class UserTrackerPersistenceImpl extends BasePersistenceImpl<UserTracker>
063            implements UserTrackerPersistence {
064            /*
065             * NOTE FOR DEVELOPERS:
066             *
067             * Never modify or reference this class directly. Always use {@link UserTrackerUtil} to access the user tracker persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
068             */
069            public static final String FINDER_CLASS_NAME_ENTITY = UserTrackerImpl.class.getName();
070            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
071                    ".List1";
072            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
073                    ".List2";
074            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(UserTrackerModelImpl.ENTITY_CACHE_ENABLED,
075                            UserTrackerModelImpl.FINDER_CACHE_ENABLED, UserTrackerImpl.class,
076                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
077            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(UserTrackerModelImpl.ENTITY_CACHE_ENABLED,
078                            UserTrackerModelImpl.FINDER_CACHE_ENABLED, UserTrackerImpl.class,
079                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
080            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(UserTrackerModelImpl.ENTITY_CACHE_ENABLED,
081                            UserTrackerModelImpl.FINDER_CACHE_ENABLED, Long.class,
082                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
083            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
084                    new FinderPath(UserTrackerModelImpl.ENTITY_CACHE_ENABLED,
085                            UserTrackerModelImpl.FINDER_CACHE_ENABLED, UserTrackerImpl.class,
086                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
087                            new String[] {
088                                    Long.class.getName(),
089                                    
090                            Integer.class.getName(), Integer.class.getName(),
091                                    OrderByComparator.class.getName()
092                            });
093            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
094                    new FinderPath(UserTrackerModelImpl.ENTITY_CACHE_ENABLED,
095                            UserTrackerModelImpl.FINDER_CACHE_ENABLED, UserTrackerImpl.class,
096                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
097                            new String[] { Long.class.getName() },
098                            UserTrackerModelImpl.COMPANYID_COLUMN_BITMASK);
099            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(UserTrackerModelImpl.ENTITY_CACHE_ENABLED,
100                            UserTrackerModelImpl.FINDER_CACHE_ENABLED, Long.class,
101                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
102                            new String[] { Long.class.getName() });
103    
104            /**
105             * Returns all the user trackers where companyId = &#63;.
106             *
107             * @param companyId the company ID
108             * @return the matching user trackers
109             * @throws SystemException if a system exception occurred
110             */
111            public List<UserTracker> findByCompanyId(long companyId)
112                    throws SystemException {
113                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
114                            null);
115            }
116    
117            /**
118             * Returns a range of all the user trackers where companyId = &#63;.
119             *
120             * <p>
121             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.UserTrackerModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
122             * </p>
123             *
124             * @param companyId the company ID
125             * @param start the lower bound of the range of user trackers
126             * @param end the upper bound of the range of user trackers (not inclusive)
127             * @return the range of matching user trackers
128             * @throws SystemException if a system exception occurred
129             */
130            public List<UserTracker> findByCompanyId(long companyId, int start, int end)
131                    throws SystemException {
132                    return findByCompanyId(companyId, start, end, null);
133            }
134    
135            /**
136             * Returns an ordered range of all the user trackers where companyId = &#63;.
137             *
138             * <p>
139             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.UserTrackerModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
140             * </p>
141             *
142             * @param companyId the company ID
143             * @param start the lower bound of the range of user trackers
144             * @param end the upper bound of the range of user trackers (not inclusive)
145             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
146             * @return the ordered range of matching user trackers
147             * @throws SystemException if a system exception occurred
148             */
149            public List<UserTracker> findByCompanyId(long companyId, int start,
150                    int end, OrderByComparator orderByComparator) throws SystemException {
151                    boolean pagination = true;
152                    FinderPath finderPath = null;
153                    Object[] finderArgs = null;
154    
155                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
156                                    (orderByComparator == null)) {
157                            pagination = false;
158                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
159                            finderArgs = new Object[] { companyId };
160                    }
161                    else {
162                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
163                            finderArgs = new Object[] { companyId, start, end, orderByComparator };
164                    }
165    
166                    List<UserTracker> list = (List<UserTracker>)FinderCacheUtil.getResult(finderPath,
167                                    finderArgs, this);
168    
169                    if ((list != null) && !list.isEmpty()) {
170                            for (UserTracker userTracker : list) {
171                                    if ((companyId != userTracker.getCompanyId())) {
172                                            list = null;
173    
174                                            break;
175                                    }
176                            }
177                    }
178    
179                    if (list == null) {
180                            StringBundler query = null;
181    
182                            if (orderByComparator != null) {
183                                    query = new StringBundler(3 +
184                                                    (orderByComparator.getOrderByFields().length * 3));
185                            }
186                            else {
187                                    query = new StringBundler(3);
188                            }
189    
190                            query.append(_SQL_SELECT_USERTRACKER_WHERE);
191    
192                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
193    
194                            if (orderByComparator != null) {
195                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
196                                            orderByComparator);
197                            }
198                            else
199                             if (pagination) {
200                                    query.append(UserTrackerModelImpl.ORDER_BY_JPQL);
201                            }
202    
203                            String sql = query.toString();
204    
205                            Session session = null;
206    
207                            try {
208                                    session = openSession();
209    
210                                    Query q = session.createQuery(sql);
211    
212                                    QueryPos qPos = QueryPos.getInstance(q);
213    
214                                    qPos.add(companyId);
215    
216                                    if (!pagination) {
217                                            list = (List<UserTracker>)QueryUtil.list(q, getDialect(),
218                                                            start, end, false);
219    
220                                            Collections.sort(list);
221    
222                                            list = new UnmodifiableList<UserTracker>(list);
223                                    }
224                                    else {
225                                            list = (List<UserTracker>)QueryUtil.list(q, getDialect(),
226                                                            start, end);
227                                    }
228    
229                                    cacheResult(list);
230    
231                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
232                            }
233                            catch (Exception e) {
234                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
235    
236                                    throw processException(e);
237                            }
238                            finally {
239                                    closeSession(session);
240                            }
241                    }
242    
243                    return list;
244            }
245    
246            /**
247             * Returns the first user tracker in the ordered set where companyId = &#63;.
248             *
249             * @param companyId the company ID
250             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
251             * @return the first matching user tracker
252             * @throws com.liferay.portal.NoSuchUserTrackerException if a matching user tracker could not be found
253             * @throws SystemException if a system exception occurred
254             */
255            public UserTracker findByCompanyId_First(long companyId,
256                    OrderByComparator orderByComparator)
257                    throws NoSuchUserTrackerException, SystemException {
258                    UserTracker userTracker = fetchByCompanyId_First(companyId,
259                                    orderByComparator);
260    
261                    if (userTracker != null) {
262                            return userTracker;
263                    }
264    
265                    StringBundler msg = new StringBundler(4);
266    
267                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
268    
269                    msg.append("companyId=");
270                    msg.append(companyId);
271    
272                    msg.append(StringPool.CLOSE_CURLY_BRACE);
273    
274                    throw new NoSuchUserTrackerException(msg.toString());
275            }
276    
277            /**
278             * Returns the first user tracker in the ordered set where companyId = &#63;.
279             *
280             * @param companyId the company ID
281             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
282             * @return the first matching user tracker, or <code>null</code> if a matching user tracker could not be found
283             * @throws SystemException if a system exception occurred
284             */
285            public UserTracker fetchByCompanyId_First(long companyId,
286                    OrderByComparator orderByComparator) throws SystemException {
287                    List<UserTracker> list = findByCompanyId(companyId, 0, 1,
288                                    orderByComparator);
289    
290                    if (!list.isEmpty()) {
291                            return list.get(0);
292                    }
293    
294                    return null;
295            }
296    
297            /**
298             * Returns the last user tracker in the ordered set where companyId = &#63;.
299             *
300             * @param companyId the company ID
301             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
302             * @return the last matching user tracker
303             * @throws com.liferay.portal.NoSuchUserTrackerException if a matching user tracker could not be found
304             * @throws SystemException if a system exception occurred
305             */
306            public UserTracker findByCompanyId_Last(long companyId,
307                    OrderByComparator orderByComparator)
308                    throws NoSuchUserTrackerException, SystemException {
309                    UserTracker userTracker = fetchByCompanyId_Last(companyId,
310                                    orderByComparator);
311    
312                    if (userTracker != null) {
313                            return userTracker;
314                    }
315    
316                    StringBundler msg = new StringBundler(4);
317    
318                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
319    
320                    msg.append("companyId=");
321                    msg.append(companyId);
322    
323                    msg.append(StringPool.CLOSE_CURLY_BRACE);
324    
325                    throw new NoSuchUserTrackerException(msg.toString());
326            }
327    
328            /**
329             * Returns the last user tracker in the ordered set where companyId = &#63;.
330             *
331             * @param companyId the company ID
332             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
333             * @return the last matching user tracker, or <code>null</code> if a matching user tracker could not be found
334             * @throws SystemException if a system exception occurred
335             */
336            public UserTracker fetchByCompanyId_Last(long companyId,
337                    OrderByComparator orderByComparator) throws SystemException {
338                    int count = countByCompanyId(companyId);
339    
340                    List<UserTracker> list = findByCompanyId(companyId, count - 1, count,
341                                    orderByComparator);
342    
343                    if (!list.isEmpty()) {
344                            return list.get(0);
345                    }
346    
347                    return null;
348            }
349    
350            /**
351             * Returns the user trackers before and after the current user tracker in the ordered set where companyId = &#63;.
352             *
353             * @param userTrackerId the primary key of the current user tracker
354             * @param companyId the company ID
355             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
356             * @return the previous, current, and next user tracker
357             * @throws com.liferay.portal.NoSuchUserTrackerException if a user tracker with the primary key could not be found
358             * @throws SystemException if a system exception occurred
359             */
360            public UserTracker[] findByCompanyId_PrevAndNext(long userTrackerId,
361                    long companyId, OrderByComparator orderByComparator)
362                    throws NoSuchUserTrackerException, SystemException {
363                    UserTracker userTracker = findByPrimaryKey(userTrackerId);
364    
365                    Session session = null;
366    
367                    try {
368                            session = openSession();
369    
370                            UserTracker[] array = new UserTrackerImpl[3];
371    
372                            array[0] = getByCompanyId_PrevAndNext(session, userTracker,
373                                            companyId, orderByComparator, true);
374    
375                            array[1] = userTracker;
376    
377                            array[2] = getByCompanyId_PrevAndNext(session, userTracker,
378                                            companyId, orderByComparator, false);
379    
380                            return array;
381                    }
382                    catch (Exception e) {
383                            throw processException(e);
384                    }
385                    finally {
386                            closeSession(session);
387                    }
388            }
389    
390            protected UserTracker getByCompanyId_PrevAndNext(Session session,
391                    UserTracker userTracker, long companyId,
392                    OrderByComparator orderByComparator, boolean previous) {
393                    StringBundler query = null;
394    
395                    if (orderByComparator != null) {
396                            query = new StringBundler(6 +
397                                            (orderByComparator.getOrderByFields().length * 6));
398                    }
399                    else {
400                            query = new StringBundler(3);
401                    }
402    
403                    query.append(_SQL_SELECT_USERTRACKER_WHERE);
404    
405                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
406    
407                    if (orderByComparator != null) {
408                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
409    
410                            if (orderByConditionFields.length > 0) {
411                                    query.append(WHERE_AND);
412                            }
413    
414                            for (int i = 0; i < orderByConditionFields.length; i++) {
415                                    query.append(_ORDER_BY_ENTITY_ALIAS);
416                                    query.append(orderByConditionFields[i]);
417    
418                                    if ((i + 1) < orderByConditionFields.length) {
419                                            if (orderByComparator.isAscending() ^ previous) {
420                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
421                                            }
422                                            else {
423                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
424                                            }
425                                    }
426                                    else {
427                                            if (orderByComparator.isAscending() ^ previous) {
428                                                    query.append(WHERE_GREATER_THAN);
429                                            }
430                                            else {
431                                                    query.append(WHERE_LESSER_THAN);
432                                            }
433                                    }
434                            }
435    
436                            query.append(ORDER_BY_CLAUSE);
437    
438                            String[] orderByFields = orderByComparator.getOrderByFields();
439    
440                            for (int i = 0; i < orderByFields.length; i++) {
441                                    query.append(_ORDER_BY_ENTITY_ALIAS);
442                                    query.append(orderByFields[i]);
443    
444                                    if ((i + 1) < orderByFields.length) {
445                                            if (orderByComparator.isAscending() ^ previous) {
446                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
447                                            }
448                                            else {
449                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
450                                            }
451                                    }
452                                    else {
453                                            if (orderByComparator.isAscending() ^ previous) {
454                                                    query.append(ORDER_BY_ASC);
455                                            }
456                                            else {
457                                                    query.append(ORDER_BY_DESC);
458                                            }
459                                    }
460                            }
461                    }
462                    else {
463                            query.append(UserTrackerModelImpl.ORDER_BY_JPQL);
464                    }
465    
466                    String sql = query.toString();
467    
468                    Query q = session.createQuery(sql);
469    
470                    q.setFirstResult(0);
471                    q.setMaxResults(2);
472    
473                    QueryPos qPos = QueryPos.getInstance(q);
474    
475                    qPos.add(companyId);
476    
477                    if (orderByComparator != null) {
478                            Object[] values = orderByComparator.getOrderByConditionValues(userTracker);
479    
480                            for (Object value : values) {
481                                    qPos.add(value);
482                            }
483                    }
484    
485                    List<UserTracker> list = q.list();
486    
487                    if (list.size() == 2) {
488                            return list.get(1);
489                    }
490                    else {
491                            return null;
492                    }
493            }
494    
495            /**
496             * Removes all the user trackers where companyId = &#63; from the database.
497             *
498             * @param companyId the company ID
499             * @throws SystemException if a system exception occurred
500             */
501            public void removeByCompanyId(long companyId) throws SystemException {
502                    for (UserTracker userTracker : findByCompanyId(companyId,
503                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
504                            remove(userTracker);
505                    }
506            }
507    
508            /**
509             * Returns the number of user trackers where companyId = &#63;.
510             *
511             * @param companyId the company ID
512             * @return the number of matching user trackers
513             * @throws SystemException if a system exception occurred
514             */
515            public int countByCompanyId(long companyId) throws SystemException {
516                    FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
517    
518                    Object[] finderArgs = new Object[] { companyId };
519    
520                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
521                                    this);
522    
523                    if (count == null) {
524                            StringBundler query = new StringBundler(2);
525    
526                            query.append(_SQL_COUNT_USERTRACKER_WHERE);
527    
528                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
529    
530                            String sql = query.toString();
531    
532                            Session session = null;
533    
534                            try {
535                                    session = openSession();
536    
537                                    Query q = session.createQuery(sql);
538    
539                                    QueryPos qPos = QueryPos.getInstance(q);
540    
541                                    qPos.add(companyId);
542    
543                                    count = (Long)q.uniqueResult();
544    
545                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
546                            }
547                            catch (Exception e) {
548                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
549    
550                                    throw processException(e);
551                            }
552                            finally {
553                                    closeSession(session);
554                            }
555                    }
556    
557                    return count.intValue();
558            }
559    
560            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "userTracker.companyId = ?";
561            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID = new FinderPath(UserTrackerModelImpl.ENTITY_CACHE_ENABLED,
562                            UserTrackerModelImpl.FINDER_CACHE_ENABLED, UserTrackerImpl.class,
563                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUserId",
564                            new String[] {
565                                    Long.class.getName(),
566                                    
567                            Integer.class.getName(), Integer.class.getName(),
568                                    OrderByComparator.class.getName()
569                            });
570            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID =
571                    new FinderPath(UserTrackerModelImpl.ENTITY_CACHE_ENABLED,
572                            UserTrackerModelImpl.FINDER_CACHE_ENABLED, UserTrackerImpl.class,
573                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserId",
574                            new String[] { Long.class.getName() },
575                            UserTrackerModelImpl.USERID_COLUMN_BITMASK);
576            public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(UserTrackerModelImpl.ENTITY_CACHE_ENABLED,
577                            UserTrackerModelImpl.FINDER_CACHE_ENABLED, Long.class,
578                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId",
579                            new String[] { Long.class.getName() });
580    
581            /**
582             * Returns all the user trackers where userId = &#63;.
583             *
584             * @param userId the user ID
585             * @return the matching user trackers
586             * @throws SystemException if a system exception occurred
587             */
588            public List<UserTracker> findByUserId(long userId)
589                    throws SystemException {
590                    return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
591            }
592    
593            /**
594             * Returns a range of all the user trackers where userId = &#63;.
595             *
596             * <p>
597             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.UserTrackerModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
598             * </p>
599             *
600             * @param userId the user ID
601             * @param start the lower bound of the range of user trackers
602             * @param end the upper bound of the range of user trackers (not inclusive)
603             * @return the range of matching user trackers
604             * @throws SystemException if a system exception occurred
605             */
606            public List<UserTracker> findByUserId(long userId, int start, int end)
607                    throws SystemException {
608                    return findByUserId(userId, start, end, null);
609            }
610    
611            /**
612             * Returns an ordered range of all the user trackers where userId = &#63;.
613             *
614             * <p>
615             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.UserTrackerModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
616             * </p>
617             *
618             * @param userId the user ID
619             * @param start the lower bound of the range of user trackers
620             * @param end the upper bound of the range of user trackers (not inclusive)
621             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
622             * @return the ordered range of matching user trackers
623             * @throws SystemException if a system exception occurred
624             */
625            public List<UserTracker> findByUserId(long userId, int start, int end,
626                    OrderByComparator orderByComparator) throws SystemException {
627                    boolean pagination = true;
628                    FinderPath finderPath = null;
629                    Object[] finderArgs = null;
630    
631                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
632                                    (orderByComparator == null)) {
633                            pagination = false;
634                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID;
635                            finderArgs = new Object[] { userId };
636                    }
637                    else {
638                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID;
639                            finderArgs = new Object[] { userId, start, end, orderByComparator };
640                    }
641    
642                    List<UserTracker> list = (List<UserTracker>)FinderCacheUtil.getResult(finderPath,
643                                    finderArgs, this);
644    
645                    if ((list != null) && !list.isEmpty()) {
646                            for (UserTracker userTracker : list) {
647                                    if ((userId != userTracker.getUserId())) {
648                                            list = null;
649    
650                                            break;
651                                    }
652                            }
653                    }
654    
655                    if (list == null) {
656                            StringBundler query = null;
657    
658                            if (orderByComparator != null) {
659                                    query = new StringBundler(3 +
660                                                    (orderByComparator.getOrderByFields().length * 3));
661                            }
662                            else {
663                                    query = new StringBundler(3);
664                            }
665    
666                            query.append(_SQL_SELECT_USERTRACKER_WHERE);
667    
668                            query.append(_FINDER_COLUMN_USERID_USERID_2);
669    
670                            if (orderByComparator != null) {
671                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
672                                            orderByComparator);
673                            }
674                            else
675                             if (pagination) {
676                                    query.append(UserTrackerModelImpl.ORDER_BY_JPQL);
677                            }
678    
679                            String sql = query.toString();
680    
681                            Session session = null;
682    
683                            try {
684                                    session = openSession();
685    
686                                    Query q = session.createQuery(sql);
687    
688                                    QueryPos qPos = QueryPos.getInstance(q);
689    
690                                    qPos.add(userId);
691    
692                                    if (!pagination) {
693                                            list = (List<UserTracker>)QueryUtil.list(q, getDialect(),
694                                                            start, end, false);
695    
696                                            Collections.sort(list);
697    
698                                            list = new UnmodifiableList<UserTracker>(list);
699                                    }
700                                    else {
701                                            list = (List<UserTracker>)QueryUtil.list(q, getDialect(),
702                                                            start, end);
703                                    }
704    
705                                    cacheResult(list);
706    
707                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
708                            }
709                            catch (Exception e) {
710                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
711    
712                                    throw processException(e);
713                            }
714                            finally {
715                                    closeSession(session);
716                            }
717                    }
718    
719                    return list;
720            }
721    
722            /**
723             * Returns the first user tracker in the ordered set where userId = &#63;.
724             *
725             * @param userId the user ID
726             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
727             * @return the first matching user tracker
728             * @throws com.liferay.portal.NoSuchUserTrackerException if a matching user tracker could not be found
729             * @throws SystemException if a system exception occurred
730             */
731            public UserTracker findByUserId_First(long userId,
732                    OrderByComparator orderByComparator)
733                    throws NoSuchUserTrackerException, SystemException {
734                    UserTracker userTracker = fetchByUserId_First(userId, orderByComparator);
735    
736                    if (userTracker != null) {
737                            return userTracker;
738                    }
739    
740                    StringBundler msg = new StringBundler(4);
741    
742                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
743    
744                    msg.append("userId=");
745                    msg.append(userId);
746    
747                    msg.append(StringPool.CLOSE_CURLY_BRACE);
748    
749                    throw new NoSuchUserTrackerException(msg.toString());
750            }
751    
752            /**
753             * Returns the first user tracker in the ordered set where userId = &#63;.
754             *
755             * @param userId the user ID
756             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
757             * @return the first matching user tracker, or <code>null</code> if a matching user tracker could not be found
758             * @throws SystemException if a system exception occurred
759             */
760            public UserTracker fetchByUserId_First(long userId,
761                    OrderByComparator orderByComparator) throws SystemException {
762                    List<UserTracker> list = findByUserId(userId, 0, 1, orderByComparator);
763    
764                    if (!list.isEmpty()) {
765                            return list.get(0);
766                    }
767    
768                    return null;
769            }
770    
771            /**
772             * Returns the last user tracker in the ordered set where userId = &#63;.
773             *
774             * @param userId the user ID
775             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
776             * @return the last matching user tracker
777             * @throws com.liferay.portal.NoSuchUserTrackerException if a matching user tracker could not be found
778             * @throws SystemException if a system exception occurred
779             */
780            public UserTracker findByUserId_Last(long userId,
781                    OrderByComparator orderByComparator)
782                    throws NoSuchUserTrackerException, SystemException {
783                    UserTracker userTracker = fetchByUserId_Last(userId, orderByComparator);
784    
785                    if (userTracker != null) {
786                            return userTracker;
787                    }
788    
789                    StringBundler msg = new StringBundler(4);
790    
791                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
792    
793                    msg.append("userId=");
794                    msg.append(userId);
795    
796                    msg.append(StringPool.CLOSE_CURLY_BRACE);
797    
798                    throw new NoSuchUserTrackerException(msg.toString());
799            }
800    
801            /**
802             * Returns the last user tracker in the ordered set where userId = &#63;.
803             *
804             * @param userId the user ID
805             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
806             * @return the last matching user tracker, or <code>null</code> if a matching user tracker could not be found
807             * @throws SystemException if a system exception occurred
808             */
809            public UserTracker fetchByUserId_Last(long userId,
810                    OrderByComparator orderByComparator) throws SystemException {
811                    int count = countByUserId(userId);
812    
813                    List<UserTracker> list = findByUserId(userId, count - 1, count,
814                                    orderByComparator);
815    
816                    if (!list.isEmpty()) {
817                            return list.get(0);
818                    }
819    
820                    return null;
821            }
822    
823            /**
824             * Returns the user trackers before and after the current user tracker in the ordered set where userId = &#63;.
825             *
826             * @param userTrackerId the primary key of the current user tracker
827             * @param userId the user ID
828             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
829             * @return the previous, current, and next user tracker
830             * @throws com.liferay.portal.NoSuchUserTrackerException if a user tracker with the primary key could not be found
831             * @throws SystemException if a system exception occurred
832             */
833            public UserTracker[] findByUserId_PrevAndNext(long userTrackerId,
834                    long userId, OrderByComparator orderByComparator)
835                    throws NoSuchUserTrackerException, SystemException {
836                    UserTracker userTracker = findByPrimaryKey(userTrackerId);
837    
838                    Session session = null;
839    
840                    try {
841                            session = openSession();
842    
843                            UserTracker[] array = new UserTrackerImpl[3];
844    
845                            array[0] = getByUserId_PrevAndNext(session, userTracker, userId,
846                                            orderByComparator, true);
847    
848                            array[1] = userTracker;
849    
850                            array[2] = getByUserId_PrevAndNext(session, userTracker, userId,
851                                            orderByComparator, false);
852    
853                            return array;
854                    }
855                    catch (Exception e) {
856                            throw processException(e);
857                    }
858                    finally {
859                            closeSession(session);
860                    }
861            }
862    
863            protected UserTracker getByUserId_PrevAndNext(Session session,
864                    UserTracker userTracker, long userId,
865                    OrderByComparator orderByComparator, boolean previous) {
866                    StringBundler query = null;
867    
868                    if (orderByComparator != null) {
869                            query = new StringBundler(6 +
870                                            (orderByComparator.getOrderByFields().length * 6));
871                    }
872                    else {
873                            query = new StringBundler(3);
874                    }
875    
876                    query.append(_SQL_SELECT_USERTRACKER_WHERE);
877    
878                    query.append(_FINDER_COLUMN_USERID_USERID_2);
879    
880                    if (orderByComparator != null) {
881                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
882    
883                            if (orderByConditionFields.length > 0) {
884                                    query.append(WHERE_AND);
885                            }
886    
887                            for (int i = 0; i < orderByConditionFields.length; i++) {
888                                    query.append(_ORDER_BY_ENTITY_ALIAS);
889                                    query.append(orderByConditionFields[i]);
890    
891                                    if ((i + 1) < orderByConditionFields.length) {
892                                            if (orderByComparator.isAscending() ^ previous) {
893                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
894                                            }
895                                            else {
896                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
897                                            }
898                                    }
899                                    else {
900                                            if (orderByComparator.isAscending() ^ previous) {
901                                                    query.append(WHERE_GREATER_THAN);
902                                            }
903                                            else {
904                                                    query.append(WHERE_LESSER_THAN);
905                                            }
906                                    }
907                            }
908    
909                            query.append(ORDER_BY_CLAUSE);
910    
911                            String[] orderByFields = orderByComparator.getOrderByFields();
912    
913                            for (int i = 0; i < orderByFields.length; i++) {
914                                    query.append(_ORDER_BY_ENTITY_ALIAS);
915                                    query.append(orderByFields[i]);
916    
917                                    if ((i + 1) < orderByFields.length) {
918                                            if (orderByComparator.isAscending() ^ previous) {
919                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
920                                            }
921                                            else {
922                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
923                                            }
924                                    }
925                                    else {
926                                            if (orderByComparator.isAscending() ^ previous) {
927                                                    query.append(ORDER_BY_ASC);
928                                            }
929                                            else {
930                                                    query.append(ORDER_BY_DESC);
931                                            }
932                                    }
933                            }
934                    }
935                    else {
936                            query.append(UserTrackerModelImpl.ORDER_BY_JPQL);
937                    }
938    
939                    String sql = query.toString();
940    
941                    Query q = session.createQuery(sql);
942    
943                    q.setFirstResult(0);
944                    q.setMaxResults(2);
945    
946                    QueryPos qPos = QueryPos.getInstance(q);
947    
948                    qPos.add(userId);
949    
950                    if (orderByComparator != null) {
951                            Object[] values = orderByComparator.getOrderByConditionValues(userTracker);
952    
953                            for (Object value : values) {
954                                    qPos.add(value);
955                            }
956                    }
957    
958                    List<UserTracker> list = q.list();
959    
960                    if (list.size() == 2) {
961                            return list.get(1);
962                    }
963                    else {
964                            return null;
965                    }
966            }
967    
968            /**
969             * Removes all the user trackers where userId = &#63; from the database.
970             *
971             * @param userId the user ID
972             * @throws SystemException if a system exception occurred
973             */
974            public void removeByUserId(long userId) throws SystemException {
975                    for (UserTracker userTracker : findByUserId(userId, QueryUtil.ALL_POS,
976                                    QueryUtil.ALL_POS, null)) {
977                            remove(userTracker);
978                    }
979            }
980    
981            /**
982             * Returns the number of user trackers where userId = &#63;.
983             *
984             * @param userId the user ID
985             * @return the number of matching user trackers
986             * @throws SystemException if a system exception occurred
987             */
988            public int countByUserId(long userId) throws SystemException {
989                    FinderPath finderPath = FINDER_PATH_COUNT_BY_USERID;
990    
991                    Object[] finderArgs = new Object[] { userId };
992    
993                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
994                                    this);
995    
996                    if (count == null) {
997                            StringBundler query = new StringBundler(2);
998    
999                            query.append(_SQL_COUNT_USERTRACKER_WHERE);
1000    
1001                            query.append(_FINDER_COLUMN_USERID_USERID_2);
1002    
1003                            String sql = query.toString();
1004    
1005                            Session session = null;
1006    
1007                            try {
1008                                    session = openSession();
1009    
1010                                    Query q = session.createQuery(sql);
1011    
1012                                    QueryPos qPos = QueryPos.getInstance(q);
1013    
1014                                    qPos.add(userId);
1015    
1016                                    count = (Long)q.uniqueResult();
1017    
1018                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1019                            }
1020                            catch (Exception e) {
1021                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1022    
1023                                    throw processException(e);
1024                            }
1025                            finally {
1026                                    closeSession(session);
1027                            }
1028                    }
1029    
1030                    return count.intValue();
1031            }
1032    
1033            private static final String _FINDER_COLUMN_USERID_USERID_2 = "userTracker.userId = ?";
1034            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_SESSIONID =
1035                    new FinderPath(UserTrackerModelImpl.ENTITY_CACHE_ENABLED,
1036                            UserTrackerModelImpl.FINDER_CACHE_ENABLED, UserTrackerImpl.class,
1037                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findBySessionId",
1038                            new String[] {
1039                                    String.class.getName(),
1040                                    
1041                            Integer.class.getName(), Integer.class.getName(),
1042                                    OrderByComparator.class.getName()
1043                            });
1044            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SESSIONID =
1045                    new FinderPath(UserTrackerModelImpl.ENTITY_CACHE_ENABLED,
1046                            UserTrackerModelImpl.FINDER_CACHE_ENABLED, UserTrackerImpl.class,
1047                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findBySessionId",
1048                            new String[] { String.class.getName() },
1049                            UserTrackerModelImpl.SESSIONID_COLUMN_BITMASK);
1050            public static final FinderPath FINDER_PATH_COUNT_BY_SESSIONID = new FinderPath(UserTrackerModelImpl.ENTITY_CACHE_ENABLED,
1051                            UserTrackerModelImpl.FINDER_CACHE_ENABLED, Long.class,
1052                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countBySessionId",
1053                            new String[] { String.class.getName() });
1054    
1055            /**
1056             * Returns all the user trackers where sessionId = &#63;.
1057             *
1058             * @param sessionId the session ID
1059             * @return the matching user trackers
1060             * @throws SystemException if a system exception occurred
1061             */
1062            public List<UserTracker> findBySessionId(String sessionId)
1063                    throws SystemException {
1064                    return findBySessionId(sessionId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1065                            null);
1066            }
1067    
1068            /**
1069             * Returns a range of all the user trackers where sessionId = &#63;.
1070             *
1071             * <p>
1072             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.UserTrackerModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1073             * </p>
1074             *
1075             * @param sessionId the session ID
1076             * @param start the lower bound of the range of user trackers
1077             * @param end the upper bound of the range of user trackers (not inclusive)
1078             * @return the range of matching user trackers
1079             * @throws SystemException if a system exception occurred
1080             */
1081            public List<UserTracker> findBySessionId(String sessionId, int start,
1082                    int end) throws SystemException {
1083                    return findBySessionId(sessionId, start, end, null);
1084            }
1085    
1086            /**
1087             * Returns an ordered range of all the user trackers where sessionId = &#63;.
1088             *
1089             * <p>
1090             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.UserTrackerModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1091             * </p>
1092             *
1093             * @param sessionId the session ID
1094             * @param start the lower bound of the range of user trackers
1095             * @param end the upper bound of the range of user trackers (not inclusive)
1096             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1097             * @return the ordered range of matching user trackers
1098             * @throws SystemException if a system exception occurred
1099             */
1100            public List<UserTracker> findBySessionId(String sessionId, int start,
1101                    int end, OrderByComparator orderByComparator) throws SystemException {
1102                    boolean pagination = true;
1103                    FinderPath finderPath = null;
1104                    Object[] finderArgs = null;
1105    
1106                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1107                                    (orderByComparator == null)) {
1108                            pagination = false;
1109                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SESSIONID;
1110                            finderArgs = new Object[] { sessionId };
1111                    }
1112                    else {
1113                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_SESSIONID;
1114                            finderArgs = new Object[] { sessionId, start, end, orderByComparator };
1115                    }
1116    
1117                    List<UserTracker> list = (List<UserTracker>)FinderCacheUtil.getResult(finderPath,
1118                                    finderArgs, this);
1119    
1120                    if ((list != null) && !list.isEmpty()) {
1121                            for (UserTracker userTracker : list) {
1122                                    if (!Validator.equals(sessionId, userTracker.getSessionId())) {
1123                                            list = null;
1124    
1125                                            break;
1126                                    }
1127                            }
1128                    }
1129    
1130                    if (list == null) {
1131                            StringBundler query = null;
1132    
1133                            if (orderByComparator != null) {
1134                                    query = new StringBundler(3 +
1135                                                    (orderByComparator.getOrderByFields().length * 3));
1136                            }
1137                            else {
1138                                    query = new StringBundler(3);
1139                            }
1140    
1141                            query.append(_SQL_SELECT_USERTRACKER_WHERE);
1142    
1143                            boolean bindSessionId = false;
1144    
1145                            if (sessionId == null) {
1146                                    query.append(_FINDER_COLUMN_SESSIONID_SESSIONID_1);
1147                            }
1148                            else if (sessionId.equals(StringPool.BLANK)) {
1149                                    query.append(_FINDER_COLUMN_SESSIONID_SESSIONID_3);
1150                            }
1151                            else {
1152                                    bindSessionId = true;
1153    
1154                                    query.append(_FINDER_COLUMN_SESSIONID_SESSIONID_2);
1155                            }
1156    
1157                            if (orderByComparator != null) {
1158                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1159                                            orderByComparator);
1160                            }
1161                            else
1162                             if (pagination) {
1163                                    query.append(UserTrackerModelImpl.ORDER_BY_JPQL);
1164                            }
1165    
1166                            String sql = query.toString();
1167    
1168                            Session session = null;
1169    
1170                            try {
1171                                    session = openSession();
1172    
1173                                    Query q = session.createQuery(sql);
1174    
1175                                    QueryPos qPos = QueryPos.getInstance(q);
1176    
1177                                    if (bindSessionId) {
1178                                            qPos.add(sessionId);
1179                                    }
1180    
1181                                    if (!pagination) {
1182                                            list = (List<UserTracker>)QueryUtil.list(q, getDialect(),
1183                                                            start, end, false);
1184    
1185                                            Collections.sort(list);
1186    
1187                                            list = new UnmodifiableList<UserTracker>(list);
1188                                    }
1189                                    else {
1190                                            list = (List<UserTracker>)QueryUtil.list(q, getDialect(),
1191                                                            start, end);
1192                                    }
1193    
1194                                    cacheResult(list);
1195    
1196                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1197                            }
1198                            catch (Exception e) {
1199                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1200    
1201                                    throw processException(e);
1202                            }
1203                            finally {
1204                                    closeSession(session);
1205                            }
1206                    }
1207    
1208                    return list;
1209            }
1210    
1211            /**
1212             * Returns the first user tracker in the ordered set where sessionId = &#63;.
1213             *
1214             * @param sessionId the session ID
1215             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1216             * @return the first matching user tracker
1217             * @throws com.liferay.portal.NoSuchUserTrackerException if a matching user tracker could not be found
1218             * @throws SystemException if a system exception occurred
1219             */
1220            public UserTracker findBySessionId_First(String sessionId,
1221                    OrderByComparator orderByComparator)
1222                    throws NoSuchUserTrackerException, SystemException {
1223                    UserTracker userTracker = fetchBySessionId_First(sessionId,
1224                                    orderByComparator);
1225    
1226                    if (userTracker != null) {
1227                            return userTracker;
1228                    }
1229    
1230                    StringBundler msg = new StringBundler(4);
1231    
1232                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1233    
1234                    msg.append("sessionId=");
1235                    msg.append(sessionId);
1236    
1237                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1238    
1239                    throw new NoSuchUserTrackerException(msg.toString());
1240            }
1241    
1242            /**
1243             * Returns the first user tracker in the ordered set where sessionId = &#63;.
1244             *
1245             * @param sessionId the session ID
1246             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1247             * @return the first matching user tracker, or <code>null</code> if a matching user tracker could not be found
1248             * @throws SystemException if a system exception occurred
1249             */
1250            public UserTracker fetchBySessionId_First(String sessionId,
1251                    OrderByComparator orderByComparator) throws SystemException {
1252                    List<UserTracker> list = findBySessionId(sessionId, 0, 1,
1253                                    orderByComparator);
1254    
1255                    if (!list.isEmpty()) {
1256                            return list.get(0);
1257                    }
1258    
1259                    return null;
1260            }
1261    
1262            /**
1263             * Returns the last user tracker in the ordered set where sessionId = &#63;.
1264             *
1265             * @param sessionId the session ID
1266             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1267             * @return the last matching user tracker
1268             * @throws com.liferay.portal.NoSuchUserTrackerException if a matching user tracker could not be found
1269             * @throws SystemException if a system exception occurred
1270             */
1271            public UserTracker findBySessionId_Last(String sessionId,
1272                    OrderByComparator orderByComparator)
1273                    throws NoSuchUserTrackerException, SystemException {
1274                    UserTracker userTracker = fetchBySessionId_Last(sessionId,
1275                                    orderByComparator);
1276    
1277                    if (userTracker != null) {
1278                            return userTracker;
1279                    }
1280    
1281                    StringBundler msg = new StringBundler(4);
1282    
1283                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1284    
1285                    msg.append("sessionId=");
1286                    msg.append(sessionId);
1287    
1288                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1289    
1290                    throw new NoSuchUserTrackerException(msg.toString());
1291            }
1292    
1293            /**
1294             * Returns the last user tracker in the ordered set where sessionId = &#63;.
1295             *
1296             * @param sessionId the session ID
1297             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1298             * @return the last matching user tracker, or <code>null</code> if a matching user tracker could not be found
1299             * @throws SystemException if a system exception occurred
1300             */
1301            public UserTracker fetchBySessionId_Last(String sessionId,
1302                    OrderByComparator orderByComparator) throws SystemException {
1303                    int count = countBySessionId(sessionId);
1304    
1305                    List<UserTracker> list = findBySessionId(sessionId, count - 1, count,
1306                                    orderByComparator);
1307    
1308                    if (!list.isEmpty()) {
1309                            return list.get(0);
1310                    }
1311    
1312                    return null;
1313            }
1314    
1315            /**
1316             * Returns the user trackers before and after the current user tracker in the ordered set where sessionId = &#63;.
1317             *
1318             * @param userTrackerId the primary key of the current user tracker
1319             * @param sessionId the session ID
1320             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1321             * @return the previous, current, and next user tracker
1322             * @throws com.liferay.portal.NoSuchUserTrackerException if a user tracker with the primary key could not be found
1323             * @throws SystemException if a system exception occurred
1324             */
1325            public UserTracker[] findBySessionId_PrevAndNext(long userTrackerId,
1326                    String sessionId, OrderByComparator orderByComparator)
1327                    throws NoSuchUserTrackerException, SystemException {
1328                    UserTracker userTracker = findByPrimaryKey(userTrackerId);
1329    
1330                    Session session = null;
1331    
1332                    try {
1333                            session = openSession();
1334    
1335                            UserTracker[] array = new UserTrackerImpl[3];
1336    
1337                            array[0] = getBySessionId_PrevAndNext(session, userTracker,
1338                                            sessionId, orderByComparator, true);
1339    
1340                            array[1] = userTracker;
1341    
1342                            array[2] = getBySessionId_PrevAndNext(session, userTracker,
1343                                            sessionId, orderByComparator, false);
1344    
1345                            return array;
1346                    }
1347                    catch (Exception e) {
1348                            throw processException(e);
1349                    }
1350                    finally {
1351                            closeSession(session);
1352                    }
1353            }
1354    
1355            protected UserTracker getBySessionId_PrevAndNext(Session session,
1356                    UserTracker userTracker, String sessionId,
1357                    OrderByComparator orderByComparator, boolean previous) {
1358                    StringBundler query = null;
1359    
1360                    if (orderByComparator != null) {
1361                            query = new StringBundler(6 +
1362                                            (orderByComparator.getOrderByFields().length * 6));
1363                    }
1364                    else {
1365                            query = new StringBundler(3);
1366                    }
1367    
1368                    query.append(_SQL_SELECT_USERTRACKER_WHERE);
1369    
1370                    boolean bindSessionId = false;
1371    
1372                    if (sessionId == null) {
1373                            query.append(_FINDER_COLUMN_SESSIONID_SESSIONID_1);
1374                    }
1375                    else if (sessionId.equals(StringPool.BLANK)) {
1376                            query.append(_FINDER_COLUMN_SESSIONID_SESSIONID_3);
1377                    }
1378                    else {
1379                            bindSessionId = true;
1380    
1381                            query.append(_FINDER_COLUMN_SESSIONID_SESSIONID_2);
1382                    }
1383    
1384                    if (orderByComparator != null) {
1385                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1386    
1387                            if (orderByConditionFields.length > 0) {
1388                                    query.append(WHERE_AND);
1389                            }
1390    
1391                            for (int i = 0; i < orderByConditionFields.length; i++) {
1392                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1393                                    query.append(orderByConditionFields[i]);
1394    
1395                                    if ((i + 1) < orderByConditionFields.length) {
1396                                            if (orderByComparator.isAscending() ^ previous) {
1397                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1398                                            }
1399                                            else {
1400                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1401                                            }
1402                                    }
1403                                    else {
1404                                            if (orderByComparator.isAscending() ^ previous) {
1405                                                    query.append(WHERE_GREATER_THAN);
1406                                            }
1407                                            else {
1408                                                    query.append(WHERE_LESSER_THAN);
1409                                            }
1410                                    }
1411                            }
1412    
1413                            query.append(ORDER_BY_CLAUSE);
1414    
1415                            String[] orderByFields = orderByComparator.getOrderByFields();
1416    
1417                            for (int i = 0; i < orderByFields.length; i++) {
1418                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1419                                    query.append(orderByFields[i]);
1420    
1421                                    if ((i + 1) < orderByFields.length) {
1422                                            if (orderByComparator.isAscending() ^ previous) {
1423                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1424                                            }
1425                                            else {
1426                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1427                                            }
1428                                    }
1429                                    else {
1430                                            if (orderByComparator.isAscending() ^ previous) {
1431                                                    query.append(ORDER_BY_ASC);
1432                                            }
1433                                            else {
1434                                                    query.append(ORDER_BY_DESC);
1435                                            }
1436                                    }
1437                            }
1438                    }
1439                    else {
1440                            query.append(UserTrackerModelImpl.ORDER_BY_JPQL);
1441                    }
1442    
1443                    String sql = query.toString();
1444    
1445                    Query q = session.createQuery(sql);
1446    
1447                    q.setFirstResult(0);
1448                    q.setMaxResults(2);
1449    
1450                    QueryPos qPos = QueryPos.getInstance(q);
1451    
1452                    if (bindSessionId) {
1453                            qPos.add(sessionId);
1454                    }
1455    
1456                    if (orderByComparator != null) {
1457                            Object[] values = orderByComparator.getOrderByConditionValues(userTracker);
1458    
1459                            for (Object value : values) {
1460                                    qPos.add(value);
1461                            }
1462                    }
1463    
1464                    List<UserTracker> list = q.list();
1465    
1466                    if (list.size() == 2) {
1467                            return list.get(1);
1468                    }
1469                    else {
1470                            return null;
1471                    }
1472            }
1473    
1474            /**
1475             * Removes all the user trackers where sessionId = &#63; from the database.
1476             *
1477             * @param sessionId the session ID
1478             * @throws SystemException if a system exception occurred
1479             */
1480            public void removeBySessionId(String sessionId) throws SystemException {
1481                    for (UserTracker userTracker : findBySessionId(sessionId,
1482                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1483                            remove(userTracker);
1484                    }
1485            }
1486    
1487            /**
1488             * Returns the number of user trackers where sessionId = &#63;.
1489             *
1490             * @param sessionId the session ID
1491             * @return the number of matching user trackers
1492             * @throws SystemException if a system exception occurred
1493             */
1494            public int countBySessionId(String sessionId) throws SystemException {
1495                    FinderPath finderPath = FINDER_PATH_COUNT_BY_SESSIONID;
1496    
1497                    Object[] finderArgs = new Object[] { sessionId };
1498    
1499                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1500                                    this);
1501    
1502                    if (count == null) {
1503                            StringBundler query = new StringBundler(2);
1504    
1505                            query.append(_SQL_COUNT_USERTRACKER_WHERE);
1506    
1507                            boolean bindSessionId = false;
1508    
1509                            if (sessionId == null) {
1510                                    query.append(_FINDER_COLUMN_SESSIONID_SESSIONID_1);
1511                            }
1512                            else if (sessionId.equals(StringPool.BLANK)) {
1513                                    query.append(_FINDER_COLUMN_SESSIONID_SESSIONID_3);
1514                            }
1515                            else {
1516                                    bindSessionId = true;
1517    
1518                                    query.append(_FINDER_COLUMN_SESSIONID_SESSIONID_2);
1519                            }
1520    
1521                            String sql = query.toString();
1522    
1523                            Session session = null;
1524    
1525                            try {
1526                                    session = openSession();
1527    
1528                                    Query q = session.createQuery(sql);
1529    
1530                                    QueryPos qPos = QueryPos.getInstance(q);
1531    
1532                                    if (bindSessionId) {
1533                                            qPos.add(sessionId);
1534                                    }
1535    
1536                                    count = (Long)q.uniqueResult();
1537    
1538                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1539                            }
1540                            catch (Exception e) {
1541                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1542    
1543                                    throw processException(e);
1544                            }
1545                            finally {
1546                                    closeSession(session);
1547                            }
1548                    }
1549    
1550                    return count.intValue();
1551            }
1552    
1553            private static final String _FINDER_COLUMN_SESSIONID_SESSIONID_1 = "userTracker.sessionId IS NULL";
1554            private static final String _FINDER_COLUMN_SESSIONID_SESSIONID_2 = "userTracker.sessionId = ?";
1555            private static final String _FINDER_COLUMN_SESSIONID_SESSIONID_3 = "(userTracker.sessionId IS NULL OR userTracker.sessionId = '')";
1556    
1557            /**
1558             * Caches the user tracker in the entity cache if it is enabled.
1559             *
1560             * @param userTracker the user tracker
1561             */
1562            public void cacheResult(UserTracker userTracker) {
1563                    EntityCacheUtil.putResult(UserTrackerModelImpl.ENTITY_CACHE_ENABLED,
1564                            UserTrackerImpl.class, userTracker.getPrimaryKey(), userTracker);
1565    
1566                    userTracker.resetOriginalValues();
1567            }
1568    
1569            /**
1570             * Caches the user trackers in the entity cache if it is enabled.
1571             *
1572             * @param userTrackers the user trackers
1573             */
1574            public void cacheResult(List<UserTracker> userTrackers) {
1575                    for (UserTracker userTracker : userTrackers) {
1576                            if (EntityCacheUtil.getResult(
1577                                                    UserTrackerModelImpl.ENTITY_CACHE_ENABLED,
1578                                                    UserTrackerImpl.class, userTracker.getPrimaryKey()) == null) {
1579                                    cacheResult(userTracker);
1580                            }
1581                            else {
1582                                    userTracker.resetOriginalValues();
1583                            }
1584                    }
1585            }
1586    
1587            /**
1588             * Clears the cache for all user trackers.
1589             *
1590             * <p>
1591             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
1592             * </p>
1593             */
1594            @Override
1595            public void clearCache() {
1596                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
1597                            CacheRegistryUtil.clear(UserTrackerImpl.class.getName());
1598                    }
1599    
1600                    EntityCacheUtil.clearCache(UserTrackerImpl.class.getName());
1601    
1602                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
1603                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1604                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1605            }
1606    
1607            /**
1608             * Clears the cache for the user tracker.
1609             *
1610             * <p>
1611             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
1612             * </p>
1613             */
1614            @Override
1615            public void clearCache(UserTracker userTracker) {
1616                    EntityCacheUtil.removeResult(UserTrackerModelImpl.ENTITY_CACHE_ENABLED,
1617                            UserTrackerImpl.class, userTracker.getPrimaryKey());
1618    
1619                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1620                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1621            }
1622    
1623            @Override
1624            public void clearCache(List<UserTracker> userTrackers) {
1625                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1626                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1627    
1628                    for (UserTracker userTracker : userTrackers) {
1629                            EntityCacheUtil.removeResult(UserTrackerModelImpl.ENTITY_CACHE_ENABLED,
1630                                    UserTrackerImpl.class, userTracker.getPrimaryKey());
1631                    }
1632            }
1633    
1634            /**
1635             * Creates a new user tracker with the primary key. Does not add the user tracker to the database.
1636             *
1637             * @param userTrackerId the primary key for the new user tracker
1638             * @return the new user tracker
1639             */
1640            public UserTracker create(long userTrackerId) {
1641                    UserTracker userTracker = new UserTrackerImpl();
1642    
1643                    userTracker.setNew(true);
1644                    userTracker.setPrimaryKey(userTrackerId);
1645    
1646                    return userTracker;
1647            }
1648    
1649            /**
1650             * Removes the user tracker with the primary key from the database. Also notifies the appropriate model listeners.
1651             *
1652             * @param userTrackerId the primary key of the user tracker
1653             * @return the user tracker that was removed
1654             * @throws com.liferay.portal.NoSuchUserTrackerException if a user tracker with the primary key could not be found
1655             * @throws SystemException if a system exception occurred
1656             */
1657            public UserTracker remove(long userTrackerId)
1658                    throws NoSuchUserTrackerException, SystemException {
1659                    return remove((Serializable)userTrackerId);
1660            }
1661    
1662            /**
1663             * Removes the user tracker with the primary key from the database. Also notifies the appropriate model listeners.
1664             *
1665             * @param primaryKey the primary key of the user tracker
1666             * @return the user tracker that was removed
1667             * @throws com.liferay.portal.NoSuchUserTrackerException if a user tracker with the primary key could not be found
1668             * @throws SystemException if a system exception occurred
1669             */
1670            @Override
1671            public UserTracker remove(Serializable primaryKey)
1672                    throws NoSuchUserTrackerException, SystemException {
1673                    Session session = null;
1674    
1675                    try {
1676                            session = openSession();
1677    
1678                            UserTracker userTracker = (UserTracker)session.get(UserTrackerImpl.class,
1679                                            primaryKey);
1680    
1681                            if (userTracker == null) {
1682                                    if (_log.isWarnEnabled()) {
1683                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1684                                    }
1685    
1686                                    throw new NoSuchUserTrackerException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1687                                            primaryKey);
1688                            }
1689    
1690                            return remove(userTracker);
1691                    }
1692                    catch (NoSuchUserTrackerException nsee) {
1693                            throw nsee;
1694                    }
1695                    catch (Exception e) {
1696                            throw processException(e);
1697                    }
1698                    finally {
1699                            closeSession(session);
1700                    }
1701            }
1702    
1703            @Override
1704            protected UserTracker removeImpl(UserTracker userTracker)
1705                    throws SystemException {
1706                    userTracker = toUnwrappedModel(userTracker);
1707    
1708                    Session session = null;
1709    
1710                    try {
1711                            session = openSession();
1712    
1713                            if (!session.contains(userTracker)) {
1714                                    userTracker = (UserTracker)session.get(UserTrackerImpl.class,
1715                                                    userTracker.getPrimaryKeyObj());
1716                            }
1717    
1718                            if (userTracker != null) {
1719                                    session.delete(userTracker);
1720                            }
1721                    }
1722                    catch (Exception e) {
1723                            throw processException(e);
1724                    }
1725                    finally {
1726                            closeSession(session);
1727                    }
1728    
1729                    if (userTracker != null) {
1730                            clearCache(userTracker);
1731                    }
1732    
1733                    return userTracker;
1734            }
1735    
1736            @Override
1737            public UserTracker updateImpl(
1738                    com.liferay.portal.model.UserTracker userTracker)
1739                    throws SystemException {
1740                    userTracker = toUnwrappedModel(userTracker);
1741    
1742                    boolean isNew = userTracker.isNew();
1743    
1744                    UserTrackerModelImpl userTrackerModelImpl = (UserTrackerModelImpl)userTracker;
1745    
1746                    Session session = null;
1747    
1748                    try {
1749                            session = openSession();
1750    
1751                            if (userTracker.isNew()) {
1752                                    session.save(userTracker);
1753    
1754                                    userTracker.setNew(false);
1755                            }
1756                            else {
1757                                    session.merge(userTracker);
1758                            }
1759                    }
1760                    catch (Exception e) {
1761                            throw processException(e);
1762                    }
1763                    finally {
1764                            closeSession(session);
1765                    }
1766    
1767                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1768    
1769                    if (isNew || !UserTrackerModelImpl.COLUMN_BITMASK_ENABLED) {
1770                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1771                    }
1772    
1773                    else {
1774                            if ((userTrackerModelImpl.getColumnBitmask() &
1775                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
1776                                    Object[] args = new Object[] {
1777                                                    userTrackerModelImpl.getOriginalCompanyId()
1778                                            };
1779    
1780                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
1781                                            args);
1782                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
1783                                            args);
1784    
1785                                    args = new Object[] { userTrackerModelImpl.getCompanyId() };
1786    
1787                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
1788                                            args);
1789                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
1790                                            args);
1791                            }
1792    
1793                            if ((userTrackerModelImpl.getColumnBitmask() &
1794                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
1795                                    Object[] args = new Object[] {
1796                                                    userTrackerModelImpl.getOriginalUserId()
1797                                            };
1798    
1799                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
1800                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
1801                                            args);
1802    
1803                                    args = new Object[] { userTrackerModelImpl.getUserId() };
1804    
1805                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
1806                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
1807                                            args);
1808                            }
1809    
1810                            if ((userTrackerModelImpl.getColumnBitmask() &
1811                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SESSIONID.getColumnBitmask()) != 0) {
1812                                    Object[] args = new Object[] {
1813                                                    userTrackerModelImpl.getOriginalSessionId()
1814                                            };
1815    
1816                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_SESSIONID,
1817                                            args);
1818                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SESSIONID,
1819                                            args);
1820    
1821                                    args = new Object[] { userTrackerModelImpl.getSessionId() };
1822    
1823                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_SESSIONID,
1824                                            args);
1825                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SESSIONID,
1826                                            args);
1827                            }
1828                    }
1829    
1830                    EntityCacheUtil.putResult(UserTrackerModelImpl.ENTITY_CACHE_ENABLED,
1831                            UserTrackerImpl.class, userTracker.getPrimaryKey(), userTracker);
1832    
1833                    return userTracker;
1834            }
1835    
1836            protected UserTracker toUnwrappedModel(UserTracker userTracker) {
1837                    if (userTracker instanceof UserTrackerImpl) {
1838                            return userTracker;
1839                    }
1840    
1841                    UserTrackerImpl userTrackerImpl = new UserTrackerImpl();
1842    
1843                    userTrackerImpl.setNew(userTracker.isNew());
1844                    userTrackerImpl.setPrimaryKey(userTracker.getPrimaryKey());
1845    
1846                    userTrackerImpl.setUserTrackerId(userTracker.getUserTrackerId());
1847                    userTrackerImpl.setCompanyId(userTracker.getCompanyId());
1848                    userTrackerImpl.setUserId(userTracker.getUserId());
1849                    userTrackerImpl.setModifiedDate(userTracker.getModifiedDate());
1850                    userTrackerImpl.setSessionId(userTracker.getSessionId());
1851                    userTrackerImpl.setRemoteAddr(userTracker.getRemoteAddr());
1852                    userTrackerImpl.setRemoteHost(userTracker.getRemoteHost());
1853                    userTrackerImpl.setUserAgent(userTracker.getUserAgent());
1854    
1855                    return userTrackerImpl;
1856            }
1857    
1858            /**
1859             * Returns the user tracker with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
1860             *
1861             * @param primaryKey the primary key of the user tracker
1862             * @return the user tracker
1863             * @throws com.liferay.portal.NoSuchUserTrackerException if a user tracker with the primary key could not be found
1864             * @throws SystemException if a system exception occurred
1865             */
1866            @Override
1867            public UserTracker findByPrimaryKey(Serializable primaryKey)
1868                    throws NoSuchUserTrackerException, SystemException {
1869                    UserTracker userTracker = fetchByPrimaryKey(primaryKey);
1870    
1871                    if (userTracker == null) {
1872                            if (_log.isWarnEnabled()) {
1873                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1874                            }
1875    
1876                            throw new NoSuchUserTrackerException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1877                                    primaryKey);
1878                    }
1879    
1880                    return userTracker;
1881            }
1882    
1883            /**
1884             * Returns the user tracker with the primary key or throws a {@link com.liferay.portal.NoSuchUserTrackerException} if it could not be found.
1885             *
1886             * @param userTrackerId the primary key of the user tracker
1887             * @return the user tracker
1888             * @throws com.liferay.portal.NoSuchUserTrackerException if a user tracker with the primary key could not be found
1889             * @throws SystemException if a system exception occurred
1890             */
1891            public UserTracker findByPrimaryKey(long userTrackerId)
1892                    throws NoSuchUserTrackerException, SystemException {
1893                    return findByPrimaryKey((Serializable)userTrackerId);
1894            }
1895    
1896            /**
1897             * Returns the user tracker with the primary key or returns <code>null</code> if it could not be found.
1898             *
1899             * @param primaryKey the primary key of the user tracker
1900             * @return the user tracker, or <code>null</code> if a user tracker with the primary key could not be found
1901             * @throws SystemException if a system exception occurred
1902             */
1903            @Override
1904            public UserTracker fetchByPrimaryKey(Serializable primaryKey)
1905                    throws SystemException {
1906                    UserTracker userTracker = (UserTracker)EntityCacheUtil.getResult(UserTrackerModelImpl.ENTITY_CACHE_ENABLED,
1907                                    UserTrackerImpl.class, primaryKey);
1908    
1909                    if (userTracker == _nullUserTracker) {
1910                            return null;
1911                    }
1912    
1913                    if (userTracker == null) {
1914                            Session session = null;
1915    
1916                            try {
1917                                    session = openSession();
1918    
1919                                    userTracker = (UserTracker)session.get(UserTrackerImpl.class,
1920                                                    primaryKey);
1921    
1922                                    if (userTracker != null) {
1923                                            cacheResult(userTracker);
1924                                    }
1925                                    else {
1926                                            EntityCacheUtil.putResult(UserTrackerModelImpl.ENTITY_CACHE_ENABLED,
1927                                                    UserTrackerImpl.class, primaryKey, _nullUserTracker);
1928                                    }
1929                            }
1930                            catch (Exception e) {
1931                                    EntityCacheUtil.removeResult(UserTrackerModelImpl.ENTITY_CACHE_ENABLED,
1932                                            UserTrackerImpl.class, primaryKey);
1933    
1934                                    throw processException(e);
1935                            }
1936                            finally {
1937                                    closeSession(session);
1938                            }
1939                    }
1940    
1941                    return userTracker;
1942            }
1943    
1944            /**
1945             * Returns the user tracker with the primary key or returns <code>null</code> if it could not be found.
1946             *
1947             * @param userTrackerId the primary key of the user tracker
1948             * @return the user tracker, or <code>null</code> if a user tracker with the primary key could not be found
1949             * @throws SystemException if a system exception occurred
1950             */
1951            public UserTracker fetchByPrimaryKey(long userTrackerId)
1952                    throws SystemException {
1953                    return fetchByPrimaryKey((Serializable)userTrackerId);
1954            }
1955    
1956            /**
1957             * Returns all the user trackers.
1958             *
1959             * @return the user trackers
1960             * @throws SystemException if a system exception occurred
1961             */
1962            public List<UserTracker> findAll() throws SystemException {
1963                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1964            }
1965    
1966            /**
1967             * Returns a range of all the user trackers.
1968             *
1969             * <p>
1970             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.UserTrackerModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1971             * </p>
1972             *
1973             * @param start the lower bound of the range of user trackers
1974             * @param end the upper bound of the range of user trackers (not inclusive)
1975             * @return the range of user trackers
1976             * @throws SystemException if a system exception occurred
1977             */
1978            public List<UserTracker> findAll(int start, int end)
1979                    throws SystemException {
1980                    return findAll(start, end, null);
1981            }
1982    
1983            /**
1984             * Returns an ordered range of all the user trackers.
1985             *
1986             * <p>
1987             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.UserTrackerModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1988             * </p>
1989             *
1990             * @param start the lower bound of the range of user trackers
1991             * @param end the upper bound of the range of user trackers (not inclusive)
1992             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1993             * @return the ordered range of user trackers
1994             * @throws SystemException if a system exception occurred
1995             */
1996            public List<UserTracker> findAll(int start, int end,
1997                    OrderByComparator orderByComparator) throws SystemException {
1998                    boolean pagination = true;
1999                    FinderPath finderPath = null;
2000                    Object[] finderArgs = null;
2001    
2002                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2003                                    (orderByComparator == null)) {
2004                            pagination = false;
2005                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2006                            finderArgs = FINDER_ARGS_EMPTY;
2007                    }
2008                    else {
2009                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2010                            finderArgs = new Object[] { start, end, orderByComparator };
2011                    }
2012    
2013                    List<UserTracker> list = (List<UserTracker>)FinderCacheUtil.getResult(finderPath,
2014                                    finderArgs, this);
2015    
2016                    if (list == null) {
2017                            StringBundler query = null;
2018                            String sql = null;
2019    
2020                            if (orderByComparator != null) {
2021                                    query = new StringBundler(2 +
2022                                                    (orderByComparator.getOrderByFields().length * 3));
2023    
2024                                    query.append(_SQL_SELECT_USERTRACKER);
2025    
2026                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2027                                            orderByComparator);
2028    
2029                                    sql = query.toString();
2030                            }
2031                            else {
2032                                    sql = _SQL_SELECT_USERTRACKER;
2033    
2034                                    if (pagination) {
2035                                            sql = sql.concat(UserTrackerModelImpl.ORDER_BY_JPQL);
2036                                    }
2037                            }
2038    
2039                            Session session = null;
2040    
2041                            try {
2042                                    session = openSession();
2043    
2044                                    Query q = session.createQuery(sql);
2045    
2046                                    if (!pagination) {
2047                                            list = (List<UserTracker>)QueryUtil.list(q, getDialect(),
2048                                                            start, end, false);
2049    
2050                                            Collections.sort(list);
2051    
2052                                            list = new UnmodifiableList<UserTracker>(list);
2053                                    }
2054                                    else {
2055                                            list = (List<UserTracker>)QueryUtil.list(q, getDialect(),
2056                                                            start, end);
2057                                    }
2058    
2059                                    cacheResult(list);
2060    
2061                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2062                            }
2063                            catch (Exception e) {
2064                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2065    
2066                                    throw processException(e);
2067                            }
2068                            finally {
2069                                    closeSession(session);
2070                            }
2071                    }
2072    
2073                    return list;
2074            }
2075    
2076            /**
2077             * Removes all the user trackers from the database.
2078             *
2079             * @throws SystemException if a system exception occurred
2080             */
2081            public void removeAll() throws SystemException {
2082                    for (UserTracker userTracker : findAll()) {
2083                            remove(userTracker);
2084                    }
2085            }
2086    
2087            /**
2088             * Returns the number of user trackers.
2089             *
2090             * @return the number of user trackers
2091             * @throws SystemException if a system exception occurred
2092             */
2093            public int countAll() throws SystemException {
2094                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2095                                    FINDER_ARGS_EMPTY, this);
2096    
2097                    if (count == null) {
2098                            Session session = null;
2099    
2100                            try {
2101                                    session = openSession();
2102    
2103                                    Query q = session.createQuery(_SQL_COUNT_USERTRACKER);
2104    
2105                                    count = (Long)q.uniqueResult();
2106    
2107                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2108                                            FINDER_ARGS_EMPTY, count);
2109                            }
2110                            catch (Exception e) {
2111                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
2112                                            FINDER_ARGS_EMPTY);
2113    
2114                                    throw processException(e);
2115                            }
2116                            finally {
2117                                    closeSession(session);
2118                            }
2119                    }
2120    
2121                    return count.intValue();
2122            }
2123    
2124            /**
2125             * Initializes the user tracker persistence.
2126             */
2127            public void afterPropertiesSet() {
2128                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2129                                            com.liferay.portal.util.PropsUtil.get(
2130                                                    "value.object.listener.com.liferay.portal.model.UserTracker")));
2131    
2132                    if (listenerClassNames.length > 0) {
2133                            try {
2134                                    List<ModelListener<UserTracker>> listenersList = new ArrayList<ModelListener<UserTracker>>();
2135    
2136                                    for (String listenerClassName : listenerClassNames) {
2137                                            listenersList.add((ModelListener<UserTracker>)InstanceFactory.newInstance(
2138                                                            getClassLoader(), listenerClassName));
2139                                    }
2140    
2141                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2142                            }
2143                            catch (Exception e) {
2144                                    _log.error(e);
2145                            }
2146                    }
2147            }
2148    
2149            public void destroy() {
2150                    EntityCacheUtil.removeCache(UserTrackerImpl.class.getName());
2151                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2152                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2153                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2154            }
2155    
2156            private static final String _SQL_SELECT_USERTRACKER = "SELECT userTracker FROM UserTracker userTracker";
2157            private static final String _SQL_SELECT_USERTRACKER_WHERE = "SELECT userTracker FROM UserTracker userTracker WHERE ";
2158            private static final String _SQL_COUNT_USERTRACKER = "SELECT COUNT(userTracker) FROM UserTracker userTracker";
2159            private static final String _SQL_COUNT_USERTRACKER_WHERE = "SELECT COUNT(userTracker) FROM UserTracker userTracker WHERE ";
2160            private static final String _ORDER_BY_ENTITY_ALIAS = "userTracker.";
2161            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No UserTracker exists with the primary key ";
2162            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No UserTracker exists with the key {";
2163            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2164            private static Log _log = LogFactoryUtil.getLog(UserTrackerPersistenceImpl.class);
2165            private static UserTracker _nullUserTracker = new UserTrackerImpl() {
2166                            @Override
2167                            public Object clone() {
2168                                    return this;
2169                            }
2170    
2171                            @Override
2172                            public CacheModel<UserTracker> toCacheModel() {
2173                                    return _nullUserTrackerCacheModel;
2174                            }
2175                    };
2176    
2177            private static CacheModel<UserTracker> _nullUserTrackerCacheModel = new CacheModel<UserTracker>() {
2178                            public UserTracker toEntityModel() {
2179                                    return _nullUserTracker;
2180                            }
2181                    };
2182    }