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