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