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            public UserTrackerPersistenceImpl() {
1600                    setModelClass(UserTracker.class);
1601            }
1602    
1603            /**
1604             * Caches the user tracker in the entity cache if it is enabled.
1605             *
1606             * @param userTracker the user tracker
1607             */
1608            @Override
1609            public void cacheResult(UserTracker userTracker) {
1610                    EntityCacheUtil.putResult(UserTrackerModelImpl.ENTITY_CACHE_ENABLED,
1611                            UserTrackerImpl.class, userTracker.getPrimaryKey(), userTracker);
1612    
1613                    userTracker.resetOriginalValues();
1614            }
1615    
1616            /**
1617             * Caches the user trackers in the entity cache if it is enabled.
1618             *
1619             * @param userTrackers the user trackers
1620             */
1621            @Override
1622            public void cacheResult(List<UserTracker> userTrackers) {
1623                    for (UserTracker userTracker : userTrackers) {
1624                            if (EntityCacheUtil.getResult(
1625                                                    UserTrackerModelImpl.ENTITY_CACHE_ENABLED,
1626                                                    UserTrackerImpl.class, userTracker.getPrimaryKey()) == null) {
1627                                    cacheResult(userTracker);
1628                            }
1629                            else {
1630                                    userTracker.resetOriginalValues();
1631                            }
1632                    }
1633            }
1634    
1635            /**
1636             * Clears the cache for all user trackers.
1637             *
1638             * <p>
1639             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
1640             * </p>
1641             */
1642            @Override
1643            public void clearCache() {
1644                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
1645                            CacheRegistryUtil.clear(UserTrackerImpl.class.getName());
1646                    }
1647    
1648                    EntityCacheUtil.clearCache(UserTrackerImpl.class.getName());
1649    
1650                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
1651                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1652                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1653            }
1654    
1655            /**
1656             * Clears the cache for the user tracker.
1657             *
1658             * <p>
1659             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
1660             * </p>
1661             */
1662            @Override
1663            public void clearCache(UserTracker userTracker) {
1664                    EntityCacheUtil.removeResult(UserTrackerModelImpl.ENTITY_CACHE_ENABLED,
1665                            UserTrackerImpl.class, userTracker.getPrimaryKey());
1666    
1667                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1668                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1669            }
1670    
1671            @Override
1672            public void clearCache(List<UserTracker> userTrackers) {
1673                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1674                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1675    
1676                    for (UserTracker userTracker : userTrackers) {
1677                            EntityCacheUtil.removeResult(UserTrackerModelImpl.ENTITY_CACHE_ENABLED,
1678                                    UserTrackerImpl.class, userTracker.getPrimaryKey());
1679                    }
1680            }
1681    
1682            /**
1683             * Creates a new user tracker with the primary key. Does not add the user tracker to the database.
1684             *
1685             * @param userTrackerId the primary key for the new user tracker
1686             * @return the new user tracker
1687             */
1688            @Override
1689            public UserTracker create(long userTrackerId) {
1690                    UserTracker userTracker = new UserTrackerImpl();
1691    
1692                    userTracker.setNew(true);
1693                    userTracker.setPrimaryKey(userTrackerId);
1694    
1695                    return userTracker;
1696            }
1697    
1698            /**
1699             * Removes the user tracker with the primary key from the database. Also notifies the appropriate model listeners.
1700             *
1701             * @param userTrackerId the primary key of the user tracker
1702             * @return the user tracker that was removed
1703             * @throws com.liferay.portal.NoSuchUserTrackerException if a user tracker with the primary key could not be found
1704             * @throws SystemException if a system exception occurred
1705             */
1706            @Override
1707            public UserTracker remove(long userTrackerId)
1708                    throws NoSuchUserTrackerException, SystemException {
1709                    return remove((Serializable)userTrackerId);
1710            }
1711    
1712            /**
1713             * Removes the user tracker with the primary key from the database. Also notifies the appropriate model listeners.
1714             *
1715             * @param primaryKey the primary key of the user tracker
1716             * @return the user tracker that was removed
1717             * @throws com.liferay.portal.NoSuchUserTrackerException if a user tracker with the primary key could not be found
1718             * @throws SystemException if a system exception occurred
1719             */
1720            @Override
1721            public UserTracker remove(Serializable primaryKey)
1722                    throws NoSuchUserTrackerException, SystemException {
1723                    Session session = null;
1724    
1725                    try {
1726                            session = openSession();
1727    
1728                            UserTracker userTracker = (UserTracker)session.get(UserTrackerImpl.class,
1729                                            primaryKey);
1730    
1731                            if (userTracker == null) {
1732                                    if (_log.isWarnEnabled()) {
1733                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1734                                    }
1735    
1736                                    throw new NoSuchUserTrackerException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1737                                            primaryKey);
1738                            }
1739    
1740                            return remove(userTracker);
1741                    }
1742                    catch (NoSuchUserTrackerException nsee) {
1743                            throw nsee;
1744                    }
1745                    catch (Exception e) {
1746                            throw processException(e);
1747                    }
1748                    finally {
1749                            closeSession(session);
1750                    }
1751            }
1752    
1753            @Override
1754            protected UserTracker removeImpl(UserTracker userTracker)
1755                    throws SystemException {
1756                    userTracker = toUnwrappedModel(userTracker);
1757    
1758                    Session session = null;
1759    
1760                    try {
1761                            session = openSession();
1762    
1763                            if (!session.contains(userTracker)) {
1764                                    userTracker = (UserTracker)session.get(UserTrackerImpl.class,
1765                                                    userTracker.getPrimaryKeyObj());
1766                            }
1767    
1768                            if (userTracker != null) {
1769                                    session.delete(userTracker);
1770                            }
1771                    }
1772                    catch (Exception e) {
1773                            throw processException(e);
1774                    }
1775                    finally {
1776                            closeSession(session);
1777                    }
1778    
1779                    if (userTracker != null) {
1780                            clearCache(userTracker);
1781                    }
1782    
1783                    return userTracker;
1784            }
1785    
1786            @Override
1787            public UserTracker updateImpl(
1788                    com.liferay.portal.model.UserTracker userTracker)
1789                    throws SystemException {
1790                    userTracker = toUnwrappedModel(userTracker);
1791    
1792                    boolean isNew = userTracker.isNew();
1793    
1794                    UserTrackerModelImpl userTrackerModelImpl = (UserTrackerModelImpl)userTracker;
1795    
1796                    Session session = null;
1797    
1798                    try {
1799                            session = openSession();
1800    
1801                            if (userTracker.isNew()) {
1802                                    session.save(userTracker);
1803    
1804                                    userTracker.setNew(false);
1805                            }
1806                            else {
1807                                    session.merge(userTracker);
1808                            }
1809                    }
1810                    catch (Exception e) {
1811                            throw processException(e);
1812                    }
1813                    finally {
1814                            closeSession(session);
1815                    }
1816    
1817                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1818    
1819                    if (isNew || !UserTrackerModelImpl.COLUMN_BITMASK_ENABLED) {
1820                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1821                    }
1822    
1823                    else {
1824                            if ((userTrackerModelImpl.getColumnBitmask() &
1825                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
1826                                    Object[] args = new Object[] {
1827                                                    userTrackerModelImpl.getOriginalCompanyId()
1828                                            };
1829    
1830                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
1831                                            args);
1832                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
1833                                            args);
1834    
1835                                    args = new Object[] { userTrackerModelImpl.getCompanyId() };
1836    
1837                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
1838                                            args);
1839                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
1840                                            args);
1841                            }
1842    
1843                            if ((userTrackerModelImpl.getColumnBitmask() &
1844                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
1845                                    Object[] args = new Object[] {
1846                                                    userTrackerModelImpl.getOriginalUserId()
1847                                            };
1848    
1849                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
1850                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
1851                                            args);
1852    
1853                                    args = new Object[] { userTrackerModelImpl.getUserId() };
1854    
1855                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
1856                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
1857                                            args);
1858                            }
1859    
1860                            if ((userTrackerModelImpl.getColumnBitmask() &
1861                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SESSIONID.getColumnBitmask()) != 0) {
1862                                    Object[] args = new Object[] {
1863                                                    userTrackerModelImpl.getOriginalSessionId()
1864                                            };
1865    
1866                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_SESSIONID,
1867                                            args);
1868                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SESSIONID,
1869                                            args);
1870    
1871                                    args = new Object[] { userTrackerModelImpl.getSessionId() };
1872    
1873                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_SESSIONID,
1874                                            args);
1875                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SESSIONID,
1876                                            args);
1877                            }
1878                    }
1879    
1880                    EntityCacheUtil.putResult(UserTrackerModelImpl.ENTITY_CACHE_ENABLED,
1881                            UserTrackerImpl.class, userTracker.getPrimaryKey(), userTracker);
1882    
1883                    return userTracker;
1884            }
1885    
1886            protected UserTracker toUnwrappedModel(UserTracker userTracker) {
1887                    if (userTracker instanceof UserTrackerImpl) {
1888                            return userTracker;
1889                    }
1890    
1891                    UserTrackerImpl userTrackerImpl = new UserTrackerImpl();
1892    
1893                    userTrackerImpl.setNew(userTracker.isNew());
1894                    userTrackerImpl.setPrimaryKey(userTracker.getPrimaryKey());
1895    
1896                    userTrackerImpl.setUserTrackerId(userTracker.getUserTrackerId());
1897                    userTrackerImpl.setCompanyId(userTracker.getCompanyId());
1898                    userTrackerImpl.setUserId(userTracker.getUserId());
1899                    userTrackerImpl.setModifiedDate(userTracker.getModifiedDate());
1900                    userTrackerImpl.setSessionId(userTracker.getSessionId());
1901                    userTrackerImpl.setRemoteAddr(userTracker.getRemoteAddr());
1902                    userTrackerImpl.setRemoteHost(userTracker.getRemoteHost());
1903                    userTrackerImpl.setUserAgent(userTracker.getUserAgent());
1904    
1905                    return userTrackerImpl;
1906            }
1907    
1908            /**
1909             * Returns the user tracker with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
1910             *
1911             * @param primaryKey the primary key of the user tracker
1912             * @return the user tracker
1913             * @throws com.liferay.portal.NoSuchUserTrackerException if a user tracker with the primary key could not be found
1914             * @throws SystemException if a system exception occurred
1915             */
1916            @Override
1917            public UserTracker findByPrimaryKey(Serializable primaryKey)
1918                    throws NoSuchUserTrackerException, SystemException {
1919                    UserTracker userTracker = fetchByPrimaryKey(primaryKey);
1920    
1921                    if (userTracker == null) {
1922                            if (_log.isWarnEnabled()) {
1923                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1924                            }
1925    
1926                            throw new NoSuchUserTrackerException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1927                                    primaryKey);
1928                    }
1929    
1930                    return userTracker;
1931            }
1932    
1933            /**
1934             * Returns the user tracker with the primary key or throws a {@link com.liferay.portal.NoSuchUserTrackerException} if it could not be found.
1935             *
1936             * @param userTrackerId the primary key of the user tracker
1937             * @return the user tracker
1938             * @throws com.liferay.portal.NoSuchUserTrackerException if a user tracker with the primary key could not be found
1939             * @throws SystemException if a system exception occurred
1940             */
1941            @Override
1942            public UserTracker findByPrimaryKey(long userTrackerId)
1943                    throws NoSuchUserTrackerException, SystemException {
1944                    return findByPrimaryKey((Serializable)userTrackerId);
1945            }
1946    
1947            /**
1948             * Returns the user tracker with the primary key or returns <code>null</code> if it could not be found.
1949             *
1950             * @param primaryKey the primary key of the user tracker
1951             * @return the user tracker, or <code>null</code> if a user tracker with the primary key could not be found
1952             * @throws SystemException if a system exception occurred
1953             */
1954            @Override
1955            public UserTracker fetchByPrimaryKey(Serializable primaryKey)
1956                    throws SystemException {
1957                    UserTracker userTracker = (UserTracker)EntityCacheUtil.getResult(UserTrackerModelImpl.ENTITY_CACHE_ENABLED,
1958                                    UserTrackerImpl.class, primaryKey);
1959    
1960                    if (userTracker == _nullUserTracker) {
1961                            return null;
1962                    }
1963    
1964                    if (userTracker == null) {
1965                            Session session = null;
1966    
1967                            try {
1968                                    session = openSession();
1969    
1970                                    userTracker = (UserTracker)session.get(UserTrackerImpl.class,
1971                                                    primaryKey);
1972    
1973                                    if (userTracker != null) {
1974                                            cacheResult(userTracker);
1975                                    }
1976                                    else {
1977                                            EntityCacheUtil.putResult(UserTrackerModelImpl.ENTITY_CACHE_ENABLED,
1978                                                    UserTrackerImpl.class, primaryKey, _nullUserTracker);
1979                                    }
1980                            }
1981                            catch (Exception e) {
1982                                    EntityCacheUtil.removeResult(UserTrackerModelImpl.ENTITY_CACHE_ENABLED,
1983                                            UserTrackerImpl.class, primaryKey);
1984    
1985                                    throw processException(e);
1986                            }
1987                            finally {
1988                                    closeSession(session);
1989                            }
1990                    }
1991    
1992                    return userTracker;
1993            }
1994    
1995            /**
1996             * Returns the user tracker with the primary key or returns <code>null</code> if it could not be found.
1997             *
1998             * @param userTrackerId the primary key of the user tracker
1999             * @return the user tracker, or <code>null</code> if a user tracker with the primary key could not be found
2000             * @throws SystemException if a system exception occurred
2001             */
2002            @Override
2003            public UserTracker fetchByPrimaryKey(long userTrackerId)
2004                    throws SystemException {
2005                    return fetchByPrimaryKey((Serializable)userTrackerId);
2006            }
2007    
2008            /**
2009             * Returns all the user trackers.
2010             *
2011             * @return the user trackers
2012             * @throws SystemException if a system exception occurred
2013             */
2014            @Override
2015            public List<UserTracker> findAll() throws SystemException {
2016                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2017            }
2018    
2019            /**
2020             * Returns a range of all the user trackers.
2021             *
2022             * <p>
2023             * 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.
2024             * </p>
2025             *
2026             * @param start the lower bound of the range of user trackers
2027             * @param end the upper bound of the range of user trackers (not inclusive)
2028             * @return the range of user trackers
2029             * @throws SystemException if a system exception occurred
2030             */
2031            @Override
2032            public List<UserTracker> findAll(int start, int end)
2033                    throws SystemException {
2034                    return findAll(start, end, null);
2035            }
2036    
2037            /**
2038             * Returns an ordered range of all the user trackers.
2039             *
2040             * <p>
2041             * 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.
2042             * </p>
2043             *
2044             * @param start the lower bound of the range of user trackers
2045             * @param end the upper bound of the range of user trackers (not inclusive)
2046             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2047             * @return the ordered range of user trackers
2048             * @throws SystemException if a system exception occurred
2049             */
2050            @Override
2051            public List<UserTracker> findAll(int start, int end,
2052                    OrderByComparator orderByComparator) throws SystemException {
2053                    boolean pagination = true;
2054                    FinderPath finderPath = null;
2055                    Object[] finderArgs = null;
2056    
2057                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2058                                    (orderByComparator == null)) {
2059                            pagination = false;
2060                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2061                            finderArgs = FINDER_ARGS_EMPTY;
2062                    }
2063                    else {
2064                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2065                            finderArgs = new Object[] { start, end, orderByComparator };
2066                    }
2067    
2068                    List<UserTracker> list = (List<UserTracker>)FinderCacheUtil.getResult(finderPath,
2069                                    finderArgs, this);
2070    
2071                    if (list == null) {
2072                            StringBundler query = null;
2073                            String sql = null;
2074    
2075                            if (orderByComparator != null) {
2076                                    query = new StringBundler(2 +
2077                                                    (orderByComparator.getOrderByFields().length * 3));
2078    
2079                                    query.append(_SQL_SELECT_USERTRACKER);
2080    
2081                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2082                                            orderByComparator);
2083    
2084                                    sql = query.toString();
2085                            }
2086                            else {
2087                                    sql = _SQL_SELECT_USERTRACKER;
2088    
2089                                    if (pagination) {
2090                                            sql = sql.concat(UserTrackerModelImpl.ORDER_BY_JPQL);
2091                                    }
2092                            }
2093    
2094                            Session session = null;
2095    
2096                            try {
2097                                    session = openSession();
2098    
2099                                    Query q = session.createQuery(sql);
2100    
2101                                    if (!pagination) {
2102                                            list = (List<UserTracker>)QueryUtil.list(q, getDialect(),
2103                                                            start, end, false);
2104    
2105                                            Collections.sort(list);
2106    
2107                                            list = new UnmodifiableList<UserTracker>(list);
2108                                    }
2109                                    else {
2110                                            list = (List<UserTracker>)QueryUtil.list(q, getDialect(),
2111                                                            start, end);
2112                                    }
2113    
2114                                    cacheResult(list);
2115    
2116                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2117                            }
2118                            catch (Exception e) {
2119                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2120    
2121                                    throw processException(e);
2122                            }
2123                            finally {
2124                                    closeSession(session);
2125                            }
2126                    }
2127    
2128                    return list;
2129            }
2130    
2131            /**
2132             * Removes all the user trackers from the database.
2133             *
2134             * @throws SystemException if a system exception occurred
2135             */
2136            @Override
2137            public void removeAll() throws SystemException {
2138                    for (UserTracker userTracker : findAll()) {
2139                            remove(userTracker);
2140                    }
2141            }
2142    
2143            /**
2144             * Returns the number of user trackers.
2145             *
2146             * @return the number of user trackers
2147             * @throws SystemException if a system exception occurred
2148             */
2149            @Override
2150            public int countAll() throws SystemException {
2151                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2152                                    FINDER_ARGS_EMPTY, this);
2153    
2154                    if (count == null) {
2155                            Session session = null;
2156    
2157                            try {
2158                                    session = openSession();
2159    
2160                                    Query q = session.createQuery(_SQL_COUNT_USERTRACKER);
2161    
2162                                    count = (Long)q.uniqueResult();
2163    
2164                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2165                                            FINDER_ARGS_EMPTY, count);
2166                            }
2167                            catch (Exception e) {
2168                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
2169                                            FINDER_ARGS_EMPTY);
2170    
2171                                    throw processException(e);
2172                            }
2173                            finally {
2174                                    closeSession(session);
2175                            }
2176                    }
2177    
2178                    return count.intValue();
2179            }
2180    
2181            /**
2182             * Initializes the user tracker persistence.
2183             */
2184            public void afterPropertiesSet() {
2185                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2186                                            com.liferay.portal.util.PropsUtil.get(
2187                                                    "value.object.listener.com.liferay.portal.model.UserTracker")));
2188    
2189                    if (listenerClassNames.length > 0) {
2190                            try {
2191                                    List<ModelListener<UserTracker>> listenersList = new ArrayList<ModelListener<UserTracker>>();
2192    
2193                                    for (String listenerClassName : listenerClassNames) {
2194                                            listenersList.add((ModelListener<UserTracker>)InstanceFactory.newInstance(
2195                                                            getClassLoader(), listenerClassName));
2196                                    }
2197    
2198                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2199                            }
2200                            catch (Exception e) {
2201                                    _log.error(e);
2202                            }
2203                    }
2204            }
2205    
2206            public void destroy() {
2207                    EntityCacheUtil.removeCache(UserTrackerImpl.class.getName());
2208                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2209                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2210                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2211            }
2212    
2213            private static final String _SQL_SELECT_USERTRACKER = "SELECT userTracker FROM UserTracker userTracker";
2214            private static final String _SQL_SELECT_USERTRACKER_WHERE = "SELECT userTracker FROM UserTracker userTracker WHERE ";
2215            private static final String _SQL_COUNT_USERTRACKER = "SELECT COUNT(userTracker) FROM UserTracker userTracker";
2216            private static final String _SQL_COUNT_USERTRACKER_WHERE = "SELECT COUNT(userTracker) FROM UserTracker userTracker WHERE ";
2217            private static final String _ORDER_BY_ENTITY_ALIAS = "userTracker.";
2218            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No UserTracker exists with the primary key ";
2219            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No UserTracker exists with the key {";
2220            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2221            private static Log _log = LogFactoryUtil.getLog(UserTrackerPersistenceImpl.class);
2222            private static UserTracker _nullUserTracker = new UserTrackerImpl() {
2223                            @Override
2224                            public Object clone() {
2225                                    return this;
2226                            }
2227    
2228                            @Override
2229                            public CacheModel<UserTracker> toCacheModel() {
2230                                    return _nullUserTrackerCacheModel;
2231                            }
2232                    };
2233    
2234            private static CacheModel<UserTracker> _nullUserTrackerCacheModel = new CacheModel<UserTracker>() {
2235                            @Override
2236                            public UserTracker toEntityModel() {
2237                                    return _nullUserTracker;
2238                            }
2239                    };
2240    }