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