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