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.GetterUtil;
36  import com.liferay.portal.kernel.util.OrderByComparator;
37  import com.liferay.portal.kernel.util.StringPool;
38  import com.liferay.portal.kernel.util.StringUtil;
39  import com.liferay.portal.kernel.util.Validator;
40  import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
41  import com.liferay.portal.model.ModelListener;
42  import com.liferay.portal.service.persistence.BatchSessionUtil;
43  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
44  
45  import com.liferay.portlet.social.NoSuchRequestException;
46  import com.liferay.portlet.social.model.SocialRequest;
47  import com.liferay.portlet.social.model.impl.SocialRequestImpl;
48  import com.liferay.portlet.social.model.impl.SocialRequestModelImpl;
49  
50  import java.util.ArrayList;
51  import java.util.Collections;
52  import java.util.List;
53  
54  /**
55   * <a href="SocialRequestPersistenceImpl.java.html"><b><i>View Source</i></b></a>
56   *
57   * @author Brian Wing Shun Chan
58   *
59   */
60  public class SocialRequestPersistenceImpl extends BasePersistenceImpl
61      implements SocialRequestPersistence {
62      public static final String FINDER_CLASS_NAME_ENTITY = SocialRequestImpl.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_UUID = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
66              SocialRequestModelImpl.FINDER_CACHE_ENABLED,
67              FINDER_CLASS_NAME_LIST, "findByUuid",
68              new String[] { String.class.getName() });
69      public static final FinderPath FINDER_PATH_FIND_BY_OBC_UUID = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
70              SocialRequestModelImpl.FINDER_CACHE_ENABLED,
71              FINDER_CLASS_NAME_LIST, "findByUuid",
72              new String[] {
73                  String.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_UUID = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
79              SocialRequestModelImpl.FINDER_CACHE_ENABLED,
80              FINDER_CLASS_NAME_LIST, "countByUuid",
81              new String[] { String.class.getName() });
82      public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
83              SocialRequestModelImpl.FINDER_CACHE_ENABLED,
84              FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
85              new String[] { String.class.getName(), Long.class.getName() });
86      public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
87              SocialRequestModelImpl.FINDER_CACHE_ENABLED,
88              FINDER_CLASS_NAME_LIST, "countByUUID_G",
89              new String[] { String.class.getName(), Long.class.getName() });
90      public static final FinderPath FINDER_PATH_FIND_BY_COMPANYID = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
91              SocialRequestModelImpl.FINDER_CACHE_ENABLED,
92              FINDER_CLASS_NAME_LIST, "findByCompanyId",
93              new String[] { Long.class.getName() });
94      public static final FinderPath FINDER_PATH_FIND_BY_OBC_COMPANYID = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
95              SocialRequestModelImpl.FINDER_CACHE_ENABLED,
96              FINDER_CLASS_NAME_LIST, "findByCompanyId",
97              new String[] {
98                  Long.class.getName(),
99                  
100             "java.lang.Integer", "java.lang.Integer",
101                 "com.liferay.portal.kernel.util.OrderByComparator"
102             });
103     public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
104             SocialRequestModelImpl.FINDER_CACHE_ENABLED,
105             FINDER_CLASS_NAME_LIST, "countByCompanyId",
106             new String[] { Long.class.getName() });
107     public static final FinderPath FINDER_PATH_FIND_BY_USERID = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
108             SocialRequestModelImpl.FINDER_CACHE_ENABLED,
109             FINDER_CLASS_NAME_LIST, "findByUserId",
110             new String[] { Long.class.getName() });
111     public static final FinderPath FINDER_PATH_FIND_BY_OBC_USERID = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
112             SocialRequestModelImpl.FINDER_CACHE_ENABLED,
113             FINDER_CLASS_NAME_LIST, "findByUserId",
114             new String[] {
115                 Long.class.getName(),
116                 
117             "java.lang.Integer", "java.lang.Integer",
118                 "com.liferay.portal.kernel.util.OrderByComparator"
119             });
120     public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
121             SocialRequestModelImpl.FINDER_CACHE_ENABLED,
122             FINDER_CLASS_NAME_LIST, "countByUserId",
123             new String[] { Long.class.getName() });
124     public static final FinderPath FINDER_PATH_FIND_BY_RECEIVERUSERID = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
125             SocialRequestModelImpl.FINDER_CACHE_ENABLED,
126             FINDER_CLASS_NAME_LIST, "findByReceiverUserId",
127             new String[] { Long.class.getName() });
128     public static final FinderPath FINDER_PATH_FIND_BY_OBC_RECEIVERUSERID = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
129             SocialRequestModelImpl.FINDER_CACHE_ENABLED,
130             FINDER_CLASS_NAME_LIST, "findByReceiverUserId",
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_RECEIVERUSERID = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
138             SocialRequestModelImpl.FINDER_CACHE_ENABLED,
139             FINDER_CLASS_NAME_LIST, "countByReceiverUserId",
140             new String[] { Long.class.getName() });
141     public static final FinderPath FINDER_PATH_FIND_BY_U_S = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
142             SocialRequestModelImpl.FINDER_CACHE_ENABLED,
143             FINDER_CLASS_NAME_LIST, "findByU_S",
144             new String[] { Long.class.getName(), Integer.class.getName() });
145     public static final FinderPath FINDER_PATH_FIND_BY_OBC_U_S = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
146             SocialRequestModelImpl.FINDER_CACHE_ENABLED,
147             FINDER_CLASS_NAME_LIST, "findByU_S",
148             new String[] {
149                 Long.class.getName(), Integer.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_U_S = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
155             SocialRequestModelImpl.FINDER_CACHE_ENABLED,
156             FINDER_CLASS_NAME_LIST, "countByU_S",
157             new String[] { Long.class.getName(), Integer.class.getName() });
158     public static final FinderPath FINDER_PATH_FIND_BY_R_S = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
159             SocialRequestModelImpl.FINDER_CACHE_ENABLED,
160             FINDER_CLASS_NAME_LIST, "findByR_S",
161             new String[] { Long.class.getName(), Integer.class.getName() });
162     public static final FinderPath FINDER_PATH_FIND_BY_OBC_R_S = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
163             SocialRequestModelImpl.FINDER_CACHE_ENABLED,
164             FINDER_CLASS_NAME_LIST, "findByR_S",
165             new String[] {
166                 Long.class.getName(), Integer.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_R_S = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
172             SocialRequestModelImpl.FINDER_CACHE_ENABLED,
173             FINDER_CLASS_NAME_LIST, "countByR_S",
174             new String[] { Long.class.getName(), Integer.class.getName() });
175     public static final FinderPath FINDER_PATH_FETCH_BY_U_C_C_T_R = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
176             SocialRequestModelImpl.FINDER_CACHE_ENABLED,
177             FINDER_CLASS_NAME_ENTITY, "fetchByU_C_C_T_R",
178             new String[] {
179                 Long.class.getName(), Long.class.getName(), Long.class.getName(),
180                 Integer.class.getName(), Long.class.getName()
181             });
182     public static final FinderPath FINDER_PATH_COUNT_BY_U_C_C_T_R = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
183             SocialRequestModelImpl.FINDER_CACHE_ENABLED,
184             FINDER_CLASS_NAME_LIST, "countByU_C_C_T_R",
185             new String[] {
186                 Long.class.getName(), Long.class.getName(), Long.class.getName(),
187                 Integer.class.getName(), Long.class.getName()
188             });
189     public static final FinderPath FINDER_PATH_FIND_BY_U_C_C_T_S = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
190             SocialRequestModelImpl.FINDER_CACHE_ENABLED,
191             FINDER_CLASS_NAME_LIST, "findByU_C_C_T_S",
192             new String[] {
193                 Long.class.getName(), Long.class.getName(), Long.class.getName(),
194                 Integer.class.getName(), Integer.class.getName()
195             });
196     public static final FinderPath FINDER_PATH_FIND_BY_OBC_U_C_C_T_S = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
197             SocialRequestModelImpl.FINDER_CACHE_ENABLED,
198             FINDER_CLASS_NAME_LIST, "findByU_C_C_T_S",
199             new String[] {
200                 Long.class.getName(), Long.class.getName(), Long.class.getName(),
201                 Integer.class.getName(), Integer.class.getName(),
202                 
203             "java.lang.Integer", "java.lang.Integer",
204                 "com.liferay.portal.kernel.util.OrderByComparator"
205             });
206     public static final FinderPath FINDER_PATH_COUNT_BY_U_C_C_T_S = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
207             SocialRequestModelImpl.FINDER_CACHE_ENABLED,
208             FINDER_CLASS_NAME_LIST, "countByU_C_C_T_S",
209             new String[] {
210                 Long.class.getName(), Long.class.getName(), Long.class.getName(),
211                 Integer.class.getName(), Integer.class.getName()
212             });
213     public static final FinderPath FINDER_PATH_FIND_BY_C_C_T_R_S = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
214             SocialRequestModelImpl.FINDER_CACHE_ENABLED,
215             FINDER_CLASS_NAME_LIST, "findByC_C_T_R_S",
216             new String[] {
217                 Long.class.getName(), Long.class.getName(),
218                 Integer.class.getName(), Long.class.getName(),
219                 Integer.class.getName()
220             });
221     public static final FinderPath FINDER_PATH_FIND_BY_OBC_C_C_T_R_S = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
222             SocialRequestModelImpl.FINDER_CACHE_ENABLED,
223             FINDER_CLASS_NAME_LIST, "findByC_C_T_R_S",
224             new String[] {
225                 Long.class.getName(), Long.class.getName(),
226                 Integer.class.getName(), Long.class.getName(),
227                 Integer.class.getName(),
228                 
229             "java.lang.Integer", "java.lang.Integer",
230                 "com.liferay.portal.kernel.util.OrderByComparator"
231             });
232     public static final FinderPath FINDER_PATH_COUNT_BY_C_C_T_R_S = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
233             SocialRequestModelImpl.FINDER_CACHE_ENABLED,
234             FINDER_CLASS_NAME_LIST, "countByC_C_T_R_S",
235             new String[] {
236                 Long.class.getName(), Long.class.getName(),
237                 Integer.class.getName(), Long.class.getName(),
238                 Integer.class.getName()
239             });
240     public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
241             SocialRequestModelImpl.FINDER_CACHE_ENABLED,
242             FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
243     public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
244             SocialRequestModelImpl.FINDER_CACHE_ENABLED,
245             FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
246 
247     public void cacheResult(SocialRequest socialRequest) {
248         EntityCacheUtil.putResult(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
249             SocialRequestImpl.class, socialRequest.getPrimaryKey(),
250             socialRequest);
251 
252         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
253             new Object[] {
254                 socialRequest.getUuid(), new Long(socialRequest.getGroupId())
255             }, socialRequest);
256 
257         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C_T_R,
258             new Object[] {
259                 new Long(socialRequest.getUserId()),
260                 new Long(socialRequest.getClassNameId()),
261                 new Long(socialRequest.getClassPK()),
262                 new Integer(socialRequest.getType()),
263                 new Long(socialRequest.getReceiverUserId())
264             }, socialRequest);
265     }
266 
267     public void cacheResult(List<SocialRequest> socialRequests) {
268         for (SocialRequest socialRequest : socialRequests) {
269             if (EntityCacheUtil.getResult(
270                         SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
271                         SocialRequestImpl.class, socialRequest.getPrimaryKey(),
272                         this) == null) {
273                 cacheResult(socialRequest);
274             }
275         }
276     }
277 
278     public void clearCache() {
279         CacheRegistry.clear(SocialRequestImpl.class.getName());
280         EntityCacheUtil.clearCache(SocialRequestImpl.class.getName());
281         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
282         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
283     }
284 
285     public SocialRequest create(long requestId) {
286         SocialRequest socialRequest = new SocialRequestImpl();
287 
288         socialRequest.setNew(true);
289         socialRequest.setPrimaryKey(requestId);
290 
291         String uuid = PortalUUIDUtil.generate();
292 
293         socialRequest.setUuid(uuid);
294 
295         return socialRequest;
296     }
297 
298     public SocialRequest remove(long requestId)
299         throws NoSuchRequestException, SystemException {
300         Session session = null;
301 
302         try {
303             session = openSession();
304 
305             SocialRequest socialRequest = (SocialRequest)session.get(SocialRequestImpl.class,
306                     new Long(requestId));
307 
308             if (socialRequest == null) {
309                 if (_log.isWarnEnabled()) {
310                     _log.warn("No SocialRequest exists with the primary key " +
311                         requestId);
312                 }
313 
314                 throw new NoSuchRequestException(
315                     "No SocialRequest exists with the primary key " +
316                     requestId);
317             }
318 
319             return remove(socialRequest);
320         }
321         catch (NoSuchRequestException nsee) {
322             throw nsee;
323         }
324         catch (Exception e) {
325             throw processException(e);
326         }
327         finally {
328             closeSession(session);
329         }
330     }
331 
332     public SocialRequest remove(SocialRequest socialRequest)
333         throws SystemException {
334         for (ModelListener<SocialRequest> listener : listeners) {
335             listener.onBeforeRemove(socialRequest);
336         }
337 
338         socialRequest = removeImpl(socialRequest);
339 
340         for (ModelListener<SocialRequest> listener : listeners) {
341             listener.onAfterRemove(socialRequest);
342         }
343 
344         return socialRequest;
345     }
346 
347     protected SocialRequest removeImpl(SocialRequest socialRequest)
348         throws SystemException {
349         Session session = null;
350 
351         try {
352             session = openSession();
353 
354             if (socialRequest.isCachedModel() || BatchSessionUtil.isEnabled()) {
355                 Object staleObject = session.get(SocialRequestImpl.class,
356                         socialRequest.getPrimaryKeyObj());
357 
358                 if (staleObject != null) {
359                     session.evict(staleObject);
360                 }
361             }
362 
363             session.delete(socialRequest);
364 
365             session.flush();
366         }
367         catch (Exception e) {
368             throw processException(e);
369         }
370         finally {
371             closeSession(session);
372         }
373 
374         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
375 
376         SocialRequestModelImpl socialRequestModelImpl = (SocialRequestModelImpl)socialRequest;
377 
378         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
379             new Object[] {
380                 socialRequestModelImpl.getOriginalUuid(),
381                 new Long(socialRequestModelImpl.getOriginalGroupId())
382             });
383 
384         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_C_C_T_R,
385             new Object[] {
386                 new Long(socialRequestModelImpl.getOriginalUserId()),
387                 new Long(socialRequestModelImpl.getOriginalClassNameId()),
388                 new Long(socialRequestModelImpl.getOriginalClassPK()),
389                 new Integer(socialRequestModelImpl.getOriginalType()),
390                 new Long(socialRequestModelImpl.getOriginalReceiverUserId())
391             });
392 
393         EntityCacheUtil.removeResult(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
394             SocialRequestImpl.class, socialRequest.getPrimaryKey());
395 
396         return socialRequest;
397     }
398 
399     /**
400      * @deprecated Use <code>update(SocialRequest socialRequest, boolean merge)</code>.
401      */
402     public SocialRequest update(SocialRequest socialRequest)
403         throws SystemException {
404         if (_log.isWarnEnabled()) {
405             _log.warn(
406                 "Using the deprecated update(SocialRequest socialRequest) method. Use update(SocialRequest socialRequest, boolean merge) instead.");
407         }
408 
409         return update(socialRequest, false);
410     }
411 
412     /**
413      * Add, update, or merge, the entity. This method also calls the model
414      * listeners to trigger the proper events associated with adding, deleting,
415      * or updating an entity.
416      *
417      * @param        socialRequest the entity to add, update, or merge
418      * @param        merge boolean value for whether to merge the entity. The
419      *                default value is false. Setting merge to true is more
420      *                expensive and should only be true when socialRequest is
421      *                transient. See LEP-5473 for a detailed discussion of this
422      *                method.
423      * @return        true if the portlet can be displayed via Ajax
424      */
425     public SocialRequest update(SocialRequest socialRequest, boolean merge)
426         throws SystemException {
427         boolean isNew = socialRequest.isNew();
428 
429         for (ModelListener<SocialRequest> listener : listeners) {
430             if (isNew) {
431                 listener.onBeforeCreate(socialRequest);
432             }
433             else {
434                 listener.onBeforeUpdate(socialRequest);
435             }
436         }
437 
438         socialRequest = updateImpl(socialRequest, merge);
439 
440         for (ModelListener<SocialRequest> listener : listeners) {
441             if (isNew) {
442                 listener.onAfterCreate(socialRequest);
443             }
444             else {
445                 listener.onAfterUpdate(socialRequest);
446             }
447         }
448 
449         return socialRequest;
450     }
451 
452     public SocialRequest updateImpl(
453         com.liferay.portlet.social.model.SocialRequest socialRequest,
454         boolean merge) throws SystemException {
455         boolean isNew = socialRequest.isNew();
456 
457         SocialRequestModelImpl socialRequestModelImpl = (SocialRequestModelImpl)socialRequest;
458 
459         if (Validator.isNull(socialRequest.getUuid())) {
460             String uuid = PortalUUIDUtil.generate();
461 
462             socialRequest.setUuid(uuid);
463         }
464 
465         Session session = null;
466 
467         try {
468             session = openSession();
469 
470             BatchSessionUtil.update(session, socialRequest, merge);
471 
472             socialRequest.setNew(false);
473         }
474         catch (Exception e) {
475             throw processException(e);
476         }
477         finally {
478             closeSession(session);
479         }
480 
481         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
482 
483         EntityCacheUtil.putResult(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
484             SocialRequestImpl.class, socialRequest.getPrimaryKey(),
485             socialRequest);
486 
487         if (!isNew &&
488                 (!Validator.equals(socialRequest.getUuid(),
489                     socialRequestModelImpl.getOriginalUuid()) ||
490                 (socialRequest.getGroupId() != socialRequestModelImpl.getOriginalGroupId()))) {
491             FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
492                 new Object[] {
493                     socialRequestModelImpl.getOriginalUuid(),
494                     new Long(socialRequestModelImpl.getOriginalGroupId())
495                 });
496         }
497 
498         if (isNew ||
499                 (!Validator.equals(socialRequest.getUuid(),
500                     socialRequestModelImpl.getOriginalUuid()) ||
501                 (socialRequest.getGroupId() != socialRequestModelImpl.getOriginalGroupId()))) {
502             FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
503                 new Object[] {
504                     socialRequest.getUuid(),
505                     new Long(socialRequest.getGroupId())
506                 }, socialRequest);
507         }
508 
509         if (!isNew &&
510                 ((socialRequest.getUserId() != socialRequestModelImpl.getOriginalUserId()) ||
511                 (socialRequest.getClassNameId() != socialRequestModelImpl.getOriginalClassNameId()) ||
512                 (socialRequest.getClassPK() != socialRequestModelImpl.getOriginalClassPK()) ||
513                 (socialRequest.getType() != socialRequestModelImpl.getOriginalType()) ||
514                 (socialRequest.getReceiverUserId() != socialRequestModelImpl.getOriginalReceiverUserId()))) {
515             FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_C_C_T_R,
516                 new Object[] {
517                     new Long(socialRequestModelImpl.getOriginalUserId()),
518                     new Long(socialRequestModelImpl.getOriginalClassNameId()),
519                     new Long(socialRequestModelImpl.getOriginalClassPK()),
520                     new Integer(socialRequestModelImpl.getOriginalType()),
521                     new Long(socialRequestModelImpl.getOriginalReceiverUserId())
522                 });
523         }
524 
525         if (isNew ||
526                 ((socialRequest.getUserId() != socialRequestModelImpl.getOriginalUserId()) ||
527                 (socialRequest.getClassNameId() != socialRequestModelImpl.getOriginalClassNameId()) ||
528                 (socialRequest.getClassPK() != socialRequestModelImpl.getOriginalClassPK()) ||
529                 (socialRequest.getType() != socialRequestModelImpl.getOriginalType()) ||
530                 (socialRequest.getReceiverUserId() != socialRequestModelImpl.getOriginalReceiverUserId()))) {
531             FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C_T_R,
532                 new Object[] {
533                     new Long(socialRequest.getUserId()),
534                     new Long(socialRequest.getClassNameId()),
535                     new Long(socialRequest.getClassPK()),
536                     new Integer(socialRequest.getType()),
537                     new Long(socialRequest.getReceiverUserId())
538                 }, socialRequest);
539         }
540 
541         return socialRequest;
542     }
543 
544     public SocialRequest findByPrimaryKey(long requestId)
545         throws NoSuchRequestException, SystemException {
546         SocialRequest socialRequest = fetchByPrimaryKey(requestId);
547 
548         if (socialRequest == null) {
549             if (_log.isWarnEnabled()) {
550                 _log.warn("No SocialRequest exists with the primary key " +
551                     requestId);
552             }
553 
554             throw new NoSuchRequestException(
555                 "No SocialRequest exists with the primary key " + requestId);
556         }
557 
558         return socialRequest;
559     }
560 
561     public SocialRequest fetchByPrimaryKey(long requestId)
562         throws SystemException {
563         SocialRequest socialRequest = (SocialRequest)EntityCacheUtil.getResult(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
564                 SocialRequestImpl.class, requestId, this);
565 
566         if (socialRequest == null) {
567             Session session = null;
568 
569             try {
570                 session = openSession();
571 
572                 socialRequest = (SocialRequest)session.get(SocialRequestImpl.class,
573                         new Long(requestId));
574             }
575             catch (Exception e) {
576                 throw processException(e);
577             }
578             finally {
579                 if (socialRequest != null) {
580                     cacheResult(socialRequest);
581                 }
582 
583                 closeSession(session);
584             }
585         }
586 
587         return socialRequest;
588     }
589 
590     public List<SocialRequest> findByUuid(String uuid)
591         throws SystemException {
592         Object[] finderArgs = new Object[] { uuid };
593 
594         List<SocialRequest> list = (List<SocialRequest>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_UUID,
595                 finderArgs, this);
596 
597         if (list == null) {
598             Session session = null;
599 
600             try {
601                 session = openSession();
602 
603                 StringBuilder query = new StringBuilder();
604 
605                 query.append(
606                     "SELECT socialRequest FROM SocialRequest socialRequest WHERE ");
607 
608                 if (uuid == null) {
609                     query.append("socialRequest.uuid IS NULL");
610                 }
611                 else {
612                     query.append("socialRequest.uuid = ?");
613                 }
614 
615                 query.append(" ");
616 
617                 query.append("ORDER BY ");
618 
619                 query.append("socialRequest.requestId DESC");
620 
621                 Query q = session.createQuery(query.toString());
622 
623                 QueryPos qPos = QueryPos.getInstance(q);
624 
625                 if (uuid != null) {
626                     qPos.add(uuid);
627                 }
628 
629                 list = q.list();
630             }
631             catch (Exception e) {
632                 throw processException(e);
633             }
634             finally {
635                 if (list == null) {
636                     list = new ArrayList<SocialRequest>();
637                 }
638 
639                 cacheResult(list);
640 
641                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_UUID, finderArgs,
642                     list);
643 
644                 closeSession(session);
645             }
646         }
647 
648         return list;
649     }
650 
651     public List<SocialRequest> findByUuid(String uuid, int start, int end)
652         throws SystemException {
653         return findByUuid(uuid, start, end, null);
654     }
655 
656     public List<SocialRequest> findByUuid(String uuid, int start, int end,
657         OrderByComparator obc) throws SystemException {
658         Object[] finderArgs = new Object[] {
659                 uuid,
660                 
661                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
662             };
663 
664         List<SocialRequest> list = (List<SocialRequest>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_UUID,
665                 finderArgs, this);
666 
667         if (list == null) {
668             Session session = null;
669 
670             try {
671                 session = openSession();
672 
673                 StringBuilder query = new StringBuilder();
674 
675                 query.append(
676                     "SELECT socialRequest FROM SocialRequest socialRequest WHERE ");
677 
678                 if (uuid == null) {
679                     query.append("socialRequest.uuid IS NULL");
680                 }
681                 else {
682                     query.append("socialRequest.uuid = ?");
683                 }
684 
685                 query.append(" ");
686 
687                 if (obc != null) {
688                     query.append("ORDER BY ");
689 
690                     String[] orderByFields = obc.getOrderByFields();
691 
692                     for (int i = 0; i < orderByFields.length; i++) {
693                         query.append("socialRequest.");
694                         query.append(orderByFields[i]);
695 
696                         if (obc.isAscending()) {
697                             query.append(" ASC");
698                         }
699                         else {
700                             query.append(" DESC");
701                         }
702 
703                         if ((i + 1) < orderByFields.length) {
704                             query.append(", ");
705                         }
706                     }
707                 }
708 
709                 else {
710                     query.append("ORDER BY ");
711 
712                     query.append("socialRequest.requestId DESC");
713                 }
714 
715                 Query q = session.createQuery(query.toString());
716 
717                 QueryPos qPos = QueryPos.getInstance(q);
718 
719                 if (uuid != null) {
720                     qPos.add(uuid);
721                 }
722 
723                 list = (List<SocialRequest>)QueryUtil.list(q, getDialect(),
724                         start, end);
725             }
726             catch (Exception e) {
727                 throw processException(e);
728             }
729             finally {
730                 if (list == null) {
731                     list = new ArrayList<SocialRequest>();
732                 }
733 
734                 cacheResult(list);
735 
736                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_UUID,
737                     finderArgs, list);
738 
739                 closeSession(session);
740             }
741         }
742 
743         return list;
744     }
745 
746     public SocialRequest findByUuid_First(String uuid, OrderByComparator obc)
747         throws NoSuchRequestException, SystemException {
748         List<SocialRequest> list = findByUuid(uuid, 0, 1, obc);
749 
750         if (list.isEmpty()) {
751             StringBuilder msg = new StringBuilder();
752 
753             msg.append("No SocialRequest exists with the key {");
754 
755             msg.append("uuid=" + uuid);
756 
757             msg.append(StringPool.CLOSE_CURLY_BRACE);
758 
759             throw new NoSuchRequestException(msg.toString());
760         }
761         else {
762             return list.get(0);
763         }
764     }
765 
766     public SocialRequest findByUuid_Last(String uuid, OrderByComparator obc)
767         throws NoSuchRequestException, SystemException {
768         int count = countByUuid(uuid);
769 
770         List<SocialRequest> list = findByUuid(uuid, count - 1, count, obc);
771 
772         if (list.isEmpty()) {
773             StringBuilder msg = new StringBuilder();
774 
775             msg.append("No SocialRequest exists with the key {");
776 
777             msg.append("uuid=" + uuid);
778 
779             msg.append(StringPool.CLOSE_CURLY_BRACE);
780 
781             throw new NoSuchRequestException(msg.toString());
782         }
783         else {
784             return list.get(0);
785         }
786     }
787 
788     public SocialRequest[] findByUuid_PrevAndNext(long requestId, String uuid,
789         OrderByComparator obc) throws NoSuchRequestException, SystemException {
790         SocialRequest socialRequest = findByPrimaryKey(requestId);
791 
792         int count = countByUuid(uuid);
793 
794         Session session = null;
795 
796         try {
797             session = openSession();
798 
799             StringBuilder query = new StringBuilder();
800 
801             query.append(
802                 "SELECT socialRequest FROM SocialRequest socialRequest WHERE ");
803 
804             if (uuid == null) {
805                 query.append("socialRequest.uuid IS NULL");
806             }
807             else {
808                 query.append("socialRequest.uuid = ?");
809             }
810 
811             query.append(" ");
812 
813             if (obc != null) {
814                 query.append("ORDER BY ");
815 
816                 String[] orderByFields = obc.getOrderByFields();
817 
818                 for (int i = 0; i < orderByFields.length; i++) {
819                     query.append("socialRequest.");
820                     query.append(orderByFields[i]);
821 
822                     if (obc.isAscending()) {
823                         query.append(" ASC");
824                     }
825                     else {
826                         query.append(" DESC");
827                     }
828 
829                     if ((i + 1) < orderByFields.length) {
830                         query.append(", ");
831                     }
832                 }
833             }
834 
835             else {
836                 query.append("ORDER BY ");
837 
838                 query.append("socialRequest.requestId DESC");
839             }
840 
841             Query q = session.createQuery(query.toString());
842 
843             QueryPos qPos = QueryPos.getInstance(q);
844 
845             if (uuid != null) {
846                 qPos.add(uuid);
847             }
848 
849             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
850                     socialRequest);
851 
852             SocialRequest[] array = new SocialRequestImpl[3];
853 
854             array[0] = (SocialRequest)objArray[0];
855             array[1] = (SocialRequest)objArray[1];
856             array[2] = (SocialRequest)objArray[2];
857 
858             return array;
859         }
860         catch (Exception e) {
861             throw processException(e);
862         }
863         finally {
864             closeSession(session);
865         }
866     }
867 
868     public SocialRequest findByUUID_G(String uuid, long groupId)
869         throws NoSuchRequestException, SystemException {
870         SocialRequest socialRequest = fetchByUUID_G(uuid, groupId);
871 
872         if (socialRequest == null) {
873             StringBuilder msg = new StringBuilder();
874 
875             msg.append("No SocialRequest exists with the key {");
876 
877             msg.append("uuid=" + uuid);
878 
879             msg.append(", ");
880             msg.append("groupId=" + groupId);
881 
882             msg.append(StringPool.CLOSE_CURLY_BRACE);
883 
884             if (_log.isWarnEnabled()) {
885                 _log.warn(msg.toString());
886             }
887 
888             throw new NoSuchRequestException(msg.toString());
889         }
890 
891         return socialRequest;
892     }
893 
894     public SocialRequest fetchByUUID_G(String uuid, long groupId)
895         throws SystemException {
896         return fetchByUUID_G(uuid, groupId, true);
897     }
898 
899     public SocialRequest fetchByUUID_G(String uuid, long groupId,
900         boolean retrieveFromCache) throws SystemException {
901         Object[] finderArgs = new Object[] { uuid, new Long(groupId) };
902 
903         Object result = null;
904 
905         if (retrieveFromCache) {
906             result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
907                     finderArgs, this);
908         }
909 
910         if (result == null) {
911             Session session = null;
912 
913             try {
914                 session = openSession();
915 
916                 StringBuilder query = new StringBuilder();
917 
918                 query.append(
919                     "SELECT socialRequest FROM SocialRequest socialRequest WHERE ");
920 
921                 if (uuid == null) {
922                     query.append("socialRequest.uuid IS NULL");
923                 }
924                 else {
925                     query.append("socialRequest.uuid = ?");
926                 }
927 
928                 query.append(" AND ");
929 
930                 query.append("socialRequest.groupId = ?");
931 
932                 query.append(" ");
933 
934                 query.append("ORDER BY ");
935 
936                 query.append("socialRequest.requestId DESC");
937 
938                 Query q = session.createQuery(query.toString());
939 
940                 QueryPos qPos = QueryPos.getInstance(q);
941 
942                 if (uuid != null) {
943                     qPos.add(uuid);
944                 }
945 
946                 qPos.add(groupId);
947 
948                 List<SocialRequest> list = q.list();
949 
950                 result = list;
951 
952                 SocialRequest socialRequest = null;
953 
954                 if (list.isEmpty()) {
955                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
956                         finderArgs, list);
957                 }
958                 else {
959                     socialRequest = list.get(0);
960 
961                     cacheResult(socialRequest);
962 
963                     if ((socialRequest.getUuid() == null) ||
964                             !socialRequest.getUuid().equals(uuid) ||
965                             (socialRequest.getGroupId() != groupId)) {
966                         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
967                             finderArgs, socialRequest);
968                     }
969                 }
970 
971                 return socialRequest;
972             }
973             catch (Exception e) {
974                 throw processException(e);
975             }
976             finally {
977                 if (result == null) {
978                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
979                         finderArgs, new ArrayList<SocialRequest>());
980                 }
981 
982                 closeSession(session);
983             }
984         }
985         else {
986             if (result instanceof List) {
987                 return null;
988             }
989             else {
990                 return (SocialRequest)result;
991             }
992         }
993     }
994 
995     public List<SocialRequest> findByCompanyId(long companyId)
996         throws SystemException {
997         Object[] finderArgs = new Object[] { new Long(companyId) };
998 
999         List<SocialRequest> list = (List<SocialRequest>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_COMPANYID,
1000                finderArgs, this);
1001
1002        if (list == null) {
1003            Session session = null;
1004
1005            try {
1006                session = openSession();
1007
1008                StringBuilder query = new StringBuilder();
1009
1010                query.append(
1011                    "SELECT socialRequest FROM SocialRequest socialRequest WHERE ");
1012
1013                query.append("socialRequest.companyId = ?");
1014
1015                query.append(" ");
1016
1017                query.append("ORDER BY ");
1018
1019                query.append("socialRequest.requestId DESC");
1020
1021                Query q = session.createQuery(query.toString());
1022
1023                QueryPos qPos = QueryPos.getInstance(q);
1024
1025                qPos.add(companyId);
1026
1027                list = q.list();
1028            }
1029            catch (Exception e) {
1030                throw processException(e);
1031            }
1032            finally {
1033                if (list == null) {
1034                    list = new ArrayList<SocialRequest>();
1035                }
1036
1037                cacheResult(list);
1038
1039                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_COMPANYID,
1040                    finderArgs, list);
1041
1042                closeSession(session);
1043            }
1044        }
1045
1046        return list;
1047    }
1048
1049    public List<SocialRequest> findByCompanyId(long companyId, int start,
1050        int end) throws SystemException {
1051        return findByCompanyId(companyId, start, end, null);
1052    }
1053
1054    public List<SocialRequest> findByCompanyId(long companyId, int start,
1055        int end, OrderByComparator obc) throws SystemException {
1056        Object[] finderArgs = new Object[] {
1057                new Long(companyId),
1058                
1059                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1060            };
1061
1062        List<SocialRequest> list = (List<SocialRequest>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_COMPANYID,
1063                finderArgs, this);
1064
1065        if (list == null) {
1066            Session session = null;
1067
1068            try {
1069                session = openSession();
1070
1071                StringBuilder query = new StringBuilder();
1072
1073                query.append(
1074                    "SELECT socialRequest FROM SocialRequest socialRequest WHERE ");
1075
1076                query.append("socialRequest.companyId = ?");
1077
1078                query.append(" ");
1079
1080                if (obc != null) {
1081                    query.append("ORDER BY ");
1082
1083                    String[] orderByFields = obc.getOrderByFields();
1084
1085                    for (int i = 0; i < orderByFields.length; i++) {
1086                        query.append("socialRequest.");
1087                        query.append(orderByFields[i]);
1088
1089                        if (obc.isAscending()) {
1090                            query.append(" ASC");
1091                        }
1092                        else {
1093                            query.append(" DESC");
1094                        }
1095
1096                        if ((i + 1) < orderByFields.length) {
1097                            query.append(", ");
1098                        }
1099                    }
1100                }
1101
1102                else {
1103                    query.append("ORDER BY ");
1104
1105                    query.append("socialRequest.requestId DESC");
1106                }
1107
1108                Query q = session.createQuery(query.toString());
1109
1110                QueryPos qPos = QueryPos.getInstance(q);
1111
1112                qPos.add(companyId);
1113
1114                list = (List<SocialRequest>)QueryUtil.list(q, getDialect(),
1115                        start, end);
1116            }
1117            catch (Exception e) {
1118                throw processException(e);
1119            }
1120            finally {
1121                if (list == null) {
1122                    list = new ArrayList<SocialRequest>();
1123                }
1124
1125                cacheResult(list);
1126
1127                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_COMPANYID,
1128                    finderArgs, list);
1129
1130                closeSession(session);
1131            }
1132        }
1133
1134        return list;
1135    }
1136
1137    public SocialRequest findByCompanyId_First(long companyId,
1138        OrderByComparator obc) throws NoSuchRequestException, SystemException {
1139        List<SocialRequest> list = findByCompanyId(companyId, 0, 1, obc);
1140
1141        if (list.isEmpty()) {
1142            StringBuilder msg = new StringBuilder();
1143
1144            msg.append("No SocialRequest exists with the key {");
1145
1146            msg.append("companyId=" + companyId);
1147
1148            msg.append(StringPool.CLOSE_CURLY_BRACE);
1149
1150            throw new NoSuchRequestException(msg.toString());
1151        }
1152        else {
1153            return list.get(0);
1154        }
1155    }
1156
1157    public SocialRequest findByCompanyId_Last(long companyId,
1158        OrderByComparator obc) throws NoSuchRequestException, SystemException {
1159        int count = countByCompanyId(companyId);
1160
1161        List<SocialRequest> list = findByCompanyId(companyId, count - 1, count,
1162                obc);
1163
1164        if (list.isEmpty()) {
1165            StringBuilder msg = new StringBuilder();
1166
1167            msg.append("No SocialRequest exists with the key {");
1168
1169            msg.append("companyId=" + companyId);
1170
1171            msg.append(StringPool.CLOSE_CURLY_BRACE);
1172
1173            throw new NoSuchRequestException(msg.toString());
1174        }
1175        else {
1176            return list.get(0);
1177        }
1178    }
1179
1180    public SocialRequest[] findByCompanyId_PrevAndNext(long requestId,
1181        long companyId, OrderByComparator obc)
1182        throws NoSuchRequestException, SystemException {
1183        SocialRequest socialRequest = findByPrimaryKey(requestId);
1184
1185        int count = countByCompanyId(companyId);
1186
1187        Session session = null;
1188
1189        try {
1190            session = openSession();
1191
1192            StringBuilder query = new StringBuilder();
1193
1194            query.append(
1195                "SELECT socialRequest FROM SocialRequest socialRequest WHERE ");
1196
1197            query.append("socialRequest.companyId = ?");
1198
1199            query.append(" ");
1200
1201            if (obc != null) {
1202                query.append("ORDER BY ");
1203
1204                String[] orderByFields = obc.getOrderByFields();
1205
1206                for (int i = 0; i < orderByFields.length; i++) {
1207                    query.append("socialRequest.");
1208                    query.append(orderByFields[i]);
1209
1210                    if (obc.isAscending()) {
1211                        query.append(" ASC");
1212                    }
1213                    else {
1214                        query.append(" DESC");
1215                    }
1216
1217                    if ((i + 1) < orderByFields.length) {
1218                        query.append(", ");
1219                    }
1220                }
1221            }
1222
1223            else {
1224                query.append("ORDER BY ");
1225
1226                query.append("socialRequest.requestId DESC");
1227            }
1228
1229            Query q = session.createQuery(query.toString());
1230
1231            QueryPos qPos = QueryPos.getInstance(q);
1232
1233            qPos.add(companyId);
1234
1235            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1236                    socialRequest);
1237
1238            SocialRequest[] array = new SocialRequestImpl[3];
1239
1240            array[0] = (SocialRequest)objArray[0];
1241            array[1] = (SocialRequest)objArray[1];
1242            array[2] = (SocialRequest)objArray[2];
1243
1244            return array;
1245        }
1246        catch (Exception e) {
1247            throw processException(e);
1248        }
1249        finally {
1250            closeSession(session);
1251        }
1252    }
1253
1254    public List<SocialRequest> findByUserId(long userId)
1255        throws SystemException {
1256        Object[] finderArgs = new Object[] { new Long(userId) };
1257
1258        List<SocialRequest> list = (List<SocialRequest>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_USERID,
1259                finderArgs, this);
1260
1261        if (list == null) {
1262            Session session = null;
1263
1264            try {
1265                session = openSession();
1266
1267                StringBuilder query = new StringBuilder();
1268
1269                query.append(
1270                    "SELECT socialRequest FROM SocialRequest socialRequest WHERE ");
1271
1272                query.append("socialRequest.userId = ?");
1273
1274                query.append(" ");
1275
1276                query.append("ORDER BY ");
1277
1278                query.append("socialRequest.requestId DESC");
1279
1280                Query q = session.createQuery(query.toString());
1281
1282                QueryPos qPos = QueryPos.getInstance(q);
1283
1284                qPos.add(userId);
1285
1286                list = q.list();
1287            }
1288            catch (Exception e) {
1289                throw processException(e);
1290            }
1291            finally {
1292                if (list == null) {
1293                    list = new ArrayList<SocialRequest>();
1294                }
1295
1296                cacheResult(list);
1297
1298                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_USERID,
1299                    finderArgs, list);
1300
1301                closeSession(session);
1302            }
1303        }
1304
1305        return list;
1306    }
1307
1308    public List<SocialRequest> findByUserId(long userId, int start, int end)
1309        throws SystemException {
1310        return findByUserId(userId, start, end, null);
1311    }
1312
1313    public List<SocialRequest> findByUserId(long userId, int start, int end,
1314        OrderByComparator obc) throws SystemException {
1315        Object[] finderArgs = new Object[] {
1316                new Long(userId),
1317                
1318                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1319            };
1320
1321        List<SocialRequest> list = (List<SocialRequest>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_USERID,
1322                finderArgs, this);
1323
1324        if (list == null) {
1325            Session session = null;
1326
1327            try {
1328                session = openSession();
1329
1330                StringBuilder query = new StringBuilder();
1331
1332                query.append(
1333                    "SELECT socialRequest FROM SocialRequest socialRequest WHERE ");
1334
1335                query.append("socialRequest.userId = ?");
1336
1337                query.append(" ");
1338
1339                if (obc != null) {
1340                    query.append("ORDER BY ");
1341
1342                    String[] orderByFields = obc.getOrderByFields();
1343
1344                    for (int i = 0; i < orderByFields.length; i++) {
1345                        query.append("socialRequest.");
1346                        query.append(orderByFields[i]);
1347
1348                        if (obc.isAscending()) {
1349                            query.append(" ASC");
1350                        }
1351                        else {
1352                            query.append(" DESC");
1353                        }
1354
1355                        if ((i + 1) < orderByFields.length) {
1356                            query.append(", ");
1357                        }
1358                    }
1359                }
1360
1361                else {
1362                    query.append("ORDER BY ");
1363
1364                    query.append("socialRequest.requestId DESC");
1365                }
1366
1367                Query q = session.createQuery(query.toString());
1368
1369                QueryPos qPos = QueryPos.getInstance(q);
1370
1371                qPos.add(userId);
1372
1373                list = (List<SocialRequest>)QueryUtil.list(q, getDialect(),
1374                        start, end);
1375            }
1376            catch (Exception e) {
1377                throw processException(e);
1378            }
1379            finally {
1380                if (list == null) {
1381                    list = new ArrayList<SocialRequest>();
1382                }
1383
1384                cacheResult(list);
1385
1386                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_USERID,
1387                    finderArgs, list);
1388
1389                closeSession(session);
1390            }
1391        }
1392
1393        return list;
1394    }
1395
1396    public SocialRequest findByUserId_First(long userId, OrderByComparator obc)
1397        throws NoSuchRequestException, SystemException {
1398        List<SocialRequest> list = findByUserId(userId, 0, 1, obc);
1399
1400        if (list.isEmpty()) {
1401            StringBuilder msg = new StringBuilder();
1402
1403            msg.append("No SocialRequest exists with the key {");
1404
1405            msg.append("userId=" + userId);
1406
1407            msg.append(StringPool.CLOSE_CURLY_BRACE);
1408
1409            throw new NoSuchRequestException(msg.toString());
1410        }
1411        else {
1412            return list.get(0);
1413        }
1414    }
1415
1416    public SocialRequest findByUserId_Last(long userId, OrderByComparator obc)
1417        throws NoSuchRequestException, SystemException {
1418        int count = countByUserId(userId);
1419
1420        List<SocialRequest> list = findByUserId(userId, count - 1, count, obc);
1421
1422        if (list.isEmpty()) {
1423            StringBuilder msg = new StringBuilder();
1424
1425            msg.append("No SocialRequest exists with the key {");
1426
1427            msg.append("userId=" + userId);
1428
1429            msg.append(StringPool.CLOSE_CURLY_BRACE);
1430
1431            throw new NoSuchRequestException(msg.toString());
1432        }
1433        else {
1434            return list.get(0);
1435        }
1436    }
1437
1438    public SocialRequest[] findByUserId_PrevAndNext(long requestId,
1439        long userId, OrderByComparator obc)
1440        throws NoSuchRequestException, SystemException {
1441        SocialRequest socialRequest = findByPrimaryKey(requestId);
1442
1443        int count = countByUserId(userId);
1444
1445        Session session = null;
1446
1447        try {
1448            session = openSession();
1449
1450            StringBuilder query = new StringBuilder();
1451
1452            query.append(
1453                "SELECT socialRequest FROM SocialRequest socialRequest WHERE ");
1454
1455            query.append("socialRequest.userId = ?");
1456
1457            query.append(" ");
1458
1459            if (obc != null) {
1460                query.append("ORDER BY ");
1461
1462                String[] orderByFields = obc.getOrderByFields();
1463
1464                for (int i = 0; i < orderByFields.length; i++) {
1465                    query.append("socialRequest.");
1466                    query.append(orderByFields[i]);
1467
1468                    if (obc.isAscending()) {
1469                        query.append(" ASC");
1470                    }
1471                    else {
1472                        query.append(" DESC");
1473                    }
1474
1475                    if ((i + 1) < orderByFields.length) {
1476                        query.append(", ");
1477                    }
1478                }
1479            }
1480
1481            else {
1482                query.append("ORDER BY ");
1483
1484                query.append("socialRequest.requestId DESC");
1485            }
1486
1487            Query q = session.createQuery(query.toString());
1488
1489            QueryPos qPos = QueryPos.getInstance(q);
1490
1491            qPos.add(userId);
1492
1493            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1494                    socialRequest);
1495
1496            SocialRequest[] array = new SocialRequestImpl[3];
1497
1498            array[0] = (SocialRequest)objArray[0];
1499            array[1] = (SocialRequest)objArray[1];
1500            array[2] = (SocialRequest)objArray[2];
1501
1502            return array;
1503        }
1504        catch (Exception e) {
1505            throw processException(e);
1506        }
1507        finally {
1508            closeSession(session);
1509        }
1510    }
1511
1512    public List<SocialRequest> findByReceiverUserId(long receiverUserId)
1513        throws SystemException {
1514        Object[] finderArgs = new Object[] { new Long(receiverUserId) };
1515
1516        List<SocialRequest> list = (List<SocialRequest>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_RECEIVERUSERID,
1517                finderArgs, this);
1518
1519        if (list == null) {
1520            Session session = null;
1521
1522            try {
1523                session = openSession();
1524
1525                StringBuilder query = new StringBuilder();
1526
1527                query.append(
1528                    "SELECT socialRequest FROM SocialRequest socialRequest WHERE ");
1529
1530                query.append("socialRequest.receiverUserId = ?");
1531
1532                query.append(" ");
1533
1534                query.append("ORDER BY ");
1535
1536                query.append("socialRequest.requestId DESC");
1537
1538                Query q = session.createQuery(query.toString());
1539
1540                QueryPos qPos = QueryPos.getInstance(q);
1541
1542                qPos.add(receiverUserId);
1543
1544                list = q.list();
1545            }
1546            catch (Exception e) {
1547                throw processException(e);
1548            }
1549            finally {
1550                if (list == null) {
1551                    list = new ArrayList<SocialRequest>();
1552                }
1553
1554                cacheResult(list);
1555
1556                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_RECEIVERUSERID,
1557                    finderArgs, list);
1558
1559                closeSession(session);
1560            }
1561        }
1562
1563        return list;
1564    }
1565
1566    public List<SocialRequest> findByReceiverUserId(long receiverUserId,
1567        int start, int end) throws SystemException {
1568        return findByReceiverUserId(receiverUserId, start, end, null);
1569    }
1570
1571    public List<SocialRequest> findByReceiverUserId(long receiverUserId,
1572        int start, int end, OrderByComparator obc) throws SystemException {
1573        Object[] finderArgs = new Object[] {
1574                new Long(receiverUserId),
1575                
1576                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1577            };
1578
1579        List<SocialRequest> list = (List<SocialRequest>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_RECEIVERUSERID,
1580                finderArgs, this);
1581
1582        if (list == null) {
1583            Session session = null;
1584
1585            try {
1586                session = openSession();
1587
1588                StringBuilder query = new StringBuilder();
1589
1590                query.append(
1591                    "SELECT socialRequest FROM SocialRequest socialRequest WHERE ");
1592
1593                query.append("socialRequest.receiverUserId = ?");
1594
1595                query.append(" ");
1596
1597                if (obc != null) {
1598                    query.append("ORDER BY ");
1599
1600                    String[] orderByFields = obc.getOrderByFields();
1601
1602                    for (int i = 0; i < orderByFields.length; i++) {
1603                        query.append("socialRequest.");
1604                        query.append(orderByFields[i]);
1605
1606                        if (obc.isAscending()) {
1607                            query.append(" ASC");
1608                        }
1609                        else {
1610                            query.append(" DESC");
1611                        }
1612
1613                        if ((i + 1) < orderByFields.length) {
1614                            query.append(", ");
1615                        }
1616                    }
1617                }
1618
1619                else {
1620                    query.append("ORDER BY ");
1621
1622                    query.append("socialRequest.requestId DESC");
1623                }
1624
1625                Query q = session.createQuery(query.toString());
1626
1627                QueryPos qPos = QueryPos.getInstance(q);
1628
1629                qPos.add(receiverUserId);
1630
1631                list = (List<SocialRequest>)QueryUtil.list(q, getDialect(),
1632                        start, end);
1633            }
1634            catch (Exception e) {
1635                throw processException(e);
1636            }
1637            finally {
1638                if (list == null) {
1639                    list = new ArrayList<SocialRequest>();
1640                }
1641
1642                cacheResult(list);
1643
1644                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_RECEIVERUSERID,
1645                    finderArgs, list);
1646
1647                closeSession(session);
1648            }
1649        }
1650
1651        return list;
1652    }
1653
1654    public SocialRequest findByReceiverUserId_First(long receiverUserId,
1655        OrderByComparator obc) throws NoSuchRequestException, SystemException {
1656        List<SocialRequest> list = findByReceiverUserId(receiverUserId, 0, 1,
1657                obc);
1658
1659        if (list.isEmpty()) {
1660            StringBuilder msg = new StringBuilder();
1661
1662            msg.append("No SocialRequest exists with the key {");
1663
1664            msg.append("receiverUserId=" + receiverUserId);
1665
1666            msg.append(StringPool.CLOSE_CURLY_BRACE);
1667
1668            throw new NoSuchRequestException(msg.toString());
1669        }
1670        else {
1671            return list.get(0);
1672        }
1673    }
1674
1675    public SocialRequest findByReceiverUserId_Last(long receiverUserId,
1676        OrderByComparator obc) throws NoSuchRequestException, SystemException {
1677        int count = countByReceiverUserId(receiverUserId);
1678
1679        List<SocialRequest> list = findByReceiverUserId(receiverUserId,
1680                count - 1, count, obc);
1681
1682        if (list.isEmpty()) {
1683            StringBuilder msg = new StringBuilder();
1684
1685            msg.append("No SocialRequest exists with the key {");
1686
1687            msg.append("receiverUserId=" + receiverUserId);
1688
1689            msg.append(StringPool.CLOSE_CURLY_BRACE);
1690
1691            throw new NoSuchRequestException(msg.toString());
1692        }
1693        else {
1694            return list.get(0);
1695        }
1696    }
1697
1698    public SocialRequest[] findByReceiverUserId_PrevAndNext(long requestId,
1699        long receiverUserId, OrderByComparator obc)
1700        throws NoSuchRequestException, SystemException {
1701        SocialRequest socialRequest = findByPrimaryKey(requestId);
1702
1703        int count = countByReceiverUserId(receiverUserId);
1704
1705        Session session = null;
1706
1707        try {
1708            session = openSession();
1709
1710            StringBuilder query = new StringBuilder();
1711
1712            query.append(
1713                "SELECT socialRequest FROM SocialRequest socialRequest WHERE ");
1714
1715            query.append("socialRequest.receiverUserId = ?");
1716
1717            query.append(" ");
1718
1719            if (obc != null) {
1720                query.append("ORDER BY ");
1721
1722                String[] orderByFields = obc.getOrderByFields();
1723
1724                for (int i = 0; i < orderByFields.length; i++) {
1725                    query.append("socialRequest.");
1726                    query.append(orderByFields[i]);
1727
1728                    if (obc.isAscending()) {
1729                        query.append(" ASC");
1730                    }
1731                    else {
1732                        query.append(" DESC");
1733                    }
1734
1735                    if ((i + 1) < orderByFields.length) {
1736                        query.append(", ");
1737                    }
1738                }
1739            }
1740
1741            else {
1742                query.append("ORDER BY ");
1743
1744                query.append("socialRequest.requestId DESC");
1745            }
1746
1747            Query q = session.createQuery(query.toString());
1748
1749            QueryPos qPos = QueryPos.getInstance(q);
1750
1751            qPos.add(receiverUserId);
1752
1753            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1754                    socialRequest);
1755
1756            SocialRequest[] array = new SocialRequestImpl[3];
1757
1758            array[0] = (SocialRequest)objArray[0];
1759            array[1] = (SocialRequest)objArray[1];
1760            array[2] = (SocialRequest)objArray[2];
1761
1762            return array;
1763        }
1764        catch (Exception e) {
1765            throw processException(e);
1766        }
1767        finally {
1768            closeSession(session);
1769        }
1770    }
1771
1772    public List<SocialRequest> findByU_S(long userId, int status)
1773        throws SystemException {
1774        Object[] finderArgs = new Object[] { new Long(userId), new Integer(status) };
1775
1776        List<SocialRequest> list = (List<SocialRequest>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_U_S,
1777                finderArgs, this);
1778
1779        if (list == null) {
1780            Session session = null;
1781
1782            try {
1783                session = openSession();
1784
1785                StringBuilder query = new StringBuilder();
1786
1787                query.append(
1788                    "SELECT socialRequest FROM SocialRequest socialRequest WHERE ");
1789
1790                query.append("socialRequest.userId = ?");
1791
1792                query.append(" AND ");
1793
1794                query.append("socialRequest.status = ?");
1795
1796                query.append(" ");
1797
1798                query.append("ORDER BY ");
1799
1800                query.append("socialRequest.requestId DESC");
1801
1802                Query q = session.createQuery(query.toString());
1803
1804                QueryPos qPos = QueryPos.getInstance(q);
1805
1806                qPos.add(userId);
1807
1808                qPos.add(status);
1809
1810                list = q.list();
1811            }
1812            catch (Exception e) {
1813                throw processException(e);
1814            }
1815            finally {
1816                if (list == null) {
1817                    list = new ArrayList<SocialRequest>();
1818                }
1819
1820                cacheResult(list);
1821
1822                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_U_S, finderArgs,
1823                    list);
1824
1825                closeSession(session);
1826            }
1827        }
1828
1829        return list;
1830    }
1831
1832    public List<SocialRequest> findByU_S(long userId, int status, int start,
1833        int end) throws SystemException {
1834        return findByU_S(userId, status, start, end, null);
1835    }
1836
1837    public List<SocialRequest> findByU_S(long userId, int status, int start,
1838        int end, OrderByComparator obc) throws SystemException {
1839        Object[] finderArgs = new Object[] {
1840                new Long(userId), new Integer(status),
1841                
1842                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1843            };
1844
1845        List<SocialRequest> list = (List<SocialRequest>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_U_S,
1846                finderArgs, this);
1847
1848        if (list == null) {
1849            Session session = null;
1850
1851            try {
1852                session = openSession();
1853
1854                StringBuilder query = new StringBuilder();
1855
1856                query.append(
1857                    "SELECT socialRequest FROM SocialRequest socialRequest WHERE ");
1858
1859                query.append("socialRequest.userId = ?");
1860
1861                query.append(" AND ");
1862
1863                query.append("socialRequest.status = ?");
1864
1865                query.append(" ");
1866
1867                if (obc != null) {
1868                    query.append("ORDER BY ");
1869
1870                    String[] orderByFields = obc.getOrderByFields();
1871
1872                    for (int i = 0; i < orderByFields.length; i++) {
1873                        query.append("socialRequest.");
1874                        query.append(orderByFields[i]);
1875
1876                        if (obc.isAscending()) {
1877                            query.append(" ASC");
1878                        }
1879                        else {
1880                            query.append(" DESC");
1881                        }
1882
1883                        if ((i + 1) < orderByFields.length) {
1884                            query.append(", ");
1885                        }
1886                    }
1887                }
1888
1889                else {
1890                    query.append("ORDER BY ");
1891
1892                    query.append("socialRequest.requestId DESC");
1893                }
1894
1895                Query q = session.createQuery(query.toString());
1896
1897                QueryPos qPos = QueryPos.getInstance(q);
1898
1899                qPos.add(userId);
1900
1901                qPos.add(status);
1902
1903                list = (List<SocialRequest>)QueryUtil.list(q, getDialect(),
1904                        start, end);
1905            }
1906            catch (Exception e) {
1907                throw processException(e);
1908            }
1909            finally {
1910                if (list == null) {
1911                    list = new ArrayList<SocialRequest>();
1912                }
1913
1914                cacheResult(list);
1915
1916                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_U_S,
1917                    finderArgs, list);
1918
1919                closeSession(session);
1920            }
1921        }
1922
1923        return list;
1924    }
1925
1926    public SocialRequest findByU_S_First(long userId, int status,
1927        OrderByComparator obc) throws NoSuchRequestException, SystemException {
1928        List<SocialRequest> list = findByU_S(userId, status, 0, 1, obc);
1929
1930        if (list.isEmpty()) {
1931            StringBuilder msg = new StringBuilder();
1932
1933            msg.append("No SocialRequest exists with the key {");
1934
1935            msg.append("userId=" + userId);
1936
1937            msg.append(", ");
1938            msg.append("status=" + status);
1939
1940            msg.append(StringPool.CLOSE_CURLY_BRACE);
1941
1942            throw new NoSuchRequestException(msg.toString());
1943        }
1944        else {
1945            return list.get(0);
1946        }
1947    }
1948
1949    public SocialRequest findByU_S_Last(long userId, int status,
1950        OrderByComparator obc) throws NoSuchRequestException, SystemException {
1951        int count = countByU_S(userId, status);
1952
1953        List<SocialRequest> list = findByU_S(userId, status, count - 1, count,
1954                obc);
1955
1956        if (list.isEmpty()) {
1957            StringBuilder msg = new StringBuilder();
1958
1959            msg.append("No SocialRequest exists with the key {");
1960
1961            msg.append("userId=" + userId);
1962
1963            msg.append(", ");
1964            msg.append("status=" + status);
1965
1966            msg.append(StringPool.CLOSE_CURLY_BRACE);
1967
1968            throw new NoSuchRequestException(msg.toString());
1969        }
1970        else {
1971            return list.get(0);
1972        }
1973    }
1974
1975    public SocialRequest[] findByU_S_PrevAndNext(long requestId, long userId,
1976        int status, OrderByComparator obc)
1977        throws NoSuchRequestException, SystemException {
1978        SocialRequest socialRequest = findByPrimaryKey(requestId);
1979
1980        int count = countByU_S(userId, status);
1981
1982        Session session = null;
1983
1984        try {
1985            session = openSession();
1986
1987            StringBuilder query = new StringBuilder();
1988
1989            query.append(
1990                "SELECT socialRequest FROM SocialRequest socialRequest WHERE ");
1991
1992            query.append("socialRequest.userId = ?");
1993
1994            query.append(" AND ");
1995
1996            query.append("socialRequest.status = ?");
1997
1998            query.append(" ");
1999
2000            if (obc != null) {
2001                query.append("ORDER BY ");
2002
2003                String[] orderByFields = obc.getOrderByFields();
2004
2005                for (int i = 0; i < orderByFields.length; i++) {
2006                    query.append("socialRequest.");
2007                    query.append(orderByFields[i]);
2008
2009                    if (obc.isAscending()) {
2010                        query.append(" ASC");
2011                    }
2012                    else {
2013                        query.append(" DESC");
2014                    }
2015
2016                    if ((i + 1) < orderByFields.length) {
2017                        query.append(", ");
2018                    }
2019                }
2020            }
2021
2022            else {
2023                query.append("ORDER BY ");
2024
2025                query.append("socialRequest.requestId DESC");
2026            }
2027
2028            Query q = session.createQuery(query.toString());
2029
2030            QueryPos qPos = QueryPos.getInstance(q);
2031
2032            qPos.add(userId);
2033
2034            qPos.add(status);
2035
2036            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
2037                    socialRequest);
2038
2039            SocialRequest[] array = new SocialRequestImpl[3];
2040
2041            array[0] = (SocialRequest)objArray[0];
2042            array[1] = (SocialRequest)objArray[1];
2043            array[2] = (SocialRequest)objArray[2];
2044
2045            return array;
2046        }
2047        catch (Exception e) {
2048            throw processException(e);
2049        }
2050        finally {
2051            closeSession(session);
2052        }
2053    }
2054
2055    public List<SocialRequest> findByR_S(long receiverUserId, int status)
2056        throws SystemException {
2057        Object[] finderArgs = new Object[] {
2058                new Long(receiverUserId), new Integer(status)
2059            };
2060
2061        List<SocialRequest> list = (List<SocialRequest>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_R_S,
2062                finderArgs, this);
2063
2064        if (list == null) {
2065            Session session = null;
2066
2067            try {
2068                session = openSession();
2069
2070                StringBuilder query = new StringBuilder();
2071
2072                query.append(
2073                    "SELECT socialRequest FROM SocialRequest socialRequest WHERE ");
2074
2075                query.append("socialRequest.receiverUserId = ?");
2076
2077                query.append(" AND ");
2078
2079                query.append("socialRequest.status = ?");
2080
2081                query.append(" ");
2082
2083                query.append("ORDER BY ");
2084
2085                query.append("socialRequest.requestId DESC");
2086
2087                Query q = session.createQuery(query.toString());
2088
2089                QueryPos qPos = QueryPos.getInstance(q);
2090
2091                qPos.add(receiverUserId);
2092
2093                qPos.add(status);
2094
2095                list = q.list();
2096            }
2097            catch (Exception e) {
2098                throw processException(e);
2099            }
2100            finally {
2101                if (list == null) {
2102                    list = new ArrayList<SocialRequest>();
2103                }
2104
2105                cacheResult(list);
2106
2107                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_R_S, finderArgs,
2108                    list);
2109
2110                closeSession(session);
2111            }
2112        }
2113
2114        return list;
2115    }
2116
2117    public List<SocialRequest> findByR_S(long receiverUserId, int status,
2118        int start, int end) throws SystemException {
2119        return findByR_S(receiverUserId, status, start, end, null);
2120    }
2121
2122    public List<SocialRequest> findByR_S(long receiverUserId, int status,
2123        int start, int end, OrderByComparator obc) throws SystemException {
2124        Object[] finderArgs = new Object[] {
2125                new Long(receiverUserId), new Integer(status),
2126                
2127                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
2128            };
2129
2130        List<SocialRequest> list = (List<SocialRequest>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_R_S,
2131                finderArgs, this);
2132
2133        if (list == null) {
2134            Session session = null;
2135
2136            try {
2137                session = openSession();
2138
2139                StringBuilder query = new StringBuilder();
2140
2141                query.append(
2142                    "SELECT socialRequest FROM SocialRequest socialRequest WHERE ");
2143
2144                query.append("socialRequest.receiverUserId = ?");
2145
2146                query.append(" AND ");
2147
2148                query.append("socialRequest.status = ?");
2149
2150                query.append(" ");
2151
2152                if (obc != null) {
2153                    query.append("ORDER BY ");
2154
2155                    String[] orderByFields = obc.getOrderByFields();
2156
2157                    for (int i = 0; i < orderByFields.length; i++) {
2158                        query.append("socialRequest.");
2159                        query.append(orderByFields[i]);
2160
2161                        if (obc.isAscending()) {
2162                            query.append(" ASC");
2163                        }
2164                        else {
2165                            query.append(" DESC");
2166                        }
2167
2168                        if ((i + 1) < orderByFields.length) {
2169                            query.append(", ");
2170                        }
2171                    }
2172                }
2173
2174                else {
2175                    query.append("ORDER BY ");
2176
2177                    query.append("socialRequest.requestId DESC");
2178                }
2179
2180                Query q = session.createQuery(query.toString());
2181
2182                QueryPos qPos = QueryPos.getInstance(q);
2183
2184                qPos.add(receiverUserId);
2185
2186                qPos.add(status);
2187
2188                list = (List<SocialRequest>)QueryUtil.list(q, getDialect(),
2189                        start, end);
2190            }
2191            catch (Exception e) {
2192                throw processException(e);
2193            }
2194            finally {
2195                if (list == null) {
2196                    list = new ArrayList<SocialRequest>();
2197                }
2198
2199                cacheResult(list);
2200
2201                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_R_S,
2202                    finderArgs, list);
2203
2204                closeSession(session);
2205            }
2206        }
2207
2208        return list;
2209    }
2210
2211    public SocialRequest findByR_S_First(long receiverUserId, int status,
2212        OrderByComparator obc) throws NoSuchRequestException, SystemException {
2213        List<SocialRequest> list = findByR_S(receiverUserId, status, 0, 1, obc);
2214
2215        if (list.isEmpty()) {
2216            StringBuilder msg = new StringBuilder();
2217
2218            msg.append("No SocialRequest exists with the key {");
2219
2220            msg.append("receiverUserId=" + receiverUserId);
2221
2222            msg.append(", ");
2223            msg.append("status=" + status);
2224
2225            msg.append(StringPool.CLOSE_CURLY_BRACE);
2226
2227            throw new NoSuchRequestException(msg.toString());
2228        }
2229        else {
2230            return list.get(0);
2231        }
2232    }
2233
2234    public SocialRequest findByR_S_Last(long receiverUserId, int status,
2235        OrderByComparator obc) throws NoSuchRequestException, SystemException {
2236        int count = countByR_S(receiverUserId, status);
2237
2238        List<SocialRequest> list = findByR_S(receiverUserId, status, count - 1,
2239                count, obc);
2240
2241        if (list.isEmpty()) {
2242            StringBuilder msg = new StringBuilder();
2243
2244            msg.append("No SocialRequest exists with the key {");
2245
2246            msg.append("receiverUserId=" + receiverUserId);
2247
2248            msg.append(", ");
2249            msg.append("status=" + status);
2250
2251            msg.append(StringPool.CLOSE_CURLY_BRACE);
2252
2253            throw new NoSuchRequestException(msg.toString());
2254        }
2255        else {
2256            return list.get(0);
2257        }
2258    }
2259
2260    public SocialRequest[] findByR_S_PrevAndNext(long requestId,
2261        long receiverUserId, int status, OrderByComparator obc)
2262        throws NoSuchRequestException, SystemException {
2263        SocialRequest socialRequest = findByPrimaryKey(requestId);
2264
2265        int count = countByR_S(receiverUserId, status);
2266
2267        Session session = null;
2268
2269        try {
2270            session = openSession();
2271
2272            StringBuilder query = new StringBuilder();
2273
2274            query.append(
2275                "SELECT socialRequest FROM SocialRequest socialRequest WHERE ");
2276
2277            query.append("socialRequest.receiverUserId = ?");
2278
2279            query.append(" AND ");
2280
2281            query.append("socialRequest.status = ?");
2282
2283            query.append(" ");
2284
2285            if (obc != null) {
2286                query.append("ORDER BY ");
2287
2288                String[] orderByFields = obc.getOrderByFields();
2289
2290                for (int i = 0; i < orderByFields.length; i++) {
2291                    query.append("socialRequest.");
2292                    query.append(orderByFields[i]);
2293
2294                    if (obc.isAscending()) {
2295                        query.append(" ASC");
2296                    }
2297                    else {
2298                        query.append(" DESC");
2299                    }
2300
2301                    if ((i + 1) < orderByFields.length) {
2302                        query.append(", ");
2303                    }
2304                }
2305            }
2306
2307            else {
2308                query.append("ORDER BY ");
2309
2310                query.append("socialRequest.requestId DESC");
2311            }
2312
2313            Query q = session.createQuery(query.toString());
2314
2315            QueryPos qPos = QueryPos.getInstance(q);
2316
2317            qPos.add(receiverUserId);
2318
2319            qPos.add(status);
2320
2321            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
2322                    socialRequest);
2323
2324            SocialRequest[] array = new SocialRequestImpl[3];
2325
2326            array[0] = (SocialRequest)objArray[0];
2327            array[1] = (SocialRequest)objArray[1];
2328            array[2] = (SocialRequest)objArray[2];
2329
2330            return array;
2331        }
2332        catch (Exception e) {
2333            throw processException(e);
2334        }
2335        finally {
2336            closeSession(session);
2337        }
2338    }
2339
2340    public SocialRequest findByU_C_C_T_R(long userId, long classNameId,
2341        long classPK, int type, long receiverUserId)
2342        throws NoSuchRequestException, SystemException {
2343        SocialRequest socialRequest = fetchByU_C_C_T_R(userId, classNameId,
2344                classPK, type, receiverUserId);
2345
2346        if (socialRequest == null) {
2347            StringBuilder msg = new StringBuilder();
2348
2349            msg.append("No SocialRequest exists with the key {");
2350
2351            msg.append("userId=" + userId);
2352
2353            msg.append(", ");
2354            msg.append("classNameId=" + classNameId);
2355
2356            msg.append(", ");
2357            msg.append("classPK=" + classPK);
2358
2359            msg.append(", ");
2360            msg.append("type=" + type);
2361
2362            msg.append(", ");
2363            msg.append("receiverUserId=" + receiverUserId);
2364
2365            msg.append(StringPool.CLOSE_CURLY_BRACE);
2366
2367            if (_log.isWarnEnabled()) {
2368                _log.warn(msg.toString());
2369            }
2370
2371            throw new NoSuchRequestException(msg.toString());
2372        }
2373
2374        return socialRequest;
2375    }
2376
2377    public SocialRequest fetchByU_C_C_T_R(long userId, long classNameId,
2378        long classPK, int type, long receiverUserId) throws SystemException {
2379        return fetchByU_C_C_T_R(userId, classNameId, classPK, type,
2380            receiverUserId, true);
2381    }
2382
2383    public SocialRequest fetchByU_C_C_T_R(long userId, long classNameId,
2384        long classPK, int type, long receiverUserId, boolean retrieveFromCache)
2385        throws SystemException {
2386        Object[] finderArgs = new Object[] {
2387                new Long(userId), new Long(classNameId), new Long(classPK),
2388                new Integer(type), new Long(receiverUserId)
2389            };
2390
2391        Object result = null;
2392
2393        if (retrieveFromCache) {
2394            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_U_C_C_T_R,
2395                    finderArgs, this);
2396        }
2397
2398        if (result == null) {
2399            Session session = null;
2400
2401            try {
2402                session = openSession();
2403
2404                StringBuilder query = new StringBuilder();
2405
2406                query.append(
2407                    "SELECT socialRequest FROM SocialRequest socialRequest WHERE ");
2408
2409                query.append("socialRequest.userId = ?");
2410
2411                query.append(" AND ");
2412
2413                query.append("socialRequest.classNameId = ?");
2414
2415                query.append(" AND ");
2416
2417                query.append("socialRequest.classPK = ?");
2418
2419                query.append(" AND ");
2420
2421                query.append("socialRequest.type = ?");
2422
2423                query.append(" AND ");
2424
2425                query.append("socialRequest.receiverUserId = ?");
2426
2427                query.append(" ");
2428
2429                query.append("ORDER BY ");
2430
2431                query.append("socialRequest.requestId DESC");
2432
2433                Query q = session.createQuery(query.toString());
2434
2435                QueryPos qPos = QueryPos.getInstance(q);
2436
2437                qPos.add(userId);
2438
2439                qPos.add(classNameId);
2440
2441                qPos.add(classPK);
2442
2443                qPos.add(type);
2444
2445                qPos.add(receiverUserId);
2446
2447                List<SocialRequest> list = q.list();
2448
2449                result = list;
2450
2451                SocialRequest socialRequest = null;
2452
2453                if (list.isEmpty()) {
2454                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C_T_R,
2455                        finderArgs, list);
2456                }
2457                else {
2458                    socialRequest = list.get(0);
2459
2460                    cacheResult(socialRequest);
2461
2462                    if ((socialRequest.getUserId() != userId) ||
2463                            (socialRequest.getClassNameId() != classNameId) ||
2464                            (socialRequest.getClassPK() != classPK) ||
2465                            (socialRequest.getType() != type) ||
2466                            (socialRequest.getReceiverUserId() != receiverUserId)) {
2467                        FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C_T_R,
2468                            finderArgs, socialRequest);
2469                    }
2470                }
2471
2472                return socialRequest;
2473            }
2474            catch (Exception e) {
2475                throw processException(e);
2476            }
2477            finally {
2478                if (result == null) {
2479                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C_T_R,
2480                        finderArgs, new ArrayList<SocialRequest>());
2481                }
2482
2483                closeSession(session);
2484            }
2485        }
2486        else {
2487            if (result instanceof List) {
2488                return null;
2489            }
2490            else {
2491                return (SocialRequest)result;
2492            }
2493        }
2494    }
2495
2496    public List<SocialRequest> findByU_C_C_T_S(long userId, long classNameId,
2497        long classPK, int type, int status) throws SystemException {
2498        Object[] finderArgs = new Object[] {
2499                new Long(userId), new Long(classNameId), new Long(classPK),
2500                new Integer(type), new Integer(status)
2501            };
2502
2503        List<SocialRequest> list = (List<SocialRequest>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_U_C_C_T_S,
2504                finderArgs, this);
2505
2506        if (list == null) {
2507            Session session = null;
2508
2509            try {
2510                session = openSession();
2511
2512                StringBuilder query = new StringBuilder();
2513
2514                query.append(
2515                    "SELECT socialRequest FROM SocialRequest socialRequest WHERE ");
2516
2517                query.append("socialRequest.userId = ?");
2518
2519                query.append(" AND ");
2520
2521                query.append("socialRequest.classNameId = ?");
2522
2523                query.append(" AND ");
2524
2525                query.append("socialRequest.classPK = ?");
2526
2527                query.append(" AND ");
2528
2529                query.append("socialRequest.type = ?");
2530
2531                query.append(" AND ");
2532
2533                query.append("socialRequest.status = ?");
2534
2535                query.append(" ");
2536
2537                query.append("ORDER BY ");
2538
2539                query.append("socialRequest.requestId DESC");
2540
2541                Query q = session.createQuery(query.toString());
2542
2543                QueryPos qPos = QueryPos.getInstance(q);
2544
2545                qPos.add(userId);
2546
2547                qPos.add(classNameId);
2548
2549                qPos.add(classPK);
2550
2551                qPos.add(type);
2552
2553                qPos.add(status);
2554
2555                list = q.list();
2556            }
2557            catch (Exception e) {
2558                throw processException(e);
2559            }
2560            finally {
2561                if (list == null) {
2562                    list = new ArrayList<SocialRequest>();
2563                }
2564
2565                cacheResult(list);
2566
2567                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_U_C_C_T_S,
2568                    finderArgs, list);
2569
2570                closeSession(session);
2571            }
2572        }
2573
2574        return list;
2575    }
2576
2577    public List<SocialRequest> findByU_C_C_T_S(long userId, long classNameId,
2578        long classPK, int type, int status, int start, int end)
2579        throws SystemException {
2580        return findByU_C_C_T_S(userId, classNameId, classPK, type, status,
2581            start, end, null);
2582    }
2583
2584    public List<SocialRequest> findByU_C_C_T_S(long userId, long classNameId,
2585        long classPK, int type, int status, int start, int end,
2586        OrderByComparator obc) throws SystemException {
2587        Object[] finderArgs = new Object[] {
2588                new Long(userId), new Long(classNameId), new Long(classPK),
2589                new Integer(type), new Integer(status),
2590                
2591                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
2592            };
2593
2594        List<SocialRequest> list = (List<SocialRequest>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_U_C_C_T_S,
2595                finderArgs, this);
2596
2597        if (list == null) {
2598            Session session = null;
2599
2600            try {
2601                session = openSession();
2602
2603                StringBuilder query = new StringBuilder();
2604
2605                query.append(
2606                    "SELECT socialRequest FROM SocialRequest socialRequest WHERE ");
2607
2608                query.append("socialRequest.userId = ?");
2609
2610                query.append(" AND ");
2611
2612                query.append("socialRequest.classNameId = ?");
2613
2614                query.append(" AND ");
2615
2616                query.append("socialRequest.classPK = ?");
2617
2618                query.append(" AND ");
2619
2620                query.append("socialRequest.type = ?");
2621
2622                query.append(" AND ");
2623
2624                query.append("socialRequest.status = ?");
2625
2626                query.append(" ");
2627
2628                if (obc != null) {
2629                    query.append("ORDER BY ");
2630
2631                    String[] orderByFields = obc.getOrderByFields();
2632
2633                    for (int i = 0; i < orderByFields.length; i++) {
2634                        query.append("socialRequest.");
2635                        query.append(orderByFields[i]);
2636
2637                        if (obc.isAscending()) {
2638                            query.append(" ASC");
2639                        }
2640                        else {
2641                            query.append(" DESC");
2642                        }
2643
2644                        if ((i + 1) < orderByFields.length) {
2645                            query.append(", ");
2646                        }
2647                    }
2648                }
2649
2650                else {
2651                    query.append("ORDER BY ");
2652
2653                    query.append("socialRequest.requestId DESC");
2654                }
2655
2656                Query q = session.createQuery(query.toString());
2657
2658                QueryPos qPos = QueryPos.getInstance(q);
2659
2660                qPos.add(userId);
2661
2662                qPos.add(classNameId);
2663
2664                qPos.add(classPK);
2665
2666                qPos.add(type);
2667
2668                qPos.add(status);
2669
2670                list = (List<SocialRequest>)QueryUtil.list(q, getDialect(),
2671                        start, end);
2672            }
2673            catch (Exception e) {
2674                throw processException(e);
2675            }
2676            finally {
2677                if (list == null) {
2678                    list = new ArrayList<SocialRequest>();
2679                }
2680
2681                cacheResult(list);
2682
2683                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_U_C_C_T_S,
2684                    finderArgs, list);
2685
2686                closeSession(session);
2687            }
2688        }
2689
2690        return list;
2691    }
2692
2693    public SocialRequest findByU_C_C_T_S_First(long userId, long classNameId,
2694        long classPK, int type, int status, OrderByComparator obc)
2695        throws NoSuchRequestException, SystemException {
2696        List<SocialRequest> list = findByU_C_C_T_S(userId, classNameId,
2697                classPK, type, status, 0, 1, obc);
2698
2699        if (list.isEmpty()) {
2700            StringBuilder msg = new StringBuilder();
2701
2702            msg.append("No SocialRequest exists with the key {");
2703
2704            msg.append("userId=" + userId);
2705
2706            msg.append(", ");
2707            msg.append("classNameId=" + classNameId);
2708
2709            msg.append(", ");
2710            msg.append("classPK=" + classPK);
2711
2712            msg.append(", ");
2713            msg.append("type=" + type);
2714
2715            msg.append(", ");
2716            msg.append("status=" + status);
2717
2718            msg.append(StringPool.CLOSE_CURLY_BRACE);
2719
2720            throw new NoSuchRequestException(msg.toString());
2721        }
2722        else {
2723            return list.get(0);
2724        }
2725    }
2726
2727    public SocialRequest findByU_C_C_T_S_Last(long userId, long classNameId,
2728        long classPK, int type, int status, OrderByComparator obc)
2729        throws NoSuchRequestException, SystemException {
2730        int count = countByU_C_C_T_S(userId, classNameId, classPK, type, status);
2731
2732        List<SocialRequest> list = findByU_C_C_T_S(userId, classNameId,
2733                classPK, type, status, count - 1, count, obc);
2734
2735        if (list.isEmpty()) {
2736            StringBuilder msg = new StringBuilder();
2737
2738            msg.append("No SocialRequest exists with the key {");
2739
2740            msg.append("userId=" + userId);
2741
2742            msg.append(", ");
2743            msg.append("classNameId=" + classNameId);
2744
2745            msg.append(", ");
2746            msg.append("classPK=" + classPK);
2747
2748            msg.append(", ");
2749            msg.append("type=" + type);
2750
2751            msg.append(", ");
2752            msg.append("status=" + status);
2753
2754            msg.append(StringPool.CLOSE_CURLY_BRACE);
2755
2756            throw new NoSuchRequestException(msg.toString());
2757        }
2758        else {
2759            return list.get(0);
2760        }
2761    }
2762
2763    public SocialRequest[] findByU_C_C_T_S_PrevAndNext(long requestId,
2764        long userId, long classNameId, long classPK, int type, int status,
2765        OrderByComparator obc) throws NoSuchRequestException, SystemException {
2766        SocialRequest socialRequest = findByPrimaryKey(requestId);
2767
2768        int count = countByU_C_C_T_S(userId, classNameId, classPK, type, status);
2769
2770        Session session = null;
2771
2772        try {
2773            session = openSession();
2774
2775            StringBuilder query = new StringBuilder();
2776
2777            query.append(
2778                "SELECT socialRequest FROM SocialRequest socialRequest WHERE ");
2779
2780            query.append("socialRequest.userId = ?");
2781
2782            query.append(" AND ");
2783
2784            query.append("socialRequest.classNameId = ?");
2785
2786            query.append(" AND ");
2787
2788            query.append("socialRequest.classPK = ?");
2789
2790            query.append(" AND ");
2791
2792            query.append("socialRequest.type = ?");
2793
2794            query.append(" AND ");
2795
2796            query.append("socialRequest.status = ?");
2797
2798            query.append(" ");
2799
2800            if (obc != null) {
2801                query.append("ORDER BY ");
2802
2803                String[] orderByFields = obc.getOrderByFields();
2804
2805                for (int i = 0; i < orderByFields.length; i++) {
2806                    query.append("socialRequest.");
2807                    query.append(orderByFields[i]);
2808
2809                    if (obc.isAscending()) {
2810                        query.append(" ASC");
2811                    }
2812                    else {
2813                        query.append(" DESC");
2814                    }
2815
2816                    if ((i + 1) < orderByFields.length) {
2817                        query.append(", ");
2818                    }
2819                }
2820            }
2821
2822            else {
2823                query.append("ORDER BY ");
2824
2825                query.append("socialRequest.requestId DESC");
2826            }
2827
2828            Query q = session.createQuery(query.toString());
2829
2830            QueryPos qPos = QueryPos.getInstance(q);
2831
2832            qPos.add(userId);
2833
2834            qPos.add(classNameId);
2835
2836            qPos.add(classPK);
2837
2838            qPos.add(type);
2839
2840            qPos.add(status);
2841
2842            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
2843                    socialRequest);
2844
2845            SocialRequest[] array = new SocialRequestImpl[3];
2846
2847            array[0] = (SocialRequest)objArray[0];
2848            array[1] = (SocialRequest)objArray[1];
2849            array[2] = (SocialRequest)objArray[2];
2850
2851            return array;
2852        }
2853        catch (Exception e) {
2854            throw processException(e);
2855        }
2856        finally {
2857            closeSession(session);
2858        }
2859    }
2860
2861    public List<SocialRequest> findByC_C_T_R_S(long classNameId, long classPK,
2862        int type, long receiverUserId, int status) throws SystemException {
2863        Object[] finderArgs = new Object[] {
2864                new Long(classNameId), new Long(classPK), new Integer(type),
2865                new Long(receiverUserId), new Integer(status)
2866            };
2867
2868        List<SocialRequest> list = (List<SocialRequest>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_C_T_R_S,
2869                finderArgs, this);
2870
2871        if (list == null) {
2872            Session session = null;
2873
2874            try {
2875                session = openSession();
2876
2877                StringBuilder query = new StringBuilder();
2878
2879                query.append(
2880                    "SELECT socialRequest FROM SocialRequest socialRequest WHERE ");
2881
2882                query.append("socialRequest.classNameId = ?");
2883
2884                query.append(" AND ");
2885
2886                query.append("socialRequest.classPK = ?");
2887
2888                query.append(" AND ");
2889
2890                query.append("socialRequest.type = ?");
2891
2892                query.append(" AND ");
2893
2894                query.append("socialRequest.receiverUserId = ?");
2895
2896                query.append(" AND ");
2897
2898                query.append("socialRequest.status = ?");
2899
2900                query.append(" ");
2901
2902                query.append("ORDER BY ");
2903
2904                query.append("socialRequest.requestId DESC");
2905
2906                Query q = session.createQuery(query.toString());
2907
2908                QueryPos qPos = QueryPos.getInstance(q);
2909
2910                qPos.add(classNameId);
2911
2912                qPos.add(classPK);
2913
2914                qPos.add(type);
2915
2916                qPos.add(receiverUserId);
2917
2918                qPos.add(status);
2919
2920                list = q.list();
2921            }
2922            catch (Exception e) {
2923                throw processException(e);
2924            }
2925            finally {
2926                if (list == null) {
2927                    list = new ArrayList<SocialRequest>();
2928                }
2929
2930                cacheResult(list);
2931
2932                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_C_T_R_S,
2933                    finderArgs, list);
2934
2935                closeSession(session);
2936            }
2937        }
2938
2939        return list;
2940    }
2941
2942    public List<SocialRequest> findByC_C_T_R_S(long classNameId, long classPK,
2943        int type, long receiverUserId, int status, int start, int end)
2944        throws SystemException {
2945        return findByC_C_T_R_S(classNameId, classPK, type, receiverUserId,
2946            status, start, end, null);
2947    }
2948
2949    public List<SocialRequest> findByC_C_T_R_S(long classNameId, long classPK,
2950        int type, long receiverUserId, int status, int start, int end,
2951        OrderByComparator obc) throws SystemException {
2952        Object[] finderArgs = new Object[] {
2953                new Long(classNameId), new Long(classPK), new Integer(type),
2954                new Long(receiverUserId), new Integer(status),
2955                
2956                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
2957            };
2958
2959        List<SocialRequest> list = (List<SocialRequest>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_C_C_T_R_S,
2960                finderArgs, this);
2961
2962        if (list == null) {
2963            Session session = null;
2964
2965            try {
2966                session = openSession();
2967
2968                StringBuilder query = new StringBuilder();
2969
2970                query.append(
2971                    "SELECT socialRequest FROM SocialRequest socialRequest WHERE ");
2972
2973                query.append("socialRequest.classNameId = ?");
2974
2975                query.append(" AND ");
2976
2977                query.append("socialRequest.classPK = ?");
2978
2979                query.append(" AND ");
2980
2981                query.append("socialRequest.type = ?");
2982
2983                query.append(" AND ");
2984
2985                query.append("socialRequest.receiverUserId = ?");
2986
2987                query.append(" AND ");
2988
2989                query.append("socialRequest.status = ?");
2990
2991                query.append(" ");
2992
2993                if (obc != null) {
2994                    query.append("ORDER BY ");
2995
2996                    String[] orderByFields = obc.getOrderByFields();
2997
2998                    for (int i = 0; i < orderByFields.length; i++) {
2999                        query.append("socialRequest.");
3000                        query.append(orderByFields[i]);
3001
3002                        if (obc.isAscending()) {
3003                            query.append(" ASC");
3004                        }
3005                        else {
3006                            query.append(" DESC");
3007                        }
3008
3009                        if ((i + 1) < orderByFields.length) {
3010                            query.append(", ");
3011                        }
3012                    }
3013                }
3014
3015                else {
3016                    query.append("ORDER BY ");
3017
3018                    query.append("socialRequest.requestId DESC");
3019                }
3020
3021                Query q = session.createQuery(query.toString());
3022
3023                QueryPos qPos = QueryPos.getInstance(q);
3024
3025                qPos.add(classNameId);
3026
3027                qPos.add(classPK);
3028
3029                qPos.add(type);
3030
3031                qPos.add(receiverUserId);
3032
3033                qPos.add(status);
3034
3035                list = (List<SocialRequest>)QueryUtil.list(q, getDialect(),
3036                        start, end);
3037            }
3038            catch (Exception e) {
3039                throw processException(e);
3040            }
3041            finally {
3042                if (list == null) {
3043                    list = new ArrayList<SocialRequest>();
3044                }
3045
3046                cacheResult(list);
3047
3048                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_C_C_T_R_S,
3049                    finderArgs, list);
3050
3051                closeSession(session);
3052            }
3053        }
3054
3055        return list;
3056    }
3057
3058    public SocialRequest findByC_C_T_R_S_First(long classNameId, long classPK,
3059        int type, long receiverUserId, int status, OrderByComparator obc)
3060        throws NoSuchRequestException, SystemException {
3061        List<SocialRequest> list = findByC_C_T_R_S(classNameId, classPK, type,
3062                receiverUserId, status, 0, 1, obc);
3063
3064        if (list.isEmpty()) {
3065            StringBuilder msg = new StringBuilder();
3066
3067            msg.append("No SocialRequest exists with the key {");
3068
3069            msg.append("classNameId=" + classNameId);
3070
3071            msg.append(", ");
3072            msg.append("classPK=" + classPK);
3073
3074            msg.append(", ");
3075            msg.append("type=" + type);
3076
3077            msg.append(", ");
3078            msg.append("receiverUserId=" + receiverUserId);
3079
3080            msg.append(", ");
3081            msg.append("status=" + status);
3082
3083            msg.append(StringPool.CLOSE_CURLY_BRACE);
3084
3085            throw new NoSuchRequestException(msg.toString());
3086        }
3087        else {
3088            return list.get(0);
3089        }
3090    }
3091
3092    public SocialRequest findByC_C_T_R_S_Last(long classNameId, long classPK,
3093        int type, long receiverUserId, int status, OrderByComparator obc)
3094        throws NoSuchRequestException, SystemException {
3095        int count = countByC_C_T_R_S(classNameId, classPK, type,
3096                receiverUserId, status);
3097
3098        List<SocialRequest> list = findByC_C_T_R_S(classNameId, classPK, type,
3099                receiverUserId, status, count - 1, count, obc);
3100
3101        if (list.isEmpty()) {
3102            StringBuilder msg = new StringBuilder();
3103
3104            msg.append("No SocialRequest exists with the key {");
3105
3106            msg.append("classNameId=" + classNameId);
3107
3108            msg.append(", ");
3109            msg.append("classPK=" + classPK);
3110
3111            msg.append(", ");
3112            msg.append("type=" + type);
3113
3114            msg.append(", ");
3115            msg.append("receiverUserId=" + receiverUserId);
3116
3117            msg.append(", ");
3118            msg.append("status=" + status);
3119
3120            msg.append(StringPool.CLOSE_CURLY_BRACE);
3121
3122            throw new NoSuchRequestException(msg.toString());
3123        }
3124        else {
3125            return list.get(0);
3126        }
3127    }
3128
3129    public SocialRequest[] findByC_C_T_R_S_PrevAndNext(long requestId,
3130        long classNameId, long classPK, int type, long receiverUserId,
3131        int status, OrderByComparator obc)
3132        throws NoSuchRequestException, SystemException {
3133        SocialRequest socialRequest = findByPrimaryKey(requestId);
3134
3135        int count = countByC_C_T_R_S(classNameId, classPK, type,
3136                receiverUserId, status);
3137
3138        Session session = null;
3139
3140        try {
3141            session = openSession();
3142
3143            StringBuilder query = new StringBuilder();
3144
3145            query.append(
3146                "SELECT socialRequest FROM SocialRequest socialRequest WHERE ");
3147
3148            query.append("socialRequest.classNameId = ?");
3149
3150            query.append(" AND ");
3151
3152            query.append("socialRequest.classPK = ?");
3153
3154            query.append(" AND ");
3155
3156            query.append("socialRequest.type = ?");
3157
3158            query.append(" AND ");
3159
3160            query.append("socialRequest.receiverUserId = ?");
3161
3162            query.append(" AND ");
3163
3164            query.append("socialRequest.status = ?");
3165
3166            query.append(" ");
3167
3168            if (obc != null) {
3169                query.append("ORDER BY ");
3170
3171                String[] orderByFields = obc.getOrderByFields();
3172
3173                for (int i = 0; i < orderByFields.length; i++) {
3174                    query.append("socialRequest.");
3175                    query.append(orderByFields[i]);
3176
3177                    if (obc.isAscending()) {
3178                        query.append(" ASC");
3179                    }
3180                    else {
3181                        query.append(" DESC");
3182                    }
3183
3184                    if ((i + 1) < orderByFields.length) {
3185                        query.append(", ");
3186                    }
3187                }
3188            }
3189
3190            else {
3191                query.append("ORDER BY ");
3192
3193                query.append("socialRequest.requestId DESC");
3194            }
3195
3196            Query q = session.createQuery(query.toString());
3197
3198            QueryPos qPos = QueryPos.getInstance(q);
3199
3200            qPos.add(classNameId);
3201
3202            qPos.add(classPK);
3203
3204            qPos.add(type);
3205
3206            qPos.add(receiverUserId);
3207
3208            qPos.add(status);
3209
3210            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
3211                    socialRequest);
3212
3213            SocialRequest[] array = new SocialRequestImpl[3];
3214
3215            array[0] = (SocialRequest)objArray[0];
3216            array[1] = (SocialRequest)objArray[1];
3217            array[2] = (SocialRequest)objArray[2];
3218
3219            return array;
3220        }
3221        catch (Exception e) {
3222            throw processException(e);
3223        }
3224        finally {
3225            closeSession(session);
3226        }
3227    }
3228
3229    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
3230        throws SystemException {
3231        Session session = null;
3232
3233        try {
3234            session = openSession();
3235
3236            dynamicQuery.compile(session);
3237
3238            return dynamicQuery.list();
3239        }
3240        catch (Exception e) {
3241            throw processException(e);
3242        }
3243        finally {
3244            closeSession(session);
3245        }
3246    }
3247
3248    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
3249        int start, int end) throws SystemException {
3250        Session session = null;
3251
3252        try {
3253            session = openSession();
3254
3255            dynamicQuery.setLimit(start, end);
3256
3257            dynamicQuery.compile(session);
3258
3259            return dynamicQuery.list();
3260        }
3261        catch (Exception e) {
3262            throw processException(e);
3263        }
3264        finally {
3265            closeSession(session);
3266        }
3267    }
3268
3269    public List<SocialRequest> findAll() throws SystemException {
3270        return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3271    }
3272
3273    public List<SocialRequest> findAll(int start, int end)
3274        throws SystemException {
3275        return findAll(start, end, null);
3276    }
3277
3278    public List<SocialRequest> findAll(int start, int end, OrderByComparator obc)
3279        throws SystemException {
3280        Object[] finderArgs = new Object[] {
3281                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
3282            };
3283
3284        List<SocialRequest> list = (List<SocialRequest>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
3285                finderArgs, this);
3286
3287        if (list == null) {
3288            Session session = null;
3289
3290            try {
3291                session = openSession();
3292
3293                StringBuilder query = new StringBuilder();
3294
3295                query.append(
3296                    "SELECT socialRequest FROM SocialRequest socialRequest ");
3297
3298                if (obc != null) {
3299                    query.append("ORDER BY ");
3300
3301                    String[] orderByFields = obc.getOrderByFields();
3302
3303                    for (int i = 0; i < orderByFields.length; i++) {
3304                        query.append("socialRequest.");
3305                        query.append(orderByFields[i]);
3306
3307                        if (obc.isAscending()) {
3308                            query.append(" ASC");
3309                        }
3310                        else {
3311                            query.append(" DESC");
3312                        }
3313
3314                        if ((i + 1) < orderByFields.length) {
3315                            query.append(", ");
3316                        }
3317                    }
3318                }
3319
3320                else {
3321                    query.append("ORDER BY ");
3322
3323                    query.append("socialRequest.requestId DESC");
3324                }
3325
3326                Query q = session.createQuery(query.toString());
3327
3328                if (obc == null) {
3329                    list = (List<SocialRequest>)QueryUtil.list(q, getDialect(),
3330                            start, end, false);
3331
3332                    Collections.sort(list);
3333                }
3334                else {
3335                    list = (List<SocialRequest>)QueryUtil.list(q, getDialect(),
3336                            start, end);
3337                }
3338            }
3339            catch (Exception e) {
3340                throw processException(e);
3341            }
3342            finally {
3343                if (list == null) {
3344                    list = new ArrayList<SocialRequest>();
3345                }
3346
3347                cacheResult(list);
3348
3349                FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
3350
3351                closeSession(session);
3352            }
3353        }
3354
3355        return list;
3356    }
3357
3358    public void removeByUuid(String uuid) throws SystemException {
3359        for (SocialRequest socialRequest : findByUuid(uuid)) {
3360            remove(socialRequest);
3361        }
3362    }
3363
3364    public void removeByUUID_G(String uuid, long groupId)
3365        throws NoSuchRequestException, SystemException {
3366        SocialRequest socialRequest = findByUUID_G(uuid, groupId);
3367
3368        remove(socialRequest);
3369    }
3370
3371    public void removeByCompanyId(long companyId) throws SystemException {
3372        for (SocialRequest socialRequest : findByCompanyId(companyId)) {
3373            remove(socialRequest);
3374        }
3375    }
3376
3377    public void removeByUserId(long userId) throws SystemException {
3378        for (SocialRequest socialRequest : findByUserId(userId)) {
3379            remove(socialRequest);
3380        }
3381    }
3382
3383    public void removeByReceiverUserId(long receiverUserId)
3384        throws SystemException {
3385        for (SocialRequest socialRequest : findByReceiverUserId(receiverUserId)) {
3386            remove(socialRequest);
3387        }
3388    }
3389
3390    public void removeByU_S(long userId, int status) throws SystemException {
3391        for (SocialRequest socialRequest : findByU_S(userId, status)) {
3392            remove(socialRequest);
3393        }
3394    }
3395
3396    public void removeByR_S(long receiverUserId, int status)
3397        throws SystemException {
3398        for (SocialRequest socialRequest : findByR_S(receiverUserId, status)) {
3399            remove(socialRequest);
3400        }
3401    }
3402
3403    public void removeByU_C_C_T_R(long userId, long classNameId, long classPK,
3404        int type, long receiverUserId)
3405        throws NoSuchRequestException, SystemException {
3406        SocialRequest socialRequest = findByU_C_C_T_R(userId, classNameId,
3407                classPK, type, receiverUserId);
3408
3409        remove(socialRequest);
3410    }
3411
3412    public void removeByU_C_C_T_S(long userId, long classNameId, long classPK,
3413        int type, int status) throws SystemException {
3414        for (SocialRequest socialRequest : findByU_C_C_T_S(userId, classNameId,
3415                classPK, type, status)) {
3416            remove(socialRequest);
3417        }
3418    }
3419
3420    public void removeByC_C_T_R_S(long classNameId, long classPK, int type,
3421        long receiverUserId, int status) throws SystemException {
3422        for (SocialRequest socialRequest : findByC_C_T_R_S(classNameId,
3423                classPK, type, receiverUserId, status)) {
3424            remove(socialRequest);
3425        }
3426    }
3427
3428    public void removeAll() throws SystemException {
3429        for (SocialRequest socialRequest : findAll()) {
3430            remove(socialRequest);
3431        }
3432    }
3433
3434    public int countByUuid(String uuid) throws SystemException {
3435        Object[] finderArgs = new Object[] { uuid };
3436
3437        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
3438                finderArgs, this);
3439
3440        if (count == null) {
3441            Session session = null;
3442
3443            try {
3444                session = openSession();
3445
3446                StringBuilder query = new StringBuilder();
3447
3448                query.append("SELECT COUNT(socialRequest) ");
3449                query.append("FROM SocialRequest socialRequest WHERE ");
3450
3451                if (uuid == null) {
3452                    query.append("socialRequest.uuid IS NULL");
3453                }
3454                else {
3455                    query.append("socialRequest.uuid = ?");
3456                }
3457
3458                query.append(" ");
3459
3460                Query q = session.createQuery(query.toString());
3461
3462                QueryPos qPos = QueryPos.getInstance(q);
3463
3464                if (uuid != null) {
3465                    qPos.add(uuid);
3466                }
3467
3468                count = (Long)q.uniqueResult();
3469            }
3470            catch (Exception e) {
3471                throw processException(e);
3472            }
3473            finally {
3474                if (count == null) {
3475                    count = Long.valueOf(0);
3476                }
3477
3478                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
3479                    finderArgs, count);
3480
3481                closeSession(session);
3482            }
3483        }
3484
3485        return count.intValue();
3486    }
3487
3488    public int countByUUID_G(String uuid, long groupId)
3489        throws SystemException {
3490        Object[] finderArgs = new Object[] { uuid, new Long(groupId) };
3491
3492        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
3493                finderArgs, this);
3494
3495        if (count == null) {
3496            Session session = null;
3497
3498            try {
3499                session = openSession();
3500
3501                StringBuilder query = new StringBuilder();
3502
3503                query.append("SELECT COUNT(socialRequest) ");
3504                query.append("FROM SocialRequest socialRequest WHERE ");
3505
3506                if (uuid == null) {
3507                    query.append("socialRequest.uuid IS NULL");
3508                }
3509                else {
3510                    query.append("socialRequest.uuid = ?");
3511                }
3512
3513                query.append(" AND ");
3514
3515                query.append("socialRequest.groupId = ?");
3516
3517                query.append(" ");
3518
3519                Query q = session.createQuery(query.toString());
3520
3521                QueryPos qPos = QueryPos.getInstance(q);
3522
3523                if (uuid != null) {
3524                    qPos.add(uuid);
3525                }
3526
3527                qPos.add(groupId);
3528
3529                count = (Long)q.uniqueResult();
3530            }
3531            catch (Exception e) {
3532                throw processException(e);
3533            }
3534            finally {
3535                if (count == null) {
3536                    count = Long.valueOf(0);
3537                }
3538
3539                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
3540                    finderArgs, count);
3541
3542                closeSession(session);
3543            }
3544        }
3545
3546        return count.intValue();
3547    }
3548
3549    public int countByCompanyId(long companyId) throws SystemException {
3550        Object[] finderArgs = new Object[] { new Long(companyId) };
3551
3552        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
3553                finderArgs, this);
3554
3555        if (count == null) {
3556            Session session = null;
3557
3558            try {
3559                session = openSession();
3560
3561                StringBuilder query = new StringBuilder();
3562
3563                query.append("SELECT COUNT(socialRequest) ");
3564                query.append("FROM SocialRequest socialRequest WHERE ");
3565
3566                query.append("socialRequest.companyId = ?");
3567
3568                query.append(" ");
3569
3570                Query q = session.createQuery(query.toString());
3571
3572                QueryPos qPos = QueryPos.getInstance(q);
3573
3574                qPos.add(companyId);
3575
3576                count = (Long)q.uniqueResult();
3577            }
3578            catch (Exception e) {
3579                throw processException(e);
3580            }
3581            finally {
3582                if (count == null) {
3583                    count = Long.valueOf(0);
3584                }
3585
3586                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
3587                    finderArgs, count);
3588
3589                closeSession(session);
3590            }
3591        }
3592
3593        return count.intValue();
3594    }
3595
3596    public int countByUserId(long userId) throws SystemException {
3597        Object[] finderArgs = new Object[] { new Long(userId) };
3598
3599        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID,
3600                finderArgs, this);
3601
3602        if (count == null) {
3603            Session session = null;
3604
3605            try {
3606                session = openSession();
3607
3608                StringBuilder query = new StringBuilder();
3609
3610                query.append("SELECT COUNT(socialRequest) ");
3611                query.append("FROM SocialRequest socialRequest WHERE ");
3612
3613                query.append("socialRequest.userId = ?");
3614
3615                query.append(" ");
3616
3617                Query q = session.createQuery(query.toString());
3618
3619                QueryPos qPos = QueryPos.getInstance(q);
3620
3621                qPos.add(userId);
3622
3623                count = (Long)q.uniqueResult();
3624            }
3625            catch (Exception e) {
3626                throw processException(e);
3627            }
3628            finally {
3629                if (count == null) {
3630                    count = Long.valueOf(0);
3631                }
3632
3633                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID,
3634                    finderArgs, count);
3635
3636                closeSession(session);
3637            }
3638        }
3639
3640        return count.intValue();
3641    }
3642
3643    public int countByReceiverUserId(long receiverUserId)
3644        throws SystemException {
3645        Object[] finderArgs = new Object[] { new Long(receiverUserId) };
3646
3647        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_RECEIVERUSERID,
3648                finderArgs, this);
3649
3650        if (count == null) {
3651            Session session = null;
3652
3653            try {
3654                session = openSession();
3655
3656                StringBuilder query = new StringBuilder();
3657
3658                query.append("SELECT COUNT(socialRequest) ");
3659                query.append("FROM SocialRequest socialRequest WHERE ");
3660
3661                query.append("socialRequest.receiverUserId = ?");
3662
3663                query.append(" ");
3664
3665                Query q = session.createQuery(query.toString());
3666
3667                QueryPos qPos = QueryPos.getInstance(q);
3668
3669                qPos.add(receiverUserId);
3670
3671                count = (Long)q.uniqueResult();
3672            }
3673            catch (Exception e) {
3674                throw processException(e);
3675            }
3676            finally {
3677                if (count == null) {
3678                    count = Long.valueOf(0);
3679                }
3680
3681                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_RECEIVERUSERID,
3682                    finderArgs, count);
3683
3684                closeSession(session);
3685            }
3686        }
3687
3688        return count.intValue();
3689    }
3690
3691    public int countByU_S(long userId, int status) throws SystemException {
3692        Object[] finderArgs = new Object[] { new Long(userId), new Integer(status) };
3693
3694        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U_S,
3695                finderArgs, this);
3696
3697        if (count == null) {
3698            Session session = null;
3699
3700            try {
3701                session = openSession();
3702
3703                StringBuilder query = new StringBuilder();
3704
3705                query.append("SELECT COUNT(socialRequest) ");
3706                query.append("FROM SocialRequest socialRequest WHERE ");
3707
3708                query.append("socialRequest.userId = ?");
3709
3710                query.append(" AND ");
3711
3712                query.append("socialRequest.status = ?");
3713
3714                query.append(" ");
3715
3716                Query q = session.createQuery(query.toString());
3717
3718                QueryPos qPos = QueryPos.getInstance(q);
3719
3720                qPos.add(userId);
3721
3722                qPos.add(status);
3723
3724                count = (Long)q.uniqueResult();
3725            }
3726            catch (Exception e) {
3727                throw processException(e);
3728            }
3729            finally {
3730                if (count == null) {
3731                    count = Long.valueOf(0);
3732                }
3733
3734                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_S, finderArgs,
3735                    count);
3736
3737                closeSession(session);
3738            }
3739        }
3740
3741        return count.intValue();
3742    }
3743
3744    public int countByR_S(long receiverUserId, int status)
3745        throws SystemException {
3746        Object[] finderArgs = new Object[] {
3747                new Long(receiverUserId), new Integer(status)
3748            };
3749
3750        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_R_S,
3751                finderArgs, this);
3752
3753        if (count == null) {
3754            Session session = null;
3755
3756            try {
3757                session = openSession();
3758
3759                StringBuilder query = new StringBuilder();
3760
3761                query.append("SELECT COUNT(socialRequest) ");
3762                query.append("FROM SocialRequest socialRequest WHERE ");
3763
3764                query.append("socialRequest.receiverUserId = ?");
3765
3766                query.append(" AND ");
3767
3768                query.append("socialRequest.status = ?");
3769
3770                query.append(" ");
3771
3772                Query q = session.createQuery(query.toString());
3773
3774                QueryPos qPos = QueryPos.getInstance(q);
3775
3776                qPos.add(receiverUserId);
3777
3778                qPos.add(status);
3779
3780                count = (Long)q.uniqueResult();
3781            }
3782            catch (Exception e) {
3783                throw processException(e);
3784            }
3785            finally {
3786                if (count == null) {
3787                    count = Long.valueOf(0);
3788                }
3789
3790                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_R_S, finderArgs,
3791                    count);
3792
3793                closeSession(session);
3794            }
3795        }
3796
3797        return count.intValue();
3798    }
3799
3800    public int countByU_C_C_T_R(long userId, long classNameId, long classPK,
3801        int type, long receiverUserId) throws SystemException {
3802        Object[] finderArgs = new Object[] {
3803                new Long(userId), new Long(classNameId), new Long(classPK),
3804                new Integer(type), new Long(receiverUserId)
3805            };
3806
3807        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U_C_C_T_R,
3808                finderArgs, this);
3809
3810        if (count == null) {
3811            Session session = null;
3812
3813            try {
3814                session = openSession();
3815
3816                StringBuilder query = new StringBuilder();
3817
3818                query.append("SELECT COUNT(socialRequest) ");
3819                query.append("FROM SocialRequest socialRequest WHERE ");
3820
3821                query.append("socialRequest.userId = ?");
3822
3823                query.append(" AND ");
3824
3825                query.append("socialRequest.classNameId = ?");
3826
3827                query.append(" AND ");
3828
3829                query.append("socialRequest.classPK = ?");
3830
3831                query.append(" AND ");
3832
3833                query.append("socialRequest.type = ?");
3834
3835                query.append(" AND ");
3836
3837                query.append("socialRequest.receiverUserId = ?");
3838
3839                query.append(" ");
3840
3841                Query q = session.createQuery(query.toString());
3842
3843                QueryPos qPos = QueryPos.getInstance(q);
3844
3845                qPos.add(userId);
3846
3847                qPos.add(classNameId);
3848
3849                qPos.add(classPK);
3850
3851                qPos.add(type);
3852
3853                qPos.add(receiverUserId);
3854
3855                count = (Long)q.uniqueResult();
3856            }
3857            catch (Exception e) {
3858                throw processException(e);
3859            }
3860            finally {
3861                if (count == null) {
3862                    count = Long.valueOf(0);
3863                }
3864
3865                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_C_C_T_R,
3866                    finderArgs, count);
3867
3868                closeSession(session);
3869            }
3870        }
3871
3872        return count.intValue();
3873    }
3874
3875    public int countByU_C_C_T_S(long userId, long classNameId, long classPK,
3876        int type, int status) throws SystemException {
3877        Object[] finderArgs = new Object[] {
3878                new Long(userId), new Long(classNameId), new Long(classPK),
3879                new Integer(type), new Integer(status)
3880            };
3881
3882        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U_C_C_T_S,
3883                finderArgs, this);
3884
3885        if (count == null) {
3886            Session session = null;
3887
3888            try {
3889                session = openSession();
3890
3891                StringBuilder query = new StringBuilder();
3892
3893                query.append("SELECT COUNT(socialRequest) ");
3894                query.append("FROM SocialRequest socialRequest WHERE ");
3895
3896                query.append("socialRequest.userId = ?");
3897
3898                query.append(" AND ");
3899
3900                query.append("socialRequest.classNameId = ?");
3901
3902                query.append(" AND ");
3903
3904                query.append("socialRequest.classPK = ?");
3905
3906                query.append(" AND ");
3907
3908                query.append("socialRequest.type = ?");
3909
3910                query.append(" AND ");
3911
3912                query.append("socialRequest.status = ?");
3913
3914                query.append(" ");
3915
3916                Query q = session.createQuery(query.toString());
3917
3918                QueryPos qPos = QueryPos.getInstance(q);
3919
3920                qPos.add(userId);
3921
3922                qPos.add(classNameId);
3923
3924                qPos.add(classPK);
3925
3926                qPos.add(type);
3927
3928                qPos.add(status);
3929
3930                count = (Long)q.uniqueResult();
3931            }
3932            catch (Exception e) {
3933                throw processException(e);
3934            }
3935            finally {
3936                if (count == null) {
3937                    count = Long.valueOf(0);
3938                }
3939
3940                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_C_C_T_S,
3941                    finderArgs, count);
3942
3943                closeSession(session);
3944            }
3945        }
3946
3947        return count.intValue();
3948    }
3949
3950    public int countByC_C_T_R_S(long classNameId, long classPK, int type,
3951        long receiverUserId, int status) throws SystemException {
3952        Object[] finderArgs = new Object[] {
3953                new Long(classNameId), new Long(classPK), new Integer(type),
3954                new Long(receiverUserId), new Integer(status)
3955            };
3956
3957        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C_T_R_S,
3958                finderArgs, this);
3959
3960        if (count == null) {
3961            Session session = null;
3962
3963            try {
3964                session = openSession();
3965
3966                StringBuilder query = new StringBuilder();
3967
3968                query.append("SELECT COUNT(socialRequest) ");
3969                query.append("FROM SocialRequest socialRequest WHERE ");
3970
3971                query.append("socialRequest.classNameId = ?");
3972
3973                query.append(" AND ");
3974
3975                query.append("socialRequest.classPK = ?");
3976
3977                query.append(" AND ");
3978
3979                query.append("socialRequest.type = ?");
3980
3981                query.append(" AND ");
3982
3983                query.append("socialRequest.receiverUserId = ?");
3984
3985                query.append(" AND ");
3986
3987                query.append("socialRequest.status = ?");
3988
3989                query.append(" ");
3990
3991                Query q = session.createQuery(query.toString());
3992
3993                QueryPos qPos = QueryPos.getInstance(q);
3994
3995                qPos.add(classNameId);
3996
3997                qPos.add(classPK);
3998
3999                qPos.add(type);
4000
4001                qPos.add(receiverUserId);
4002
4003                qPos.add(status);
4004
4005                count = (Long)q.uniqueResult();
4006            }
4007            catch (Exception e) {
4008                throw processException(e);
4009            }
4010            finally {
4011                if (count == null) {
4012                    count = Long.valueOf(0);
4013                }
4014
4015                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C_T_R_S,
4016                    finderArgs, count);
4017
4018                closeSession(session);
4019            }
4020        }
4021
4022        return count.intValue();
4023    }
4024
4025    public int countAll() throws SystemException {
4026        Object[] finderArgs = new Object[0];
4027
4028        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
4029                finderArgs, this);
4030
4031        if (count == null) {
4032            Session session = null;
4033
4034            try {
4035                session = openSession();
4036
4037                Query q = session.createQuery(
4038                        "SELECT COUNT(socialRequest) FROM SocialRequest socialRequest");
4039
4040                count = (Long)q.uniqueResult();
4041            }
4042            catch (Exception e) {
4043                throw processException(e);
4044            }
4045            finally {
4046                if (count == null) {
4047                    count = Long.valueOf(0);
4048                }
4049
4050                FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
4051                    count);
4052
4053                closeSession(session);
4054            }
4055        }
4056
4057        return count.intValue();
4058    }
4059
4060    public void afterPropertiesSet() {
4061        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
4062                    com.liferay.portal.util.PropsUtil.get(
4063                        "value.object.listener.com.liferay.portlet.social.model.SocialRequest")));
4064
4065        if (listenerClassNames.length > 0) {
4066            try {
4067                List<ModelListener<SocialRequest>> listenersList = new ArrayList<ModelListener<SocialRequest>>();
4068
4069                for (String listenerClassName : listenerClassNames) {
4070                    listenersList.add((ModelListener<SocialRequest>)Class.forName(
4071                            listenerClassName).newInstance());
4072                }
4073
4074                listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
4075            }
4076            catch (Exception e) {
4077                _log.error(e);
4078            }
4079        }
4080    }
4081
4082    @BeanReference(name = "com.liferay.portlet.social.service.persistence.SocialActivityPersistence.impl")
4083    protected com.liferay.portlet.social.service.persistence.SocialActivityPersistence socialActivityPersistence;
4084    @BeanReference(name = "com.liferay.portlet.social.service.persistence.SocialRelationPersistence.impl")
4085    protected com.liferay.portlet.social.service.persistence.SocialRelationPersistence socialRelationPersistence;
4086    @BeanReference(name = "com.liferay.portlet.social.service.persistence.SocialRequestPersistence.impl")
4087    protected com.liferay.portlet.social.service.persistence.SocialRequestPersistence socialRequestPersistence;
4088    @BeanReference(name = "com.liferay.portal.service.persistence.UserPersistence.impl")
4089    protected com.liferay.portal.service.persistence.UserPersistence userPersistence;
4090    private static Log _log = LogFactoryUtil.getLog(SocialRequestPersistenceImpl.class);
4091}