001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.service.persistence;
016    
017    import com.liferay.portal.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                                    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 instanceof BrowserTracker) {
519                            BrowserTracker browserTracker = (BrowserTracker)result;
520    
521                            if ((userId != browserTracker.getUserId())) {
522                                    result = null;
523                            }
524                    }
525    
526                    if (result == null) {
527                            StringBundler query = new StringBundler(2);
528    
529                            query.append(_SQL_SELECT_BROWSERTRACKER_WHERE);
530    
531                            query.append(_FINDER_COLUMN_USERID_USERID_2);
532    
533                            String sql = query.toString();
534    
535                            Session session = null;
536    
537                            try {
538                                    session = openSession();
539    
540                                    Query q = session.createQuery(sql);
541    
542                                    QueryPos qPos = QueryPos.getInstance(q);
543    
544                                    qPos.add(userId);
545    
546                                    List<BrowserTracker> list = q.list();
547    
548                                    result = list;
549    
550                                    BrowserTracker browserTracker = null;
551    
552                                    if (list.isEmpty()) {
553                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_USERID,
554                                                    finderArgs, list);
555                                    }
556                                    else {
557                                            browserTracker = list.get(0);
558    
559                                            cacheResult(browserTracker);
560    
561                                            if ((browserTracker.getUserId() != userId)) {
562                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_USERID,
563                                                            finderArgs, browserTracker);
564                                            }
565                                    }
566    
567                                    return browserTracker;
568                            }
569                            catch (Exception e) {
570                                    throw processException(e);
571                            }
572                            finally {
573                                    if (result == null) {
574                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_USERID,
575                                                    finderArgs);
576                                    }
577    
578                                    closeSession(session);
579                            }
580                    }
581                    else {
582                            if (result instanceof List<?>) {
583                                    return null;
584                            }
585                            else {
586                                    return (BrowserTracker)result;
587                            }
588                    }
589            }
590    
591            /**
592             * Returns all the browser trackers.
593             *
594             * @return the browser trackers
595             * @throws SystemException if a system exception occurred
596             */
597            public List<BrowserTracker> findAll() throws SystemException {
598                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
599            }
600    
601            /**
602             * Returns a range of all the browser trackers.
603             *
604             * <p>
605             * 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.
606             * </p>
607             *
608             * @param start the lower bound of the range of browser trackers
609             * @param end the upper bound of the range of browser trackers (not inclusive)
610             * @return the range of browser trackers
611             * @throws SystemException if a system exception occurred
612             */
613            public List<BrowserTracker> findAll(int start, int end)
614                    throws SystemException {
615                    return findAll(start, end, null);
616            }
617    
618            /**
619             * Returns an ordered range of all the browser trackers.
620             *
621             * <p>
622             * 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.
623             * </p>
624             *
625             * @param start the lower bound of the range of browser trackers
626             * @param end the upper bound of the range of browser trackers (not inclusive)
627             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
628             * @return the ordered range of browser trackers
629             * @throws SystemException if a system exception occurred
630             */
631            public List<BrowserTracker> findAll(int start, int end,
632                    OrderByComparator orderByComparator) throws SystemException {
633                    FinderPath finderPath = null;
634                    Object[] finderArgs = new Object[] { start, end, orderByComparator };
635    
636                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
637                                    (orderByComparator == null)) {
638                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
639                            finderArgs = FINDER_ARGS_EMPTY;
640                    }
641                    else {
642                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
643                            finderArgs = new Object[] { start, end, orderByComparator };
644                    }
645    
646                    List<BrowserTracker> list = (List<BrowserTracker>)FinderCacheUtil.getResult(finderPath,
647                                    finderArgs, this);
648    
649                    if (list == null) {
650                            StringBundler query = null;
651                            String sql = null;
652    
653                            if (orderByComparator != null) {
654                                    query = new StringBundler(2 +
655                                                    (orderByComparator.getOrderByFields().length * 3));
656    
657                                    query.append(_SQL_SELECT_BROWSERTRACKER);
658    
659                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
660                                            orderByComparator);
661    
662                                    sql = query.toString();
663                            }
664                            else {
665                                    sql = _SQL_SELECT_BROWSERTRACKER;
666                            }
667    
668                            Session session = null;
669    
670                            try {
671                                    session = openSession();
672    
673                                    Query q = session.createQuery(sql);
674    
675                                    if (orderByComparator == null) {
676                                            list = (List<BrowserTracker>)QueryUtil.list(q,
677                                                            getDialect(), start, end, false);
678    
679                                            Collections.sort(list);
680                                    }
681                                    else {
682                                            list = (List<BrowserTracker>)QueryUtil.list(q,
683                                                            getDialect(), start, end);
684                                    }
685                            }
686                            catch (Exception e) {
687                                    throw processException(e);
688                            }
689                            finally {
690                                    if (list == null) {
691                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
692                                    }
693                                    else {
694                                            cacheResult(list);
695    
696                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
697                                    }
698    
699                                    closeSession(session);
700                            }
701                    }
702    
703                    return list;
704            }
705    
706            /**
707             * Removes the browser tracker where userId = &#63; from the database.
708             *
709             * @param userId the user ID
710             * @throws SystemException if a system exception occurred
711             */
712            public void removeByUserId(long userId)
713                    throws NoSuchBrowserTrackerException, SystemException {
714                    BrowserTracker browserTracker = findByUserId(userId);
715    
716                    remove(browserTracker);
717            }
718    
719            /**
720             * Removes all the browser trackers from the database.
721             *
722             * @throws SystemException if a system exception occurred
723             */
724            public void removeAll() throws SystemException {
725                    for (BrowserTracker browserTracker : findAll()) {
726                            remove(browserTracker);
727                    }
728            }
729    
730            /**
731             * Returns the number of browser trackers where userId = &#63;.
732             *
733             * @param userId the user ID
734             * @return the number of matching browser trackers
735             * @throws SystemException if a system exception occurred
736             */
737            public int countByUserId(long userId) throws SystemException {
738                    Object[] finderArgs = new Object[] { userId };
739    
740                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID,
741                                    finderArgs, this);
742    
743                    if (count == null) {
744                            StringBundler query = new StringBundler(2);
745    
746                            query.append(_SQL_COUNT_BROWSERTRACKER_WHERE);
747    
748                            query.append(_FINDER_COLUMN_USERID_USERID_2);
749    
750                            String sql = query.toString();
751    
752                            Session session = null;
753    
754                            try {
755                                    session = openSession();
756    
757                                    Query q = session.createQuery(sql);
758    
759                                    QueryPos qPos = QueryPos.getInstance(q);
760    
761                                    qPos.add(userId);
762    
763                                    count = (Long)q.uniqueResult();
764                            }
765                            catch (Exception e) {
766                                    throw processException(e);
767                            }
768                            finally {
769                                    if (count == null) {
770                                            count = Long.valueOf(0);
771                                    }
772    
773                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID,
774                                            finderArgs, count);
775    
776                                    closeSession(session);
777                            }
778                    }
779    
780                    return count.intValue();
781            }
782    
783            /**
784             * Returns the number of browser trackers.
785             *
786             * @return the number of browser trackers
787             * @throws SystemException if a system exception occurred
788             */
789            public int countAll() throws SystemException {
790                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
791                                    FINDER_ARGS_EMPTY, this);
792    
793                    if (count == null) {
794                            Session session = null;
795    
796                            try {
797                                    session = openSession();
798    
799                                    Query q = session.createQuery(_SQL_COUNT_BROWSERTRACKER);
800    
801                                    count = (Long)q.uniqueResult();
802                            }
803                            catch (Exception e) {
804                                    throw processException(e);
805                            }
806                            finally {
807                                    if (count == null) {
808                                            count = Long.valueOf(0);
809                                    }
810    
811                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
812                                            FINDER_ARGS_EMPTY, count);
813    
814                                    closeSession(session);
815                            }
816                    }
817    
818                    return count.intValue();
819            }
820    
821            /**
822             * Initializes the browser tracker persistence.
823             */
824            public void afterPropertiesSet() {
825                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
826                                            com.liferay.portal.util.PropsUtil.get(
827                                                    "value.object.listener.com.liferay.portal.model.BrowserTracker")));
828    
829                    if (listenerClassNames.length > 0) {
830                            try {
831                                    List<ModelListener<BrowserTracker>> listenersList = new ArrayList<ModelListener<BrowserTracker>>();
832    
833                                    for (String listenerClassName : listenerClassNames) {
834                                            listenersList.add((ModelListener<BrowserTracker>)InstanceFactory.newInstance(
835                                                            listenerClassName));
836                                    }
837    
838                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
839                            }
840                            catch (Exception e) {
841                                    _log.error(e);
842                            }
843                    }
844            }
845    
846            public void destroy() {
847                    EntityCacheUtil.removeCache(BrowserTrackerImpl.class.getName());
848                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
849                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
850            }
851    
852            @BeanReference(type = AccountPersistence.class)
853            protected AccountPersistence accountPersistence;
854            @BeanReference(type = AddressPersistence.class)
855            protected AddressPersistence addressPersistence;
856            @BeanReference(type = BrowserTrackerPersistence.class)
857            protected BrowserTrackerPersistence browserTrackerPersistence;
858            @BeanReference(type = ClassNamePersistence.class)
859            protected ClassNamePersistence classNamePersistence;
860            @BeanReference(type = ClusterGroupPersistence.class)
861            protected ClusterGroupPersistence clusterGroupPersistence;
862            @BeanReference(type = CompanyPersistence.class)
863            protected CompanyPersistence companyPersistence;
864            @BeanReference(type = ContactPersistence.class)
865            protected ContactPersistence contactPersistence;
866            @BeanReference(type = CountryPersistence.class)
867            protected CountryPersistence countryPersistence;
868            @BeanReference(type = EmailAddressPersistence.class)
869            protected EmailAddressPersistence emailAddressPersistence;
870            @BeanReference(type = GroupPersistence.class)
871            protected GroupPersistence groupPersistence;
872            @BeanReference(type = ImagePersistence.class)
873            protected ImagePersistence imagePersistence;
874            @BeanReference(type = LayoutPersistence.class)
875            protected LayoutPersistence layoutPersistence;
876            @BeanReference(type = LayoutBranchPersistence.class)
877            protected LayoutBranchPersistence layoutBranchPersistence;
878            @BeanReference(type = LayoutPrototypePersistence.class)
879            protected LayoutPrototypePersistence layoutPrototypePersistence;
880            @BeanReference(type = LayoutRevisionPersistence.class)
881            protected LayoutRevisionPersistence layoutRevisionPersistence;
882            @BeanReference(type = LayoutSetPersistence.class)
883            protected LayoutSetPersistence layoutSetPersistence;
884            @BeanReference(type = LayoutSetBranchPersistence.class)
885            protected LayoutSetBranchPersistence layoutSetBranchPersistence;
886            @BeanReference(type = LayoutSetPrototypePersistence.class)
887            protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
888            @BeanReference(type = ListTypePersistence.class)
889            protected ListTypePersistence listTypePersistence;
890            @BeanReference(type = LockPersistence.class)
891            protected LockPersistence lockPersistence;
892            @BeanReference(type = MembershipRequestPersistence.class)
893            protected MembershipRequestPersistence membershipRequestPersistence;
894            @BeanReference(type = OrganizationPersistence.class)
895            protected OrganizationPersistence organizationPersistence;
896            @BeanReference(type = OrgGroupPermissionPersistence.class)
897            protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
898            @BeanReference(type = OrgGroupRolePersistence.class)
899            protected OrgGroupRolePersistence orgGroupRolePersistence;
900            @BeanReference(type = OrgLaborPersistence.class)
901            protected OrgLaborPersistence orgLaborPersistence;
902            @BeanReference(type = PasswordPolicyPersistence.class)
903            protected PasswordPolicyPersistence passwordPolicyPersistence;
904            @BeanReference(type = PasswordPolicyRelPersistence.class)
905            protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
906            @BeanReference(type = PasswordTrackerPersistence.class)
907            protected PasswordTrackerPersistence passwordTrackerPersistence;
908            @BeanReference(type = PermissionPersistence.class)
909            protected PermissionPersistence permissionPersistence;
910            @BeanReference(type = PhonePersistence.class)
911            protected PhonePersistence phonePersistence;
912            @BeanReference(type = PluginSettingPersistence.class)
913            protected PluginSettingPersistence pluginSettingPersistence;
914            @BeanReference(type = PortalPreferencesPersistence.class)
915            protected PortalPreferencesPersistence portalPreferencesPersistence;
916            @BeanReference(type = PortletPersistence.class)
917            protected PortletPersistence portletPersistence;
918            @BeanReference(type = PortletItemPersistence.class)
919            protected PortletItemPersistence portletItemPersistence;
920            @BeanReference(type = PortletPreferencesPersistence.class)
921            protected PortletPreferencesPersistence portletPreferencesPersistence;
922            @BeanReference(type = RegionPersistence.class)
923            protected RegionPersistence regionPersistence;
924            @BeanReference(type = ReleasePersistence.class)
925            protected ReleasePersistence releasePersistence;
926            @BeanReference(type = RepositoryPersistence.class)
927            protected RepositoryPersistence repositoryPersistence;
928            @BeanReference(type = RepositoryEntryPersistence.class)
929            protected RepositoryEntryPersistence repositoryEntryPersistence;
930            @BeanReference(type = ResourcePersistence.class)
931            protected ResourcePersistence resourcePersistence;
932            @BeanReference(type = ResourceActionPersistence.class)
933            protected ResourceActionPersistence resourceActionPersistence;
934            @BeanReference(type = ResourceBlockPersistence.class)
935            protected ResourceBlockPersistence resourceBlockPersistence;
936            @BeanReference(type = ResourceBlockPermissionPersistence.class)
937            protected ResourceBlockPermissionPersistence resourceBlockPermissionPersistence;
938            @BeanReference(type = ResourceCodePersistence.class)
939            protected ResourceCodePersistence resourceCodePersistence;
940            @BeanReference(type = ResourcePermissionPersistence.class)
941            protected ResourcePermissionPersistence resourcePermissionPersistence;
942            @BeanReference(type = ResourceTypePermissionPersistence.class)
943            protected ResourceTypePermissionPersistence resourceTypePermissionPersistence;
944            @BeanReference(type = RolePersistence.class)
945            protected RolePersistence rolePersistence;
946            @BeanReference(type = ServiceComponentPersistence.class)
947            protected ServiceComponentPersistence serviceComponentPersistence;
948            @BeanReference(type = ShardPersistence.class)
949            protected ShardPersistence shardPersistence;
950            @BeanReference(type = SubscriptionPersistence.class)
951            protected SubscriptionPersistence subscriptionPersistence;
952            @BeanReference(type = TeamPersistence.class)
953            protected TeamPersistence teamPersistence;
954            @BeanReference(type = TicketPersistence.class)
955            protected TicketPersistence ticketPersistence;
956            @BeanReference(type = UserPersistence.class)
957            protected UserPersistence userPersistence;
958            @BeanReference(type = UserGroupPersistence.class)
959            protected UserGroupPersistence userGroupPersistence;
960            @BeanReference(type = UserGroupGroupRolePersistence.class)
961            protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
962            @BeanReference(type = UserGroupRolePersistence.class)
963            protected UserGroupRolePersistence userGroupRolePersistence;
964            @BeanReference(type = UserIdMapperPersistence.class)
965            protected UserIdMapperPersistence userIdMapperPersistence;
966            @BeanReference(type = UserNotificationEventPersistence.class)
967            protected UserNotificationEventPersistence userNotificationEventPersistence;
968            @BeanReference(type = UserTrackerPersistence.class)
969            protected UserTrackerPersistence userTrackerPersistence;
970            @BeanReference(type = UserTrackerPathPersistence.class)
971            protected UserTrackerPathPersistence userTrackerPathPersistence;
972            @BeanReference(type = VirtualHostPersistence.class)
973            protected VirtualHostPersistence virtualHostPersistence;
974            @BeanReference(type = WebDAVPropsPersistence.class)
975            protected WebDAVPropsPersistence webDAVPropsPersistence;
976            @BeanReference(type = WebsitePersistence.class)
977            protected WebsitePersistence websitePersistence;
978            @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
979            protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
980            @BeanReference(type = WorkflowInstanceLinkPersistence.class)
981            protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
982            private static final String _SQL_SELECT_BROWSERTRACKER = "SELECT browserTracker FROM BrowserTracker browserTracker";
983            private static final String _SQL_SELECT_BROWSERTRACKER_WHERE = "SELECT browserTracker FROM BrowserTracker browserTracker WHERE ";
984            private static final String _SQL_COUNT_BROWSERTRACKER = "SELECT COUNT(browserTracker) FROM BrowserTracker browserTracker";
985            private static final String _SQL_COUNT_BROWSERTRACKER_WHERE = "SELECT COUNT(browserTracker) FROM BrowserTracker browserTracker WHERE ";
986            private static final String _FINDER_COLUMN_USERID_USERID_2 = "browserTracker.userId = ?";
987            private static final String _ORDER_BY_ENTITY_ALIAS = "browserTracker.";
988            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No BrowserTracker exists with the primary key ";
989            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No BrowserTracker exists with the key {";
990            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
991            private static Log _log = LogFactoryUtil.getLog(BrowserTrackerPersistenceImpl.class);
992            private static BrowserTracker _nullBrowserTracker = new BrowserTrackerImpl() {
993                            @Override
994                            public Object clone() {
995                                    return this;
996                            }
997    
998                            @Override
999                            public CacheModel<BrowserTracker> toCacheModel() {
1000                                    return _nullBrowserTrackerCacheModel;
1001                            }
1002                    };
1003    
1004            private static CacheModel<BrowserTracker> _nullBrowserTrackerCacheModel = new CacheModel<BrowserTracker>() {
1005                            public BrowserTracker toEntityModel() {
1006                                    return _nullBrowserTracker;
1007                            }
1008                    };
1009    }