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