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