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