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