001    /**
002     * Copyright (c) 2000-2011 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 implementation for the browser tracker service.
051     *
052     * <p>
053     * 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.
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. Does not add the browser tracker to the database.
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                            BatchSessionUtil.delete(session, browserTracker);
224                    }
225                    catch (Exception e) {
226                            throw processException(e);
227                    }
228                    finally {
229                            closeSession(session);
230                    }
231    
232                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
233    
234                    BrowserTrackerModelImpl browserTrackerModelImpl = (BrowserTrackerModelImpl)browserTracker;
235    
236                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_USERID,
237                            new Object[] { new Long(browserTrackerModelImpl.getUserId()) });
238    
239                    EntityCacheUtil.removeResult(BrowserTrackerModelImpl.ENTITY_CACHE_ENABLED,
240                            BrowserTrackerImpl.class, browserTracker.getPrimaryKey());
241    
242                    return browserTracker;
243            }
244    
245            public BrowserTracker updateImpl(
246                    com.liferay.portal.model.BrowserTracker browserTracker, boolean merge)
247                    throws SystemException {
248                    browserTracker = toUnwrappedModel(browserTracker);
249    
250                    boolean isNew = browserTracker.isNew();
251    
252                    BrowserTrackerModelImpl browserTrackerModelImpl = (BrowserTrackerModelImpl)browserTracker;
253    
254                    Session session = null;
255    
256                    try {
257                            session = openSession();
258    
259                            BatchSessionUtil.update(session, browserTracker, merge);
260    
261                            browserTracker.setNew(false);
262                    }
263                    catch (Exception e) {
264                            throw processException(e);
265                    }
266                    finally {
267                            closeSession(session);
268                    }
269    
270                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
271    
272                    EntityCacheUtil.putResult(BrowserTrackerModelImpl.ENTITY_CACHE_ENABLED,
273                            BrowserTrackerImpl.class, browserTracker.getPrimaryKey(),
274                            browserTracker);
275    
276                    if (!isNew &&
277                                    (browserTracker.getUserId() != browserTrackerModelImpl.getOriginalUserId())) {
278                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_USERID,
279                                    new Object[] {
280                                            new Long(browserTrackerModelImpl.getOriginalUserId())
281                                    });
282                    }
283    
284                    if (isNew ||
285                                    (browserTracker.getUserId() != browserTrackerModelImpl.getOriginalUserId())) {
286                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_USERID,
287                                    new Object[] { new Long(browserTracker.getUserId()) },
288                                    browserTracker);
289                    }
290    
291                    return browserTracker;
292            }
293    
294            protected BrowserTracker toUnwrappedModel(BrowserTracker browserTracker) {
295                    if (browserTracker instanceof BrowserTrackerImpl) {
296                            return browserTracker;
297                    }
298    
299                    BrowserTrackerImpl browserTrackerImpl = new BrowserTrackerImpl();
300    
301                    browserTrackerImpl.setNew(browserTracker.isNew());
302                    browserTrackerImpl.setPrimaryKey(browserTracker.getPrimaryKey());
303    
304                    browserTrackerImpl.setBrowserTrackerId(browserTracker.getBrowserTrackerId());
305                    browserTrackerImpl.setUserId(browserTracker.getUserId());
306                    browserTrackerImpl.setBrowserKey(browserTracker.getBrowserKey());
307    
308                    return browserTrackerImpl;
309            }
310    
311            /**
312             * Finds the browser tracker with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
313             *
314             * @param primaryKey the primary key of the browser tracker to find
315             * @return the browser tracker
316             * @throws com.liferay.portal.NoSuchModelException if a browser tracker with the primary key could not be found
317             * @throws SystemException if a system exception occurred
318             */
319            public BrowserTracker findByPrimaryKey(Serializable primaryKey)
320                    throws NoSuchModelException, SystemException {
321                    return findByPrimaryKey(((Long)primaryKey).longValue());
322            }
323    
324            /**
325             * Finds the browser tracker with the primary key or throws a {@link com.liferay.portal.NoSuchBrowserTrackerException} if it could not be found.
326             *
327             * @param browserTrackerId the primary key of the browser tracker to find
328             * @return the browser tracker
329             * @throws com.liferay.portal.NoSuchBrowserTrackerException if a browser tracker with the primary key could not be found
330             * @throws SystemException if a system exception occurred
331             */
332            public BrowserTracker findByPrimaryKey(long browserTrackerId)
333                    throws NoSuchBrowserTrackerException, SystemException {
334                    BrowserTracker browserTracker = fetchByPrimaryKey(browserTrackerId);
335    
336                    if (browserTracker == null) {
337                            if (_log.isWarnEnabled()) {
338                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + browserTrackerId);
339                            }
340    
341                            throw new NoSuchBrowserTrackerException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
342                                    browserTrackerId);
343                    }
344    
345                    return browserTracker;
346            }
347    
348            /**
349             * Finds the browser tracker with the primary key or returns <code>null</code> if it could not be found.
350             *
351             * @param primaryKey the primary key of the browser tracker to find
352             * @return the browser tracker, or <code>null</code> if a browser tracker with the primary key could not be found
353             * @throws SystemException if a system exception occurred
354             */
355            public BrowserTracker fetchByPrimaryKey(Serializable primaryKey)
356                    throws SystemException {
357                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
358            }
359    
360            /**
361             * Finds the browser tracker with the primary key or returns <code>null</code> if it could not be found.
362             *
363             * @param browserTrackerId the primary key of the browser tracker to find
364             * @return the browser tracker, or <code>null</code> if a browser tracker with the primary key could not be found
365             * @throws SystemException if a system exception occurred
366             */
367            public BrowserTracker fetchByPrimaryKey(long browserTrackerId)
368                    throws SystemException {
369                    BrowserTracker browserTracker = (BrowserTracker)EntityCacheUtil.getResult(BrowserTrackerModelImpl.ENTITY_CACHE_ENABLED,
370                                    BrowserTrackerImpl.class, browserTrackerId, this);
371    
372                    if (browserTracker == null) {
373                            Session session = null;
374    
375                            try {
376                                    session = openSession();
377    
378                                    browserTracker = (BrowserTracker)session.get(BrowserTrackerImpl.class,
379                                                    new Long(browserTrackerId));
380                            }
381                            catch (Exception e) {
382                                    throw processException(e);
383                            }
384                            finally {
385                                    if (browserTracker != null) {
386                                            cacheResult(browserTracker);
387                                    }
388    
389                                    closeSession(session);
390                            }
391                    }
392    
393                    return browserTracker;
394            }
395    
396            /**
397             * Finds the browser tracker where userId = &#63; or throws a {@link com.liferay.portal.NoSuchBrowserTrackerException} if it could not be found.
398             *
399             * @param userId the user id to search with
400             * @return the matching browser tracker
401             * @throws com.liferay.portal.NoSuchBrowserTrackerException if a matching browser tracker could not be found
402             * @throws SystemException if a system exception occurred
403             */
404            public BrowserTracker findByUserId(long userId)
405                    throws NoSuchBrowserTrackerException, SystemException {
406                    BrowserTracker browserTracker = fetchByUserId(userId);
407    
408                    if (browserTracker == null) {
409                            StringBundler msg = new StringBundler(4);
410    
411                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
412    
413                            msg.append("userId=");
414                            msg.append(userId);
415    
416                            msg.append(StringPool.CLOSE_CURLY_BRACE);
417    
418                            if (_log.isWarnEnabled()) {
419                                    _log.warn(msg.toString());
420                            }
421    
422                            throw new NoSuchBrowserTrackerException(msg.toString());
423                    }
424    
425                    return browserTracker;
426            }
427    
428            /**
429             * Finds the browser tracker where userId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
430             *
431             * @param userId the user id to search with
432             * @return the matching browser tracker, or <code>null</code> if a matching browser tracker could not be found
433             * @throws SystemException if a system exception occurred
434             */
435            public BrowserTracker fetchByUserId(long userId) throws SystemException {
436                    return fetchByUserId(userId, true);
437            }
438    
439            /**
440             * Finds the browser tracker where userId = &#63; or returns <code>null</code> if it could not be found, optionally using 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, boolean retrieveFromCache)
447                    throws SystemException {
448                    Object[] finderArgs = new Object[] { userId };
449    
450                    Object result = null;
451    
452                    if (retrieveFromCache) {
453                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_USERID,
454                                            finderArgs, this);
455                    }
456    
457                    if (result == null) {
458                            StringBundler query = new StringBundler(2);
459    
460                            query.append(_SQL_SELECT_BROWSERTRACKER_WHERE);
461    
462                            query.append(_FINDER_COLUMN_USERID_USERID_2);
463    
464                            String sql = query.toString();
465    
466                            Session session = null;
467    
468                            try {
469                                    session = openSession();
470    
471                                    Query q = session.createQuery(sql);
472    
473                                    QueryPos qPos = QueryPos.getInstance(q);
474    
475                                    qPos.add(userId);
476    
477                                    List<BrowserTracker> list = q.list();
478    
479                                    result = list;
480    
481                                    BrowserTracker browserTracker = null;
482    
483                                    if (list.isEmpty()) {
484                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_USERID,
485                                                    finderArgs, list);
486                                    }
487                                    else {
488                                            browserTracker = list.get(0);
489    
490                                            cacheResult(browserTracker);
491    
492                                            if ((browserTracker.getUserId() != userId)) {
493                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_USERID,
494                                                            finderArgs, browserTracker);
495                                            }
496                                    }
497    
498                                    return browserTracker;
499                            }
500                            catch (Exception e) {
501                                    throw processException(e);
502                            }
503                            finally {
504                                    if (result == null) {
505                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_USERID,
506                                                    finderArgs);
507                                    }
508    
509                                    closeSession(session);
510                            }
511                    }
512                    else {
513                            if (result instanceof List<?>) {
514                                    return null;
515                            }
516                            else {
517                                    return (BrowserTracker)result;
518                            }
519                    }
520            }
521    
522            /**
523             * Finds all the browser trackers.
524             *
525             * @return the browser trackers
526             * @throws SystemException if a system exception occurred
527             */
528            public List<BrowserTracker> findAll() throws SystemException {
529                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
530            }
531    
532            /**
533             * Finds a range of all the browser trackers.
534             *
535             * <p>
536             * 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.
537             * </p>
538             *
539             * @param start the lower bound of the range of browser trackers to return
540             * @param end the upper bound of the range of browser trackers to return (not inclusive)
541             * @return the range of browser trackers
542             * @throws SystemException if a system exception occurred
543             */
544            public List<BrowserTracker> findAll(int start, int end)
545                    throws SystemException {
546                    return findAll(start, end, null);
547            }
548    
549            /**
550             * Finds an ordered range of all the browser trackers.
551             *
552             * <p>
553             * 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.
554             * </p>
555             *
556             * @param start the lower bound of the range of browser trackers to return
557             * @param end the upper bound of the range of browser trackers to return (not inclusive)
558             * @param orderByComparator the comparator to order the results by
559             * @return the ordered range of browser trackers
560             * @throws SystemException if a system exception occurred
561             */
562            public List<BrowserTracker> findAll(int start, int end,
563                    OrderByComparator orderByComparator) throws SystemException {
564                    Object[] finderArgs = new Object[] {
565                                    String.valueOf(start), String.valueOf(end),
566                                    String.valueOf(orderByComparator)
567                            };
568    
569                    List<BrowserTracker> list = (List<BrowserTracker>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
570                                    finderArgs, this);
571    
572                    if (list == null) {
573                            StringBundler query = null;
574                            String sql = null;
575    
576                            if (orderByComparator != null) {
577                                    query = new StringBundler(2 +
578                                                    (orderByComparator.getOrderByFields().length * 3));
579    
580                                    query.append(_SQL_SELECT_BROWSERTRACKER);
581    
582                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
583                                            orderByComparator);
584    
585                                    sql = query.toString();
586                            }
587                            else {
588                                    sql = _SQL_SELECT_BROWSERTRACKER;
589                            }
590    
591                            Session session = null;
592    
593                            try {
594                                    session = openSession();
595    
596                                    Query q = session.createQuery(sql);
597    
598                                    if (orderByComparator == null) {
599                                            list = (List<BrowserTracker>)QueryUtil.list(q,
600                                                            getDialect(), start, end, false);
601    
602                                            Collections.sort(list);
603                                    }
604                                    else {
605                                            list = (List<BrowserTracker>)QueryUtil.list(q,
606                                                            getDialect(), start, end);
607                                    }
608                            }
609                            catch (Exception e) {
610                                    throw processException(e);
611                            }
612                            finally {
613                                    if (list == null) {
614                                            FinderCacheUtil.removeResult(FINDER_PATH_FIND_ALL,
615                                                    finderArgs);
616                                    }
617                                    else {
618                                            cacheResult(list);
619    
620                                            FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs,
621                                                    list);
622                                    }
623    
624                                    closeSession(session);
625                            }
626                    }
627    
628                    return list;
629            }
630    
631            /**
632             * Removes the browser tracker where userId = &#63; from the database.
633             *
634             * @param userId the user id to search with
635             * @throws SystemException if a system exception occurred
636             */
637            public void removeByUserId(long userId)
638                    throws NoSuchBrowserTrackerException, SystemException {
639                    BrowserTracker browserTracker = findByUserId(userId);
640    
641                    remove(browserTracker);
642            }
643    
644            /**
645             * Removes all the browser trackers from the database.
646             *
647             * @throws SystemException if a system exception occurred
648             */
649            public void removeAll() throws SystemException {
650                    for (BrowserTracker browserTracker : findAll()) {
651                            remove(browserTracker);
652                    }
653            }
654    
655            /**
656             * Counts all the browser trackers where userId = &#63;.
657             *
658             * @param userId the user id to search with
659             * @return the number of matching browser trackers
660             * @throws SystemException if a system exception occurred
661             */
662            public int countByUserId(long userId) throws SystemException {
663                    Object[] finderArgs = new Object[] { userId };
664    
665                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID,
666                                    finderArgs, this);
667    
668                    if (count == null) {
669                            StringBundler query = new StringBundler(2);
670    
671                            query.append(_SQL_COUNT_BROWSERTRACKER_WHERE);
672    
673                            query.append(_FINDER_COLUMN_USERID_USERID_2);
674    
675                            String sql = query.toString();
676    
677                            Session session = null;
678    
679                            try {
680                                    session = openSession();
681    
682                                    Query q = session.createQuery(sql);
683    
684                                    QueryPos qPos = QueryPos.getInstance(q);
685    
686                                    qPos.add(userId);
687    
688                                    count = (Long)q.uniqueResult();
689                            }
690                            catch (Exception e) {
691                                    throw processException(e);
692                            }
693                            finally {
694                                    if (count == null) {
695                                            count = Long.valueOf(0);
696                                    }
697    
698                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID,
699                                            finderArgs, count);
700    
701                                    closeSession(session);
702                            }
703                    }
704    
705                    return count.intValue();
706            }
707    
708            /**
709             * Counts all the browser trackers.
710             *
711             * @return the number of browser trackers
712             * @throws SystemException if a system exception occurred
713             */
714            public int countAll() throws SystemException {
715                    Object[] finderArgs = new Object[0];
716    
717                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
718                                    finderArgs, this);
719    
720                    if (count == null) {
721                            Session session = null;
722    
723                            try {
724                                    session = openSession();
725    
726                                    Query q = session.createQuery(_SQL_COUNT_BROWSERTRACKER);
727    
728                                    count = (Long)q.uniqueResult();
729                            }
730                            catch (Exception e) {
731                                    throw processException(e);
732                            }
733                            finally {
734                                    if (count == null) {
735                                            count = Long.valueOf(0);
736                                    }
737    
738                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
739                                            count);
740    
741                                    closeSession(session);
742                            }
743                    }
744    
745                    return count.intValue();
746            }
747    
748            /**
749             * Initializes the browser tracker persistence.
750             */
751            public void afterPropertiesSet() {
752                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
753                                            com.liferay.portal.util.PropsUtil.get(
754                                                    "value.object.listener.com.liferay.portal.model.BrowserTracker")));
755    
756                    if (listenerClassNames.length > 0) {
757                            try {
758                                    List<ModelListener<BrowserTracker>> listenersList = new ArrayList<ModelListener<BrowserTracker>>();
759    
760                                    for (String listenerClassName : listenerClassNames) {
761                                            listenersList.add((ModelListener<BrowserTracker>)InstanceFactory.newInstance(
762                                                            listenerClassName));
763                                    }
764    
765                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
766                            }
767                            catch (Exception e) {
768                                    _log.error(e);
769                            }
770                    }
771            }
772    
773            public void destroy() {
774                    EntityCacheUtil.removeCache(BrowserTrackerImpl.class.getName());
775                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
776                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
777            }
778    
779            @BeanReference(type = AccountPersistence.class)
780            protected AccountPersistence accountPersistence;
781            @BeanReference(type = AddressPersistence.class)
782            protected AddressPersistence addressPersistence;
783            @BeanReference(type = BrowserTrackerPersistence.class)
784            protected BrowserTrackerPersistence browserTrackerPersistence;
785            @BeanReference(type = ClassNamePersistence.class)
786            protected ClassNamePersistence classNamePersistence;
787            @BeanReference(type = ClusterGroupPersistence.class)
788            protected ClusterGroupPersistence clusterGroupPersistence;
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    }