001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.service.persistence;
016    
017    import com.liferay.portal.NoSuchBrowserTrackerException;
018    import com.liferay.portal.NoSuchModelException;
019    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderPath;
023    import com.liferay.portal.kernel.dao.orm.Query;
024    import com.liferay.portal.kernel.dao.orm.QueryPos;
025    import com.liferay.portal.kernel.dao.orm.QueryUtil;
026    import com.liferay.portal.kernel.dao.orm.Session;
027    import com.liferay.portal.kernel.exception.SystemException;
028    import com.liferay.portal.kernel.log.Log;
029    import com.liferay.portal.kernel.log.LogFactoryUtil;
030    import com.liferay.portal.kernel.util.GetterUtil;
031    import com.liferay.portal.kernel.util.InstanceFactory;
032    import com.liferay.portal.kernel.util.OrderByComparator;
033    import com.liferay.portal.kernel.util.StringBundler;
034    import com.liferay.portal.kernel.util.StringPool;
035    import com.liferay.portal.kernel.util.StringUtil;
036    import com.liferay.portal.kernel.util.UnmodifiableList;
037    import com.liferay.portal.model.BrowserTracker;
038    import com.liferay.portal.model.CacheModel;
039    import com.liferay.portal.model.ModelListener;
040    import com.liferay.portal.model.impl.BrowserTrackerImpl;
041    import com.liferay.portal.model.impl.BrowserTrackerModelImpl;
042    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
043    
044    import java.io.Serializable;
045    
046    import java.util.ArrayList;
047    import java.util.Collections;
048    import java.util.List;
049    
050    /**
051     * The persistence implementation for the browser tracker service.
052     *
053     * <p>
054     * Caching information and settings can be found in <code>portal.properties</code>
055     * </p>
056     *
057     * @author Brian Wing Shun Chan
058     * @see BrowserTrackerPersistence
059     * @see BrowserTrackerUtil
060     * @generated
061     */
062    public class BrowserTrackerPersistenceImpl extends BasePersistenceImpl<BrowserTracker>
063            implements BrowserTrackerPersistence {
064            /*
065             * NOTE FOR DEVELOPERS:
066             *
067             * Never modify or reference this class directly. Always use {@link BrowserTrackerUtil} to access the browser tracker persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
068             */
069            public static final String FINDER_CLASS_NAME_ENTITY = BrowserTrackerImpl.class.getName();
070            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
071                    ".List1";
072            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
073                    ".List2";
074            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(BrowserTrackerModelImpl.ENTITY_CACHE_ENABLED,
075                            BrowserTrackerModelImpl.FINDER_CACHE_ENABLED,
076                            BrowserTrackerImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
077                            "findAll", new String[0]);
078            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(BrowserTrackerModelImpl.ENTITY_CACHE_ENABLED,
079                            BrowserTrackerModelImpl.FINDER_CACHE_ENABLED,
080                            BrowserTrackerImpl.class,
081                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
082            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(BrowserTrackerModelImpl.ENTITY_CACHE_ENABLED,
083                            BrowserTrackerModelImpl.FINDER_CACHE_ENABLED, Long.class,
084                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
085            public static final FinderPath FINDER_PATH_FETCH_BY_USERID = new FinderPath(BrowserTrackerModelImpl.ENTITY_CACHE_ENABLED,
086                            BrowserTrackerModelImpl.FINDER_CACHE_ENABLED,
087                            BrowserTrackerImpl.class, FINDER_CLASS_NAME_ENTITY,
088                            "fetchByUserId", new String[] { Long.class.getName() },
089                            BrowserTrackerModelImpl.USERID_COLUMN_BITMASK);
090            public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(BrowserTrackerModelImpl.ENTITY_CACHE_ENABLED,
091                            BrowserTrackerModelImpl.FINDER_CACHE_ENABLED, Long.class,
092                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId",
093                            new String[] { Long.class.getName() });
094    
095            /**
096             * Returns the browser tracker where userId = &#63; or throws a {@link com.liferay.portal.NoSuchBrowserTrackerException} if it could not be found.
097             *
098             * @param userId the user ID
099             * @return the matching browser tracker
100             * @throws com.liferay.portal.NoSuchBrowserTrackerException if a matching browser tracker could not be found
101             * @throws SystemException if a system exception occurred
102             */
103            public BrowserTracker findByUserId(long userId)
104                    throws NoSuchBrowserTrackerException, SystemException {
105                    BrowserTracker browserTracker = fetchByUserId(userId);
106    
107                    if (browserTracker == null) {
108                            StringBundler msg = new StringBundler(4);
109    
110                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
111    
112                            msg.append("userId=");
113                            msg.append(userId);
114    
115                            msg.append(StringPool.CLOSE_CURLY_BRACE);
116    
117                            if (_log.isWarnEnabled()) {
118                                    _log.warn(msg.toString());
119                            }
120    
121                            throw new NoSuchBrowserTrackerException(msg.toString());
122                    }
123    
124                    return browserTracker;
125            }
126    
127            /**
128             * Returns the browser tracker where userId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
129             *
130             * @param userId the user ID
131             * @return the matching browser tracker, or <code>null</code> if a matching browser tracker could not be found
132             * @throws SystemException if a system exception occurred
133             */
134            public BrowserTracker fetchByUserId(long userId) throws SystemException {
135                    return fetchByUserId(userId, true);
136            }
137    
138            /**
139             * Returns the browser tracker where userId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
140             *
141             * @param userId the user ID
142             * @param retrieveFromCache whether to use the finder cache
143             * @return the matching browser tracker, or <code>null</code> if a matching browser tracker could not be found
144             * @throws SystemException if a system exception occurred
145             */
146            public BrowserTracker fetchByUserId(long userId, boolean retrieveFromCache)
147                    throws SystemException {
148                    Object[] finderArgs = new Object[] { userId };
149    
150                    Object result = null;
151    
152                    if (retrieveFromCache) {
153                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_USERID,
154                                            finderArgs, this);
155                    }
156    
157                    if (result instanceof BrowserTracker) {
158                            BrowserTracker browserTracker = (BrowserTracker)result;
159    
160                            if ((userId != browserTracker.getUserId())) {
161                                    result = null;
162                            }
163                    }
164    
165                    if (result == null) {
166                            StringBundler query = new StringBundler(3);
167    
168                            query.append(_SQL_SELECT_BROWSERTRACKER_WHERE);
169    
170                            query.append(_FINDER_COLUMN_USERID_USERID_2);
171    
172                            String sql = query.toString();
173    
174                            Session session = null;
175    
176                            try {
177                                    session = openSession();
178    
179                                    Query q = session.createQuery(sql);
180    
181                                    QueryPos qPos = QueryPos.getInstance(q);
182    
183                                    qPos.add(userId);
184    
185                                    List<BrowserTracker> list = q.list();
186    
187                                    if (list.isEmpty()) {
188                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_USERID,
189                                                    finderArgs, list);
190                                    }
191                                    else {
192                                            BrowserTracker browserTracker = list.get(0);
193    
194                                            result = browserTracker;
195    
196                                            cacheResult(browserTracker);
197    
198                                            if ((browserTracker.getUserId() != userId)) {
199                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_USERID,
200                                                            finderArgs, browserTracker);
201                                            }
202                                    }
203                            }
204                            catch (Exception e) {
205                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_USERID,
206                                            finderArgs);
207    
208                                    throw processException(e);
209                            }
210                            finally {
211                                    closeSession(session);
212                            }
213                    }
214    
215                    if (result instanceof List<?>) {
216                            return null;
217                    }
218                    else {
219                            return (BrowserTracker)result;
220                    }
221            }
222    
223            /**
224             * Removes the browser tracker where userId = &#63; from the database.
225             *
226             * @param userId the user ID
227             * @return the browser tracker that was removed
228             * @throws SystemException if a system exception occurred
229             */
230            public BrowserTracker removeByUserId(long userId)
231                    throws NoSuchBrowserTrackerException, SystemException {
232                    BrowserTracker browserTracker = findByUserId(userId);
233    
234                    return remove(browserTracker);
235            }
236    
237            /**
238             * Returns the number of browser trackers where userId = &#63;.
239             *
240             * @param userId the user ID
241             * @return the number of matching browser trackers
242             * @throws SystemException if a system exception occurred
243             */
244            public int countByUserId(long userId) throws SystemException {
245                    FinderPath finderPath = FINDER_PATH_COUNT_BY_USERID;
246    
247                    Object[] finderArgs = new Object[] { userId };
248    
249                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
250                                    this);
251    
252                    if (count == null) {
253                            StringBundler query = new StringBundler(2);
254    
255                            query.append(_SQL_COUNT_BROWSERTRACKER_WHERE);
256    
257                            query.append(_FINDER_COLUMN_USERID_USERID_2);
258    
259                            String sql = query.toString();
260    
261                            Session session = null;
262    
263                            try {
264                                    session = openSession();
265    
266                                    Query q = session.createQuery(sql);
267    
268                                    QueryPos qPos = QueryPos.getInstance(q);
269    
270                                    qPos.add(userId);
271    
272                                    count = (Long)q.uniqueResult();
273    
274                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
275                            }
276                            catch (Exception e) {
277                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
278    
279                                    throw processException(e);
280                            }
281                            finally {
282                                    closeSession(session);
283                            }
284                    }
285    
286                    return count.intValue();
287            }
288    
289            private static final String _FINDER_COLUMN_USERID_USERID_2 = "browserTracker.userId = ?";
290    
291            /**
292             * Caches the browser tracker in the entity cache if it is enabled.
293             *
294             * @param browserTracker the browser tracker
295             */
296            public void cacheResult(BrowserTracker browserTracker) {
297                    EntityCacheUtil.putResult(BrowserTrackerModelImpl.ENTITY_CACHE_ENABLED,
298                            BrowserTrackerImpl.class, browserTracker.getPrimaryKey(),
299                            browserTracker);
300    
301                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_USERID,
302                            new Object[] { Long.valueOf(browserTracker.getUserId()) },
303                            browserTracker);
304    
305                    browserTracker.resetOriginalValues();
306            }
307    
308            /**
309             * Caches the browser trackers in the entity cache if it is enabled.
310             *
311             * @param browserTrackers the browser trackers
312             */
313            public void cacheResult(List<BrowserTracker> browserTrackers) {
314                    for (BrowserTracker browserTracker : browserTrackers) {
315                            if (EntityCacheUtil.getResult(
316                                                    BrowserTrackerModelImpl.ENTITY_CACHE_ENABLED,
317                                                    BrowserTrackerImpl.class, browserTracker.getPrimaryKey()) == null) {
318                                    cacheResult(browserTracker);
319                            }
320                            else {
321                                    browserTracker.resetOriginalValues();
322                            }
323                    }
324            }
325    
326            /**
327             * Clears the cache for all browser trackers.
328             *
329             * <p>
330             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
331             * </p>
332             */
333            @Override
334            public void clearCache() {
335                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
336                            CacheRegistryUtil.clear(BrowserTrackerImpl.class.getName());
337                    }
338    
339                    EntityCacheUtil.clearCache(BrowserTrackerImpl.class.getName());
340    
341                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
342                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
343                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
344            }
345    
346            /**
347             * Clears the cache for the browser tracker.
348             *
349             * <p>
350             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
351             * </p>
352             */
353            @Override
354            public void clearCache(BrowserTracker browserTracker) {
355                    EntityCacheUtil.removeResult(BrowserTrackerModelImpl.ENTITY_CACHE_ENABLED,
356                            BrowserTrackerImpl.class, browserTracker.getPrimaryKey());
357    
358                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
359                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
360    
361                    clearUniqueFindersCache(browserTracker);
362            }
363    
364            @Override
365            public void clearCache(List<BrowserTracker> browserTrackers) {
366                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
367                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
368    
369                    for (BrowserTracker browserTracker : browserTrackers) {
370                            EntityCacheUtil.removeResult(BrowserTrackerModelImpl.ENTITY_CACHE_ENABLED,
371                                    BrowserTrackerImpl.class, browserTracker.getPrimaryKey());
372    
373                            clearUniqueFindersCache(browserTracker);
374                    }
375            }
376    
377            protected void cacheUniqueFindersCache(BrowserTracker browserTracker) {
378                    if (browserTracker.isNew()) {
379                            Object[] args = new Object[] {
380                                            Long.valueOf(browserTracker.getUserId())
381                                    };
382    
383                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID, args,
384                                    Long.valueOf(1));
385                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_USERID, args,
386                                    browserTracker);
387                    }
388                    else {
389                            BrowserTrackerModelImpl browserTrackerModelImpl = (BrowserTrackerModelImpl)browserTracker;
390    
391                            if ((browserTrackerModelImpl.getColumnBitmask() &
392                                            FINDER_PATH_FETCH_BY_USERID.getColumnBitmask()) != 0) {
393                                    Object[] args = new Object[] {
394                                                    Long.valueOf(browserTracker.getUserId())
395                                            };
396    
397                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID, args,
398                                            Long.valueOf(1));
399                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_USERID, args,
400                                            browserTracker);
401                            }
402                    }
403            }
404    
405            protected void clearUniqueFindersCache(BrowserTracker browserTracker) {
406                    BrowserTrackerModelImpl browserTrackerModelImpl = (BrowserTrackerModelImpl)browserTracker;
407    
408                    Object[] args = new Object[] { Long.valueOf(browserTracker.getUserId()) };
409    
410                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
411                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_USERID, args);
412    
413                    if ((browserTrackerModelImpl.getColumnBitmask() &
414                                    FINDER_PATH_FETCH_BY_USERID.getColumnBitmask()) != 0) {
415                            args = new Object[] {
416                                            Long.valueOf(browserTrackerModelImpl.getOriginalUserId())
417                                    };
418    
419                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
420                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_USERID, args);
421                    }
422            }
423    
424            /**
425             * Creates a new browser tracker with the primary key. Does not add the browser tracker to the database.
426             *
427             * @param browserTrackerId the primary key for the new browser tracker
428             * @return the new browser tracker
429             */
430            public BrowserTracker create(long browserTrackerId) {
431                    BrowserTracker browserTracker = new BrowserTrackerImpl();
432    
433                    browserTracker.setNew(true);
434                    browserTracker.setPrimaryKey(browserTrackerId);
435    
436                    return browserTracker;
437            }
438    
439            /**
440             * Removes the browser tracker with the primary key from the database. Also notifies the appropriate model listeners.
441             *
442             * @param browserTrackerId the primary key of the browser tracker
443             * @return the browser tracker that was removed
444             * @throws com.liferay.portal.NoSuchBrowserTrackerException if a browser tracker with the primary key could not be found
445             * @throws SystemException if a system exception occurred
446             */
447            public BrowserTracker remove(long browserTrackerId)
448                    throws NoSuchBrowserTrackerException, SystemException {
449                    return remove(Long.valueOf(browserTrackerId));
450            }
451    
452            /**
453             * Removes the browser tracker with the primary key from the database. Also notifies the appropriate model listeners.
454             *
455             * @param primaryKey the primary key of the browser tracker
456             * @return the browser tracker that was removed
457             * @throws com.liferay.portal.NoSuchBrowserTrackerException if a browser tracker with the primary key could not be found
458             * @throws SystemException if a system exception occurred
459             */
460            @Override
461            public BrowserTracker remove(Serializable primaryKey)
462                    throws NoSuchBrowserTrackerException, SystemException {
463                    Session session = null;
464    
465                    try {
466                            session = openSession();
467    
468                            BrowserTracker browserTracker = (BrowserTracker)session.get(BrowserTrackerImpl.class,
469                                            primaryKey);
470    
471                            if (browserTracker == null) {
472                                    if (_log.isWarnEnabled()) {
473                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
474                                    }
475    
476                                    throw new NoSuchBrowserTrackerException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
477                                            primaryKey);
478                            }
479    
480                            return remove(browserTracker);
481                    }
482                    catch (NoSuchBrowserTrackerException nsee) {
483                            throw nsee;
484                    }
485                    catch (Exception e) {
486                            throw processException(e);
487                    }
488                    finally {
489                            closeSession(session);
490                    }
491            }
492    
493            @Override
494            protected BrowserTracker removeImpl(BrowserTracker browserTracker)
495                    throws SystemException {
496                    browserTracker = toUnwrappedModel(browserTracker);
497    
498                    Session session = null;
499    
500                    try {
501                            session = openSession();
502    
503                            if (!session.contains(browserTracker)) {
504                                    browserTracker = (BrowserTracker)session.get(BrowserTrackerImpl.class,
505                                                    browserTracker.getPrimaryKeyObj());
506                            }
507    
508                            if (browserTracker != null) {
509                                    session.delete(browserTracker);
510                            }
511                    }
512                    catch (Exception e) {
513                            throw processException(e);
514                    }
515                    finally {
516                            closeSession(session);
517                    }
518    
519                    if (browserTracker != null) {
520                            clearCache(browserTracker);
521                    }
522    
523                    return browserTracker;
524            }
525    
526            @Override
527            public BrowserTracker updateImpl(
528                    com.liferay.portal.model.BrowserTracker browserTracker)
529                    throws SystemException {
530                    browserTracker = toUnwrappedModel(browserTracker);
531    
532                    boolean isNew = browserTracker.isNew();
533    
534                    Session session = null;
535    
536                    try {
537                            session = openSession();
538    
539                            if (browserTracker.isNew()) {
540                                    session.save(browserTracker);
541    
542                                    browserTracker.setNew(false);
543                            }
544                            else {
545                                    session.merge(browserTracker);
546                            }
547                    }
548                    catch (Exception e) {
549                            throw processException(e);
550                    }
551                    finally {
552                            closeSession(session);
553                    }
554    
555                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
556    
557                    if (isNew || !BrowserTrackerModelImpl.COLUMN_BITMASK_ENABLED) {
558                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
559                    }
560    
561                    EntityCacheUtil.putResult(BrowserTrackerModelImpl.ENTITY_CACHE_ENABLED,
562                            BrowserTrackerImpl.class, browserTracker.getPrimaryKey(),
563                            browserTracker);
564    
565                    clearUniqueFindersCache(browserTracker);
566                    cacheUniqueFindersCache(browserTracker);
567    
568                    return browserTracker;
569            }
570    
571            protected BrowserTracker toUnwrappedModel(BrowserTracker browserTracker) {
572                    if (browserTracker instanceof BrowserTrackerImpl) {
573                            return browserTracker;
574                    }
575    
576                    BrowserTrackerImpl browserTrackerImpl = new BrowserTrackerImpl();
577    
578                    browserTrackerImpl.setNew(browserTracker.isNew());
579                    browserTrackerImpl.setPrimaryKey(browserTracker.getPrimaryKey());
580    
581                    browserTrackerImpl.setBrowserTrackerId(browserTracker.getBrowserTrackerId());
582                    browserTrackerImpl.setUserId(browserTracker.getUserId());
583                    browserTrackerImpl.setBrowserKey(browserTracker.getBrowserKey());
584    
585                    return browserTrackerImpl;
586            }
587    
588            /**
589             * Returns the browser tracker with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
590             *
591             * @param primaryKey the primary key of the browser tracker
592             * @return the browser tracker
593             * @throws com.liferay.portal.NoSuchModelException if a browser tracker with the primary key could not be found
594             * @throws SystemException if a system exception occurred
595             */
596            @Override
597            public BrowserTracker findByPrimaryKey(Serializable primaryKey)
598                    throws NoSuchModelException, SystemException {
599                    return findByPrimaryKey(((Long)primaryKey).longValue());
600            }
601    
602            /**
603             * Returns the browser tracker with the primary key or throws a {@link com.liferay.portal.NoSuchBrowserTrackerException} if it could not be found.
604             *
605             * @param browserTrackerId the primary key of the browser tracker
606             * @return the browser tracker
607             * @throws com.liferay.portal.NoSuchBrowserTrackerException if a browser tracker with the primary key could not be found
608             * @throws SystemException if a system exception occurred
609             */
610            public BrowserTracker findByPrimaryKey(long browserTrackerId)
611                    throws NoSuchBrowserTrackerException, SystemException {
612                    BrowserTracker browserTracker = fetchByPrimaryKey(browserTrackerId);
613    
614                    if (browserTracker == null) {
615                            if (_log.isWarnEnabled()) {
616                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + browserTrackerId);
617                            }
618    
619                            throw new NoSuchBrowserTrackerException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
620                                    browserTrackerId);
621                    }
622    
623                    return browserTracker;
624            }
625    
626            /**
627             * Returns the browser tracker with the primary key or returns <code>null</code> if it could not be found.
628             *
629             * @param primaryKey the primary key of the browser tracker
630             * @return the browser tracker, or <code>null</code> if a browser tracker with the primary key could not be found
631             * @throws SystemException if a system exception occurred
632             */
633            @Override
634            public BrowserTracker fetchByPrimaryKey(Serializable primaryKey)
635                    throws SystemException {
636                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
637            }
638    
639            /**
640             * Returns the browser tracker with the primary key or returns <code>null</code> if it could not be found.
641             *
642             * @param browserTrackerId the primary key of the browser tracker
643             * @return the browser tracker, or <code>null</code> if a browser tracker with the primary key could not be found
644             * @throws SystemException if a system exception occurred
645             */
646            public BrowserTracker fetchByPrimaryKey(long browserTrackerId)
647                    throws SystemException {
648                    BrowserTracker browserTracker = (BrowserTracker)EntityCacheUtil.getResult(BrowserTrackerModelImpl.ENTITY_CACHE_ENABLED,
649                                    BrowserTrackerImpl.class, browserTrackerId);
650    
651                    if (browserTracker == _nullBrowserTracker) {
652                            return null;
653                    }
654    
655                    if (browserTracker == null) {
656                            Session session = null;
657    
658                            try {
659                                    session = openSession();
660    
661                                    browserTracker = (BrowserTracker)session.get(BrowserTrackerImpl.class,
662                                                    Long.valueOf(browserTrackerId));
663    
664                                    if (browserTracker != null) {
665                                            cacheResult(browserTracker);
666                                    }
667                                    else {
668                                            EntityCacheUtil.putResult(BrowserTrackerModelImpl.ENTITY_CACHE_ENABLED,
669                                                    BrowserTrackerImpl.class, browserTrackerId,
670                                                    _nullBrowserTracker);
671                                    }
672                            }
673                            catch (Exception e) {
674                                    EntityCacheUtil.removeResult(BrowserTrackerModelImpl.ENTITY_CACHE_ENABLED,
675                                            BrowserTrackerImpl.class, browserTrackerId);
676    
677                                    throw processException(e);
678                            }
679                            finally {
680                                    closeSession(session);
681                            }
682                    }
683    
684                    return browserTracker;
685            }
686    
687            /**
688             * Returns all the browser trackers.
689             *
690             * @return the browser trackers
691             * @throws SystemException if a system exception occurred
692             */
693            public List<BrowserTracker> findAll() throws SystemException {
694                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
695            }
696    
697            /**
698             * Returns a range of all the browser trackers.
699             *
700             * <p>
701             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.BrowserTrackerModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
702             * </p>
703             *
704             * @param start the lower bound of the range of browser trackers
705             * @param end the upper bound of the range of browser trackers (not inclusive)
706             * @return the range of browser trackers
707             * @throws SystemException if a system exception occurred
708             */
709            public List<BrowserTracker> findAll(int start, int end)
710                    throws SystemException {
711                    return findAll(start, end, null);
712            }
713    
714            /**
715             * Returns an ordered range of all the browser trackers.
716             *
717             * <p>
718             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.BrowserTrackerModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
719             * </p>
720             *
721             * @param start the lower bound of the range of browser trackers
722             * @param end the upper bound of the range of browser trackers (not inclusive)
723             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
724             * @return the ordered range of browser trackers
725             * @throws SystemException if a system exception occurred
726             */
727            public List<BrowserTracker> findAll(int start, int end,
728                    OrderByComparator orderByComparator) throws SystemException {
729                    boolean pagination = true;
730                    FinderPath finderPath = null;
731                    Object[] finderArgs = null;
732    
733                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
734                                    (orderByComparator == null)) {
735                            pagination = false;
736                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
737                            finderArgs = FINDER_ARGS_EMPTY;
738                    }
739                    else {
740                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
741                            finderArgs = new Object[] { start, end, orderByComparator };
742                    }
743    
744                    List<BrowserTracker> list = (List<BrowserTracker>)FinderCacheUtil.getResult(finderPath,
745                                    finderArgs, this);
746    
747                    if (list == null) {
748                            StringBundler query = null;
749                            String sql = null;
750    
751                            if (orderByComparator != null) {
752                                    query = new StringBundler(2 +
753                                                    (orderByComparator.getOrderByFields().length * 3));
754    
755                                    query.append(_SQL_SELECT_BROWSERTRACKER);
756    
757                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
758                                            orderByComparator);
759    
760                                    sql = query.toString();
761                            }
762                            else {
763                                    sql = _SQL_SELECT_BROWSERTRACKER;
764    
765                                    if (pagination) {
766                                            sql = sql.concat(BrowserTrackerModelImpl.ORDER_BY_JPQL);
767                                    }
768                            }
769    
770                            Session session = null;
771    
772                            try {
773                                    session = openSession();
774    
775                                    Query q = session.createQuery(sql);
776    
777                                    if (!pagination) {
778                                            list = (List<BrowserTracker>)QueryUtil.list(q,
779                                                            getDialect(), start, end, false);
780    
781                                            Collections.sort(list);
782    
783                                            list = new UnmodifiableList<BrowserTracker>(list);
784                                    }
785                                    else {
786                                            list = (List<BrowserTracker>)QueryUtil.list(q,
787                                                            getDialect(), start, end);
788                                    }
789    
790                                    cacheResult(list);
791    
792                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
793                            }
794                            catch (Exception e) {
795                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
796    
797                                    throw processException(e);
798                            }
799                            finally {
800                                    closeSession(session);
801                            }
802                    }
803    
804                    return list;
805            }
806    
807            /**
808             * Removes all the browser trackers from the database.
809             *
810             * @throws SystemException if a system exception occurred
811             */
812            public void removeAll() throws SystemException {
813                    for (BrowserTracker browserTracker : findAll()) {
814                            remove(browserTracker);
815                    }
816            }
817    
818            /**
819             * Returns the number of browser trackers.
820             *
821             * @return the number of browser trackers
822             * @throws SystemException if a system exception occurred
823             */
824            public int countAll() throws SystemException {
825                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
826                                    FINDER_ARGS_EMPTY, this);
827    
828                    if (count == null) {
829                            Session session = null;
830    
831                            try {
832                                    session = openSession();
833    
834                                    Query q = session.createQuery(_SQL_COUNT_BROWSERTRACKER);
835    
836                                    count = (Long)q.uniqueResult();
837    
838                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
839                                            FINDER_ARGS_EMPTY, count);
840                            }
841                            catch (Exception e) {
842                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
843                                            FINDER_ARGS_EMPTY);
844    
845                                    throw processException(e);
846                            }
847                            finally {
848                                    closeSession(session);
849                            }
850                    }
851    
852                    return count.intValue();
853            }
854    
855            /**
856             * Initializes the browser tracker persistence.
857             */
858            public void afterPropertiesSet() {
859                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
860                                            com.liferay.portal.util.PropsUtil.get(
861                                                    "value.object.listener.com.liferay.portal.model.BrowserTracker")));
862    
863                    if (listenerClassNames.length > 0) {
864                            try {
865                                    List<ModelListener<BrowserTracker>> listenersList = new ArrayList<ModelListener<BrowserTracker>>();
866    
867                                    for (String listenerClassName : listenerClassNames) {
868                                            listenersList.add((ModelListener<BrowserTracker>)InstanceFactory.newInstance(
869                                                            listenerClassName));
870                                    }
871    
872                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
873                            }
874                            catch (Exception e) {
875                                    _log.error(e);
876                            }
877                    }
878            }
879    
880            public void destroy() {
881                    EntityCacheUtil.removeCache(BrowserTrackerImpl.class.getName());
882                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
883                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
884                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
885            }
886    
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 _ORDER_BY_ENTITY_ALIAS = "browserTracker.";
892            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No BrowserTracker exists with the primary key ";
893            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No BrowserTracker exists with the key {";
894            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
895            private static Log _log = LogFactoryUtil.getLog(BrowserTrackerPersistenceImpl.class);
896            private static BrowserTracker _nullBrowserTracker = new BrowserTrackerImpl() {
897                            @Override
898                            public Object clone() {
899                                    return this;
900                            }
901    
902                            @Override
903                            public CacheModel<BrowserTracker> toCacheModel() {
904                                    return _nullBrowserTrackerCacheModel;
905                            }
906                    };
907    
908            private static CacheModel<BrowserTracker> _nullBrowserTrackerCacheModel = new CacheModel<BrowserTracker>() {
909                            public BrowserTracker toEntityModel() {
910                                    return _nullBrowserTracker;
911                            }
912                    };
913    }