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