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