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