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