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