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