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