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