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