001    /**
002     * Copyright (c) 2000-present 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.impl;
016    
017    import aQute.bnd.annotation.ProviderType;
018    
019    import com.liferay.portal.NoSuchBrowserTrackerException;
020    import com.liferay.portal.kernel.bean.BeanReference;
021    import com.liferay.portal.kernel.dao.orm.EntityCache;
022    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
023    import com.liferay.portal.kernel.dao.orm.FinderCache;
024    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
025    import com.liferay.portal.kernel.dao.orm.FinderPath;
026    import com.liferay.portal.kernel.dao.orm.Query;
027    import com.liferay.portal.kernel.dao.orm.QueryPos;
028    import com.liferay.portal.kernel.dao.orm.QueryUtil;
029    import com.liferay.portal.kernel.dao.orm.Session;
030    import com.liferay.portal.kernel.log.Log;
031    import com.liferay.portal.kernel.log.LogFactoryUtil;
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.model.BrowserTracker;
036    import com.liferay.portal.model.CacheModel;
037    import com.liferay.portal.model.MVCCModel;
038    import com.liferay.portal.model.impl.BrowserTrackerImpl;
039    import com.liferay.portal.model.impl.BrowserTrackerModelImpl;
040    import com.liferay.portal.service.persistence.BrowserTrackerPersistence;
041    import com.liferay.portal.service.persistence.CompanyProvider;
042    
043    import java.io.Serializable;
044    
045    import java.util.Collections;
046    import java.util.HashMap;
047    import java.util.HashSet;
048    import java.util.Iterator;
049    import java.util.List;
050    import java.util.Map;
051    import java.util.Set;
052    
053    /**
054     * The persistence implementation for the browser tracker service.
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 com.liferay.portal.service.persistence.BrowserTrackerUtil
063     * @generated
064     */
065    @ProviderType
066    public class BrowserTrackerPersistenceImpl extends BasePersistenceImpl<BrowserTracker>
067            implements BrowserTrackerPersistence {
068            /*
069             * NOTE FOR DEVELOPERS:
070             *
071             * 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.
072             */
073            public static final String FINDER_CLASS_NAME_ENTITY = BrowserTrackerImpl.class.getName();
074            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
075                    ".List1";
076            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
077                    ".List2";
078            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(BrowserTrackerModelImpl.ENTITY_CACHE_ENABLED,
079                            BrowserTrackerModelImpl.FINDER_CACHE_ENABLED,
080                            BrowserTrackerImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
081                            "findAll", new String[0]);
082            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(BrowserTrackerModelImpl.ENTITY_CACHE_ENABLED,
083                            BrowserTrackerModelImpl.FINDER_CACHE_ENABLED,
084                            BrowserTrackerImpl.class,
085                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
086            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(BrowserTrackerModelImpl.ENTITY_CACHE_ENABLED,
087                            BrowserTrackerModelImpl.FINDER_CACHE_ENABLED, Long.class,
088                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
089            public static final FinderPath FINDER_PATH_FETCH_BY_USERID = new FinderPath(BrowserTrackerModelImpl.ENTITY_CACHE_ENABLED,
090                            BrowserTrackerModelImpl.FINDER_CACHE_ENABLED,
091                            BrowserTrackerImpl.class, FINDER_CLASS_NAME_ENTITY,
092                            "fetchByUserId", new String[] { Long.class.getName() },
093                            BrowserTrackerModelImpl.USERID_COLUMN_BITMASK);
094            public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(BrowserTrackerModelImpl.ENTITY_CACHE_ENABLED,
095                            BrowserTrackerModelImpl.FINDER_CACHE_ENABLED, Long.class,
096                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId",
097                            new String[] { Long.class.getName() });
098    
099            /**
100             * Returns the browser tracker where userId = &#63; or throws a {@link NoSuchBrowserTrackerException} if it could not be found.
101             *
102             * @param userId the user ID
103             * @return the matching browser tracker
104             * @throws NoSuchBrowserTrackerException if a matching browser tracker could not be found
105             */
106            @Override
107            public BrowserTracker findByUserId(long userId)
108                    throws NoSuchBrowserTrackerException {
109                    BrowserTracker browserTracker = fetchByUserId(userId);
110    
111                    if (browserTracker == null) {
112                            StringBundler msg = new StringBundler(4);
113    
114                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
115    
116                            msg.append("userId=");
117                            msg.append(userId);
118    
119                            msg.append(StringPool.CLOSE_CURLY_BRACE);
120    
121                            if (_log.isWarnEnabled()) {
122                                    _log.warn(msg.toString());
123                            }
124    
125                            throw new NoSuchBrowserTrackerException(msg.toString());
126                    }
127    
128                    return browserTracker;
129            }
130    
131            /**
132             * Returns the browser tracker where userId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
133             *
134             * @param userId the user ID
135             * @return the matching browser tracker, or <code>null</code> if a matching browser tracker could not be found
136             */
137            @Override
138            public BrowserTracker fetchByUserId(long userId) {
139                    return fetchByUserId(userId, true);
140            }
141    
142            /**
143             * Returns the browser tracker where userId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
144             *
145             * @param userId the user ID
146             * @param retrieveFromCache whether to retrieve from the finder cache
147             * @return the matching browser tracker, or <code>null</code> if a matching browser tracker could not be found
148             */
149            @Override
150            public BrowserTracker fetchByUserId(long userId, boolean retrieveFromCache) {
151                    Object[] finderArgs = new Object[] { userId };
152    
153                    Object result = null;
154    
155                    if (retrieveFromCache) {
156                            result = finderCache.getResult(FINDER_PATH_FETCH_BY_USERID,
157                                            finderArgs, this);
158                    }
159    
160                    if (result instanceof BrowserTracker) {
161                            BrowserTracker browserTracker = (BrowserTracker)result;
162    
163                            if ((userId != browserTracker.getUserId())) {
164                                    result = null;
165                            }
166                    }
167    
168                    if (result == null) {
169                            StringBundler query = new StringBundler(3);
170    
171                            query.append(_SQL_SELECT_BROWSERTRACKER_WHERE);
172    
173                            query.append(_FINDER_COLUMN_USERID_USERID_2);
174    
175                            String sql = query.toString();
176    
177                            Session session = null;
178    
179                            try {
180                                    session = openSession();
181    
182                                    Query q = session.createQuery(sql);
183    
184                                    QueryPos qPos = QueryPos.getInstance(q);
185    
186                                    qPos.add(userId);
187    
188                                    List<BrowserTracker> list = q.list();
189    
190                                    if (list.isEmpty()) {
191                                            finderCache.putResult(FINDER_PATH_FETCH_BY_USERID,
192                                                    finderArgs, list);
193                                    }
194                                    else {
195                                            BrowserTracker browserTracker = list.get(0);
196    
197                                            result = browserTracker;
198    
199                                            cacheResult(browserTracker);
200    
201                                            if ((browserTracker.getUserId() != userId)) {
202                                                    finderCache.putResult(FINDER_PATH_FETCH_BY_USERID,
203                                                            finderArgs, browserTracker);
204                                            }
205                                    }
206                            }
207                            catch (Exception e) {
208                                    finderCache.removeResult(FINDER_PATH_FETCH_BY_USERID, finderArgs);
209    
210                                    throw processException(e);
211                            }
212                            finally {
213                                    closeSession(session);
214                            }
215                    }
216    
217                    if (result instanceof List<?>) {
218                            return null;
219                    }
220                    else {
221                            return (BrowserTracker)result;
222                    }
223            }
224    
225            /**
226             * Removes the browser tracker where userId = &#63; from the database.
227             *
228             * @param userId the user ID
229             * @return the browser tracker that was removed
230             */
231            @Override
232            public BrowserTracker removeByUserId(long userId)
233                    throws NoSuchBrowserTrackerException {
234                    BrowserTracker browserTracker = findByUserId(userId);
235    
236                    return remove(browserTracker);
237            }
238    
239            /**
240             * Returns the number of browser trackers where userId = &#63;.
241             *
242             * @param userId the user ID
243             * @return the number of matching browser trackers
244             */
245            @Override
246            public int countByUserId(long userId) {
247                    FinderPath finderPath = FINDER_PATH_COUNT_BY_USERID;
248    
249                    Object[] finderArgs = new Object[] { userId };
250    
251                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
252    
253                    if (count == null) {
254                            StringBundler query = new StringBundler(2);
255    
256                            query.append(_SQL_COUNT_BROWSERTRACKER_WHERE);
257    
258                            query.append(_FINDER_COLUMN_USERID_USERID_2);
259    
260                            String sql = query.toString();
261    
262                            Session session = null;
263    
264                            try {
265                                    session = openSession();
266    
267                                    Query q = session.createQuery(sql);
268    
269                                    QueryPos qPos = QueryPos.getInstance(q);
270    
271                                    qPos.add(userId);
272    
273                                    count = (Long)q.uniqueResult();
274    
275                                    finderCache.putResult(finderPath, finderArgs, count);
276                            }
277                            catch (Exception e) {
278                                    finderCache.removeResult(finderPath, finderArgs);
279    
280                                    throw processException(e);
281                            }
282                            finally {
283                                    closeSession(session);
284                            }
285                    }
286    
287                    return count.intValue();
288            }
289    
290            private static final String _FINDER_COLUMN_USERID_USERID_2 = "browserTracker.userId = ?";
291    
292            public BrowserTrackerPersistenceImpl() {
293                    setModelClass(BrowserTracker.class);
294            }
295    
296            /**
297             * Caches the browser tracker in the entity cache if it is enabled.
298             *
299             * @param browserTracker the browser tracker
300             */
301            @Override
302            public void cacheResult(BrowserTracker browserTracker) {
303                    entityCache.putResult(BrowserTrackerModelImpl.ENTITY_CACHE_ENABLED,
304                            BrowserTrackerImpl.class, browserTracker.getPrimaryKey(),
305                            browserTracker);
306    
307                    finderCache.putResult(FINDER_PATH_FETCH_BY_USERID,
308                            new Object[] { browserTracker.getUserId() }, browserTracker);
309    
310                    browserTracker.resetOriginalValues();
311            }
312    
313            /**
314             * Caches the browser trackers in the entity cache if it is enabled.
315             *
316             * @param browserTrackers the browser trackers
317             */
318            @Override
319            public void cacheResult(List<BrowserTracker> browserTrackers) {
320                    for (BrowserTracker browserTracker : browserTrackers) {
321                            if (entityCache.getResult(
322                                                    BrowserTrackerModelImpl.ENTITY_CACHE_ENABLED,
323                                                    BrowserTrackerImpl.class, browserTracker.getPrimaryKey()) == null) {
324                                    cacheResult(browserTracker);
325                            }
326                            else {
327                                    browserTracker.resetOriginalValues();
328                            }
329                    }
330            }
331    
332            /**
333             * Clears the cache for all browser trackers.
334             *
335             * <p>
336             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
337             * </p>
338             */
339            @Override
340            public void clearCache() {
341                    entityCache.clearCache(BrowserTrackerImpl.class);
342    
343                    finderCache.clearCache(FINDER_CLASS_NAME_ENTITY);
344                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
345                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
346            }
347    
348            /**
349             * Clears the cache for the browser tracker.
350             *
351             * <p>
352             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
353             * </p>
354             */
355            @Override
356            public void clearCache(BrowserTracker browserTracker) {
357                    entityCache.removeResult(BrowserTrackerModelImpl.ENTITY_CACHE_ENABLED,
358                            BrowserTrackerImpl.class, browserTracker.getPrimaryKey());
359    
360                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
361                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
362    
363                    clearUniqueFindersCache((BrowserTrackerModelImpl)browserTracker);
364            }
365    
366            @Override
367            public void clearCache(List<BrowserTracker> browserTrackers) {
368                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
369                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
370    
371                    for (BrowserTracker browserTracker : browserTrackers) {
372                            entityCache.removeResult(BrowserTrackerModelImpl.ENTITY_CACHE_ENABLED,
373                                    BrowserTrackerImpl.class, browserTracker.getPrimaryKey());
374    
375                            clearUniqueFindersCache((BrowserTrackerModelImpl)browserTracker);
376                    }
377            }
378    
379            protected void cacheUniqueFindersCache(
380                    BrowserTrackerModelImpl browserTrackerModelImpl, boolean isNew) {
381                    if (isNew) {
382                            Object[] args = new Object[] { browserTrackerModelImpl.getUserId() };
383    
384                            finderCache.putResult(FINDER_PATH_COUNT_BY_USERID, args,
385                                    Long.valueOf(1));
386                            finderCache.putResult(FINDER_PATH_FETCH_BY_USERID, args,
387                                    browserTrackerModelImpl);
388                    }
389                    else {
390                            if ((browserTrackerModelImpl.getColumnBitmask() &
391                                            FINDER_PATH_FETCH_BY_USERID.getColumnBitmask()) != 0) {
392                                    Object[] args = new Object[] { browserTrackerModelImpl.getUserId() };
393    
394                                    finderCache.putResult(FINDER_PATH_COUNT_BY_USERID, args,
395                                            Long.valueOf(1));
396                                    finderCache.putResult(FINDER_PATH_FETCH_BY_USERID, args,
397                                            browserTrackerModelImpl);
398                            }
399                    }
400            }
401    
402            protected void clearUniqueFindersCache(
403                    BrowserTrackerModelImpl browserTrackerModelImpl) {
404                    Object[] args = new Object[] { browserTrackerModelImpl.getUserId() };
405    
406                    finderCache.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
407                    finderCache.removeResult(FINDER_PATH_FETCH_BY_USERID, args);
408    
409                    if ((browserTrackerModelImpl.getColumnBitmask() &
410                                    FINDER_PATH_FETCH_BY_USERID.getColumnBitmask()) != 0) {
411                            args = new Object[] { browserTrackerModelImpl.getOriginalUserId() };
412    
413                            finderCache.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
414                            finderCache.removeResult(FINDER_PATH_FETCH_BY_USERID, args);
415                    }
416            }
417    
418            /**
419             * Creates a new browser tracker with the primary key. Does not add the browser tracker to the database.
420             *
421             * @param browserTrackerId the primary key for the new browser tracker
422             * @return the new browser tracker
423             */
424            @Override
425            public BrowserTracker create(long browserTrackerId) {
426                    BrowserTracker browserTracker = new BrowserTrackerImpl();
427    
428                    browserTracker.setNew(true);
429                    browserTracker.setPrimaryKey(browserTrackerId);
430    
431                    return browserTracker;
432            }
433    
434            /**
435             * Removes the browser tracker with the primary key from the database. Also notifies the appropriate model listeners.
436             *
437             * @param browserTrackerId the primary key of the browser tracker
438             * @return the browser tracker that was removed
439             * @throws NoSuchBrowserTrackerException if a browser tracker with the primary key could not be found
440             */
441            @Override
442            public BrowserTracker remove(long browserTrackerId)
443                    throws NoSuchBrowserTrackerException {
444                    return remove((Serializable)browserTrackerId);
445            }
446    
447            /**
448             * Removes the browser tracker with the primary key from the database. Also notifies the appropriate model listeners.
449             *
450             * @param primaryKey the primary key of the browser tracker
451             * @return the browser tracker that was removed
452             * @throws NoSuchBrowserTrackerException if a browser tracker with the primary key could not be found
453             */
454            @Override
455            public BrowserTracker remove(Serializable primaryKey)
456                    throws NoSuchBrowserTrackerException {
457                    Session session = null;
458    
459                    try {
460                            session = openSession();
461    
462                            BrowserTracker browserTracker = (BrowserTracker)session.get(BrowserTrackerImpl.class,
463                                            primaryKey);
464    
465                            if (browserTracker == null) {
466                                    if (_log.isWarnEnabled()) {
467                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
468                                    }
469    
470                                    throw new NoSuchBrowserTrackerException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
471                                            primaryKey);
472                            }
473    
474                            return remove(browserTracker);
475                    }
476                    catch (NoSuchBrowserTrackerException nsee) {
477                            throw nsee;
478                    }
479                    catch (Exception e) {
480                            throw processException(e);
481                    }
482                    finally {
483                            closeSession(session);
484                    }
485            }
486    
487            @Override
488            protected BrowserTracker removeImpl(BrowserTracker browserTracker) {
489                    browserTracker = toUnwrappedModel(browserTracker);
490    
491                    Session session = null;
492    
493                    try {
494                            session = openSession();
495    
496                            if (!session.contains(browserTracker)) {
497                                    browserTracker = (BrowserTracker)session.get(BrowserTrackerImpl.class,
498                                                    browserTracker.getPrimaryKeyObj());
499                            }
500    
501                            if (browserTracker != null) {
502                                    session.delete(browserTracker);
503                            }
504                    }
505                    catch (Exception e) {
506                            throw processException(e);
507                    }
508                    finally {
509                            closeSession(session);
510                    }
511    
512                    if (browserTracker != null) {
513                            clearCache(browserTracker);
514                    }
515    
516                    return browserTracker;
517            }
518    
519            @Override
520            public BrowserTracker updateImpl(BrowserTracker browserTracker) {
521                    browserTracker = toUnwrappedModel(browserTracker);
522    
523                    boolean isNew = browserTracker.isNew();
524    
525                    BrowserTrackerModelImpl browserTrackerModelImpl = (BrowserTrackerModelImpl)browserTracker;
526    
527                    Session session = null;
528    
529                    try {
530                            session = openSession();
531    
532                            if (browserTracker.isNew()) {
533                                    session.save(browserTracker);
534    
535                                    browserTracker.setNew(false);
536                            }
537                            else {
538                                    browserTracker = (BrowserTracker)session.merge(browserTracker);
539                            }
540                    }
541                    catch (Exception e) {
542                            throw processException(e);
543                    }
544                    finally {
545                            closeSession(session);
546                    }
547    
548                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
549    
550                    if (isNew || !BrowserTrackerModelImpl.COLUMN_BITMASK_ENABLED) {
551                            finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
552                    }
553    
554                    entityCache.putResult(BrowserTrackerModelImpl.ENTITY_CACHE_ENABLED,
555                            BrowserTrackerImpl.class, browserTracker.getPrimaryKey(),
556                            browserTracker, false);
557    
558                    clearUniqueFindersCache(browserTrackerModelImpl);
559                    cacheUniqueFindersCache(browserTrackerModelImpl, isNew);
560    
561                    browserTracker.resetOriginalValues();
562    
563                    return browserTracker;
564            }
565    
566            protected BrowserTracker toUnwrappedModel(BrowserTracker browserTracker) {
567                    if (browserTracker instanceof BrowserTrackerImpl) {
568                            return browserTracker;
569                    }
570    
571                    BrowserTrackerImpl browserTrackerImpl = new BrowserTrackerImpl();
572    
573                    browserTrackerImpl.setNew(browserTracker.isNew());
574                    browserTrackerImpl.setPrimaryKey(browserTracker.getPrimaryKey());
575    
576                    browserTrackerImpl.setMvccVersion(browserTracker.getMvccVersion());
577                    browserTrackerImpl.setBrowserTrackerId(browserTracker.getBrowserTrackerId());
578                    browserTrackerImpl.setCompanyId(browserTracker.getCompanyId());
579                    browserTrackerImpl.setUserId(browserTracker.getUserId());
580                    browserTrackerImpl.setBrowserKey(browserTracker.getBrowserKey());
581    
582                    return browserTrackerImpl;
583            }
584    
585            /**
586             * Returns the browser tracker with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
587             *
588             * @param primaryKey the primary key of the browser tracker
589             * @return the browser tracker
590             * @throws NoSuchBrowserTrackerException if a browser tracker with the primary key could not be found
591             */
592            @Override
593            public BrowserTracker findByPrimaryKey(Serializable primaryKey)
594                    throws NoSuchBrowserTrackerException {
595                    BrowserTracker browserTracker = fetchByPrimaryKey(primaryKey);
596    
597                    if (browserTracker == null) {
598                            if (_log.isWarnEnabled()) {
599                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
600                            }
601    
602                            throw new NoSuchBrowserTrackerException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
603                                    primaryKey);
604                    }
605    
606                    return browserTracker;
607            }
608    
609            /**
610             * Returns the browser tracker with the primary key or throws a {@link NoSuchBrowserTrackerException} if it could not be found.
611             *
612             * @param browserTrackerId the primary key of the browser tracker
613             * @return the browser tracker
614             * @throws NoSuchBrowserTrackerException if a browser tracker with the primary key could not be found
615             */
616            @Override
617            public BrowserTracker findByPrimaryKey(long browserTrackerId)
618                    throws NoSuchBrowserTrackerException {
619                    return findByPrimaryKey((Serializable)browserTrackerId);
620            }
621    
622            /**
623             * Returns the browser tracker with the primary key or returns <code>null</code> if it could not be found.
624             *
625             * @param primaryKey the primary key of the browser tracker
626             * @return the browser tracker, or <code>null</code> if a browser tracker with the primary key could not be found
627             */
628            @Override
629            public BrowserTracker fetchByPrimaryKey(Serializable primaryKey) {
630                    BrowserTracker browserTracker = (BrowserTracker)entityCache.getResult(BrowserTrackerModelImpl.ENTITY_CACHE_ENABLED,
631                                    BrowserTrackerImpl.class, primaryKey);
632    
633                    if (browserTracker == _nullBrowserTracker) {
634                            return null;
635                    }
636    
637                    if (browserTracker == null) {
638                            Session session = null;
639    
640                            try {
641                                    session = openSession();
642    
643                                    browserTracker = (BrowserTracker)session.get(BrowserTrackerImpl.class,
644                                                    primaryKey);
645    
646                                    if (browserTracker != null) {
647                                            cacheResult(browserTracker);
648                                    }
649                                    else {
650                                            entityCache.putResult(BrowserTrackerModelImpl.ENTITY_CACHE_ENABLED,
651                                                    BrowserTrackerImpl.class, primaryKey,
652                                                    _nullBrowserTracker);
653                                    }
654                            }
655                            catch (Exception e) {
656                                    entityCache.removeResult(BrowserTrackerModelImpl.ENTITY_CACHE_ENABLED,
657                                            BrowserTrackerImpl.class, primaryKey);
658    
659                                    throw processException(e);
660                            }
661                            finally {
662                                    closeSession(session);
663                            }
664                    }
665    
666                    return browserTracker;
667            }
668    
669            /**
670             * Returns the browser tracker with the primary key or returns <code>null</code> if it could not be found.
671             *
672             * @param browserTrackerId the primary key of the browser tracker
673             * @return the browser tracker, or <code>null</code> if a browser tracker with the primary key could not be found
674             */
675            @Override
676            public BrowserTracker fetchByPrimaryKey(long browserTrackerId) {
677                    return fetchByPrimaryKey((Serializable)browserTrackerId);
678            }
679    
680            @Override
681            public Map<Serializable, BrowserTracker> fetchByPrimaryKeys(
682                    Set<Serializable> primaryKeys) {
683                    if (primaryKeys.isEmpty()) {
684                            return Collections.emptyMap();
685                    }
686    
687                    Map<Serializable, BrowserTracker> map = new HashMap<Serializable, BrowserTracker>();
688    
689                    if (primaryKeys.size() == 1) {
690                            Iterator<Serializable> iterator = primaryKeys.iterator();
691    
692                            Serializable primaryKey = iterator.next();
693    
694                            BrowserTracker browserTracker = fetchByPrimaryKey(primaryKey);
695    
696                            if (browserTracker != null) {
697                                    map.put(primaryKey, browserTracker);
698                            }
699    
700                            return map;
701                    }
702    
703                    Set<Serializable> uncachedPrimaryKeys = null;
704    
705                    for (Serializable primaryKey : primaryKeys) {
706                            BrowserTracker browserTracker = (BrowserTracker)entityCache.getResult(BrowserTrackerModelImpl.ENTITY_CACHE_ENABLED,
707                                            BrowserTrackerImpl.class, primaryKey);
708    
709                            if (browserTracker == null) {
710                                    if (uncachedPrimaryKeys == null) {
711                                            uncachedPrimaryKeys = new HashSet<Serializable>();
712                                    }
713    
714                                    uncachedPrimaryKeys.add(primaryKey);
715                            }
716                            else {
717                                    map.put(primaryKey, browserTracker);
718                            }
719                    }
720    
721                    if (uncachedPrimaryKeys == null) {
722                            return map;
723                    }
724    
725                    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
726                                    1);
727    
728                    query.append(_SQL_SELECT_BROWSERTRACKER_WHERE_PKS_IN);
729    
730                    for (Serializable primaryKey : uncachedPrimaryKeys) {
731                            query.append(String.valueOf(primaryKey));
732    
733                            query.append(StringPool.COMMA);
734                    }
735    
736                    query.setIndex(query.index() - 1);
737    
738                    query.append(StringPool.CLOSE_PARENTHESIS);
739    
740                    String sql = query.toString();
741    
742                    Session session = null;
743    
744                    try {
745                            session = openSession();
746    
747                            Query q = session.createQuery(sql);
748    
749                            for (BrowserTracker browserTracker : (List<BrowserTracker>)q.list()) {
750                                    map.put(browserTracker.getPrimaryKeyObj(), browserTracker);
751    
752                                    cacheResult(browserTracker);
753    
754                                    uncachedPrimaryKeys.remove(browserTracker.getPrimaryKeyObj());
755                            }
756    
757                            for (Serializable primaryKey : uncachedPrimaryKeys) {
758                                    entityCache.putResult(BrowserTrackerModelImpl.ENTITY_CACHE_ENABLED,
759                                            BrowserTrackerImpl.class, primaryKey, _nullBrowserTracker);
760                            }
761                    }
762                    catch (Exception e) {
763                            throw processException(e);
764                    }
765                    finally {
766                            closeSession(session);
767                    }
768    
769                    return map;
770            }
771    
772            /**
773             * Returns all the browser trackers.
774             *
775             * @return the browser trackers
776             */
777            @Override
778            public List<BrowserTracker> findAll() {
779                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
780            }
781    
782            /**
783             * Returns a range of all the browser trackers.
784             *
785             * <p>
786             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
787             * </p>
788             *
789             * @param start the lower bound of the range of browser trackers
790             * @param end the upper bound of the range of browser trackers (not inclusive)
791             * @return the range of browser trackers
792             */
793            @Override
794            public List<BrowserTracker> findAll(int start, int end) {
795                    return findAll(start, end, null);
796            }
797    
798            /**
799             * Returns an ordered range of all the browser trackers.
800             *
801             * <p>
802             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
803             * </p>
804             *
805             * @param start the lower bound of the range of browser trackers
806             * @param end the upper bound of the range of browser trackers (not inclusive)
807             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
808             * @return the ordered range of browser trackers
809             */
810            @Override
811            public List<BrowserTracker> findAll(int start, int end,
812                    OrderByComparator<BrowserTracker> orderByComparator) {
813                    return findAll(start, end, orderByComparator, true);
814            }
815    
816            /**
817             * Returns an ordered range of all the browser trackers.
818             *
819             * <p>
820             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
821             * </p>
822             *
823             * @param start the lower bound of the range of browser trackers
824             * @param end the upper bound of the range of browser trackers (not inclusive)
825             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
826             * @param retrieveFromCache whether to retrieve from the finder cache
827             * @return the ordered range of browser trackers
828             */
829            @Override
830            public List<BrowserTracker> findAll(int start, int end,
831                    OrderByComparator<BrowserTracker> orderByComparator,
832                    boolean retrieveFromCache) {
833                    boolean pagination = true;
834                    FinderPath finderPath = null;
835                    Object[] finderArgs = null;
836    
837                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
838                                    (orderByComparator == null)) {
839                            pagination = false;
840                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
841                            finderArgs = FINDER_ARGS_EMPTY;
842                    }
843                    else {
844                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
845                            finderArgs = new Object[] { start, end, orderByComparator };
846                    }
847    
848                    List<BrowserTracker> list = null;
849    
850                    if (retrieveFromCache) {
851                            list = (List<BrowserTracker>)finderCache.getResult(finderPath,
852                                            finderArgs, this);
853                    }
854    
855                    if (list == null) {
856                            StringBundler query = null;
857                            String sql = null;
858    
859                            if (orderByComparator != null) {
860                                    query = new StringBundler(2 +
861                                                    (orderByComparator.getOrderByFields().length * 3));
862    
863                                    query.append(_SQL_SELECT_BROWSERTRACKER);
864    
865                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
866                                            orderByComparator);
867    
868                                    sql = query.toString();
869                            }
870                            else {
871                                    sql = _SQL_SELECT_BROWSERTRACKER;
872    
873                                    if (pagination) {
874                                            sql = sql.concat(BrowserTrackerModelImpl.ORDER_BY_JPQL);
875                                    }
876                            }
877    
878                            Session session = null;
879    
880                            try {
881                                    session = openSession();
882    
883                                    Query q = session.createQuery(sql);
884    
885                                    if (!pagination) {
886                                            list = (List<BrowserTracker>)QueryUtil.list(q,
887                                                            getDialect(), start, end, false);
888    
889                                            Collections.sort(list);
890    
891                                            list = Collections.unmodifiableList(list);
892                                    }
893                                    else {
894                                            list = (List<BrowserTracker>)QueryUtil.list(q,
895                                                            getDialect(), start, end);
896                                    }
897    
898                                    cacheResult(list);
899    
900                                    finderCache.putResult(finderPath, finderArgs, list);
901                            }
902                            catch (Exception e) {
903                                    finderCache.removeResult(finderPath, finderArgs);
904    
905                                    throw processException(e);
906                            }
907                            finally {
908                                    closeSession(session);
909                            }
910                    }
911    
912                    return list;
913            }
914    
915            /**
916             * Removes all the browser trackers from the database.
917             *
918             */
919            @Override
920            public void removeAll() {
921                    for (BrowserTracker browserTracker : findAll()) {
922                            remove(browserTracker);
923                    }
924            }
925    
926            /**
927             * Returns the number of browser trackers.
928             *
929             * @return the number of browser trackers
930             */
931            @Override
932            public int countAll() {
933                    Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL,
934                                    FINDER_ARGS_EMPTY, this);
935    
936                    if (count == null) {
937                            Session session = null;
938    
939                            try {
940                                    session = openSession();
941    
942                                    Query q = session.createQuery(_SQL_COUNT_BROWSERTRACKER);
943    
944                                    count = (Long)q.uniqueResult();
945    
946                                    finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY,
947                                            count);
948                            }
949                            catch (Exception e) {
950                                    finderCache.removeResult(FINDER_PATH_COUNT_ALL,
951                                            FINDER_ARGS_EMPTY);
952    
953                                    throw processException(e);
954                            }
955                            finally {
956                                    closeSession(session);
957                            }
958                    }
959    
960                    return count.intValue();
961            }
962    
963            @Override
964            protected Map<String, Integer> getTableColumnsMap() {
965                    return BrowserTrackerModelImpl.TABLE_COLUMNS_MAP;
966            }
967    
968            /**
969             * Initializes the browser tracker persistence.
970             */
971            public void afterPropertiesSet() {
972            }
973    
974            public void destroy() {
975                    entityCache.removeCache(BrowserTrackerImpl.class.getName());
976                    finderCache.removeCache(FINDER_CLASS_NAME_ENTITY);
977                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
978                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
979            }
980    
981            @BeanReference(type = CompanyProvider.class)
982            protected CompanyProvider companyProvider;
983            protected EntityCache entityCache = EntityCacheUtil.getEntityCache();
984            protected FinderCache finderCache = FinderCacheUtil.getFinderCache();
985            private static final String _SQL_SELECT_BROWSERTRACKER = "SELECT browserTracker FROM BrowserTracker browserTracker";
986            private static final String _SQL_SELECT_BROWSERTRACKER_WHERE_PKS_IN = "SELECT browserTracker FROM BrowserTracker browserTracker WHERE browserTrackerId IN (";
987            private static final String _SQL_SELECT_BROWSERTRACKER_WHERE = "SELECT browserTracker FROM BrowserTracker browserTracker WHERE ";
988            private static final String _SQL_COUNT_BROWSERTRACKER = "SELECT COUNT(browserTracker) FROM BrowserTracker browserTracker";
989            private static final String _SQL_COUNT_BROWSERTRACKER_WHERE = "SELECT COUNT(browserTracker) FROM BrowserTracker browserTracker WHERE ";
990            private static final String _ORDER_BY_ENTITY_ALIAS = "browserTracker.";
991            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No BrowserTracker exists with the primary key ";
992            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No BrowserTracker exists with the key {";
993            private static final Log _log = LogFactoryUtil.getLog(BrowserTrackerPersistenceImpl.class);
994            private static final BrowserTracker _nullBrowserTracker = new BrowserTrackerImpl() {
995                            @Override
996                            public Object clone() {
997                                    return this;
998                            }
999    
1000                            @Override
1001                            public CacheModel<BrowserTracker> toCacheModel() {
1002                                    return _nullBrowserTrackerCacheModel;
1003                            }
1004                    };
1005    
1006            private static final CacheModel<BrowserTracker> _nullBrowserTrackerCacheModel =
1007                    new NullCacheModel();
1008    
1009            private static class NullCacheModel implements CacheModel<BrowserTracker>,
1010                    MVCCModel {
1011                    @Override
1012                    public long getMvccVersion() {
1013                            return -1;
1014                    }
1015    
1016                    @Override
1017                    public void setMvccVersion(long mvccVersion) {
1018                    }
1019    
1020                    @Override
1021                    public BrowserTracker toEntityModel() {
1022                            return _nullBrowserTracker;
1023                    }
1024            }
1025    }