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