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.portlet.asset.service.persistence.impl;
016    
017    import aQute.bnd.annotation.ProviderType;
018    
019    import com.liferay.asset.kernel.exception.NoSuchTagStatsException;
020    import com.liferay.asset.kernel.model.AssetTagStats;
021    import com.liferay.asset.kernel.service.persistence.AssetTagStatsPersistence;
022    
023    import com.liferay.portal.kernel.bean.BeanReference;
024    import com.liferay.portal.kernel.dao.orm.EntityCache;
025    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
026    import com.liferay.portal.kernel.dao.orm.FinderCache;
027    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
028    import com.liferay.portal.kernel.dao.orm.FinderPath;
029    import com.liferay.portal.kernel.dao.orm.Query;
030    import com.liferay.portal.kernel.dao.orm.QueryPos;
031    import com.liferay.portal.kernel.dao.orm.QueryUtil;
032    import com.liferay.portal.kernel.dao.orm.Session;
033    import com.liferay.portal.kernel.log.Log;
034    import com.liferay.portal.kernel.log.LogFactoryUtil;
035    import com.liferay.portal.kernel.model.CacheModel;
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    
043    import com.liferay.portlet.asset.model.impl.AssetTagStatsImpl;
044    import com.liferay.portlet.asset.model.impl.AssetTagStatsModelImpl;
045    
046    import java.io.Serializable;
047    
048    import java.util.Collections;
049    import java.util.HashMap;
050    import java.util.HashSet;
051    import java.util.Iterator;
052    import java.util.List;
053    import java.util.Map;
054    import java.util.Set;
055    
056    /**
057     * The persistence implementation for the asset tag stats service.
058     *
059     * <p>
060     * Caching information and settings can be found in <code>portal.properties</code>
061     * </p>
062     *
063     * @author Brian Wing Shun Chan
064     * @see AssetTagStatsPersistence
065     * @see com.liferay.asset.kernel.service.persistence.AssetTagStatsUtil
066     * @generated
067     */
068    @ProviderType
069    public class AssetTagStatsPersistenceImpl extends BasePersistenceImpl<AssetTagStats>
070            implements AssetTagStatsPersistence {
071            /*
072             * NOTE FOR DEVELOPERS:
073             *
074             * Never modify or reference this class directly. Always use {@link AssetTagStatsUtil} to access the asset tag stats persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
075             */
076            public static final String FINDER_CLASS_NAME_ENTITY = AssetTagStatsImpl.class.getName();
077            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
078                    ".List1";
079            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
080                    ".List2";
081            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(AssetTagStatsModelImpl.ENTITY_CACHE_ENABLED,
082                            AssetTagStatsModelImpl.FINDER_CACHE_ENABLED,
083                            AssetTagStatsImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
084                            "findAll", new String[0]);
085            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(AssetTagStatsModelImpl.ENTITY_CACHE_ENABLED,
086                            AssetTagStatsModelImpl.FINDER_CACHE_ENABLED,
087                            AssetTagStatsImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
088                            "findAll", new String[0]);
089            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(AssetTagStatsModelImpl.ENTITY_CACHE_ENABLED,
090                            AssetTagStatsModelImpl.FINDER_CACHE_ENABLED, Long.class,
091                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
092            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_TAGID = new FinderPath(AssetTagStatsModelImpl.ENTITY_CACHE_ENABLED,
093                            AssetTagStatsModelImpl.FINDER_CACHE_ENABLED,
094                            AssetTagStatsImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
095                            "findByTagId",
096                            new String[] {
097                                    Long.class.getName(),
098                                    
099                            Integer.class.getName(), Integer.class.getName(),
100                                    OrderByComparator.class.getName()
101                            });
102            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TAGID = new FinderPath(AssetTagStatsModelImpl.ENTITY_CACHE_ENABLED,
103                            AssetTagStatsModelImpl.FINDER_CACHE_ENABLED,
104                            AssetTagStatsImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
105                            "findByTagId", new String[] { Long.class.getName() },
106                            AssetTagStatsModelImpl.TAGID_COLUMN_BITMASK |
107                            AssetTagStatsModelImpl.ASSETCOUNT_COLUMN_BITMASK);
108            public static final FinderPath FINDER_PATH_COUNT_BY_TAGID = new FinderPath(AssetTagStatsModelImpl.ENTITY_CACHE_ENABLED,
109                            AssetTagStatsModelImpl.FINDER_CACHE_ENABLED, Long.class,
110                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByTagId",
111                            new String[] { Long.class.getName() });
112    
113            /**
114             * Returns all the asset tag statses where tagId = &#63;.
115             *
116             * @param tagId the tag ID
117             * @return the matching asset tag statses
118             */
119            @Override
120            public List<AssetTagStats> findByTagId(long tagId) {
121                    return findByTagId(tagId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
122            }
123    
124            /**
125             * Returns a range of all the asset tag statses where tagId = &#63;.
126             *
127             * <p>
128             * 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 AssetTagStatsModelImpl}. 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.
129             * </p>
130             *
131             * @param tagId the tag ID
132             * @param start the lower bound of the range of asset tag statses
133             * @param end the upper bound of the range of asset tag statses (not inclusive)
134             * @return the range of matching asset tag statses
135             */
136            @Override
137            public List<AssetTagStats> findByTagId(long tagId, int start, int end) {
138                    return findByTagId(tagId, start, end, null);
139            }
140    
141            /**
142             * Returns an ordered range of all the asset tag statses where tagId = &#63;.
143             *
144             * <p>
145             * 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 AssetTagStatsModelImpl}. 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.
146             * </p>
147             *
148             * @param tagId the tag ID
149             * @param start the lower bound of the range of asset tag statses
150             * @param end the upper bound of the range of asset tag statses (not inclusive)
151             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
152             * @return the ordered range of matching asset tag statses
153             */
154            @Override
155            public List<AssetTagStats> findByTagId(long tagId, int start, int end,
156                    OrderByComparator<AssetTagStats> orderByComparator) {
157                    return findByTagId(tagId, start, end, orderByComparator, true);
158            }
159    
160            /**
161             * Returns an ordered range of all the asset tag statses where tagId = &#63;.
162             *
163             * <p>
164             * 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 AssetTagStatsModelImpl}. 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.
165             * </p>
166             *
167             * @param tagId the tag ID
168             * @param start the lower bound of the range of asset tag statses
169             * @param end the upper bound of the range of asset tag statses (not inclusive)
170             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
171             * @param retrieveFromCache whether to retrieve from the finder cache
172             * @return the ordered range of matching asset tag statses
173             */
174            @Override
175            public List<AssetTagStats> findByTagId(long tagId, int start, int end,
176                    OrderByComparator<AssetTagStats> orderByComparator,
177                    boolean retrieveFromCache) {
178                    boolean pagination = true;
179                    FinderPath finderPath = null;
180                    Object[] finderArgs = null;
181    
182                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
183                                    (orderByComparator == null)) {
184                            pagination = false;
185                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TAGID;
186                            finderArgs = new Object[] { tagId };
187                    }
188                    else {
189                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_TAGID;
190                            finderArgs = new Object[] { tagId, start, end, orderByComparator };
191                    }
192    
193                    List<AssetTagStats> list = null;
194    
195                    if (retrieveFromCache) {
196                            list = (List<AssetTagStats>)finderCache.getResult(finderPath,
197                                            finderArgs, this);
198    
199                            if ((list != null) && !list.isEmpty()) {
200                                    for (AssetTagStats assetTagStats : list) {
201                                            if ((tagId != assetTagStats.getTagId())) {
202                                                    list = null;
203    
204                                                    break;
205                                            }
206                                    }
207                            }
208                    }
209    
210                    if (list == null) {
211                            StringBundler query = null;
212    
213                            if (orderByComparator != null) {
214                                    query = new StringBundler(3 +
215                                                    (orderByComparator.getOrderByFields().length * 2));
216                            }
217                            else {
218                                    query = new StringBundler(3);
219                            }
220    
221                            query.append(_SQL_SELECT_ASSETTAGSTATS_WHERE);
222    
223                            query.append(_FINDER_COLUMN_TAGID_TAGID_2);
224    
225                            if (orderByComparator != null) {
226                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
227                                            orderByComparator);
228                            }
229                            else
230                             if (pagination) {
231                                    query.append(AssetTagStatsModelImpl.ORDER_BY_JPQL);
232                            }
233    
234                            String sql = query.toString();
235    
236                            Session session = null;
237    
238                            try {
239                                    session = openSession();
240    
241                                    Query q = session.createQuery(sql);
242    
243                                    QueryPos qPos = QueryPos.getInstance(q);
244    
245                                    qPos.add(tagId);
246    
247                                    if (!pagination) {
248                                            list = (List<AssetTagStats>)QueryUtil.list(q, getDialect(),
249                                                            start, end, false);
250    
251                                            Collections.sort(list);
252    
253                                            list = Collections.unmodifiableList(list);
254                                    }
255                                    else {
256                                            list = (List<AssetTagStats>)QueryUtil.list(q, getDialect(),
257                                                            start, end);
258                                    }
259    
260                                    cacheResult(list);
261    
262                                    finderCache.putResult(finderPath, finderArgs, list);
263                            }
264                            catch (Exception e) {
265                                    finderCache.removeResult(finderPath, finderArgs);
266    
267                                    throw processException(e);
268                            }
269                            finally {
270                                    closeSession(session);
271                            }
272                    }
273    
274                    return list;
275            }
276    
277            /**
278             * Returns the first asset tag stats in the ordered set where tagId = &#63;.
279             *
280             * @param tagId the tag ID
281             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
282             * @return the first matching asset tag stats
283             * @throws NoSuchTagStatsException if a matching asset tag stats could not be found
284             */
285            @Override
286            public AssetTagStats findByTagId_First(long tagId,
287                    OrderByComparator<AssetTagStats> orderByComparator)
288                    throws NoSuchTagStatsException {
289                    AssetTagStats assetTagStats = fetchByTagId_First(tagId,
290                                    orderByComparator);
291    
292                    if (assetTagStats != null) {
293                            return assetTagStats;
294                    }
295    
296                    StringBundler msg = new StringBundler(4);
297    
298                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
299    
300                    msg.append("tagId=");
301                    msg.append(tagId);
302    
303                    msg.append(StringPool.CLOSE_CURLY_BRACE);
304    
305                    throw new NoSuchTagStatsException(msg.toString());
306            }
307    
308            /**
309             * Returns the first asset tag stats in the ordered set where tagId = &#63;.
310             *
311             * @param tagId the tag ID
312             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
313             * @return the first matching asset tag stats, or <code>null</code> if a matching asset tag stats could not be found
314             */
315            @Override
316            public AssetTagStats fetchByTagId_First(long tagId,
317                    OrderByComparator<AssetTagStats> orderByComparator) {
318                    List<AssetTagStats> list = findByTagId(tagId, 0, 1, orderByComparator);
319    
320                    if (!list.isEmpty()) {
321                            return list.get(0);
322                    }
323    
324                    return null;
325            }
326    
327            /**
328             * Returns the last asset tag stats in the ordered set where tagId = &#63;.
329             *
330             * @param tagId the tag ID
331             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
332             * @return the last matching asset tag stats
333             * @throws NoSuchTagStatsException if a matching asset tag stats could not be found
334             */
335            @Override
336            public AssetTagStats findByTagId_Last(long tagId,
337                    OrderByComparator<AssetTagStats> orderByComparator)
338                    throws NoSuchTagStatsException {
339                    AssetTagStats assetTagStats = fetchByTagId_Last(tagId, orderByComparator);
340    
341                    if (assetTagStats != null) {
342                            return assetTagStats;
343                    }
344    
345                    StringBundler msg = new StringBundler(4);
346    
347                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
348    
349                    msg.append("tagId=");
350                    msg.append(tagId);
351    
352                    msg.append(StringPool.CLOSE_CURLY_BRACE);
353    
354                    throw new NoSuchTagStatsException(msg.toString());
355            }
356    
357            /**
358             * Returns the last asset tag stats in the ordered set where tagId = &#63;.
359             *
360             * @param tagId the tag ID
361             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
362             * @return the last matching asset tag stats, or <code>null</code> if a matching asset tag stats could not be found
363             */
364            @Override
365            public AssetTagStats fetchByTagId_Last(long tagId,
366                    OrderByComparator<AssetTagStats> orderByComparator) {
367                    int count = countByTagId(tagId);
368    
369                    if (count == 0) {
370                            return null;
371                    }
372    
373                    List<AssetTagStats> list = findByTagId(tagId, count - 1, count,
374                                    orderByComparator);
375    
376                    if (!list.isEmpty()) {
377                            return list.get(0);
378                    }
379    
380                    return null;
381            }
382    
383            /**
384             * Returns the asset tag statses before and after the current asset tag stats in the ordered set where tagId = &#63;.
385             *
386             * @param tagStatsId the primary key of the current asset tag stats
387             * @param tagId the tag ID
388             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
389             * @return the previous, current, and next asset tag stats
390             * @throws NoSuchTagStatsException if a asset tag stats with the primary key could not be found
391             */
392            @Override
393            public AssetTagStats[] findByTagId_PrevAndNext(long tagStatsId, long tagId,
394                    OrderByComparator<AssetTagStats> orderByComparator)
395                    throws NoSuchTagStatsException {
396                    AssetTagStats assetTagStats = findByPrimaryKey(tagStatsId);
397    
398                    Session session = null;
399    
400                    try {
401                            session = openSession();
402    
403                            AssetTagStats[] array = new AssetTagStatsImpl[3];
404    
405                            array[0] = getByTagId_PrevAndNext(session, assetTagStats, tagId,
406                                            orderByComparator, true);
407    
408                            array[1] = assetTagStats;
409    
410                            array[2] = getByTagId_PrevAndNext(session, assetTagStats, tagId,
411                                            orderByComparator, false);
412    
413                            return array;
414                    }
415                    catch (Exception e) {
416                            throw processException(e);
417                    }
418                    finally {
419                            closeSession(session);
420                    }
421            }
422    
423            protected AssetTagStats getByTagId_PrevAndNext(Session session,
424                    AssetTagStats assetTagStats, long tagId,
425                    OrderByComparator<AssetTagStats> orderByComparator, boolean previous) {
426                    StringBundler query = null;
427    
428                    if (orderByComparator != null) {
429                            query = new StringBundler(4 +
430                                            (orderByComparator.getOrderByConditionFields().length * 3) +
431                                            (orderByComparator.getOrderByFields().length * 3));
432                    }
433                    else {
434                            query = new StringBundler(3);
435                    }
436    
437                    query.append(_SQL_SELECT_ASSETTAGSTATS_WHERE);
438    
439                    query.append(_FINDER_COLUMN_TAGID_TAGID_2);
440    
441                    if (orderByComparator != null) {
442                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
443    
444                            if (orderByConditionFields.length > 0) {
445                                    query.append(WHERE_AND);
446                            }
447    
448                            for (int i = 0; i < orderByConditionFields.length; i++) {
449                                    query.append(_ORDER_BY_ENTITY_ALIAS);
450                                    query.append(orderByConditionFields[i]);
451    
452                                    if ((i + 1) < orderByConditionFields.length) {
453                                            if (orderByComparator.isAscending() ^ previous) {
454                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
455                                            }
456                                            else {
457                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
458                                            }
459                                    }
460                                    else {
461                                            if (orderByComparator.isAscending() ^ previous) {
462                                                    query.append(WHERE_GREATER_THAN);
463                                            }
464                                            else {
465                                                    query.append(WHERE_LESSER_THAN);
466                                            }
467                                    }
468                            }
469    
470                            query.append(ORDER_BY_CLAUSE);
471    
472                            String[] orderByFields = orderByComparator.getOrderByFields();
473    
474                            for (int i = 0; i < orderByFields.length; i++) {
475                                    query.append(_ORDER_BY_ENTITY_ALIAS);
476                                    query.append(orderByFields[i]);
477    
478                                    if ((i + 1) < orderByFields.length) {
479                                            if (orderByComparator.isAscending() ^ previous) {
480                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
481                                            }
482                                            else {
483                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
484                                            }
485                                    }
486                                    else {
487                                            if (orderByComparator.isAscending() ^ previous) {
488                                                    query.append(ORDER_BY_ASC);
489                                            }
490                                            else {
491                                                    query.append(ORDER_BY_DESC);
492                                            }
493                                    }
494                            }
495                    }
496                    else {
497                            query.append(AssetTagStatsModelImpl.ORDER_BY_JPQL);
498                    }
499    
500                    String sql = query.toString();
501    
502                    Query q = session.createQuery(sql);
503    
504                    q.setFirstResult(0);
505                    q.setMaxResults(2);
506    
507                    QueryPos qPos = QueryPos.getInstance(q);
508    
509                    qPos.add(tagId);
510    
511                    if (orderByComparator != null) {
512                            Object[] values = orderByComparator.getOrderByConditionValues(assetTagStats);
513    
514                            for (Object value : values) {
515                                    qPos.add(value);
516                            }
517                    }
518    
519                    List<AssetTagStats> list = q.list();
520    
521                    if (list.size() == 2) {
522                            return list.get(1);
523                    }
524                    else {
525                            return null;
526                    }
527            }
528    
529            /**
530             * Removes all the asset tag statses where tagId = &#63; from the database.
531             *
532             * @param tagId the tag ID
533             */
534            @Override
535            public void removeByTagId(long tagId) {
536                    for (AssetTagStats assetTagStats : findByTagId(tagId,
537                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
538                            remove(assetTagStats);
539                    }
540            }
541    
542            /**
543             * Returns the number of asset tag statses where tagId = &#63;.
544             *
545             * @param tagId the tag ID
546             * @return the number of matching asset tag statses
547             */
548            @Override
549            public int countByTagId(long tagId) {
550                    FinderPath finderPath = FINDER_PATH_COUNT_BY_TAGID;
551    
552                    Object[] finderArgs = new Object[] { tagId };
553    
554                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
555    
556                    if (count == null) {
557                            StringBundler query = new StringBundler(2);
558    
559                            query.append(_SQL_COUNT_ASSETTAGSTATS_WHERE);
560    
561                            query.append(_FINDER_COLUMN_TAGID_TAGID_2);
562    
563                            String sql = query.toString();
564    
565                            Session session = null;
566    
567                            try {
568                                    session = openSession();
569    
570                                    Query q = session.createQuery(sql);
571    
572                                    QueryPos qPos = QueryPos.getInstance(q);
573    
574                                    qPos.add(tagId);
575    
576                                    count = (Long)q.uniqueResult();
577    
578                                    finderCache.putResult(finderPath, finderArgs, count);
579                            }
580                            catch (Exception e) {
581                                    finderCache.removeResult(finderPath, finderArgs);
582    
583                                    throw processException(e);
584                            }
585                            finally {
586                                    closeSession(session);
587                            }
588                    }
589    
590                    return count.intValue();
591            }
592    
593            private static final String _FINDER_COLUMN_TAGID_TAGID_2 = "assetTagStats.tagId = ?";
594            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_CLASSNAMEID =
595                    new FinderPath(AssetTagStatsModelImpl.ENTITY_CACHE_ENABLED,
596                            AssetTagStatsModelImpl.FINDER_CACHE_ENABLED,
597                            AssetTagStatsImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
598                            "findByClassNameId",
599                            new String[] {
600                                    Long.class.getName(),
601                                    
602                            Integer.class.getName(), Integer.class.getName(),
603                                    OrderByComparator.class.getName()
604                            });
605            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLASSNAMEID =
606                    new FinderPath(AssetTagStatsModelImpl.ENTITY_CACHE_ENABLED,
607                            AssetTagStatsModelImpl.FINDER_CACHE_ENABLED,
608                            AssetTagStatsImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
609                            "findByClassNameId", new String[] { Long.class.getName() },
610                            AssetTagStatsModelImpl.CLASSNAMEID_COLUMN_BITMASK |
611                            AssetTagStatsModelImpl.ASSETCOUNT_COLUMN_BITMASK);
612            public static final FinderPath FINDER_PATH_COUNT_BY_CLASSNAMEID = new FinderPath(AssetTagStatsModelImpl.ENTITY_CACHE_ENABLED,
613                            AssetTagStatsModelImpl.FINDER_CACHE_ENABLED, Long.class,
614                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByClassNameId",
615                            new String[] { Long.class.getName() });
616    
617            /**
618             * Returns all the asset tag statses where classNameId = &#63;.
619             *
620             * @param classNameId the class name ID
621             * @return the matching asset tag statses
622             */
623            @Override
624            public List<AssetTagStats> findByClassNameId(long classNameId) {
625                    return findByClassNameId(classNameId, QueryUtil.ALL_POS,
626                            QueryUtil.ALL_POS, null);
627            }
628    
629            /**
630             * Returns a range of all the asset tag statses where classNameId = &#63;.
631             *
632             * <p>
633             * 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 AssetTagStatsModelImpl}. 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.
634             * </p>
635             *
636             * @param classNameId the class name ID
637             * @param start the lower bound of the range of asset tag statses
638             * @param end the upper bound of the range of asset tag statses (not inclusive)
639             * @return the range of matching asset tag statses
640             */
641            @Override
642            public List<AssetTagStats> findByClassNameId(long classNameId, int start,
643                    int end) {
644                    return findByClassNameId(classNameId, start, end, null);
645            }
646    
647            /**
648             * Returns an ordered range of all the asset tag statses where classNameId = &#63;.
649             *
650             * <p>
651             * 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 AssetTagStatsModelImpl}. 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.
652             * </p>
653             *
654             * @param classNameId the class name ID
655             * @param start the lower bound of the range of asset tag statses
656             * @param end the upper bound of the range of asset tag statses (not inclusive)
657             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
658             * @return the ordered range of matching asset tag statses
659             */
660            @Override
661            public List<AssetTagStats> findByClassNameId(long classNameId, int start,
662                    int end, OrderByComparator<AssetTagStats> orderByComparator) {
663                    return findByClassNameId(classNameId, start, end, orderByComparator,
664                            true);
665            }
666    
667            /**
668             * Returns an ordered range of all the asset tag statses where classNameId = &#63;.
669             *
670             * <p>
671             * 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 AssetTagStatsModelImpl}. 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.
672             * </p>
673             *
674             * @param classNameId the class name ID
675             * @param start the lower bound of the range of asset tag statses
676             * @param end the upper bound of the range of asset tag statses (not inclusive)
677             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
678             * @param retrieveFromCache whether to retrieve from the finder cache
679             * @return the ordered range of matching asset tag statses
680             */
681            @Override
682            public List<AssetTagStats> findByClassNameId(long classNameId, int start,
683                    int end, OrderByComparator<AssetTagStats> orderByComparator,
684                    boolean retrieveFromCache) {
685                    boolean pagination = true;
686                    FinderPath finderPath = null;
687                    Object[] finderArgs = null;
688    
689                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
690                                    (orderByComparator == null)) {
691                            pagination = false;
692                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLASSNAMEID;
693                            finderArgs = new Object[] { classNameId };
694                    }
695                    else {
696                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_CLASSNAMEID;
697                            finderArgs = new Object[] { classNameId, start, end, orderByComparator };
698                    }
699    
700                    List<AssetTagStats> list = null;
701    
702                    if (retrieveFromCache) {
703                            list = (List<AssetTagStats>)finderCache.getResult(finderPath,
704                                            finderArgs, this);
705    
706                            if ((list != null) && !list.isEmpty()) {
707                                    for (AssetTagStats assetTagStats : list) {
708                                            if ((classNameId != assetTagStats.getClassNameId())) {
709                                                    list = null;
710    
711                                                    break;
712                                            }
713                                    }
714                            }
715                    }
716    
717                    if (list == null) {
718                            StringBundler query = null;
719    
720                            if (orderByComparator != null) {
721                                    query = new StringBundler(3 +
722                                                    (orderByComparator.getOrderByFields().length * 2));
723                            }
724                            else {
725                                    query = new StringBundler(3);
726                            }
727    
728                            query.append(_SQL_SELECT_ASSETTAGSTATS_WHERE);
729    
730                            query.append(_FINDER_COLUMN_CLASSNAMEID_CLASSNAMEID_2);
731    
732                            if (orderByComparator != null) {
733                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
734                                            orderByComparator);
735                            }
736                            else
737                             if (pagination) {
738                                    query.append(AssetTagStatsModelImpl.ORDER_BY_JPQL);
739                            }
740    
741                            String sql = query.toString();
742    
743                            Session session = null;
744    
745                            try {
746                                    session = openSession();
747    
748                                    Query q = session.createQuery(sql);
749    
750                                    QueryPos qPos = QueryPos.getInstance(q);
751    
752                                    qPos.add(classNameId);
753    
754                                    if (!pagination) {
755                                            list = (List<AssetTagStats>)QueryUtil.list(q, getDialect(),
756                                                            start, end, false);
757    
758                                            Collections.sort(list);
759    
760                                            list = Collections.unmodifiableList(list);
761                                    }
762                                    else {
763                                            list = (List<AssetTagStats>)QueryUtil.list(q, getDialect(),
764                                                            start, end);
765                                    }
766    
767                                    cacheResult(list);
768    
769                                    finderCache.putResult(finderPath, finderArgs, list);
770                            }
771                            catch (Exception e) {
772                                    finderCache.removeResult(finderPath, finderArgs);
773    
774                                    throw processException(e);
775                            }
776                            finally {
777                                    closeSession(session);
778                            }
779                    }
780    
781                    return list;
782            }
783    
784            /**
785             * Returns the first asset tag stats in the ordered set where classNameId = &#63;.
786             *
787             * @param classNameId the class name ID
788             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
789             * @return the first matching asset tag stats
790             * @throws NoSuchTagStatsException if a matching asset tag stats could not be found
791             */
792            @Override
793            public AssetTagStats findByClassNameId_First(long classNameId,
794                    OrderByComparator<AssetTagStats> orderByComparator)
795                    throws NoSuchTagStatsException {
796                    AssetTagStats assetTagStats = fetchByClassNameId_First(classNameId,
797                                    orderByComparator);
798    
799                    if (assetTagStats != null) {
800                            return assetTagStats;
801                    }
802    
803                    StringBundler msg = new StringBundler(4);
804    
805                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
806    
807                    msg.append("classNameId=");
808                    msg.append(classNameId);
809    
810                    msg.append(StringPool.CLOSE_CURLY_BRACE);
811    
812                    throw new NoSuchTagStatsException(msg.toString());
813            }
814    
815            /**
816             * Returns the first asset tag stats in the ordered set where classNameId = &#63;.
817             *
818             * @param classNameId the class name ID
819             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
820             * @return the first matching asset tag stats, or <code>null</code> if a matching asset tag stats could not be found
821             */
822            @Override
823            public AssetTagStats fetchByClassNameId_First(long classNameId,
824                    OrderByComparator<AssetTagStats> orderByComparator) {
825                    List<AssetTagStats> list = findByClassNameId(classNameId, 0, 1,
826                                    orderByComparator);
827    
828                    if (!list.isEmpty()) {
829                            return list.get(0);
830                    }
831    
832                    return null;
833            }
834    
835            /**
836             * Returns the last asset tag stats in the ordered set where classNameId = &#63;.
837             *
838             * @param classNameId the class name ID
839             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
840             * @return the last matching asset tag stats
841             * @throws NoSuchTagStatsException if a matching asset tag stats could not be found
842             */
843            @Override
844            public AssetTagStats findByClassNameId_Last(long classNameId,
845                    OrderByComparator<AssetTagStats> orderByComparator)
846                    throws NoSuchTagStatsException {
847                    AssetTagStats assetTagStats = fetchByClassNameId_Last(classNameId,
848                                    orderByComparator);
849    
850                    if (assetTagStats != null) {
851                            return assetTagStats;
852                    }
853    
854                    StringBundler msg = new StringBundler(4);
855    
856                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
857    
858                    msg.append("classNameId=");
859                    msg.append(classNameId);
860    
861                    msg.append(StringPool.CLOSE_CURLY_BRACE);
862    
863                    throw new NoSuchTagStatsException(msg.toString());
864            }
865    
866            /**
867             * Returns the last asset tag stats in the ordered set where classNameId = &#63;.
868             *
869             * @param classNameId the class name ID
870             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
871             * @return the last matching asset tag stats, or <code>null</code> if a matching asset tag stats could not be found
872             */
873            @Override
874            public AssetTagStats fetchByClassNameId_Last(long classNameId,
875                    OrderByComparator<AssetTagStats> orderByComparator) {
876                    int count = countByClassNameId(classNameId);
877    
878                    if (count == 0) {
879                            return null;
880                    }
881    
882                    List<AssetTagStats> list = findByClassNameId(classNameId, count - 1,
883                                    count, orderByComparator);
884    
885                    if (!list.isEmpty()) {
886                            return list.get(0);
887                    }
888    
889                    return null;
890            }
891    
892            /**
893             * Returns the asset tag statses before and after the current asset tag stats in the ordered set where classNameId = &#63;.
894             *
895             * @param tagStatsId the primary key of the current asset tag stats
896             * @param classNameId the class name ID
897             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
898             * @return the previous, current, and next asset tag stats
899             * @throws NoSuchTagStatsException if a asset tag stats with the primary key could not be found
900             */
901            @Override
902            public AssetTagStats[] findByClassNameId_PrevAndNext(long tagStatsId,
903                    long classNameId, OrderByComparator<AssetTagStats> orderByComparator)
904                    throws NoSuchTagStatsException {
905                    AssetTagStats assetTagStats = findByPrimaryKey(tagStatsId);
906    
907                    Session session = null;
908    
909                    try {
910                            session = openSession();
911    
912                            AssetTagStats[] array = new AssetTagStatsImpl[3];
913    
914                            array[0] = getByClassNameId_PrevAndNext(session, assetTagStats,
915                                            classNameId, orderByComparator, true);
916    
917                            array[1] = assetTagStats;
918    
919                            array[2] = getByClassNameId_PrevAndNext(session, assetTagStats,
920                                            classNameId, orderByComparator, false);
921    
922                            return array;
923                    }
924                    catch (Exception e) {
925                            throw processException(e);
926                    }
927                    finally {
928                            closeSession(session);
929                    }
930            }
931    
932            protected AssetTagStats getByClassNameId_PrevAndNext(Session session,
933                    AssetTagStats assetTagStats, long classNameId,
934                    OrderByComparator<AssetTagStats> orderByComparator, boolean previous) {
935                    StringBundler query = null;
936    
937                    if (orderByComparator != null) {
938                            query = new StringBundler(4 +
939                                            (orderByComparator.getOrderByConditionFields().length * 3) +
940                                            (orderByComparator.getOrderByFields().length * 3));
941                    }
942                    else {
943                            query = new StringBundler(3);
944                    }
945    
946                    query.append(_SQL_SELECT_ASSETTAGSTATS_WHERE);
947    
948                    query.append(_FINDER_COLUMN_CLASSNAMEID_CLASSNAMEID_2);
949    
950                    if (orderByComparator != null) {
951                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
952    
953                            if (orderByConditionFields.length > 0) {
954                                    query.append(WHERE_AND);
955                            }
956    
957                            for (int i = 0; i < orderByConditionFields.length; i++) {
958                                    query.append(_ORDER_BY_ENTITY_ALIAS);
959                                    query.append(orderByConditionFields[i]);
960    
961                                    if ((i + 1) < orderByConditionFields.length) {
962                                            if (orderByComparator.isAscending() ^ previous) {
963                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
964                                            }
965                                            else {
966                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
967                                            }
968                                    }
969                                    else {
970                                            if (orderByComparator.isAscending() ^ previous) {
971                                                    query.append(WHERE_GREATER_THAN);
972                                            }
973                                            else {
974                                                    query.append(WHERE_LESSER_THAN);
975                                            }
976                                    }
977                            }
978    
979                            query.append(ORDER_BY_CLAUSE);
980    
981                            String[] orderByFields = orderByComparator.getOrderByFields();
982    
983                            for (int i = 0; i < orderByFields.length; i++) {
984                                    query.append(_ORDER_BY_ENTITY_ALIAS);
985                                    query.append(orderByFields[i]);
986    
987                                    if ((i + 1) < orderByFields.length) {
988                                            if (orderByComparator.isAscending() ^ previous) {
989                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
990                                            }
991                                            else {
992                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
993                                            }
994                                    }
995                                    else {
996                                            if (orderByComparator.isAscending() ^ previous) {
997                                                    query.append(ORDER_BY_ASC);
998                                            }
999                                            else {
1000                                                    query.append(ORDER_BY_DESC);
1001                                            }
1002                                    }
1003                            }
1004                    }
1005                    else {
1006                            query.append(AssetTagStatsModelImpl.ORDER_BY_JPQL);
1007                    }
1008    
1009                    String sql = query.toString();
1010    
1011                    Query q = session.createQuery(sql);
1012    
1013                    q.setFirstResult(0);
1014                    q.setMaxResults(2);
1015    
1016                    QueryPos qPos = QueryPos.getInstance(q);
1017    
1018                    qPos.add(classNameId);
1019    
1020                    if (orderByComparator != null) {
1021                            Object[] values = orderByComparator.getOrderByConditionValues(assetTagStats);
1022    
1023                            for (Object value : values) {
1024                                    qPos.add(value);
1025                            }
1026                    }
1027    
1028                    List<AssetTagStats> list = q.list();
1029    
1030                    if (list.size() == 2) {
1031                            return list.get(1);
1032                    }
1033                    else {
1034                            return null;
1035                    }
1036            }
1037    
1038            /**
1039             * Removes all the asset tag statses where classNameId = &#63; from the database.
1040             *
1041             * @param classNameId the class name ID
1042             */
1043            @Override
1044            public void removeByClassNameId(long classNameId) {
1045                    for (AssetTagStats assetTagStats : findByClassNameId(classNameId,
1046                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1047                            remove(assetTagStats);
1048                    }
1049            }
1050    
1051            /**
1052             * Returns the number of asset tag statses where classNameId = &#63;.
1053             *
1054             * @param classNameId the class name ID
1055             * @return the number of matching asset tag statses
1056             */
1057            @Override
1058            public int countByClassNameId(long classNameId) {
1059                    FinderPath finderPath = FINDER_PATH_COUNT_BY_CLASSNAMEID;
1060    
1061                    Object[] finderArgs = new Object[] { classNameId };
1062    
1063                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1064    
1065                    if (count == null) {
1066                            StringBundler query = new StringBundler(2);
1067    
1068                            query.append(_SQL_COUNT_ASSETTAGSTATS_WHERE);
1069    
1070                            query.append(_FINDER_COLUMN_CLASSNAMEID_CLASSNAMEID_2);
1071    
1072                            String sql = query.toString();
1073    
1074                            Session session = null;
1075    
1076                            try {
1077                                    session = openSession();
1078    
1079                                    Query q = session.createQuery(sql);
1080    
1081                                    QueryPos qPos = QueryPos.getInstance(q);
1082    
1083                                    qPos.add(classNameId);
1084    
1085                                    count = (Long)q.uniqueResult();
1086    
1087                                    finderCache.putResult(finderPath, finderArgs, count);
1088                            }
1089                            catch (Exception e) {
1090                                    finderCache.removeResult(finderPath, finderArgs);
1091    
1092                                    throw processException(e);
1093                            }
1094                            finally {
1095                                    closeSession(session);
1096                            }
1097                    }
1098    
1099                    return count.intValue();
1100            }
1101    
1102            private static final String _FINDER_COLUMN_CLASSNAMEID_CLASSNAMEID_2 = "assetTagStats.classNameId = ?";
1103            public static final FinderPath FINDER_PATH_FETCH_BY_T_C = new FinderPath(AssetTagStatsModelImpl.ENTITY_CACHE_ENABLED,
1104                            AssetTagStatsModelImpl.FINDER_CACHE_ENABLED,
1105                            AssetTagStatsImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByT_C",
1106                            new String[] { Long.class.getName(), Long.class.getName() },
1107                            AssetTagStatsModelImpl.TAGID_COLUMN_BITMASK |
1108                            AssetTagStatsModelImpl.CLASSNAMEID_COLUMN_BITMASK);
1109            public static final FinderPath FINDER_PATH_COUNT_BY_T_C = new FinderPath(AssetTagStatsModelImpl.ENTITY_CACHE_ENABLED,
1110                            AssetTagStatsModelImpl.FINDER_CACHE_ENABLED, Long.class,
1111                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_C",
1112                            new String[] { Long.class.getName(), Long.class.getName() });
1113    
1114            /**
1115             * Returns the asset tag stats where tagId = &#63; and classNameId = &#63; or throws a {@link NoSuchTagStatsException} if it could not be found.
1116             *
1117             * @param tagId the tag ID
1118             * @param classNameId the class name ID
1119             * @return the matching asset tag stats
1120             * @throws NoSuchTagStatsException if a matching asset tag stats could not be found
1121             */
1122            @Override
1123            public AssetTagStats findByT_C(long tagId, long classNameId)
1124                    throws NoSuchTagStatsException {
1125                    AssetTagStats assetTagStats = fetchByT_C(tagId, classNameId);
1126    
1127                    if (assetTagStats == null) {
1128                            StringBundler msg = new StringBundler(6);
1129    
1130                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1131    
1132                            msg.append("tagId=");
1133                            msg.append(tagId);
1134    
1135                            msg.append(", classNameId=");
1136                            msg.append(classNameId);
1137    
1138                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1139    
1140                            if (_log.isDebugEnabled()) {
1141                                    _log.debug(msg.toString());
1142                            }
1143    
1144                            throw new NoSuchTagStatsException(msg.toString());
1145                    }
1146    
1147                    return assetTagStats;
1148            }
1149    
1150            /**
1151             * Returns the asset tag stats where tagId = &#63; and classNameId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
1152             *
1153             * @param tagId the tag ID
1154             * @param classNameId the class name ID
1155             * @return the matching asset tag stats, or <code>null</code> if a matching asset tag stats could not be found
1156             */
1157            @Override
1158            public AssetTagStats fetchByT_C(long tagId, long classNameId) {
1159                    return fetchByT_C(tagId, classNameId, true);
1160            }
1161    
1162            /**
1163             * Returns the asset tag stats where tagId = &#63; and classNameId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
1164             *
1165             * @param tagId the tag ID
1166             * @param classNameId the class name ID
1167             * @param retrieveFromCache whether to retrieve from the finder cache
1168             * @return the matching asset tag stats, or <code>null</code> if a matching asset tag stats could not be found
1169             */
1170            @Override
1171            public AssetTagStats fetchByT_C(long tagId, long classNameId,
1172                    boolean retrieveFromCache) {
1173                    Object[] finderArgs = new Object[] { tagId, classNameId };
1174    
1175                    Object result = null;
1176    
1177                    if (retrieveFromCache) {
1178                            result = finderCache.getResult(FINDER_PATH_FETCH_BY_T_C,
1179                                            finderArgs, this);
1180                    }
1181    
1182                    if (result instanceof AssetTagStats) {
1183                            AssetTagStats assetTagStats = (AssetTagStats)result;
1184    
1185                            if ((tagId != assetTagStats.getTagId()) ||
1186                                            (classNameId != assetTagStats.getClassNameId())) {
1187                                    result = null;
1188                            }
1189                    }
1190    
1191                    if (result == null) {
1192                            StringBundler query = new StringBundler(4);
1193    
1194                            query.append(_SQL_SELECT_ASSETTAGSTATS_WHERE);
1195    
1196                            query.append(_FINDER_COLUMN_T_C_TAGID_2);
1197    
1198                            query.append(_FINDER_COLUMN_T_C_CLASSNAMEID_2);
1199    
1200                            String sql = query.toString();
1201    
1202                            Session session = null;
1203    
1204                            try {
1205                                    session = openSession();
1206    
1207                                    Query q = session.createQuery(sql);
1208    
1209                                    QueryPos qPos = QueryPos.getInstance(q);
1210    
1211                                    qPos.add(tagId);
1212    
1213                                    qPos.add(classNameId);
1214    
1215                                    List<AssetTagStats> list = q.list();
1216    
1217                                    if (list.isEmpty()) {
1218                                            finderCache.putResult(FINDER_PATH_FETCH_BY_T_C, finderArgs,
1219                                                    list);
1220                                    }
1221                                    else {
1222                                            AssetTagStats assetTagStats = list.get(0);
1223    
1224                                            result = assetTagStats;
1225    
1226                                            cacheResult(assetTagStats);
1227    
1228                                            if ((assetTagStats.getTagId() != tagId) ||
1229                                                            (assetTagStats.getClassNameId() != classNameId)) {
1230                                                    finderCache.putResult(FINDER_PATH_FETCH_BY_T_C,
1231                                                            finderArgs, assetTagStats);
1232                                            }
1233                                    }
1234                            }
1235                            catch (Exception e) {
1236                                    finderCache.removeResult(FINDER_PATH_FETCH_BY_T_C, finderArgs);
1237    
1238                                    throw processException(e);
1239                            }
1240                            finally {
1241                                    closeSession(session);
1242                            }
1243                    }
1244    
1245                    if (result instanceof List<?>) {
1246                            return null;
1247                    }
1248                    else {
1249                            return (AssetTagStats)result;
1250                    }
1251            }
1252    
1253            /**
1254             * Removes the asset tag stats where tagId = &#63; and classNameId = &#63; from the database.
1255             *
1256             * @param tagId the tag ID
1257             * @param classNameId the class name ID
1258             * @return the asset tag stats that was removed
1259             */
1260            @Override
1261            public AssetTagStats removeByT_C(long tagId, long classNameId)
1262                    throws NoSuchTagStatsException {
1263                    AssetTagStats assetTagStats = findByT_C(tagId, classNameId);
1264    
1265                    return remove(assetTagStats);
1266            }
1267    
1268            /**
1269             * Returns the number of asset tag statses where tagId = &#63; and classNameId = &#63;.
1270             *
1271             * @param tagId the tag ID
1272             * @param classNameId the class name ID
1273             * @return the number of matching asset tag statses
1274             */
1275            @Override
1276            public int countByT_C(long tagId, long classNameId) {
1277                    FinderPath finderPath = FINDER_PATH_COUNT_BY_T_C;
1278    
1279                    Object[] finderArgs = new Object[] { tagId, classNameId };
1280    
1281                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1282    
1283                    if (count == null) {
1284                            StringBundler query = new StringBundler(3);
1285    
1286                            query.append(_SQL_COUNT_ASSETTAGSTATS_WHERE);
1287    
1288                            query.append(_FINDER_COLUMN_T_C_TAGID_2);
1289    
1290                            query.append(_FINDER_COLUMN_T_C_CLASSNAMEID_2);
1291    
1292                            String sql = query.toString();
1293    
1294                            Session session = null;
1295    
1296                            try {
1297                                    session = openSession();
1298    
1299                                    Query q = session.createQuery(sql);
1300    
1301                                    QueryPos qPos = QueryPos.getInstance(q);
1302    
1303                                    qPos.add(tagId);
1304    
1305                                    qPos.add(classNameId);
1306    
1307                                    count = (Long)q.uniqueResult();
1308    
1309                                    finderCache.putResult(finderPath, finderArgs, count);
1310                            }
1311                            catch (Exception e) {
1312                                    finderCache.removeResult(finderPath, finderArgs);
1313    
1314                                    throw processException(e);
1315                            }
1316                            finally {
1317                                    closeSession(session);
1318                            }
1319                    }
1320    
1321                    return count.intValue();
1322            }
1323    
1324            private static final String _FINDER_COLUMN_T_C_TAGID_2 = "assetTagStats.tagId = ? AND ";
1325            private static final String _FINDER_COLUMN_T_C_CLASSNAMEID_2 = "assetTagStats.classNameId = ?";
1326    
1327            public AssetTagStatsPersistenceImpl() {
1328                    setModelClass(AssetTagStats.class);
1329            }
1330    
1331            /**
1332             * Caches the asset tag stats in the entity cache if it is enabled.
1333             *
1334             * @param assetTagStats the asset tag stats
1335             */
1336            @Override
1337            public void cacheResult(AssetTagStats assetTagStats) {
1338                    entityCache.putResult(AssetTagStatsModelImpl.ENTITY_CACHE_ENABLED,
1339                            AssetTagStatsImpl.class, assetTagStats.getPrimaryKey(),
1340                            assetTagStats);
1341    
1342                    finderCache.putResult(FINDER_PATH_FETCH_BY_T_C,
1343                            new Object[] {
1344                                    assetTagStats.getTagId(), assetTagStats.getClassNameId()
1345                            }, assetTagStats);
1346    
1347                    assetTagStats.resetOriginalValues();
1348            }
1349    
1350            /**
1351             * Caches the asset tag statses in the entity cache if it is enabled.
1352             *
1353             * @param assetTagStatses the asset tag statses
1354             */
1355            @Override
1356            public void cacheResult(List<AssetTagStats> assetTagStatses) {
1357                    for (AssetTagStats assetTagStats : assetTagStatses) {
1358                            if (entityCache.getResult(
1359                                                    AssetTagStatsModelImpl.ENTITY_CACHE_ENABLED,
1360                                                    AssetTagStatsImpl.class, assetTagStats.getPrimaryKey()) == null) {
1361                                    cacheResult(assetTagStats);
1362                            }
1363                            else {
1364                                    assetTagStats.resetOriginalValues();
1365                            }
1366                    }
1367            }
1368    
1369            /**
1370             * Clears the cache for all asset tag statses.
1371             *
1372             * <p>
1373             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
1374             * </p>
1375             */
1376            @Override
1377            public void clearCache() {
1378                    entityCache.clearCache(AssetTagStatsImpl.class);
1379    
1380                    finderCache.clearCache(FINDER_CLASS_NAME_ENTITY);
1381                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1382                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1383            }
1384    
1385            /**
1386             * Clears the cache for the asset tag stats.
1387             *
1388             * <p>
1389             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
1390             * </p>
1391             */
1392            @Override
1393            public void clearCache(AssetTagStats assetTagStats) {
1394                    entityCache.removeResult(AssetTagStatsModelImpl.ENTITY_CACHE_ENABLED,
1395                            AssetTagStatsImpl.class, assetTagStats.getPrimaryKey());
1396    
1397                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1398                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1399    
1400                    clearUniqueFindersCache((AssetTagStatsModelImpl)assetTagStats);
1401            }
1402    
1403            @Override
1404            public void clearCache(List<AssetTagStats> assetTagStatses) {
1405                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1406                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1407    
1408                    for (AssetTagStats assetTagStats : assetTagStatses) {
1409                            entityCache.removeResult(AssetTagStatsModelImpl.ENTITY_CACHE_ENABLED,
1410                                    AssetTagStatsImpl.class, assetTagStats.getPrimaryKey());
1411    
1412                            clearUniqueFindersCache((AssetTagStatsModelImpl)assetTagStats);
1413                    }
1414            }
1415    
1416            protected void cacheUniqueFindersCache(
1417                    AssetTagStatsModelImpl assetTagStatsModelImpl, boolean isNew) {
1418                    if (isNew) {
1419                            Object[] args = new Object[] {
1420                                            assetTagStatsModelImpl.getTagId(),
1421                                            assetTagStatsModelImpl.getClassNameId()
1422                                    };
1423    
1424                            finderCache.putResult(FINDER_PATH_COUNT_BY_T_C, args,
1425                                    Long.valueOf(1));
1426                            finderCache.putResult(FINDER_PATH_FETCH_BY_T_C, args,
1427                                    assetTagStatsModelImpl);
1428                    }
1429                    else {
1430                            if ((assetTagStatsModelImpl.getColumnBitmask() &
1431                                            FINDER_PATH_FETCH_BY_T_C.getColumnBitmask()) != 0) {
1432                                    Object[] args = new Object[] {
1433                                                    assetTagStatsModelImpl.getTagId(),
1434                                                    assetTagStatsModelImpl.getClassNameId()
1435                                            };
1436    
1437                                    finderCache.putResult(FINDER_PATH_COUNT_BY_T_C, args,
1438                                            Long.valueOf(1));
1439                                    finderCache.putResult(FINDER_PATH_FETCH_BY_T_C, args,
1440                                            assetTagStatsModelImpl);
1441                            }
1442                    }
1443            }
1444    
1445            protected void clearUniqueFindersCache(
1446                    AssetTagStatsModelImpl assetTagStatsModelImpl) {
1447                    Object[] args = new Object[] {
1448                                    assetTagStatsModelImpl.getTagId(),
1449                                    assetTagStatsModelImpl.getClassNameId()
1450                            };
1451    
1452                    finderCache.removeResult(FINDER_PATH_COUNT_BY_T_C, args);
1453                    finderCache.removeResult(FINDER_PATH_FETCH_BY_T_C, args);
1454    
1455                    if ((assetTagStatsModelImpl.getColumnBitmask() &
1456                                    FINDER_PATH_FETCH_BY_T_C.getColumnBitmask()) != 0) {
1457                            args = new Object[] {
1458                                            assetTagStatsModelImpl.getOriginalTagId(),
1459                                            assetTagStatsModelImpl.getOriginalClassNameId()
1460                                    };
1461    
1462                            finderCache.removeResult(FINDER_PATH_COUNT_BY_T_C, args);
1463                            finderCache.removeResult(FINDER_PATH_FETCH_BY_T_C, args);
1464                    }
1465            }
1466    
1467            /**
1468             * Creates a new asset tag stats with the primary key. Does not add the asset tag stats to the database.
1469             *
1470             * @param tagStatsId the primary key for the new asset tag stats
1471             * @return the new asset tag stats
1472             */
1473            @Override
1474            public AssetTagStats create(long tagStatsId) {
1475                    AssetTagStats assetTagStats = new AssetTagStatsImpl();
1476    
1477                    assetTagStats.setNew(true);
1478                    assetTagStats.setPrimaryKey(tagStatsId);
1479    
1480                    assetTagStats.setCompanyId(companyProvider.getCompanyId());
1481    
1482                    return assetTagStats;
1483            }
1484    
1485            /**
1486             * Removes the asset tag stats with the primary key from the database. Also notifies the appropriate model listeners.
1487             *
1488             * @param tagStatsId the primary key of the asset tag stats
1489             * @return the asset tag stats that was removed
1490             * @throws NoSuchTagStatsException if a asset tag stats with the primary key could not be found
1491             */
1492            @Override
1493            public AssetTagStats remove(long tagStatsId) throws NoSuchTagStatsException {
1494                    return remove((Serializable)tagStatsId);
1495            }
1496    
1497            /**
1498             * Removes the asset tag stats with the primary key from the database. Also notifies the appropriate model listeners.
1499             *
1500             * @param primaryKey the primary key of the asset tag stats
1501             * @return the asset tag stats that was removed
1502             * @throws NoSuchTagStatsException if a asset tag stats with the primary key could not be found
1503             */
1504            @Override
1505            public AssetTagStats remove(Serializable primaryKey)
1506                    throws NoSuchTagStatsException {
1507                    Session session = null;
1508    
1509                    try {
1510                            session = openSession();
1511    
1512                            AssetTagStats assetTagStats = (AssetTagStats)session.get(AssetTagStatsImpl.class,
1513                                            primaryKey);
1514    
1515                            if (assetTagStats == null) {
1516                                    if (_log.isDebugEnabled()) {
1517                                            _log.debug(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1518                                    }
1519    
1520                                    throw new NoSuchTagStatsException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1521                                            primaryKey);
1522                            }
1523    
1524                            return remove(assetTagStats);
1525                    }
1526                    catch (NoSuchTagStatsException nsee) {
1527                            throw nsee;
1528                    }
1529                    catch (Exception e) {
1530                            throw processException(e);
1531                    }
1532                    finally {
1533                            closeSession(session);
1534                    }
1535            }
1536    
1537            @Override
1538            protected AssetTagStats removeImpl(AssetTagStats assetTagStats) {
1539                    assetTagStats = toUnwrappedModel(assetTagStats);
1540    
1541                    Session session = null;
1542    
1543                    try {
1544                            session = openSession();
1545    
1546                            if (!session.contains(assetTagStats)) {
1547                                    assetTagStats = (AssetTagStats)session.get(AssetTagStatsImpl.class,
1548                                                    assetTagStats.getPrimaryKeyObj());
1549                            }
1550    
1551                            if (assetTagStats != null) {
1552                                    session.delete(assetTagStats);
1553                            }
1554                    }
1555                    catch (Exception e) {
1556                            throw processException(e);
1557                    }
1558                    finally {
1559                            closeSession(session);
1560                    }
1561    
1562                    if (assetTagStats != null) {
1563                            clearCache(assetTagStats);
1564                    }
1565    
1566                    return assetTagStats;
1567            }
1568    
1569            @Override
1570            public AssetTagStats updateImpl(AssetTagStats assetTagStats) {
1571                    assetTagStats = toUnwrappedModel(assetTagStats);
1572    
1573                    boolean isNew = assetTagStats.isNew();
1574    
1575                    AssetTagStatsModelImpl assetTagStatsModelImpl = (AssetTagStatsModelImpl)assetTagStats;
1576    
1577                    Session session = null;
1578    
1579                    try {
1580                            session = openSession();
1581    
1582                            if (assetTagStats.isNew()) {
1583                                    session.save(assetTagStats);
1584    
1585                                    assetTagStats.setNew(false);
1586                            }
1587                            else {
1588                                    assetTagStats = (AssetTagStats)session.merge(assetTagStats);
1589                            }
1590                    }
1591                    catch (Exception e) {
1592                            throw processException(e);
1593                    }
1594                    finally {
1595                            closeSession(session);
1596                    }
1597    
1598                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1599    
1600                    if (isNew || !AssetTagStatsModelImpl.COLUMN_BITMASK_ENABLED) {
1601                            finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1602                    }
1603    
1604                    else {
1605                            if ((assetTagStatsModelImpl.getColumnBitmask() &
1606                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TAGID.getColumnBitmask()) != 0) {
1607                                    Object[] args = new Object[] {
1608                                                    assetTagStatsModelImpl.getOriginalTagId()
1609                                            };
1610    
1611                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_TAGID, args);
1612                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TAGID,
1613                                            args);
1614    
1615                                    args = new Object[] { assetTagStatsModelImpl.getTagId() };
1616    
1617                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_TAGID, args);
1618                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TAGID,
1619                                            args);
1620                            }
1621    
1622                            if ((assetTagStatsModelImpl.getColumnBitmask() &
1623                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLASSNAMEID.getColumnBitmask()) != 0) {
1624                                    Object[] args = new Object[] {
1625                                                    assetTagStatsModelImpl.getOriginalClassNameId()
1626                                            };
1627    
1628                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_CLASSNAMEID, args);
1629                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLASSNAMEID,
1630                                            args);
1631    
1632                                    args = new Object[] { assetTagStatsModelImpl.getClassNameId() };
1633    
1634                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_CLASSNAMEID, args);
1635                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLASSNAMEID,
1636                                            args);
1637                            }
1638                    }
1639    
1640                    entityCache.putResult(AssetTagStatsModelImpl.ENTITY_CACHE_ENABLED,
1641                            AssetTagStatsImpl.class, assetTagStats.getPrimaryKey(),
1642                            assetTagStats, false);
1643    
1644                    clearUniqueFindersCache(assetTagStatsModelImpl);
1645                    cacheUniqueFindersCache(assetTagStatsModelImpl, isNew);
1646    
1647                    assetTagStats.resetOriginalValues();
1648    
1649                    return assetTagStats;
1650            }
1651    
1652            protected AssetTagStats toUnwrappedModel(AssetTagStats assetTagStats) {
1653                    if (assetTagStats instanceof AssetTagStatsImpl) {
1654                            return assetTagStats;
1655                    }
1656    
1657                    AssetTagStatsImpl assetTagStatsImpl = new AssetTagStatsImpl();
1658    
1659                    assetTagStatsImpl.setNew(assetTagStats.isNew());
1660                    assetTagStatsImpl.setPrimaryKey(assetTagStats.getPrimaryKey());
1661    
1662                    assetTagStatsImpl.setTagStatsId(assetTagStats.getTagStatsId());
1663                    assetTagStatsImpl.setCompanyId(assetTagStats.getCompanyId());
1664                    assetTagStatsImpl.setTagId(assetTagStats.getTagId());
1665                    assetTagStatsImpl.setClassNameId(assetTagStats.getClassNameId());
1666                    assetTagStatsImpl.setAssetCount(assetTagStats.getAssetCount());
1667    
1668                    return assetTagStatsImpl;
1669            }
1670    
1671            /**
1672             * Returns the asset tag stats with the primary key or throws a {@link com.liferay.portal.kernel.exception.NoSuchModelException} if it could not be found.
1673             *
1674             * @param primaryKey the primary key of the asset tag stats
1675             * @return the asset tag stats
1676             * @throws NoSuchTagStatsException if a asset tag stats with the primary key could not be found
1677             */
1678            @Override
1679            public AssetTagStats findByPrimaryKey(Serializable primaryKey)
1680                    throws NoSuchTagStatsException {
1681                    AssetTagStats assetTagStats = fetchByPrimaryKey(primaryKey);
1682    
1683                    if (assetTagStats == null) {
1684                            if (_log.isDebugEnabled()) {
1685                                    _log.debug(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1686                            }
1687    
1688                            throw new NoSuchTagStatsException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1689                                    primaryKey);
1690                    }
1691    
1692                    return assetTagStats;
1693            }
1694    
1695            /**
1696             * Returns the asset tag stats with the primary key or throws a {@link NoSuchTagStatsException} if it could not be found.
1697             *
1698             * @param tagStatsId the primary key of the asset tag stats
1699             * @return the asset tag stats
1700             * @throws NoSuchTagStatsException if a asset tag stats with the primary key could not be found
1701             */
1702            @Override
1703            public AssetTagStats findByPrimaryKey(long tagStatsId)
1704                    throws NoSuchTagStatsException {
1705                    return findByPrimaryKey((Serializable)tagStatsId);
1706            }
1707    
1708            /**
1709             * Returns the asset tag stats with the primary key or returns <code>null</code> if it could not be found.
1710             *
1711             * @param primaryKey the primary key of the asset tag stats
1712             * @return the asset tag stats, or <code>null</code> if a asset tag stats with the primary key could not be found
1713             */
1714            @Override
1715            public AssetTagStats fetchByPrimaryKey(Serializable primaryKey) {
1716                    AssetTagStats assetTagStats = (AssetTagStats)entityCache.getResult(AssetTagStatsModelImpl.ENTITY_CACHE_ENABLED,
1717                                    AssetTagStatsImpl.class, primaryKey);
1718    
1719                    if (assetTagStats == _nullAssetTagStats) {
1720                            return null;
1721                    }
1722    
1723                    if (assetTagStats == null) {
1724                            Session session = null;
1725    
1726                            try {
1727                                    session = openSession();
1728    
1729                                    assetTagStats = (AssetTagStats)session.get(AssetTagStatsImpl.class,
1730                                                    primaryKey);
1731    
1732                                    if (assetTagStats != null) {
1733                                            cacheResult(assetTagStats);
1734                                    }
1735                                    else {
1736                                            entityCache.putResult(AssetTagStatsModelImpl.ENTITY_CACHE_ENABLED,
1737                                                    AssetTagStatsImpl.class, primaryKey, _nullAssetTagStats);
1738                                    }
1739                            }
1740                            catch (Exception e) {
1741                                    entityCache.removeResult(AssetTagStatsModelImpl.ENTITY_CACHE_ENABLED,
1742                                            AssetTagStatsImpl.class, primaryKey);
1743    
1744                                    throw processException(e);
1745                            }
1746                            finally {
1747                                    closeSession(session);
1748                            }
1749                    }
1750    
1751                    return assetTagStats;
1752            }
1753    
1754            /**
1755             * Returns the asset tag stats with the primary key or returns <code>null</code> if it could not be found.
1756             *
1757             * @param tagStatsId the primary key of the asset tag stats
1758             * @return the asset tag stats, or <code>null</code> if a asset tag stats with the primary key could not be found
1759             */
1760            @Override
1761            public AssetTagStats fetchByPrimaryKey(long tagStatsId) {
1762                    return fetchByPrimaryKey((Serializable)tagStatsId);
1763            }
1764    
1765            @Override
1766            public Map<Serializable, AssetTagStats> fetchByPrimaryKeys(
1767                    Set<Serializable> primaryKeys) {
1768                    if (primaryKeys.isEmpty()) {
1769                            return Collections.emptyMap();
1770                    }
1771    
1772                    Map<Serializable, AssetTagStats> map = new HashMap<Serializable, AssetTagStats>();
1773    
1774                    if (primaryKeys.size() == 1) {
1775                            Iterator<Serializable> iterator = primaryKeys.iterator();
1776    
1777                            Serializable primaryKey = iterator.next();
1778    
1779                            AssetTagStats assetTagStats = fetchByPrimaryKey(primaryKey);
1780    
1781                            if (assetTagStats != null) {
1782                                    map.put(primaryKey, assetTagStats);
1783                            }
1784    
1785                            return map;
1786                    }
1787    
1788                    Set<Serializable> uncachedPrimaryKeys = null;
1789    
1790                    for (Serializable primaryKey : primaryKeys) {
1791                            AssetTagStats assetTagStats = (AssetTagStats)entityCache.getResult(AssetTagStatsModelImpl.ENTITY_CACHE_ENABLED,
1792                                            AssetTagStatsImpl.class, primaryKey);
1793    
1794                            if (assetTagStats == null) {
1795                                    if (uncachedPrimaryKeys == null) {
1796                                            uncachedPrimaryKeys = new HashSet<Serializable>();
1797                                    }
1798    
1799                                    uncachedPrimaryKeys.add(primaryKey);
1800                            }
1801                            else {
1802                                    map.put(primaryKey, assetTagStats);
1803                            }
1804                    }
1805    
1806                    if (uncachedPrimaryKeys == null) {
1807                            return map;
1808                    }
1809    
1810                    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
1811                                    1);
1812    
1813                    query.append(_SQL_SELECT_ASSETTAGSTATS_WHERE_PKS_IN);
1814    
1815                    for (Serializable primaryKey : uncachedPrimaryKeys) {
1816                            query.append(String.valueOf(primaryKey));
1817    
1818                            query.append(StringPool.COMMA);
1819                    }
1820    
1821                    query.setIndex(query.index() - 1);
1822    
1823                    query.append(StringPool.CLOSE_PARENTHESIS);
1824    
1825                    String sql = query.toString();
1826    
1827                    Session session = null;
1828    
1829                    try {
1830                            session = openSession();
1831    
1832                            Query q = session.createQuery(sql);
1833    
1834                            for (AssetTagStats assetTagStats : (List<AssetTagStats>)q.list()) {
1835                                    map.put(assetTagStats.getPrimaryKeyObj(), assetTagStats);
1836    
1837                                    cacheResult(assetTagStats);
1838    
1839                                    uncachedPrimaryKeys.remove(assetTagStats.getPrimaryKeyObj());
1840                            }
1841    
1842                            for (Serializable primaryKey : uncachedPrimaryKeys) {
1843                                    entityCache.putResult(AssetTagStatsModelImpl.ENTITY_CACHE_ENABLED,
1844                                            AssetTagStatsImpl.class, primaryKey, _nullAssetTagStats);
1845                            }
1846                    }
1847                    catch (Exception e) {
1848                            throw processException(e);
1849                    }
1850                    finally {
1851                            closeSession(session);
1852                    }
1853    
1854                    return map;
1855            }
1856    
1857            /**
1858             * Returns all the asset tag statses.
1859             *
1860             * @return the asset tag statses
1861             */
1862            @Override
1863            public List<AssetTagStats> findAll() {
1864                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1865            }
1866    
1867            /**
1868             * Returns a range of all the asset tag statses.
1869             *
1870             * <p>
1871             * 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 AssetTagStatsModelImpl}. 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.
1872             * </p>
1873             *
1874             * @param start the lower bound of the range of asset tag statses
1875             * @param end the upper bound of the range of asset tag statses (not inclusive)
1876             * @return the range of asset tag statses
1877             */
1878            @Override
1879            public List<AssetTagStats> findAll(int start, int end) {
1880                    return findAll(start, end, null);
1881            }
1882    
1883            /**
1884             * Returns an ordered range of all the asset tag statses.
1885             *
1886             * <p>
1887             * 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 AssetTagStatsModelImpl}. 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.
1888             * </p>
1889             *
1890             * @param start the lower bound of the range of asset tag statses
1891             * @param end the upper bound of the range of asset tag statses (not inclusive)
1892             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1893             * @return the ordered range of asset tag statses
1894             */
1895            @Override
1896            public List<AssetTagStats> findAll(int start, int end,
1897                    OrderByComparator<AssetTagStats> orderByComparator) {
1898                    return findAll(start, end, orderByComparator, true);
1899            }
1900    
1901            /**
1902             * Returns an ordered range of all the asset tag statses.
1903             *
1904             * <p>
1905             * 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 AssetTagStatsModelImpl}. 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.
1906             * </p>
1907             *
1908             * @param start the lower bound of the range of asset tag statses
1909             * @param end the upper bound of the range of asset tag statses (not inclusive)
1910             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1911             * @param retrieveFromCache whether to retrieve from the finder cache
1912             * @return the ordered range of asset tag statses
1913             */
1914            @Override
1915            public List<AssetTagStats> findAll(int start, int end,
1916                    OrderByComparator<AssetTagStats> orderByComparator,
1917                    boolean retrieveFromCache) {
1918                    boolean pagination = true;
1919                    FinderPath finderPath = null;
1920                    Object[] finderArgs = null;
1921    
1922                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1923                                    (orderByComparator == null)) {
1924                            pagination = false;
1925                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1926                            finderArgs = FINDER_ARGS_EMPTY;
1927                    }
1928                    else {
1929                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1930                            finderArgs = new Object[] { start, end, orderByComparator };
1931                    }
1932    
1933                    List<AssetTagStats> list = null;
1934    
1935                    if (retrieveFromCache) {
1936                            list = (List<AssetTagStats>)finderCache.getResult(finderPath,
1937                                            finderArgs, this);
1938                    }
1939    
1940                    if (list == null) {
1941                            StringBundler query = null;
1942                            String sql = null;
1943    
1944                            if (orderByComparator != null) {
1945                                    query = new StringBundler(2 +
1946                                                    (orderByComparator.getOrderByFields().length * 2));
1947    
1948                                    query.append(_SQL_SELECT_ASSETTAGSTATS);
1949    
1950                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1951                                            orderByComparator);
1952    
1953                                    sql = query.toString();
1954                            }
1955                            else {
1956                                    sql = _SQL_SELECT_ASSETTAGSTATS;
1957    
1958                                    if (pagination) {
1959                                            sql = sql.concat(AssetTagStatsModelImpl.ORDER_BY_JPQL);
1960                                    }
1961                            }
1962    
1963                            Session session = null;
1964    
1965                            try {
1966                                    session = openSession();
1967    
1968                                    Query q = session.createQuery(sql);
1969    
1970                                    if (!pagination) {
1971                                            list = (List<AssetTagStats>)QueryUtil.list(q, getDialect(),
1972                                                            start, end, false);
1973    
1974                                            Collections.sort(list);
1975    
1976                                            list = Collections.unmodifiableList(list);
1977                                    }
1978                                    else {
1979                                            list = (List<AssetTagStats>)QueryUtil.list(q, getDialect(),
1980                                                            start, end);
1981                                    }
1982    
1983                                    cacheResult(list);
1984    
1985                                    finderCache.putResult(finderPath, finderArgs, list);
1986                            }
1987                            catch (Exception e) {
1988                                    finderCache.removeResult(finderPath, finderArgs);
1989    
1990                                    throw processException(e);
1991                            }
1992                            finally {
1993                                    closeSession(session);
1994                            }
1995                    }
1996    
1997                    return list;
1998            }
1999    
2000            /**
2001             * Removes all the asset tag statses from the database.
2002             *
2003             */
2004            @Override
2005            public void removeAll() {
2006                    for (AssetTagStats assetTagStats : findAll()) {
2007                            remove(assetTagStats);
2008                    }
2009            }
2010    
2011            /**
2012             * Returns the number of asset tag statses.
2013             *
2014             * @return the number of asset tag statses
2015             */
2016            @Override
2017            public int countAll() {
2018                    Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL,
2019                                    FINDER_ARGS_EMPTY, this);
2020    
2021                    if (count == null) {
2022                            Session session = null;
2023    
2024                            try {
2025                                    session = openSession();
2026    
2027                                    Query q = session.createQuery(_SQL_COUNT_ASSETTAGSTATS);
2028    
2029                                    count = (Long)q.uniqueResult();
2030    
2031                                    finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY,
2032                                            count);
2033                            }
2034                            catch (Exception e) {
2035                                    finderCache.removeResult(FINDER_PATH_COUNT_ALL,
2036                                            FINDER_ARGS_EMPTY);
2037    
2038                                    throw processException(e);
2039                            }
2040                            finally {
2041                                    closeSession(session);
2042                            }
2043                    }
2044    
2045                    return count.intValue();
2046            }
2047    
2048            @Override
2049            protected Map<String, Integer> getTableColumnsMap() {
2050                    return AssetTagStatsModelImpl.TABLE_COLUMNS_MAP;
2051            }
2052    
2053            /**
2054             * Initializes the asset tag stats persistence.
2055             */
2056            public void afterPropertiesSet() {
2057            }
2058    
2059            public void destroy() {
2060                    entityCache.removeCache(AssetTagStatsImpl.class.getName());
2061                    finderCache.removeCache(FINDER_CLASS_NAME_ENTITY);
2062                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2063                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2064            }
2065    
2066            @BeanReference(type = CompanyProviderWrapper.class)
2067            protected CompanyProvider companyProvider;
2068            protected EntityCache entityCache = EntityCacheUtil.getEntityCache();
2069            protected FinderCache finderCache = FinderCacheUtil.getFinderCache();
2070            private static final String _SQL_SELECT_ASSETTAGSTATS = "SELECT assetTagStats FROM AssetTagStats assetTagStats";
2071            private static final String _SQL_SELECT_ASSETTAGSTATS_WHERE_PKS_IN = "SELECT assetTagStats FROM AssetTagStats assetTagStats WHERE tagStatsId IN (";
2072            private static final String _SQL_SELECT_ASSETTAGSTATS_WHERE = "SELECT assetTagStats FROM AssetTagStats assetTagStats WHERE ";
2073            private static final String _SQL_COUNT_ASSETTAGSTATS = "SELECT COUNT(assetTagStats) FROM AssetTagStats assetTagStats";
2074            private static final String _SQL_COUNT_ASSETTAGSTATS_WHERE = "SELECT COUNT(assetTagStats) FROM AssetTagStats assetTagStats WHERE ";
2075            private static final String _ORDER_BY_ENTITY_ALIAS = "assetTagStats.";
2076            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No AssetTagStats exists with the primary key ";
2077            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No AssetTagStats exists with the key {";
2078            private static final Log _log = LogFactoryUtil.getLog(AssetTagStatsPersistenceImpl.class);
2079            private static final AssetTagStats _nullAssetTagStats = new AssetTagStatsImpl() {
2080                            @Override
2081                            public Object clone() {
2082                                    return this;
2083                            }
2084    
2085                            @Override
2086                            public CacheModel<AssetTagStats> toCacheModel() {
2087                                    return _nullAssetTagStatsCacheModel;
2088                            }
2089                    };
2090    
2091            private static final CacheModel<AssetTagStats> _nullAssetTagStatsCacheModel = new CacheModel<AssetTagStats>() {
2092                            @Override
2093                            public AssetTagStats toEntityModel() {
2094                                    return _nullAssetTagStats;
2095                            }
2096                    };
2097    }