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