001    /**
002     * Copyright (c) 2000-2011 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.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,
086                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "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, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
090                            "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                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_USERID, args);
329    
330                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_USERID,
331                                            new Object[] { Long.valueOf(browserTracker.getUserId()) },
332                                            browserTracker);
333                            }
334                    }
335    
336                    return browserTracker;
337            }
338    
339            protected BrowserTracker toUnwrappedModel(BrowserTracker browserTracker) {
340                    if (browserTracker instanceof BrowserTrackerImpl) {
341                            return browserTracker;
342                    }
343    
344                    BrowserTrackerImpl browserTrackerImpl = new BrowserTrackerImpl();
345    
346                    browserTrackerImpl.setNew(browserTracker.isNew());
347                    browserTrackerImpl.setPrimaryKey(browserTracker.getPrimaryKey());
348    
349                    browserTrackerImpl.setBrowserTrackerId(browserTracker.getBrowserTrackerId());
350                    browserTrackerImpl.setUserId(browserTracker.getUserId());
351                    browserTrackerImpl.setBrowserKey(browserTracker.getBrowserKey());
352    
353                    return browserTrackerImpl;
354            }
355    
356            /**
357             * Returns the browser tracker with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
358             *
359             * @param primaryKey the primary key of the browser tracker
360             * @return the browser tracker
361             * @throws com.liferay.portal.NoSuchModelException if a browser tracker with the primary key could not be found
362             * @throws SystemException if a system exception occurred
363             */
364            @Override
365            public BrowserTracker findByPrimaryKey(Serializable primaryKey)
366                    throws NoSuchModelException, SystemException {
367                    return findByPrimaryKey(((Long)primaryKey).longValue());
368            }
369    
370            /**
371             * Returns the browser tracker with the primary key or throws a {@link com.liferay.portal.NoSuchBrowserTrackerException} if it could not be found.
372             *
373             * @param browserTrackerId the primary key of the browser tracker
374             * @return the browser tracker
375             * @throws com.liferay.portal.NoSuchBrowserTrackerException if a browser tracker with the primary key could not be found
376             * @throws SystemException if a system exception occurred
377             */
378            public BrowserTracker findByPrimaryKey(long browserTrackerId)
379                    throws NoSuchBrowserTrackerException, SystemException {
380                    BrowserTracker browserTracker = fetchByPrimaryKey(browserTrackerId);
381    
382                    if (browserTracker == null) {
383                            if (_log.isWarnEnabled()) {
384                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + browserTrackerId);
385                            }
386    
387                            throw new NoSuchBrowserTrackerException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
388                                    browserTrackerId);
389                    }
390    
391                    return browserTracker;
392            }
393    
394            /**
395             * Returns the browser tracker with the primary key or returns <code>null</code> if it could not be found.
396             *
397             * @param primaryKey the primary key of the browser tracker
398             * @return the browser tracker, or <code>null</code> if a browser tracker with the primary key could not be found
399             * @throws SystemException if a system exception occurred
400             */
401            @Override
402            public BrowserTracker fetchByPrimaryKey(Serializable primaryKey)
403                    throws SystemException {
404                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
405            }
406    
407            /**
408             * Returns the browser tracker with the primary key or returns <code>null</code> if it could not be found.
409             *
410             * @param browserTrackerId the primary key of the browser tracker
411             * @return the browser tracker, or <code>null</code> if a browser tracker with the primary key could not be found
412             * @throws SystemException if a system exception occurred
413             */
414            public BrowserTracker fetchByPrimaryKey(long browserTrackerId)
415                    throws SystemException {
416                    BrowserTracker browserTracker = (BrowserTracker)EntityCacheUtil.getResult(BrowserTrackerModelImpl.ENTITY_CACHE_ENABLED,
417                                    BrowserTrackerImpl.class, browserTrackerId);
418    
419                    if (browserTracker == _nullBrowserTracker) {
420                            return null;
421                    }
422    
423                    if (browserTracker == null) {
424                            Session session = null;
425    
426                            boolean hasException = false;
427    
428                            try {
429                                    session = openSession();
430    
431                                    browserTracker = (BrowserTracker)session.get(BrowserTrackerImpl.class,
432                                                    Long.valueOf(browserTrackerId));
433                            }
434                            catch (Exception e) {
435                                    hasException = true;
436    
437                                    throw processException(e);
438                            }
439                            finally {
440                                    if (browserTracker != null) {
441                                            cacheResult(browserTracker);
442                                    }
443                                    else if (!hasException) {
444                                            EntityCacheUtil.putResult(BrowserTrackerModelImpl.ENTITY_CACHE_ENABLED,
445                                                    BrowserTrackerImpl.class, browserTrackerId,
446                                                    _nullBrowserTracker);
447                                    }
448    
449                                    closeSession(session);
450                            }
451                    }
452    
453                    return browserTracker;
454            }
455    
456            /**
457             * Returns the browser tracker where userId = &#63; or throws a {@link com.liferay.portal.NoSuchBrowserTrackerException} if it could not be found.
458             *
459             * @param userId the user ID
460             * @return the matching browser tracker
461             * @throws com.liferay.portal.NoSuchBrowserTrackerException if a matching browser tracker could not be found
462             * @throws SystemException if a system exception occurred
463             */
464            public BrowserTracker findByUserId(long userId)
465                    throws NoSuchBrowserTrackerException, SystemException {
466                    BrowserTracker browserTracker = fetchByUserId(userId);
467    
468                    if (browserTracker == null) {
469                            StringBundler msg = new StringBundler(4);
470    
471                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
472    
473                            msg.append("userId=");
474                            msg.append(userId);
475    
476                            msg.append(StringPool.CLOSE_CURLY_BRACE);
477    
478                            if (_log.isWarnEnabled()) {
479                                    _log.warn(msg.toString());
480                            }
481    
482                            throw new NoSuchBrowserTrackerException(msg.toString());
483                    }
484    
485                    return browserTracker;
486            }
487    
488            /**
489             * Returns the browser tracker where userId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
490             *
491             * @param userId the user ID
492             * @return the matching browser tracker, or <code>null</code> if a matching browser tracker could not be found
493             * @throws SystemException if a system exception occurred
494             */
495            public BrowserTracker fetchByUserId(long userId) throws SystemException {
496                    return fetchByUserId(userId, true);
497            }
498    
499            /**
500             * Returns the browser tracker where userId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
501             *
502             * @param userId the user ID
503             * @param retrieveFromCache whether to use the finder cache
504             * @return the matching browser tracker, or <code>null</code> if a matching browser tracker could not be found
505             * @throws SystemException if a system exception occurred
506             */
507            public BrowserTracker fetchByUserId(long userId, boolean retrieveFromCache)
508                    throws SystemException {
509                    Object[] finderArgs = new Object[] { userId };
510    
511                    Object result = null;
512    
513                    if (retrieveFromCache) {
514                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_USERID,
515                                            finderArgs, this);
516                    }
517    
518                    if (result == null) {
519                            StringBundler query = new StringBundler(2);
520    
521                            query.append(_SQL_SELECT_BROWSERTRACKER_WHERE);
522    
523                            query.append(_FINDER_COLUMN_USERID_USERID_2);
524    
525                            String sql = query.toString();
526    
527                            Session session = null;
528    
529                            try {
530                                    session = openSession();
531    
532                                    Query q = session.createQuery(sql);
533    
534                                    QueryPos qPos = QueryPos.getInstance(q);
535    
536                                    qPos.add(userId);
537    
538                                    List<BrowserTracker> list = q.list();
539    
540                                    result = list;
541    
542                                    BrowserTracker browserTracker = null;
543    
544                                    if (list.isEmpty()) {
545                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_USERID,
546                                                    finderArgs, list);
547                                    }
548                                    else {
549                                            browserTracker = list.get(0);
550    
551                                            cacheResult(browserTracker);
552    
553                                            if ((browserTracker.getUserId() != userId)) {
554                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_USERID,
555                                                            finderArgs, browserTracker);
556                                            }
557                                    }
558    
559                                    return browserTracker;
560                            }
561                            catch (Exception e) {
562                                    throw processException(e);
563                            }
564                            finally {
565                                    if (result == null) {
566                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_USERID,
567                                                    finderArgs);
568                                    }
569    
570                                    closeSession(session);
571                            }
572                    }
573                    else {
574                            if (result instanceof List<?>) {
575                                    return null;
576                            }
577                            else {
578                                    return (BrowserTracker)result;
579                            }
580                    }
581            }
582    
583            /**
584             * Returns all the browser trackers.
585             *
586             * @return the browser trackers
587             * @throws SystemException if a system exception occurred
588             */
589            public List<BrowserTracker> findAll() throws SystemException {
590                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
591            }
592    
593            /**
594             * Returns a range of all the browser trackers.
595             *
596             * <p>
597             * 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.
598             * </p>
599             *
600             * @param start the lower bound of the range of browser trackers
601             * @param end the upper bound of the range of browser trackers (not inclusive)
602             * @return the range of browser trackers
603             * @throws SystemException if a system exception occurred
604             */
605            public List<BrowserTracker> findAll(int start, int end)
606                    throws SystemException {
607                    return findAll(start, end, null);
608            }
609    
610            /**
611             * Returns an ordered range of all the browser trackers.
612             *
613             * <p>
614             * 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.
615             * </p>
616             *
617             * @param start the lower bound of the range of browser trackers
618             * @param end the upper bound of the range of browser trackers (not inclusive)
619             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
620             * @return the ordered range of browser trackers
621             * @throws SystemException if a system exception occurred
622             */
623            public List<BrowserTracker> findAll(int start, int end,
624                    OrderByComparator orderByComparator) throws SystemException {
625                    FinderPath finderPath = null;
626                    Object[] finderArgs = new Object[] { start, end, orderByComparator };
627    
628                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
629                                    (orderByComparator == null)) {
630                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
631                            finderArgs = FINDER_ARGS_EMPTY;
632                    }
633                    else {
634                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
635                            finderArgs = new Object[] { start, end, orderByComparator };
636                    }
637    
638                    List<BrowserTracker> list = (List<BrowserTracker>)FinderCacheUtil.getResult(finderPath,
639                                    finderArgs, this);
640    
641                    if (list == null) {
642                            StringBundler query = null;
643                            String sql = null;
644    
645                            if (orderByComparator != null) {
646                                    query = new StringBundler(2 +
647                                                    (orderByComparator.getOrderByFields().length * 3));
648    
649                                    query.append(_SQL_SELECT_BROWSERTRACKER);
650    
651                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
652                                            orderByComparator);
653    
654                                    sql = query.toString();
655                            }
656                            else {
657                                    sql = _SQL_SELECT_BROWSERTRACKER;
658                            }
659    
660                            Session session = null;
661    
662                            try {
663                                    session = openSession();
664    
665                                    Query q = session.createQuery(sql);
666    
667                                    if (orderByComparator == null) {
668                                            list = (List<BrowserTracker>)QueryUtil.list(q,
669                                                            getDialect(), start, end, false);
670    
671                                            Collections.sort(list);
672                                    }
673                                    else {
674                                            list = (List<BrowserTracker>)QueryUtil.list(q,
675                                                            getDialect(), start, end);
676                                    }
677                            }
678                            catch (Exception e) {
679                                    throw processException(e);
680                            }
681                            finally {
682                                    if (list == null) {
683                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
684                                    }
685                                    else {
686                                            cacheResult(list);
687    
688                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
689                                    }
690    
691                                    closeSession(session);
692                            }
693                    }
694    
695                    return list;
696            }
697    
698            /**
699             * Removes the browser tracker where userId = &#63; from the database.
700             *
701             * @param userId the user ID
702             * @throws SystemException if a system exception occurred
703             */
704            public void removeByUserId(long userId)
705                    throws NoSuchBrowserTrackerException, SystemException {
706                    BrowserTracker browserTracker = findByUserId(userId);
707    
708                    remove(browserTracker);
709            }
710    
711            /**
712             * Removes all the browser trackers from the database.
713             *
714             * @throws SystemException if a system exception occurred
715             */
716            public void removeAll() throws SystemException {
717                    for (BrowserTracker browserTracker : findAll()) {
718                            remove(browserTracker);
719                    }
720            }
721    
722            /**
723             * Returns the number of browser trackers where userId = &#63;.
724             *
725             * @param userId the user ID
726             * @return the number of matching browser trackers
727             * @throws SystemException if a system exception occurred
728             */
729            public int countByUserId(long userId) throws SystemException {
730                    Object[] finderArgs = new Object[] { userId };
731    
732                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID,
733                                    finderArgs, this);
734    
735                    if (count == null) {
736                            StringBundler query = new StringBundler(2);
737    
738                            query.append(_SQL_COUNT_BROWSERTRACKER_WHERE);
739    
740                            query.append(_FINDER_COLUMN_USERID_USERID_2);
741    
742                            String sql = query.toString();
743    
744                            Session session = null;
745    
746                            try {
747                                    session = openSession();
748    
749                                    Query q = session.createQuery(sql);
750    
751                                    QueryPos qPos = QueryPos.getInstance(q);
752    
753                                    qPos.add(userId);
754    
755                                    count = (Long)q.uniqueResult();
756                            }
757                            catch (Exception e) {
758                                    throw processException(e);
759                            }
760                            finally {
761                                    if (count == null) {
762                                            count = Long.valueOf(0);
763                                    }
764    
765                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID,
766                                            finderArgs, count);
767    
768                                    closeSession(session);
769                            }
770                    }
771    
772                    return count.intValue();
773            }
774    
775            /**
776             * Returns the number of browser trackers.
777             *
778             * @return the number of browser trackers
779             * @throws SystemException if a system exception occurred
780             */
781            public int countAll() throws SystemException {
782                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
783                                    FINDER_ARGS_EMPTY, this);
784    
785                    if (count == null) {
786                            Session session = null;
787    
788                            try {
789                                    session = openSession();
790    
791                                    Query q = session.createQuery(_SQL_COUNT_BROWSERTRACKER);
792    
793                                    count = (Long)q.uniqueResult();
794                            }
795                            catch (Exception e) {
796                                    throw processException(e);
797                            }
798                            finally {
799                                    if (count == null) {
800                                            count = Long.valueOf(0);
801                                    }
802    
803                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
804                                            FINDER_ARGS_EMPTY, count);
805    
806                                    closeSession(session);
807                            }
808                    }
809    
810                    return count.intValue();
811            }
812    
813            /**
814             * Initializes the browser tracker persistence.
815             */
816            public void afterPropertiesSet() {
817                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
818                                            com.liferay.portal.util.PropsUtil.get(
819                                                    "value.object.listener.com.liferay.portal.model.BrowserTracker")));
820    
821                    if (listenerClassNames.length > 0) {
822                            try {
823                                    List<ModelListener<BrowserTracker>> listenersList = new ArrayList<ModelListener<BrowserTracker>>();
824    
825                                    for (String listenerClassName : listenerClassNames) {
826                                            listenersList.add((ModelListener<BrowserTracker>)InstanceFactory.newInstance(
827                                                            listenerClassName));
828                                    }
829    
830                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
831                            }
832                            catch (Exception e) {
833                                    _log.error(e);
834                            }
835                    }
836            }
837    
838            public void destroy() {
839                    EntityCacheUtil.removeCache(BrowserTrackerImpl.class.getName());
840                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
841                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
842            }
843    
844            @BeanReference(type = AccountPersistence.class)
845            protected AccountPersistence accountPersistence;
846            @BeanReference(type = AddressPersistence.class)
847            protected AddressPersistence addressPersistence;
848            @BeanReference(type = BrowserTrackerPersistence.class)
849            protected BrowserTrackerPersistence browserTrackerPersistence;
850            @BeanReference(type = ClassNamePersistence.class)
851            protected ClassNamePersistence classNamePersistence;
852            @BeanReference(type = ClusterGroupPersistence.class)
853            protected ClusterGroupPersistence clusterGroupPersistence;
854            @BeanReference(type = CompanyPersistence.class)
855            protected CompanyPersistence companyPersistence;
856            @BeanReference(type = ContactPersistence.class)
857            protected ContactPersistence contactPersistence;
858            @BeanReference(type = CountryPersistence.class)
859            protected CountryPersistence countryPersistence;
860            @BeanReference(type = EmailAddressPersistence.class)
861            protected EmailAddressPersistence emailAddressPersistence;
862            @BeanReference(type = GroupPersistence.class)
863            protected GroupPersistence groupPersistence;
864            @BeanReference(type = ImagePersistence.class)
865            protected ImagePersistence imagePersistence;
866            @BeanReference(type = LayoutPersistence.class)
867            protected LayoutPersistence layoutPersistence;
868            @BeanReference(type = LayoutBranchPersistence.class)
869            protected LayoutBranchPersistence layoutBranchPersistence;
870            @BeanReference(type = LayoutPrototypePersistence.class)
871            protected LayoutPrototypePersistence layoutPrototypePersistence;
872            @BeanReference(type = LayoutRevisionPersistence.class)
873            protected LayoutRevisionPersistence layoutRevisionPersistence;
874            @BeanReference(type = LayoutSetPersistence.class)
875            protected LayoutSetPersistence layoutSetPersistence;
876            @BeanReference(type = LayoutSetBranchPersistence.class)
877            protected LayoutSetBranchPersistence layoutSetBranchPersistence;
878            @BeanReference(type = LayoutSetPrototypePersistence.class)
879            protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
880            @BeanReference(type = ListTypePersistence.class)
881            protected ListTypePersistence listTypePersistence;
882            @BeanReference(type = LockPersistence.class)
883            protected LockPersistence lockPersistence;
884            @BeanReference(type = MembershipRequestPersistence.class)
885            protected MembershipRequestPersistence membershipRequestPersistence;
886            @BeanReference(type = OrganizationPersistence.class)
887            protected OrganizationPersistence organizationPersistence;
888            @BeanReference(type = OrgGroupPermissionPersistence.class)
889            protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
890            @BeanReference(type = OrgGroupRolePersistence.class)
891            protected OrgGroupRolePersistence orgGroupRolePersistence;
892            @BeanReference(type = OrgLaborPersistence.class)
893            protected OrgLaborPersistence orgLaborPersistence;
894            @BeanReference(type = PasswordPolicyPersistence.class)
895            protected PasswordPolicyPersistence passwordPolicyPersistence;
896            @BeanReference(type = PasswordPolicyRelPersistence.class)
897            protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
898            @BeanReference(type = PasswordTrackerPersistence.class)
899            protected PasswordTrackerPersistence passwordTrackerPersistence;
900            @BeanReference(type = PermissionPersistence.class)
901            protected PermissionPersistence permissionPersistence;
902            @BeanReference(type = PhonePersistence.class)
903            protected PhonePersistence phonePersistence;
904            @BeanReference(type = PluginSettingPersistence.class)
905            protected PluginSettingPersistence pluginSettingPersistence;
906            @BeanReference(type = PortalPreferencesPersistence.class)
907            protected PortalPreferencesPersistence portalPreferencesPersistence;
908            @BeanReference(type = PortletPersistence.class)
909            protected PortletPersistence portletPersistence;
910            @BeanReference(type = PortletItemPersistence.class)
911            protected PortletItemPersistence portletItemPersistence;
912            @BeanReference(type = PortletPreferencesPersistence.class)
913            protected PortletPreferencesPersistence portletPreferencesPersistence;
914            @BeanReference(type = RegionPersistence.class)
915            protected RegionPersistence regionPersistence;
916            @BeanReference(type = ReleasePersistence.class)
917            protected ReleasePersistence releasePersistence;
918            @BeanReference(type = RepositoryPersistence.class)
919            protected RepositoryPersistence repositoryPersistence;
920            @BeanReference(type = RepositoryEntryPersistence.class)
921            protected RepositoryEntryPersistence repositoryEntryPersistence;
922            @BeanReference(type = ResourcePersistence.class)
923            protected ResourcePersistence resourcePersistence;
924            @BeanReference(type = ResourceActionPersistence.class)
925            protected ResourceActionPersistence resourceActionPersistence;
926            @BeanReference(type = ResourceBlockPersistence.class)
927            protected ResourceBlockPersistence resourceBlockPersistence;
928            @BeanReference(type = ResourceBlockPermissionPersistence.class)
929            protected ResourceBlockPermissionPersistence resourceBlockPermissionPersistence;
930            @BeanReference(type = ResourceCodePersistence.class)
931            protected ResourceCodePersistence resourceCodePersistence;
932            @BeanReference(type = ResourcePermissionPersistence.class)
933            protected ResourcePermissionPersistence resourcePermissionPersistence;
934            @BeanReference(type = ResourceTypePermissionPersistence.class)
935            protected ResourceTypePermissionPersistence resourceTypePermissionPersistence;
936            @BeanReference(type = RolePersistence.class)
937            protected RolePersistence rolePersistence;
938            @BeanReference(type = ServiceComponentPersistence.class)
939            protected ServiceComponentPersistence serviceComponentPersistence;
940            @BeanReference(type = ShardPersistence.class)
941            protected ShardPersistence shardPersistence;
942            @BeanReference(type = SubscriptionPersistence.class)
943            protected SubscriptionPersistence subscriptionPersistence;
944            @BeanReference(type = TeamPersistence.class)
945            protected TeamPersistence teamPersistence;
946            @BeanReference(type = TicketPersistence.class)
947            protected TicketPersistence ticketPersistence;
948            @BeanReference(type = UserPersistence.class)
949            protected UserPersistence userPersistence;
950            @BeanReference(type = UserGroupPersistence.class)
951            protected UserGroupPersistence userGroupPersistence;
952            @BeanReference(type = UserGroupGroupRolePersistence.class)
953            protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
954            @BeanReference(type = UserGroupRolePersistence.class)
955            protected UserGroupRolePersistence userGroupRolePersistence;
956            @BeanReference(type = UserIdMapperPersistence.class)
957            protected UserIdMapperPersistence userIdMapperPersistence;
958            @BeanReference(type = UserNotificationEventPersistence.class)
959            protected UserNotificationEventPersistence userNotificationEventPersistence;
960            @BeanReference(type = UserTrackerPersistence.class)
961            protected UserTrackerPersistence userTrackerPersistence;
962            @BeanReference(type = UserTrackerPathPersistence.class)
963            protected UserTrackerPathPersistence userTrackerPathPersistence;
964            @BeanReference(type = VirtualHostPersistence.class)
965            protected VirtualHostPersistence virtualHostPersistence;
966            @BeanReference(type = WebDAVPropsPersistence.class)
967            protected WebDAVPropsPersistence webDAVPropsPersistence;
968            @BeanReference(type = WebsitePersistence.class)
969            protected WebsitePersistence websitePersistence;
970            @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
971            protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
972            @BeanReference(type = WorkflowInstanceLinkPersistence.class)
973            protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
974            private static final String _SQL_SELECT_BROWSERTRACKER = "SELECT browserTracker FROM BrowserTracker browserTracker";
975            private static final String _SQL_SELECT_BROWSERTRACKER_WHERE = "SELECT browserTracker FROM BrowserTracker browserTracker WHERE ";
976            private static final String _SQL_COUNT_BROWSERTRACKER = "SELECT COUNT(browserTracker) FROM BrowserTracker browserTracker";
977            private static final String _SQL_COUNT_BROWSERTRACKER_WHERE = "SELECT COUNT(browserTracker) FROM BrowserTracker browserTracker WHERE ";
978            private static final String _FINDER_COLUMN_USERID_USERID_2 = "browserTracker.userId = ?";
979            private static final String _ORDER_BY_ENTITY_ALIAS = "browserTracker.";
980            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No BrowserTracker exists with the primary key ";
981            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No BrowserTracker exists with the key {";
982            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
983            private static Log _log = LogFactoryUtil.getLog(BrowserTrackerPersistenceImpl.class);
984            private static BrowserTracker _nullBrowserTracker = new BrowserTrackerImpl() {
985                            @Override
986                            public Object clone() {
987                                    return this;
988                            }
989    
990                            @Override
991                            public CacheModel<BrowserTracker> toCacheModel() {
992                                    return _nullBrowserTrackerCacheModel;
993                            }
994                    };
995    
996            private static CacheModel<BrowserTracker> _nullBrowserTrackerCacheModel = new CacheModel<BrowserTracker>() {
997                            public BrowserTracker toEntityModel() {
998                                    return _nullBrowserTracker;
999                            }
1000                    };
1001    }