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