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