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.orm.DynamicQuery;
27  import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
28  import com.liferay.portal.kernel.dao.orm.Query;
29  import com.liferay.portal.kernel.dao.orm.QueryPos;
30  import com.liferay.portal.kernel.dao.orm.QueryUtil;
31  import com.liferay.portal.kernel.dao.orm.Session;
32  import com.liferay.portal.kernel.util.CalendarUtil;
33  import com.liferay.portal.kernel.util.GetterUtil;
34  import com.liferay.portal.kernel.util.ListUtil;
35  import com.liferay.portal.kernel.util.OrderByComparator;
36  import com.liferay.portal.kernel.util.StringPool;
37  import com.liferay.portal.kernel.util.StringUtil;
38  import com.liferay.portal.model.ModelListener;
39  import com.liferay.portal.service.persistence.BatchSessionUtil;
40  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
41  
42  import com.liferay.portlet.social.NoSuchActivityException;
43  import com.liferay.portlet.social.model.SocialActivity;
44  import com.liferay.portlet.social.model.impl.SocialActivityImpl;
45  import com.liferay.portlet.social.model.impl.SocialActivityModelImpl;
46  
47  import org.apache.commons.logging.Log;
48  import org.apache.commons.logging.LogFactory;
49  
50  import java.util.ArrayList;
51  import java.util.Collections;
52  import java.util.Date;
53  import java.util.Iterator;
54  import java.util.List;
55  
56  /**
57   * <a href="SocialActivityPersistenceImpl.java.html"><b><i>View Source</i></b></a>
58   *
59   * @author Brian Wing Shun Chan
60   *
61   */
62  public class SocialActivityPersistenceImpl extends BasePersistenceImpl
63      implements SocialActivityPersistence {
64      public SocialActivity create(long activityId) {
65          SocialActivity socialActivity = new SocialActivityImpl();
66  
67          socialActivity.setNew(true);
68          socialActivity.setPrimaryKey(activityId);
69  
70          return socialActivity;
71      }
72  
73      public SocialActivity remove(long activityId)
74          throws NoSuchActivityException, SystemException {
75          Session session = null;
76  
77          try {
78              session = openSession();
79  
80              SocialActivity socialActivity = (SocialActivity)session.get(SocialActivityImpl.class,
81                      new Long(activityId));
82  
83              if (socialActivity == null) {
84                  if (_log.isWarnEnabled()) {
85                      _log.warn("No SocialActivity exists with the primary key " +
86                          activityId);
87                  }
88  
89                  throw new NoSuchActivityException(
90                      "No SocialActivity exists with the primary key " +
91                      activityId);
92              }
93  
94              return remove(socialActivity);
95          }
96          catch (NoSuchActivityException nsee) {
97              throw nsee;
98          }
99          catch (Exception e) {
100             throw processException(e);
101         }
102         finally {
103             closeSession(session);
104         }
105     }
106 
107     public SocialActivity remove(SocialActivity socialActivity)
108         throws SystemException {
109         if (_listeners.length > 0) {
110             for (ModelListener listener : _listeners) {
111                 listener.onBeforeRemove(socialActivity);
112             }
113         }
114 
115         socialActivity = removeImpl(socialActivity);
116 
117         if (_listeners.length > 0) {
118             for (ModelListener listener : _listeners) {
119                 listener.onAfterRemove(socialActivity);
120             }
121         }
122 
123         return socialActivity;
124     }
125 
126     protected SocialActivity removeImpl(SocialActivity socialActivity)
127         throws SystemException {
128         Session session = null;
129 
130         try {
131             session = openSession();
132 
133             if (BatchSessionUtil.isEnabled()) {
134                 Object staleObject = session.get(SocialActivityImpl.class,
135                         socialActivity.getPrimaryKeyObj());
136 
137                 if (staleObject != null) {
138                     session.evict(staleObject);
139                 }
140             }
141 
142             session.delete(socialActivity);
143 
144             session.flush();
145 
146             return socialActivity;
147         }
148         catch (Exception e) {
149             throw processException(e);
150         }
151         finally {
152             closeSession(session);
153 
154             FinderCacheUtil.clearCache(SocialActivity.class.getName());
155         }
156     }
157 
158     /**
159      * @deprecated Use <code>update(SocialActivity socialActivity, boolean merge)</code>.
160      */
161     public SocialActivity update(SocialActivity socialActivity)
162         throws SystemException {
163         if (_log.isWarnEnabled()) {
164             _log.warn(
165                 "Using the deprecated update(SocialActivity socialActivity) method. Use update(SocialActivity socialActivity, boolean merge) instead.");
166         }
167 
168         return update(socialActivity, false);
169     }
170 
171     /**
172      * Add, update, or merge, the entity. This method also calls the model
173      * listeners to trigger the proper events associated with adding, deleting,
174      * or updating an entity.
175      *
176      * @param        socialActivity the entity to add, update, or merge
177      * @param        merge boolean value for whether to merge the entity. The
178      *                default value is false. Setting merge to true is more
179      *                expensive and should only be true when socialActivity is
180      *                transient. See LEP-5473 for a detailed discussion of this
181      *                method.
182      * @return        true if the portlet can be displayed via Ajax
183      */
184     public SocialActivity update(SocialActivity socialActivity, boolean merge)
185         throws SystemException {
186         boolean isNew = socialActivity.isNew();
187 
188         if (_listeners.length > 0) {
189             for (ModelListener listener : _listeners) {
190                 if (isNew) {
191                     listener.onBeforeCreate(socialActivity);
192                 }
193                 else {
194                     listener.onBeforeUpdate(socialActivity);
195                 }
196             }
197         }
198 
199         socialActivity = updateImpl(socialActivity, merge);
200 
201         if (_listeners.length > 0) {
202             for (ModelListener listener : _listeners) {
203                 if (isNew) {
204                     listener.onAfterCreate(socialActivity);
205                 }
206                 else {
207                     listener.onAfterUpdate(socialActivity);
208                 }
209             }
210         }
211 
212         return socialActivity;
213     }
214 
215     public SocialActivity updateImpl(
216         com.liferay.portlet.social.model.SocialActivity socialActivity,
217         boolean merge) throws SystemException {
218         Session session = null;
219 
220         try {
221             session = openSession();
222 
223             BatchSessionUtil.update(session, socialActivity, merge);
224 
225             socialActivity.setNew(false);
226 
227             return socialActivity;
228         }
229         catch (Exception e) {
230             throw processException(e);
231         }
232         finally {
233             closeSession(session);
234 
235             FinderCacheUtil.clearCache(SocialActivity.class.getName());
236         }
237     }
238 
239     public SocialActivity findByPrimaryKey(long activityId)
240         throws NoSuchActivityException, SystemException {
241         SocialActivity socialActivity = fetchByPrimaryKey(activityId);
242 
243         if (socialActivity == null) {
244             if (_log.isWarnEnabled()) {
245                 _log.warn("No SocialActivity exists with the primary key " +
246                     activityId);
247             }
248 
249             throw new NoSuchActivityException(
250                 "No SocialActivity exists with the primary key " + activityId);
251         }
252 
253         return socialActivity;
254     }
255 
256     public SocialActivity fetchByPrimaryKey(long activityId)
257         throws SystemException {
258         Session session = null;
259 
260         try {
261             session = openSession();
262 
263             return (SocialActivity)session.get(SocialActivityImpl.class,
264                 new Long(activityId));
265         }
266         catch (Exception e) {
267             throw processException(e);
268         }
269         finally {
270             closeSession(session);
271         }
272     }
273 
274     public List<SocialActivity> findByGroupId(long groupId)
275         throws SystemException {
276         boolean finderClassNameCacheEnabled = SocialActivityModelImpl.CACHE_ENABLED;
277         String finderClassName = SocialActivity.class.getName();
278         String finderMethodName = "findByGroupId";
279         String[] finderParams = new String[] { Long.class.getName() };
280         Object[] finderArgs = new Object[] { new Long(groupId) };
281 
282         Object result = null;
283 
284         if (finderClassNameCacheEnabled) {
285             result = FinderCacheUtil.getResult(finderClassName,
286                     finderMethodName, finderParams, finderArgs, this);
287         }
288 
289         if (result == null) {
290             Session session = null;
291 
292             try {
293                 session = openSession();
294 
295                 StringBuilder query = new StringBuilder();
296 
297                 query.append(
298                     "FROM com.liferay.portlet.social.model.SocialActivity WHERE ");
299 
300                 query.append("groupId = ?");
301 
302                 query.append(" ");
303 
304                 query.append("ORDER BY ");
305 
306                 query.append("createDate DESC");
307 
308                 Query q = session.createQuery(query.toString());
309 
310                 QueryPos qPos = QueryPos.getInstance(q);
311 
312                 qPos.add(groupId);
313 
314                 List<SocialActivity> list = q.list();
315 
316                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
317                     finderClassName, finderMethodName, finderParams,
318                     finderArgs, list);
319 
320                 return list;
321             }
322             catch (Exception e) {
323                 throw processException(e);
324             }
325             finally {
326                 closeSession(session);
327             }
328         }
329         else {
330             return (List<SocialActivity>)result;
331         }
332     }
333 
334     public List<SocialActivity> findByGroupId(long groupId, int start, int end)
335         throws SystemException {
336         return findByGroupId(groupId, start, end, null);
337     }
338 
339     public List<SocialActivity> findByGroupId(long groupId, int start, int end,
340         OrderByComparator obc) throws SystemException {
341         boolean finderClassNameCacheEnabled = SocialActivityModelImpl.CACHE_ENABLED;
342         String finderClassName = SocialActivity.class.getName();
343         String finderMethodName = "findByGroupId";
344         String[] finderParams = new String[] {
345                 Long.class.getName(),
346                 
347                 "java.lang.Integer", "java.lang.Integer",
348                 "com.liferay.portal.kernel.util.OrderByComparator"
349             };
350         Object[] finderArgs = new Object[] {
351                 new Long(groupId),
352                 
353                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
354             };
355 
356         Object result = null;
357 
358         if (finderClassNameCacheEnabled) {
359             result = FinderCacheUtil.getResult(finderClassName,
360                     finderMethodName, finderParams, finderArgs, this);
361         }
362 
363         if (result == null) {
364             Session session = null;
365 
366             try {
367                 session = openSession();
368 
369                 StringBuilder query = new StringBuilder();
370 
371                 query.append(
372                     "FROM com.liferay.portlet.social.model.SocialActivity WHERE ");
373 
374                 query.append("groupId = ?");
375 
376                 query.append(" ");
377 
378                 if (obc != null) {
379                     query.append("ORDER BY ");
380                     query.append(obc.getOrderBy());
381                 }
382 
383                 else {
384                     query.append("ORDER BY ");
385 
386                     query.append("createDate DESC");
387                 }
388 
389                 Query q = session.createQuery(query.toString());
390 
391                 QueryPos qPos = QueryPos.getInstance(q);
392 
393                 qPos.add(groupId);
394 
395                 List<SocialActivity> list = (List<SocialActivity>)QueryUtil.list(q,
396                         getDialect(), start, end);
397 
398                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
399                     finderClassName, finderMethodName, finderParams,
400                     finderArgs, list);
401 
402                 return list;
403             }
404             catch (Exception e) {
405                 throw processException(e);
406             }
407             finally {
408                 closeSession(session);
409             }
410         }
411         else {
412             return (List<SocialActivity>)result;
413         }
414     }
415 
416     public SocialActivity findByGroupId_First(long groupId,
417         OrderByComparator obc) throws NoSuchActivityException, SystemException {
418         List<SocialActivity> list = findByGroupId(groupId, 0, 1, obc);
419 
420         if (list.size() == 0) {
421             StringBuilder msg = new StringBuilder();
422 
423             msg.append("No SocialActivity exists with the key {");
424 
425             msg.append("groupId=" + groupId);
426 
427             msg.append(StringPool.CLOSE_CURLY_BRACE);
428 
429             throw new NoSuchActivityException(msg.toString());
430         }
431         else {
432             return list.get(0);
433         }
434     }
435 
436     public SocialActivity findByGroupId_Last(long groupId, OrderByComparator obc)
437         throws NoSuchActivityException, SystemException {
438         int count = countByGroupId(groupId);
439 
440         List<SocialActivity> list = findByGroupId(groupId, count - 1, count, obc);
441 
442         if (list.size() == 0) {
443             StringBuilder msg = new StringBuilder();
444 
445             msg.append("No SocialActivity exists with the key {");
446 
447             msg.append("groupId=" + groupId);
448 
449             msg.append(StringPool.CLOSE_CURLY_BRACE);
450 
451             throw new NoSuchActivityException(msg.toString());
452         }
453         else {
454             return list.get(0);
455         }
456     }
457 
458     public SocialActivity[] findByGroupId_PrevAndNext(long activityId,
459         long groupId, OrderByComparator obc)
460         throws NoSuchActivityException, SystemException {
461         SocialActivity socialActivity = findByPrimaryKey(activityId);
462 
463         int count = countByGroupId(groupId);
464 
465         Session session = null;
466 
467         try {
468             session = openSession();
469 
470             StringBuilder query = new StringBuilder();
471 
472             query.append(
473                 "FROM com.liferay.portlet.social.model.SocialActivity WHERE ");
474 
475             query.append("groupId = ?");
476 
477             query.append(" ");
478 
479             if (obc != null) {
480                 query.append("ORDER BY ");
481                 query.append(obc.getOrderBy());
482             }
483 
484             else {
485                 query.append("ORDER BY ");
486 
487                 query.append("createDate DESC");
488             }
489 
490             Query q = session.createQuery(query.toString());
491 
492             QueryPos qPos = QueryPos.getInstance(q);
493 
494             qPos.add(groupId);
495 
496             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
497                     socialActivity);
498 
499             SocialActivity[] array = new SocialActivityImpl[3];
500 
501             array[0] = (SocialActivity)objArray[0];
502             array[1] = (SocialActivity)objArray[1];
503             array[2] = (SocialActivity)objArray[2];
504 
505             return array;
506         }
507         catch (Exception e) {
508             throw processException(e);
509         }
510         finally {
511             closeSession(session);
512         }
513     }
514 
515     public List<SocialActivity> findByCompanyId(long companyId)
516         throws SystemException {
517         boolean finderClassNameCacheEnabled = SocialActivityModelImpl.CACHE_ENABLED;
518         String finderClassName = SocialActivity.class.getName();
519         String finderMethodName = "findByCompanyId";
520         String[] finderParams = new String[] { Long.class.getName() };
521         Object[] finderArgs = new Object[] { new Long(companyId) };
522 
523         Object result = null;
524 
525         if (finderClassNameCacheEnabled) {
526             result = FinderCacheUtil.getResult(finderClassName,
527                     finderMethodName, finderParams, finderArgs, this);
528         }
529 
530         if (result == null) {
531             Session session = null;
532 
533             try {
534                 session = openSession();
535 
536                 StringBuilder query = new StringBuilder();
537 
538                 query.append(
539                     "FROM com.liferay.portlet.social.model.SocialActivity WHERE ");
540 
541                 query.append("companyId = ?");
542 
543                 query.append(" ");
544 
545                 query.append("ORDER BY ");
546 
547                 query.append("createDate DESC");
548 
549                 Query q = session.createQuery(query.toString());
550 
551                 QueryPos qPos = QueryPos.getInstance(q);
552 
553                 qPos.add(companyId);
554 
555                 List<SocialActivity> list = q.list();
556 
557                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
558                     finderClassName, finderMethodName, finderParams,
559                     finderArgs, list);
560 
561                 return list;
562             }
563             catch (Exception e) {
564                 throw processException(e);
565             }
566             finally {
567                 closeSession(session);
568             }
569         }
570         else {
571             return (List<SocialActivity>)result;
572         }
573     }
574 
575     public List<SocialActivity> findByCompanyId(long companyId, int start,
576         int end) throws SystemException {
577         return findByCompanyId(companyId, start, end, null);
578     }
579 
580     public List<SocialActivity> findByCompanyId(long companyId, int start,
581         int end, OrderByComparator obc) throws SystemException {
582         boolean finderClassNameCacheEnabled = SocialActivityModelImpl.CACHE_ENABLED;
583         String finderClassName = SocialActivity.class.getName();
584         String finderMethodName = "findByCompanyId";
585         String[] finderParams = new String[] {
586                 Long.class.getName(),
587                 
588                 "java.lang.Integer", "java.lang.Integer",
589                 "com.liferay.portal.kernel.util.OrderByComparator"
590             };
591         Object[] finderArgs = new Object[] {
592                 new Long(companyId),
593                 
594                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
595             };
596 
597         Object result = null;
598 
599         if (finderClassNameCacheEnabled) {
600             result = FinderCacheUtil.getResult(finderClassName,
601                     finderMethodName, finderParams, finderArgs, this);
602         }
603 
604         if (result == null) {
605             Session session = null;
606 
607             try {
608                 session = openSession();
609 
610                 StringBuilder query = new StringBuilder();
611 
612                 query.append(
613                     "FROM com.liferay.portlet.social.model.SocialActivity WHERE ");
614 
615                 query.append("companyId = ?");
616 
617                 query.append(" ");
618 
619                 if (obc != null) {
620                     query.append("ORDER BY ");
621                     query.append(obc.getOrderBy());
622                 }
623 
624                 else {
625                     query.append("ORDER BY ");
626 
627                     query.append("createDate DESC");
628                 }
629 
630                 Query q = session.createQuery(query.toString());
631 
632                 QueryPos qPos = QueryPos.getInstance(q);
633 
634                 qPos.add(companyId);
635 
636                 List<SocialActivity> list = (List<SocialActivity>)QueryUtil.list(q,
637                         getDialect(), start, end);
638 
639                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
640                     finderClassName, finderMethodName, finderParams,
641                     finderArgs, list);
642 
643                 return list;
644             }
645             catch (Exception e) {
646                 throw processException(e);
647             }
648             finally {
649                 closeSession(session);
650             }
651         }
652         else {
653             return (List<SocialActivity>)result;
654         }
655     }
656 
657     public SocialActivity findByCompanyId_First(long companyId,
658         OrderByComparator obc) throws NoSuchActivityException, SystemException {
659         List<SocialActivity> list = findByCompanyId(companyId, 0, 1, obc);
660 
661         if (list.size() == 0) {
662             StringBuilder msg = new StringBuilder();
663 
664             msg.append("No SocialActivity exists with the key {");
665 
666             msg.append("companyId=" + companyId);
667 
668             msg.append(StringPool.CLOSE_CURLY_BRACE);
669 
670             throw new NoSuchActivityException(msg.toString());
671         }
672         else {
673             return list.get(0);
674         }
675     }
676 
677     public SocialActivity findByCompanyId_Last(long companyId,
678         OrderByComparator obc) throws NoSuchActivityException, SystemException {
679         int count = countByCompanyId(companyId);
680 
681         List<SocialActivity> list = findByCompanyId(companyId, count - 1,
682                 count, obc);
683 
684         if (list.size() == 0) {
685             StringBuilder msg = new StringBuilder();
686 
687             msg.append("No SocialActivity exists with the key {");
688 
689             msg.append("companyId=" + companyId);
690 
691             msg.append(StringPool.CLOSE_CURLY_BRACE);
692 
693             throw new NoSuchActivityException(msg.toString());
694         }
695         else {
696             return list.get(0);
697         }
698     }
699 
700     public SocialActivity[] findByCompanyId_PrevAndNext(long activityId,
701         long companyId, OrderByComparator obc)
702         throws NoSuchActivityException, SystemException {
703         SocialActivity socialActivity = findByPrimaryKey(activityId);
704 
705         int count = countByCompanyId(companyId);
706 
707         Session session = null;
708 
709         try {
710             session = openSession();
711 
712             StringBuilder query = new StringBuilder();
713 
714             query.append(
715                 "FROM com.liferay.portlet.social.model.SocialActivity WHERE ");
716 
717             query.append("companyId = ?");
718 
719             query.append(" ");
720 
721             if (obc != null) {
722                 query.append("ORDER BY ");
723                 query.append(obc.getOrderBy());
724             }
725 
726             else {
727                 query.append("ORDER BY ");
728 
729                 query.append("createDate DESC");
730             }
731 
732             Query q = session.createQuery(query.toString());
733 
734             QueryPos qPos = QueryPos.getInstance(q);
735 
736             qPos.add(companyId);
737 
738             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
739                     socialActivity);
740 
741             SocialActivity[] array = new SocialActivityImpl[3];
742 
743             array[0] = (SocialActivity)objArray[0];
744             array[1] = (SocialActivity)objArray[1];
745             array[2] = (SocialActivity)objArray[2];
746 
747             return array;
748         }
749         catch (Exception e) {
750             throw processException(e);
751         }
752         finally {
753             closeSession(session);
754         }
755     }
756 
757     public List<SocialActivity> findByUserId(long userId)
758         throws SystemException {
759         boolean finderClassNameCacheEnabled = SocialActivityModelImpl.CACHE_ENABLED;
760         String finderClassName = SocialActivity.class.getName();
761         String finderMethodName = "findByUserId";
762         String[] finderParams = new String[] { Long.class.getName() };
763         Object[] finderArgs = new Object[] { new Long(userId) };
764 
765         Object result = null;
766 
767         if (finderClassNameCacheEnabled) {
768             result = FinderCacheUtil.getResult(finderClassName,
769                     finderMethodName, finderParams, finderArgs, this);
770         }
771 
772         if (result == null) {
773             Session session = null;
774 
775             try {
776                 session = openSession();
777 
778                 StringBuilder query = new StringBuilder();
779 
780                 query.append(
781                     "FROM com.liferay.portlet.social.model.SocialActivity WHERE ");
782 
783                 query.append("userId = ?");
784 
785                 query.append(" ");
786 
787                 query.append("ORDER BY ");
788 
789                 query.append("createDate DESC");
790 
791                 Query q = session.createQuery(query.toString());
792 
793                 QueryPos qPos = QueryPos.getInstance(q);
794 
795                 qPos.add(userId);
796 
797                 List<SocialActivity> list = q.list();
798 
799                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
800                     finderClassName, finderMethodName, finderParams,
801                     finderArgs, list);
802 
803                 return list;
804             }
805             catch (Exception e) {
806                 throw processException(e);
807             }
808             finally {
809                 closeSession(session);
810             }
811         }
812         else {
813             return (List<SocialActivity>)result;
814         }
815     }
816 
817     public List<SocialActivity> findByUserId(long userId, int start, int end)
818         throws SystemException {
819         return findByUserId(userId, start, end, null);
820     }
821 
822     public List<SocialActivity> findByUserId(long userId, int start, int end,
823         OrderByComparator obc) throws SystemException {
824         boolean finderClassNameCacheEnabled = SocialActivityModelImpl.CACHE_ENABLED;
825         String finderClassName = SocialActivity.class.getName();
826         String finderMethodName = "findByUserId";
827         String[] finderParams = new String[] {
828                 Long.class.getName(),
829                 
830                 "java.lang.Integer", "java.lang.Integer",
831                 "com.liferay.portal.kernel.util.OrderByComparator"
832             };
833         Object[] finderArgs = new Object[] {
834                 new Long(userId),
835                 
836                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
837             };
838 
839         Object result = null;
840 
841         if (finderClassNameCacheEnabled) {
842             result = FinderCacheUtil.getResult(finderClassName,
843                     finderMethodName, finderParams, finderArgs, this);
844         }
845 
846         if (result == null) {
847             Session session = null;
848 
849             try {
850                 session = openSession();
851 
852                 StringBuilder query = new StringBuilder();
853 
854                 query.append(
855                     "FROM com.liferay.portlet.social.model.SocialActivity WHERE ");
856 
857                 query.append("userId = ?");
858 
859                 query.append(" ");
860 
861                 if (obc != null) {
862                     query.append("ORDER BY ");
863                     query.append(obc.getOrderBy());
864                 }
865 
866                 else {
867                     query.append("ORDER BY ");
868 
869                     query.append("createDate DESC");
870                 }
871 
872                 Query q = session.createQuery(query.toString());
873 
874                 QueryPos qPos = QueryPos.getInstance(q);
875 
876                 qPos.add(userId);
877 
878                 List<SocialActivity> list = (List<SocialActivity>)QueryUtil.list(q,
879                         getDialect(), start, end);
880 
881                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
882                     finderClassName, finderMethodName, finderParams,
883                     finderArgs, list);
884 
885                 return list;
886             }
887             catch (Exception e) {
888                 throw processException(e);
889             }
890             finally {
891                 closeSession(session);
892             }
893         }
894         else {
895             return (List<SocialActivity>)result;
896         }
897     }
898 
899     public SocialActivity findByUserId_First(long userId, OrderByComparator obc)
900         throws NoSuchActivityException, SystemException {
901         List<SocialActivity> list = findByUserId(userId, 0, 1, obc);
902 
903         if (list.size() == 0) {
904             StringBuilder msg = new StringBuilder();
905 
906             msg.append("No SocialActivity exists with the key {");
907 
908             msg.append("userId=" + userId);
909 
910             msg.append(StringPool.CLOSE_CURLY_BRACE);
911 
912             throw new NoSuchActivityException(msg.toString());
913         }
914         else {
915             return list.get(0);
916         }
917     }
918 
919     public SocialActivity findByUserId_Last(long userId, OrderByComparator obc)
920         throws NoSuchActivityException, SystemException {
921         int count = countByUserId(userId);
922 
923         List<SocialActivity> list = findByUserId(userId, count - 1, count, obc);
924 
925         if (list.size() == 0) {
926             StringBuilder msg = new StringBuilder();
927 
928             msg.append("No SocialActivity exists with the key {");
929 
930             msg.append("userId=" + userId);
931 
932             msg.append(StringPool.CLOSE_CURLY_BRACE);
933 
934             throw new NoSuchActivityException(msg.toString());
935         }
936         else {
937             return list.get(0);
938         }
939     }
940 
941     public SocialActivity[] findByUserId_PrevAndNext(long activityId,
942         long userId, OrderByComparator obc)
943         throws NoSuchActivityException, SystemException {
944         SocialActivity socialActivity = findByPrimaryKey(activityId);
945 
946         int count = countByUserId(userId);
947 
948         Session session = null;
949 
950         try {
951             session = openSession();
952 
953             StringBuilder query = new StringBuilder();
954 
955             query.append(
956                 "FROM com.liferay.portlet.social.model.SocialActivity WHERE ");
957 
958             query.append("userId = ?");
959 
960             query.append(" ");
961 
962             if (obc != null) {
963                 query.append("ORDER BY ");
964                 query.append(obc.getOrderBy());
965             }
966 
967             else {
968                 query.append("ORDER BY ");
969 
970                 query.append("createDate DESC");
971             }
972 
973             Query q = session.createQuery(query.toString());
974 
975             QueryPos qPos = QueryPos.getInstance(q);
976 
977             qPos.add(userId);
978 
979             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
980                     socialActivity);
981 
982             SocialActivity[] array = new SocialActivityImpl[3];
983 
984             array[0] = (SocialActivity)objArray[0];
985             array[1] = (SocialActivity)objArray[1];
986             array[2] = (SocialActivity)objArray[2];
987 
988             return array;
989         }
990         catch (Exception e) {
991             throw processException(e);
992         }
993         finally {
994             closeSession(session);
995         }
996     }
997 
998     public SocialActivity findByMirrorActivityId(long mirrorActivityId)
999         throws NoSuchActivityException, SystemException {
1000        SocialActivity socialActivity = fetchByMirrorActivityId(mirrorActivityId);
1001
1002        if (socialActivity == null) {
1003            StringBuilder msg = new StringBuilder();
1004
1005            msg.append("No SocialActivity exists with the key {");
1006
1007            msg.append("mirrorActivityId=" + mirrorActivityId);
1008
1009            msg.append(StringPool.CLOSE_CURLY_BRACE);
1010
1011            if (_log.isWarnEnabled()) {
1012                _log.warn(msg.toString());
1013            }
1014
1015            throw new NoSuchActivityException(msg.toString());
1016        }
1017
1018        return socialActivity;
1019    }
1020
1021    public SocialActivity fetchByMirrorActivityId(long mirrorActivityId)
1022        throws SystemException {
1023        boolean finderClassNameCacheEnabled = SocialActivityModelImpl.CACHE_ENABLED;
1024        String finderClassName = SocialActivity.class.getName();
1025        String finderMethodName = "fetchByMirrorActivityId";
1026        String[] finderParams = new String[] { Long.class.getName() };
1027        Object[] finderArgs = new Object[] { new Long(mirrorActivityId) };
1028
1029        Object result = null;
1030
1031        if (finderClassNameCacheEnabled) {
1032            result = FinderCacheUtil.getResult(finderClassName,
1033                    finderMethodName, finderParams, finderArgs, this);
1034        }
1035
1036        if (result == null) {
1037            Session session = null;
1038
1039            try {
1040                session = openSession();
1041
1042                StringBuilder query = new StringBuilder();
1043
1044                query.append(
1045                    "FROM com.liferay.portlet.social.model.SocialActivity WHERE ");
1046
1047                query.append("mirrorActivityId = ?");
1048
1049                query.append(" ");
1050
1051                query.append("ORDER BY ");
1052
1053                query.append("createDate DESC");
1054
1055                Query q = session.createQuery(query.toString());
1056
1057                QueryPos qPos = QueryPos.getInstance(q);
1058
1059                qPos.add(mirrorActivityId);
1060
1061                List<SocialActivity> list = q.list();
1062
1063                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1064                    finderClassName, finderMethodName, finderParams,
1065                    finderArgs, list);
1066
1067                if (list.size() == 0) {
1068                    return null;
1069                }
1070                else {
1071                    return list.get(0);
1072                }
1073            }
1074            catch (Exception e) {
1075                throw processException(e);
1076            }
1077            finally {
1078                closeSession(session);
1079            }
1080        }
1081        else {
1082            List<SocialActivity> list = (List<SocialActivity>)result;
1083
1084            if (list.size() == 0) {
1085                return null;
1086            }
1087            else {
1088                return list.get(0);
1089            }
1090        }
1091    }
1092
1093    public List<SocialActivity> findByClassNameId(long classNameId)
1094        throws SystemException {
1095        boolean finderClassNameCacheEnabled = SocialActivityModelImpl.CACHE_ENABLED;
1096        String finderClassName = SocialActivity.class.getName();
1097        String finderMethodName = "findByClassNameId";
1098        String[] finderParams = new String[] { Long.class.getName() };
1099        Object[] finderArgs = new Object[] { new Long(classNameId) };
1100
1101        Object result = null;
1102
1103        if (finderClassNameCacheEnabled) {
1104            result = FinderCacheUtil.getResult(finderClassName,
1105                    finderMethodName, finderParams, finderArgs, this);
1106        }
1107
1108        if (result == null) {
1109            Session session = null;
1110
1111            try {
1112                session = openSession();
1113
1114                StringBuilder query = new StringBuilder();
1115
1116                query.append(
1117                    "FROM com.liferay.portlet.social.model.SocialActivity WHERE ");
1118
1119                query.append("classNameId = ?");
1120
1121                query.append(" ");
1122
1123                query.append("ORDER BY ");
1124
1125                query.append("createDate DESC");
1126
1127                Query q = session.createQuery(query.toString());
1128
1129                QueryPos qPos = QueryPos.getInstance(q);
1130
1131                qPos.add(classNameId);
1132
1133                List<SocialActivity> list = q.list();
1134
1135                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1136                    finderClassName, finderMethodName, finderParams,
1137                    finderArgs, list);
1138
1139                return list;
1140            }
1141            catch (Exception e) {
1142                throw processException(e);
1143            }
1144            finally {
1145                closeSession(session);
1146            }
1147        }
1148        else {
1149            return (List<SocialActivity>)result;
1150        }
1151    }
1152
1153    public List<SocialActivity> findByClassNameId(long classNameId, int start,
1154        int end) throws SystemException {
1155        return findByClassNameId(classNameId, start, end, null);
1156    }
1157
1158    public List<SocialActivity> findByClassNameId(long classNameId, int start,
1159        int end, OrderByComparator obc) throws SystemException {
1160        boolean finderClassNameCacheEnabled = SocialActivityModelImpl.CACHE_ENABLED;
1161        String finderClassName = SocialActivity.class.getName();
1162        String finderMethodName = "findByClassNameId";
1163        String[] finderParams = new String[] {
1164                Long.class.getName(),
1165                
1166                "java.lang.Integer", "java.lang.Integer",
1167                "com.liferay.portal.kernel.util.OrderByComparator"
1168            };
1169        Object[] finderArgs = new Object[] {
1170                new Long(classNameId),
1171                
1172                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1173            };
1174
1175        Object result = null;
1176
1177        if (finderClassNameCacheEnabled) {
1178            result = FinderCacheUtil.getResult(finderClassName,
1179                    finderMethodName, finderParams, finderArgs, this);
1180        }
1181
1182        if (result == null) {
1183            Session session = null;
1184
1185            try {
1186                session = openSession();
1187
1188                StringBuilder query = new StringBuilder();
1189
1190                query.append(
1191                    "FROM com.liferay.portlet.social.model.SocialActivity WHERE ");
1192
1193                query.append("classNameId = ?");
1194
1195                query.append(" ");
1196
1197                if (obc != null) {
1198                    query.append("ORDER BY ");
1199                    query.append(obc.getOrderBy());
1200                }
1201
1202                else {
1203                    query.append("ORDER BY ");
1204
1205                    query.append("createDate DESC");
1206                }
1207
1208                Query q = session.createQuery(query.toString());
1209
1210                QueryPos qPos = QueryPos.getInstance(q);
1211
1212                qPos.add(classNameId);
1213
1214                List<SocialActivity> list = (List<SocialActivity>)QueryUtil.list(q,
1215                        getDialect(), start, end);
1216
1217                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1218                    finderClassName, finderMethodName, finderParams,
1219                    finderArgs, list);
1220
1221                return list;
1222            }
1223            catch (Exception e) {
1224                throw processException(e);
1225            }
1226            finally {
1227                closeSession(session);
1228            }
1229        }
1230        else {
1231            return (List<SocialActivity>)result;
1232        }
1233    }
1234
1235    public SocialActivity findByClassNameId_First(long classNameId,
1236        OrderByComparator obc) throws NoSuchActivityException, SystemException {
1237        List<SocialActivity> list = findByClassNameId(classNameId, 0, 1, obc);
1238
1239        if (list.size() == 0) {
1240            StringBuilder msg = new StringBuilder();
1241
1242            msg.append("No SocialActivity exists with the key {");
1243
1244            msg.append("classNameId=" + classNameId);
1245
1246            msg.append(StringPool.CLOSE_CURLY_BRACE);
1247
1248            throw new NoSuchActivityException(msg.toString());
1249        }
1250        else {
1251            return list.get(0);
1252        }
1253    }
1254
1255    public SocialActivity findByClassNameId_Last(long classNameId,
1256        OrderByComparator obc) throws NoSuchActivityException, SystemException {
1257        int count = countByClassNameId(classNameId);
1258
1259        List<SocialActivity> list = findByClassNameId(classNameId, count - 1,
1260                count, obc);
1261
1262        if (list.size() == 0) {
1263            StringBuilder msg = new StringBuilder();
1264
1265            msg.append("No SocialActivity exists with the key {");
1266
1267            msg.append("classNameId=" + classNameId);
1268
1269            msg.append(StringPool.CLOSE_CURLY_BRACE);
1270
1271            throw new NoSuchActivityException(msg.toString());
1272        }
1273        else {
1274            return list.get(0);
1275        }
1276    }
1277
1278    public SocialActivity[] findByClassNameId_PrevAndNext(long activityId,
1279        long classNameId, OrderByComparator obc)
1280        throws NoSuchActivityException, SystemException {
1281        SocialActivity socialActivity = findByPrimaryKey(activityId);
1282
1283        int count = countByClassNameId(classNameId);
1284
1285        Session session = null;
1286
1287        try {
1288            session = openSession();
1289
1290            StringBuilder query = new StringBuilder();
1291
1292            query.append(
1293                "FROM com.liferay.portlet.social.model.SocialActivity WHERE ");
1294
1295            query.append("classNameId = ?");
1296
1297            query.append(" ");
1298
1299            if (obc != null) {
1300                query.append("ORDER BY ");
1301                query.append(obc.getOrderBy());
1302            }
1303
1304            else {
1305                query.append("ORDER BY ");
1306
1307                query.append("createDate DESC");
1308            }
1309
1310            Query q = session.createQuery(query.toString());
1311
1312            QueryPos qPos = QueryPos.getInstance(q);
1313
1314            qPos.add(classNameId);
1315
1316            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1317                    socialActivity);
1318
1319            SocialActivity[] array = new SocialActivityImpl[3];
1320
1321            array[0] = (SocialActivity)objArray[0];
1322            array[1] = (SocialActivity)objArray[1];
1323            array[2] = (SocialActivity)objArray[2];
1324
1325            return array;
1326        }
1327        catch (Exception e) {
1328            throw processException(e);
1329        }
1330        finally {
1331            closeSession(session);
1332        }
1333    }
1334
1335    public List<SocialActivity> findByReceiverUserId(long receiverUserId)
1336        throws SystemException {
1337        boolean finderClassNameCacheEnabled = SocialActivityModelImpl.CACHE_ENABLED;
1338        String finderClassName = SocialActivity.class.getName();
1339        String finderMethodName = "findByReceiverUserId";
1340        String[] finderParams = new String[] { Long.class.getName() };
1341        Object[] finderArgs = new Object[] { new Long(receiverUserId) };
1342
1343        Object result = null;
1344
1345        if (finderClassNameCacheEnabled) {
1346            result = FinderCacheUtil.getResult(finderClassName,
1347                    finderMethodName, finderParams, finderArgs, this);
1348        }
1349
1350        if (result == null) {
1351            Session session = null;
1352
1353            try {
1354                session = openSession();
1355
1356                StringBuilder query = new StringBuilder();
1357
1358                query.append(
1359                    "FROM com.liferay.portlet.social.model.SocialActivity WHERE ");
1360
1361                query.append("receiverUserId = ?");
1362
1363                query.append(" ");
1364
1365                query.append("ORDER BY ");
1366
1367                query.append("createDate DESC");
1368
1369                Query q = session.createQuery(query.toString());
1370
1371                QueryPos qPos = QueryPos.getInstance(q);
1372
1373                qPos.add(receiverUserId);
1374
1375                List<SocialActivity> list = q.list();
1376
1377                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1378                    finderClassName, finderMethodName, finderParams,
1379                    finderArgs, list);
1380
1381                return list;
1382            }
1383            catch (Exception e) {
1384                throw processException(e);
1385            }
1386            finally {
1387                closeSession(session);
1388            }
1389        }
1390        else {
1391            return (List<SocialActivity>)result;
1392        }
1393    }
1394
1395    public List<SocialActivity> findByReceiverUserId(long receiverUserId,
1396        int start, int end) throws SystemException {
1397        return findByReceiverUserId(receiverUserId, start, end, null);
1398    }
1399
1400    public List<SocialActivity> findByReceiverUserId(long receiverUserId,
1401        int start, int end, OrderByComparator obc) throws SystemException {
1402        boolean finderClassNameCacheEnabled = SocialActivityModelImpl.CACHE_ENABLED;
1403        String finderClassName = SocialActivity.class.getName();
1404        String finderMethodName = "findByReceiverUserId";
1405        String[] finderParams = new String[] {
1406                Long.class.getName(),
1407                
1408                "java.lang.Integer", "java.lang.Integer",
1409                "com.liferay.portal.kernel.util.OrderByComparator"
1410            };
1411        Object[] finderArgs = new Object[] {
1412                new Long(receiverUserId),
1413                
1414                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1415            };
1416
1417        Object result = null;
1418
1419        if (finderClassNameCacheEnabled) {
1420            result = FinderCacheUtil.getResult(finderClassName,
1421                    finderMethodName, finderParams, finderArgs, this);
1422        }
1423
1424        if (result == null) {
1425            Session session = null;
1426
1427            try {
1428                session = openSession();
1429
1430                StringBuilder query = new StringBuilder();
1431
1432                query.append(
1433                    "FROM com.liferay.portlet.social.model.SocialActivity WHERE ");
1434
1435                query.append("receiverUserId = ?");
1436
1437                query.append(" ");
1438
1439                if (obc != null) {
1440                    query.append("ORDER BY ");
1441                    query.append(obc.getOrderBy());
1442                }
1443
1444                else {
1445                    query.append("ORDER BY ");
1446
1447                    query.append("createDate DESC");
1448                }
1449
1450                Query q = session.createQuery(query.toString());
1451
1452                QueryPos qPos = QueryPos.getInstance(q);
1453
1454                qPos.add(receiverUserId);
1455
1456                List<SocialActivity> list = (List<SocialActivity>)QueryUtil.list(q,
1457                        getDialect(), start, end);
1458
1459                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1460                    finderClassName, finderMethodName, finderParams,
1461                    finderArgs, list);
1462
1463                return list;
1464            }
1465            catch (Exception e) {
1466                throw processException(e);
1467            }
1468            finally {
1469                closeSession(session);
1470            }
1471        }
1472        else {
1473            return (List<SocialActivity>)result;
1474        }
1475    }
1476
1477    public SocialActivity findByReceiverUserId_First(long receiverUserId,
1478        OrderByComparator obc) throws NoSuchActivityException, SystemException {
1479        List<SocialActivity> list = findByReceiverUserId(receiverUserId, 0, 1,
1480                obc);
1481
1482        if (list.size() == 0) {
1483            StringBuilder msg = new StringBuilder();
1484
1485            msg.append("No SocialActivity exists with the key {");
1486
1487            msg.append("receiverUserId=" + receiverUserId);
1488
1489            msg.append(StringPool.CLOSE_CURLY_BRACE);
1490
1491            throw new NoSuchActivityException(msg.toString());
1492        }
1493        else {
1494            return list.get(0);
1495        }
1496    }
1497
1498    public SocialActivity findByReceiverUserId_Last(long receiverUserId,
1499        OrderByComparator obc) throws NoSuchActivityException, SystemException {
1500        int count = countByReceiverUserId(receiverUserId);
1501
1502        List<SocialActivity> list = findByReceiverUserId(receiverUserId,
1503                count - 1, count, obc);
1504
1505        if (list.size() == 0) {
1506            StringBuilder msg = new StringBuilder();
1507
1508            msg.append("No SocialActivity exists with the key {");
1509
1510            msg.append("receiverUserId=" + receiverUserId);
1511
1512            msg.append(StringPool.CLOSE_CURLY_BRACE);
1513
1514            throw new NoSuchActivityException(msg.toString());
1515        }
1516        else {
1517            return list.get(0);
1518        }
1519    }
1520
1521    public SocialActivity[] findByReceiverUserId_PrevAndNext(long activityId,
1522        long receiverUserId, OrderByComparator obc)
1523        throws NoSuchActivityException, SystemException {
1524        SocialActivity socialActivity = findByPrimaryKey(activityId);
1525
1526        int count = countByReceiverUserId(receiverUserId);
1527
1528        Session session = null;
1529
1530        try {
1531            session = openSession();
1532
1533            StringBuilder query = new StringBuilder();
1534
1535            query.append(
1536                "FROM com.liferay.portlet.social.model.SocialActivity WHERE ");
1537
1538            query.append("receiverUserId = ?");
1539
1540            query.append(" ");
1541
1542            if (obc != null) {
1543                query.append("ORDER BY ");
1544                query.append(obc.getOrderBy());
1545            }
1546
1547            else {
1548                query.append("ORDER BY ");
1549
1550                query.append("createDate DESC");
1551            }
1552
1553            Query q = session.createQuery(query.toString());
1554
1555            QueryPos qPos = QueryPos.getInstance(q);
1556
1557            qPos.add(receiverUserId);
1558
1559            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1560                    socialActivity);
1561
1562            SocialActivity[] array = new SocialActivityImpl[3];
1563
1564            array[0] = (SocialActivity)objArray[0];
1565            array[1] = (SocialActivity)objArray[1];
1566            array[2] = (SocialActivity)objArray[2];
1567
1568            return array;
1569        }
1570        catch (Exception e) {
1571            throw processException(e);
1572        }
1573        finally {
1574            closeSession(session);
1575        }
1576    }
1577
1578    public List<SocialActivity> findByC_C(long classNameId, long classPK)
1579        throws SystemException {
1580        boolean finderClassNameCacheEnabled = SocialActivityModelImpl.CACHE_ENABLED;
1581        String finderClassName = SocialActivity.class.getName();
1582        String finderMethodName = "findByC_C";
1583        String[] finderParams = new String[] {
1584                Long.class.getName(), Long.class.getName()
1585            };
1586        Object[] finderArgs = new Object[] {
1587                new Long(classNameId), new Long(classPK)
1588            };
1589
1590        Object result = null;
1591
1592        if (finderClassNameCacheEnabled) {
1593            result = FinderCacheUtil.getResult(finderClassName,
1594                    finderMethodName, finderParams, finderArgs, this);
1595        }
1596
1597        if (result == null) {
1598            Session session = null;
1599
1600            try {
1601                session = openSession();
1602
1603                StringBuilder query = new StringBuilder();
1604
1605                query.append(
1606                    "FROM com.liferay.portlet.social.model.SocialActivity WHERE ");
1607
1608                query.append("classNameId = ?");
1609
1610                query.append(" AND ");
1611
1612                query.append("classPK = ?");
1613
1614                query.append(" ");
1615
1616                query.append("ORDER BY ");
1617
1618                query.append("createDate DESC");
1619
1620                Query q = session.createQuery(query.toString());
1621
1622                QueryPos qPos = QueryPos.getInstance(q);
1623
1624                qPos.add(classNameId);
1625
1626                qPos.add(classPK);
1627
1628                List<SocialActivity> list = q.list();
1629
1630                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1631                    finderClassName, finderMethodName, finderParams,
1632                    finderArgs, list);
1633
1634                return list;
1635            }
1636            catch (Exception e) {
1637                throw processException(e);
1638            }
1639            finally {
1640                closeSession(session);
1641            }
1642        }
1643        else {
1644            return (List<SocialActivity>)result;
1645        }
1646    }
1647
1648    public List<SocialActivity> findByC_C(long classNameId, long classPK,
1649        int start, int end) throws SystemException {
1650        return findByC_C(classNameId, classPK, start, end, null);
1651    }
1652
1653    public List<SocialActivity> findByC_C(long classNameId, long classPK,
1654        int start, int end, OrderByComparator obc) throws SystemException {
1655        boolean finderClassNameCacheEnabled = SocialActivityModelImpl.CACHE_ENABLED;
1656        String finderClassName = SocialActivity.class.getName();
1657        String finderMethodName = "findByC_C";
1658        String[] finderParams = new String[] {
1659                Long.class.getName(), Long.class.getName(),
1660                
1661                "java.lang.Integer", "java.lang.Integer",
1662                "com.liferay.portal.kernel.util.OrderByComparator"
1663            };
1664        Object[] finderArgs = new Object[] {
1665                new Long(classNameId), new Long(classPK),
1666                
1667                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1668            };
1669
1670        Object result = null;
1671
1672        if (finderClassNameCacheEnabled) {
1673            result = FinderCacheUtil.getResult(finderClassName,
1674                    finderMethodName, finderParams, finderArgs, this);
1675        }
1676
1677        if (result == null) {
1678            Session session = null;
1679
1680            try {
1681                session = openSession();
1682
1683                StringBuilder query = new StringBuilder();
1684
1685                query.append(
1686                    "FROM com.liferay.portlet.social.model.SocialActivity WHERE ");
1687
1688                query.append("classNameId = ?");
1689
1690                query.append(" AND ");
1691
1692                query.append("classPK = ?");
1693
1694                query.append(" ");
1695
1696                if (obc != null) {
1697                    query.append("ORDER BY ");
1698                    query.append(obc.getOrderBy());
1699                }
1700
1701                else {
1702                    query.append("ORDER BY ");
1703
1704                    query.append("createDate DESC");
1705                }
1706
1707                Query q = session.createQuery(query.toString());
1708
1709                QueryPos qPos = QueryPos.getInstance(q);
1710
1711                qPos.add(classNameId);
1712
1713                qPos.add(classPK);
1714
1715                List<SocialActivity> list = (List<SocialActivity>)QueryUtil.list(q,
1716                        getDialect(), start, end);
1717
1718                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1719                    finderClassName, finderMethodName, finderParams,
1720                    finderArgs, list);
1721
1722                return list;
1723            }
1724            catch (Exception e) {
1725                throw processException(e);
1726            }
1727            finally {
1728                closeSession(session);
1729            }
1730        }
1731        else {
1732            return (List<SocialActivity>)result;
1733        }
1734    }
1735
1736    public SocialActivity findByC_C_First(long classNameId, long classPK,
1737        OrderByComparator obc) throws NoSuchActivityException, SystemException {
1738        List<SocialActivity> list = findByC_C(classNameId, classPK, 0, 1, obc);
1739
1740        if (list.size() == 0) {
1741            StringBuilder msg = new StringBuilder();
1742
1743            msg.append("No SocialActivity exists with the key {");
1744
1745            msg.append("classNameId=" + classNameId);
1746
1747            msg.append(", ");
1748            msg.append("classPK=" + classPK);
1749
1750            msg.append(StringPool.CLOSE_CURLY_BRACE);
1751
1752            throw new NoSuchActivityException(msg.toString());
1753        }
1754        else {
1755            return list.get(0);
1756        }
1757    }
1758
1759    public SocialActivity findByC_C_Last(long classNameId, long classPK,
1760        OrderByComparator obc) throws NoSuchActivityException, SystemException {
1761        int count = countByC_C(classNameId, classPK);
1762
1763        List<SocialActivity> list = findByC_C(classNameId, classPK, count - 1,
1764                count, obc);
1765
1766        if (list.size() == 0) {
1767            StringBuilder msg = new StringBuilder();
1768
1769            msg.append("No SocialActivity exists with the key {");
1770
1771            msg.append("classNameId=" + classNameId);
1772
1773            msg.append(", ");
1774            msg.append("classPK=" + classPK);
1775
1776            msg.append(StringPool.CLOSE_CURLY_BRACE);
1777
1778            throw new NoSuchActivityException(msg.toString());
1779        }
1780        else {
1781            return list.get(0);
1782        }
1783    }
1784
1785    public SocialActivity[] findByC_C_PrevAndNext(long activityId,
1786        long classNameId, long classPK, OrderByComparator obc)
1787        throws NoSuchActivityException, SystemException {
1788        SocialActivity socialActivity = findByPrimaryKey(activityId);
1789
1790        int count = countByC_C(classNameId, classPK);
1791
1792        Session session = null;
1793
1794        try {
1795            session = openSession();
1796
1797            StringBuilder query = new StringBuilder();
1798
1799            query.append(
1800                "FROM com.liferay.portlet.social.model.SocialActivity WHERE ");
1801
1802            query.append("classNameId = ?");
1803
1804            query.append(" AND ");
1805
1806            query.append("classPK = ?");
1807
1808            query.append(" ");
1809
1810            if (obc != null) {
1811                query.append("ORDER BY ");
1812                query.append(obc.getOrderBy());
1813            }
1814
1815            else {
1816                query.append("ORDER BY ");
1817
1818                query.append("createDate DESC");
1819            }
1820
1821            Query q = session.createQuery(query.toString());
1822
1823            QueryPos qPos = QueryPos.getInstance(q);
1824
1825            qPos.add(classNameId);
1826
1827            qPos.add(classPK);
1828
1829            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1830                    socialActivity);
1831
1832            SocialActivity[] array = new SocialActivityImpl[3];
1833
1834            array[0] = (SocialActivity)objArray[0];
1835            array[1] = (SocialActivity)objArray[1];
1836            array[2] = (SocialActivity)objArray[2];
1837
1838            return array;
1839        }
1840        catch (Exception e) {
1841            throw processException(e);
1842        }
1843        finally {
1844            closeSession(session);
1845        }
1846    }
1847
1848    public List<SocialActivity> findByM_C_C(long mirrorActivityId,
1849        long classNameId, long classPK) throws SystemException {
1850        boolean finderClassNameCacheEnabled = SocialActivityModelImpl.CACHE_ENABLED;
1851        String finderClassName = SocialActivity.class.getName();
1852        String finderMethodName = "findByM_C_C";
1853        String[] finderParams = new String[] {
1854                Long.class.getName(), Long.class.getName(), Long.class.getName()
1855            };
1856        Object[] finderArgs = new Object[] {
1857                new Long(mirrorActivityId), new Long(classNameId),
1858                new Long(classPK)
1859            };
1860
1861        Object result = null;
1862
1863        if (finderClassNameCacheEnabled) {
1864            result = FinderCacheUtil.getResult(finderClassName,
1865                    finderMethodName, finderParams, finderArgs, this);
1866        }
1867
1868        if (result == null) {
1869            Session session = null;
1870
1871            try {
1872                session = openSession();
1873
1874                StringBuilder query = new StringBuilder();
1875
1876                query.append(
1877                    "FROM com.liferay.portlet.social.model.SocialActivity WHERE ");
1878
1879                query.append("mirrorActivityId = ?");
1880
1881                query.append(" AND ");
1882
1883                query.append("classNameId = ?");
1884
1885                query.append(" AND ");
1886
1887                query.append("classPK = ?");
1888
1889                query.append(" ");
1890
1891                query.append("ORDER BY ");
1892
1893                query.append("createDate DESC");
1894
1895                Query q = session.createQuery(query.toString());
1896
1897                QueryPos qPos = QueryPos.getInstance(q);
1898
1899                qPos.add(mirrorActivityId);
1900
1901                qPos.add(classNameId);
1902
1903                qPos.add(classPK);
1904
1905                List<SocialActivity> list = q.list();
1906
1907                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1908                    finderClassName, finderMethodName, finderParams,
1909                    finderArgs, list);
1910
1911                return list;
1912            }
1913            catch (Exception e) {
1914                throw processException(e);
1915            }
1916            finally {
1917                closeSession(session);
1918            }
1919        }
1920        else {
1921            return (List<SocialActivity>)result;
1922        }
1923    }
1924
1925    public List<SocialActivity> findByM_C_C(long mirrorActivityId,
1926        long classNameId, long classPK, int start, int end)
1927        throws SystemException {
1928        return findByM_C_C(mirrorActivityId, classNameId, classPK, start, end,
1929            null);
1930    }
1931
1932    public List<SocialActivity> findByM_C_C(long mirrorActivityId,
1933        long classNameId, long classPK, int start, int end,
1934        OrderByComparator obc) throws SystemException {
1935        boolean finderClassNameCacheEnabled = SocialActivityModelImpl.CACHE_ENABLED;
1936        String finderClassName = SocialActivity.class.getName();
1937        String finderMethodName = "findByM_C_C";
1938        String[] finderParams = new String[] {
1939                Long.class.getName(), Long.class.getName(), Long.class.getName(),
1940                
1941                "java.lang.Integer", "java.lang.Integer",
1942                "com.liferay.portal.kernel.util.OrderByComparator"
1943            };
1944        Object[] finderArgs = new Object[] {
1945                new Long(mirrorActivityId), new Long(classNameId),
1946                new Long(classPK),
1947                
1948                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1949            };
1950
1951        Object result = null;
1952
1953        if (finderClassNameCacheEnabled) {
1954            result = FinderCacheUtil.getResult(finderClassName,
1955                    finderMethodName, finderParams, finderArgs, this);
1956        }
1957
1958        if (result == null) {
1959            Session session = null;
1960
1961            try {
1962                session = openSession();
1963
1964                StringBuilder query = new StringBuilder();
1965
1966                query.append(
1967                    "FROM com.liferay.portlet.social.model.SocialActivity WHERE ");
1968
1969                query.append("mirrorActivityId = ?");
1970
1971                query.append(" AND ");
1972
1973                query.append("classNameId = ?");
1974
1975                query.append(" AND ");
1976
1977                query.append("classPK = ?");
1978
1979                query.append(" ");
1980
1981                if (obc != null) {
1982                    query.append("ORDER BY ");
1983                    query.append(obc.getOrderBy());
1984                }
1985
1986                else {
1987                    query.append("ORDER BY ");
1988
1989                    query.append("createDate DESC");
1990                }
1991
1992                Query q = session.createQuery(query.toString());
1993
1994                QueryPos qPos = QueryPos.getInstance(q);
1995
1996                qPos.add(mirrorActivityId);
1997
1998                qPos.add(classNameId);
1999
2000                qPos.add(classPK);
2001
2002                List<SocialActivity> list = (List<SocialActivity>)QueryUtil.list(q,
2003                        getDialect(), start, end);
2004
2005                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2006                    finderClassName, finderMethodName, finderParams,
2007                    finderArgs, list);
2008
2009                return list;
2010            }
2011            catch (Exception e) {
2012                throw processException(e);
2013            }
2014            finally {
2015                closeSession(session);
2016            }
2017        }
2018        else {
2019            return (List<SocialActivity>)result;
2020        }
2021    }
2022
2023    public SocialActivity findByM_C_C_First(long mirrorActivityId,
2024        long classNameId, long classPK, OrderByComparator obc)
2025        throws NoSuchActivityException, SystemException {
2026        List<SocialActivity> list = findByM_C_C(mirrorActivityId, classNameId,
2027                classPK, 0, 1, obc);
2028
2029        if (list.size() == 0) {
2030            StringBuilder msg = new StringBuilder();
2031
2032            msg.append("No SocialActivity exists with the key {");
2033
2034            msg.append("mirrorActivityId=" + mirrorActivityId);
2035
2036            msg.append(", ");
2037            msg.append("classNameId=" + classNameId);
2038
2039            msg.append(", ");
2040            msg.append("classPK=" + classPK);
2041
2042            msg.append(StringPool.CLOSE_CURLY_BRACE);
2043
2044            throw new NoSuchActivityException(msg.toString());
2045        }
2046        else {
2047            return list.get(0);
2048        }
2049    }
2050
2051    public SocialActivity findByM_C_C_Last(long mirrorActivityId,
2052        long classNameId, long classPK, OrderByComparator obc)
2053        throws NoSuchActivityException, SystemException {
2054        int count = countByM_C_C(mirrorActivityId, classNameId, classPK);
2055
2056        List<SocialActivity> list = findByM_C_C(mirrorActivityId, classNameId,
2057                classPK, count - 1, count, obc);
2058
2059        if (list.size() == 0) {
2060            StringBuilder msg = new StringBuilder();
2061
2062            msg.append("No SocialActivity exists with the key {");
2063
2064            msg.append("mirrorActivityId=" + mirrorActivityId);
2065
2066            msg.append(", ");
2067            msg.append("classNameId=" + classNameId);
2068
2069            msg.append(", ");
2070            msg.append("classPK=" + classPK);
2071
2072            msg.append(StringPool.CLOSE_CURLY_BRACE);
2073
2074            throw new NoSuchActivityException(msg.toString());
2075        }
2076        else {
2077            return list.get(0);
2078        }
2079    }
2080
2081    public SocialActivity[] findByM_C_C_PrevAndNext(long activityId,
2082        long mirrorActivityId, long classNameId, long classPK,
2083        OrderByComparator obc) throws NoSuchActivityException, SystemException {
2084        SocialActivity socialActivity = findByPrimaryKey(activityId);
2085
2086        int count = countByM_C_C(mirrorActivityId, classNameId, classPK);
2087
2088        Session session = null;
2089
2090        try {
2091            session = openSession();
2092
2093            StringBuilder query = new StringBuilder();
2094
2095            query.append(
2096                "FROM com.liferay.portlet.social.model.SocialActivity WHERE ");
2097
2098            query.append("mirrorActivityId = ?");
2099
2100            query.append(" AND ");
2101
2102            query.append("classNameId = ?");
2103
2104            query.append(" AND ");
2105
2106            query.append("classPK = ?");
2107
2108            query.append(" ");
2109
2110            if (obc != null) {
2111                query.append("ORDER BY ");
2112                query.append(obc.getOrderBy());
2113            }
2114
2115            else {
2116                query.append("ORDER BY ");
2117
2118                query.append("createDate DESC");
2119            }
2120
2121            Query q = session.createQuery(query.toString());
2122
2123            QueryPos qPos = QueryPos.getInstance(q);
2124
2125            qPos.add(mirrorActivityId);
2126
2127            qPos.add(classNameId);
2128
2129            qPos.add(classPK);
2130
2131            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
2132                    socialActivity);
2133
2134            SocialActivity[] array = new SocialActivityImpl[3];
2135
2136            array[0] = (SocialActivity)objArray[0];
2137            array[1] = (SocialActivity)objArray[1];
2138            array[2] = (SocialActivity)objArray[2];
2139
2140            return array;
2141        }
2142        catch (Exception e) {
2143            throw processException(e);
2144        }
2145        finally {
2146            closeSession(session);
2147        }
2148    }
2149
2150    public SocialActivity findByG_U_CD_C_C_T_R(long groupId, long userId,
2151        Date createDate, long classNameId, long classPK, int type,
2152        long receiverUserId) throws NoSuchActivityException, SystemException {
2153        SocialActivity socialActivity = fetchByG_U_CD_C_C_T_R(groupId, userId,
2154                createDate, classNameId, classPK, type, receiverUserId);
2155
2156        if (socialActivity == null) {
2157            StringBuilder msg = new StringBuilder();
2158
2159            msg.append("No SocialActivity exists with the key {");
2160
2161            msg.append("groupId=" + groupId);
2162
2163            msg.append(", ");
2164            msg.append("userId=" + userId);
2165
2166            msg.append(", ");
2167            msg.append("createDate=" + createDate);
2168
2169            msg.append(", ");
2170            msg.append("classNameId=" + classNameId);
2171
2172            msg.append(", ");
2173            msg.append("classPK=" + classPK);
2174
2175            msg.append(", ");
2176            msg.append("type=" + type);
2177
2178            msg.append(", ");
2179            msg.append("receiverUserId=" + receiverUserId);
2180
2181            msg.append(StringPool.CLOSE_CURLY_BRACE);
2182
2183            if (_log.isWarnEnabled()) {
2184                _log.warn(msg.toString());
2185            }
2186
2187            throw new NoSuchActivityException(msg.toString());
2188        }
2189
2190        return socialActivity;
2191    }
2192
2193    public SocialActivity fetchByG_U_CD_C_C_T_R(long groupId, long userId,
2194        Date createDate, long classNameId, long classPK, int type,
2195        long receiverUserId) throws SystemException {
2196        boolean finderClassNameCacheEnabled = SocialActivityModelImpl.CACHE_ENABLED;
2197        String finderClassName = SocialActivity.class.getName();
2198        String finderMethodName = "fetchByG_U_CD_C_C_T_R";
2199        String[] finderParams = new String[] {
2200                Long.class.getName(), Long.class.getName(), Date.class.getName(),
2201                Long.class.getName(), Long.class.getName(),
2202                Integer.class.getName(), Long.class.getName()
2203            };
2204        Object[] finderArgs = new Object[] {
2205                new Long(groupId), new Long(userId),
2206                
2207                createDate, new Long(classNameId), new Long(classPK),
2208                new Integer(type), new Long(receiverUserId)
2209            };
2210
2211        Object result = null;
2212
2213        if (finderClassNameCacheEnabled) {
2214            result = FinderCacheUtil.getResult(finderClassName,
2215                    finderMethodName, finderParams, finderArgs, this);
2216        }
2217
2218        if (result == null) {
2219            Session session = null;
2220
2221            try {
2222                session = openSession();
2223
2224                StringBuilder query = new StringBuilder();
2225
2226                query.append(
2227                    "FROM com.liferay.portlet.social.model.SocialActivity WHERE ");
2228
2229                query.append("groupId = ?");
2230
2231                query.append(" AND ");
2232
2233                query.append("userId = ?");
2234
2235                query.append(" AND ");
2236
2237                if (createDate == null) {
2238                    query.append("createDate IS NULL");
2239                }
2240                else {
2241                    query.append("createDate = ?");
2242                }
2243
2244                query.append(" AND ");
2245
2246                query.append("classNameId = ?");
2247
2248                query.append(" AND ");
2249
2250                query.append("classPK = ?");
2251
2252                query.append(" AND ");
2253
2254                query.append("type_ = ?");
2255
2256                query.append(" AND ");
2257
2258                query.append("receiverUserId = ?");
2259
2260                query.append(" ");
2261
2262                query.append("ORDER BY ");
2263
2264                query.append("createDate DESC");
2265
2266                Query q = session.createQuery(query.toString());
2267
2268                QueryPos qPos = QueryPos.getInstance(q);
2269
2270                qPos.add(groupId);
2271
2272                qPos.add(userId);
2273
2274                if (createDate != null) {
2275                    qPos.add(CalendarUtil.getTimestamp(createDate));
2276                }
2277
2278                qPos.add(classNameId);
2279
2280                qPos.add(classPK);
2281
2282                qPos.add(type);
2283
2284                qPos.add(receiverUserId);
2285
2286                List<SocialActivity> list = q.list();
2287
2288                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2289                    finderClassName, finderMethodName, finderParams,
2290                    finderArgs, list);
2291
2292                if (list.size() == 0) {
2293                    return null;
2294                }
2295                else {
2296                    return list.get(0);
2297                }
2298            }
2299            catch (Exception e) {
2300                throw processException(e);
2301            }
2302            finally {
2303                closeSession(session);
2304            }
2305        }
2306        else {
2307            List<SocialActivity> list = (List<SocialActivity>)result;
2308
2309            if (list.size() == 0) {
2310                return null;
2311            }
2312            else {
2313                return list.get(0);
2314            }
2315        }
2316    }
2317
2318    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
2319        throws SystemException {
2320        Session session = null;
2321
2322        try {
2323            session = openSession();
2324
2325            dynamicQuery.compile(session);
2326
2327            return dynamicQuery.list();
2328        }
2329        catch (Exception e) {
2330            throw processException(e);
2331        }
2332        finally {
2333            closeSession(session);
2334        }
2335    }
2336
2337    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
2338        int start, int end) throws SystemException {
2339        Session session = null;
2340
2341        try {
2342            session = openSession();
2343
2344            dynamicQuery.setLimit(start, end);
2345
2346            dynamicQuery.compile(session);
2347
2348            return dynamicQuery.list();
2349        }
2350        catch (Exception e) {
2351            throw processException(e);
2352        }
2353        finally {
2354            closeSession(session);
2355        }
2356    }
2357
2358    public List<SocialActivity> findAll() throws SystemException {
2359        return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2360    }
2361
2362    public List<SocialActivity> findAll(int start, int end)
2363        throws SystemException {
2364        return findAll(start, end, null);
2365    }
2366
2367    public List<SocialActivity> findAll(int start, int end,
2368        OrderByComparator obc) throws SystemException {
2369        boolean finderClassNameCacheEnabled = SocialActivityModelImpl.CACHE_ENABLED;
2370        String finderClassName = SocialActivity.class.getName();
2371        String finderMethodName = "findAll";
2372        String[] finderParams = new String[] {
2373                "java.lang.Integer", "java.lang.Integer",
2374                "com.liferay.portal.kernel.util.OrderByComparator"
2375            };
2376        Object[] finderArgs = new Object[] {
2377                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
2378            };
2379
2380        Object result = null;
2381
2382        if (finderClassNameCacheEnabled) {
2383            result = FinderCacheUtil.getResult(finderClassName,
2384                    finderMethodName, finderParams, finderArgs, this);
2385        }
2386
2387        if (result == null) {
2388            Session session = null;
2389
2390            try {
2391                session = openSession();
2392
2393                StringBuilder query = new StringBuilder();
2394
2395                query.append(
2396                    "FROM com.liferay.portlet.social.model.SocialActivity ");
2397
2398                if (obc != null) {
2399                    query.append("ORDER BY ");
2400                    query.append(obc.getOrderBy());
2401                }
2402
2403                else {
2404                    query.append("ORDER BY ");
2405
2406                    query.append("createDate DESC");
2407                }
2408
2409                Query q = session.createQuery(query.toString());
2410
2411                List<SocialActivity> list = null;
2412
2413                if (obc == null) {
2414                    list = (List<SocialActivity>)QueryUtil.list(q,
2415                            getDialect(), start, end, false);
2416
2417                    Collections.sort(list);
2418                }
2419                else {
2420                    list = (List<SocialActivity>)QueryUtil.list(q,
2421                            getDialect(), start, end);
2422                }
2423
2424                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2425                    finderClassName, finderMethodName, finderParams,
2426                    finderArgs, list);
2427
2428                return list;
2429            }
2430            catch (Exception e) {
2431                throw processException(e);
2432            }
2433            finally {
2434                closeSession(session);
2435            }
2436        }
2437        else {
2438            return (List<SocialActivity>)result;
2439        }
2440    }
2441
2442    public void removeByGroupId(long groupId) throws SystemException {
2443        for (SocialActivity socialActivity : findByGroupId(groupId)) {
2444            remove(socialActivity);
2445        }
2446    }
2447
2448    public void removeByCompanyId(long companyId) throws SystemException {
2449        for (SocialActivity socialActivity : findByCompanyId(companyId)) {
2450            remove(socialActivity);
2451        }
2452    }
2453
2454    public void removeByUserId(long userId) throws SystemException {
2455        for (SocialActivity socialActivity : findByUserId(userId)) {
2456            remove(socialActivity);
2457        }
2458    }
2459
2460    public void removeByMirrorActivityId(long mirrorActivityId)
2461        throws NoSuchActivityException, SystemException {
2462        SocialActivity socialActivity = findByMirrorActivityId(mirrorActivityId);
2463
2464        remove(socialActivity);
2465    }
2466
2467    public void removeByClassNameId(long classNameId) throws SystemException {
2468        for (SocialActivity socialActivity : findByClassNameId(classNameId)) {
2469            remove(socialActivity);
2470        }
2471    }
2472
2473    public void removeByReceiverUserId(long receiverUserId)
2474        throws SystemException {
2475        for (SocialActivity socialActivity : findByReceiverUserId(
2476                receiverUserId)) {
2477            remove(socialActivity);
2478        }
2479    }
2480
2481    public void removeByC_C(long classNameId, long classPK)
2482        throws SystemException {
2483        for (SocialActivity socialActivity : findByC_C(classNameId, classPK)) {
2484            remove(socialActivity);
2485        }
2486    }
2487
2488    public void removeByM_C_C(long mirrorActivityId, long classNameId,
2489        long classPK) throws SystemException {
2490        for (SocialActivity socialActivity : findByM_C_C(mirrorActivityId,
2491                classNameId, classPK)) {
2492            remove(socialActivity);
2493        }
2494    }
2495
2496    public void removeByG_U_CD_C_C_T_R(long groupId, long userId,
2497        Date createDate, long classNameId, long classPK, int type,
2498        long receiverUserId) throws NoSuchActivityException, SystemException {
2499        SocialActivity socialActivity = findByG_U_CD_C_C_T_R(groupId, userId,
2500                createDate, classNameId, classPK, type, receiverUserId);
2501
2502        remove(socialActivity);
2503    }
2504
2505    public void removeAll() throws SystemException {
2506        for (SocialActivity socialActivity : findAll()) {
2507            remove(socialActivity);
2508        }
2509    }
2510
2511    public int countByGroupId(long groupId) throws SystemException {
2512        boolean finderClassNameCacheEnabled = SocialActivityModelImpl.CACHE_ENABLED;
2513        String finderClassName = SocialActivity.class.getName();
2514        String finderMethodName = "countByGroupId";
2515        String[] finderParams = new String[] { Long.class.getName() };
2516        Object[] finderArgs = new Object[] { new Long(groupId) };
2517
2518        Object result = null;
2519
2520        if (finderClassNameCacheEnabled) {
2521            result = FinderCacheUtil.getResult(finderClassName,
2522                    finderMethodName, finderParams, finderArgs, this);
2523        }
2524
2525        if (result == null) {
2526            Session session = null;
2527
2528            try {
2529                session = openSession();
2530
2531                StringBuilder query = new StringBuilder();
2532
2533                query.append("SELECT COUNT(*) ");
2534                query.append(
2535                    "FROM com.liferay.portlet.social.model.SocialActivity WHERE ");
2536
2537                query.append("groupId = ?");
2538
2539                query.append(" ");
2540
2541                Query q = session.createQuery(query.toString());
2542
2543                QueryPos qPos = QueryPos.getInstance(q);
2544
2545                qPos.add(groupId);
2546
2547                Long count = null;
2548
2549                Iterator<Long> itr = q.list().iterator();
2550
2551                if (itr.hasNext()) {
2552                    count = itr.next();
2553                }
2554
2555                if (count == null) {
2556                    count = new Long(0);
2557                }
2558
2559                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2560                    finderClassName, finderMethodName, finderParams,
2561                    finderArgs, count);
2562
2563                return count.intValue();
2564            }
2565            catch (Exception e) {
2566                throw processException(e);
2567            }
2568            finally {
2569                closeSession(session);
2570            }
2571        }
2572        else {
2573            return ((Long)result).intValue();
2574        }
2575    }
2576
2577    public int countByCompanyId(long companyId) throws SystemException {
2578        boolean finderClassNameCacheEnabled = SocialActivityModelImpl.CACHE_ENABLED;
2579        String finderClassName = SocialActivity.class.getName();
2580        String finderMethodName = "countByCompanyId";
2581        String[] finderParams = new String[] { Long.class.getName() };
2582        Object[] finderArgs = new Object[] { new Long(companyId) };
2583
2584        Object result = null;
2585
2586        if (finderClassNameCacheEnabled) {
2587            result = FinderCacheUtil.getResult(finderClassName,
2588                    finderMethodName, finderParams, finderArgs, this);
2589        }
2590
2591        if (result == null) {
2592            Session session = null;
2593
2594            try {
2595                session = openSession();
2596
2597                StringBuilder query = new StringBuilder();
2598
2599                query.append("SELECT COUNT(*) ");
2600                query.append(
2601                    "FROM com.liferay.portlet.social.model.SocialActivity WHERE ");
2602
2603                query.append("companyId = ?");
2604
2605                query.append(" ");
2606
2607                Query q = session.createQuery(query.toString());
2608
2609                QueryPos qPos = QueryPos.getInstance(q);
2610
2611                qPos.add(companyId);
2612
2613                Long count = null;
2614
2615                Iterator<Long> itr = q.list().iterator();
2616
2617                if (itr.hasNext()) {
2618                    count = itr.next();
2619                }
2620
2621                if (count == null) {
2622                    count = new Long(0);
2623                }
2624
2625                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2626                    finderClassName, finderMethodName, finderParams,
2627                    finderArgs, count);
2628
2629                return count.intValue();
2630            }
2631            catch (Exception e) {
2632                throw processException(e);
2633            }
2634            finally {
2635                closeSession(session);
2636            }
2637        }
2638        else {
2639            return ((Long)result).intValue();
2640        }
2641    }
2642
2643    public int countByUserId(long userId) throws SystemException {
2644        boolean finderClassNameCacheEnabled = SocialActivityModelImpl.CACHE_ENABLED;
2645        String finderClassName = SocialActivity.class.getName();
2646        String finderMethodName = "countByUserId";
2647        String[] finderParams = new String[] { Long.class.getName() };
2648        Object[] finderArgs = new Object[] { new Long(userId) };
2649
2650        Object result = null;
2651
2652        if (finderClassNameCacheEnabled) {
2653            result = FinderCacheUtil.getResult(finderClassName,
2654                    finderMethodName, finderParams, finderArgs, this);
2655        }
2656
2657        if (result == null) {
2658            Session session = null;
2659
2660            try {
2661                session = openSession();
2662
2663                StringBuilder query = new StringBuilder();
2664
2665                query.append("SELECT COUNT(*) ");
2666                query.append(
2667                    "FROM com.liferay.portlet.social.model.SocialActivity WHERE ");
2668
2669                query.append("userId = ?");
2670
2671                query.append(" ");
2672
2673                Query q = session.createQuery(query.toString());
2674
2675                QueryPos qPos = QueryPos.getInstance(q);
2676
2677                qPos.add(userId);
2678
2679                Long count = null;
2680
2681                Iterator<Long> itr = q.list().iterator();
2682
2683                if (itr.hasNext()) {
2684                    count = itr.next();
2685                }
2686
2687                if (count == null) {
2688                    count = new Long(0);
2689                }
2690
2691                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2692                    finderClassName, finderMethodName, finderParams,
2693                    finderArgs, count);
2694
2695                return count.intValue();
2696            }
2697            catch (Exception e) {
2698                throw processException(e);
2699            }
2700            finally {
2701                closeSession(session);
2702            }
2703        }
2704        else {
2705            return ((Long)result).intValue();
2706        }
2707    }
2708
2709    public int countByMirrorActivityId(long mirrorActivityId)
2710        throws SystemException {
2711        boolean finderClassNameCacheEnabled = SocialActivityModelImpl.CACHE_ENABLED;
2712        String finderClassName = SocialActivity.class.getName();
2713        String finderMethodName = "countByMirrorActivityId";
2714        String[] finderParams = new String[] { Long.class.getName() };
2715        Object[] finderArgs = new Object[] { new Long(mirrorActivityId) };
2716
2717        Object result = null;
2718
2719        if (finderClassNameCacheEnabled) {
2720            result = FinderCacheUtil.getResult(finderClassName,
2721                    finderMethodName, finderParams, finderArgs, this);
2722        }
2723
2724        if (result == null) {
2725            Session session = null;
2726
2727            try {
2728                session = openSession();
2729
2730                StringBuilder query = new StringBuilder();
2731
2732                query.append("SELECT COUNT(*) ");
2733                query.append(
2734                    "FROM com.liferay.portlet.social.model.SocialActivity WHERE ");
2735
2736                query.append("mirrorActivityId = ?");
2737
2738                query.append(" ");
2739
2740                Query q = session.createQuery(query.toString());
2741
2742                QueryPos qPos = QueryPos.getInstance(q);
2743
2744                qPos.add(mirrorActivityId);
2745
2746                Long count = null;
2747
2748                Iterator<Long> itr = q.list().iterator();
2749
2750                if (itr.hasNext()) {
2751                    count = itr.next();
2752                }
2753
2754                if (count == null) {
2755                    count = new Long(0);
2756                }
2757
2758                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2759                    finderClassName, finderMethodName, finderParams,
2760                    finderArgs, count);
2761
2762                return count.intValue();
2763            }
2764            catch (Exception e) {
2765                throw processException(e);
2766            }
2767            finally {
2768                closeSession(session);
2769            }
2770        }
2771        else {
2772            return ((Long)result).intValue();
2773        }
2774    }
2775
2776    public int countByClassNameId(long classNameId) throws SystemException {
2777        boolean finderClassNameCacheEnabled = SocialActivityModelImpl.CACHE_ENABLED;
2778        String finderClassName = SocialActivity.class.getName();
2779        String finderMethodName = "countByClassNameId";
2780        String[] finderParams = new String[] { Long.class.getName() };
2781        Object[] finderArgs = new Object[] { new Long(classNameId) };
2782
2783        Object result = null;
2784
2785        if (finderClassNameCacheEnabled) {
2786            result = FinderCacheUtil.getResult(finderClassName,
2787                    finderMethodName, finderParams, finderArgs, this);
2788        }
2789
2790        if (result == null) {
2791            Session session = null;
2792
2793            try {
2794                session = openSession();
2795
2796                StringBuilder query = new StringBuilder();
2797
2798                query.append("SELECT COUNT(*) ");
2799                query.append(
2800                    "FROM com.liferay.portlet.social.model.SocialActivity WHERE ");
2801
2802                query.append("classNameId = ?");
2803
2804                query.append(" ");
2805
2806                Query q = session.createQuery(query.toString());
2807
2808                QueryPos qPos = QueryPos.getInstance(q);
2809
2810                qPos.add(classNameId);
2811
2812                Long count = null;
2813
2814                Iterator<Long> itr = q.list().iterator();
2815
2816                if (itr.hasNext()) {
2817                    count = itr.next();
2818                }
2819
2820                if (count == null) {
2821                    count = new Long(0);
2822                }
2823
2824                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2825                    finderClassName, finderMethodName, finderParams,
2826                    finderArgs, count);
2827
2828                return count.intValue();
2829            }
2830            catch (Exception e) {
2831                throw processException(e);
2832            }
2833            finally {
2834                closeSession(session);
2835            }
2836        }
2837        else {
2838            return ((Long)result).intValue();
2839        }
2840    }
2841
2842    public int countByReceiverUserId(long receiverUserId)
2843        throws SystemException {
2844        boolean finderClassNameCacheEnabled = SocialActivityModelImpl.CACHE_ENABLED;
2845        String finderClassName = SocialActivity.class.getName();
2846        String finderMethodName = "countByReceiverUserId";
2847        String[] finderParams = new String[] { Long.class.getName() };
2848        Object[] finderArgs = new Object[] { new Long(receiverUserId) };
2849
2850        Object result = null;
2851
2852        if (finderClassNameCacheEnabled) {
2853            result = FinderCacheUtil.getResult(finderClassName,
2854                    finderMethodName, finderParams, finderArgs, this);
2855        }
2856
2857        if (result == null) {
2858            Session session = null;
2859
2860            try {
2861                session = openSession();
2862
2863                StringBuilder query = new StringBuilder();
2864
2865                query.append("SELECT COUNT(*) ");
2866                query.append(
2867                    "FROM com.liferay.portlet.social.model.SocialActivity WHERE ");
2868
2869                query.append("receiverUserId = ?");
2870
2871                query.append(" ");
2872
2873                Query q = session.createQuery(query.toString());
2874
2875                QueryPos qPos = QueryPos.getInstance(q);
2876
2877                qPos.add(receiverUserId);
2878
2879                Long count = null;
2880
2881                Iterator<Long> itr = q.list().iterator();
2882
2883                if (itr.hasNext()) {
2884                    count = itr.next();
2885                }
2886
2887                if (count == null) {
2888                    count = new Long(0);
2889                }
2890
2891                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2892                    finderClassName, finderMethodName, finderParams,
2893                    finderArgs, count);
2894
2895                return count.intValue();
2896            }
2897            catch (Exception e) {
2898                throw processException(e);
2899            }
2900            finally {
2901                closeSession(session);
2902            }
2903        }
2904        else {
2905            return ((Long)result).intValue();
2906        }
2907    }
2908
2909    public int countByC_C(long classNameId, long classPK)
2910        throws SystemException {
2911        boolean finderClassNameCacheEnabled = SocialActivityModelImpl.CACHE_ENABLED;
2912        String finderClassName = SocialActivity.class.getName();
2913        String finderMethodName = "countByC_C";
2914        String[] finderParams = new String[] {
2915                Long.class.getName(), Long.class.getName()
2916            };
2917        Object[] finderArgs = new Object[] {
2918                new Long(classNameId), new Long(classPK)
2919            };
2920
2921        Object result = null;
2922
2923        if (finderClassNameCacheEnabled) {
2924            result = FinderCacheUtil.getResult(finderClassName,
2925                    finderMethodName, finderParams, finderArgs, this);
2926        }
2927
2928        if (result == null) {
2929            Session session = null;
2930
2931            try {
2932                session = openSession();
2933
2934                StringBuilder query = new StringBuilder();
2935
2936                query.append("SELECT COUNT(*) ");
2937                query.append(
2938                    "FROM com.liferay.portlet.social.model.SocialActivity WHERE ");
2939
2940                query.append("classNameId = ?");
2941
2942                query.append(" AND ");
2943
2944                query.append("classPK = ?");
2945
2946                query.append(" ");
2947
2948                Query q = session.createQuery(query.toString());
2949
2950                QueryPos qPos = QueryPos.getInstance(q);
2951
2952                qPos.add(classNameId);
2953
2954                qPos.add(classPK);
2955
2956                Long count = null;
2957
2958                Iterator<Long> itr = q.list().iterator();
2959
2960                if (itr.hasNext()) {
2961                    count = itr.next();
2962                }
2963
2964                if (count == null) {
2965                    count = new Long(0);
2966                }
2967
2968                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2969                    finderClassName, finderMethodName, finderParams,
2970                    finderArgs, count);
2971
2972                return count.intValue();
2973            }
2974            catch (Exception e) {
2975                throw processException(e);
2976            }
2977            finally {
2978                closeSession(session);
2979            }
2980        }
2981        else {
2982            return ((Long)result).intValue();
2983        }
2984    }
2985
2986    public int countByM_C_C(long mirrorActivityId, long classNameId,
2987        long classPK) throws SystemException {
2988        boolean finderClassNameCacheEnabled = SocialActivityModelImpl.CACHE_ENABLED;
2989        String finderClassName = SocialActivity.class.getName();
2990        String finderMethodName = "countByM_C_C";
2991        String[] finderParams = new String[] {
2992                Long.class.getName(), Long.class.getName(), Long.class.getName()
2993            };
2994        Object[] finderArgs = new Object[] {
2995                new Long(mirrorActivityId), new Long(classNameId),
2996                new Long(classPK)
2997            };
2998
2999        Object result = null;
3000
3001        if (finderClassNameCacheEnabled) {
3002            result = FinderCacheUtil.getResult(finderClassName,
3003                    finderMethodName, finderParams, finderArgs, this);
3004        }
3005
3006        if (result == null) {
3007            Session session = null;
3008
3009            try {
3010                session = openSession();
3011
3012                StringBuilder query = new StringBuilder();
3013
3014                query.append("SELECT COUNT(*) ");
3015                query.append(
3016                    "FROM com.liferay.portlet.social.model.SocialActivity WHERE ");
3017
3018                query.append("mirrorActivityId = ?");
3019
3020                query.append(" AND ");
3021
3022                query.append("classNameId = ?");
3023
3024                query.append(" AND ");
3025
3026                query.append("classPK = ?");
3027
3028                query.append(" ");
3029
3030                Query q = session.createQuery(query.toString());
3031
3032                QueryPos qPos = QueryPos.getInstance(q);
3033
3034                qPos.add(mirrorActivityId);
3035
3036                qPos.add(classNameId);
3037
3038                qPos.add(classPK);
3039
3040                Long count = null;
3041
3042                Iterator<Long> itr = q.list().iterator();
3043
3044                if (itr.hasNext()) {
3045                    count = itr.next();
3046                }
3047
3048                if (count == null) {
3049                    count = new Long(0);
3050                }
3051
3052                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
3053                    finderClassName, finderMethodName, finderParams,
3054                    finderArgs, count);
3055
3056                return count.intValue();
3057            }
3058            catch (Exception e) {
3059                throw processException(e);
3060            }
3061            finally {
3062                closeSession(session);
3063            }
3064        }
3065        else {
3066            return ((Long)result).intValue();
3067        }
3068    }
3069
3070    public int countByG_U_CD_C_C_T_R(long groupId, long userId,
3071        Date createDate, long classNameId, long classPK, int type,
3072        long receiverUserId) throws SystemException {
3073        boolean finderClassNameCacheEnabled = SocialActivityModelImpl.CACHE_ENABLED;
3074        String finderClassName = SocialActivity.class.getName();
3075        String finderMethodName = "countByG_U_CD_C_C_T_R";
3076        String[] finderParams = new String[] {
3077                Long.class.getName(), Long.class.getName(), Date.class.getName(),
3078                Long.class.getName(), Long.class.getName(),
3079                Integer.class.getName(), Long.class.getName()
3080            };
3081        Object[] finderArgs = new Object[] {
3082                new Long(groupId), new Long(userId),
3083                
3084                createDate, new Long(classNameId), new Long(classPK),
3085                new Integer(type), new Long(receiverUserId)
3086            };
3087
3088        Object result = null;
3089
3090        if (finderClassNameCacheEnabled) {
3091            result = FinderCacheUtil.getResult(finderClassName,
3092                    finderMethodName, finderParams, finderArgs, this);
3093        }
3094
3095        if (result == null) {
3096            Session session = null;
3097
3098            try {
3099                session = openSession();
3100
3101                StringBuilder query = new StringBuilder();
3102
3103                query.append("SELECT COUNT(*) ");
3104                query.append(
3105                    "FROM com.liferay.portlet.social.model.SocialActivity WHERE ");
3106
3107                query.append("groupId = ?");
3108
3109                query.append(" AND ");
3110
3111                query.append("userId = ?");
3112
3113                query.append(" AND ");
3114
3115                if (createDate == null) {
3116                    query.append("createDate IS NULL");
3117                }
3118                else {
3119                    query.append("createDate = ?");
3120                }
3121
3122                query.append(" AND ");
3123
3124                query.append("classNameId = ?");
3125
3126                query.append(" AND ");
3127
3128                query.append("classPK = ?");
3129
3130                query.append(" AND ");
3131
3132                query.append("type_ = ?");
3133
3134                query.append(" AND ");
3135
3136                query.append("receiverUserId = ?");
3137
3138                query.append(" ");
3139
3140                Query q = session.createQuery(query.toString());
3141
3142                QueryPos qPos = QueryPos.getInstance(q);
3143
3144                qPos.add(groupId);
3145
3146                qPos.add(userId);
3147
3148                if (createDate != null) {
3149                    qPos.add(CalendarUtil.getTimestamp(createDate));
3150                }
3151
3152                qPos.add(classNameId);
3153
3154                qPos.add(classPK);
3155
3156                qPos.add(type);
3157
3158                qPos.add(receiverUserId);
3159
3160                Long count = null;
3161
3162                Iterator<Long> itr = q.list().iterator();
3163
3164                if (itr.hasNext()) {
3165                    count = itr.next();
3166                }
3167
3168                if (count == null) {
3169                    count = new Long(0);
3170                }
3171
3172                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
3173                    finderClassName, finderMethodName, finderParams,
3174                    finderArgs, count);
3175
3176                return count.intValue();
3177            }
3178            catch (Exception e) {
3179                throw processException(e);
3180            }
3181            finally {
3182                closeSession(session);
3183            }
3184        }
3185        else {
3186            return ((Long)result).intValue();
3187        }
3188    }
3189
3190    public int countAll() throws SystemException {
3191        boolean finderClassNameCacheEnabled = SocialActivityModelImpl.CACHE_ENABLED;
3192        String finderClassName = SocialActivity.class.getName();
3193        String finderMethodName = "countAll";
3194        String[] finderParams = new String[] {  };
3195        Object[] finderArgs = new Object[] {  };
3196
3197        Object result = null;
3198
3199        if (finderClassNameCacheEnabled) {
3200            result = FinderCacheUtil.getResult(finderClassName,
3201                    finderMethodName, finderParams, finderArgs, this);
3202        }
3203
3204        if (result == null) {
3205            Session session = null;
3206
3207            try {
3208                session = openSession();
3209
3210                Query q = session.createQuery(
3211                        "SELECT COUNT(*) FROM com.liferay.portlet.social.model.SocialActivity");
3212
3213                Long count = null;
3214
3215                Iterator<Long> itr = q.list().iterator();
3216
3217                if (itr.hasNext()) {
3218                    count = itr.next();
3219                }
3220
3221                if (count == null) {
3222                    count = new Long(0);
3223                }
3224
3225                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
3226                    finderClassName, finderMethodName, finderParams,
3227                    finderArgs, count);
3228
3229                return count.intValue();
3230            }
3231            catch (Exception e) {
3232                throw processException(e);
3233            }
3234            finally {
3235                closeSession(session);
3236            }
3237        }
3238        else {
3239            return ((Long)result).intValue();
3240        }
3241    }
3242
3243    public void registerListener(ModelListener listener) {
3244        List<ModelListener> listeners = ListUtil.fromArray(_listeners);
3245
3246        listeners.add(listener);
3247
3248        _listeners = listeners.toArray(new ModelListener[listeners.size()]);
3249    }
3250
3251    public void unregisterListener(ModelListener listener) {
3252        List<ModelListener> listeners = ListUtil.fromArray(_listeners);
3253
3254        listeners.remove(listener);
3255
3256        _listeners = listeners.toArray(new ModelListener[listeners.size()]);
3257    }
3258
3259    public void afterPropertiesSet() {
3260        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
3261                    com.liferay.portal.util.PropsUtil.get(
3262                        "value.object.listener.com.liferay.portlet.social.model.SocialActivity")));
3263
3264        if (listenerClassNames.length > 0) {
3265            try {
3266                List<ModelListener> listeners = new ArrayList<ModelListener>();
3267
3268                for (String listenerClassName : listenerClassNames) {
3269                    listeners.add((ModelListener)Class.forName(
3270                            listenerClassName).newInstance());
3271                }
3272
3273                _listeners = listeners.toArray(new ModelListener[listeners.size()]);
3274            }
3275            catch (Exception e) {
3276                _log.error(e);
3277            }
3278        }
3279    }
3280
3281    private static Log _log = LogFactory.getLog(SocialActivityPersistenceImpl.class);
3282    private ModelListener[] _listeners = new ModelListener[0];
3283}