001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.service.persistence;
016    
017    import com.liferay.portal.NoSuchBrowserTrackerException;
018    import com.liferay.portal.NoSuchModelException;
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.model.BrowserTracker;
038    import com.liferay.portal.model.CacheModel;
039    import com.liferay.portal.model.ModelListener;
040    import com.liferay.portal.model.impl.BrowserTrackerImpl;
041    import com.liferay.portal.model.impl.BrowserTrackerModelImpl;
042    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
043    
044    import java.io.Serializable;
045    
046    import java.util.ArrayList;
047    import java.util.Collections;
048    import java.util.List;
049    
050    /**
051     * The persistence implementation for the browser tracker service.
052     *
053     * <p>
054     * Caching information and settings can be found in <code>portal.properties</code>
055     * </p>
056     *
057     * @author Brian Wing Shun Chan
058     * @see BrowserTrackerPersistence
059     * @see BrowserTrackerUtil
060     * @generated
061     */
062    public class BrowserTrackerPersistenceImpl extends BasePersistenceImpl<BrowserTracker>
063            implements BrowserTrackerPersistence {
064            /*
065             * NOTE FOR DEVELOPERS:
066             *
067             * Never modify or reference this class directly. Always use {@link BrowserTrackerUtil} to access the browser tracker persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
068             */
069            public static final String FINDER_CLASS_NAME_ENTITY = BrowserTrackerImpl.class.getName();
070            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
071                    ".List1";
072            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
073                    ".List2";
074            public static final FinderPath FINDER_PATH_FETCH_BY_USERID = new FinderPath(BrowserTrackerModelImpl.ENTITY_CACHE_ENABLED,
075                            BrowserTrackerModelImpl.FINDER_CACHE_ENABLED,
076                            BrowserTrackerImpl.class, FINDER_CLASS_NAME_ENTITY,
077                            "fetchByUserId", new String[] { Long.class.getName() },
078                            BrowserTrackerModelImpl.USERID_COLUMN_BITMASK);
079            public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(BrowserTrackerModelImpl.ENTITY_CACHE_ENABLED,
080                            BrowserTrackerModelImpl.FINDER_CACHE_ENABLED, Long.class,
081                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId",
082                            new String[] { Long.class.getName() });
083            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(BrowserTrackerModelImpl.ENTITY_CACHE_ENABLED,
084                            BrowserTrackerModelImpl.FINDER_CACHE_ENABLED,
085                            BrowserTrackerImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
086                            "findAll", new String[0]);
087            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(BrowserTrackerModelImpl.ENTITY_CACHE_ENABLED,
088                            BrowserTrackerModelImpl.FINDER_CACHE_ENABLED,
089                            BrowserTrackerImpl.class,
090                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
091            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(BrowserTrackerModelImpl.ENTITY_CACHE_ENABLED,
092                            BrowserTrackerModelImpl.FINDER_CACHE_ENABLED, Long.class,
093                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
094    
095            /**
096             * Caches the browser tracker in the entity cache if it is enabled.
097             *
098             * @param browserTracker the browser tracker
099             */
100            public void cacheResult(BrowserTracker browserTracker) {
101                    EntityCacheUtil.putResult(BrowserTrackerModelImpl.ENTITY_CACHE_ENABLED,
102                            BrowserTrackerImpl.class, browserTracker.getPrimaryKey(),
103                            browserTracker);
104    
105                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_USERID,
106                            new Object[] { Long.valueOf(browserTracker.getUserId()) },
107                            browserTracker);
108    
109                    browserTracker.resetOriginalValues();
110            }
111    
112            /**
113             * Caches the browser trackers in the entity cache if it is enabled.
114             *
115             * @param browserTrackers the browser trackers
116             */
117            public void cacheResult(List<BrowserTracker> browserTrackers) {
118                    for (BrowserTracker browserTracker : browserTrackers) {
119                            if (EntityCacheUtil.getResult(
120                                                    BrowserTrackerModelImpl.ENTITY_CACHE_ENABLED,
121                                                    BrowserTrackerImpl.class, browserTracker.getPrimaryKey()) == null) {
122                                    cacheResult(browserTracker);
123                            }
124                            else {
125                                    browserTracker.resetOriginalValues();
126                            }
127                    }
128            }
129    
130            /**
131             * Clears the cache for all browser trackers.
132             *
133             * <p>
134             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
135             * </p>
136             */
137            @Override
138            public void clearCache() {
139                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
140                            CacheRegistryUtil.clear(BrowserTrackerImpl.class.getName());
141                    }
142    
143                    EntityCacheUtil.clearCache(BrowserTrackerImpl.class.getName());
144    
145                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
146                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
147                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
148            }
149    
150            /**
151             * Clears the cache for the browser tracker.
152             *
153             * <p>
154             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
155             * </p>
156             */
157            @Override
158            public void clearCache(BrowserTracker browserTracker) {
159                    EntityCacheUtil.removeResult(BrowserTrackerModelImpl.ENTITY_CACHE_ENABLED,
160                            BrowserTrackerImpl.class, browserTracker.getPrimaryKey());
161    
162                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
163                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
164    
165                    clearUniqueFindersCache(browserTracker);
166            }
167    
168            @Override
169            public void clearCache(List<BrowserTracker> browserTrackers) {
170                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
171                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
172    
173                    for (BrowserTracker browserTracker : browserTrackers) {
174                            EntityCacheUtil.removeResult(BrowserTrackerModelImpl.ENTITY_CACHE_ENABLED,
175                                    BrowserTrackerImpl.class, browserTracker.getPrimaryKey());
176    
177                            clearUniqueFindersCache(browserTracker);
178                    }
179            }
180    
181            protected void clearUniqueFindersCache(BrowserTracker browserTracker) {
182                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_USERID,
183                            new Object[] { Long.valueOf(browserTracker.getUserId()) });
184            }
185    
186            /**
187             * Creates a new browser tracker with the primary key. Does not add the browser tracker to the database.
188             *
189             * @param browserTrackerId the primary key for the new browser tracker
190             * @return the new browser tracker
191             */
192            public BrowserTracker create(long browserTrackerId) {
193                    BrowserTracker browserTracker = new BrowserTrackerImpl();
194    
195                    browserTracker.setNew(true);
196                    browserTracker.setPrimaryKey(browserTrackerId);
197    
198                    return browserTracker;
199            }
200    
201            /**
202             * Removes the browser tracker with the primary key from the database. Also notifies the appropriate model listeners.
203             *
204             * @param browserTrackerId the primary key of the browser tracker
205             * @return the browser tracker that was removed
206             * @throws com.liferay.portal.NoSuchBrowserTrackerException if a browser tracker with the primary key could not be found
207             * @throws SystemException if a system exception occurred
208             */
209            public BrowserTracker remove(long browserTrackerId)
210                    throws NoSuchBrowserTrackerException, SystemException {
211                    return remove(Long.valueOf(browserTrackerId));
212            }
213    
214            /**
215             * Removes the browser tracker with the primary key from the database. Also notifies the appropriate model listeners.
216             *
217             * @param primaryKey the primary key of the browser tracker
218             * @return the browser tracker that was removed
219             * @throws com.liferay.portal.NoSuchBrowserTrackerException if a browser tracker with the primary key could not be found
220             * @throws SystemException if a system exception occurred
221             */
222            @Override
223            public BrowserTracker remove(Serializable primaryKey)
224                    throws NoSuchBrowserTrackerException, SystemException {
225                    Session session = null;
226    
227                    try {
228                            session = openSession();
229    
230                            BrowserTracker browserTracker = (BrowserTracker)session.get(BrowserTrackerImpl.class,
231                                            primaryKey);
232    
233                            if (browserTracker == null) {
234                                    if (_log.isWarnEnabled()) {
235                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
236                                    }
237    
238                                    throw new NoSuchBrowserTrackerException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
239                                            primaryKey);
240                            }
241    
242                            return remove(browserTracker);
243                    }
244                    catch (NoSuchBrowserTrackerException nsee) {
245                            throw nsee;
246                    }
247                    catch (Exception e) {
248                            throw processException(e);
249                    }
250                    finally {
251                            closeSession(session);
252                    }
253            }
254    
255            @Override
256            protected BrowserTracker removeImpl(BrowserTracker browserTracker)
257                    throws SystemException {
258                    browserTracker = toUnwrappedModel(browserTracker);
259    
260                    Session session = null;
261    
262                    try {
263                            session = openSession();
264    
265                            BatchSessionUtil.delete(session, browserTracker);
266                    }
267                    catch (Exception e) {
268                            throw processException(e);
269                    }
270                    finally {
271                            closeSession(session);
272                    }
273    
274                    clearCache(browserTracker);
275    
276                    return browserTracker;
277            }
278    
279            @Override
280            public BrowserTracker updateImpl(
281                    com.liferay.portal.model.BrowserTracker browserTracker, boolean merge)
282                    throws SystemException {
283                    browserTracker = toUnwrappedModel(browserTracker);
284    
285                    boolean isNew = browserTracker.isNew();
286    
287                    BrowserTrackerModelImpl browserTrackerModelImpl = (BrowserTrackerModelImpl)browserTracker;
288    
289                    Session session = null;
290    
291                    try {
292                            session = openSession();
293    
294                            BatchSessionUtil.update(session, browserTracker, merge);
295    
296                            browserTracker.setNew(false);
297                    }
298                    catch (Exception e) {
299                            throw processException(e);
300                    }
301                    finally {
302                            closeSession(session);
303                    }
304    
305                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
306    
307                    if (isNew || !BrowserTrackerModelImpl.COLUMN_BITMASK_ENABLED) {
308                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
309                    }
310    
311                    EntityCacheUtil.putResult(BrowserTrackerModelImpl.ENTITY_CACHE_ENABLED,
312                            BrowserTrackerImpl.class, browserTracker.getPrimaryKey(),
313                            browserTracker);
314    
315                    if (isNew) {
316                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_USERID,
317                                    new Object[] { Long.valueOf(browserTracker.getUserId()) },
318                                    browserTracker);
319                    }
320                    else {
321                            if ((browserTrackerModelImpl.getColumnBitmask() &
322                                            FINDER_PATH_FETCH_BY_USERID.getColumnBitmask()) != 0) {
323                                    Object[] args = new Object[] {
324                                                    Long.valueOf(browserTrackerModelImpl.getOriginalUserId())
325                                            };
326    
327                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
328    
329                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_USERID, args);
330    
331                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_USERID,
332                                            new Object[] { Long.valueOf(browserTracker.getUserId()) },
333                                            browserTracker);
334                            }
335                    }
336    
337                    return browserTracker;
338            }
339    
340            protected BrowserTracker toUnwrappedModel(BrowserTracker browserTracker) {
341                    if (browserTracker instanceof BrowserTrackerImpl) {
342                            return browserTracker;
343                    }
344    
345                    BrowserTrackerImpl browserTrackerImpl = new BrowserTrackerImpl();
346    
347                    browserTrackerImpl.setNew(browserTracker.isNew());
348                    browserTrackerImpl.setPrimaryKey(browserTracker.getPrimaryKey());
349    
350                    browserTrackerImpl.setBrowserTrackerId(browserTracker.getBrowserTrackerId());
351                    browserTrackerImpl.setUserId(browserTracker.getUserId());
352                    browserTrackerImpl.setBrowserKey(browserTracker.getBrowserKey());
353    
354                    return browserTrackerImpl;
355            }
356    
357            /**
358             * Returns the browser tracker with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
359             *
360             * @param primaryKey the primary key of the browser tracker
361             * @return the browser tracker
362             * @throws com.liferay.portal.NoSuchModelException if a browser tracker with the primary key could not be found
363             * @throws SystemException if a system exception occurred
364             */
365            @Override
366            public BrowserTracker findByPrimaryKey(Serializable primaryKey)
367                    throws NoSuchModelException, SystemException {
368                    return findByPrimaryKey(((Long)primaryKey).longValue());
369            }
370    
371            /**
372             * Returns the browser tracker with the primary key or throws a {@link com.liferay.portal.NoSuchBrowserTrackerException} if it could not be found.
373             *
374             * @param browserTrackerId the primary key of the browser tracker
375             * @return the browser tracker
376             * @throws com.liferay.portal.NoSuchBrowserTrackerException if a browser tracker with the primary key could not be found
377             * @throws SystemException if a system exception occurred
378             */
379            public BrowserTracker findByPrimaryKey(long browserTrackerId)
380                    throws NoSuchBrowserTrackerException, SystemException {
381                    BrowserTracker browserTracker = fetchByPrimaryKey(browserTrackerId);
382    
383                    if (browserTracker == null) {
384                            if (_log.isWarnEnabled()) {
385                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + browserTrackerId);
386                            }
387    
388                            throw new NoSuchBrowserTrackerException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
389                                    browserTrackerId);
390                    }
391    
392                    return browserTracker;
393            }
394    
395            /**
396             * Returns the browser tracker with the primary key or returns <code>null</code> if it could not be found.
397             *
398             * @param primaryKey the primary key of the browser tracker
399             * @return the browser tracker, or <code>null</code> if a browser tracker with the primary key could not be found
400             * @throws SystemException if a system exception occurred
401             */
402            @Override
403            public BrowserTracker fetchByPrimaryKey(Serializable primaryKey)
404                    throws SystemException {
405                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
406            }
407    
408            /**
409             * Returns the browser tracker with the primary key or returns <code>null</code> if it could not be found.
410             *
411             * @param browserTrackerId the primary key of the browser tracker
412             * @return the browser tracker, or <code>null</code> if a browser tracker with the primary key could not be found
413             * @throws SystemException if a system exception occurred
414             */
415            public BrowserTracker fetchByPrimaryKey(long browserTrackerId)
416                    throws SystemException {
417                    BrowserTracker browserTracker = (BrowserTracker)EntityCacheUtil.getResult(BrowserTrackerModelImpl.ENTITY_CACHE_ENABLED,
418                                    BrowserTrackerImpl.class, browserTrackerId);
419    
420                    if (browserTracker == _nullBrowserTracker) {
421                            return null;
422                    }
423    
424                    if (browserTracker == null) {
425                            Session session = null;
426    
427                            boolean hasException = false;
428    
429                            try {
430                                    session = openSession();
431    
432                                    browserTracker = (BrowserTracker)session.get(BrowserTrackerImpl.class,
433                                                    Long.valueOf(browserTrackerId));
434                            }
435                            catch (Exception e) {
436                                    hasException = true;
437    
438                                    throw processException(e);
439                            }
440                            finally {
441                                    if (browserTracker != null) {
442                                            cacheResult(browserTracker);
443                                    }
444                                    else if (!hasException) {
445                                            EntityCacheUtil.putResult(BrowserTrackerModelImpl.ENTITY_CACHE_ENABLED,
446                                                    BrowserTrackerImpl.class, browserTrackerId,
447                                                    _nullBrowserTracker);
448                                    }
449    
450                                    closeSession(session);
451                            }
452                    }
453    
454                    return browserTracker;
455            }
456    
457            /**
458             * Returns the browser tracker where userId = &#63; or throws a {@link com.liferay.portal.NoSuchBrowserTrackerException} if it could not be found.
459             *
460             * @param userId the user ID
461             * @return the matching browser tracker
462             * @throws com.liferay.portal.NoSuchBrowserTrackerException if a matching browser tracker could not be found
463             * @throws SystemException if a system exception occurred
464             */
465            public BrowserTracker findByUserId(long userId)
466                    throws NoSuchBrowserTrackerException, SystemException {
467                    BrowserTracker browserTracker = fetchByUserId(userId);
468    
469                    if (browserTracker == null) {
470                            StringBundler msg = new StringBundler(4);
471    
472                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
473    
474                            msg.append("userId=");
475                            msg.append(userId);
476    
477                            msg.append(StringPool.CLOSE_CURLY_BRACE);
478    
479                            if (_log.isWarnEnabled()) {
480                                    _log.warn(msg.toString());
481                            }
482    
483                            throw new NoSuchBrowserTrackerException(msg.toString());
484                    }
485    
486                    return browserTracker;
487            }
488    
489            /**
490             * Returns the browser tracker where userId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
491             *
492             * @param userId the user ID
493             * @return the matching browser tracker, or <code>null</code> if a matching browser tracker could not be found
494             * @throws SystemException if a system exception occurred
495             */
496            public BrowserTracker fetchByUserId(long userId) throws SystemException {
497                    return fetchByUserId(userId, true);
498            }
499    
500            /**
501             * Returns the browser tracker where userId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
502             *
503             * @param userId the user ID
504             * @param retrieveFromCache whether to use the finder cache
505             * @return the matching browser tracker, or <code>null</code> if a matching browser tracker could not be found
506             * @throws SystemException if a system exception occurred
507             */
508            public BrowserTracker fetchByUserId(long userId, boolean retrieveFromCache)
509                    throws SystemException {
510                    Object[] finderArgs = new Object[] { userId };
511    
512                    Object result = null;
513    
514                    if (retrieveFromCache) {
515                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_USERID,
516                                            finderArgs, this);
517                    }
518    
519                    if (result instanceof BrowserTracker) {
520                            BrowserTracker browserTracker = (BrowserTracker)result;
521    
522                            if ((userId != browserTracker.getUserId())) {
523                                    result = null;
524                            }
525                    }
526    
527                    if (result == null) {
528                            StringBundler query = new StringBundler(2);
529    
530                            query.append(_SQL_SELECT_BROWSERTRACKER_WHERE);
531    
532                            query.append(_FINDER_COLUMN_USERID_USERID_2);
533    
534                            String sql = query.toString();
535    
536                            Session session = null;
537    
538                            try {
539                                    session = openSession();
540    
541                                    Query q = session.createQuery(sql);
542    
543                                    QueryPos qPos = QueryPos.getInstance(q);
544    
545                                    qPos.add(userId);
546    
547                                    List<BrowserTracker> list = q.list();
548    
549                                    result = list;
550    
551                                    BrowserTracker browserTracker = null;
552    
553                                    if (list.isEmpty()) {
554                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_USERID,
555                                                    finderArgs, list);
556                                    }
557                                    else {
558                                            browserTracker = list.get(0);
559    
560                                            cacheResult(browserTracker);
561    
562                                            if ((browserTracker.getUserId() != userId)) {
563                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_USERID,
564                                                            finderArgs, browserTracker);
565                                            }
566                                    }
567    
568                                    return browserTracker;
569                            }
570                            catch (Exception e) {
571                                    throw processException(e);
572                            }
573                            finally {
574                                    if (result == null) {
575                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_USERID,
576                                                    finderArgs);
577                                    }
578    
579                                    closeSession(session);
580                            }
581                    }
582                    else {
583                            if (result instanceof List<?>) {
584                                    return null;
585                            }
586                            else {
587                                    return (BrowserTracker)result;
588                            }
589                    }
590            }
591    
592            /**
593             * Returns all the browser trackers.
594             *
595             * @return the browser trackers
596             * @throws SystemException if a system exception occurred
597             */
598            public List<BrowserTracker> findAll() throws SystemException {
599                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
600            }
601    
602            /**
603             * Returns a range of all the browser trackers.
604             *
605             * <p>
606             * 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.
607             * </p>
608             *
609             * @param start the lower bound of the range of browser trackers
610             * @param end the upper bound of the range of browser trackers (not inclusive)
611             * @return the range of browser trackers
612             * @throws SystemException if a system exception occurred
613             */
614            public List<BrowserTracker> findAll(int start, int end)
615                    throws SystemException {
616                    return findAll(start, end, null);
617            }
618    
619            /**
620             * Returns an ordered range of all the browser trackers.
621             *
622             * <p>
623             * 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.
624             * </p>
625             *
626             * @param start the lower bound of the range of browser trackers
627             * @param end the upper bound of the range of browser trackers (not inclusive)
628             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
629             * @return the ordered range of browser trackers
630             * @throws SystemException if a system exception occurred
631             */
632            public List<BrowserTracker> findAll(int start, int end,
633                    OrderByComparator orderByComparator) throws SystemException {
634                    FinderPath finderPath = null;
635                    Object[] finderArgs = new Object[] { start, end, orderByComparator };
636    
637                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
638                                    (orderByComparator == null)) {
639                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
640                            finderArgs = FINDER_ARGS_EMPTY;
641                    }
642                    else {
643                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
644                            finderArgs = new Object[] { start, end, orderByComparator };
645                    }
646    
647                    List<BrowserTracker> list = (List<BrowserTracker>)FinderCacheUtil.getResult(finderPath,
648                                    finderArgs, this);
649    
650                    if (list == null) {
651                            StringBundler query = null;
652                            String sql = null;
653    
654                            if (orderByComparator != null) {
655                                    query = new StringBundler(2 +
656                                                    (orderByComparator.getOrderByFields().length * 3));
657    
658                                    query.append(_SQL_SELECT_BROWSERTRACKER);
659    
660                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
661                                            orderByComparator);
662    
663                                    sql = query.toString();
664                            }
665                            else {
666                                    sql = _SQL_SELECT_BROWSERTRACKER;
667                            }
668    
669                            Session session = null;
670    
671                            try {
672                                    session = openSession();
673    
674                                    Query q = session.createQuery(sql);
675    
676                                    if (orderByComparator == null) {
677                                            list = (List<BrowserTracker>)QueryUtil.list(q,
678                                                            getDialect(), start, end, false);
679    
680                                            Collections.sort(list);
681                                    }
682                                    else {
683                                            list = (List<BrowserTracker>)QueryUtil.list(q,
684                                                            getDialect(), start, end);
685                                    }
686                            }
687                            catch (Exception e) {
688                                    throw processException(e);
689                            }
690                            finally {
691                                    if (list == null) {
692                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
693                                    }
694                                    else {
695                                            cacheResult(list);
696    
697                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
698                                    }
699    
700                                    closeSession(session);
701                            }
702                    }
703    
704                    return list;
705            }
706    
707            /**
708             * Removes the browser tracker where userId = &#63; from the database.
709             *
710             * @param userId the user ID
711             * @return the browser tracker that was removed
712             * @throws SystemException if a system exception occurred
713             */
714            public BrowserTracker removeByUserId(long userId)
715                    throws NoSuchBrowserTrackerException, SystemException {
716                    BrowserTracker browserTracker = findByUserId(userId);
717    
718                    return remove(browserTracker);
719            }
720    
721            /**
722             * Removes all the browser trackers from the database.
723             *
724             * @throws SystemException if a system exception occurred
725             */
726            public void removeAll() throws SystemException {
727                    for (BrowserTracker browserTracker : findAll()) {
728                            remove(browserTracker);
729                    }
730            }
731    
732            /**
733             * Returns the number of browser trackers where userId = &#63;.
734             *
735             * @param userId the user ID
736             * @return the number of matching browser trackers
737             * @throws SystemException if a system exception occurred
738             */
739            public int countByUserId(long userId) throws SystemException {
740                    Object[] finderArgs = new Object[] { userId };
741    
742                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID,
743                                    finderArgs, this);
744    
745                    if (count == null) {
746                            StringBundler query = new StringBundler(2);
747    
748                            query.append(_SQL_COUNT_BROWSERTRACKER_WHERE);
749    
750                            query.append(_FINDER_COLUMN_USERID_USERID_2);
751    
752                            String sql = query.toString();
753    
754                            Session session = null;
755    
756                            try {
757                                    session = openSession();
758    
759                                    Query q = session.createQuery(sql);
760    
761                                    QueryPos qPos = QueryPos.getInstance(q);
762    
763                                    qPos.add(userId);
764    
765                                    count = (Long)q.uniqueResult();
766                            }
767                            catch (Exception e) {
768                                    throw processException(e);
769                            }
770                            finally {
771                                    if (count == null) {
772                                            count = Long.valueOf(0);
773                                    }
774    
775                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID,
776                                            finderArgs, count);
777    
778                                    closeSession(session);
779                            }
780                    }
781    
782                    return count.intValue();
783            }
784    
785            /**
786             * Returns the number of browser trackers.
787             *
788             * @return the number of browser trackers
789             * @throws SystemException if a system exception occurred
790             */
791            public int countAll() throws SystemException {
792                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
793                                    FINDER_ARGS_EMPTY, this);
794    
795                    if (count == null) {
796                            Session session = null;
797    
798                            try {
799                                    session = openSession();
800    
801                                    Query q = session.createQuery(_SQL_COUNT_BROWSERTRACKER);
802    
803                                    count = (Long)q.uniqueResult();
804                            }
805                            catch (Exception e) {
806                                    throw processException(e);
807                            }
808                            finally {
809                                    if (count == null) {
810                                            count = Long.valueOf(0);
811                                    }
812    
813                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
814                                            FINDER_ARGS_EMPTY, count);
815    
816                                    closeSession(session);
817                            }
818                    }
819    
820                    return count.intValue();
821            }
822    
823            /**
824             * Initializes the browser tracker persistence.
825             */
826            public void afterPropertiesSet() {
827                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
828                                            com.liferay.portal.util.PropsUtil.get(
829                                                    "value.object.listener.com.liferay.portal.model.BrowserTracker")));
830    
831                    if (listenerClassNames.length > 0) {
832                            try {
833                                    List<ModelListener<BrowserTracker>> listenersList = new ArrayList<ModelListener<BrowserTracker>>();
834    
835                                    for (String listenerClassName : listenerClassNames) {
836                                            listenersList.add((ModelListener<BrowserTracker>)InstanceFactory.newInstance(
837                                                            listenerClassName));
838                                    }
839    
840                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
841                            }
842                            catch (Exception e) {
843                                    _log.error(e);
844                            }
845                    }
846            }
847    
848            public void destroy() {
849                    EntityCacheUtil.removeCache(BrowserTrackerImpl.class.getName());
850                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
851                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
852            }
853    
854            @BeanReference(type = AccountPersistence.class)
855            protected AccountPersistence accountPersistence;
856            @BeanReference(type = AddressPersistence.class)
857            protected AddressPersistence addressPersistence;
858            @BeanReference(type = BrowserTrackerPersistence.class)
859            protected BrowserTrackerPersistence browserTrackerPersistence;
860            @BeanReference(type = ClassNamePersistence.class)
861            protected ClassNamePersistence classNamePersistence;
862            @BeanReference(type = ClusterGroupPersistence.class)
863            protected ClusterGroupPersistence clusterGroupPersistence;
864            @BeanReference(type = CompanyPersistence.class)
865            protected CompanyPersistence companyPersistence;
866            @BeanReference(type = ContactPersistence.class)
867            protected ContactPersistence contactPersistence;
868            @BeanReference(type = CountryPersistence.class)
869            protected CountryPersistence countryPersistence;
870            @BeanReference(type = EmailAddressPersistence.class)
871            protected EmailAddressPersistence emailAddressPersistence;
872            @BeanReference(type = GroupPersistence.class)
873            protected GroupPersistence groupPersistence;
874            @BeanReference(type = ImagePersistence.class)
875            protected ImagePersistence imagePersistence;
876            @BeanReference(type = LayoutPersistence.class)
877            protected LayoutPersistence layoutPersistence;
878            @BeanReference(type = LayoutBranchPersistence.class)
879            protected LayoutBranchPersistence layoutBranchPersistence;
880            @BeanReference(type = LayoutPrototypePersistence.class)
881            protected LayoutPrototypePersistence layoutPrototypePersistence;
882            @BeanReference(type = LayoutRevisionPersistence.class)
883            protected LayoutRevisionPersistence layoutRevisionPersistence;
884            @BeanReference(type = LayoutSetPersistence.class)
885            protected LayoutSetPersistence layoutSetPersistence;
886            @BeanReference(type = LayoutSetBranchPersistence.class)
887            protected LayoutSetBranchPersistence layoutSetBranchPersistence;
888            @BeanReference(type = LayoutSetPrototypePersistence.class)
889            protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
890            @BeanReference(type = ListTypePersistence.class)
891            protected ListTypePersistence listTypePersistence;
892            @BeanReference(type = LockPersistence.class)
893            protected LockPersistence lockPersistence;
894            @BeanReference(type = MembershipRequestPersistence.class)
895            protected MembershipRequestPersistence membershipRequestPersistence;
896            @BeanReference(type = OrganizationPersistence.class)
897            protected OrganizationPersistence organizationPersistence;
898            @BeanReference(type = OrgGroupPermissionPersistence.class)
899            protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
900            @BeanReference(type = OrgGroupRolePersistence.class)
901            protected OrgGroupRolePersistence orgGroupRolePersistence;
902            @BeanReference(type = OrgLaborPersistence.class)
903            protected OrgLaborPersistence orgLaborPersistence;
904            @BeanReference(type = PasswordPolicyPersistence.class)
905            protected PasswordPolicyPersistence passwordPolicyPersistence;
906            @BeanReference(type = PasswordPolicyRelPersistence.class)
907            protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
908            @BeanReference(type = PasswordTrackerPersistence.class)
909            protected PasswordTrackerPersistence passwordTrackerPersistence;
910            @BeanReference(type = PermissionPersistence.class)
911            protected PermissionPersistence permissionPersistence;
912            @BeanReference(type = PhonePersistence.class)
913            protected PhonePersistence phonePersistence;
914            @BeanReference(type = PluginSettingPersistence.class)
915            protected PluginSettingPersistence pluginSettingPersistence;
916            @BeanReference(type = PortalPreferencesPersistence.class)
917            protected PortalPreferencesPersistence portalPreferencesPersistence;
918            @BeanReference(type = PortletPersistence.class)
919            protected PortletPersistence portletPersistence;
920            @BeanReference(type = PortletItemPersistence.class)
921            protected PortletItemPersistence portletItemPersistence;
922            @BeanReference(type = PortletPreferencesPersistence.class)
923            protected PortletPreferencesPersistence portletPreferencesPersistence;
924            @BeanReference(type = RegionPersistence.class)
925            protected RegionPersistence regionPersistence;
926            @BeanReference(type = ReleasePersistence.class)
927            protected ReleasePersistence releasePersistence;
928            @BeanReference(type = RepositoryPersistence.class)
929            protected RepositoryPersistence repositoryPersistence;
930            @BeanReference(type = RepositoryEntryPersistence.class)
931            protected RepositoryEntryPersistence repositoryEntryPersistence;
932            @BeanReference(type = ResourcePersistence.class)
933            protected ResourcePersistence resourcePersistence;
934            @BeanReference(type = ResourceActionPersistence.class)
935            protected ResourceActionPersistence resourceActionPersistence;
936            @BeanReference(type = ResourceBlockPersistence.class)
937            protected ResourceBlockPersistence resourceBlockPersistence;
938            @BeanReference(type = ResourceBlockPermissionPersistence.class)
939            protected ResourceBlockPermissionPersistence resourceBlockPermissionPersistence;
940            @BeanReference(type = ResourceCodePersistence.class)
941            protected ResourceCodePersistence resourceCodePersistence;
942            @BeanReference(type = ResourcePermissionPersistence.class)
943            protected ResourcePermissionPersistence resourcePermissionPersistence;
944            @BeanReference(type = ResourceTypePermissionPersistence.class)
945            protected ResourceTypePermissionPersistence resourceTypePermissionPersistence;
946            @BeanReference(type = RolePersistence.class)
947            protected RolePersistence rolePersistence;
948            @BeanReference(type = ServiceComponentPersistence.class)
949            protected ServiceComponentPersistence serviceComponentPersistence;
950            @BeanReference(type = ShardPersistence.class)
951            protected ShardPersistence shardPersistence;
952            @BeanReference(type = SubscriptionPersistence.class)
953            protected SubscriptionPersistence subscriptionPersistence;
954            @BeanReference(type = TeamPersistence.class)
955            protected TeamPersistence teamPersistence;
956            @BeanReference(type = TicketPersistence.class)
957            protected TicketPersistence ticketPersistence;
958            @BeanReference(type = UserPersistence.class)
959            protected UserPersistence userPersistence;
960            @BeanReference(type = UserGroupPersistence.class)
961            protected UserGroupPersistence userGroupPersistence;
962            @BeanReference(type = UserGroupGroupRolePersistence.class)
963            protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
964            @BeanReference(type = UserGroupRolePersistence.class)
965            protected UserGroupRolePersistence userGroupRolePersistence;
966            @BeanReference(type = UserIdMapperPersistence.class)
967            protected UserIdMapperPersistence userIdMapperPersistence;
968            @BeanReference(type = UserNotificationEventPersistence.class)
969            protected UserNotificationEventPersistence userNotificationEventPersistence;
970            @BeanReference(type = UserTrackerPersistence.class)
971            protected UserTrackerPersistence userTrackerPersistence;
972            @BeanReference(type = UserTrackerPathPersistence.class)
973            protected UserTrackerPathPersistence userTrackerPathPersistence;
974            @BeanReference(type = VirtualHostPersistence.class)
975            protected VirtualHostPersistence virtualHostPersistence;
976            @BeanReference(type = WebDAVPropsPersistence.class)
977            protected WebDAVPropsPersistence webDAVPropsPersistence;
978            @BeanReference(type = WebsitePersistence.class)
979            protected WebsitePersistence websitePersistence;
980            @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
981            protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
982            @BeanReference(type = WorkflowInstanceLinkPersistence.class)
983            protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
984            private static final String _SQL_SELECT_BROWSERTRACKER = "SELECT browserTracker FROM BrowserTracker browserTracker";
985            private static final String _SQL_SELECT_BROWSERTRACKER_WHERE = "SELECT browserTracker FROM BrowserTracker browserTracker WHERE ";
986            private static final String _SQL_COUNT_BROWSERTRACKER = "SELECT COUNT(browserTracker) FROM BrowserTracker browserTracker";
987            private static final String _SQL_COUNT_BROWSERTRACKER_WHERE = "SELECT COUNT(browserTracker) FROM BrowserTracker browserTracker WHERE ";
988            private static final String _FINDER_COLUMN_USERID_USERID_2 = "browserTracker.userId = ?";
989            private static final String _ORDER_BY_ENTITY_ALIAS = "browserTracker.";
990            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No BrowserTracker exists with the primary key ";
991            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No BrowserTracker exists with the key {";
992            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
993            private static Log _log = LogFactoryUtil.getLog(BrowserTrackerPersistenceImpl.class);
994            private static BrowserTracker _nullBrowserTracker = new BrowserTrackerImpl() {
995                            @Override
996                            public Object clone() {
997                                    return this;
998                            }
999    
1000                            @Override
1001                            public CacheModel<BrowserTracker> toCacheModel() {
1002                                    return _nullBrowserTrackerCacheModel;
1003                            }
1004                    };
1005    
1006            private static CacheModel<BrowserTracker> _nullBrowserTrackerCacheModel = new CacheModel<BrowserTracker>() {
1007                            public BrowserTracker toEntityModel() {
1008                                    return _nullBrowserTracker;
1009                            }
1010                    };
1011    }