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                     "SELECT blogsStatsUser FROM BlogsStatsUser blogsStatsUser WHERE ");
445 
446                 query.append("blogsStatsUser.groupId = ?");
447 
448                 query.append(" ");
449 
450                 query.append("ORDER BY ");
451 
452                 query.append("blogsStatsUser.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                     "SELECT blogsStatsUser FROM BlogsStatsUser blogsStatsUser WHERE ");
508 
509                 query.append("blogsStatsUser.groupId = ?");
510 
511                 query.append(" ");
512 
513                 if (obc != null) {
514                     query.append("ORDER BY ");
515 
516                     String[] orderByFields = obc.getOrderByFields();
517 
518                     for (int i = 0; i < orderByFields.length; i++) {
519                         query.append("blogsStatsUser.");
520                         query.append(orderByFields[i]);
521 
522                         if (obc.isAscending()) {
523                             query.append(" ASC");
524                         }
525                         else {
526                             query.append(" DESC");
527                         }
528 
529                         if ((i + 1) < orderByFields.length) {
530                             query.append(", ");
531                         }
532                     }
533                 }
534 
535                 else {
536                     query.append("ORDER BY ");
537 
538                     query.append("blogsStatsUser.entryCount DESC");
539                 }
540 
541                 Query q = session.createQuery(query.toString());
542 
543                 QueryPos qPos = QueryPos.getInstance(q);
544 
545                 qPos.add(groupId);
546 
547                 list = (List<BlogsStatsUser>)QueryUtil.list(q, getDialect(),
548                         start, end);
549             }
550             catch (Exception e) {
551                 throw processException(e);
552             }
553             finally {
554                 if (list == null) {
555                     list = new ArrayList<BlogsStatsUser>();
556                 }
557 
558                 cacheResult(list);
559 
560                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_GROUPID,
561                     finderArgs, list);
562 
563                 closeSession(session);
564             }
565         }
566 
567         return list;
568     }
569 
570     public BlogsStatsUser findByGroupId_First(long groupId,
571         OrderByComparator obc) throws NoSuchStatsUserException, SystemException {
572         List<BlogsStatsUser> list = findByGroupId(groupId, 0, 1, obc);
573 
574         if (list.isEmpty()) {
575             StringBuilder msg = new StringBuilder();
576 
577             msg.append("No BlogsStatsUser exists with the key {");
578 
579             msg.append("groupId=" + groupId);
580 
581             msg.append(StringPool.CLOSE_CURLY_BRACE);
582 
583             throw new NoSuchStatsUserException(msg.toString());
584         }
585         else {
586             return list.get(0);
587         }
588     }
589 
590     public BlogsStatsUser findByGroupId_Last(long groupId, OrderByComparator obc)
591         throws NoSuchStatsUserException, SystemException {
592         int count = countByGroupId(groupId);
593 
594         List<BlogsStatsUser> list = findByGroupId(groupId, count - 1, count, obc);
595 
596         if (list.isEmpty()) {
597             StringBuilder msg = new StringBuilder();
598 
599             msg.append("No BlogsStatsUser exists with the key {");
600 
601             msg.append("groupId=" + groupId);
602 
603             msg.append(StringPool.CLOSE_CURLY_BRACE);
604 
605             throw new NoSuchStatsUserException(msg.toString());
606         }
607         else {
608             return list.get(0);
609         }
610     }
611 
612     public BlogsStatsUser[] findByGroupId_PrevAndNext(long statsUserId,
613         long groupId, OrderByComparator obc)
614         throws NoSuchStatsUserException, SystemException {
615         BlogsStatsUser blogsStatsUser = findByPrimaryKey(statsUserId);
616 
617         int count = countByGroupId(groupId);
618 
619         Session session = null;
620 
621         try {
622             session = openSession();
623 
624             StringBuilder query = new StringBuilder();
625 
626             query.append(
627                 "SELECT blogsStatsUser FROM BlogsStatsUser blogsStatsUser WHERE ");
628 
629             query.append("blogsStatsUser.groupId = ?");
630 
631             query.append(" ");
632 
633             if (obc != null) {
634                 query.append("ORDER BY ");
635 
636                 String[] orderByFields = obc.getOrderByFields();
637 
638                 for (int i = 0; i < orderByFields.length; i++) {
639                     query.append("blogsStatsUser.");
640                     query.append(orderByFields[i]);
641 
642                     if (obc.isAscending()) {
643                         query.append(" ASC");
644                     }
645                     else {
646                         query.append(" DESC");
647                     }
648 
649                     if ((i + 1) < orderByFields.length) {
650                         query.append(", ");
651                     }
652                 }
653             }
654 
655             else {
656                 query.append("ORDER BY ");
657 
658                 query.append("blogsStatsUser.entryCount DESC");
659             }
660 
661             Query q = session.createQuery(query.toString());
662 
663             QueryPos qPos = QueryPos.getInstance(q);
664 
665             qPos.add(groupId);
666 
667             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
668                     blogsStatsUser);
669 
670             BlogsStatsUser[] array = new BlogsStatsUserImpl[3];
671 
672             array[0] = (BlogsStatsUser)objArray[0];
673             array[1] = (BlogsStatsUser)objArray[1];
674             array[2] = (BlogsStatsUser)objArray[2];
675 
676             return array;
677         }
678         catch (Exception e) {
679             throw processException(e);
680         }
681         finally {
682             closeSession(session);
683         }
684     }
685 
686     public List<BlogsStatsUser> findByUserId(long userId)
687         throws SystemException {
688         Object[] finderArgs = new Object[] { new Long(userId) };
689 
690         List<BlogsStatsUser> list = (List<BlogsStatsUser>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_USERID,
691                 finderArgs, this);
692 
693         if (list == null) {
694             Session session = null;
695 
696             try {
697                 session = openSession();
698 
699                 StringBuilder query = new StringBuilder();
700 
701                 query.append(
702                     "SELECT blogsStatsUser FROM BlogsStatsUser blogsStatsUser WHERE ");
703 
704                 query.append("blogsStatsUser.userId = ?");
705 
706                 query.append(" ");
707 
708                 query.append("ORDER BY ");
709 
710                 query.append("blogsStatsUser.entryCount DESC");
711 
712                 Query q = session.createQuery(query.toString());
713 
714                 QueryPos qPos = QueryPos.getInstance(q);
715 
716                 qPos.add(userId);
717 
718                 list = q.list();
719             }
720             catch (Exception e) {
721                 throw processException(e);
722             }
723             finally {
724                 if (list == null) {
725                     list = new ArrayList<BlogsStatsUser>();
726                 }
727 
728                 cacheResult(list);
729 
730                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_USERID,
731                     finderArgs, list);
732 
733                 closeSession(session);
734             }
735         }
736 
737         return list;
738     }
739 
740     public List<BlogsStatsUser> findByUserId(long userId, int start, int end)
741         throws SystemException {
742         return findByUserId(userId, start, end, null);
743     }
744 
745     public List<BlogsStatsUser> findByUserId(long userId, int start, int end,
746         OrderByComparator obc) throws SystemException {
747         Object[] finderArgs = new Object[] {
748                 new Long(userId),
749                 
750                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
751             };
752 
753         List<BlogsStatsUser> list = (List<BlogsStatsUser>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_USERID,
754                 finderArgs, this);
755 
756         if (list == null) {
757             Session session = null;
758 
759             try {
760                 session = openSession();
761 
762                 StringBuilder query = new StringBuilder();
763 
764                 query.append(
765                     "SELECT blogsStatsUser FROM BlogsStatsUser blogsStatsUser WHERE ");
766 
767                 query.append("blogsStatsUser.userId = ?");
768 
769                 query.append(" ");
770 
771                 if (obc != null) {
772                     query.append("ORDER BY ");
773 
774                     String[] orderByFields = obc.getOrderByFields();
775 
776                     for (int i = 0; i < orderByFields.length; i++) {
777                         query.append("blogsStatsUser.");
778                         query.append(orderByFields[i]);
779 
780                         if (obc.isAscending()) {
781                             query.append(" ASC");
782                         }
783                         else {
784                             query.append(" DESC");
785                         }
786 
787                         if ((i + 1) < orderByFields.length) {
788                             query.append(", ");
789                         }
790                     }
791                 }
792 
793                 else {
794                     query.append("ORDER BY ");
795 
796                     query.append("blogsStatsUser.entryCount DESC");
797                 }
798 
799                 Query q = session.createQuery(query.toString());
800 
801                 QueryPos qPos = QueryPos.getInstance(q);
802 
803                 qPos.add(userId);
804 
805                 list = (List<BlogsStatsUser>)QueryUtil.list(q, getDialect(),
806                         start, end);
807             }
808             catch (Exception e) {
809                 throw processException(e);
810             }
811             finally {
812                 if (list == null) {
813                     list = new ArrayList<BlogsStatsUser>();
814                 }
815 
816                 cacheResult(list);
817 
818                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_USERID,
819                     finderArgs, list);
820 
821                 closeSession(session);
822             }
823         }
824 
825         return list;
826     }
827 
828     public BlogsStatsUser findByUserId_First(long userId, OrderByComparator obc)
829         throws NoSuchStatsUserException, SystemException {
830         List<BlogsStatsUser> list = findByUserId(userId, 0, 1, obc);
831 
832         if (list.isEmpty()) {
833             StringBuilder msg = new StringBuilder();
834 
835             msg.append("No BlogsStatsUser exists with the key {");
836 
837             msg.append("userId=" + userId);
838 
839             msg.append(StringPool.CLOSE_CURLY_BRACE);
840 
841             throw new NoSuchStatsUserException(msg.toString());
842         }
843         else {
844             return list.get(0);
845         }
846     }
847 
848     public BlogsStatsUser findByUserId_Last(long userId, OrderByComparator obc)
849         throws NoSuchStatsUserException, SystemException {
850         int count = countByUserId(userId);
851 
852         List<BlogsStatsUser> list = findByUserId(userId, count - 1, count, obc);
853 
854         if (list.isEmpty()) {
855             StringBuilder msg = new StringBuilder();
856 
857             msg.append("No BlogsStatsUser exists with the key {");
858 
859             msg.append("userId=" + userId);
860 
861             msg.append(StringPool.CLOSE_CURLY_BRACE);
862 
863             throw new NoSuchStatsUserException(msg.toString());
864         }
865         else {
866             return list.get(0);
867         }
868     }
869 
870     public BlogsStatsUser[] findByUserId_PrevAndNext(long statsUserId,
871         long userId, OrderByComparator obc)
872         throws NoSuchStatsUserException, SystemException {
873         BlogsStatsUser blogsStatsUser = findByPrimaryKey(statsUserId);
874 
875         int count = countByUserId(userId);
876 
877         Session session = null;
878 
879         try {
880             session = openSession();
881 
882             StringBuilder query = new StringBuilder();
883 
884             query.append(
885                 "SELECT blogsStatsUser FROM BlogsStatsUser blogsStatsUser WHERE ");
886 
887             query.append("blogsStatsUser.userId = ?");
888 
889             query.append(" ");
890 
891             if (obc != null) {
892                 query.append("ORDER BY ");
893 
894                 String[] orderByFields = obc.getOrderByFields();
895 
896                 for (int i = 0; i < orderByFields.length; i++) {
897                     query.append("blogsStatsUser.");
898                     query.append(orderByFields[i]);
899 
900                     if (obc.isAscending()) {
901                         query.append(" ASC");
902                     }
903                     else {
904                         query.append(" DESC");
905                     }
906 
907                     if ((i + 1) < orderByFields.length) {
908                         query.append(", ");
909                     }
910                 }
911             }
912 
913             else {
914                 query.append("ORDER BY ");
915 
916                 query.append("blogsStatsUser.entryCount DESC");
917             }
918 
919             Query q = session.createQuery(query.toString());
920 
921             QueryPos qPos = QueryPos.getInstance(q);
922 
923             qPos.add(userId);
924 
925             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
926                     blogsStatsUser);
927 
928             BlogsStatsUser[] array = new BlogsStatsUserImpl[3];
929 
930             array[0] = (BlogsStatsUser)objArray[0];
931             array[1] = (BlogsStatsUser)objArray[1];
932             array[2] = (BlogsStatsUser)objArray[2];
933 
934             return array;
935         }
936         catch (Exception e) {
937             throw processException(e);
938         }
939         finally {
940             closeSession(session);
941         }
942     }
943 
944     public BlogsStatsUser findByG_U(long groupId, long userId)
945         throws NoSuchStatsUserException, SystemException {
946         BlogsStatsUser blogsStatsUser = fetchByG_U(groupId, userId);
947 
948         if (blogsStatsUser == null) {
949             StringBuilder msg = new StringBuilder();
950 
951             msg.append("No BlogsStatsUser exists with the key {");
952 
953             msg.append("groupId=" + groupId);
954 
955             msg.append(", ");
956             msg.append("userId=" + userId);
957 
958             msg.append(StringPool.CLOSE_CURLY_BRACE);
959 
960             if (_log.isWarnEnabled()) {
961                 _log.warn(msg.toString());
962             }
963 
964             throw new NoSuchStatsUserException(msg.toString());
965         }
966 
967         return blogsStatsUser;
968     }
969 
970     public BlogsStatsUser fetchByG_U(long groupId, long userId)
971         throws SystemException {
972         return fetchByG_U(groupId, userId, true);
973     }
974 
975     public BlogsStatsUser fetchByG_U(long groupId, long userId,
976         boolean retrieveFromCache) throws SystemException {
977         Object[] finderArgs = new Object[] { new Long(groupId), new Long(userId) };
978 
979         Object result = null;
980 
981         if (retrieveFromCache) {
982             result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_U,
983                     finderArgs, this);
984         }
985 
986         if (result == null) {
987             Session session = null;
988 
989             try {
990                 session = openSession();
991 
992                 StringBuilder query = new StringBuilder();
993 
994                 query.append(
995                     "SELECT blogsStatsUser FROM BlogsStatsUser blogsStatsUser WHERE ");
996 
997                 query.append("blogsStatsUser.groupId = ?");
998 
999                 query.append(" AND ");
1000
1001                query.append("blogsStatsUser.userId = ?");
1002
1003                query.append(" ");
1004
1005                query.append("ORDER BY ");
1006
1007                query.append("blogsStatsUser.entryCount DESC");
1008
1009                Query q = session.createQuery(query.toString());
1010
1011                QueryPos qPos = QueryPos.getInstance(q);
1012
1013                qPos.add(groupId);
1014
1015                qPos.add(userId);
1016
1017                List<BlogsStatsUser> list = q.list();
1018
1019                result = list;
1020
1021                BlogsStatsUser blogsStatsUser = null;
1022
1023                if (list.isEmpty()) {
1024                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U,
1025                        finderArgs, list);
1026                }
1027                else {
1028                    blogsStatsUser = list.get(0);
1029
1030                    cacheResult(blogsStatsUser);
1031
1032                    if ((blogsStatsUser.getGroupId() != groupId) ||
1033                            (blogsStatsUser.getUserId() != userId)) {
1034                        FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U,
1035                            finderArgs, blogsStatsUser);
1036                    }
1037                }
1038
1039                return blogsStatsUser;
1040            }
1041            catch (Exception e) {
1042                throw processException(e);
1043            }
1044            finally {
1045                if (result == null) {
1046                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U,
1047                        finderArgs, new ArrayList<BlogsStatsUser>());
1048                }
1049
1050                closeSession(session);
1051            }
1052        }
1053        else {
1054            if (result instanceof List) {
1055                return null;
1056            }
1057            else {
1058                return (BlogsStatsUser)result;
1059            }
1060        }
1061    }
1062
1063    public List<BlogsStatsUser> findByG_E(long groupId, int entryCount)
1064        throws SystemException {
1065        Object[] finderArgs = new Object[] {
1066                new Long(groupId), new Integer(entryCount)
1067            };
1068
1069        List<BlogsStatsUser> list = (List<BlogsStatsUser>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_E,
1070                finderArgs, this);
1071
1072        if (list == null) {
1073            Session session = null;
1074
1075            try {
1076                session = openSession();
1077
1078                StringBuilder query = new StringBuilder();
1079
1080                query.append(
1081                    "SELECT blogsStatsUser FROM BlogsStatsUser blogsStatsUser WHERE ");
1082
1083                query.append("blogsStatsUser.groupId = ?");
1084
1085                query.append(" AND ");
1086
1087                query.append("blogsStatsUser.entryCount != ?");
1088
1089                query.append(" ");
1090
1091                query.append("ORDER BY ");
1092
1093                query.append("blogsStatsUser.entryCount DESC");
1094
1095                Query q = session.createQuery(query.toString());
1096
1097                QueryPos qPos = QueryPos.getInstance(q);
1098
1099                qPos.add(groupId);
1100
1101                qPos.add(entryCount);
1102
1103                list = q.list();
1104            }
1105            catch (Exception e) {
1106                throw processException(e);
1107            }
1108            finally {
1109                if (list == null) {
1110                    list = new ArrayList<BlogsStatsUser>();
1111                }
1112
1113                cacheResult(list);
1114
1115                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_E, finderArgs,
1116                    list);
1117
1118                closeSession(session);
1119            }
1120        }
1121
1122        return list;
1123    }
1124
1125    public List<BlogsStatsUser> findByG_E(long groupId, int entryCount,
1126        int start, int end) throws SystemException {
1127        return findByG_E(groupId, entryCount, start, end, null);
1128    }
1129
1130    public List<BlogsStatsUser> findByG_E(long groupId, int entryCount,
1131        int start, int end, OrderByComparator obc) throws SystemException {
1132        Object[] finderArgs = new Object[] {
1133                new Long(groupId), new Integer(entryCount),
1134                
1135                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1136            };
1137
1138        List<BlogsStatsUser> list = (List<BlogsStatsUser>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_G_E,
1139                finderArgs, this);
1140
1141        if (list == null) {
1142            Session session = null;
1143
1144            try {
1145                session = openSession();
1146
1147                StringBuilder query = new StringBuilder();
1148
1149                query.append(
1150                    "SELECT blogsStatsUser FROM BlogsStatsUser blogsStatsUser WHERE ");
1151
1152                query.append("blogsStatsUser.groupId = ?");
1153
1154                query.append(" AND ");
1155
1156                query.append("blogsStatsUser.entryCount != ?");
1157
1158                query.append(" ");
1159
1160                if (obc != null) {
1161                    query.append("ORDER BY ");
1162
1163                    String[] orderByFields = obc.getOrderByFields();
1164
1165                    for (int i = 0; i < orderByFields.length; i++) {
1166                        query.append("blogsStatsUser.");
1167                        query.append(orderByFields[i]);
1168
1169                        if (obc.isAscending()) {
1170                            query.append(" ASC");
1171                        }
1172                        else {
1173                            query.append(" DESC");
1174                        }
1175
1176                        if ((i + 1) < orderByFields.length) {
1177                            query.append(", ");
1178                        }
1179                    }
1180                }
1181
1182                else {
1183                    query.append("ORDER BY ");
1184
1185                    query.append("blogsStatsUser.entryCount DESC");
1186                }
1187
1188                Query q = session.createQuery(query.toString());
1189
1190                QueryPos qPos = QueryPos.getInstance(q);
1191
1192                qPos.add(groupId);
1193
1194                qPos.add(entryCount);
1195
1196                list = (List<BlogsStatsUser>)QueryUtil.list(q, getDialect(),
1197                        start, end);
1198            }
1199            catch (Exception e) {
1200                throw processException(e);
1201            }
1202            finally {
1203                if (list == null) {
1204                    list = new ArrayList<BlogsStatsUser>();
1205                }
1206
1207                cacheResult(list);
1208
1209                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_G_E,
1210                    finderArgs, list);
1211
1212                closeSession(session);
1213            }
1214        }
1215
1216        return list;
1217    }
1218
1219    public BlogsStatsUser findByG_E_First(long groupId, int entryCount,
1220        OrderByComparator obc) throws NoSuchStatsUserException, SystemException {
1221        List<BlogsStatsUser> list = findByG_E(groupId, entryCount, 0, 1, obc);
1222
1223        if (list.isEmpty()) {
1224            StringBuilder msg = new StringBuilder();
1225
1226            msg.append("No BlogsStatsUser exists with the key {");
1227
1228            msg.append("groupId=" + groupId);
1229
1230            msg.append(", ");
1231            msg.append("entryCount=" + entryCount);
1232
1233            msg.append(StringPool.CLOSE_CURLY_BRACE);
1234
1235            throw new NoSuchStatsUserException(msg.toString());
1236        }
1237        else {
1238            return list.get(0);
1239        }
1240    }
1241
1242    public BlogsStatsUser findByG_E_Last(long groupId, int entryCount,
1243        OrderByComparator obc) throws NoSuchStatsUserException, SystemException {
1244        int count = countByG_E(groupId, entryCount);
1245
1246        List<BlogsStatsUser> list = findByG_E(groupId, entryCount, count - 1,
1247                count, obc);
1248
1249        if (list.isEmpty()) {
1250            StringBuilder msg = new StringBuilder();
1251
1252            msg.append("No BlogsStatsUser exists with the key {");
1253
1254            msg.append("groupId=" + groupId);
1255
1256            msg.append(", ");
1257            msg.append("entryCount=" + entryCount);
1258
1259            msg.append(StringPool.CLOSE_CURLY_BRACE);
1260
1261            throw new NoSuchStatsUserException(msg.toString());
1262        }
1263        else {
1264            return list.get(0);
1265        }
1266    }
1267
1268    public BlogsStatsUser[] findByG_E_PrevAndNext(long statsUserId,
1269        long groupId, int entryCount, OrderByComparator obc)
1270        throws NoSuchStatsUserException, SystemException {
1271        BlogsStatsUser blogsStatsUser = findByPrimaryKey(statsUserId);
1272
1273        int count = countByG_E(groupId, entryCount);
1274
1275        Session session = null;
1276
1277        try {
1278            session = openSession();
1279
1280            StringBuilder query = new StringBuilder();
1281
1282            query.append(
1283                "SELECT blogsStatsUser FROM BlogsStatsUser blogsStatsUser WHERE ");
1284
1285            query.append("blogsStatsUser.groupId = ?");
1286
1287            query.append(" AND ");
1288
1289            query.append("blogsStatsUser.entryCount != ?");
1290
1291            query.append(" ");
1292
1293            if (obc != null) {
1294                query.append("ORDER BY ");
1295
1296                String[] orderByFields = obc.getOrderByFields();
1297
1298                for (int i = 0; i < orderByFields.length; i++) {
1299                    query.append("blogsStatsUser.");
1300                    query.append(orderByFields[i]);
1301
1302                    if (obc.isAscending()) {
1303                        query.append(" ASC");
1304                    }
1305                    else {
1306                        query.append(" DESC");
1307                    }
1308
1309                    if ((i + 1) < orderByFields.length) {
1310                        query.append(", ");
1311                    }
1312                }
1313            }
1314
1315            else {
1316                query.append("ORDER BY ");
1317
1318                query.append("blogsStatsUser.entryCount DESC");
1319            }
1320
1321            Query q = session.createQuery(query.toString());
1322
1323            QueryPos qPos = QueryPos.getInstance(q);
1324
1325            qPos.add(groupId);
1326
1327            qPos.add(entryCount);
1328
1329            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1330                    blogsStatsUser);
1331
1332            BlogsStatsUser[] array = new BlogsStatsUserImpl[3];
1333
1334            array[0] = (BlogsStatsUser)objArray[0];
1335            array[1] = (BlogsStatsUser)objArray[1];
1336            array[2] = (BlogsStatsUser)objArray[2];
1337
1338            return array;
1339        }
1340        catch (Exception e) {
1341            throw processException(e);
1342        }
1343        finally {
1344            closeSession(session);
1345        }
1346    }
1347
1348    public List<BlogsStatsUser> findByC_E(long companyId, int entryCount)
1349        throws SystemException {
1350        Object[] finderArgs = new Object[] {
1351                new Long(companyId), new Integer(entryCount)
1352            };
1353
1354        List<BlogsStatsUser> list = (List<BlogsStatsUser>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_E,
1355                finderArgs, this);
1356
1357        if (list == null) {
1358            Session session = null;
1359
1360            try {
1361                session = openSession();
1362
1363                StringBuilder query = new StringBuilder();
1364
1365                query.append(
1366                    "SELECT blogsStatsUser FROM BlogsStatsUser blogsStatsUser WHERE ");
1367
1368                query.append("blogsStatsUser.companyId = ?");
1369
1370                query.append(" AND ");
1371
1372                query.append("blogsStatsUser.entryCount != ?");
1373
1374                query.append(" ");
1375
1376                query.append("ORDER BY ");
1377
1378                query.append("blogsStatsUser.entryCount DESC");
1379
1380                Query q = session.createQuery(query.toString());
1381
1382                QueryPos qPos = QueryPos.getInstance(q);
1383
1384                qPos.add(companyId);
1385
1386                qPos.add(entryCount);
1387
1388                list = q.list();
1389            }
1390            catch (Exception e) {
1391                throw processException(e);
1392            }
1393            finally {
1394                if (list == null) {
1395                    list = new ArrayList<BlogsStatsUser>();
1396                }
1397
1398                cacheResult(list);
1399
1400                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_E, finderArgs,
1401                    list);
1402
1403                closeSession(session);
1404            }
1405        }
1406
1407        return list;
1408    }
1409
1410    public List<BlogsStatsUser> findByC_E(long companyId, int entryCount,
1411        int start, int end) throws SystemException {
1412        return findByC_E(companyId, entryCount, start, end, null);
1413    }
1414
1415    public List<BlogsStatsUser> findByC_E(long companyId, int entryCount,
1416        int start, int end, OrderByComparator obc) throws SystemException {
1417        Object[] finderArgs = new Object[] {
1418                new Long(companyId), new Integer(entryCount),
1419                
1420                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1421            };
1422
1423        List<BlogsStatsUser> list = (List<BlogsStatsUser>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_C_E,
1424                finderArgs, this);
1425
1426        if (list == null) {
1427            Session session = null;
1428
1429            try {
1430                session = openSession();
1431
1432                StringBuilder query = new StringBuilder();
1433
1434                query.append(
1435                    "SELECT blogsStatsUser FROM BlogsStatsUser blogsStatsUser WHERE ");
1436
1437                query.append("blogsStatsUser.companyId = ?");
1438
1439                query.append(" AND ");
1440
1441                query.append("blogsStatsUser.entryCount != ?");
1442
1443                query.append(" ");
1444
1445                if (obc != null) {
1446                    query.append("ORDER BY ");
1447
1448                    String[] orderByFields = obc.getOrderByFields();
1449
1450                    for (int i = 0; i < orderByFields.length; i++) {
1451                        query.append("blogsStatsUser.");
1452                        query.append(orderByFields[i]);
1453
1454                        if (obc.isAscending()) {
1455                            query.append(" ASC");
1456                        }
1457                        else {
1458                            query.append(" DESC");
1459                        }
1460
1461                        if ((i + 1) < orderByFields.length) {
1462                            query.append(", ");
1463                        }
1464                    }
1465                }
1466
1467                else {
1468                    query.append("ORDER BY ");
1469
1470                    query.append("blogsStatsUser.entryCount DESC");
1471                }
1472
1473                Query q = session.createQuery(query.toString());
1474
1475                QueryPos qPos = QueryPos.getInstance(q);
1476
1477                qPos.add(companyId);
1478
1479                qPos.add(entryCount);
1480
1481                list = (List<BlogsStatsUser>)QueryUtil.list(q, getDialect(),
1482                        start, end);
1483            }
1484            catch (Exception e) {
1485                throw processException(e);
1486            }
1487            finally {
1488                if (list == null) {
1489                    list = new ArrayList<BlogsStatsUser>();
1490                }
1491
1492                cacheResult(list);
1493
1494                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_C_E,
1495                    finderArgs, list);
1496
1497                closeSession(session);
1498            }
1499        }
1500
1501        return list;
1502    }
1503
1504    public BlogsStatsUser findByC_E_First(long companyId, int entryCount,
1505        OrderByComparator obc) throws NoSuchStatsUserException, SystemException {
1506        List<BlogsStatsUser> list = findByC_E(companyId, entryCount, 0, 1, obc);
1507
1508        if (list.isEmpty()) {
1509            StringBuilder msg = new StringBuilder();
1510
1511            msg.append("No BlogsStatsUser exists with the key {");
1512
1513            msg.append("companyId=" + companyId);
1514
1515            msg.append(", ");
1516            msg.append("entryCount=" + entryCount);
1517
1518            msg.append(StringPool.CLOSE_CURLY_BRACE);
1519
1520            throw new NoSuchStatsUserException(msg.toString());
1521        }
1522        else {
1523            return list.get(0);
1524        }
1525    }
1526
1527    public BlogsStatsUser findByC_E_Last(long companyId, int entryCount,
1528        OrderByComparator obc) throws NoSuchStatsUserException, SystemException {
1529        int count = countByC_E(companyId, entryCount);
1530
1531        List<BlogsStatsUser> list = findByC_E(companyId, entryCount, count - 1,
1532                count, obc);
1533
1534        if (list.isEmpty()) {
1535            StringBuilder msg = new StringBuilder();
1536
1537            msg.append("No BlogsStatsUser exists with the key {");
1538
1539            msg.append("companyId=" + companyId);
1540
1541            msg.append(", ");
1542            msg.append("entryCount=" + entryCount);
1543
1544            msg.append(StringPool.CLOSE_CURLY_BRACE);
1545
1546            throw new NoSuchStatsUserException(msg.toString());
1547        }
1548        else {
1549            return list.get(0);
1550        }
1551    }
1552
1553    public BlogsStatsUser[] findByC_E_PrevAndNext(long statsUserId,
1554        long companyId, int entryCount, OrderByComparator obc)
1555        throws NoSuchStatsUserException, SystemException {
1556        BlogsStatsUser blogsStatsUser = findByPrimaryKey(statsUserId);
1557
1558        int count = countByC_E(companyId, entryCount);
1559
1560        Session session = null;
1561
1562        try {
1563            session = openSession();
1564
1565            StringBuilder query = new StringBuilder();
1566
1567            query.append(
1568                "SELECT blogsStatsUser FROM BlogsStatsUser blogsStatsUser WHERE ");
1569
1570            query.append("blogsStatsUser.companyId = ?");
1571
1572            query.append(" AND ");
1573
1574            query.append("blogsStatsUser.entryCount != ?");
1575
1576            query.append(" ");
1577
1578            if (obc != null) {
1579                query.append("ORDER BY ");
1580
1581                String[] orderByFields = obc.getOrderByFields();
1582
1583                for (int i = 0; i < orderByFields.length; i++) {
1584                    query.append("blogsStatsUser.");
1585                    query.append(orderByFields[i]);
1586
1587                    if (obc.isAscending()) {
1588                        query.append(" ASC");
1589                    }
1590                    else {
1591                        query.append(" DESC");
1592                    }
1593
1594                    if ((i + 1) < orderByFields.length) {
1595                        query.append(", ");
1596                    }
1597                }
1598            }
1599
1600            else {
1601                query.append("ORDER BY ");
1602
1603                query.append("blogsStatsUser.entryCount DESC");
1604            }
1605
1606            Query q = session.createQuery(query.toString());
1607
1608            QueryPos qPos = QueryPos.getInstance(q);
1609
1610            qPos.add(companyId);
1611
1612            qPos.add(entryCount);
1613
1614            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1615                    blogsStatsUser);
1616
1617            BlogsStatsUser[] array = new BlogsStatsUserImpl[3];
1618
1619            array[0] = (BlogsStatsUser)objArray[0];
1620            array[1] = (BlogsStatsUser)objArray[1];
1621            array[2] = (BlogsStatsUser)objArray[2];
1622
1623            return array;
1624        }
1625        catch (Exception e) {
1626            throw processException(e);
1627        }
1628        finally {
1629            closeSession(session);
1630        }
1631    }
1632
1633    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
1634        throws SystemException {
1635        Session session = null;
1636
1637        try {
1638            session = openSession();
1639
1640            dynamicQuery.compile(session);
1641
1642            return dynamicQuery.list();
1643        }
1644        catch (Exception e) {
1645            throw processException(e);
1646        }
1647        finally {
1648            closeSession(session);
1649        }
1650    }
1651
1652    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
1653        int start, int end) throws SystemException {
1654        Session session = null;
1655
1656        try {
1657            session = openSession();
1658
1659            dynamicQuery.setLimit(start, end);
1660
1661            dynamicQuery.compile(session);
1662
1663            return dynamicQuery.list();
1664        }
1665        catch (Exception e) {
1666            throw processException(e);
1667        }
1668        finally {
1669            closeSession(session);
1670        }
1671    }
1672
1673    public List<BlogsStatsUser> findAll() throws SystemException {
1674        return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1675    }
1676
1677    public List<BlogsStatsUser> findAll(int start, int end)
1678        throws SystemException {
1679        return findAll(start, end, null);
1680    }
1681
1682    public List<BlogsStatsUser> findAll(int start, int end,
1683        OrderByComparator obc) throws SystemException {
1684        Object[] finderArgs = new Object[] {
1685                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1686            };
1687
1688        List<BlogsStatsUser> list = (List<BlogsStatsUser>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1689                finderArgs, this);
1690
1691        if (list == null) {
1692            Session session = null;
1693
1694            try {
1695                session = openSession();
1696
1697                StringBuilder query = new StringBuilder();
1698
1699                query.append(
1700                    "SELECT blogsStatsUser FROM BlogsStatsUser blogsStatsUser ");
1701
1702                if (obc != null) {
1703                    query.append("ORDER BY ");
1704
1705                    String[] orderByFields = obc.getOrderByFields();
1706
1707                    for (int i = 0; i < orderByFields.length; i++) {
1708                        query.append("blogsStatsUser.");
1709                        query.append(orderByFields[i]);
1710
1711                        if (obc.isAscending()) {
1712                            query.append(" ASC");
1713                        }
1714                        else {
1715                            query.append(" DESC");
1716                        }
1717
1718                        if ((i + 1) < orderByFields.length) {
1719                            query.append(", ");
1720                        }
1721                    }
1722                }
1723
1724                else {
1725                    query.append("ORDER BY ");
1726
1727                    query.append("blogsStatsUser.entryCount DESC");
1728                }
1729
1730                Query q = session.createQuery(query.toString());
1731
1732                if (obc == null) {
1733                    list = (List<BlogsStatsUser>)QueryUtil.list(q,
1734                            getDialect(), start, end, false);
1735
1736                    Collections.sort(list);
1737                }
1738                else {
1739                    list = (List<BlogsStatsUser>)QueryUtil.list(q,
1740                            getDialect(), start, end);
1741                }
1742            }
1743            catch (Exception e) {
1744                throw processException(e);
1745            }
1746            finally {
1747                if (list == null) {
1748                    list = new ArrayList<BlogsStatsUser>();
1749                }
1750
1751                cacheResult(list);
1752
1753                FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1754
1755                closeSession(session);
1756            }
1757        }
1758
1759        return list;
1760    }
1761
1762    public void removeByGroupId(long groupId) throws SystemException {
1763        for (BlogsStatsUser blogsStatsUser : findByGroupId(groupId)) {
1764            remove(blogsStatsUser);
1765        }
1766    }
1767
1768    public void removeByUserId(long userId) throws SystemException {
1769        for (BlogsStatsUser blogsStatsUser : findByUserId(userId)) {
1770            remove(blogsStatsUser);
1771        }
1772    }
1773
1774    public void removeByG_U(long groupId, long userId)
1775        throws NoSuchStatsUserException, SystemException {
1776        BlogsStatsUser blogsStatsUser = findByG_U(groupId, userId);
1777
1778        remove(blogsStatsUser);
1779    }
1780
1781    public void removeByG_E(long groupId, int entryCount)
1782        throws SystemException {
1783        for (BlogsStatsUser blogsStatsUser : findByG_E(groupId, entryCount)) {
1784            remove(blogsStatsUser);
1785        }
1786    }
1787
1788    public void removeByC_E(long companyId, int entryCount)
1789        throws SystemException {
1790        for (BlogsStatsUser blogsStatsUser : findByC_E(companyId, entryCount)) {
1791            remove(blogsStatsUser);
1792        }
1793    }
1794
1795    public void removeAll() throws SystemException {
1796        for (BlogsStatsUser blogsStatsUser : findAll()) {
1797            remove(blogsStatsUser);
1798        }
1799    }
1800
1801    public int countByGroupId(long groupId) throws SystemException {
1802        Object[] finderArgs = new Object[] { new Long(groupId) };
1803
1804        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
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(blogsStatsUser) ");
1816                query.append("FROM BlogsStatsUser blogsStatsUser WHERE ");
1817
1818                query.append("blogsStatsUser.groupId = ?");
1819
1820                query.append(" ");
1821
1822                Query q = session.createQuery(query.toString());
1823
1824                QueryPos qPos = QueryPos.getInstance(q);
1825
1826                qPos.add(groupId);
1827
1828                count = (Long)q.uniqueResult();
1829            }
1830            catch (Exception e) {
1831                throw processException(e);
1832            }
1833            finally {
1834                if (count == null) {
1835                    count = Long.valueOf(0);
1836                }
1837
1838                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
1839                    finderArgs, count);
1840
1841                closeSession(session);
1842            }
1843        }
1844
1845        return count.intValue();
1846    }
1847
1848    public int countByUserId(long userId) throws SystemException {
1849        Object[] finderArgs = new Object[] { new Long(userId) };
1850
1851        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID,
1852                finderArgs, this);
1853
1854        if (count == null) {
1855            Session session = null;
1856
1857            try {
1858                session = openSession();
1859
1860                StringBuilder query = new StringBuilder();
1861
1862                query.append("SELECT COUNT(blogsStatsUser) ");
1863                query.append("FROM BlogsStatsUser blogsStatsUser WHERE ");
1864
1865                query.append("blogsStatsUser.userId = ?");
1866
1867                query.append(" ");
1868
1869                Query q = session.createQuery(query.toString());
1870
1871                QueryPos qPos = QueryPos.getInstance(q);
1872
1873                qPos.add(userId);
1874
1875                count = (Long)q.uniqueResult();
1876            }
1877            catch (Exception e) {
1878                throw processException(e);
1879            }
1880            finally {
1881                if (count == null) {
1882                    count = Long.valueOf(0);
1883                }
1884
1885                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID,
1886                    finderArgs, count);
1887
1888                closeSession(session);
1889            }
1890        }
1891
1892        return count.intValue();
1893    }
1894
1895    public int countByG_U(long groupId, long userId) throws SystemException {
1896        Object[] finderArgs = new Object[] { new Long(groupId), new Long(userId) };
1897
1898        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_U,
1899                finderArgs, this);
1900
1901        if (count == null) {
1902            Session session = null;
1903
1904            try {
1905                session = openSession();
1906
1907                StringBuilder query = new StringBuilder();
1908
1909                query.append("SELECT COUNT(blogsStatsUser) ");
1910                query.append("FROM BlogsStatsUser blogsStatsUser WHERE ");
1911
1912                query.append("blogsStatsUser.groupId = ?");
1913
1914                query.append(" AND ");
1915
1916                query.append("blogsStatsUser.userId = ?");
1917
1918                query.append(" ");
1919
1920                Query q = session.createQuery(query.toString());
1921
1922                QueryPos qPos = QueryPos.getInstance(q);
1923
1924                qPos.add(groupId);
1925
1926                qPos.add(userId);
1927
1928                count = (Long)q.uniqueResult();
1929            }
1930            catch (Exception e) {
1931                throw processException(e);
1932            }
1933            finally {
1934                if (count == null) {
1935                    count = Long.valueOf(0);
1936                }
1937
1938                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_U, finderArgs,
1939                    count);
1940
1941                closeSession(session);
1942            }
1943        }
1944
1945        return count.intValue();
1946    }
1947
1948    public int countByG_E(long groupId, int entryCount)
1949        throws SystemException {
1950        Object[] finderArgs = new Object[] {
1951                new Long(groupId), new Integer(entryCount)
1952            };
1953
1954        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_E,
1955                finderArgs, this);
1956
1957        if (count == null) {
1958            Session session = null;
1959
1960            try {
1961                session = openSession();
1962
1963                StringBuilder query = new StringBuilder();
1964
1965                query.append("SELECT COUNT(blogsStatsUser) ");
1966                query.append("FROM BlogsStatsUser blogsStatsUser WHERE ");
1967
1968                query.append("blogsStatsUser.groupId = ?");
1969
1970                query.append(" AND ");
1971
1972                query.append("blogsStatsUser.entryCount != ?");
1973
1974                query.append(" ");
1975
1976                Query q = session.createQuery(query.toString());
1977
1978                QueryPos qPos = QueryPos.getInstance(q);
1979
1980                qPos.add(groupId);
1981
1982                qPos.add(entryCount);
1983
1984                count = (Long)q.uniqueResult();
1985            }
1986            catch (Exception e) {
1987                throw processException(e);
1988            }
1989            finally {
1990                if (count == null) {
1991                    count = Long.valueOf(0);
1992                }
1993
1994                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_E, finderArgs,
1995                    count);
1996
1997                closeSession(session);
1998            }
1999        }
2000
2001        return count.intValue();
2002    }
2003
2004    public int countByC_E(long companyId, int entryCount)
2005        throws SystemException {
2006        Object[] finderArgs = new Object[] {
2007                new Long(companyId), new Integer(entryCount)
2008            };
2009
2010        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_E,
2011                finderArgs, this);
2012
2013        if (count == null) {
2014            Session session = null;
2015
2016            try {
2017                session = openSession();
2018
2019                StringBuilder query = new StringBuilder();
2020
2021                query.append("SELECT COUNT(blogsStatsUser) ");
2022                query.append("FROM BlogsStatsUser blogsStatsUser WHERE ");
2023
2024                query.append("blogsStatsUser.companyId = ?");
2025
2026                query.append(" AND ");
2027
2028                query.append("blogsStatsUser.entryCount != ?");
2029
2030                query.append(" ");
2031
2032                Query q = session.createQuery(query.toString());
2033
2034                QueryPos qPos = QueryPos.getInstance(q);
2035
2036                qPos.add(companyId);
2037
2038                qPos.add(entryCount);
2039
2040                count = (Long)q.uniqueResult();
2041            }
2042            catch (Exception e) {
2043                throw processException(e);
2044            }
2045            finally {
2046                if (count == null) {
2047                    count = Long.valueOf(0);
2048                }
2049
2050                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_E, finderArgs,
2051                    count);
2052
2053                closeSession(session);
2054            }
2055        }
2056
2057        return count.intValue();
2058    }
2059
2060    public int countAll() throws SystemException {
2061        Object[] finderArgs = new Object[0];
2062
2063        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2064                finderArgs, this);
2065
2066        if (count == null) {
2067            Session session = null;
2068
2069            try {
2070                session = openSession();
2071
2072                Query q = session.createQuery(
2073                        "SELECT COUNT(blogsStatsUser) FROM BlogsStatsUser blogsStatsUser");
2074
2075                count = (Long)q.uniqueResult();
2076            }
2077            catch (Exception e) {
2078                throw processException(e);
2079            }
2080            finally {
2081                if (count == null) {
2082                    count = Long.valueOf(0);
2083                }
2084
2085                FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
2086                    count);
2087
2088                closeSession(session);
2089            }
2090        }
2091
2092        return count.intValue();
2093    }
2094
2095    public void afterPropertiesSet() {
2096        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2097                    com.liferay.portal.util.PropsUtil.get(
2098                        "value.object.listener.com.liferay.portlet.blogs.model.BlogsStatsUser")));
2099
2100        if (listenerClassNames.length > 0) {
2101            try {
2102                List<ModelListener<BlogsStatsUser>> listenersList = new ArrayList<ModelListener<BlogsStatsUser>>();
2103
2104                for (String listenerClassName : listenerClassNames) {
2105                    listenersList.add((ModelListener<BlogsStatsUser>)Class.forName(
2106                            listenerClassName).newInstance());
2107                }
2108
2109                listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2110            }
2111            catch (Exception e) {
2112                _log.error(e);
2113            }
2114        }
2115    }
2116
2117    @BeanReference(name = "com.liferay.portlet.blogs.service.persistence.BlogsEntryPersistence.impl")
2118    protected com.liferay.portlet.blogs.service.persistence.BlogsEntryPersistence blogsEntryPersistence;
2119    @BeanReference(name = "com.liferay.portlet.blogs.service.persistence.BlogsStatsUserPersistence.impl")
2120    protected com.liferay.portlet.blogs.service.persistence.BlogsStatsUserPersistence blogsStatsUserPersistence;
2121    @BeanReference(name = "com.liferay.portal.service.persistence.GroupPersistence.impl")
2122    protected com.liferay.portal.service.persistence.GroupPersistence groupPersistence;
2123    private static Log _log = LogFactoryUtil.getLog(BlogsStatsUserPersistenceImpl.class);
2124}