001    /**
002     * Copyright (c) 2000-2010 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.annotation.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.ModelListener;
039    import com.liferay.portal.model.impl.BrowserTrackerImpl;
040    import com.liferay.portal.model.impl.BrowserTrackerModelImpl;
041    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
042    
043    import java.io.Serializable;
044    
045    import java.util.ArrayList;
046    import java.util.Collections;
047    import java.util.List;
048    
049    /**
050     * The persistence for the browser tracker service.
051     *
052     * <p>
053     * Never modify this class directly. Modify <code>service.xml</code> and rerun ServiceBuilder to regnerate this class.
054     * </p>
055     *
056     * <p>
057     * Caching information and settings can be found in <code>portal.properties</code>
058     * </p>
059     *
060     * @author Brian Wing Shun Chan
061     * @see BrowserTrackerPersistence
062     * @see BrowserTrackerUtil
063     * @generated
064     */
065    public class BrowserTrackerPersistenceImpl extends BasePersistenceImpl<BrowserTracker>
066            implements BrowserTrackerPersistence {
067            public static final String FINDER_CLASS_NAME_ENTITY = BrowserTrackerImpl.class.getName();
068            public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
069                    ".List";
070            public static final FinderPath FINDER_PATH_FETCH_BY_USERID = new FinderPath(BrowserTrackerModelImpl.ENTITY_CACHE_ENABLED,
071                            BrowserTrackerModelImpl.FINDER_CACHE_ENABLED,
072                            FINDER_CLASS_NAME_ENTITY, "fetchByUserId",
073                            new String[] { Long.class.getName() });
074            public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(BrowserTrackerModelImpl.ENTITY_CACHE_ENABLED,
075                            BrowserTrackerModelImpl.FINDER_CACHE_ENABLED,
076                            FINDER_CLASS_NAME_LIST, "countByUserId",
077                            new String[] { Long.class.getName() });
078            public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(BrowserTrackerModelImpl.ENTITY_CACHE_ENABLED,
079                            BrowserTrackerModelImpl.FINDER_CACHE_ENABLED,
080                            FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
081            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(BrowserTrackerModelImpl.ENTITY_CACHE_ENABLED,
082                            BrowserTrackerModelImpl.FINDER_CACHE_ENABLED,
083                            FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
084    
085            /**
086             * Caches the browser tracker in the entity cache if it is enabled.
087             *
088             * @param browserTracker the browser tracker to cache
089             */
090            public void cacheResult(BrowserTracker browserTracker) {
091                    EntityCacheUtil.putResult(BrowserTrackerModelImpl.ENTITY_CACHE_ENABLED,
092                            BrowserTrackerImpl.class, browserTracker.getPrimaryKey(),
093                            browserTracker);
094    
095                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_USERID,
096                            new Object[] { new Long(browserTracker.getUserId()) },
097                            browserTracker);
098            }
099    
100            /**
101             * Caches the browser trackers in the entity cache if it is enabled.
102             *
103             * @param browserTrackers the browser trackers to cache
104             */
105            public void cacheResult(List<BrowserTracker> browserTrackers) {
106                    for (BrowserTracker browserTracker : browserTrackers) {
107                            if (EntityCacheUtil.getResult(
108                                                    BrowserTrackerModelImpl.ENTITY_CACHE_ENABLED,
109                                                    BrowserTrackerImpl.class,
110                                                    browserTracker.getPrimaryKey(), this) == null) {
111                                    cacheResult(browserTracker);
112                            }
113                    }
114            }
115    
116            /**
117             * Clears the cache for all browser trackers.
118             *
119             * <p>
120             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
121             * </p>
122             */
123            public void clearCache() {
124                    CacheRegistryUtil.clear(BrowserTrackerImpl.class.getName());
125                    EntityCacheUtil.clearCache(BrowserTrackerImpl.class.getName());
126                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
127                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
128            }
129    
130            /**
131             * Clears the cache for the browser tracker.
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            public void clearCache(BrowserTracker browserTracker) {
138                    EntityCacheUtil.removeResult(BrowserTrackerModelImpl.ENTITY_CACHE_ENABLED,
139                            BrowserTrackerImpl.class, browserTracker.getPrimaryKey());
140    
141                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_USERID,
142                            new Object[] { new Long(browserTracker.getUserId()) });
143            }
144    
145            /**
146             * Creates a new browser tracker with the primary key.
147             *
148             * @param browserTrackerId the primary key for the new browser tracker
149             * @return the new browser tracker
150             */
151            public BrowserTracker create(long browserTrackerId) {
152                    BrowserTracker browserTracker = new BrowserTrackerImpl();
153    
154                    browserTracker.setNew(true);
155                    browserTracker.setPrimaryKey(browserTrackerId);
156    
157                    return browserTracker;
158            }
159    
160            /**
161             * Removes the browser tracker with the primary key from the database. Also notifies the appropriate model listeners.
162             *
163             * @param primaryKey the primary key of the browser tracker to remove
164             * @return the browser tracker that was removed
165             * @throws com.liferay.portal.NoSuchModelException if a browser tracker with the primary key could not be found
166             * @throws SystemException if a system exception occurred
167             */
168            public BrowserTracker remove(Serializable primaryKey)
169                    throws NoSuchModelException, SystemException {
170                    return remove(((Long)primaryKey).longValue());
171            }
172    
173            /**
174             * Removes the browser tracker with the primary key from the database. Also notifies the appropriate model listeners.
175             *
176             * @param browserTrackerId the primary key of the browser tracker to remove
177             * @return the browser tracker that was removed
178             * @throws com.liferay.portal.NoSuchBrowserTrackerException if a browser tracker with the primary key could not be found
179             * @throws SystemException if a system exception occurred
180             */
181            public BrowserTracker remove(long browserTrackerId)
182                    throws NoSuchBrowserTrackerException, SystemException {
183                    Session session = null;
184    
185                    try {
186                            session = openSession();
187    
188                            BrowserTracker browserTracker = (BrowserTracker)session.get(BrowserTrackerImpl.class,
189                                            new Long(browserTrackerId));
190    
191                            if (browserTracker == null) {
192                                    if (_log.isWarnEnabled()) {
193                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
194                                                    browserTrackerId);
195                                    }
196    
197                                    throw new NoSuchBrowserTrackerException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
198                                            browserTrackerId);
199                            }
200    
201                            return remove(browserTracker);
202                    }
203                    catch (NoSuchBrowserTrackerException nsee) {
204                            throw nsee;
205                    }
206                    catch (Exception e) {
207                            throw processException(e);
208                    }
209                    finally {
210                            closeSession(session);
211                    }
212            }
213    
214            protected BrowserTracker removeImpl(BrowserTracker browserTracker)
215                    throws SystemException {
216                    browserTracker = toUnwrappedModel(browserTracker);
217    
218                    Session session = null;
219    
220                    try {
221                            session = openSession();
222    
223                            if (browserTracker.isCachedModel() || BatchSessionUtil.isEnabled()) {
224                                    Object staleObject = session.get(BrowserTrackerImpl.class,
225                                                    browserTracker.getPrimaryKeyObj());
226    
227                                    if (staleObject != null) {
228                                            session.evict(staleObject);
229                                    }
230                            }
231    
232                            session.delete(browserTracker);
233    
234                            session.flush();
235                    }
236                    catch (Exception e) {
237                            throw processException(e);
238                    }
239                    finally {
240                            closeSession(session);
241                    }
242    
243                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
244    
245                    BrowserTrackerModelImpl browserTrackerModelImpl = (BrowserTrackerModelImpl)browserTracker;
246    
247                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_USERID,
248                            new Object[] { new Long(browserTrackerModelImpl.getOriginalUserId()) });
249    
250                    EntityCacheUtil.removeResult(BrowserTrackerModelImpl.ENTITY_CACHE_ENABLED,
251                            BrowserTrackerImpl.class, browserTracker.getPrimaryKey());
252    
253                    return browserTracker;
254            }
255    
256            public BrowserTracker updateImpl(
257                    com.liferay.portal.model.BrowserTracker browserTracker, boolean merge)
258                    throws SystemException {
259                    browserTracker = toUnwrappedModel(browserTracker);
260    
261                    boolean isNew = browserTracker.isNew();
262    
263                    BrowserTrackerModelImpl browserTrackerModelImpl = (BrowserTrackerModelImpl)browserTracker;
264    
265                    Session session = null;
266    
267                    try {
268                            session = openSession();
269    
270                            BatchSessionUtil.update(session, browserTracker, merge);
271    
272                            browserTracker.setNew(false);
273                    }
274                    catch (Exception e) {
275                            throw processException(e);
276                    }
277                    finally {
278                            closeSession(session);
279                    }
280    
281                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
282    
283                    EntityCacheUtil.putResult(BrowserTrackerModelImpl.ENTITY_CACHE_ENABLED,
284                            BrowserTrackerImpl.class, browserTracker.getPrimaryKey(),
285                            browserTracker);
286    
287                    if (!isNew &&
288                                    (browserTracker.getUserId() != browserTrackerModelImpl.getOriginalUserId())) {
289                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_USERID,
290                                    new Object[] {
291                                            new Long(browserTrackerModelImpl.getOriginalUserId())
292                                    });
293                    }
294    
295                    if (isNew ||
296                                    (browserTracker.getUserId() != browserTrackerModelImpl.getOriginalUserId())) {
297                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_USERID,
298                                    new Object[] { new Long(browserTracker.getUserId()) },
299                                    browserTracker);
300                    }
301    
302                    return browserTracker;
303            }
304    
305            protected BrowserTracker toUnwrappedModel(BrowserTracker browserTracker) {
306                    if (browserTracker instanceof BrowserTrackerImpl) {
307                            return browserTracker;
308                    }
309    
310                    BrowserTrackerImpl browserTrackerImpl = new BrowserTrackerImpl();
311    
312                    browserTrackerImpl.setNew(browserTracker.isNew());
313                    browserTrackerImpl.setPrimaryKey(browserTracker.getPrimaryKey());
314    
315                    browserTrackerImpl.setBrowserTrackerId(browserTracker.getBrowserTrackerId());
316                    browserTrackerImpl.setUserId(browserTracker.getUserId());
317                    browserTrackerImpl.setBrowserKey(browserTracker.getBrowserKey());
318    
319                    return browserTrackerImpl;
320            }
321    
322            /**
323             * Finds the browser tracker with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
324             *
325             * @param primaryKey the primary key of the browser tracker to find
326             * @return the browser tracker
327             * @throws com.liferay.portal.NoSuchModelException if a browser tracker with the primary key could not be found
328             * @throws SystemException if a system exception occurred
329             */
330            public BrowserTracker findByPrimaryKey(Serializable primaryKey)
331                    throws NoSuchModelException, SystemException {
332                    return findByPrimaryKey(((Long)primaryKey).longValue());
333            }
334    
335            /**
336             * Finds the browser tracker with the primary key or throws a {@link com.liferay.portal.NoSuchBrowserTrackerException} if it could not be found.
337             *
338             * @param browserTrackerId the primary key of the browser tracker to find
339             * @return the browser tracker
340             * @throws com.liferay.portal.NoSuchBrowserTrackerException if a browser tracker with the primary key could not be found
341             * @throws SystemException if a system exception occurred
342             */
343            public BrowserTracker findByPrimaryKey(long browserTrackerId)
344                    throws NoSuchBrowserTrackerException, SystemException {
345                    BrowserTracker browserTracker = fetchByPrimaryKey(browserTrackerId);
346    
347                    if (browserTracker == null) {
348                            if (_log.isWarnEnabled()) {
349                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + browserTrackerId);
350                            }
351    
352                            throw new NoSuchBrowserTrackerException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
353                                    browserTrackerId);
354                    }
355    
356                    return browserTracker;
357            }
358    
359            /**
360             * Finds the browser tracker with the primary key or returns <code>null</code> if it could not be found.
361             *
362             * @param primaryKey the primary key of the browser tracker to find
363             * @return the browser tracker, or <code>null</code> if a browser tracker with the primary key could not be found
364             * @throws SystemException if a system exception occurred
365             */
366            public BrowserTracker fetchByPrimaryKey(Serializable primaryKey)
367                    throws SystemException {
368                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
369            }
370    
371            /**
372             * Finds the browser tracker with the primary key or returns <code>null</code> if it could not be found.
373             *
374             * @param browserTrackerId the primary key of the browser tracker to find
375             * @return the browser tracker, or <code>null</code> if a browser tracker with the primary key could not be found
376             * @throws SystemException if a system exception occurred
377             */
378            public BrowserTracker fetchByPrimaryKey(long browserTrackerId)
379                    throws SystemException {
380                    BrowserTracker browserTracker = (BrowserTracker)EntityCacheUtil.getResult(BrowserTrackerModelImpl.ENTITY_CACHE_ENABLED,
381                                    BrowserTrackerImpl.class, browserTrackerId, this);
382    
383                    if (browserTracker == null) {
384                            Session session = null;
385    
386                            try {
387                                    session = openSession();
388    
389                                    browserTracker = (BrowserTracker)session.get(BrowserTrackerImpl.class,
390                                                    new Long(browserTrackerId));
391                            }
392                            catch (Exception e) {
393                                    throw processException(e);
394                            }
395                            finally {
396                                    if (browserTracker != null) {
397                                            cacheResult(browserTracker);
398                                    }
399    
400                                    closeSession(session);
401                            }
402                    }
403    
404                    return browserTracker;
405            }
406    
407            /**
408             * Finds the browser tracker where userId = &#63; or throws a {@link com.liferay.portal.NoSuchBrowserTrackerException} if it could not be found.
409             *
410             * @param userId the user id to search with
411             * @return the matching browser tracker
412             * @throws com.liferay.portal.NoSuchBrowserTrackerException if a matching browser tracker could not be found
413             * @throws SystemException if a system exception occurred
414             */
415            public BrowserTracker findByUserId(long userId)
416                    throws NoSuchBrowserTrackerException, SystemException {
417                    BrowserTracker browserTracker = fetchByUserId(userId);
418    
419                    if (browserTracker == null) {
420                            StringBundler msg = new StringBundler(4);
421    
422                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
423    
424                            msg.append("userId=");
425                            msg.append(userId);
426    
427                            msg.append(StringPool.CLOSE_CURLY_BRACE);
428    
429                            if (_log.isWarnEnabled()) {
430                                    _log.warn(msg.toString());
431                            }
432    
433                            throw new NoSuchBrowserTrackerException(msg.toString());
434                    }
435    
436                    return browserTracker;
437            }
438    
439            /**
440             * Finds the browser tracker where userId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
441             *
442             * @param userId the user id to search with
443             * @return the matching browser tracker, or <code>null</code> if a matching browser tracker could not be found
444             * @throws SystemException if a system exception occurred
445             */
446            public BrowserTracker fetchByUserId(long userId) throws SystemException {
447                    return fetchByUserId(userId, true);
448            }
449    
450            /**
451             * Finds the browser tracker where userId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
452             *
453             * @param userId the user id to search with
454             * @return the matching browser tracker, or <code>null</code> if a matching browser tracker could not be found
455             * @throws SystemException if a system exception occurred
456             */
457            public BrowserTracker fetchByUserId(long userId, boolean retrieveFromCache)
458                    throws SystemException {
459                    Object[] finderArgs = new Object[] { userId };
460    
461                    Object result = null;
462    
463                    if (retrieveFromCache) {
464                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_USERID,
465                                            finderArgs, this);
466                    }
467    
468                    if (result == null) {
469                            Session session = null;
470    
471                            try {
472                                    session = openSession();
473    
474                                    StringBundler query = new StringBundler(2);
475    
476                                    query.append(_SQL_SELECT_BROWSERTRACKER_WHERE);
477    
478                                    query.append(_FINDER_COLUMN_USERID_USERID_2);
479    
480                                    String sql = query.toString();
481    
482                                    Query q = session.createQuery(sql);
483    
484                                    QueryPos qPos = QueryPos.getInstance(q);
485    
486                                    qPos.add(userId);
487    
488                                    List<BrowserTracker> list = q.list();
489    
490                                    result = list;
491    
492                                    BrowserTracker browserTracker = null;
493    
494                                    if (list.isEmpty()) {
495                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_USERID,
496                                                    finderArgs, list);
497                                    }
498                                    else {
499                                            browserTracker = list.get(0);
500    
501                                            cacheResult(browserTracker);
502    
503                                            if ((browserTracker.getUserId() != userId)) {
504                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_USERID,
505                                                            finderArgs, browserTracker);
506                                            }
507                                    }
508    
509                                    return browserTracker;
510                            }
511                            catch (Exception e) {
512                                    throw processException(e);
513                            }
514                            finally {
515                                    if (result == null) {
516                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_USERID,
517                                                    finderArgs, new ArrayList<BrowserTracker>());
518                                    }
519    
520                                    closeSession(session);
521                            }
522                    }
523                    else {
524                            if (result instanceof List<?>) {
525                                    return null;
526                            }
527                            else {
528                                    return (BrowserTracker)result;
529                            }
530                    }
531            }
532    
533            /**
534             * Finds all the browser trackers.
535             *
536             * @return the browser trackers
537             * @throws SystemException if a system exception occurred
538             */
539            public List<BrowserTracker> findAll() throws SystemException {
540                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
541            }
542    
543            /**
544             * Finds a range of all the browser trackers.
545             *
546             * <p>
547             * 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.
548             * </p>
549             *
550             * @param start the lower bound of the range of browser trackers to return
551             * @param end the upper bound of the range of browser trackers to return (not inclusive)
552             * @return the range of browser trackers
553             * @throws SystemException if a system exception occurred
554             */
555            public List<BrowserTracker> findAll(int start, int end)
556                    throws SystemException {
557                    return findAll(start, end, null);
558            }
559    
560            /**
561             * Finds an ordered range of all the browser trackers.
562             *
563             * <p>
564             * 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.
565             * </p>
566             *
567             * @param start the lower bound of the range of browser trackers to return
568             * @param end the upper bound of the range of browser trackers to return (not inclusive)
569             * @param orderByComparator the comparator to order the results by
570             * @return the ordered range of browser trackers
571             * @throws SystemException if a system exception occurred
572             */
573            public List<BrowserTracker> findAll(int start, int end,
574                    OrderByComparator orderByComparator) throws SystemException {
575                    Object[] finderArgs = new Object[] {
576                                    String.valueOf(start), String.valueOf(end),
577                                    String.valueOf(orderByComparator)
578                            };
579    
580                    List<BrowserTracker> list = (List<BrowserTracker>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
581                                    finderArgs, this);
582    
583                    if (list == null) {
584                            Session session = null;
585    
586                            try {
587                                    session = openSession();
588    
589                                    StringBundler query = null;
590                                    String sql = null;
591    
592                                    if (orderByComparator != null) {
593                                            query = new StringBundler(2 +
594                                                            (orderByComparator.getOrderByFields().length * 3));
595    
596                                            query.append(_SQL_SELECT_BROWSERTRACKER);
597    
598                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
599                                                    orderByComparator);
600    
601                                            sql = query.toString();
602                                    }
603                                    else {
604                                            sql = _SQL_SELECT_BROWSERTRACKER;
605                                    }
606    
607                                    Query q = session.createQuery(sql);
608    
609                                    if (orderByComparator == null) {
610                                            list = (List<BrowserTracker>)QueryUtil.list(q,
611                                                            getDialect(), start, end, false);
612    
613                                            Collections.sort(list);
614                                    }
615                                    else {
616                                            list = (List<BrowserTracker>)QueryUtil.list(q,
617                                                            getDialect(), start, end);
618                                    }
619                            }
620                            catch (Exception e) {
621                                    throw processException(e);
622                            }
623                            finally {
624                                    if (list == null) {
625                                            list = new ArrayList<BrowserTracker>();
626                                    }
627    
628                                    cacheResult(list);
629    
630                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
631    
632                                    closeSession(session);
633                            }
634                    }
635    
636                    return list;
637            }
638    
639            /**
640             * Removes the browser tracker where userId = &#63; from the database.
641             *
642             * @param userId the user id to search with
643             * @throws SystemException if a system exception occurred
644             */
645            public void removeByUserId(long userId)
646                    throws NoSuchBrowserTrackerException, SystemException {
647                    BrowserTracker browserTracker = findByUserId(userId);
648    
649                    remove(browserTracker);
650            }
651    
652            /**
653             * Removes all the browser trackers from the database.
654             *
655             * @throws SystemException if a system exception occurred
656             */
657            public void removeAll() throws SystemException {
658                    for (BrowserTracker browserTracker : findAll()) {
659                            remove(browserTracker);
660                    }
661            }
662    
663            /**
664             * Counts all the browser trackers where userId = &#63;.
665             *
666             * @param userId the user id to search with
667             * @return the number of matching browser trackers
668             * @throws SystemException if a system exception occurred
669             */
670            public int countByUserId(long userId) throws SystemException {
671                    Object[] finderArgs = new Object[] { userId };
672    
673                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID,
674                                    finderArgs, this);
675    
676                    if (count == null) {
677                            Session session = null;
678    
679                            try {
680                                    session = openSession();
681    
682                                    StringBundler query = new StringBundler(2);
683    
684                                    query.append(_SQL_COUNT_BROWSERTRACKER_WHERE);
685    
686                                    query.append(_FINDER_COLUMN_USERID_USERID_2);
687    
688                                    String sql = query.toString();
689    
690                                    Query q = session.createQuery(sql);
691    
692                                    QueryPos qPos = QueryPos.getInstance(q);
693    
694                                    qPos.add(userId);
695    
696                                    count = (Long)q.uniqueResult();
697                            }
698                            catch (Exception e) {
699                                    throw processException(e);
700                            }
701                            finally {
702                                    if (count == null) {
703                                            count = Long.valueOf(0);
704                                    }
705    
706                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID,
707                                            finderArgs, count);
708    
709                                    closeSession(session);
710                            }
711                    }
712    
713                    return count.intValue();
714            }
715    
716            /**
717             * Counts all the browser trackers.
718             *
719             * @return the number of browser trackers
720             * @throws SystemException if a system exception occurred
721             */
722            public int countAll() throws SystemException {
723                    Object[] finderArgs = new Object[0];
724    
725                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
726                                    finderArgs, this);
727    
728                    if (count == null) {
729                            Session session = null;
730    
731                            try {
732                                    session = openSession();
733    
734                                    Query q = session.createQuery(_SQL_COUNT_BROWSERTRACKER);
735    
736                                    count = (Long)q.uniqueResult();
737                            }
738                            catch (Exception e) {
739                                    throw processException(e);
740                            }
741                            finally {
742                                    if (count == null) {
743                                            count = Long.valueOf(0);
744                                    }
745    
746                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
747                                            count);
748    
749                                    closeSession(session);
750                            }
751                    }
752    
753                    return count.intValue();
754            }
755    
756            /**
757             * Initializes the browser tracker persistence.
758             */
759            public void afterPropertiesSet() {
760                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
761                                            com.liferay.portal.util.PropsUtil.get(
762                                                    "value.object.listener.com.liferay.portal.model.BrowserTracker")));
763    
764                    if (listenerClassNames.length > 0) {
765                            try {
766                                    List<ModelListener<BrowserTracker>> listenersList = new ArrayList<ModelListener<BrowserTracker>>();
767    
768                                    for (String listenerClassName : listenerClassNames) {
769                                            listenersList.add((ModelListener<BrowserTracker>)InstanceFactory.newInstance(
770                                                            listenerClassName));
771                                    }
772    
773                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
774                            }
775                            catch (Exception e) {
776                                    _log.error(e);
777                            }
778                    }
779            }
780    
781            @BeanReference(type = AccountPersistence.class)
782            protected AccountPersistence accountPersistence;
783            @BeanReference(type = AddressPersistence.class)
784            protected AddressPersistence addressPersistence;
785            @BeanReference(type = BrowserTrackerPersistence.class)
786            protected BrowserTrackerPersistence browserTrackerPersistence;
787            @BeanReference(type = ClassNamePersistence.class)
788            protected ClassNamePersistence classNamePersistence;
789            @BeanReference(type = CompanyPersistence.class)
790            protected CompanyPersistence companyPersistence;
791            @BeanReference(type = ContactPersistence.class)
792            protected ContactPersistence contactPersistence;
793            @BeanReference(type = CountryPersistence.class)
794            protected CountryPersistence countryPersistence;
795            @BeanReference(type = EmailAddressPersistence.class)
796            protected EmailAddressPersistence emailAddressPersistence;
797            @BeanReference(type = GroupPersistence.class)
798            protected GroupPersistence groupPersistence;
799            @BeanReference(type = ImagePersistence.class)
800            protected ImagePersistence imagePersistence;
801            @BeanReference(type = LayoutPersistence.class)
802            protected LayoutPersistence layoutPersistence;
803            @BeanReference(type = LayoutPrototypePersistence.class)
804            protected LayoutPrototypePersistence layoutPrototypePersistence;
805            @BeanReference(type = LayoutSetPersistence.class)
806            protected LayoutSetPersistence layoutSetPersistence;
807            @BeanReference(type = LayoutSetPrototypePersistence.class)
808            protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
809            @BeanReference(type = ListTypePersistence.class)
810            protected ListTypePersistence listTypePersistence;
811            @BeanReference(type = LockPersistence.class)
812            protected LockPersistence lockPersistence;
813            @BeanReference(type = MembershipRequestPersistence.class)
814            protected MembershipRequestPersistence membershipRequestPersistence;
815            @BeanReference(type = OrganizationPersistence.class)
816            protected OrganizationPersistence organizationPersistence;
817            @BeanReference(type = OrgGroupPermissionPersistence.class)
818            protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
819            @BeanReference(type = OrgGroupRolePersistence.class)
820            protected OrgGroupRolePersistence orgGroupRolePersistence;
821            @BeanReference(type = OrgLaborPersistence.class)
822            protected OrgLaborPersistence orgLaborPersistence;
823            @BeanReference(type = PasswordPolicyPersistence.class)
824            protected PasswordPolicyPersistence passwordPolicyPersistence;
825            @BeanReference(type = PasswordPolicyRelPersistence.class)
826            protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
827            @BeanReference(type = PasswordTrackerPersistence.class)
828            protected PasswordTrackerPersistence passwordTrackerPersistence;
829            @BeanReference(type = PermissionPersistence.class)
830            protected PermissionPersistence permissionPersistence;
831            @BeanReference(type = PhonePersistence.class)
832            protected PhonePersistence phonePersistence;
833            @BeanReference(type = PluginSettingPersistence.class)
834            protected PluginSettingPersistence pluginSettingPersistence;
835            @BeanReference(type = PortletPersistence.class)
836            protected PortletPersistence portletPersistence;
837            @BeanReference(type = PortletItemPersistence.class)
838            protected PortletItemPersistence portletItemPersistence;
839            @BeanReference(type = PortletPreferencesPersistence.class)
840            protected PortletPreferencesPersistence portletPreferencesPersistence;
841            @BeanReference(type = RegionPersistence.class)
842            protected RegionPersistence regionPersistence;
843            @BeanReference(type = ReleasePersistence.class)
844            protected ReleasePersistence releasePersistence;
845            @BeanReference(type = ResourcePersistence.class)
846            protected ResourcePersistence resourcePersistence;
847            @BeanReference(type = ResourceActionPersistence.class)
848            protected ResourceActionPersistence resourceActionPersistence;
849            @BeanReference(type = ResourceCodePersistence.class)
850            protected ResourceCodePersistence resourceCodePersistence;
851            @BeanReference(type = ResourcePermissionPersistence.class)
852            protected ResourcePermissionPersistence resourcePermissionPersistence;
853            @BeanReference(type = RolePersistence.class)
854            protected RolePersistence rolePersistence;
855            @BeanReference(type = ServiceComponentPersistence.class)
856            protected ServiceComponentPersistence serviceComponentPersistence;
857            @BeanReference(type = ShardPersistence.class)
858            protected ShardPersistence shardPersistence;
859            @BeanReference(type = SubscriptionPersistence.class)
860            protected SubscriptionPersistence subscriptionPersistence;
861            @BeanReference(type = TicketPersistence.class)
862            protected TicketPersistence ticketPersistence;
863            @BeanReference(type = TeamPersistence.class)
864            protected TeamPersistence teamPersistence;
865            @BeanReference(type = UserPersistence.class)
866            protected UserPersistence userPersistence;
867            @BeanReference(type = UserGroupPersistence.class)
868            protected UserGroupPersistence userGroupPersistence;
869            @BeanReference(type = UserGroupGroupRolePersistence.class)
870            protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
871            @BeanReference(type = UserGroupRolePersistence.class)
872            protected UserGroupRolePersistence userGroupRolePersistence;
873            @BeanReference(type = UserIdMapperPersistence.class)
874            protected UserIdMapperPersistence userIdMapperPersistence;
875            @BeanReference(type = UserTrackerPersistence.class)
876            protected UserTrackerPersistence userTrackerPersistence;
877            @BeanReference(type = UserTrackerPathPersistence.class)
878            protected UserTrackerPathPersistence userTrackerPathPersistence;
879            @BeanReference(type = WebDAVPropsPersistence.class)
880            protected WebDAVPropsPersistence webDAVPropsPersistence;
881            @BeanReference(type = WebsitePersistence.class)
882            protected WebsitePersistence websitePersistence;
883            @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
884            protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
885            @BeanReference(type = WorkflowInstanceLinkPersistence.class)
886            protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
887            private static final String _SQL_SELECT_BROWSERTRACKER = "SELECT browserTracker FROM BrowserTracker browserTracker";
888            private static final String _SQL_SELECT_BROWSERTRACKER_WHERE = "SELECT browserTracker FROM BrowserTracker browserTracker WHERE ";
889            private static final String _SQL_COUNT_BROWSERTRACKER = "SELECT COUNT(browserTracker) FROM BrowserTracker browserTracker";
890            private static final String _SQL_COUNT_BROWSERTRACKER_WHERE = "SELECT COUNT(browserTracker) FROM BrowserTracker browserTracker WHERE ";
891            private static final String _FINDER_COLUMN_USERID_USERID_2 = "browserTracker.userId = ?";
892            private static final String _ORDER_BY_ENTITY_ALIAS = "browserTracker.";
893            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No BrowserTracker exists with the primary key ";
894            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No BrowserTracker exists with the key {";
895            private static Log _log = LogFactoryUtil.getLog(BrowserTrackerPersistenceImpl.class);
896    }