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