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