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