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