001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
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.getOriginalTagId()),
273                                    new Long(assetTagStatsModelImpl.getOriginalClassNameId())
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                            Session session = null;
497    
498                            try {
499                                    session = openSession();
500    
501                                    StringBundler query = null;
502    
503                                    if (orderByComparator != null) {
504                                            query = new StringBundler(3 +
505                                                            (orderByComparator.getOrderByFields().length * 3));
506                                    }
507                                    else {
508                                            query = new StringBundler(3);
509                                    }
510    
511                                    query.append(_SQL_SELECT_ASSETTAGSTATS_WHERE);
512    
513                                    query.append(_FINDER_COLUMN_TAGID_TAGID_2);
514    
515                                    if (orderByComparator != null) {
516                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
517                                                    orderByComparator);
518                                    }
519    
520                                    else {
521                                            query.append(AssetTagStatsModelImpl.ORDER_BY_JPQL);
522                                    }
523    
524                                    String sql = query.toString();
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                                            list = new ArrayList<AssetTagStats>();
541                                    }
542    
543                                    cacheResult(list);
544    
545                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_TAGID,
546                                            finderArgs, list);
547    
548                                    closeSession(session);
549                            }
550                    }
551    
552                    return list;
553            }
554    
555            /**
556             * Finds the first asset tag stats in the ordered set where tagId = &#63;.
557             *
558             * <p>
559             * 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.
560             * </p>
561             *
562             * @param tagId the tag id to search with
563             * @param orderByComparator the comparator to order the set by
564             * @return the first matching asset tag stats
565             * @throws com.liferay.portlet.asset.NoSuchTagStatsException if a matching asset tag stats could not be found
566             * @throws SystemException if a system exception occurred
567             */
568            public AssetTagStats findByTagId_First(long tagId,
569                    OrderByComparator orderByComparator)
570                    throws NoSuchTagStatsException, SystemException {
571                    List<AssetTagStats> list = findByTagId(tagId, 0, 1, orderByComparator);
572    
573                    if (list.isEmpty()) {
574                            StringBundler msg = new StringBundler(4);
575    
576                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
577    
578                            msg.append("tagId=");
579                            msg.append(tagId);
580    
581                            msg.append(StringPool.CLOSE_CURLY_BRACE);
582    
583                            throw new NoSuchTagStatsException(msg.toString());
584                    }
585                    else {
586                            return list.get(0);
587                    }
588            }
589    
590            /**
591             * Finds the last asset tag stats in the ordered set where tagId = &#63;.
592             *
593             * <p>
594             * 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.
595             * </p>
596             *
597             * @param tagId the tag id to search with
598             * @param orderByComparator the comparator to order the set by
599             * @return the last matching asset tag stats
600             * @throws com.liferay.portlet.asset.NoSuchTagStatsException if a matching asset tag stats could not be found
601             * @throws SystemException if a system exception occurred
602             */
603            public AssetTagStats findByTagId_Last(long tagId,
604                    OrderByComparator orderByComparator)
605                    throws NoSuchTagStatsException, SystemException {
606                    int count = countByTagId(tagId);
607    
608                    List<AssetTagStats> list = findByTagId(tagId, count - 1, count,
609                                    orderByComparator);
610    
611                    if (list.isEmpty()) {
612                            StringBundler msg = new StringBundler(4);
613    
614                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
615    
616                            msg.append("tagId=");
617                            msg.append(tagId);
618    
619                            msg.append(StringPool.CLOSE_CURLY_BRACE);
620    
621                            throw new NoSuchTagStatsException(msg.toString());
622                    }
623                    else {
624                            return list.get(0);
625                    }
626            }
627    
628            /**
629             * Finds the asset tag statses before and after the current asset tag stats in the ordered set where tagId = &#63;.
630             *
631             * <p>
632             * 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.
633             * </p>
634             *
635             * @param tagStatsId the primary key of the current asset tag stats
636             * @param tagId the tag id to search with
637             * @param orderByComparator the comparator to order the set by
638             * @return the previous, current, and next asset tag stats
639             * @throws com.liferay.portlet.asset.NoSuchTagStatsException if a asset tag stats with the primary key could not be found
640             * @throws SystemException if a system exception occurred
641             */
642            public AssetTagStats[] findByTagId_PrevAndNext(long tagStatsId, long tagId,
643                    OrderByComparator orderByComparator)
644                    throws NoSuchTagStatsException, SystemException {
645                    AssetTagStats assetTagStats = findByPrimaryKey(tagStatsId);
646    
647                    Session session = null;
648    
649                    try {
650                            session = openSession();
651    
652                            AssetTagStats[] array = new AssetTagStatsImpl[3];
653    
654                            array[0] = getByTagId_PrevAndNext(session, assetTagStats, tagId,
655                                            orderByComparator, true);
656    
657                            array[1] = assetTagStats;
658    
659                            array[2] = getByTagId_PrevAndNext(session, assetTagStats, tagId,
660                                            orderByComparator, false);
661    
662                            return array;
663                    }
664                    catch (Exception e) {
665                            throw processException(e);
666                    }
667                    finally {
668                            closeSession(session);
669                    }
670            }
671    
672            protected AssetTagStats getByTagId_PrevAndNext(Session session,
673                    AssetTagStats assetTagStats, long tagId,
674                    OrderByComparator orderByComparator, boolean previous) {
675                    StringBundler query = null;
676    
677                    if (orderByComparator != null) {
678                            query = new StringBundler(6 +
679                                            (orderByComparator.getOrderByFields().length * 6));
680                    }
681                    else {
682                            query = new StringBundler(3);
683                    }
684    
685                    query.append(_SQL_SELECT_ASSETTAGSTATS_WHERE);
686    
687                    query.append(_FINDER_COLUMN_TAGID_TAGID_2);
688    
689                    if (orderByComparator != null) {
690                            String[] orderByFields = orderByComparator.getOrderByFields();
691    
692                            if (orderByFields.length > 0) {
693                                    query.append(WHERE_AND);
694                            }
695    
696                            for (int i = 0; i < orderByFields.length; i++) {
697                                    query.append(_ORDER_BY_ENTITY_ALIAS);
698                                    query.append(orderByFields[i]);
699    
700                                    if ((i + 1) < orderByFields.length) {
701                                            if (orderByComparator.isAscending() ^ previous) {
702                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
703                                            }
704                                            else {
705                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
706                                            }
707                                    }
708                                    else {
709                                            if (orderByComparator.isAscending() ^ previous) {
710                                                    query.append(WHERE_GREATER_THAN);
711                                            }
712                                            else {
713                                                    query.append(WHERE_LESSER_THAN);
714                                            }
715                                    }
716                            }
717    
718                            query.append(ORDER_BY_CLAUSE);
719    
720                            for (int i = 0; i < orderByFields.length; i++) {
721                                    query.append(_ORDER_BY_ENTITY_ALIAS);
722                                    query.append(orderByFields[i]);
723    
724                                    if ((i + 1) < orderByFields.length) {
725                                            if (orderByComparator.isAscending() ^ previous) {
726                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
727                                            }
728                                            else {
729                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
730                                            }
731                                    }
732                                    else {
733                                            if (orderByComparator.isAscending() ^ previous) {
734                                                    query.append(ORDER_BY_ASC);
735                                            }
736                                            else {
737                                                    query.append(ORDER_BY_DESC);
738                                            }
739                                    }
740                            }
741                    }
742    
743                    else {
744                            query.append(AssetTagStatsModelImpl.ORDER_BY_JPQL);
745                    }
746    
747                    String sql = query.toString();
748    
749                    Query q = session.createQuery(sql);
750    
751                    q.setFirstResult(0);
752                    q.setMaxResults(2);
753    
754                    QueryPos qPos = QueryPos.getInstance(q);
755    
756                    qPos.add(tagId);
757    
758                    if (orderByComparator != null) {
759                            Object[] values = orderByComparator.getOrderByValues(assetTagStats);
760    
761                            for (Object value : values) {
762                                    qPos.add(value);
763                            }
764                    }
765    
766                    List<AssetTagStats> list = q.list();
767    
768                    if (list.size() == 2) {
769                            return list.get(1);
770                    }
771                    else {
772                            return null;
773                    }
774            }
775    
776            /**
777             * Finds all the asset tag statses where classNameId = &#63;.
778             *
779             * @param classNameId the class name id to search with
780             * @return the matching asset tag statses
781             * @throws SystemException if a system exception occurred
782             */
783            public List<AssetTagStats> findByClassNameId(long classNameId)
784                    throws SystemException {
785                    return findByClassNameId(classNameId, QueryUtil.ALL_POS,
786                            QueryUtil.ALL_POS, null);
787            }
788    
789            /**
790             * Finds a range of all the asset tag statses where classNameId = &#63;.
791             *
792             * <p>
793             * 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.
794             * </p>
795             *
796             * @param classNameId the class name id to search with
797             * @param start the lower bound of the range of asset tag statses to return
798             * @param end the upper bound of the range of asset tag statses to return (not inclusive)
799             * @return the range of matching asset tag statses
800             * @throws SystemException if a system exception occurred
801             */
802            public List<AssetTagStats> findByClassNameId(long classNameId, int start,
803                    int end) throws SystemException {
804                    return findByClassNameId(classNameId, start, end, null);
805            }
806    
807            /**
808             * Finds an ordered range of all the asset tag statses where classNameId = &#63;.
809             *
810             * <p>
811             * 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.
812             * </p>
813             *
814             * @param classNameId the class name id to search with
815             * @param start the lower bound of the range of asset tag statses to return
816             * @param end the upper bound of the range of asset tag statses to return (not inclusive)
817             * @param orderByComparator the comparator to order the results by
818             * @return the ordered range of matching asset tag statses
819             * @throws SystemException if a system exception occurred
820             */
821            public List<AssetTagStats> findByClassNameId(long classNameId, int start,
822                    int end, OrderByComparator orderByComparator) throws SystemException {
823                    Object[] finderArgs = new Object[] {
824                                    classNameId,
825                                    
826                                    String.valueOf(start), String.valueOf(end),
827                                    String.valueOf(orderByComparator)
828                            };
829    
830                    List<AssetTagStats> list = (List<AssetTagStats>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_CLASSNAMEID,
831                                    finderArgs, this);
832    
833                    if (list == null) {
834                            Session session = null;
835    
836                            try {
837                                    session = openSession();
838    
839                                    StringBundler query = null;
840    
841                                    if (orderByComparator != null) {
842                                            query = new StringBundler(3 +
843                                                            (orderByComparator.getOrderByFields().length * 3));
844                                    }
845                                    else {
846                                            query = new StringBundler(3);
847                                    }
848    
849                                    query.append(_SQL_SELECT_ASSETTAGSTATS_WHERE);
850    
851                                    query.append(_FINDER_COLUMN_CLASSNAMEID_CLASSNAMEID_2);
852    
853                                    if (orderByComparator != null) {
854                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
855                                                    orderByComparator);
856                                    }
857    
858                                    else {
859                                            query.append(AssetTagStatsModelImpl.ORDER_BY_JPQL);
860                                    }
861    
862                                    String sql = query.toString();
863    
864                                    Query q = session.createQuery(sql);
865    
866                                    QueryPos qPos = QueryPos.getInstance(q);
867    
868                                    qPos.add(classNameId);
869    
870                                    list = (List<AssetTagStats>)QueryUtil.list(q, getDialect(),
871                                                    start, end);
872                            }
873                            catch (Exception e) {
874                                    throw processException(e);
875                            }
876                            finally {
877                                    if (list == null) {
878                                            list = new ArrayList<AssetTagStats>();
879                                    }
880    
881                                    cacheResult(list);
882    
883                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_CLASSNAMEID,
884                                            finderArgs, list);
885    
886                                    closeSession(session);
887                            }
888                    }
889    
890                    return list;
891            }
892    
893            /**
894             * Finds the first asset tag stats in the ordered set where classNameId = &#63;.
895             *
896             * <p>
897             * 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.
898             * </p>
899             *
900             * @param classNameId the class name id to search with
901             * @param orderByComparator the comparator to order the set by
902             * @return the first matching asset tag stats
903             * @throws com.liferay.portlet.asset.NoSuchTagStatsException if a matching asset tag stats could not be found
904             * @throws SystemException if a system exception occurred
905             */
906            public AssetTagStats findByClassNameId_First(long classNameId,
907                    OrderByComparator orderByComparator)
908                    throws NoSuchTagStatsException, SystemException {
909                    List<AssetTagStats> list = findByClassNameId(classNameId, 0, 1,
910                                    orderByComparator);
911    
912                    if (list.isEmpty()) {
913                            StringBundler msg = new StringBundler(4);
914    
915                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
916    
917                            msg.append("classNameId=");
918                            msg.append(classNameId);
919    
920                            msg.append(StringPool.CLOSE_CURLY_BRACE);
921    
922                            throw new NoSuchTagStatsException(msg.toString());
923                    }
924                    else {
925                            return list.get(0);
926                    }
927            }
928    
929            /**
930             * Finds the last asset tag stats in the ordered set where classNameId = &#63;.
931             *
932             * <p>
933             * 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.
934             * </p>
935             *
936             * @param classNameId the class name id to search with
937             * @param orderByComparator the comparator to order the set by
938             * @return the last matching asset tag stats
939             * @throws com.liferay.portlet.asset.NoSuchTagStatsException if a matching asset tag stats could not be found
940             * @throws SystemException if a system exception occurred
941             */
942            public AssetTagStats findByClassNameId_Last(long classNameId,
943                    OrderByComparator orderByComparator)
944                    throws NoSuchTagStatsException, SystemException {
945                    int count = countByClassNameId(classNameId);
946    
947                    List<AssetTagStats> list = findByClassNameId(classNameId, count - 1,
948                                    count, orderByComparator);
949    
950                    if (list.isEmpty()) {
951                            StringBundler msg = new StringBundler(4);
952    
953                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
954    
955                            msg.append("classNameId=");
956                            msg.append(classNameId);
957    
958                            msg.append(StringPool.CLOSE_CURLY_BRACE);
959    
960                            throw new NoSuchTagStatsException(msg.toString());
961                    }
962                    else {
963                            return list.get(0);
964                    }
965            }
966    
967            /**
968             * Finds the asset tag statses before and after the current asset tag stats in the ordered set where classNameId = &#63;.
969             *
970             * <p>
971             * 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.
972             * </p>
973             *
974             * @param tagStatsId the primary key of the current asset tag stats
975             * @param classNameId the class name id to search with
976             * @param orderByComparator the comparator to order the set by
977             * @return the previous, current, and next asset tag stats
978             * @throws com.liferay.portlet.asset.NoSuchTagStatsException if a asset tag stats with the primary key could not be found
979             * @throws SystemException if a system exception occurred
980             */
981            public AssetTagStats[] findByClassNameId_PrevAndNext(long tagStatsId,
982                    long classNameId, OrderByComparator orderByComparator)
983                    throws NoSuchTagStatsException, SystemException {
984                    AssetTagStats assetTagStats = findByPrimaryKey(tagStatsId);
985    
986                    Session session = null;
987    
988                    try {
989                            session = openSession();
990    
991                            AssetTagStats[] array = new AssetTagStatsImpl[3];
992    
993                            array[0] = getByClassNameId_PrevAndNext(session, assetTagStats,
994                                            classNameId, orderByComparator, true);
995    
996                            array[1] = assetTagStats;
997    
998                            array[2] = getByClassNameId_PrevAndNext(session, assetTagStats,
999                                            classNameId, orderByComparator, false);
1000    
1001                            return array;
1002                    }
1003                    catch (Exception e) {
1004                            throw processException(e);
1005                    }
1006                    finally {
1007                            closeSession(session);
1008                    }
1009            }
1010    
1011            protected AssetTagStats getByClassNameId_PrevAndNext(Session session,
1012                    AssetTagStats assetTagStats, long classNameId,
1013                    OrderByComparator orderByComparator, boolean previous) {
1014                    StringBundler query = null;
1015    
1016                    if (orderByComparator != null) {
1017                            query = new StringBundler(6 +
1018                                            (orderByComparator.getOrderByFields().length * 6));
1019                    }
1020                    else {
1021                            query = new StringBundler(3);
1022                    }
1023    
1024                    query.append(_SQL_SELECT_ASSETTAGSTATS_WHERE);
1025    
1026                    query.append(_FINDER_COLUMN_CLASSNAMEID_CLASSNAMEID_2);
1027    
1028                    if (orderByComparator != null) {
1029                            String[] orderByFields = orderByComparator.getOrderByFields();
1030    
1031                            if (orderByFields.length > 0) {
1032                                    query.append(WHERE_AND);
1033                            }
1034    
1035                            for (int i = 0; i < orderByFields.length; i++) {
1036                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1037                                    query.append(orderByFields[i]);
1038    
1039                                    if ((i + 1) < orderByFields.length) {
1040                                            if (orderByComparator.isAscending() ^ previous) {
1041                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1042                                            }
1043                                            else {
1044                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1045                                            }
1046                                    }
1047                                    else {
1048                                            if (orderByComparator.isAscending() ^ previous) {
1049                                                    query.append(WHERE_GREATER_THAN);
1050                                            }
1051                                            else {
1052                                                    query.append(WHERE_LESSER_THAN);
1053                                            }
1054                                    }
1055                            }
1056    
1057                            query.append(ORDER_BY_CLAUSE);
1058    
1059                            for (int i = 0; i < orderByFields.length; i++) {
1060                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1061                                    query.append(orderByFields[i]);
1062    
1063                                    if ((i + 1) < orderByFields.length) {
1064                                            if (orderByComparator.isAscending() ^ previous) {
1065                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1066                                            }
1067                                            else {
1068                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1069                                            }
1070                                    }
1071                                    else {
1072                                            if (orderByComparator.isAscending() ^ previous) {
1073                                                    query.append(ORDER_BY_ASC);
1074                                            }
1075                                            else {
1076                                                    query.append(ORDER_BY_DESC);
1077                                            }
1078                                    }
1079                            }
1080                    }
1081    
1082                    else {
1083                            query.append(AssetTagStatsModelImpl.ORDER_BY_JPQL);
1084                    }
1085    
1086                    String sql = query.toString();
1087    
1088                    Query q = session.createQuery(sql);
1089    
1090                    q.setFirstResult(0);
1091                    q.setMaxResults(2);
1092    
1093                    QueryPos qPos = QueryPos.getInstance(q);
1094    
1095                    qPos.add(classNameId);
1096    
1097                    if (orderByComparator != null) {
1098                            Object[] values = orderByComparator.getOrderByValues(assetTagStats);
1099    
1100                            for (Object value : values) {
1101                                    qPos.add(value);
1102                            }
1103                    }
1104    
1105                    List<AssetTagStats> list = q.list();
1106    
1107                    if (list.size() == 2) {
1108                            return list.get(1);
1109                    }
1110                    else {
1111                            return null;
1112                    }
1113            }
1114    
1115            /**
1116             * 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.
1117             *
1118             * @param tagId the tag id to search with
1119             * @param classNameId the class name id to search with
1120             * @return the matching asset tag stats
1121             * @throws com.liferay.portlet.asset.NoSuchTagStatsException if a matching asset tag stats could not be found
1122             * @throws SystemException if a system exception occurred
1123             */
1124            public AssetTagStats findByT_C(long tagId, long classNameId)
1125                    throws NoSuchTagStatsException, SystemException {
1126                    AssetTagStats assetTagStats = fetchByT_C(tagId, classNameId);
1127    
1128                    if (assetTagStats == null) {
1129                            StringBundler msg = new StringBundler(6);
1130    
1131                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1132    
1133                            msg.append("tagId=");
1134                            msg.append(tagId);
1135    
1136                            msg.append(", classNameId=");
1137                            msg.append(classNameId);
1138    
1139                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1140    
1141                            if (_log.isWarnEnabled()) {
1142                                    _log.warn(msg.toString());
1143                            }
1144    
1145                            throw new NoSuchTagStatsException(msg.toString());
1146                    }
1147    
1148                    return assetTagStats;
1149            }
1150    
1151            /**
1152             * 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.
1153             *
1154             * @param tagId the tag id to search with
1155             * @param classNameId the class name id to search with
1156             * @return the matching asset tag stats, or <code>null</code> if a matching asset tag stats could not be found
1157             * @throws SystemException if a system exception occurred
1158             */
1159            public AssetTagStats fetchByT_C(long tagId, long classNameId)
1160                    throws SystemException {
1161                    return fetchByT_C(tagId, classNameId, true);
1162            }
1163    
1164            /**
1165             * 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.
1166             *
1167             * @param tagId the tag id to search with
1168             * @param classNameId the class name id to search with
1169             * @return the matching asset tag stats, or <code>null</code> if a matching asset tag stats could not be found
1170             * @throws SystemException if a system exception occurred
1171             */
1172            public AssetTagStats fetchByT_C(long tagId, long classNameId,
1173                    boolean retrieveFromCache) throws SystemException {
1174                    Object[] finderArgs = new Object[] { tagId, classNameId };
1175    
1176                    Object result = null;
1177    
1178                    if (retrieveFromCache) {
1179                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_T_C,
1180                                            finderArgs, this);
1181                    }
1182    
1183                    if (result == null) {
1184                            Session session = null;
1185    
1186                            try {
1187                                    session = openSession();
1188    
1189                                    StringBundler query = new StringBundler(4);
1190    
1191                                    query.append(_SQL_SELECT_ASSETTAGSTATS_WHERE);
1192    
1193                                    query.append(_FINDER_COLUMN_T_C_TAGID_2);
1194    
1195                                    query.append(_FINDER_COLUMN_T_C_CLASSNAMEID_2);
1196    
1197                                    query.append(AssetTagStatsModelImpl.ORDER_BY_JPQL);
1198    
1199                                    String sql = query.toString();
1200    
1201                                    Query q = session.createQuery(sql);
1202    
1203                                    QueryPos qPos = QueryPos.getInstance(q);
1204    
1205                                    qPos.add(tagId);
1206    
1207                                    qPos.add(classNameId);
1208    
1209                                    List<AssetTagStats> list = q.list();
1210    
1211                                    result = list;
1212    
1213                                    AssetTagStats assetTagStats = null;
1214    
1215                                    if (list.isEmpty()) {
1216                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_C,
1217                                                    finderArgs, list);
1218                                    }
1219                                    else {
1220                                            assetTagStats = list.get(0);
1221    
1222                                            cacheResult(assetTagStats);
1223    
1224                                            if ((assetTagStats.getTagId() != tagId) ||
1225                                                            (assetTagStats.getClassNameId() != classNameId)) {
1226                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_C,
1227                                                            finderArgs, assetTagStats);
1228                                            }
1229                                    }
1230    
1231                                    return assetTagStats;
1232                            }
1233                            catch (Exception e) {
1234                                    throw processException(e);
1235                            }
1236                            finally {
1237                                    if (result == null) {
1238                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_C,
1239                                                    finderArgs, new ArrayList<AssetTagStats>());
1240                                    }
1241    
1242                                    closeSession(session);
1243                            }
1244                    }
1245                    else {
1246                            if (result instanceof List<?>) {
1247                                    return null;
1248                            }
1249                            else {
1250                                    return (AssetTagStats)result;
1251                            }
1252                    }
1253            }
1254    
1255            /**
1256             * Finds all the asset tag statses.
1257             *
1258             * @return the asset tag statses
1259             * @throws SystemException if a system exception occurred
1260             */
1261            public List<AssetTagStats> findAll() throws SystemException {
1262                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1263            }
1264    
1265            /**
1266             * Finds a range of all the asset tag statses.
1267             *
1268             * <p>
1269             * 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.
1270             * </p>
1271             *
1272             * @param start the lower bound of the range of asset tag statses to return
1273             * @param end the upper bound of the range of asset tag statses to return (not inclusive)
1274             * @return the range of asset tag statses
1275             * @throws SystemException if a system exception occurred
1276             */
1277            public List<AssetTagStats> findAll(int start, int end)
1278                    throws SystemException {
1279                    return findAll(start, end, null);
1280            }
1281    
1282            /**
1283             * Finds an ordered range of all the asset tag statses.
1284             *
1285             * <p>
1286             * 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.
1287             * </p>
1288             *
1289             * @param start the lower bound of the range of asset tag statses to return
1290             * @param end the upper bound of the range of asset tag statses to return (not inclusive)
1291             * @param orderByComparator the comparator to order the results by
1292             * @return the ordered range of asset tag statses
1293             * @throws SystemException if a system exception occurred
1294             */
1295            public List<AssetTagStats> findAll(int start, int end,
1296                    OrderByComparator orderByComparator) throws SystemException {
1297                    Object[] finderArgs = new Object[] {
1298                                    String.valueOf(start), String.valueOf(end),
1299                                    String.valueOf(orderByComparator)
1300                            };
1301    
1302                    List<AssetTagStats> list = (List<AssetTagStats>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1303                                    finderArgs, this);
1304    
1305                    if (list == null) {
1306                            Session session = null;
1307    
1308                            try {
1309                                    session = openSession();
1310    
1311                                    StringBundler query = null;
1312                                    String sql = null;
1313    
1314                                    if (orderByComparator != null) {
1315                                            query = new StringBundler(2 +
1316                                                            (orderByComparator.getOrderByFields().length * 3));
1317    
1318                                            query.append(_SQL_SELECT_ASSETTAGSTATS);
1319    
1320                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1321                                                    orderByComparator);
1322    
1323                                            sql = query.toString();
1324                                    }
1325                                    else {
1326                                            sql = _SQL_SELECT_ASSETTAGSTATS.concat(AssetTagStatsModelImpl.ORDER_BY_JPQL);
1327                                    }
1328    
1329                                    Query q = session.createQuery(sql);
1330    
1331                                    if (orderByComparator == null) {
1332                                            list = (List<AssetTagStats>)QueryUtil.list(q, getDialect(),
1333                                                            start, end, false);
1334    
1335                                            Collections.sort(list);
1336                                    }
1337                                    else {
1338                                            list = (List<AssetTagStats>)QueryUtil.list(q, getDialect(),
1339                                                            start, end);
1340                                    }
1341                            }
1342                            catch (Exception e) {
1343                                    throw processException(e);
1344                            }
1345                            finally {
1346                                    if (list == null) {
1347                                            list = new ArrayList<AssetTagStats>();
1348                                    }
1349    
1350                                    cacheResult(list);
1351    
1352                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1353    
1354                                    closeSession(session);
1355                            }
1356                    }
1357    
1358                    return list;
1359            }
1360    
1361            /**
1362             * Removes all the asset tag statses where tagId = &#63; from the database.
1363             *
1364             * @param tagId the tag id to search with
1365             * @throws SystemException if a system exception occurred
1366             */
1367            public void removeByTagId(long tagId) throws SystemException {
1368                    for (AssetTagStats assetTagStats : findByTagId(tagId)) {
1369                            remove(assetTagStats);
1370                    }
1371            }
1372    
1373            /**
1374             * Removes all the asset tag statses where classNameId = &#63; from the database.
1375             *
1376             * @param classNameId the class name id to search with
1377             * @throws SystemException if a system exception occurred
1378             */
1379            public void removeByClassNameId(long classNameId) throws SystemException {
1380                    for (AssetTagStats assetTagStats : findByClassNameId(classNameId)) {
1381                            remove(assetTagStats);
1382                    }
1383            }
1384    
1385            /**
1386             * Removes the asset tag stats where tagId = &#63; and classNameId = &#63; from the database.
1387             *
1388             * @param tagId the tag id to search with
1389             * @param classNameId the class name id to search with
1390             * @throws SystemException if a system exception occurred
1391             */
1392            public void removeByT_C(long tagId, long classNameId)
1393                    throws NoSuchTagStatsException, SystemException {
1394                    AssetTagStats assetTagStats = findByT_C(tagId, classNameId);
1395    
1396                    remove(assetTagStats);
1397            }
1398    
1399            /**
1400             * Removes all the asset tag statses from the database.
1401             *
1402             * @throws SystemException if a system exception occurred
1403             */
1404            public void removeAll() throws SystemException {
1405                    for (AssetTagStats assetTagStats : findAll()) {
1406                            remove(assetTagStats);
1407                    }
1408            }
1409    
1410            /**
1411             * Counts all the asset tag statses where tagId = &#63;.
1412             *
1413             * @param tagId the tag id to search with
1414             * @return the number of matching asset tag statses
1415             * @throws SystemException if a system exception occurred
1416             */
1417            public int countByTagId(long tagId) throws SystemException {
1418                    Object[] finderArgs = new Object[] { tagId };
1419    
1420                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_TAGID,
1421                                    finderArgs, this);
1422    
1423                    if (count == null) {
1424                            Session session = null;
1425    
1426                            try {
1427                                    session = openSession();
1428    
1429                                    StringBundler query = new StringBundler(2);
1430    
1431                                    query.append(_SQL_COUNT_ASSETTAGSTATS_WHERE);
1432    
1433                                    query.append(_FINDER_COLUMN_TAGID_TAGID_2);
1434    
1435                                    String sql = query.toString();
1436    
1437                                    Query q = session.createQuery(sql);
1438    
1439                                    QueryPos qPos = QueryPos.getInstance(q);
1440    
1441                                    qPos.add(tagId);
1442    
1443                                    count = (Long)q.uniqueResult();
1444                            }
1445                            catch (Exception e) {
1446                                    throw processException(e);
1447                            }
1448                            finally {
1449                                    if (count == null) {
1450                                            count = Long.valueOf(0);
1451                                    }
1452    
1453                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_TAGID,
1454                                            finderArgs, count);
1455    
1456                                    closeSession(session);
1457                            }
1458                    }
1459    
1460                    return count.intValue();
1461            }
1462    
1463            /**
1464             * Counts all the asset tag statses where classNameId = &#63;.
1465             *
1466             * @param classNameId the class name id to search with
1467             * @return the number of matching asset tag statses
1468             * @throws SystemException if a system exception occurred
1469             */
1470            public int countByClassNameId(long classNameId) throws SystemException {
1471                    Object[] finderArgs = new Object[] { classNameId };
1472    
1473                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_CLASSNAMEID,
1474                                    finderArgs, this);
1475    
1476                    if (count == null) {
1477                            Session session = null;
1478    
1479                            try {
1480                                    session = openSession();
1481    
1482                                    StringBundler query = new StringBundler(2);
1483    
1484                                    query.append(_SQL_COUNT_ASSETTAGSTATS_WHERE);
1485    
1486                                    query.append(_FINDER_COLUMN_CLASSNAMEID_CLASSNAMEID_2);
1487    
1488                                    String sql = query.toString();
1489    
1490                                    Query q = session.createQuery(sql);
1491    
1492                                    QueryPos qPos = QueryPos.getInstance(q);
1493    
1494                                    qPos.add(classNameId);
1495    
1496                                    count = (Long)q.uniqueResult();
1497                            }
1498                            catch (Exception e) {
1499                                    throw processException(e);
1500                            }
1501                            finally {
1502                                    if (count == null) {
1503                                            count = Long.valueOf(0);
1504                                    }
1505    
1506                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_CLASSNAMEID,
1507                                            finderArgs, count);
1508    
1509                                    closeSession(session);
1510                            }
1511                    }
1512    
1513                    return count.intValue();
1514            }
1515    
1516            /**
1517             * Counts all the asset tag statses where tagId = &#63; and classNameId = &#63;.
1518             *
1519             * @param tagId the tag id to search with
1520             * @param classNameId the class name id to search with
1521             * @return the number of matching asset tag statses
1522             * @throws SystemException if a system exception occurred
1523             */
1524            public int countByT_C(long tagId, long classNameId)
1525                    throws SystemException {
1526                    Object[] finderArgs = new Object[] { tagId, classNameId };
1527    
1528                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_T_C,
1529                                    finderArgs, this);
1530    
1531                    if (count == null) {
1532                            Session session = null;
1533    
1534                            try {
1535                                    session = openSession();
1536    
1537                                    StringBundler query = new StringBundler(3);
1538    
1539                                    query.append(_SQL_COUNT_ASSETTAGSTATS_WHERE);
1540    
1541                                    query.append(_FINDER_COLUMN_T_C_TAGID_2);
1542    
1543                                    query.append(_FINDER_COLUMN_T_C_CLASSNAMEID_2);
1544    
1545                                    String sql = query.toString();
1546    
1547                                    Query q = session.createQuery(sql);
1548    
1549                                    QueryPos qPos = QueryPos.getInstance(q);
1550    
1551                                    qPos.add(tagId);
1552    
1553                                    qPos.add(classNameId);
1554    
1555                                    count = (Long)q.uniqueResult();
1556                            }
1557                            catch (Exception e) {
1558                                    throw processException(e);
1559                            }
1560                            finally {
1561                                    if (count == null) {
1562                                            count = Long.valueOf(0);
1563                                    }
1564    
1565                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_C, finderArgs,
1566                                            count);
1567    
1568                                    closeSession(session);
1569                            }
1570                    }
1571    
1572                    return count.intValue();
1573            }
1574    
1575            /**
1576             * Counts all the asset tag statses.
1577             *
1578             * @return the number of asset tag statses
1579             * @throws SystemException if a system exception occurred
1580             */
1581            public int countAll() throws SystemException {
1582                    Object[] finderArgs = new Object[0];
1583    
1584                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1585                                    finderArgs, this);
1586    
1587                    if (count == null) {
1588                            Session session = null;
1589    
1590                            try {
1591                                    session = openSession();
1592    
1593                                    Query q = session.createQuery(_SQL_COUNT_ASSETTAGSTATS);
1594    
1595                                    count = (Long)q.uniqueResult();
1596                            }
1597                            catch (Exception e) {
1598                                    throw processException(e);
1599                            }
1600                            finally {
1601                                    if (count == null) {
1602                                            count = Long.valueOf(0);
1603                                    }
1604    
1605                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1606                                            count);
1607    
1608                                    closeSession(session);
1609                            }
1610                    }
1611    
1612                    return count.intValue();
1613            }
1614    
1615            /**
1616             * Initializes the asset tag stats persistence.
1617             */
1618            public void afterPropertiesSet() {
1619                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1620                                            com.liferay.portal.util.PropsUtil.get(
1621                                                    "value.object.listener.com.liferay.portlet.asset.model.AssetTagStats")));
1622    
1623                    if (listenerClassNames.length > 0) {
1624                            try {
1625                                    List<ModelListener<AssetTagStats>> listenersList = new ArrayList<ModelListener<AssetTagStats>>();
1626    
1627                                    for (String listenerClassName : listenerClassNames) {
1628                                            listenersList.add((ModelListener<AssetTagStats>)InstanceFactory.newInstance(
1629                                                            listenerClassName));
1630                                    }
1631    
1632                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1633                            }
1634                            catch (Exception e) {
1635                                    _log.error(e);
1636                            }
1637                    }
1638            }
1639    
1640            public void destroy() {
1641                    EntityCacheUtil.removeCache(AssetTagStatsImpl.class.getName());
1642                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1643                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
1644            }
1645    
1646            @BeanReference(type = AssetCategoryPersistence.class)
1647            protected AssetCategoryPersistence assetCategoryPersistence;
1648            @BeanReference(type = AssetCategoryPropertyPersistence.class)
1649            protected AssetCategoryPropertyPersistence assetCategoryPropertyPersistence;
1650            @BeanReference(type = AssetEntryPersistence.class)
1651            protected AssetEntryPersistence assetEntryPersistence;
1652            @BeanReference(type = AssetLinkPersistence.class)
1653            protected AssetLinkPersistence assetLinkPersistence;
1654            @BeanReference(type = AssetTagPersistence.class)
1655            protected AssetTagPersistence assetTagPersistence;
1656            @BeanReference(type = AssetTagPropertyPersistence.class)
1657            protected AssetTagPropertyPersistence assetTagPropertyPersistence;
1658            @BeanReference(type = AssetTagStatsPersistence.class)
1659            protected AssetTagStatsPersistence assetTagStatsPersistence;
1660            @BeanReference(type = AssetVocabularyPersistence.class)
1661            protected AssetVocabularyPersistence assetVocabularyPersistence;
1662            @BeanReference(type = ResourcePersistence.class)
1663            protected ResourcePersistence resourcePersistence;
1664            @BeanReference(type = UserPersistence.class)
1665            protected UserPersistence userPersistence;
1666            private static final String _SQL_SELECT_ASSETTAGSTATS = "SELECT assetTagStats FROM AssetTagStats assetTagStats";
1667            private static final String _SQL_SELECT_ASSETTAGSTATS_WHERE = "SELECT assetTagStats FROM AssetTagStats assetTagStats WHERE ";
1668            private static final String _SQL_COUNT_ASSETTAGSTATS = "SELECT COUNT(assetTagStats) FROM AssetTagStats assetTagStats";
1669            private static final String _SQL_COUNT_ASSETTAGSTATS_WHERE = "SELECT COUNT(assetTagStats) FROM AssetTagStats assetTagStats WHERE ";
1670            private static final String _FINDER_COLUMN_TAGID_TAGID_2 = "assetTagStats.tagId = ?";
1671            private static final String _FINDER_COLUMN_CLASSNAMEID_CLASSNAMEID_2 = "assetTagStats.classNameId = ?";
1672            private static final String _FINDER_COLUMN_T_C_TAGID_2 = "assetTagStats.tagId = ? AND ";
1673            private static final String _FINDER_COLUMN_T_C_CLASSNAMEID_2 = "assetTagStats.classNameId = ?";
1674            private static final String _ORDER_BY_ENTITY_ALIAS = "assetTagStats.";
1675            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No AssetTagStats exists with the primary key ";
1676            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No AssetTagStats exists with the key {";
1677            private static Log _log = LogFactoryUtil.getLog(AssetTagStatsPersistenceImpl.class);
1678    }