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