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