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