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