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