1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.portlet.blogs.service.persistence;
21  
22  import com.liferay.portal.SystemException;
23  import com.liferay.portal.kernel.annotation.BeanReference;
24  import com.liferay.portal.kernel.cache.CacheRegistry;
25  import com.liferay.portal.kernel.dao.orm.DynamicQuery;
26  import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
27  import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
28  import com.liferay.portal.kernel.dao.orm.FinderPath;
29  import com.liferay.portal.kernel.dao.orm.Query;
30  import com.liferay.portal.kernel.dao.orm.QueryPos;
31  import com.liferay.portal.kernel.dao.orm.QueryUtil;
32  import com.liferay.portal.kernel.dao.orm.Session;
33  import com.liferay.portal.kernel.log.Log;
34  import com.liferay.portal.kernel.log.LogFactoryUtil;
35  import com.liferay.portal.kernel.util.GetterUtil;
36  import com.liferay.portal.kernel.util.OrderByComparator;
37  import com.liferay.portal.kernel.util.StringPool;
38  import com.liferay.portal.kernel.util.StringUtil;
39  import com.liferay.portal.model.ModelListener;
40  import com.liferay.portal.service.persistence.BatchSessionUtil;
41  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
42  
43  import com.liferay.portlet.blogs.NoSuchStatsUserException;
44  import com.liferay.portlet.blogs.model.BlogsStatsUser;
45  import com.liferay.portlet.blogs.model.impl.BlogsStatsUserImpl;
46  import com.liferay.portlet.blogs.model.impl.BlogsStatsUserModelImpl;
47  
48  import java.util.ArrayList;
49  import java.util.Collections;
50  import java.util.List;
51  
52  /**
53   * <a href="BlogsStatsUserPersistenceImpl.java.html"><b><i>View Source</i></b></a>
54   *
55   * @author Brian Wing Shun Chan
56   *
57   */
58  public class BlogsStatsUserPersistenceImpl extends BasePersistenceImpl
59      implements BlogsStatsUserPersistence {
60      public static final String FINDER_CLASS_NAME_ENTITY = BlogsStatsUserImpl.class.getName();
61      public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
62          ".List";
63      public static final FinderPath FINDER_PATH_FIND_BY_GROUPID = new FinderPath(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
64              BlogsStatsUserModelImpl.FINDER_CACHE_ENABLED,
65              FINDER_CLASS_NAME_LIST, "findByGroupId",
66              new String[] { Long.class.getName() });
67      public static final FinderPath FINDER_PATH_FIND_BY_OBC_GROUPID = new FinderPath(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
68              BlogsStatsUserModelImpl.FINDER_CACHE_ENABLED,
69              FINDER_CLASS_NAME_LIST, "findByGroupId",
70              new String[] {
71                  Long.class.getName(),
72                  
73              "java.lang.Integer", "java.lang.Integer",
74                  "com.liferay.portal.kernel.util.OrderByComparator"
75              });
76      public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
77              BlogsStatsUserModelImpl.FINDER_CACHE_ENABLED,
78              FINDER_CLASS_NAME_LIST, "countByGroupId",
79              new String[] { Long.class.getName() });
80      public static final FinderPath FINDER_PATH_FIND_BY_USERID = new FinderPath(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
81              BlogsStatsUserModelImpl.FINDER_CACHE_ENABLED,
82              FINDER_CLASS_NAME_LIST, "findByUserId",
83              new String[] { Long.class.getName() });
84      public static final FinderPath FINDER_PATH_FIND_BY_OBC_USERID = new FinderPath(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
85              BlogsStatsUserModelImpl.FINDER_CACHE_ENABLED,
86              FINDER_CLASS_NAME_LIST, "findByUserId",
87              new String[] {
88                  Long.class.getName(),
89                  
90              "java.lang.Integer", "java.lang.Integer",
91                  "com.liferay.portal.kernel.util.OrderByComparator"
92              });
93      public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
94              BlogsStatsUserModelImpl.FINDER_CACHE_ENABLED,
95              FINDER_CLASS_NAME_LIST, "countByUserId",
96              new String[] { Long.class.getName() });
97      public static final FinderPath FINDER_PATH_FETCH_BY_G_U = new FinderPath(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
98              BlogsStatsUserModelImpl.FINDER_CACHE_ENABLED,
99              FINDER_CLASS_NAME_ENTITY, "fetchByG_U",
100             new String[] { Long.class.getName(), Long.class.getName() });
101     public static final FinderPath FINDER_PATH_COUNT_BY_G_U = new FinderPath(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
102             BlogsStatsUserModelImpl.FINDER_CACHE_ENABLED,
103             FINDER_CLASS_NAME_LIST, "countByG_U",
104             new String[] { Long.class.getName(), Long.class.getName() });
105     public static final FinderPath FINDER_PATH_FIND_BY_G_E = new FinderPath(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
106             BlogsStatsUserModelImpl.FINDER_CACHE_ENABLED,
107             FINDER_CLASS_NAME_LIST, "findByG_E",
108             new String[] { Long.class.getName(), Integer.class.getName() });
109     public static final FinderPath FINDER_PATH_FIND_BY_OBC_G_E = new FinderPath(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
110             BlogsStatsUserModelImpl.FINDER_CACHE_ENABLED,
111             FINDER_CLASS_NAME_LIST, "findByG_E",
112             new String[] {
113                 Long.class.getName(), Integer.class.getName(),
114                 
115             "java.lang.Integer", "java.lang.Integer",
116                 "com.liferay.portal.kernel.util.OrderByComparator"
117             });
118     public static final FinderPath FINDER_PATH_COUNT_BY_G_E = new FinderPath(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
119             BlogsStatsUserModelImpl.FINDER_CACHE_ENABLED,
120             FINDER_CLASS_NAME_LIST, "countByG_E",
121             new String[] { Long.class.getName(), Integer.class.getName() });
122     public static final FinderPath FINDER_PATH_FIND_BY_C_E = new FinderPath(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
123             BlogsStatsUserModelImpl.FINDER_CACHE_ENABLED,
124             FINDER_CLASS_NAME_LIST, "findByC_E",
125             new String[] { Long.class.getName(), Integer.class.getName() });
126     public static final FinderPath FINDER_PATH_FIND_BY_OBC_C_E = new FinderPath(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
127             BlogsStatsUserModelImpl.FINDER_CACHE_ENABLED,
128             FINDER_CLASS_NAME_LIST, "findByC_E",
129             new String[] {
130                 Long.class.getName(), Integer.class.getName(),
131                 
132             "java.lang.Integer", "java.lang.Integer",
133                 "com.liferay.portal.kernel.util.OrderByComparator"
134             });
135     public static final FinderPath FINDER_PATH_COUNT_BY_C_E = new FinderPath(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
136             BlogsStatsUserModelImpl.FINDER_CACHE_ENABLED,
137             FINDER_CLASS_NAME_LIST, "countByC_E",
138             new String[] { Long.class.getName(), Integer.class.getName() });
139     public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
140             BlogsStatsUserModelImpl.FINDER_CACHE_ENABLED,
141             FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
142     public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
143             BlogsStatsUserModelImpl.FINDER_CACHE_ENABLED,
144             FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
145 
146     public void cacheResult(BlogsStatsUser blogsStatsUser) {
147         EntityCacheUtil.putResult(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
148             BlogsStatsUserImpl.class, blogsStatsUser.getPrimaryKey(),
149             blogsStatsUser);
150 
151         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U,
152             new Object[] {
153                 new Long(blogsStatsUser.getGroupId()),
154                 new Long(blogsStatsUser.getUserId())
155             }, blogsStatsUser);
156     }
157 
158     public void cacheResult(List<BlogsStatsUser> blogsStatsUsers) {
159         for (BlogsStatsUser blogsStatsUser : blogsStatsUsers) {
160             if (EntityCacheUtil.getResult(
161                         BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
162                         BlogsStatsUserImpl.class,
163                         blogsStatsUser.getPrimaryKey(), this) == null) {
164                 cacheResult(blogsStatsUser);
165             }
166         }
167     }
168 
169     public void clearCache() {
170         CacheRegistry.clear(BlogsStatsUserImpl.class.getName());
171         EntityCacheUtil.clearCache(BlogsStatsUserImpl.class.getName());
172         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
173         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
174     }
175 
176     public BlogsStatsUser create(long statsUserId) {
177         BlogsStatsUser blogsStatsUser = new BlogsStatsUserImpl();
178 
179         blogsStatsUser.setNew(true);
180         blogsStatsUser.setPrimaryKey(statsUserId);
181 
182         return blogsStatsUser;
183     }
184 
185     public BlogsStatsUser remove(long statsUserId)
186         throws NoSuchStatsUserException, SystemException {
187         Session session = null;
188 
189         try {
190             session = openSession();
191 
192             BlogsStatsUser blogsStatsUser = (BlogsStatsUser)session.get(BlogsStatsUserImpl.class,
193                     new Long(statsUserId));
194 
195             if (blogsStatsUser == null) {
196                 if (_log.isWarnEnabled()) {
197                     _log.warn("No BlogsStatsUser exists with the primary key " +
198                         statsUserId);
199                 }
200 
201                 throw new NoSuchStatsUserException(
202                     "No BlogsStatsUser exists with the primary key " +
203                     statsUserId);
204             }
205 
206             return remove(blogsStatsUser);
207         }
208         catch (NoSuchStatsUserException nsee) {
209             throw nsee;
210         }
211         catch (Exception e) {
212             throw processException(e);
213         }
214         finally {
215             closeSession(session);
216         }
217     }
218 
219     public BlogsStatsUser remove(BlogsStatsUser blogsStatsUser)
220         throws SystemException {
221         for (ModelListener<BlogsStatsUser> listener : listeners) {
222             listener.onBeforeRemove(blogsStatsUser);
223         }
224 
225         blogsStatsUser = removeImpl(blogsStatsUser);
226 
227         for (ModelListener<BlogsStatsUser> listener : listeners) {
228             listener.onAfterRemove(blogsStatsUser);
229         }
230 
231         return blogsStatsUser;
232     }
233 
234     protected BlogsStatsUser removeImpl(BlogsStatsUser blogsStatsUser)
235         throws SystemException {
236         Session session = null;
237 
238         try {
239             session = openSession();
240 
241             if (blogsStatsUser.isCachedModel() || BatchSessionUtil.isEnabled()) {
242                 Object staleObject = session.get(BlogsStatsUserImpl.class,
243                         blogsStatsUser.getPrimaryKeyObj());
244 
245                 if (staleObject != null) {
246                     session.evict(staleObject);
247                 }
248             }
249 
250             session.delete(blogsStatsUser);
251 
252             session.flush();
253         }
254         catch (Exception e) {
255             throw processException(e);
256         }
257         finally {
258             closeSession(session);
259         }
260 
261         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
262 
263         BlogsStatsUserModelImpl blogsStatsUserModelImpl = (BlogsStatsUserModelImpl)blogsStatsUser;
264 
265         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_U,
266             new Object[] {
267                 new Long(blogsStatsUserModelImpl.getOriginalGroupId()),
268                 new Long(blogsStatsUserModelImpl.getOriginalUserId())
269             });
270 
271         EntityCacheUtil.removeResult(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
272             BlogsStatsUserImpl.class, blogsStatsUser.getPrimaryKey());
273 
274         return blogsStatsUser;
275     }
276 
277     /**
278      * @deprecated Use <code>update(BlogsStatsUser blogsStatsUser, boolean merge)</code>.
279      */
280     public BlogsStatsUser update(BlogsStatsUser blogsStatsUser)
281         throws SystemException {
282         if (_log.isWarnEnabled()) {
283             _log.warn(
284                 "Using the deprecated update(BlogsStatsUser blogsStatsUser) method. Use update(BlogsStatsUser blogsStatsUser, boolean merge) instead.");
285         }
286 
287         return update(blogsStatsUser, false);
288     }
289 
290     /**
291      * Add, update, or merge, the entity. This method also calls the model
292      * listeners to trigger the proper events associated with adding, deleting,
293      * or updating an entity.
294      *
295      * @param        blogsStatsUser the entity to add, update, or merge
296      * @param        merge boolean value for whether to merge the entity. The
297      *                default value is false. Setting merge to true is more
298      *                expensive and should only be true when blogsStatsUser is
299      *                transient. See LEP-5473 for a detailed discussion of this
300      *                method.
301      * @return        true if the portlet can be displayed via Ajax
302      */
303     public BlogsStatsUser update(BlogsStatsUser blogsStatsUser, boolean merge)
304         throws SystemException {
305         boolean isNew = blogsStatsUser.isNew();
306 
307         for (ModelListener<BlogsStatsUser> listener : listeners) {
308             if (isNew) {
309                 listener.onBeforeCreate(blogsStatsUser);
310             }
311             else {
312                 listener.onBeforeUpdate(blogsStatsUser);
313             }
314         }
315 
316         blogsStatsUser = updateImpl(blogsStatsUser, merge);
317 
318         for (ModelListener<BlogsStatsUser> listener : listeners) {
319             if (isNew) {
320                 listener.onAfterCreate(blogsStatsUser);
321             }
322             else {
323                 listener.onAfterUpdate(blogsStatsUser);
324             }
325         }
326 
327         return blogsStatsUser;
328     }
329 
330     public BlogsStatsUser updateImpl(
331         com.liferay.portlet.blogs.model.BlogsStatsUser blogsStatsUser,
332         boolean merge) throws SystemException {
333         boolean isNew = blogsStatsUser.isNew();
334 
335         BlogsStatsUserModelImpl blogsStatsUserModelImpl = (BlogsStatsUserModelImpl)blogsStatsUser;
336 
337         Session session = null;
338 
339         try {
340             session = openSession();
341 
342             BatchSessionUtil.update(session, blogsStatsUser, merge);
343 
344             blogsStatsUser.setNew(false);
345         }
346         catch (Exception e) {
347             throw processException(e);
348         }
349         finally {
350             closeSession(session);
351         }
352 
353         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
354 
355         EntityCacheUtil.putResult(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
356             BlogsStatsUserImpl.class, blogsStatsUser.getPrimaryKey(),
357             blogsStatsUser);
358 
359         if (!isNew &&
360                 ((blogsStatsUser.getGroupId() != blogsStatsUserModelImpl.getOriginalGroupId()) ||
361                 (blogsStatsUser.getUserId() != blogsStatsUserModelImpl.getOriginalUserId()))) {
362             FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_U,
363                 new Object[] {
364                     new Long(blogsStatsUserModelImpl.getOriginalGroupId()),
365                     new Long(blogsStatsUserModelImpl.getOriginalUserId())
366                 });
367         }
368 
369         if (isNew ||
370                 ((blogsStatsUser.getGroupId() != blogsStatsUserModelImpl.getOriginalGroupId()) ||
371                 (blogsStatsUser.getUserId() != blogsStatsUserModelImpl.getOriginalUserId()))) {
372             FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U,
373                 new Object[] {
374                     new Long(blogsStatsUser.getGroupId()),
375                     new Long(blogsStatsUser.getUserId())
376                 }, blogsStatsUser);
377         }
378 
379         return blogsStatsUser;
380     }
381 
382     public BlogsStatsUser findByPrimaryKey(long statsUserId)
383         throws NoSuchStatsUserException, SystemException {
384         BlogsStatsUser blogsStatsUser = fetchByPrimaryKey(statsUserId);
385 
386         if (blogsStatsUser == null) {
387             if (_log.isWarnEnabled()) {
388                 _log.warn("No BlogsStatsUser exists with the primary key " +
389                     statsUserId);
390             }
391 
392             throw new NoSuchStatsUserException(
393                 "No BlogsStatsUser exists with the primary key " + statsUserId);
394         }
395 
396         return blogsStatsUser;
397     }
398 
399     public BlogsStatsUser fetchByPrimaryKey(long statsUserId)
400         throws SystemException {
401         BlogsStatsUser blogsStatsUser = (BlogsStatsUser)EntityCacheUtil.getResult(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
402                 BlogsStatsUserImpl.class, statsUserId, this);
403 
404         if (blogsStatsUser == null) {
405             Session session = null;
406 
407             try {
408                 session = openSession();
409 
410                 blogsStatsUser = (BlogsStatsUser)session.get(BlogsStatsUserImpl.class,
411                         new Long(statsUserId));
412             }
413             catch (Exception e) {
414                 throw processException(e);
415             }
416             finally {
417                 if (blogsStatsUser != null) {
418                     cacheResult(blogsStatsUser);
419                 }
420 
421                 closeSession(session);
422             }
423         }
424 
425         return blogsStatsUser;
426     }
427 
428     public List<BlogsStatsUser> findByGroupId(long groupId)
429         throws SystemException {
430         Object[] finderArgs = new Object[] { new Long(groupId) };
431 
432         List<BlogsStatsUser> list = (List<BlogsStatsUser>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_GROUPID,
433                 finderArgs, this);
434 
435         if (list == null) {
436             Session session = null;
437 
438             try {
439                 session = openSession();
440 
441                 StringBuilder query = new StringBuilder();
442 
443                 query.append(
444                     "FROM com.liferay.portlet.blogs.model.BlogsStatsUser WHERE ");
445 
446                 query.append("groupId = ?");
447 
448                 query.append(" ");
449 
450                 query.append("ORDER BY ");
451 
452                 query.append("entryCount DESC");
453 
454                 Query q = session.createQuery(query.toString());
455 
456                 QueryPos qPos = QueryPos.getInstance(q);
457 
458                 qPos.add(groupId);
459 
460                 list = q.list();
461             }
462             catch (Exception e) {
463                 throw processException(e);
464             }
465             finally {
466                 if (list == null) {
467                     list = new ArrayList<BlogsStatsUser>();
468                 }
469 
470                 cacheResult(list);
471 
472                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID,
473                     finderArgs, list);
474 
475                 closeSession(session);
476             }
477         }
478 
479         return list;
480     }
481 
482     public List<BlogsStatsUser> findByGroupId(long groupId, int start, int end)
483         throws SystemException {
484         return findByGroupId(groupId, start, end, null);
485     }
486 
487     public List<BlogsStatsUser> findByGroupId(long groupId, int start, int end,
488         OrderByComparator obc) throws SystemException {
489         Object[] finderArgs = new Object[] {
490                 new Long(groupId),
491                 
492                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
493             };
494 
495         List<BlogsStatsUser> list = (List<BlogsStatsUser>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_GROUPID,
496                 finderArgs, this);
497 
498         if (list == null) {
499             Session session = null;
500 
501             try {
502                 session = openSession();
503 
504                 StringBuilder query = new StringBuilder();
505 
506                 query.append(
507                     "FROM com.liferay.portlet.blogs.model.BlogsStatsUser WHERE ");
508 
509                 query.append("groupId = ?");
510 
511                 query.append(" ");
512 
513                 if (obc != null) {
514                     query.append("ORDER BY ");
515                     query.append(obc.getOrderBy());
516                 }
517 
518                 else {
519                     query.append("ORDER BY ");
520 
521                     query.append("entryCount DESC");
522                 }
523 
524                 Query q = session.createQuery(query.toString());
525 
526                 QueryPos qPos = QueryPos.getInstance(q);
527 
528                 qPos.add(groupId);
529 
530                 list = (List<BlogsStatsUser>)QueryUtil.list(q, getDialect(),
531                         start, end);
532             }
533             catch (Exception e) {
534                 throw processException(e);
535             }
536             finally {
537                 if (list == null) {
538                     list = new ArrayList<BlogsStatsUser>();
539                 }
540 
541                 cacheResult(list);
542 
543                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_GROUPID,
544                     finderArgs, list);
545 
546                 closeSession(session);
547             }
548         }
549 
550         return list;
551     }
552 
553     public BlogsStatsUser findByGroupId_First(long groupId,
554         OrderByComparator obc) throws NoSuchStatsUserException, SystemException {
555         List<BlogsStatsUser> list = findByGroupId(groupId, 0, 1, obc);
556 
557         if (list.isEmpty()) {
558             StringBuilder msg = new StringBuilder();
559 
560             msg.append("No BlogsStatsUser exists with the key {");
561 
562             msg.append("groupId=" + groupId);
563 
564             msg.append(StringPool.CLOSE_CURLY_BRACE);
565 
566             throw new NoSuchStatsUserException(msg.toString());
567         }
568         else {
569             return list.get(0);
570         }
571     }
572 
573     public BlogsStatsUser findByGroupId_Last(long groupId, OrderByComparator obc)
574         throws NoSuchStatsUserException, SystemException {
575         int count = countByGroupId(groupId);
576 
577         List<BlogsStatsUser> list = findByGroupId(groupId, count - 1, count, obc);
578 
579         if (list.isEmpty()) {
580             StringBuilder msg = new StringBuilder();
581 
582             msg.append("No BlogsStatsUser exists with the key {");
583 
584             msg.append("groupId=" + groupId);
585 
586             msg.append(StringPool.CLOSE_CURLY_BRACE);
587 
588             throw new NoSuchStatsUserException(msg.toString());
589         }
590         else {
591             return list.get(0);
592         }
593     }
594 
595     public BlogsStatsUser[] findByGroupId_PrevAndNext(long statsUserId,
596         long groupId, OrderByComparator obc)
597         throws NoSuchStatsUserException, SystemException {
598         BlogsStatsUser blogsStatsUser = findByPrimaryKey(statsUserId);
599 
600         int count = countByGroupId(groupId);
601 
602         Session session = null;
603 
604         try {
605             session = openSession();
606 
607             StringBuilder query = new StringBuilder();
608 
609             query.append(
610                 "FROM com.liferay.portlet.blogs.model.BlogsStatsUser WHERE ");
611 
612             query.append("groupId = ?");
613 
614             query.append(" ");
615 
616             if (obc != null) {
617                 query.append("ORDER BY ");
618                 query.append(obc.getOrderBy());
619             }
620 
621             else {
622                 query.append("ORDER BY ");
623 
624                 query.append("entryCount DESC");
625             }
626 
627             Query q = session.createQuery(query.toString());
628 
629             QueryPos qPos = QueryPos.getInstance(q);
630 
631             qPos.add(groupId);
632 
633             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
634                     blogsStatsUser);
635 
636             BlogsStatsUser[] array = new BlogsStatsUserImpl[3];
637 
638             array[0] = (BlogsStatsUser)objArray[0];
639             array[1] = (BlogsStatsUser)objArray[1];
640             array[2] = (BlogsStatsUser)objArray[2];
641 
642             return array;
643         }
644         catch (Exception e) {
645             throw processException(e);
646         }
647         finally {
648             closeSession(session);
649         }
650     }
651 
652     public List<BlogsStatsUser> findByUserId(long userId)
653         throws SystemException {
654         Object[] finderArgs = new Object[] { new Long(userId) };
655 
656         List<BlogsStatsUser> list = (List<BlogsStatsUser>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_USERID,
657                 finderArgs, this);
658 
659         if (list == null) {
660             Session session = null;
661 
662             try {
663                 session = openSession();
664 
665                 StringBuilder query = new StringBuilder();
666 
667                 query.append(
668                     "FROM com.liferay.portlet.blogs.model.BlogsStatsUser WHERE ");
669 
670                 query.append("userId = ?");
671 
672                 query.append(" ");
673 
674                 query.append("ORDER BY ");
675 
676                 query.append("entryCount DESC");
677 
678                 Query q = session.createQuery(query.toString());
679 
680                 QueryPos qPos = QueryPos.getInstance(q);
681 
682                 qPos.add(userId);
683 
684                 list = q.list();
685             }
686             catch (Exception e) {
687                 throw processException(e);
688             }
689             finally {
690                 if (list == null) {
691                     list = new ArrayList<BlogsStatsUser>();
692                 }
693 
694                 cacheResult(list);
695 
696                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_USERID,
697                     finderArgs, list);
698 
699                 closeSession(session);
700             }
701         }
702 
703         return list;
704     }
705 
706     public List<BlogsStatsUser> findByUserId(long userId, int start, int end)
707         throws SystemException {
708         return findByUserId(userId, start, end, null);
709     }
710 
711     public List<BlogsStatsUser> findByUserId(long userId, int start, int end,
712         OrderByComparator obc) throws SystemException {
713         Object[] finderArgs = new Object[] {
714                 new Long(userId),
715                 
716                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
717             };
718 
719         List<BlogsStatsUser> list = (List<BlogsStatsUser>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_USERID,
720                 finderArgs, this);
721 
722         if (list == null) {
723             Session session = null;
724 
725             try {
726                 session = openSession();
727 
728                 StringBuilder query = new StringBuilder();
729 
730                 query.append(
731                     "FROM com.liferay.portlet.blogs.model.BlogsStatsUser WHERE ");
732 
733                 query.append("userId = ?");
734 
735                 query.append(" ");
736 
737                 if (obc != null) {
738                     query.append("ORDER BY ");
739                     query.append(obc.getOrderBy());
740                 }
741 
742                 else {
743                     query.append("ORDER BY ");
744 
745                     query.append("entryCount DESC");
746                 }
747 
748                 Query q = session.createQuery(query.toString());
749 
750                 QueryPos qPos = QueryPos.getInstance(q);
751 
752                 qPos.add(userId);
753 
754                 list = (List<BlogsStatsUser>)QueryUtil.list(q, getDialect(),
755                         start, end);
756             }
757             catch (Exception e) {
758                 throw processException(e);
759             }
760             finally {
761                 if (list == null) {
762                     list = new ArrayList<BlogsStatsUser>();
763                 }
764 
765                 cacheResult(list);
766 
767                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_USERID,
768                     finderArgs, list);
769 
770                 closeSession(session);
771             }
772         }
773 
774         return list;
775     }
776 
777     public BlogsStatsUser findByUserId_First(long userId, OrderByComparator obc)
778         throws NoSuchStatsUserException, SystemException {
779         List<BlogsStatsUser> list = findByUserId(userId, 0, 1, obc);
780 
781         if (list.isEmpty()) {
782             StringBuilder msg = new StringBuilder();
783 
784             msg.append("No BlogsStatsUser exists with the key {");
785 
786             msg.append("userId=" + userId);
787 
788             msg.append(StringPool.CLOSE_CURLY_BRACE);
789 
790             throw new NoSuchStatsUserException(msg.toString());
791         }
792         else {
793             return list.get(0);
794         }
795     }
796 
797     public BlogsStatsUser findByUserId_Last(long userId, OrderByComparator obc)
798         throws NoSuchStatsUserException, SystemException {
799         int count = countByUserId(userId);
800 
801         List<BlogsStatsUser> list = findByUserId(userId, count - 1, count, obc);
802 
803         if (list.isEmpty()) {
804             StringBuilder msg = new StringBuilder();
805 
806             msg.append("No BlogsStatsUser exists with the key {");
807 
808             msg.append("userId=" + userId);
809 
810             msg.append(StringPool.CLOSE_CURLY_BRACE);
811 
812             throw new NoSuchStatsUserException(msg.toString());
813         }
814         else {
815             return list.get(0);
816         }
817     }
818 
819     public BlogsStatsUser[] findByUserId_PrevAndNext(long statsUserId,
820         long userId, OrderByComparator obc)
821         throws NoSuchStatsUserException, SystemException {
822         BlogsStatsUser blogsStatsUser = findByPrimaryKey(statsUserId);
823 
824         int count = countByUserId(userId);
825 
826         Session session = null;
827 
828         try {
829             session = openSession();
830 
831             StringBuilder query = new StringBuilder();
832 
833             query.append(
834                 "FROM com.liferay.portlet.blogs.model.BlogsStatsUser WHERE ");
835 
836             query.append("userId = ?");
837 
838             query.append(" ");
839 
840             if (obc != null) {
841                 query.append("ORDER BY ");
842                 query.append(obc.getOrderBy());
843             }
844 
845             else {
846                 query.append("ORDER BY ");
847 
848                 query.append("entryCount DESC");
849             }
850 
851             Query q = session.createQuery(query.toString());
852 
853             QueryPos qPos = QueryPos.getInstance(q);
854 
855             qPos.add(userId);
856 
857             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
858                     blogsStatsUser);
859 
860             BlogsStatsUser[] array = new BlogsStatsUserImpl[3];
861 
862             array[0] = (BlogsStatsUser)objArray[0];
863             array[1] = (BlogsStatsUser)objArray[1];
864             array[2] = (BlogsStatsUser)objArray[2];
865 
866             return array;
867         }
868         catch (Exception e) {
869             throw processException(e);
870         }
871         finally {
872             closeSession(session);
873         }
874     }
875 
876     public BlogsStatsUser findByG_U(long groupId, long userId)
877         throws NoSuchStatsUserException, SystemException {
878         BlogsStatsUser blogsStatsUser = fetchByG_U(groupId, userId);
879 
880         if (blogsStatsUser == null) {
881             StringBuilder msg = new StringBuilder();
882 
883             msg.append("No BlogsStatsUser exists with the key {");
884 
885             msg.append("groupId=" + groupId);
886 
887             msg.append(", ");
888             msg.append("userId=" + userId);
889 
890             msg.append(StringPool.CLOSE_CURLY_BRACE);
891 
892             if (_log.isWarnEnabled()) {
893                 _log.warn(msg.toString());
894             }
895 
896             throw new NoSuchStatsUserException(msg.toString());
897         }
898 
899         return blogsStatsUser;
900     }
901 
902     public BlogsStatsUser fetchByG_U(long groupId, long userId)
903         throws SystemException {
904         return fetchByG_U(groupId, userId, true);
905     }
906 
907     public BlogsStatsUser fetchByG_U(long groupId, long userId,
908         boolean retrieveFromCache) throws SystemException {
909         Object[] finderArgs = new Object[] { new Long(groupId), new Long(userId) };
910 
911         Object result = null;
912 
913         if (retrieveFromCache) {
914             result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_U,
915                     finderArgs, this);
916         }
917 
918         if (result == null) {
919             Session session = null;
920 
921             try {
922                 session = openSession();
923 
924                 StringBuilder query = new StringBuilder();
925 
926                 query.append(
927                     "FROM com.liferay.portlet.blogs.model.BlogsStatsUser WHERE ");
928 
929                 query.append("groupId = ?");
930 
931                 query.append(" AND ");
932 
933                 query.append("userId = ?");
934 
935                 query.append(" ");
936 
937                 query.append("ORDER BY ");
938 
939                 query.append("entryCount DESC");
940 
941                 Query q = session.createQuery(query.toString());
942 
943                 QueryPos qPos = QueryPos.getInstance(q);
944 
945                 qPos.add(groupId);
946 
947                 qPos.add(userId);
948 
949                 List<BlogsStatsUser> list = q.list();
950 
951                 result = list;
952 
953                 BlogsStatsUser blogsStatsUser = null;
954 
955                 if (list.isEmpty()) {
956                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U,
957                         finderArgs, list);
958                 }
959                 else {
960                     blogsStatsUser = list.get(0);
961 
962                     cacheResult(blogsStatsUser);
963 
964                     if ((blogsStatsUser.getGroupId() != groupId) ||
965                             (blogsStatsUser.getUserId() != userId)) {
966                         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U,
967                             finderArgs, list);
968                     }
969                 }
970 
971                 return blogsStatsUser;
972             }
973             catch (Exception e) {
974                 throw processException(e);
975             }
976             finally {
977                 if (result == null) {
978                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U,
979                         finderArgs, new ArrayList<BlogsStatsUser>());
980                 }
981 
982                 closeSession(session);
983             }
984         }
985         else {
986             if (result instanceof List) {
987                 return null;
988             }
989             else {
990                 return (BlogsStatsUser)result;
991             }
992         }
993     }
994 
995     public List<BlogsStatsUser> findByG_E(long groupId, int entryCount)
996         throws SystemException {
997         Object[] finderArgs = new Object[] {
998                 new Long(groupId), new Integer(entryCount)
999             };
1000
1001        List<BlogsStatsUser> list = (List<BlogsStatsUser>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_E,
1002                finderArgs, this);
1003
1004        if (list == null) {
1005            Session session = null;
1006
1007            try {
1008                session = openSession();
1009
1010                StringBuilder query = new StringBuilder();
1011
1012                query.append(
1013                    "FROM com.liferay.portlet.blogs.model.BlogsStatsUser WHERE ");
1014
1015                query.append("groupId = ?");
1016
1017                query.append(" AND ");
1018
1019                query.append("entryCount != ?");
1020
1021                query.append(" ");
1022
1023                query.append("ORDER BY ");
1024
1025                query.append("entryCount DESC");
1026
1027                Query q = session.createQuery(query.toString());
1028
1029                QueryPos qPos = QueryPos.getInstance(q);
1030
1031                qPos.add(groupId);
1032
1033                qPos.add(entryCount);
1034
1035                list = q.list();
1036            }
1037            catch (Exception e) {
1038                throw processException(e);
1039            }
1040            finally {
1041                if (list == null) {
1042                    list = new ArrayList<BlogsStatsUser>();
1043                }
1044
1045                cacheResult(list);
1046
1047                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_E, finderArgs,
1048                    list);
1049
1050                closeSession(session);
1051            }
1052        }
1053
1054        return list;
1055    }
1056
1057    public List<BlogsStatsUser> findByG_E(long groupId, int entryCount,
1058        int start, int end) throws SystemException {
1059        return findByG_E(groupId, entryCount, start, end, null);
1060    }
1061
1062    public List<BlogsStatsUser> findByG_E(long groupId, int entryCount,
1063        int start, int end, OrderByComparator obc) throws SystemException {
1064        Object[] finderArgs = new Object[] {
1065                new Long(groupId), new Integer(entryCount),
1066                
1067                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1068            };
1069
1070        List<BlogsStatsUser> list = (List<BlogsStatsUser>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_G_E,
1071                finderArgs, this);
1072
1073        if (list == null) {
1074            Session session = null;
1075
1076            try {
1077                session = openSession();
1078
1079                StringBuilder query = new StringBuilder();
1080
1081                query.append(
1082                    "FROM com.liferay.portlet.blogs.model.BlogsStatsUser WHERE ");
1083
1084                query.append("groupId = ?");
1085
1086                query.append(" AND ");
1087
1088                query.append("entryCount != ?");
1089
1090                query.append(" ");
1091
1092                if (obc != null) {
1093                    query.append("ORDER BY ");
1094                    query.append(obc.getOrderBy());
1095                }
1096
1097                else {
1098                    query.append("ORDER BY ");
1099
1100                    query.append("entryCount DESC");
1101                }
1102
1103                Query q = session.createQuery(query.toString());
1104
1105                QueryPos qPos = QueryPos.getInstance(q);
1106
1107                qPos.add(groupId);
1108
1109                qPos.add(entryCount);
1110
1111                list = (List<BlogsStatsUser>)QueryUtil.list(q, getDialect(),
1112                        start, end);
1113            }
1114            catch (Exception e) {
1115                throw processException(e);
1116            }
1117            finally {
1118                if (list == null) {
1119                    list = new ArrayList<BlogsStatsUser>();
1120                }
1121
1122                cacheResult(list);
1123
1124                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_G_E,
1125                    finderArgs, list);
1126
1127                closeSession(session);
1128            }
1129        }
1130
1131        return list;
1132    }
1133
1134    public BlogsStatsUser findByG_E_First(long groupId, int entryCount,
1135        OrderByComparator obc) throws NoSuchStatsUserException, SystemException {
1136        List<BlogsStatsUser> list = findByG_E(groupId, entryCount, 0, 1, obc);
1137
1138        if (list.isEmpty()) {
1139            StringBuilder msg = new StringBuilder();
1140
1141            msg.append("No BlogsStatsUser exists with the key {");
1142
1143            msg.append("groupId=" + groupId);
1144
1145            msg.append(", ");
1146            msg.append("entryCount=" + entryCount);
1147
1148            msg.append(StringPool.CLOSE_CURLY_BRACE);
1149
1150            throw new NoSuchStatsUserException(msg.toString());
1151        }
1152        else {
1153            return list.get(0);
1154        }
1155    }
1156
1157    public BlogsStatsUser findByG_E_Last(long groupId, int entryCount,
1158        OrderByComparator obc) throws NoSuchStatsUserException, SystemException {
1159        int count = countByG_E(groupId, entryCount);
1160
1161        List<BlogsStatsUser> list = findByG_E(groupId, entryCount, count - 1,
1162                count, obc);
1163
1164        if (list.isEmpty()) {
1165            StringBuilder msg = new StringBuilder();
1166
1167            msg.append("No BlogsStatsUser exists with the key {");
1168
1169            msg.append("groupId=" + groupId);
1170
1171            msg.append(", ");
1172            msg.append("entryCount=" + entryCount);
1173
1174            msg.append(StringPool.CLOSE_CURLY_BRACE);
1175
1176            throw new NoSuchStatsUserException(msg.toString());
1177        }
1178        else {
1179            return list.get(0);
1180        }
1181    }
1182
1183    public BlogsStatsUser[] findByG_E_PrevAndNext(long statsUserId,
1184        long groupId, int entryCount, OrderByComparator obc)
1185        throws NoSuchStatsUserException, SystemException {
1186        BlogsStatsUser blogsStatsUser = findByPrimaryKey(statsUserId);
1187
1188        int count = countByG_E(groupId, entryCount);
1189
1190        Session session = null;
1191
1192        try {
1193            session = openSession();
1194
1195            StringBuilder query = new StringBuilder();
1196
1197            query.append(
1198                "FROM com.liferay.portlet.blogs.model.BlogsStatsUser WHERE ");
1199
1200            query.append("groupId = ?");
1201
1202            query.append(" AND ");
1203
1204            query.append("entryCount != ?");
1205
1206            query.append(" ");
1207
1208            if (obc != null) {
1209                query.append("ORDER BY ");
1210                query.append(obc.getOrderBy());
1211            }
1212
1213            else {
1214                query.append("ORDER BY ");
1215
1216                query.append("entryCount DESC");
1217            }
1218
1219            Query q = session.createQuery(query.toString());
1220
1221            QueryPos qPos = QueryPos.getInstance(q);
1222
1223            qPos.add(groupId);
1224
1225            qPos.add(entryCount);
1226
1227            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1228                    blogsStatsUser);
1229
1230            BlogsStatsUser[] array = new BlogsStatsUserImpl[3];
1231
1232            array[0] = (BlogsStatsUser)objArray[0];
1233            array[1] = (BlogsStatsUser)objArray[1];
1234            array[2] = (BlogsStatsUser)objArray[2];
1235
1236            return array;
1237        }
1238        catch (Exception e) {
1239            throw processException(e);
1240        }
1241        finally {
1242            closeSession(session);
1243        }
1244    }
1245
1246    public List<BlogsStatsUser> findByC_E(long companyId, int entryCount)
1247        throws SystemException {
1248        Object[] finderArgs = new Object[] {
1249                new Long(companyId), new Integer(entryCount)
1250            };
1251
1252        List<BlogsStatsUser> list = (List<BlogsStatsUser>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_E,
1253                finderArgs, this);
1254
1255        if (list == null) {
1256            Session session = null;
1257
1258            try {
1259                session = openSession();
1260
1261                StringBuilder query = new StringBuilder();
1262
1263                query.append(
1264                    "FROM com.liferay.portlet.blogs.model.BlogsStatsUser WHERE ");
1265
1266                query.append("companyId = ?");
1267
1268                query.append(" AND ");
1269
1270                query.append("entryCount != ?");
1271
1272                query.append(" ");
1273
1274                query.append("ORDER BY ");
1275
1276                query.append("entryCount DESC");
1277
1278                Query q = session.createQuery(query.toString());
1279
1280                QueryPos qPos = QueryPos.getInstance(q);
1281
1282                qPos.add(companyId);
1283
1284                qPos.add(entryCount);
1285
1286                list = q.list();
1287            }
1288            catch (Exception e) {
1289                throw processException(e);
1290            }
1291            finally {
1292                if (list == null) {
1293                    list = new ArrayList<BlogsStatsUser>();
1294                }
1295
1296                cacheResult(list);
1297
1298                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_E, finderArgs,
1299                    list);
1300
1301                closeSession(session);
1302            }
1303        }
1304
1305        return list;
1306    }
1307
1308    public List<BlogsStatsUser> findByC_E(long companyId, int entryCount,
1309        int start, int end) throws SystemException {
1310        return findByC_E(companyId, entryCount, start, end, null);
1311    }
1312
1313    public List<BlogsStatsUser> findByC_E(long companyId, int entryCount,
1314        int start, int end, OrderByComparator obc) throws SystemException {
1315        Object[] finderArgs = new Object[] {
1316                new Long(companyId), new Integer(entryCount),
1317                
1318                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1319            };
1320
1321        List<BlogsStatsUser> list = (List<BlogsStatsUser>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_C_E,
1322                finderArgs, this);
1323
1324        if (list == null) {
1325            Session session = null;
1326
1327            try {
1328                session = openSession();
1329
1330                StringBuilder query = new StringBuilder();
1331
1332                query.append(
1333                    "FROM com.liferay.portlet.blogs.model.BlogsStatsUser WHERE ");
1334
1335                query.append("companyId = ?");
1336
1337                query.append(" AND ");
1338
1339                query.append("entryCount != ?");
1340
1341                query.append(" ");
1342
1343                if (obc != null) {
1344                    query.append("ORDER BY ");
1345                    query.append(obc.getOrderBy());
1346                }
1347
1348                else {
1349                    query.append("ORDER BY ");
1350
1351                    query.append("entryCount DESC");
1352                }
1353
1354                Query q = session.createQuery(query.toString());
1355
1356                QueryPos qPos = QueryPos.getInstance(q);
1357
1358                qPos.add(companyId);
1359
1360                qPos.add(entryCount);
1361
1362                list = (List<BlogsStatsUser>)QueryUtil.list(q, getDialect(),
1363                        start, end);
1364            }
1365            catch (Exception e) {
1366                throw processException(e);
1367            }
1368            finally {
1369                if (list == null) {
1370                    list = new ArrayList<BlogsStatsUser>();
1371                }
1372
1373                cacheResult(list);
1374
1375                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_C_E,
1376                    finderArgs, list);
1377
1378                closeSession(session);
1379            }
1380        }
1381
1382        return list;
1383    }
1384
1385    public BlogsStatsUser findByC_E_First(long companyId, int entryCount,
1386        OrderByComparator obc) throws NoSuchStatsUserException, SystemException {
1387        List<BlogsStatsUser> list = findByC_E(companyId, entryCount, 0, 1, obc);
1388
1389        if (list.isEmpty()) {
1390            StringBuilder msg = new StringBuilder();
1391
1392            msg.append("No BlogsStatsUser exists with the key {");
1393
1394            msg.append("companyId=" + companyId);
1395
1396            msg.append(", ");
1397            msg.append("entryCount=" + entryCount);
1398
1399            msg.append(StringPool.CLOSE_CURLY_BRACE);
1400
1401            throw new NoSuchStatsUserException(msg.toString());
1402        }
1403        else {
1404            return list.get(0);
1405        }
1406    }
1407
1408    public BlogsStatsUser findByC_E_Last(long companyId, int entryCount,
1409        OrderByComparator obc) throws NoSuchStatsUserException, SystemException {
1410        int count = countByC_E(companyId, entryCount);
1411
1412        List<BlogsStatsUser> list = findByC_E(companyId, entryCount, count - 1,
1413                count, obc);
1414
1415        if (list.isEmpty()) {
1416            StringBuilder msg = new StringBuilder();
1417
1418            msg.append("No BlogsStatsUser exists with the key {");
1419
1420            msg.append("companyId=" + companyId);
1421
1422            msg.append(", ");
1423            msg.append("entryCount=" + entryCount);
1424
1425            msg.append(StringPool.CLOSE_CURLY_BRACE);
1426
1427            throw new NoSuchStatsUserException(msg.toString());
1428        }
1429        else {
1430            return list.get(0);
1431        }
1432    }
1433
1434    public BlogsStatsUser[] findByC_E_PrevAndNext(long statsUserId,
1435        long companyId, int entryCount, OrderByComparator obc)
1436        throws NoSuchStatsUserException, SystemException {
1437        BlogsStatsUser blogsStatsUser = findByPrimaryKey(statsUserId);
1438
1439        int count = countByC_E(companyId, entryCount);
1440
1441        Session session = null;
1442
1443        try {
1444            session = openSession();
1445
1446            StringBuilder query = new StringBuilder();
1447
1448            query.append(
1449                "FROM com.liferay.portlet.blogs.model.BlogsStatsUser WHERE ");
1450
1451            query.append("companyId = ?");
1452
1453            query.append(" AND ");
1454
1455            query.append("entryCount != ?");
1456
1457            query.append(" ");
1458
1459            if (obc != null) {
1460                query.append("ORDER BY ");
1461                query.append(obc.getOrderBy());
1462            }
1463
1464            else {
1465                query.append("ORDER BY ");
1466
1467                query.append("entryCount DESC");
1468            }
1469
1470            Query q = session.createQuery(query.toString());
1471
1472            QueryPos qPos = QueryPos.getInstance(q);
1473
1474            qPos.add(companyId);
1475
1476            qPos.add(entryCount);
1477
1478            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1479                    blogsStatsUser);
1480
1481            BlogsStatsUser[] array = new BlogsStatsUserImpl[3];
1482
1483            array[0] = (BlogsStatsUser)objArray[0];
1484            array[1] = (BlogsStatsUser)objArray[1];
1485            array[2] = (BlogsStatsUser)objArray[2];
1486
1487            return array;
1488        }
1489        catch (Exception e) {
1490            throw processException(e);
1491        }
1492        finally {
1493            closeSession(session);
1494        }
1495    }
1496
1497    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
1498        throws SystemException {
1499        Session session = null;
1500
1501        try {
1502            session = openSession();
1503
1504            dynamicQuery.compile(session);
1505
1506            return dynamicQuery.list();
1507        }
1508        catch (Exception e) {
1509            throw processException(e);
1510        }
1511        finally {
1512            closeSession(session);
1513        }
1514    }
1515
1516    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
1517        int start, int end) throws SystemException {
1518        Session session = null;
1519
1520        try {
1521            session = openSession();
1522
1523            dynamicQuery.setLimit(start, end);
1524
1525            dynamicQuery.compile(session);
1526
1527            return dynamicQuery.list();
1528        }
1529        catch (Exception e) {
1530            throw processException(e);
1531        }
1532        finally {
1533            closeSession(session);
1534        }
1535    }
1536
1537    public List<BlogsStatsUser> findAll() throws SystemException {
1538        return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1539    }
1540
1541    public List<BlogsStatsUser> findAll(int start, int end)
1542        throws SystemException {
1543        return findAll(start, end, null);
1544    }
1545
1546    public List<BlogsStatsUser> findAll(int start, int end,
1547        OrderByComparator obc) throws SystemException {
1548        Object[] finderArgs = new Object[] {
1549                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1550            };
1551
1552        List<BlogsStatsUser> list = (List<BlogsStatsUser>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1553                finderArgs, this);
1554
1555        if (list == null) {
1556            Session session = null;
1557
1558            try {
1559                session = openSession();
1560
1561                StringBuilder query = new StringBuilder();
1562
1563                query.append(
1564                    "FROM com.liferay.portlet.blogs.model.BlogsStatsUser ");
1565
1566                if (obc != null) {
1567                    query.append("ORDER BY ");
1568                    query.append(obc.getOrderBy());
1569                }
1570
1571                else {
1572                    query.append("ORDER BY ");
1573
1574                    query.append("entryCount DESC");
1575                }
1576
1577                Query q = session.createQuery(query.toString());
1578
1579                if (obc == null) {
1580                    list = (List<BlogsStatsUser>)QueryUtil.list(q,
1581                            getDialect(), start, end, false);
1582
1583                    Collections.sort(list);
1584                }
1585                else {
1586                    list = (List<BlogsStatsUser>)QueryUtil.list(q,
1587                            getDialect(), start, end);
1588                }
1589            }
1590            catch (Exception e) {
1591                throw processException(e);
1592            }
1593            finally {
1594                if (list == null) {
1595                    list = new ArrayList<BlogsStatsUser>();
1596                }
1597
1598                cacheResult(list);
1599
1600                FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1601
1602                closeSession(session);
1603            }
1604        }
1605
1606        return list;
1607    }
1608
1609    public void removeByGroupId(long groupId) throws SystemException {
1610        for (BlogsStatsUser blogsStatsUser : findByGroupId(groupId)) {
1611            remove(blogsStatsUser);
1612        }
1613    }
1614
1615    public void removeByUserId(long userId) throws SystemException {
1616        for (BlogsStatsUser blogsStatsUser : findByUserId(userId)) {
1617            remove(blogsStatsUser);
1618        }
1619    }
1620
1621    public void removeByG_U(long groupId, long userId)
1622        throws NoSuchStatsUserException, SystemException {
1623        BlogsStatsUser blogsStatsUser = findByG_U(groupId, userId);
1624
1625        remove(blogsStatsUser);
1626    }
1627
1628    public void removeByG_E(long groupId, int entryCount)
1629        throws SystemException {
1630        for (BlogsStatsUser blogsStatsUser : findByG_E(groupId, entryCount)) {
1631            remove(blogsStatsUser);
1632        }
1633    }
1634
1635    public void removeByC_E(long companyId, int entryCount)
1636        throws SystemException {
1637        for (BlogsStatsUser blogsStatsUser : findByC_E(companyId, entryCount)) {
1638            remove(blogsStatsUser);
1639        }
1640    }
1641
1642    public void removeAll() throws SystemException {
1643        for (BlogsStatsUser blogsStatsUser : findAll()) {
1644            remove(blogsStatsUser);
1645        }
1646    }
1647
1648    public int countByGroupId(long groupId) throws SystemException {
1649        Object[] finderArgs = new Object[] { new Long(groupId) };
1650
1651        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
1652                finderArgs, this);
1653
1654        if (count == null) {
1655            Session session = null;
1656
1657            try {
1658                session = openSession();
1659
1660                StringBuilder query = new StringBuilder();
1661
1662                query.append("SELECT COUNT(*) ");
1663                query.append(
1664                    "FROM com.liferay.portlet.blogs.model.BlogsStatsUser WHERE ");
1665
1666                query.append("groupId = ?");
1667
1668                query.append(" ");
1669
1670                Query q = session.createQuery(query.toString());
1671
1672                QueryPos qPos = QueryPos.getInstance(q);
1673
1674                qPos.add(groupId);
1675
1676                count = (Long)q.uniqueResult();
1677            }
1678            catch (Exception e) {
1679                throw processException(e);
1680            }
1681            finally {
1682                if (count == null) {
1683                    count = Long.valueOf(0);
1684                }
1685
1686                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
1687                    finderArgs, count);
1688
1689                closeSession(session);
1690            }
1691        }
1692
1693        return count.intValue();
1694    }
1695
1696    public int countByUserId(long userId) throws SystemException {
1697        Object[] finderArgs = new Object[] { new Long(userId) };
1698
1699        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID,
1700                finderArgs, this);
1701
1702        if (count == null) {
1703            Session session = null;
1704
1705            try {
1706                session = openSession();
1707
1708                StringBuilder query = new StringBuilder();
1709
1710                query.append("SELECT COUNT(*) ");
1711                query.append(
1712                    "FROM com.liferay.portlet.blogs.model.BlogsStatsUser WHERE ");
1713
1714                query.append("userId = ?");
1715
1716                query.append(" ");
1717
1718                Query q = session.createQuery(query.toString());
1719
1720                QueryPos qPos = QueryPos.getInstance(q);
1721
1722                qPos.add(userId);
1723
1724                count = (Long)q.uniqueResult();
1725            }
1726            catch (Exception e) {
1727                throw processException(e);
1728            }
1729            finally {
1730                if (count == null) {
1731                    count = Long.valueOf(0);
1732                }
1733
1734                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID,
1735                    finderArgs, count);
1736
1737                closeSession(session);
1738            }
1739        }
1740
1741        return count.intValue();
1742    }
1743
1744    public int countByG_U(long groupId, long userId) throws SystemException {
1745        Object[] finderArgs = new Object[] { new Long(groupId), new Long(userId) };
1746
1747        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_U,
1748                finderArgs, this);
1749
1750        if (count == null) {
1751            Session session = null;
1752
1753            try {
1754                session = openSession();
1755
1756                StringBuilder query = new StringBuilder();
1757
1758                query.append("SELECT COUNT(*) ");
1759                query.append(
1760                    "FROM com.liferay.portlet.blogs.model.BlogsStatsUser WHERE ");
1761
1762                query.append("groupId = ?");
1763
1764                query.append(" AND ");
1765
1766                query.append("userId = ?");
1767
1768                query.append(" ");
1769
1770                Query q = session.createQuery(query.toString());
1771
1772                QueryPos qPos = QueryPos.getInstance(q);
1773
1774                qPos.add(groupId);
1775
1776                qPos.add(userId);
1777
1778                count = (Long)q.uniqueResult();
1779            }
1780            catch (Exception e) {
1781                throw processException(e);
1782            }
1783            finally {
1784                if (count == null) {
1785                    count = Long.valueOf(0);
1786                }
1787
1788                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_U, finderArgs,
1789                    count);
1790
1791                closeSession(session);
1792            }
1793        }
1794
1795        return count.intValue();
1796    }
1797
1798    public int countByG_E(long groupId, int entryCount)
1799        throws SystemException {
1800        Object[] finderArgs = new Object[] {
1801                new Long(groupId), new Integer(entryCount)
1802            };
1803
1804        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_E,
1805                finderArgs, this);
1806
1807        if (count == null) {
1808            Session session = null;
1809
1810            try {
1811                session = openSession();
1812
1813                StringBuilder query = new StringBuilder();
1814
1815                query.append("SELECT COUNT(*) ");
1816                query.append(
1817                    "FROM com.liferay.portlet.blogs.model.BlogsStatsUser WHERE ");
1818
1819                query.append("groupId = ?");
1820
1821                query.append(" AND ");
1822
1823                query.append("entryCount != ?");
1824
1825                query.append(" ");
1826
1827                Query q = session.createQuery(query.toString());
1828
1829                QueryPos qPos = QueryPos.getInstance(q);
1830
1831                qPos.add(groupId);
1832
1833                qPos.add(entryCount);
1834
1835                count = (Long)q.uniqueResult();
1836            }
1837            catch (Exception e) {
1838                throw processException(e);
1839            }
1840            finally {
1841                if (count == null) {
1842                    count = Long.valueOf(0);
1843                }
1844
1845                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_E, finderArgs,
1846                    count);
1847
1848                closeSession(session);
1849            }
1850        }
1851
1852        return count.intValue();
1853    }
1854
1855    public int countByC_E(long companyId, int entryCount)
1856        throws SystemException {
1857        Object[] finderArgs = new Object[] {
1858                new Long(companyId), new Integer(entryCount)
1859            };
1860
1861        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_E,
1862                finderArgs, this);
1863
1864        if (count == null) {
1865            Session session = null;
1866
1867            try {
1868                session = openSession();
1869
1870                StringBuilder query = new StringBuilder();
1871
1872                query.append("SELECT COUNT(*) ");
1873                query.append(
1874                    "FROM com.liferay.portlet.blogs.model.BlogsStatsUser WHERE ");
1875
1876                query.append("companyId = ?");
1877
1878                query.append(" AND ");
1879
1880                query.append("entryCount != ?");
1881
1882                query.append(" ");
1883
1884                Query q = session.createQuery(query.toString());
1885
1886                QueryPos qPos = QueryPos.getInstance(q);
1887
1888                qPos.add(companyId);
1889
1890                qPos.add(entryCount);
1891
1892                count = (Long)q.uniqueResult();
1893            }
1894            catch (Exception e) {
1895                throw processException(e);
1896            }
1897            finally {
1898                if (count == null) {
1899                    count = Long.valueOf(0);
1900                }
1901
1902                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_E, finderArgs,
1903                    count);
1904
1905                closeSession(session);
1906            }
1907        }
1908
1909        return count.intValue();
1910    }
1911
1912    public int countAll() throws SystemException {
1913        Object[] finderArgs = new Object[0];
1914
1915        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1916                finderArgs, this);
1917
1918        if (count == null) {
1919            Session session = null;
1920
1921            try {
1922                session = openSession();
1923
1924                Query q = session.createQuery(
1925                        "SELECT COUNT(*) FROM com.liferay.portlet.blogs.model.BlogsStatsUser");
1926
1927                count = (Long)q.uniqueResult();
1928            }
1929            catch (Exception e) {
1930                throw processException(e);
1931            }
1932            finally {
1933                if (count == null) {
1934                    count = Long.valueOf(0);
1935                }
1936
1937                FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1938                    count);
1939
1940                closeSession(session);
1941            }
1942        }
1943
1944        return count.intValue();
1945    }
1946
1947    public void afterPropertiesSet() {
1948        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1949                    com.liferay.portal.util.PropsUtil.get(
1950                        "value.object.listener.com.liferay.portlet.blogs.model.BlogsStatsUser")));
1951
1952        if (listenerClassNames.length > 0) {
1953            try {
1954                List<ModelListener<BlogsStatsUser>> listenersList = new ArrayList<ModelListener<BlogsStatsUser>>();
1955
1956                for (String listenerClassName : listenerClassNames) {
1957                    listenersList.add((ModelListener<BlogsStatsUser>)Class.forName(
1958                            listenerClassName).newInstance());
1959                }
1960
1961                listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1962            }
1963            catch (Exception e) {
1964                _log.error(e);
1965            }
1966        }
1967    }
1968
1969    @BeanReference(name = "com.liferay.portlet.blogs.service.persistence.BlogsEntryPersistence.impl")
1970    protected com.liferay.portlet.blogs.service.persistence.BlogsEntryPersistence blogsEntryPersistence;
1971    @BeanReference(name = "com.liferay.portlet.blogs.service.persistence.BlogsStatsUserPersistence.impl")
1972    protected com.liferay.portlet.blogs.service.persistence.BlogsStatsUserPersistence blogsStatsUserPersistence;
1973    @BeanReference(name = "com.liferay.portal.service.persistence.GroupPersistence.impl")
1974    protected com.liferay.portal.service.persistence.GroupPersistence groupPersistence;
1975    private static Log _log = LogFactoryUtil.getLog(BlogsStatsUserPersistenceImpl.class);
1976}