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