1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portlet.asset.service.persistence;
16  
17  import com.liferay.portal.NoSuchModelException;
18  import com.liferay.portal.kernel.annotation.BeanReference;
19  import com.liferay.portal.kernel.cache.CacheRegistry;
20  import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
21  import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
22  import com.liferay.portal.kernel.dao.orm.FinderPath;
23  import com.liferay.portal.kernel.dao.orm.Query;
24  import com.liferay.portal.kernel.dao.orm.QueryPos;
25  import com.liferay.portal.kernel.dao.orm.QueryUtil;
26  import com.liferay.portal.kernel.dao.orm.Session;
27  import com.liferay.portal.kernel.exception.SystemException;
28  import com.liferay.portal.kernel.log.Log;
29  import com.liferay.portal.kernel.log.LogFactoryUtil;
30  import com.liferay.portal.kernel.util.GetterUtil;
31  import com.liferay.portal.kernel.util.OrderByComparator;
32  import com.liferay.portal.kernel.util.StringBundler;
33  import com.liferay.portal.kernel.util.StringPool;
34  import com.liferay.portal.kernel.util.StringUtil;
35  import com.liferay.portal.model.ModelListener;
36  import com.liferay.portal.service.persistence.BatchSessionUtil;
37  import com.liferay.portal.service.persistence.ResourcePersistence;
38  import com.liferay.portal.service.persistence.UserPersistence;
39  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
40  
41  import com.liferay.portlet.asset.NoSuchTagStatsException;
42  import com.liferay.portlet.asset.model.AssetTagStats;
43  import com.liferay.portlet.asset.model.impl.AssetTagStatsImpl;
44  import com.liferay.portlet.asset.model.impl.AssetTagStatsModelImpl;
45  
46  import java.io.Serializable;
47  
48  import java.util.ArrayList;
49  import java.util.Collections;
50  import java.util.List;
51  
52  /**
53   * <a href="AssetTagStatsPersistenceImpl.java.html"><b><i>View Source</i></b></a>
54   *
55   * <p>
56   * ServiceBuilder generated this class. Modifications in this class will be
57   * overwritten the next time is generated.
58   * </p>
59   *
60   * @author    Brian Wing Shun Chan
61   * @see       AssetTagStatsPersistence
62   * @see       AssetTagStatsUtil
63   * @generated
64   */
65  public class AssetTagStatsPersistenceImpl extends BasePersistenceImpl<AssetTagStats>
66      implements AssetTagStatsPersistence {
67      public static final String FINDER_CLASS_NAME_ENTITY = AssetTagStatsImpl.class.getName();
68      public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
69          ".List";
70      public static final FinderPath FINDER_PATH_FIND_BY_TAGID = new FinderPath(AssetTagStatsModelImpl.ENTITY_CACHE_ENABLED,
71              AssetTagStatsModelImpl.FINDER_CACHE_ENABLED,
72              FINDER_CLASS_NAME_LIST, "findByTagId",
73              new String[] { Long.class.getName() });
74      public static final FinderPath FINDER_PATH_FIND_BY_OBC_TAGID = new FinderPath(AssetTagStatsModelImpl.ENTITY_CACHE_ENABLED,
75              AssetTagStatsModelImpl.FINDER_CACHE_ENABLED,
76              FINDER_CLASS_NAME_LIST, "findByTagId",
77              new String[] {
78                  Long.class.getName(),
79                  
80              "java.lang.Integer", "java.lang.Integer",
81                  "com.liferay.portal.kernel.util.OrderByComparator"
82              });
83      public static final FinderPath FINDER_PATH_COUNT_BY_TAGID = new FinderPath(AssetTagStatsModelImpl.ENTITY_CACHE_ENABLED,
84              AssetTagStatsModelImpl.FINDER_CACHE_ENABLED,
85              FINDER_CLASS_NAME_LIST, "countByTagId",
86              new String[] { Long.class.getName() });
87      public static final FinderPath FINDER_PATH_FIND_BY_CLASSNAMEID = new FinderPath(AssetTagStatsModelImpl.ENTITY_CACHE_ENABLED,
88              AssetTagStatsModelImpl.FINDER_CACHE_ENABLED,
89              FINDER_CLASS_NAME_LIST, "findByClassNameId",
90              new String[] { Long.class.getName() });
91      public static final FinderPath FINDER_PATH_FIND_BY_OBC_CLASSNAMEID = new FinderPath(AssetTagStatsModelImpl.ENTITY_CACHE_ENABLED,
92              AssetTagStatsModelImpl.FINDER_CACHE_ENABLED,
93              FINDER_CLASS_NAME_LIST, "findByClassNameId",
94              new String[] {
95                  Long.class.getName(),
96                  
97              "java.lang.Integer", "java.lang.Integer",
98                  "com.liferay.portal.kernel.util.OrderByComparator"
99              });
100     public static final FinderPath FINDER_PATH_COUNT_BY_CLASSNAMEID = new FinderPath(AssetTagStatsModelImpl.ENTITY_CACHE_ENABLED,
101             AssetTagStatsModelImpl.FINDER_CACHE_ENABLED,
102             FINDER_CLASS_NAME_LIST, "countByClassNameId",
103             new String[] { Long.class.getName() });
104     public static final FinderPath FINDER_PATH_FETCH_BY_T_C = new FinderPath(AssetTagStatsModelImpl.ENTITY_CACHE_ENABLED,
105             AssetTagStatsModelImpl.FINDER_CACHE_ENABLED,
106             FINDER_CLASS_NAME_ENTITY, "fetchByT_C",
107             new String[] { Long.class.getName(), Long.class.getName() });
108     public static final FinderPath FINDER_PATH_COUNT_BY_T_C = new FinderPath(AssetTagStatsModelImpl.ENTITY_CACHE_ENABLED,
109             AssetTagStatsModelImpl.FINDER_CACHE_ENABLED,
110             FINDER_CLASS_NAME_LIST, "countByT_C",
111             new String[] { Long.class.getName(), Long.class.getName() });
112     public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(AssetTagStatsModelImpl.ENTITY_CACHE_ENABLED,
113             AssetTagStatsModelImpl.FINDER_CACHE_ENABLED,
114             FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
115     public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(AssetTagStatsModelImpl.ENTITY_CACHE_ENABLED,
116             AssetTagStatsModelImpl.FINDER_CACHE_ENABLED,
117             FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
118 
119     public void cacheResult(AssetTagStats assetTagStats) {
120         EntityCacheUtil.putResult(AssetTagStatsModelImpl.ENTITY_CACHE_ENABLED,
121             AssetTagStatsImpl.class, assetTagStats.getPrimaryKey(),
122             assetTagStats);
123 
124         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_C,
125             new Object[] {
126                 new Long(assetTagStats.getTagId()),
127                 new Long(assetTagStats.getClassNameId())
128             }, assetTagStats);
129     }
130 
131     public void cacheResult(List<AssetTagStats> assetTagStatses) {
132         for (AssetTagStats assetTagStats : assetTagStatses) {
133             if (EntityCacheUtil.getResult(
134                         AssetTagStatsModelImpl.ENTITY_CACHE_ENABLED,
135                         AssetTagStatsImpl.class, assetTagStats.getPrimaryKey(),
136                         this) == null) {
137                 cacheResult(assetTagStats);
138             }
139         }
140     }
141 
142     public void clearCache() {
143         CacheRegistry.clear(AssetTagStatsImpl.class.getName());
144         EntityCacheUtil.clearCache(AssetTagStatsImpl.class.getName());
145         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
146         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
147     }
148 
149     public AssetTagStats create(long tagStatsId) {
150         AssetTagStats assetTagStats = new AssetTagStatsImpl();
151 
152         assetTagStats.setNew(true);
153         assetTagStats.setPrimaryKey(tagStatsId);
154 
155         return assetTagStats;
156     }
157 
158     public AssetTagStats remove(Serializable primaryKey)
159         throws NoSuchModelException, SystemException {
160         return remove(((Long)primaryKey).longValue());
161     }
162 
163     public AssetTagStats remove(long tagStatsId)
164         throws NoSuchTagStatsException, SystemException {
165         Session session = null;
166 
167         try {
168             session = openSession();
169 
170             AssetTagStats assetTagStats = (AssetTagStats)session.get(AssetTagStatsImpl.class,
171                     new Long(tagStatsId));
172 
173             if (assetTagStats == null) {
174                 if (_log.isWarnEnabled()) {
175                     _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + tagStatsId);
176                 }
177 
178                 throw new NoSuchTagStatsException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
179                     tagStatsId);
180             }
181 
182             return remove(assetTagStats);
183         }
184         catch (NoSuchTagStatsException nsee) {
185             throw nsee;
186         }
187         catch (Exception e) {
188             throw processException(e);
189         }
190         finally {
191             closeSession(session);
192         }
193     }
194 
195     public AssetTagStats remove(AssetTagStats assetTagStats)
196         throws SystemException {
197         for (ModelListener<AssetTagStats> listener : listeners) {
198             listener.onBeforeRemove(assetTagStats);
199         }
200 
201         assetTagStats = removeImpl(assetTagStats);
202 
203         for (ModelListener<AssetTagStats> listener : listeners) {
204             listener.onAfterRemove(assetTagStats);
205         }
206 
207         return assetTagStats;
208     }
209 
210     protected AssetTagStats removeImpl(AssetTagStats assetTagStats)
211         throws SystemException {
212         assetTagStats = toUnwrappedModel(assetTagStats);
213 
214         Session session = null;
215 
216         try {
217             session = openSession();
218 
219             if (assetTagStats.isCachedModel() || BatchSessionUtil.isEnabled()) {
220                 Object staleObject = session.get(AssetTagStatsImpl.class,
221                         assetTagStats.getPrimaryKeyObj());
222 
223                 if (staleObject != null) {
224                     session.evict(staleObject);
225                 }
226             }
227 
228             session.delete(assetTagStats);
229 
230             session.flush();
231         }
232         catch (Exception e) {
233             throw processException(e);
234         }
235         finally {
236             closeSession(session);
237         }
238 
239         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
240 
241         AssetTagStatsModelImpl assetTagStatsModelImpl = (AssetTagStatsModelImpl)assetTagStats;
242 
243         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_T_C,
244             new Object[] {
245                 new Long(assetTagStatsModelImpl.getOriginalTagId()),
246                 new Long(assetTagStatsModelImpl.getOriginalClassNameId())
247             });
248 
249         EntityCacheUtil.removeResult(AssetTagStatsModelImpl.ENTITY_CACHE_ENABLED,
250             AssetTagStatsImpl.class, assetTagStats.getPrimaryKey());
251 
252         return assetTagStats;
253     }
254 
255     public AssetTagStats updateImpl(
256         com.liferay.portlet.asset.model.AssetTagStats assetTagStats,
257         boolean merge) throws SystemException {
258         assetTagStats = toUnwrappedModel(assetTagStats);
259 
260         boolean isNew = assetTagStats.isNew();
261 
262         AssetTagStatsModelImpl assetTagStatsModelImpl = (AssetTagStatsModelImpl)assetTagStats;
263 
264         Session session = null;
265 
266         try {
267             session = openSession();
268 
269             BatchSessionUtil.update(session, assetTagStats, merge);
270 
271             assetTagStats.setNew(false);
272         }
273         catch (Exception e) {
274             throw processException(e);
275         }
276         finally {
277             closeSession(session);
278         }
279 
280         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
281 
282         EntityCacheUtil.putResult(AssetTagStatsModelImpl.ENTITY_CACHE_ENABLED,
283             AssetTagStatsImpl.class, assetTagStats.getPrimaryKey(),
284             assetTagStats);
285 
286         if (!isNew &&
287                 ((assetTagStats.getTagId() != assetTagStatsModelImpl.getOriginalTagId()) ||
288                 (assetTagStats.getClassNameId() != assetTagStatsModelImpl.getOriginalClassNameId()))) {
289             FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_T_C,
290                 new Object[] {
291                     new Long(assetTagStatsModelImpl.getOriginalTagId()),
292                     new Long(assetTagStatsModelImpl.getOriginalClassNameId())
293                 });
294         }
295 
296         if (isNew ||
297                 ((assetTagStats.getTagId() != assetTagStatsModelImpl.getOriginalTagId()) ||
298                 (assetTagStats.getClassNameId() != assetTagStatsModelImpl.getOriginalClassNameId()))) {
299             FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_C,
300                 new Object[] {
301                     new Long(assetTagStats.getTagId()),
302                     new Long(assetTagStats.getClassNameId())
303                 }, assetTagStats);
304         }
305 
306         return assetTagStats;
307     }
308 
309     protected AssetTagStats toUnwrappedModel(AssetTagStats assetTagStats) {
310         if (assetTagStats instanceof AssetTagStatsImpl) {
311             return assetTagStats;
312         }
313 
314         AssetTagStatsImpl assetTagStatsImpl = new AssetTagStatsImpl();
315 
316         assetTagStatsImpl.setNew(assetTagStats.isNew());
317         assetTagStatsImpl.setPrimaryKey(assetTagStats.getPrimaryKey());
318 
319         assetTagStatsImpl.setTagStatsId(assetTagStats.getTagStatsId());
320         assetTagStatsImpl.setTagId(assetTagStats.getTagId());
321         assetTagStatsImpl.setClassNameId(assetTagStats.getClassNameId());
322         assetTagStatsImpl.setAssetCount(assetTagStats.getAssetCount());
323 
324         return assetTagStatsImpl;
325     }
326 
327     public AssetTagStats findByPrimaryKey(Serializable primaryKey)
328         throws NoSuchModelException, SystemException {
329         return findByPrimaryKey(((Long)primaryKey).longValue());
330     }
331 
332     public AssetTagStats findByPrimaryKey(long tagStatsId)
333         throws NoSuchTagStatsException, SystemException {
334         AssetTagStats assetTagStats = fetchByPrimaryKey(tagStatsId);
335 
336         if (assetTagStats == null) {
337             if (_log.isWarnEnabled()) {
338                 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + tagStatsId);
339             }
340 
341             throw new NoSuchTagStatsException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
342                 tagStatsId);
343         }
344 
345         return assetTagStats;
346     }
347 
348     public AssetTagStats fetchByPrimaryKey(Serializable primaryKey)
349         throws SystemException {
350         return fetchByPrimaryKey(((Long)primaryKey).longValue());
351     }
352 
353     public AssetTagStats fetchByPrimaryKey(long tagStatsId)
354         throws SystemException {
355         AssetTagStats assetTagStats = (AssetTagStats)EntityCacheUtil.getResult(AssetTagStatsModelImpl.ENTITY_CACHE_ENABLED,
356                 AssetTagStatsImpl.class, tagStatsId, this);
357 
358         if (assetTagStats == null) {
359             Session session = null;
360 
361             try {
362                 session = openSession();
363 
364                 assetTagStats = (AssetTagStats)session.get(AssetTagStatsImpl.class,
365                         new Long(tagStatsId));
366             }
367             catch (Exception e) {
368                 throw processException(e);
369             }
370             finally {
371                 if (assetTagStats != null) {
372                     cacheResult(assetTagStats);
373                 }
374 
375                 closeSession(session);
376             }
377         }
378 
379         return assetTagStats;
380     }
381 
382     public List<AssetTagStats> findByTagId(long tagId)
383         throws SystemException {
384         Object[] finderArgs = new Object[] { new Long(tagId) };
385 
386         List<AssetTagStats> list = (List<AssetTagStats>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_TAGID,
387                 finderArgs, this);
388 
389         if (list == null) {
390             Session session = null;
391 
392             try {
393                 session = openSession();
394 
395                 StringBundler query = new StringBundler(3);
396 
397                 query.append(_SQL_SELECT_ASSETTAGSTATS_WHERE);
398 
399                 query.append(_FINDER_COLUMN_TAGID_TAGID_2);
400 
401                 query.append(AssetTagStatsModelImpl.ORDER_BY_JPQL);
402 
403                 String sql = query.toString();
404 
405                 Query q = session.createQuery(sql);
406 
407                 QueryPos qPos = QueryPos.getInstance(q);
408 
409                 qPos.add(tagId);
410 
411                 list = q.list();
412             }
413             catch (Exception e) {
414                 throw processException(e);
415             }
416             finally {
417                 if (list == null) {
418                     list = new ArrayList<AssetTagStats>();
419                 }
420 
421                 cacheResult(list);
422 
423                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_TAGID,
424                     finderArgs, list);
425 
426                 closeSession(session);
427             }
428         }
429 
430         return list;
431     }
432 
433     public List<AssetTagStats> findByTagId(long tagId, int start, int end)
434         throws SystemException {
435         return findByTagId(tagId, start, end, null);
436     }
437 
438     public List<AssetTagStats> findByTagId(long tagId, int start, int end,
439         OrderByComparator orderByComparator) throws SystemException {
440         Object[] finderArgs = new Object[] {
441                 new Long(tagId),
442                 
443                 String.valueOf(start), String.valueOf(end),
444                 String.valueOf(orderByComparator)
445             };
446 
447         List<AssetTagStats> list = (List<AssetTagStats>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_TAGID,
448                 finderArgs, this);
449 
450         if (list == null) {
451             Session session = null;
452 
453             try {
454                 session = openSession();
455 
456                 StringBundler query = null;
457 
458                 if (orderByComparator != null) {
459                     query = new StringBundler(3 +
460                             (orderByComparator.getOrderByFields().length * 3));
461                 }
462                 else {
463                     query = new StringBundler(3);
464                 }
465 
466                 query.append(_SQL_SELECT_ASSETTAGSTATS_WHERE);
467 
468                 query.append(_FINDER_COLUMN_TAGID_TAGID_2);
469 
470                 if (orderByComparator != null) {
471                     appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
472                         orderByComparator);
473                 }
474 
475                 else {
476                     query.append(AssetTagStatsModelImpl.ORDER_BY_JPQL);
477                 }
478 
479                 String sql = query.toString();
480 
481                 Query q = session.createQuery(sql);
482 
483                 QueryPos qPos = QueryPos.getInstance(q);
484 
485                 qPos.add(tagId);
486 
487                 list = (List<AssetTagStats>)QueryUtil.list(q, getDialect(),
488                         start, end);
489             }
490             catch (Exception e) {
491                 throw processException(e);
492             }
493             finally {
494                 if (list == null) {
495                     list = new ArrayList<AssetTagStats>();
496                 }
497 
498                 cacheResult(list);
499 
500                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_TAGID,
501                     finderArgs, list);
502 
503                 closeSession(session);
504             }
505         }
506 
507         return list;
508     }
509 
510     public AssetTagStats findByTagId_First(long tagId,
511         OrderByComparator orderByComparator)
512         throws NoSuchTagStatsException, SystemException {
513         List<AssetTagStats> list = findByTagId(tagId, 0, 1, orderByComparator);
514 
515         if (list.isEmpty()) {
516             StringBundler msg = new StringBundler(4);
517 
518             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
519 
520             msg.append("tagId=");
521             msg.append(tagId);
522 
523             msg.append(StringPool.CLOSE_CURLY_BRACE);
524 
525             throw new NoSuchTagStatsException(msg.toString());
526         }
527         else {
528             return list.get(0);
529         }
530     }
531 
532     public AssetTagStats findByTagId_Last(long tagId,
533         OrderByComparator orderByComparator)
534         throws NoSuchTagStatsException, SystemException {
535         int count = countByTagId(tagId);
536 
537         List<AssetTagStats> list = findByTagId(tagId, count - 1, count,
538                 orderByComparator);
539 
540         if (list.isEmpty()) {
541             StringBundler msg = new StringBundler(4);
542 
543             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
544 
545             msg.append("tagId=");
546             msg.append(tagId);
547 
548             msg.append(StringPool.CLOSE_CURLY_BRACE);
549 
550             throw new NoSuchTagStatsException(msg.toString());
551         }
552         else {
553             return list.get(0);
554         }
555     }
556 
557     public AssetTagStats[] findByTagId_PrevAndNext(long tagStatsId, long tagId,
558         OrderByComparator orderByComparator)
559         throws NoSuchTagStatsException, SystemException {
560         AssetTagStats assetTagStats = findByPrimaryKey(tagStatsId);
561 
562         int count = countByTagId(tagId);
563 
564         Session session = null;
565 
566         try {
567             session = openSession();
568 
569             StringBundler query = null;
570 
571             if (orderByComparator != null) {
572                 query = new StringBundler(3 +
573                         (orderByComparator.getOrderByFields().length * 3));
574             }
575             else {
576                 query = new StringBundler(3);
577             }
578 
579             query.append(_SQL_SELECT_ASSETTAGSTATS_WHERE);
580 
581             query.append(_FINDER_COLUMN_TAGID_TAGID_2);
582 
583             if (orderByComparator != null) {
584                 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
585                     orderByComparator);
586             }
587 
588             else {
589                 query.append(AssetTagStatsModelImpl.ORDER_BY_JPQL);
590             }
591 
592             String sql = query.toString();
593 
594             Query q = session.createQuery(sql);
595 
596             QueryPos qPos = QueryPos.getInstance(q);
597 
598             qPos.add(tagId);
599 
600             Object[] objArray = QueryUtil.getPrevAndNext(q, count,
601                     orderByComparator, assetTagStats);
602 
603             AssetTagStats[] array = new AssetTagStatsImpl[3];
604 
605             array[0] = (AssetTagStats)objArray[0];
606             array[1] = (AssetTagStats)objArray[1];
607             array[2] = (AssetTagStats)objArray[2];
608 
609             return array;
610         }
611         catch (Exception e) {
612             throw processException(e);
613         }
614         finally {
615             closeSession(session);
616         }
617     }
618 
619     public List<AssetTagStats> findByClassNameId(long classNameId)
620         throws SystemException {
621         Object[] finderArgs = new Object[] { new Long(classNameId) };
622 
623         List<AssetTagStats> list = (List<AssetTagStats>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_CLASSNAMEID,
624                 finderArgs, this);
625 
626         if (list == null) {
627             Session session = null;
628 
629             try {
630                 session = openSession();
631 
632                 StringBundler query = new StringBundler(3);
633 
634                 query.append(_SQL_SELECT_ASSETTAGSTATS_WHERE);
635 
636                 query.append(_FINDER_COLUMN_CLASSNAMEID_CLASSNAMEID_2);
637 
638                 query.append(AssetTagStatsModelImpl.ORDER_BY_JPQL);
639 
640                 String sql = query.toString();
641 
642                 Query q = session.createQuery(sql);
643 
644                 QueryPos qPos = QueryPos.getInstance(q);
645 
646                 qPos.add(classNameId);
647 
648                 list = q.list();
649             }
650             catch (Exception e) {
651                 throw processException(e);
652             }
653             finally {
654                 if (list == null) {
655                     list = new ArrayList<AssetTagStats>();
656                 }
657 
658                 cacheResult(list);
659 
660                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_CLASSNAMEID,
661                     finderArgs, list);
662 
663                 closeSession(session);
664             }
665         }
666 
667         return list;
668     }
669 
670     public List<AssetTagStats> findByClassNameId(long classNameId, int start,
671         int end) throws SystemException {
672         return findByClassNameId(classNameId, start, end, null);
673     }
674 
675     public List<AssetTagStats> findByClassNameId(long classNameId, int start,
676         int end, OrderByComparator orderByComparator) throws SystemException {
677         Object[] finderArgs = new Object[] {
678                 new Long(classNameId),
679                 
680                 String.valueOf(start), String.valueOf(end),
681                 String.valueOf(orderByComparator)
682             };
683 
684         List<AssetTagStats> list = (List<AssetTagStats>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_CLASSNAMEID,
685                 finderArgs, this);
686 
687         if (list == null) {
688             Session session = null;
689 
690             try {
691                 session = openSession();
692 
693                 StringBundler query = null;
694 
695                 if (orderByComparator != null) {
696                     query = new StringBundler(3 +
697                             (orderByComparator.getOrderByFields().length * 3));
698                 }
699                 else {
700                     query = new StringBundler(3);
701                 }
702 
703                 query.append(_SQL_SELECT_ASSETTAGSTATS_WHERE);
704 
705                 query.append(_FINDER_COLUMN_CLASSNAMEID_CLASSNAMEID_2);
706 
707                 if (orderByComparator != null) {
708                     appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
709                         orderByComparator);
710                 }
711 
712                 else {
713                     query.append(AssetTagStatsModelImpl.ORDER_BY_JPQL);
714                 }
715 
716                 String sql = query.toString();
717 
718                 Query q = session.createQuery(sql);
719 
720                 QueryPos qPos = QueryPos.getInstance(q);
721 
722                 qPos.add(classNameId);
723 
724                 list = (List<AssetTagStats>)QueryUtil.list(q, getDialect(),
725                         start, end);
726             }
727             catch (Exception e) {
728                 throw processException(e);
729             }
730             finally {
731                 if (list == null) {
732                     list = new ArrayList<AssetTagStats>();
733                 }
734 
735                 cacheResult(list);
736 
737                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_CLASSNAMEID,
738                     finderArgs, list);
739 
740                 closeSession(session);
741             }
742         }
743 
744         return list;
745     }
746 
747     public AssetTagStats findByClassNameId_First(long classNameId,
748         OrderByComparator orderByComparator)
749         throws NoSuchTagStatsException, SystemException {
750         List<AssetTagStats> list = findByClassNameId(classNameId, 0, 1,
751                 orderByComparator);
752 
753         if (list.isEmpty()) {
754             StringBundler msg = new StringBundler(4);
755 
756             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
757 
758             msg.append("classNameId=");
759             msg.append(classNameId);
760 
761             msg.append(StringPool.CLOSE_CURLY_BRACE);
762 
763             throw new NoSuchTagStatsException(msg.toString());
764         }
765         else {
766             return list.get(0);
767         }
768     }
769 
770     public AssetTagStats findByClassNameId_Last(long classNameId,
771         OrderByComparator orderByComparator)
772         throws NoSuchTagStatsException, SystemException {
773         int count = countByClassNameId(classNameId);
774 
775         List<AssetTagStats> list = findByClassNameId(classNameId, count - 1,
776                 count, orderByComparator);
777 
778         if (list.isEmpty()) {
779             StringBundler msg = new StringBundler(4);
780 
781             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
782 
783             msg.append("classNameId=");
784             msg.append(classNameId);
785 
786             msg.append(StringPool.CLOSE_CURLY_BRACE);
787 
788             throw new NoSuchTagStatsException(msg.toString());
789         }
790         else {
791             return list.get(0);
792         }
793     }
794 
795     public AssetTagStats[] findByClassNameId_PrevAndNext(long tagStatsId,
796         long classNameId, OrderByComparator orderByComparator)
797         throws NoSuchTagStatsException, SystemException {
798         AssetTagStats assetTagStats = findByPrimaryKey(tagStatsId);
799 
800         int count = countByClassNameId(classNameId);
801 
802         Session session = null;
803 
804         try {
805             session = openSession();
806 
807             StringBundler query = null;
808 
809             if (orderByComparator != null) {
810                 query = new StringBundler(3 +
811                         (orderByComparator.getOrderByFields().length * 3));
812             }
813             else {
814                 query = new StringBundler(3);
815             }
816 
817             query.append(_SQL_SELECT_ASSETTAGSTATS_WHERE);
818 
819             query.append(_FINDER_COLUMN_CLASSNAMEID_CLASSNAMEID_2);
820 
821             if (orderByComparator != null) {
822                 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
823                     orderByComparator);
824             }
825 
826             else {
827                 query.append(AssetTagStatsModelImpl.ORDER_BY_JPQL);
828             }
829 
830             String sql = query.toString();
831 
832             Query q = session.createQuery(sql);
833 
834             QueryPos qPos = QueryPos.getInstance(q);
835 
836             qPos.add(classNameId);
837 
838             Object[] objArray = QueryUtil.getPrevAndNext(q, count,
839                     orderByComparator, assetTagStats);
840 
841             AssetTagStats[] array = new AssetTagStatsImpl[3];
842 
843             array[0] = (AssetTagStats)objArray[0];
844             array[1] = (AssetTagStats)objArray[1];
845             array[2] = (AssetTagStats)objArray[2];
846 
847             return array;
848         }
849         catch (Exception e) {
850             throw processException(e);
851         }
852         finally {
853             closeSession(session);
854         }
855     }
856 
857     public AssetTagStats findByT_C(long tagId, long classNameId)
858         throws NoSuchTagStatsException, SystemException {
859         AssetTagStats assetTagStats = fetchByT_C(tagId, classNameId);
860 
861         if (assetTagStats == null) {
862             StringBundler msg = new StringBundler(6);
863 
864             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
865 
866             msg.append("tagId=");
867             msg.append(tagId);
868 
869             msg.append(", classNameId=");
870             msg.append(classNameId);
871 
872             msg.append(StringPool.CLOSE_CURLY_BRACE);
873 
874             if (_log.isWarnEnabled()) {
875                 _log.warn(msg.toString());
876             }
877 
878             throw new NoSuchTagStatsException(msg.toString());
879         }
880 
881         return assetTagStats;
882     }
883 
884     public AssetTagStats fetchByT_C(long tagId, long classNameId)
885         throws SystemException {
886         return fetchByT_C(tagId, classNameId, true);
887     }
888 
889     public AssetTagStats fetchByT_C(long tagId, long classNameId,
890         boolean retrieveFromCache) throws SystemException {
891         Object[] finderArgs = new Object[] {
892                 new Long(tagId), new Long(classNameId)
893             };
894 
895         Object result = null;
896 
897         if (retrieveFromCache) {
898             result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_T_C,
899                     finderArgs, this);
900         }
901 
902         if (result == null) {
903             Session session = null;
904 
905             try {
906                 session = openSession();
907 
908                 StringBundler query = new StringBundler(4);
909 
910                 query.append(_SQL_SELECT_ASSETTAGSTATS_WHERE);
911 
912                 query.append(_FINDER_COLUMN_T_C_TAGID_2);
913 
914                 query.append(_FINDER_COLUMN_T_C_CLASSNAMEID_2);
915 
916                 query.append(AssetTagStatsModelImpl.ORDER_BY_JPQL);
917 
918                 String sql = query.toString();
919 
920                 Query q = session.createQuery(sql);
921 
922                 QueryPos qPos = QueryPos.getInstance(q);
923 
924                 qPos.add(tagId);
925 
926                 qPos.add(classNameId);
927 
928                 List<AssetTagStats> list = q.list();
929 
930                 result = list;
931 
932                 AssetTagStats assetTagStats = null;
933 
934                 if (list.isEmpty()) {
935                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_C,
936                         finderArgs, list);
937                 }
938                 else {
939                     assetTagStats = list.get(0);
940 
941                     cacheResult(assetTagStats);
942 
943                     if ((assetTagStats.getTagId() != tagId) ||
944                             (assetTagStats.getClassNameId() != classNameId)) {
945                         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_C,
946                             finderArgs, assetTagStats);
947                     }
948                 }
949 
950                 return assetTagStats;
951             }
952             catch (Exception e) {
953                 throw processException(e);
954             }
955             finally {
956                 if (result == null) {
957                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_C,
958                         finderArgs, new ArrayList<AssetTagStats>());
959                 }
960 
961                 closeSession(session);
962             }
963         }
964         else {
965             if (result instanceof List<?>) {
966                 return null;
967             }
968             else {
969                 return (AssetTagStats)result;
970             }
971         }
972     }
973 
974     public List<AssetTagStats> findAll() throws SystemException {
975         return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
976     }
977 
978     public List<AssetTagStats> findAll(int start, int end)
979         throws SystemException {
980         return findAll(start, end, null);
981     }
982 
983     public List<AssetTagStats> findAll(int start, int end,
984         OrderByComparator orderByComparator) throws SystemException {
985         Object[] finderArgs = new Object[] {
986                 String.valueOf(start), String.valueOf(end),
987                 String.valueOf(orderByComparator)
988             };
989 
990         List<AssetTagStats> list = (List<AssetTagStats>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
991                 finderArgs, this);
992 
993         if (list == null) {
994             Session session = null;
995 
996             try {
997                 session = openSession();
998 
999                 StringBundler query = null;
1000                String sql = null;
1001
1002                if (orderByComparator != null) {
1003                    query = new StringBundler(2 +
1004                            (orderByComparator.getOrderByFields().length * 3));
1005
1006                    query.append(_SQL_SELECT_ASSETTAGSTATS);
1007
1008                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1009                        orderByComparator);
1010
1011                    sql = query.toString();
1012                }
1013
1014                else {
1015                    sql = _SQL_SELECT_ASSETTAGSTATS.concat(AssetTagStatsModelImpl.ORDER_BY_JPQL);
1016                }
1017
1018                Query q = session.createQuery(sql);
1019
1020                if (orderByComparator == null) {
1021                    list = (List<AssetTagStats>)QueryUtil.list(q, getDialect(),
1022                            start, end, false);
1023
1024                    Collections.sort(list);
1025                }
1026                else {
1027                    list = (List<AssetTagStats>)QueryUtil.list(q, getDialect(),
1028                            start, end);
1029                }
1030            }
1031            catch (Exception e) {
1032                throw processException(e);
1033            }
1034            finally {
1035                if (list == null) {
1036                    list = new ArrayList<AssetTagStats>();
1037                }
1038
1039                cacheResult(list);
1040
1041                FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1042
1043                closeSession(session);
1044            }
1045        }
1046
1047        return list;
1048    }
1049
1050    public void removeByTagId(long tagId) throws SystemException {
1051        for (AssetTagStats assetTagStats : findByTagId(tagId)) {
1052            remove(assetTagStats);
1053        }
1054    }
1055
1056    public void removeByClassNameId(long classNameId) throws SystemException {
1057        for (AssetTagStats assetTagStats : findByClassNameId(classNameId)) {
1058            remove(assetTagStats);
1059        }
1060    }
1061
1062    public void removeByT_C(long tagId, long classNameId)
1063        throws NoSuchTagStatsException, SystemException {
1064        AssetTagStats assetTagStats = findByT_C(tagId, classNameId);
1065
1066        remove(assetTagStats);
1067    }
1068
1069    public void removeAll() throws SystemException {
1070        for (AssetTagStats assetTagStats : findAll()) {
1071            remove(assetTagStats);
1072        }
1073    }
1074
1075    public int countByTagId(long tagId) throws SystemException {
1076        Object[] finderArgs = new Object[] { new Long(tagId) };
1077
1078        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_TAGID,
1079                finderArgs, this);
1080
1081        if (count == null) {
1082            Session session = null;
1083
1084            try {
1085                session = openSession();
1086
1087                StringBundler query = new StringBundler(2);
1088
1089                query.append(_SQL_COUNT_ASSETTAGSTATS_WHERE);
1090
1091                query.append(_FINDER_COLUMN_TAGID_TAGID_2);
1092
1093                String sql = query.toString();
1094
1095                Query q = session.createQuery(sql);
1096
1097                QueryPos qPos = QueryPos.getInstance(q);
1098
1099                qPos.add(tagId);
1100
1101                count = (Long)q.uniqueResult();
1102            }
1103            catch (Exception e) {
1104                throw processException(e);
1105            }
1106            finally {
1107                if (count == null) {
1108                    count = Long.valueOf(0);
1109                }
1110
1111                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_TAGID,
1112                    finderArgs, count);
1113
1114                closeSession(session);
1115            }
1116        }
1117
1118        return count.intValue();
1119    }
1120
1121    public int countByClassNameId(long classNameId) throws SystemException {
1122        Object[] finderArgs = new Object[] { new Long(classNameId) };
1123
1124        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_CLASSNAMEID,
1125                finderArgs, this);
1126
1127        if (count == null) {
1128            Session session = null;
1129
1130            try {
1131                session = openSession();
1132
1133                StringBundler query = new StringBundler(2);
1134
1135                query.append(_SQL_COUNT_ASSETTAGSTATS_WHERE);
1136
1137                query.append(_FINDER_COLUMN_CLASSNAMEID_CLASSNAMEID_2);
1138
1139                String sql = query.toString();
1140
1141                Query q = session.createQuery(sql);
1142
1143                QueryPos qPos = QueryPos.getInstance(q);
1144
1145                qPos.add(classNameId);
1146
1147                count = (Long)q.uniqueResult();
1148            }
1149            catch (Exception e) {
1150                throw processException(e);
1151            }
1152            finally {
1153                if (count == null) {
1154                    count = Long.valueOf(0);
1155                }
1156
1157                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_CLASSNAMEID,
1158                    finderArgs, count);
1159
1160                closeSession(session);
1161            }
1162        }
1163
1164        return count.intValue();
1165    }
1166
1167    public int countByT_C(long tagId, long classNameId)
1168        throws SystemException {
1169        Object[] finderArgs = new Object[] {
1170                new Long(tagId), new Long(classNameId)
1171            };
1172
1173        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_T_C,
1174                finderArgs, this);
1175
1176        if (count == null) {
1177            Session session = null;
1178
1179            try {
1180                session = openSession();
1181
1182                StringBundler query = new StringBundler(3);
1183
1184                query.append(_SQL_COUNT_ASSETTAGSTATS_WHERE);
1185
1186                query.append(_FINDER_COLUMN_T_C_TAGID_2);
1187
1188                query.append(_FINDER_COLUMN_T_C_CLASSNAMEID_2);
1189
1190                String sql = query.toString();
1191
1192                Query q = session.createQuery(sql);
1193
1194                QueryPos qPos = QueryPos.getInstance(q);
1195
1196                qPos.add(tagId);
1197
1198                qPos.add(classNameId);
1199
1200                count = (Long)q.uniqueResult();
1201            }
1202            catch (Exception e) {
1203                throw processException(e);
1204            }
1205            finally {
1206                if (count == null) {
1207                    count = Long.valueOf(0);
1208                }
1209
1210                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_C, finderArgs,
1211                    count);
1212
1213                closeSession(session);
1214            }
1215        }
1216
1217        return count.intValue();
1218    }
1219
1220    public int countAll() throws SystemException {
1221        Object[] finderArgs = new Object[0];
1222
1223        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1224                finderArgs, this);
1225
1226        if (count == null) {
1227            Session session = null;
1228
1229            try {
1230                session = openSession();
1231
1232                Query q = session.createQuery(_SQL_COUNT_ASSETTAGSTATS);
1233
1234                count = (Long)q.uniqueResult();
1235            }
1236            catch (Exception e) {
1237                throw processException(e);
1238            }
1239            finally {
1240                if (count == null) {
1241                    count = Long.valueOf(0);
1242                }
1243
1244                FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1245                    count);
1246
1247                closeSession(session);
1248            }
1249        }
1250
1251        return count.intValue();
1252    }
1253
1254    public void afterPropertiesSet() {
1255        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1256                    com.liferay.portal.util.PropsUtil.get(
1257                        "value.object.listener.com.liferay.portlet.asset.model.AssetTagStats")));
1258
1259        if (listenerClassNames.length > 0) {
1260            try {
1261                List<ModelListener<AssetTagStats>> listenersList = new ArrayList<ModelListener<AssetTagStats>>();
1262
1263                for (String listenerClassName : listenerClassNames) {
1264                    listenersList.add((ModelListener<AssetTagStats>)Class.forName(
1265                            listenerClassName).newInstance());
1266                }
1267
1268                listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1269            }
1270            catch (Exception e) {
1271                _log.error(e);
1272            }
1273        }
1274    }
1275
1276    @BeanReference(type = AssetCategoryPersistence.class)
1277    protected AssetCategoryPersistence assetCategoryPersistence;
1278    @BeanReference(type = AssetCategoryPropertyPersistence.class)
1279    protected AssetCategoryPropertyPersistence assetCategoryPropertyPersistence;
1280    @BeanReference(type = AssetEntryPersistence.class)
1281    protected AssetEntryPersistence assetEntryPersistence;
1282    @BeanReference(type = AssetLinkPersistence.class)
1283    protected AssetLinkPersistence assetLinkPersistence;
1284    @BeanReference(type = AssetTagPersistence.class)
1285    protected AssetTagPersistence assetTagPersistence;
1286    @BeanReference(type = AssetTagPropertyPersistence.class)
1287    protected AssetTagPropertyPersistence assetTagPropertyPersistence;
1288    @BeanReference(type = AssetTagStatsPersistence.class)
1289    protected AssetTagStatsPersistence assetTagStatsPersistence;
1290    @BeanReference(type = AssetVocabularyPersistence.class)
1291    protected AssetVocabularyPersistence assetVocabularyPersistence;
1292    @BeanReference(type = ResourcePersistence.class)
1293    protected ResourcePersistence resourcePersistence;
1294    @BeanReference(type = UserPersistence.class)
1295    protected UserPersistence userPersistence;
1296    private static final String _SQL_SELECT_ASSETTAGSTATS = "SELECT assetTagStats FROM AssetTagStats assetTagStats";
1297    private static final String _SQL_SELECT_ASSETTAGSTATS_WHERE = "SELECT assetTagStats FROM AssetTagStats assetTagStats WHERE ";
1298    private static final String _SQL_COUNT_ASSETTAGSTATS = "SELECT COUNT(assetTagStats) FROM AssetTagStats assetTagStats";
1299    private static final String _SQL_COUNT_ASSETTAGSTATS_WHERE = "SELECT COUNT(assetTagStats) FROM AssetTagStats assetTagStats WHERE ";
1300    private static final String _FINDER_COLUMN_TAGID_TAGID_2 = "assetTagStats.tagId = ?";
1301    private static final String _FINDER_COLUMN_CLASSNAMEID_CLASSNAMEID_2 = "assetTagStats.classNameId = ?";
1302    private static final String _FINDER_COLUMN_T_C_TAGID_2 = "assetTagStats.tagId = ? AND ";
1303    private static final String _FINDER_COLUMN_T_C_CLASSNAMEID_2 = "assetTagStats.classNameId = ?";
1304    private static final String _ORDER_BY_ENTITY_ALIAS = "assetTagStats.";
1305    private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No AssetTagStats exists with the primary key ";
1306    private static final String _NO_SUCH_ENTITY_WITH_KEY = "No AssetTagStats exists with the key {";
1307    private static Log _log = LogFactoryUtil.getLog(AssetTagStatsPersistenceImpl.class);
1308}