001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.service.persistence;
016    
017    import com.liferay.portal.NoSuchBrowserTrackerException;
018    import com.liferay.portal.NoSuchModelException;
019    import com.liferay.portal.kernel.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.getOriginalUserId()) });
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                            Session session = null;
459    
460                            try {
461                                    session = openSession();
462    
463                                    StringBundler query = new StringBundler(2);
464    
465                                    query.append(_SQL_SELECT_BROWSERTRACKER_WHERE);
466    
467                                    query.append(_FINDER_COLUMN_USERID_USERID_2);
468    
469                                    String sql = query.toString();
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.putResult(FINDER_PATH_FETCH_BY_USERID,
506                                                    finderArgs, new ArrayList<BrowserTracker>());
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                            Session session = null;
574    
575                            try {
576                                    session = openSession();
577    
578                                    StringBundler query = null;
579                                    String sql = null;
580    
581                                    if (orderByComparator != null) {
582                                            query = new StringBundler(2 +
583                                                            (orderByComparator.getOrderByFields().length * 3));
584    
585                                            query.append(_SQL_SELECT_BROWSERTRACKER);
586    
587                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
588                                                    orderByComparator);
589    
590                                            sql = query.toString();
591                                    }
592                                    else {
593                                            sql = _SQL_SELECT_BROWSERTRACKER;
594                                    }
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                                            list = new ArrayList<BrowserTracker>();
615                                    }
616    
617                                    cacheResult(list);
618    
619                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
620    
621                                    closeSession(session);
622                            }
623                    }
624    
625                    return list;
626            }
627    
628            /**
629             * Removes the browser tracker where userId = &#63; from the database.
630             *
631             * @param userId the user id to search with
632             * @throws SystemException if a system exception occurred
633             */
634            public void removeByUserId(long userId)
635                    throws NoSuchBrowserTrackerException, SystemException {
636                    BrowserTracker browserTracker = findByUserId(userId);
637    
638                    remove(browserTracker);
639            }
640    
641            /**
642             * Removes all the browser trackers from the database.
643             *
644             * @throws SystemException if a system exception occurred
645             */
646            public void removeAll() throws SystemException {
647                    for (BrowserTracker browserTracker : findAll()) {
648                            remove(browserTracker);
649                    }
650            }
651    
652            /**
653             * Counts all the browser trackers where userId = &#63;.
654             *
655             * @param userId the user id to search with
656             * @return the number of matching browser trackers
657             * @throws SystemException if a system exception occurred
658             */
659            public int countByUserId(long userId) throws SystemException {
660                    Object[] finderArgs = new Object[] { userId };
661    
662                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID,
663                                    finderArgs, this);
664    
665                    if (count == null) {
666                            Session session = null;
667    
668                            try {
669                                    session = openSession();
670    
671                                    StringBundler query = new StringBundler(2);
672    
673                                    query.append(_SQL_COUNT_BROWSERTRACKER_WHERE);
674    
675                                    query.append(_FINDER_COLUMN_USERID_USERID_2);
676    
677                                    String sql = query.toString();
678    
679                                    Query q = session.createQuery(sql);
680    
681                                    QueryPos qPos = QueryPos.getInstance(q);
682    
683                                    qPos.add(userId);
684    
685                                    count = (Long)q.uniqueResult();
686                            }
687                            catch (Exception e) {
688                                    throw processException(e);
689                            }
690                            finally {
691                                    if (count == null) {
692                                            count = Long.valueOf(0);
693                                    }
694    
695                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID,
696                                            finderArgs, count);
697    
698                                    closeSession(session);
699                            }
700                    }
701    
702                    return count.intValue();
703            }
704    
705            /**
706             * Counts all the browser trackers.
707             *
708             * @return the number of browser trackers
709             * @throws SystemException if a system exception occurred
710             */
711            public int countAll() throws SystemException {
712                    Object[] finderArgs = new Object[0];
713    
714                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
715                                    finderArgs, this);
716    
717                    if (count == null) {
718                            Session session = null;
719    
720                            try {
721                                    session = openSession();
722    
723                                    Query q = session.createQuery(_SQL_COUNT_BROWSERTRACKER);
724    
725                                    count = (Long)q.uniqueResult();
726                            }
727                            catch (Exception e) {
728                                    throw processException(e);
729                            }
730                            finally {
731                                    if (count == null) {
732                                            count = Long.valueOf(0);
733                                    }
734    
735                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
736                                            count);
737    
738                                    closeSession(session);
739                            }
740                    }
741    
742                    return count.intValue();
743            }
744    
745            /**
746             * Initializes the browser tracker persistence.
747             */
748            public void afterPropertiesSet() {
749                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
750                                            com.liferay.portal.util.PropsUtil.get(
751                                                    "value.object.listener.com.liferay.portal.model.BrowserTracker")));
752    
753                    if (listenerClassNames.length > 0) {
754                            try {
755                                    List<ModelListener<BrowserTracker>> listenersList = new ArrayList<ModelListener<BrowserTracker>>();
756    
757                                    for (String listenerClassName : listenerClassNames) {
758                                            listenersList.add((ModelListener<BrowserTracker>)InstanceFactory.newInstance(
759                                                            listenerClassName));
760                                    }
761    
762                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
763                            }
764                            catch (Exception e) {
765                                    _log.error(e);
766                            }
767                    }
768            }
769    
770            public void destroy() {
771                    EntityCacheUtil.removeCache(BrowserTrackerImpl.class.getName());
772                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
773                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
774            }
775    
776            @BeanReference(type = AccountPersistence.class)
777            protected AccountPersistence accountPersistence;
778            @BeanReference(type = AddressPersistence.class)
779            protected AddressPersistence addressPersistence;
780            @BeanReference(type = BrowserTrackerPersistence.class)
781            protected BrowserTrackerPersistence browserTrackerPersistence;
782            @BeanReference(type = ClassNamePersistence.class)
783            protected ClassNamePersistence classNamePersistence;
784            @BeanReference(type = ClusterGroupPersistence.class)
785            protected ClusterGroupPersistence clusterGroupPersistence;
786            @BeanReference(type = CompanyPersistence.class)
787            protected CompanyPersistence companyPersistence;
788            @BeanReference(type = ContactPersistence.class)
789            protected ContactPersistence contactPersistence;
790            @BeanReference(type = CountryPersistence.class)
791            protected CountryPersistence countryPersistence;
792            @BeanReference(type = EmailAddressPersistence.class)
793            protected EmailAddressPersistence emailAddressPersistence;
794            @BeanReference(type = GroupPersistence.class)
795            protected GroupPersistence groupPersistence;
796            @BeanReference(type = ImagePersistence.class)
797            protected ImagePersistence imagePersistence;
798            @BeanReference(type = LayoutPersistence.class)
799            protected LayoutPersistence layoutPersistence;
800            @BeanReference(type = LayoutPrototypePersistence.class)
801            protected LayoutPrototypePersistence layoutPrototypePersistence;
802            @BeanReference(type = LayoutSetPersistence.class)
803            protected LayoutSetPersistence layoutSetPersistence;
804            @BeanReference(type = LayoutSetPrototypePersistence.class)
805            protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
806            @BeanReference(type = ListTypePersistence.class)
807            protected ListTypePersistence listTypePersistence;
808            @BeanReference(type = LockPersistence.class)
809            protected LockPersistence lockPersistence;
810            @BeanReference(type = MembershipRequestPersistence.class)
811            protected MembershipRequestPersistence membershipRequestPersistence;
812            @BeanReference(type = OrganizationPersistence.class)
813            protected OrganizationPersistence organizationPersistence;
814            @BeanReference(type = OrgGroupPermissionPersistence.class)
815            protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
816            @BeanReference(type = OrgGroupRolePersistence.class)
817            protected OrgGroupRolePersistence orgGroupRolePersistence;
818            @BeanReference(type = OrgLaborPersistence.class)
819            protected OrgLaborPersistence orgLaborPersistence;
820            @BeanReference(type = PasswordPolicyPersistence.class)
821            protected PasswordPolicyPersistence passwordPolicyPersistence;
822            @BeanReference(type = PasswordPolicyRelPersistence.class)
823            protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
824            @BeanReference(type = PasswordTrackerPersistence.class)
825            protected PasswordTrackerPersistence passwordTrackerPersistence;
826            @BeanReference(type = PermissionPersistence.class)
827            protected PermissionPersistence permissionPersistence;
828            @BeanReference(type = PhonePersistence.class)
829            protected PhonePersistence phonePersistence;
830            @BeanReference(type = PluginSettingPersistence.class)
831            protected PluginSettingPersistence pluginSettingPersistence;
832            @BeanReference(type = PortletPersistence.class)
833            protected PortletPersistence portletPersistence;
834            @BeanReference(type = PortletItemPersistence.class)
835            protected PortletItemPersistence portletItemPersistence;
836            @BeanReference(type = PortletPreferencesPersistence.class)
837            protected PortletPreferencesPersistence portletPreferencesPersistence;
838            @BeanReference(type = RegionPersistence.class)
839            protected RegionPersistence regionPersistence;
840            @BeanReference(type = ReleasePersistence.class)
841            protected ReleasePersistence releasePersistence;
842            @BeanReference(type = ResourcePersistence.class)
843            protected ResourcePersistence resourcePersistence;
844            @BeanReference(type = ResourceActionPersistence.class)
845            protected ResourceActionPersistence resourceActionPersistence;
846            @BeanReference(type = ResourceCodePersistence.class)
847            protected ResourceCodePersistence resourceCodePersistence;
848            @BeanReference(type = ResourcePermissionPersistence.class)
849            protected ResourcePermissionPersistence resourcePermissionPersistence;
850            @BeanReference(type = RolePersistence.class)
851            protected RolePersistence rolePersistence;
852            @BeanReference(type = ServiceComponentPersistence.class)
853            protected ServiceComponentPersistence serviceComponentPersistence;
854            @BeanReference(type = ShardPersistence.class)
855            protected ShardPersistence shardPersistence;
856            @BeanReference(type = SubscriptionPersistence.class)
857            protected SubscriptionPersistence subscriptionPersistence;
858            @BeanReference(type = TicketPersistence.class)
859            protected TicketPersistence ticketPersistence;
860            @BeanReference(type = TeamPersistence.class)
861            protected TeamPersistence teamPersistence;
862            @BeanReference(type = UserPersistence.class)
863            protected UserPersistence userPersistence;
864            @BeanReference(type = UserGroupPersistence.class)
865            protected UserGroupPersistence userGroupPersistence;
866            @BeanReference(type = UserGroupGroupRolePersistence.class)
867            protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
868            @BeanReference(type = UserGroupRolePersistence.class)
869            protected UserGroupRolePersistence userGroupRolePersistence;
870            @BeanReference(type = UserIdMapperPersistence.class)
871            protected UserIdMapperPersistence userIdMapperPersistence;
872            @BeanReference(type = UserTrackerPersistence.class)
873            protected UserTrackerPersistence userTrackerPersistence;
874            @BeanReference(type = UserTrackerPathPersistence.class)
875            protected UserTrackerPathPersistence userTrackerPathPersistence;
876            @BeanReference(type = WebDAVPropsPersistence.class)
877            protected WebDAVPropsPersistence webDAVPropsPersistence;
878            @BeanReference(type = WebsitePersistence.class)
879            protected WebsitePersistence websitePersistence;
880            @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
881            protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
882            @BeanReference(type = WorkflowInstanceLinkPersistence.class)
883            protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
884            private static final String _SQL_SELECT_BROWSERTRACKER = "SELECT browserTracker FROM BrowserTracker browserTracker";
885            private static final String _SQL_SELECT_BROWSERTRACKER_WHERE = "SELECT browserTracker FROM BrowserTracker browserTracker WHERE ";
886            private static final String _SQL_COUNT_BROWSERTRACKER = "SELECT COUNT(browserTracker) FROM BrowserTracker browserTracker";
887            private static final String _SQL_COUNT_BROWSERTRACKER_WHERE = "SELECT COUNT(browserTracker) FROM BrowserTracker browserTracker WHERE ";
888            private static final String _FINDER_COLUMN_USERID_USERID_2 = "browserTracker.userId = ?";
889            private static final String _ORDER_BY_ENTITY_ALIAS = "browserTracker.";
890            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No BrowserTracker exists with the primary key ";
891            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No BrowserTracker exists with the key {";
892            private static Log _log = LogFactoryUtil.getLog(BrowserTrackerPersistenceImpl.class);
893    }