001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.social.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.kernel.bean.BeanReference;
019    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderPath;
023    import com.liferay.portal.kernel.dao.orm.Query;
024    import com.liferay.portal.kernel.dao.orm.QueryPos;
025    import com.liferay.portal.kernel.dao.orm.QueryUtil;
026    import com.liferay.portal.kernel.dao.orm.Session;
027    import com.liferay.portal.kernel.exception.SystemException;
028    import com.liferay.portal.kernel.log.Log;
029    import com.liferay.portal.kernel.log.LogFactoryUtil;
030    import com.liferay.portal.kernel.util.GetterUtil;
031    import com.liferay.portal.kernel.util.InstanceFactory;
032    import com.liferay.portal.kernel.util.OrderByComparator;
033    import com.liferay.portal.kernel.util.StringBundler;
034    import com.liferay.portal.kernel.util.StringPool;
035    import com.liferay.portal.kernel.util.StringUtil;
036    import com.liferay.portal.kernel.util.Validator;
037    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
038    import com.liferay.portal.model.CacheModel;
039    import com.liferay.portal.model.ModelListener;
040    import com.liferay.portal.service.persistence.BatchSessionUtil;
041    import com.liferay.portal.service.persistence.ResourcePersistence;
042    import com.liferay.portal.service.persistence.UserPersistence;
043    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
044    
045    import com.liferay.portlet.social.NoSuchRequestException;
046    import com.liferay.portlet.social.model.SocialRequest;
047    import com.liferay.portlet.social.model.impl.SocialRequestImpl;
048    import com.liferay.portlet.social.model.impl.SocialRequestModelImpl;
049    
050    import java.io.Serializable;
051    
052    import java.util.ArrayList;
053    import java.util.Collections;
054    import java.util.List;
055    
056    /**
057     * The persistence implementation for the social request service.
058     *
059     * <p>
060     * Caching information and settings can be found in <code>portal.properties</code>
061     * </p>
062     *
063     * @author Brian Wing Shun Chan
064     * @see SocialRequestPersistence
065     * @see SocialRequestUtil
066     * @generated
067     */
068    public class SocialRequestPersistenceImpl extends BasePersistenceImpl<SocialRequest>
069            implements SocialRequestPersistence {
070            /*
071             * NOTE FOR DEVELOPERS:
072             *
073             * Never modify or reference this class directly. Always use {@link SocialRequestUtil} to access the social request persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
074             */
075            public static final String FINDER_CLASS_NAME_ENTITY = SocialRequestImpl.class.getName();
076            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
077                    ".List1";
078            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
079                    ".List2";
080            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
081                            SocialRequestModelImpl.FINDER_CACHE_ENABLED,
082                            SocialRequestImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
083                            "findByUuid",
084                            new String[] {
085                                    String.class.getName(),
086                                    
087                            "java.lang.Integer", "java.lang.Integer",
088                                    "com.liferay.portal.kernel.util.OrderByComparator"
089                            });
090            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
091                            SocialRequestModelImpl.FINDER_CACHE_ENABLED,
092                            SocialRequestImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
093                            "findByUuid", new String[] { String.class.getName() },
094                            SocialRequestModelImpl.UUID_COLUMN_BITMASK);
095            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
096                            SocialRequestModelImpl.FINDER_CACHE_ENABLED, Long.class,
097                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
098                            new String[] { String.class.getName() });
099            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
100                            SocialRequestModelImpl.FINDER_CACHE_ENABLED,
101                            SocialRequestImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
102                            new String[] { String.class.getName(), Long.class.getName() },
103                            SocialRequestModelImpl.UUID_COLUMN_BITMASK |
104                            SocialRequestModelImpl.GROUPID_COLUMN_BITMASK);
105            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
106                            SocialRequestModelImpl.FINDER_CACHE_ENABLED, Long.class,
107                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
108                            new String[] { String.class.getName(), Long.class.getName() });
109            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
110                    new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
111                            SocialRequestModelImpl.FINDER_CACHE_ENABLED,
112                            SocialRequestImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
113                            "findByCompanyId",
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_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
121                    new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
122                            SocialRequestModelImpl.FINDER_CACHE_ENABLED,
123                            SocialRequestImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
124                            "findByCompanyId", new String[] { Long.class.getName() },
125                            SocialRequestModelImpl.COMPANYID_COLUMN_BITMASK);
126            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
127                            SocialRequestModelImpl.FINDER_CACHE_ENABLED, Long.class,
128                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
129                            new String[] { Long.class.getName() });
130            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
131                            SocialRequestModelImpl.FINDER_CACHE_ENABLED,
132                            SocialRequestImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
133                            "findByUserId",
134                            new String[] {
135                                    Long.class.getName(),
136                                    
137                            "java.lang.Integer", "java.lang.Integer",
138                                    "com.liferay.portal.kernel.util.OrderByComparator"
139                            });
140            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID =
141                    new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
142                            SocialRequestModelImpl.FINDER_CACHE_ENABLED,
143                            SocialRequestImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
144                            "findByUserId", new String[] { Long.class.getName() },
145                            SocialRequestModelImpl.USERID_COLUMN_BITMASK);
146            public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
147                            SocialRequestModelImpl.FINDER_CACHE_ENABLED, Long.class,
148                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId",
149                            new String[] { Long.class.getName() });
150            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_RECEIVERUSERID =
151                    new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
152                            SocialRequestModelImpl.FINDER_CACHE_ENABLED,
153                            SocialRequestImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
154                            "findByReceiverUserId",
155                            new String[] {
156                                    Long.class.getName(),
157                                    
158                            "java.lang.Integer", "java.lang.Integer",
159                                    "com.liferay.portal.kernel.util.OrderByComparator"
160                            });
161            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RECEIVERUSERID =
162                    new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
163                            SocialRequestModelImpl.FINDER_CACHE_ENABLED,
164                            SocialRequestImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
165                            "findByReceiverUserId", new String[] { Long.class.getName() },
166                            SocialRequestModelImpl.RECEIVERUSERID_COLUMN_BITMASK);
167            public static final FinderPath FINDER_PATH_COUNT_BY_RECEIVERUSERID = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
168                            SocialRequestModelImpl.FINDER_CACHE_ENABLED, Long.class,
169                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByReceiverUserId",
170                            new String[] { Long.class.getName() });
171            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_S = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
172                            SocialRequestModelImpl.FINDER_CACHE_ENABLED,
173                            SocialRequestImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
174                            "findByU_S",
175                            new String[] {
176                                    Long.class.getName(), Integer.class.getName(),
177                                    
178                            "java.lang.Integer", "java.lang.Integer",
179                                    "com.liferay.portal.kernel.util.OrderByComparator"
180                            });
181            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_S = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
182                            SocialRequestModelImpl.FINDER_CACHE_ENABLED,
183                            SocialRequestImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
184                            "findByU_S",
185                            new String[] { Long.class.getName(), Integer.class.getName() },
186                            SocialRequestModelImpl.USERID_COLUMN_BITMASK |
187                            SocialRequestModelImpl.STATUS_COLUMN_BITMASK);
188            public static final FinderPath FINDER_PATH_COUNT_BY_U_S = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
189                            SocialRequestModelImpl.FINDER_CACHE_ENABLED, Long.class,
190                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_S",
191                            new String[] { Long.class.getName(), Integer.class.getName() });
192            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_R_S = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
193                            SocialRequestModelImpl.FINDER_CACHE_ENABLED,
194                            SocialRequestImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
195                            "findByR_S",
196                            new String[] {
197                                    Long.class.getName(), Integer.class.getName(),
198                                    
199                            "java.lang.Integer", "java.lang.Integer",
200                                    "com.liferay.portal.kernel.util.OrderByComparator"
201                            });
202            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_S = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
203                            SocialRequestModelImpl.FINDER_CACHE_ENABLED,
204                            SocialRequestImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
205                            "findByR_S",
206                            new String[] { Long.class.getName(), Integer.class.getName() },
207                            SocialRequestModelImpl.RECEIVERUSERID_COLUMN_BITMASK |
208                            SocialRequestModelImpl.STATUS_COLUMN_BITMASK);
209            public static final FinderPath FINDER_PATH_COUNT_BY_R_S = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
210                            SocialRequestModelImpl.FINDER_CACHE_ENABLED, Long.class,
211                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByR_S",
212                            new String[] { Long.class.getName(), Integer.class.getName() });
213            public static final FinderPath FINDER_PATH_FETCH_BY_U_C_C_T_R = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
214                            SocialRequestModelImpl.FINDER_CACHE_ENABLED,
215                            SocialRequestImpl.class, FINDER_CLASS_NAME_ENTITY,
216                            "fetchByU_C_C_T_R",
217                            new String[] {
218                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
219                                    Integer.class.getName(), Long.class.getName()
220                            },
221                            SocialRequestModelImpl.USERID_COLUMN_BITMASK |
222                            SocialRequestModelImpl.CLASSNAMEID_COLUMN_BITMASK |
223                            SocialRequestModelImpl.CLASSPK_COLUMN_BITMASK |
224                            SocialRequestModelImpl.TYPE_COLUMN_BITMASK |
225                            SocialRequestModelImpl.RECEIVERUSERID_COLUMN_BITMASK);
226            public static final FinderPath FINDER_PATH_COUNT_BY_U_C_C_T_R = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
227                            SocialRequestModelImpl.FINDER_CACHE_ENABLED, Long.class,
228                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C_C_T_R",
229                            new String[] {
230                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
231                                    Integer.class.getName(), Long.class.getName()
232                            });
233            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_C_T_S =
234                    new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
235                            SocialRequestModelImpl.FINDER_CACHE_ENABLED,
236                            SocialRequestImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
237                            "findByU_C_C_T_S",
238                            new String[] {
239                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
240                                    Integer.class.getName(), Integer.class.getName(),
241                                    
242                            "java.lang.Integer", "java.lang.Integer",
243                                    "com.liferay.portal.kernel.util.OrderByComparator"
244                            });
245            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_T_S =
246                    new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
247                            SocialRequestModelImpl.FINDER_CACHE_ENABLED,
248                            SocialRequestImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
249                            "findByU_C_C_T_S",
250                            new String[] {
251                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
252                                    Integer.class.getName(), Integer.class.getName()
253                            },
254                            SocialRequestModelImpl.USERID_COLUMN_BITMASK |
255                            SocialRequestModelImpl.CLASSNAMEID_COLUMN_BITMASK |
256                            SocialRequestModelImpl.CLASSPK_COLUMN_BITMASK |
257                            SocialRequestModelImpl.TYPE_COLUMN_BITMASK |
258                            SocialRequestModelImpl.STATUS_COLUMN_BITMASK);
259            public static final FinderPath FINDER_PATH_COUNT_BY_U_C_C_T_S = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
260                            SocialRequestModelImpl.FINDER_CACHE_ENABLED, Long.class,
261                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C_C_T_S",
262                            new String[] {
263                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
264                                    Integer.class.getName(), Integer.class.getName()
265                            });
266            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_T_R_S =
267                    new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
268                            SocialRequestModelImpl.FINDER_CACHE_ENABLED,
269                            SocialRequestImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
270                            "findByC_C_T_R_S",
271                            new String[] {
272                                    Long.class.getName(), Long.class.getName(),
273                                    Integer.class.getName(), Long.class.getName(),
274                                    Integer.class.getName(),
275                                    
276                            "java.lang.Integer", "java.lang.Integer",
277                                    "com.liferay.portal.kernel.util.OrderByComparator"
278                            });
279            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_T_R_S =
280                    new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
281                            SocialRequestModelImpl.FINDER_CACHE_ENABLED,
282                            SocialRequestImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
283                            "findByC_C_T_R_S",
284                            new String[] {
285                                    Long.class.getName(), Long.class.getName(),
286                                    Integer.class.getName(), Long.class.getName(),
287                                    Integer.class.getName()
288                            },
289                            SocialRequestModelImpl.CLASSNAMEID_COLUMN_BITMASK |
290                            SocialRequestModelImpl.CLASSPK_COLUMN_BITMASK |
291                            SocialRequestModelImpl.TYPE_COLUMN_BITMASK |
292                            SocialRequestModelImpl.RECEIVERUSERID_COLUMN_BITMASK |
293                            SocialRequestModelImpl.STATUS_COLUMN_BITMASK);
294            public static final FinderPath FINDER_PATH_COUNT_BY_C_C_T_R_S = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
295                            SocialRequestModelImpl.FINDER_CACHE_ENABLED, Long.class,
296                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C_T_R_S",
297                            new String[] {
298                                    Long.class.getName(), Long.class.getName(),
299                                    Integer.class.getName(), Long.class.getName(),
300                                    Integer.class.getName()
301                            });
302            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
303                            SocialRequestModelImpl.FINDER_CACHE_ENABLED,
304                            SocialRequestImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
305                            "findAll", new String[0]);
306            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
307                            SocialRequestModelImpl.FINDER_CACHE_ENABLED,
308                            SocialRequestImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
309                            "findAll", new String[0]);
310            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
311                            SocialRequestModelImpl.FINDER_CACHE_ENABLED, Long.class,
312                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
313    
314            /**
315             * Caches the social request in the entity cache if it is enabled.
316             *
317             * @param socialRequest the social request
318             */
319            public void cacheResult(SocialRequest socialRequest) {
320                    EntityCacheUtil.putResult(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
321                            SocialRequestImpl.class, socialRequest.getPrimaryKey(),
322                            socialRequest);
323    
324                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
325                            new Object[] {
326                                    socialRequest.getUuid(),
327                                    Long.valueOf(socialRequest.getGroupId())
328                            }, socialRequest);
329    
330                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C_T_R,
331                            new Object[] {
332                                    Long.valueOf(socialRequest.getUserId()),
333                                    Long.valueOf(socialRequest.getClassNameId()),
334                                    Long.valueOf(socialRequest.getClassPK()),
335                                    Integer.valueOf(socialRequest.getType()),
336                                    Long.valueOf(socialRequest.getReceiverUserId())
337                            }, socialRequest);
338    
339                    socialRequest.resetOriginalValues();
340            }
341    
342            /**
343             * Caches the social requests in the entity cache if it is enabled.
344             *
345             * @param socialRequests the social requests
346             */
347            public void cacheResult(List<SocialRequest> socialRequests) {
348                    for (SocialRequest socialRequest : socialRequests) {
349                            if (EntityCacheUtil.getResult(
350                                                    SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
351                                                    SocialRequestImpl.class, socialRequest.getPrimaryKey()) == null) {
352                                    cacheResult(socialRequest);
353                            }
354                            else {
355                                    socialRequest.resetOriginalValues();
356                            }
357                    }
358            }
359    
360            /**
361             * Clears the cache for all social requests.
362             *
363             * <p>
364             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
365             * </p>
366             */
367            @Override
368            public void clearCache() {
369                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
370                            CacheRegistryUtil.clear(SocialRequestImpl.class.getName());
371                    }
372    
373                    EntityCacheUtil.clearCache(SocialRequestImpl.class.getName());
374    
375                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
376                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
377                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
378            }
379    
380            /**
381             * Clears the cache for the social request.
382             *
383             * <p>
384             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
385             * </p>
386             */
387            @Override
388            public void clearCache(SocialRequest socialRequest) {
389                    EntityCacheUtil.removeResult(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
390                            SocialRequestImpl.class, socialRequest.getPrimaryKey());
391    
392                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
393                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
394    
395                    clearUniqueFindersCache(socialRequest);
396            }
397    
398            @Override
399            public void clearCache(List<SocialRequest> socialRequests) {
400                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
401                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
402    
403                    for (SocialRequest socialRequest : socialRequests) {
404                            EntityCacheUtil.removeResult(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
405                                    SocialRequestImpl.class, socialRequest.getPrimaryKey());
406    
407                            clearUniqueFindersCache(socialRequest);
408                    }
409            }
410    
411            protected void cacheUniqueFindersCache(SocialRequest socialRequest) {
412                    if (socialRequest.isNew()) {
413                            Object[] args = new Object[] {
414                                            socialRequest.getUuid(),
415                                            Long.valueOf(socialRequest.getGroupId())
416                                    };
417    
418                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
419                                    Long.valueOf(1));
420                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
421                                    socialRequest);
422    
423                            args = new Object[] {
424                                            Long.valueOf(socialRequest.getUserId()),
425                                            Long.valueOf(socialRequest.getClassNameId()),
426                                            Long.valueOf(socialRequest.getClassPK()),
427                                            Integer.valueOf(socialRequest.getType()),
428                                            Long.valueOf(socialRequest.getReceiverUserId())
429                                    };
430    
431                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_C_C_T_R, args,
432                                    Long.valueOf(1));
433                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C_T_R, args,
434                                    socialRequest);
435                    }
436                    else {
437                            SocialRequestModelImpl socialRequestModelImpl = (SocialRequestModelImpl)socialRequest;
438    
439                            if ((socialRequestModelImpl.getColumnBitmask() &
440                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
441                                    Object[] args = new Object[] {
442                                                    socialRequest.getUuid(),
443                                                    Long.valueOf(socialRequest.getGroupId())
444                                            };
445    
446                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
447                                            Long.valueOf(1));
448                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
449                                            socialRequest);
450                            }
451    
452                            if ((socialRequestModelImpl.getColumnBitmask() &
453                                            FINDER_PATH_FETCH_BY_U_C_C_T_R.getColumnBitmask()) != 0) {
454                                    Object[] args = new Object[] {
455                                                    Long.valueOf(socialRequest.getUserId()),
456                                                    Long.valueOf(socialRequest.getClassNameId()),
457                                                    Long.valueOf(socialRequest.getClassPK()),
458                                                    Integer.valueOf(socialRequest.getType()),
459                                                    Long.valueOf(socialRequest.getReceiverUserId())
460                                            };
461    
462                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_C_C_T_R, args,
463                                            Long.valueOf(1));
464                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C_T_R, args,
465                                            socialRequest);
466                            }
467                    }
468            }
469    
470            protected void clearUniqueFindersCache(SocialRequest socialRequest) {
471                    SocialRequestModelImpl socialRequestModelImpl = (SocialRequestModelImpl)socialRequest;
472    
473                    Object[] args = new Object[] {
474                                    socialRequest.getUuid(),
475                                    Long.valueOf(socialRequest.getGroupId())
476                            };
477    
478                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
479                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
480    
481                    if ((socialRequestModelImpl.getColumnBitmask() &
482                                    FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
483                            args = new Object[] {
484                                            socialRequestModelImpl.getOriginalUuid(),
485                                            Long.valueOf(socialRequestModelImpl.getOriginalGroupId())
486                                    };
487    
488                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
489                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
490                    }
491    
492                    args = new Object[] {
493                                    Long.valueOf(socialRequest.getUserId()),
494                                    Long.valueOf(socialRequest.getClassNameId()),
495                                    Long.valueOf(socialRequest.getClassPK()),
496                                    Integer.valueOf(socialRequest.getType()),
497                                    Long.valueOf(socialRequest.getReceiverUserId())
498                            };
499    
500                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_C_T_R, args);
501                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_C_C_T_R, args);
502    
503                    if ((socialRequestModelImpl.getColumnBitmask() &
504                                    FINDER_PATH_FETCH_BY_U_C_C_T_R.getColumnBitmask()) != 0) {
505                            args = new Object[] {
506                                            Long.valueOf(socialRequestModelImpl.getOriginalUserId()),
507                                            Long.valueOf(socialRequestModelImpl.getOriginalClassNameId()),
508                                            Long.valueOf(socialRequestModelImpl.getOriginalClassPK()),
509                                            Integer.valueOf(socialRequestModelImpl.getOriginalType()),
510                                            Long.valueOf(socialRequestModelImpl.getOriginalReceiverUserId())
511                                    };
512    
513                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_C_T_R, args);
514                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_C_C_T_R, args);
515                    }
516            }
517    
518            /**
519             * Creates a new social request with the primary key. Does not add the social request to the database.
520             *
521             * @param requestId the primary key for the new social request
522             * @return the new social request
523             */
524            public SocialRequest create(long requestId) {
525                    SocialRequest socialRequest = new SocialRequestImpl();
526    
527                    socialRequest.setNew(true);
528                    socialRequest.setPrimaryKey(requestId);
529    
530                    String uuid = PortalUUIDUtil.generate();
531    
532                    socialRequest.setUuid(uuid);
533    
534                    return socialRequest;
535            }
536    
537            /**
538             * Removes the social request with the primary key from the database. Also notifies the appropriate model listeners.
539             *
540             * @param requestId the primary key of the social request
541             * @return the social request that was removed
542             * @throws com.liferay.portlet.social.NoSuchRequestException if a social request with the primary key could not be found
543             * @throws SystemException if a system exception occurred
544             */
545            public SocialRequest remove(long requestId)
546                    throws NoSuchRequestException, SystemException {
547                    return remove(Long.valueOf(requestId));
548            }
549    
550            /**
551             * Removes the social request with the primary key from the database. Also notifies the appropriate model listeners.
552             *
553             * @param primaryKey the primary key of the social request
554             * @return the social request that was removed
555             * @throws com.liferay.portlet.social.NoSuchRequestException if a social request with the primary key could not be found
556             * @throws SystemException if a system exception occurred
557             */
558            @Override
559            public SocialRequest remove(Serializable primaryKey)
560                    throws NoSuchRequestException, SystemException {
561                    Session session = null;
562    
563                    try {
564                            session = openSession();
565    
566                            SocialRequest socialRequest = (SocialRequest)session.get(SocialRequestImpl.class,
567                                            primaryKey);
568    
569                            if (socialRequest == null) {
570                                    if (_log.isWarnEnabled()) {
571                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
572                                    }
573    
574                                    throw new NoSuchRequestException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
575                                            primaryKey);
576                            }
577    
578                            return remove(socialRequest);
579                    }
580                    catch (NoSuchRequestException nsee) {
581                            throw nsee;
582                    }
583                    catch (Exception e) {
584                            throw processException(e);
585                    }
586                    finally {
587                            closeSession(session);
588                    }
589            }
590    
591            @Override
592            protected SocialRequest removeImpl(SocialRequest socialRequest)
593                    throws SystemException {
594                    socialRequest = toUnwrappedModel(socialRequest);
595    
596                    Session session = null;
597    
598                    try {
599                            session = openSession();
600    
601                            BatchSessionUtil.delete(session, socialRequest);
602                    }
603                    catch (Exception e) {
604                            throw processException(e);
605                    }
606                    finally {
607                            closeSession(session);
608                    }
609    
610                    clearCache(socialRequest);
611    
612                    return socialRequest;
613            }
614    
615            @Override
616            public SocialRequest updateImpl(
617                    com.liferay.portlet.social.model.SocialRequest socialRequest,
618                    boolean merge) throws SystemException {
619                    socialRequest = toUnwrappedModel(socialRequest);
620    
621                    boolean isNew = socialRequest.isNew();
622    
623                    SocialRequestModelImpl socialRequestModelImpl = (SocialRequestModelImpl)socialRequest;
624    
625                    if (Validator.isNull(socialRequest.getUuid())) {
626                            String uuid = PortalUUIDUtil.generate();
627    
628                            socialRequest.setUuid(uuid);
629                    }
630    
631                    Session session = null;
632    
633                    try {
634                            session = openSession();
635    
636                            BatchSessionUtil.update(session, socialRequest, merge);
637    
638                            socialRequest.setNew(false);
639                    }
640                    catch (Exception e) {
641                            throw processException(e);
642                    }
643                    finally {
644                            closeSession(session);
645                    }
646    
647                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
648    
649                    if (isNew || !SocialRequestModelImpl.COLUMN_BITMASK_ENABLED) {
650                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
651                    }
652    
653                    else {
654                            if ((socialRequestModelImpl.getColumnBitmask() &
655                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
656                                    Object[] args = new Object[] {
657                                                    socialRequestModelImpl.getOriginalUuid()
658                                            };
659    
660                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
661                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
662                                            args);
663    
664                                    args = new Object[] { socialRequestModelImpl.getUuid() };
665    
666                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
667                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
668                                            args);
669                            }
670    
671                            if ((socialRequestModelImpl.getColumnBitmask() &
672                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
673                                    Object[] args = new Object[] {
674                                                    Long.valueOf(socialRequestModelImpl.getOriginalCompanyId())
675                                            };
676    
677                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
678                                            args);
679                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
680                                            args);
681    
682                                    args = new Object[] {
683                                                    Long.valueOf(socialRequestModelImpl.getCompanyId())
684                                            };
685    
686                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
687                                            args);
688                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
689                                            args);
690                            }
691    
692                            if ((socialRequestModelImpl.getColumnBitmask() &
693                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
694                                    Object[] args = new Object[] {
695                                                    Long.valueOf(socialRequestModelImpl.getOriginalUserId())
696                                            };
697    
698                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
699                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
700                                            args);
701    
702                                    args = new Object[] {
703                                                    Long.valueOf(socialRequestModelImpl.getUserId())
704                                            };
705    
706                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
707                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
708                                            args);
709                            }
710    
711                            if ((socialRequestModelImpl.getColumnBitmask() &
712                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RECEIVERUSERID.getColumnBitmask()) != 0) {
713                                    Object[] args = new Object[] {
714                                                    Long.valueOf(socialRequestModelImpl.getOriginalReceiverUserId())
715                                            };
716    
717                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_RECEIVERUSERID,
718                                            args);
719                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RECEIVERUSERID,
720                                            args);
721    
722                                    args = new Object[] {
723                                                    Long.valueOf(socialRequestModelImpl.getReceiverUserId())
724                                            };
725    
726                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_RECEIVERUSERID,
727                                            args);
728                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RECEIVERUSERID,
729                                            args);
730                            }
731    
732                            if ((socialRequestModelImpl.getColumnBitmask() &
733                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_S.getColumnBitmask()) != 0) {
734                                    Object[] args = new Object[] {
735                                                    Long.valueOf(socialRequestModelImpl.getOriginalUserId()),
736                                                    Integer.valueOf(socialRequestModelImpl.getOriginalStatus())
737                                            };
738    
739                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_S, args);
740                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_S,
741                                            args);
742    
743                                    args = new Object[] {
744                                                    Long.valueOf(socialRequestModelImpl.getUserId()),
745                                                    Integer.valueOf(socialRequestModelImpl.getStatus())
746                                            };
747    
748                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_S, args);
749                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_S,
750                                            args);
751                            }
752    
753                            if ((socialRequestModelImpl.getColumnBitmask() &
754                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_S.getColumnBitmask()) != 0) {
755                                    Object[] args = new Object[] {
756                                                    Long.valueOf(socialRequestModelImpl.getOriginalReceiverUserId()),
757                                                    Integer.valueOf(socialRequestModelImpl.getOriginalStatus())
758                                            };
759    
760                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_S, args);
761                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_S,
762                                            args);
763    
764                                    args = new Object[] {
765                                                    Long.valueOf(socialRequestModelImpl.getReceiverUserId()),
766                                                    Integer.valueOf(socialRequestModelImpl.getStatus())
767                                            };
768    
769                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_S, args);
770                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_S,
771                                            args);
772                            }
773    
774                            if ((socialRequestModelImpl.getColumnBitmask() &
775                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_T_S.getColumnBitmask()) != 0) {
776                                    Object[] args = new Object[] {
777                                                    Long.valueOf(socialRequestModelImpl.getOriginalUserId()),
778                                                    Long.valueOf(socialRequestModelImpl.getOriginalClassNameId()),
779                                                    Long.valueOf(socialRequestModelImpl.getOriginalClassPK()),
780                                                    Integer.valueOf(socialRequestModelImpl.getOriginalType()),
781                                                    Integer.valueOf(socialRequestModelImpl.getOriginalStatus())
782                                            };
783    
784                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_C_T_S,
785                                            args);
786                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_T_S,
787                                            args);
788    
789                                    args = new Object[] {
790                                                    Long.valueOf(socialRequestModelImpl.getUserId()),
791                                                    Long.valueOf(socialRequestModelImpl.getClassNameId()),
792                                                    Long.valueOf(socialRequestModelImpl.getClassPK()),
793                                                    Integer.valueOf(socialRequestModelImpl.getType()),
794                                                    Integer.valueOf(socialRequestModelImpl.getStatus())
795                                            };
796    
797                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_C_T_S,
798                                            args);
799                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_T_S,
800                                            args);
801                            }
802    
803                            if ((socialRequestModelImpl.getColumnBitmask() &
804                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_T_R_S.getColumnBitmask()) != 0) {
805                                    Object[] args = new Object[] {
806                                                    Long.valueOf(socialRequestModelImpl.getOriginalClassNameId()),
807                                                    Long.valueOf(socialRequestModelImpl.getOriginalClassPK()),
808                                                    Integer.valueOf(socialRequestModelImpl.getOriginalType()),
809                                                    Long.valueOf(socialRequestModelImpl.getOriginalReceiverUserId()),
810                                                    Integer.valueOf(socialRequestModelImpl.getOriginalStatus())
811                                            };
812    
813                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_T_R_S,
814                                            args);
815                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_T_R_S,
816                                            args);
817    
818                                    args = new Object[] {
819                                                    Long.valueOf(socialRequestModelImpl.getClassNameId()),
820                                                    Long.valueOf(socialRequestModelImpl.getClassPK()),
821                                                    Integer.valueOf(socialRequestModelImpl.getType()),
822                                                    Long.valueOf(socialRequestModelImpl.getReceiverUserId()),
823                                                    Integer.valueOf(socialRequestModelImpl.getStatus())
824                                            };
825    
826                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_T_R_S,
827                                            args);
828                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_T_R_S,
829                                            args);
830                            }
831                    }
832    
833                    EntityCacheUtil.putResult(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
834                            SocialRequestImpl.class, socialRequest.getPrimaryKey(),
835                            socialRequest);
836    
837                    clearUniqueFindersCache(socialRequest);
838                    cacheUniqueFindersCache(socialRequest);
839    
840                    return socialRequest;
841            }
842    
843            protected SocialRequest toUnwrappedModel(SocialRequest socialRequest) {
844                    if (socialRequest instanceof SocialRequestImpl) {
845                            return socialRequest;
846                    }
847    
848                    SocialRequestImpl socialRequestImpl = new SocialRequestImpl();
849    
850                    socialRequestImpl.setNew(socialRequest.isNew());
851                    socialRequestImpl.setPrimaryKey(socialRequest.getPrimaryKey());
852    
853                    socialRequestImpl.setUuid(socialRequest.getUuid());
854                    socialRequestImpl.setRequestId(socialRequest.getRequestId());
855                    socialRequestImpl.setGroupId(socialRequest.getGroupId());
856                    socialRequestImpl.setCompanyId(socialRequest.getCompanyId());
857                    socialRequestImpl.setUserId(socialRequest.getUserId());
858                    socialRequestImpl.setCreateDate(socialRequest.getCreateDate());
859                    socialRequestImpl.setModifiedDate(socialRequest.getModifiedDate());
860                    socialRequestImpl.setClassNameId(socialRequest.getClassNameId());
861                    socialRequestImpl.setClassPK(socialRequest.getClassPK());
862                    socialRequestImpl.setType(socialRequest.getType());
863                    socialRequestImpl.setExtraData(socialRequest.getExtraData());
864                    socialRequestImpl.setReceiverUserId(socialRequest.getReceiverUserId());
865                    socialRequestImpl.setStatus(socialRequest.getStatus());
866    
867                    return socialRequestImpl;
868            }
869    
870            /**
871             * Returns the social request with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
872             *
873             * @param primaryKey the primary key of the social request
874             * @return the social request
875             * @throws com.liferay.portal.NoSuchModelException if a social request with the primary key could not be found
876             * @throws SystemException if a system exception occurred
877             */
878            @Override
879            public SocialRequest findByPrimaryKey(Serializable primaryKey)
880                    throws NoSuchModelException, SystemException {
881                    return findByPrimaryKey(((Long)primaryKey).longValue());
882            }
883    
884            /**
885             * Returns the social request with the primary key or throws a {@link com.liferay.portlet.social.NoSuchRequestException} if it could not be found.
886             *
887             * @param requestId the primary key of the social request
888             * @return the social request
889             * @throws com.liferay.portlet.social.NoSuchRequestException if a social request with the primary key could not be found
890             * @throws SystemException if a system exception occurred
891             */
892            public SocialRequest findByPrimaryKey(long requestId)
893                    throws NoSuchRequestException, SystemException {
894                    SocialRequest socialRequest = fetchByPrimaryKey(requestId);
895    
896                    if (socialRequest == null) {
897                            if (_log.isWarnEnabled()) {
898                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + requestId);
899                            }
900    
901                            throw new NoSuchRequestException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
902                                    requestId);
903                    }
904    
905                    return socialRequest;
906            }
907    
908            /**
909             * Returns the social request with the primary key or returns <code>null</code> if it could not be found.
910             *
911             * @param primaryKey the primary key of the social request
912             * @return the social request, or <code>null</code> if a social request with the primary key could not be found
913             * @throws SystemException if a system exception occurred
914             */
915            @Override
916            public SocialRequest fetchByPrimaryKey(Serializable primaryKey)
917                    throws SystemException {
918                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
919            }
920    
921            /**
922             * Returns the social request with the primary key or returns <code>null</code> if it could not be found.
923             *
924             * @param requestId the primary key of the social request
925             * @return the social request, or <code>null</code> if a social request with the primary key could not be found
926             * @throws SystemException if a system exception occurred
927             */
928            public SocialRequest fetchByPrimaryKey(long requestId)
929                    throws SystemException {
930                    SocialRequest socialRequest = (SocialRequest)EntityCacheUtil.getResult(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
931                                    SocialRequestImpl.class, requestId);
932    
933                    if (socialRequest == _nullSocialRequest) {
934                            return null;
935                    }
936    
937                    if (socialRequest == null) {
938                            Session session = null;
939    
940                            boolean hasException = false;
941    
942                            try {
943                                    session = openSession();
944    
945                                    socialRequest = (SocialRequest)session.get(SocialRequestImpl.class,
946                                                    Long.valueOf(requestId));
947                            }
948                            catch (Exception e) {
949                                    hasException = true;
950    
951                                    throw processException(e);
952                            }
953                            finally {
954                                    if (socialRequest != null) {
955                                            cacheResult(socialRequest);
956                                    }
957                                    else if (!hasException) {
958                                            EntityCacheUtil.putResult(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
959                                                    SocialRequestImpl.class, requestId, _nullSocialRequest);
960                                    }
961    
962                                    closeSession(session);
963                            }
964                    }
965    
966                    return socialRequest;
967            }
968    
969            /**
970             * Returns all the social requests where uuid = &#63;.
971             *
972             * @param uuid the uuid
973             * @return the matching social requests
974             * @throws SystemException if a system exception occurred
975             */
976            public List<SocialRequest> findByUuid(String uuid)
977                    throws SystemException {
978                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
979            }
980    
981            /**
982             * Returns a range of all the social requests where uuid = &#63;.
983             *
984             * <p>
985             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
986             * </p>
987             *
988             * @param uuid the uuid
989             * @param start the lower bound of the range of social requests
990             * @param end the upper bound of the range of social requests (not inclusive)
991             * @return the range of matching social requests
992             * @throws SystemException if a system exception occurred
993             */
994            public List<SocialRequest> findByUuid(String uuid, int start, int end)
995                    throws SystemException {
996                    return findByUuid(uuid, start, end, null);
997            }
998    
999            /**
1000             * Returns an ordered range of all the social requests where uuid = &#63;.
1001             *
1002             * <p>
1003             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1004             * </p>
1005             *
1006             * @param uuid the uuid
1007             * @param start the lower bound of the range of social requests
1008             * @param end the upper bound of the range of social requests (not inclusive)
1009             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1010             * @return the ordered range of matching social requests
1011             * @throws SystemException if a system exception occurred
1012             */
1013            public List<SocialRequest> findByUuid(String uuid, int start, int end,
1014                    OrderByComparator orderByComparator) throws SystemException {
1015                    FinderPath finderPath = null;
1016                    Object[] finderArgs = null;
1017    
1018                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1019                                    (orderByComparator == null)) {
1020                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
1021                            finderArgs = new Object[] { uuid };
1022                    }
1023                    else {
1024                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
1025                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
1026                    }
1027    
1028                    List<SocialRequest> list = (List<SocialRequest>)FinderCacheUtil.getResult(finderPath,
1029                                    finderArgs, this);
1030    
1031                    if ((list != null) && !list.isEmpty()) {
1032                            for (SocialRequest socialRequest : list) {
1033                                    if (!Validator.equals(uuid, socialRequest.getUuid())) {
1034                                            list = null;
1035    
1036                                            break;
1037                                    }
1038                            }
1039                    }
1040    
1041                    if (list == null) {
1042                            StringBundler query = null;
1043    
1044                            if (orderByComparator != null) {
1045                                    query = new StringBundler(3 +
1046                                                    (orderByComparator.getOrderByFields().length * 3));
1047                            }
1048                            else {
1049                                    query = new StringBundler(3);
1050                            }
1051    
1052                            query.append(_SQL_SELECT_SOCIALREQUEST_WHERE);
1053    
1054                            if (uuid == null) {
1055                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
1056                            }
1057                            else {
1058                                    if (uuid.equals(StringPool.BLANK)) {
1059                                            query.append(_FINDER_COLUMN_UUID_UUID_3);
1060                                    }
1061                                    else {
1062                                            query.append(_FINDER_COLUMN_UUID_UUID_2);
1063                                    }
1064                            }
1065    
1066                            if (orderByComparator != null) {
1067                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1068                                            orderByComparator);
1069                            }
1070    
1071                            else {
1072                                    query.append(SocialRequestModelImpl.ORDER_BY_JPQL);
1073                            }
1074    
1075                            String sql = query.toString();
1076    
1077                            Session session = null;
1078    
1079                            try {
1080                                    session = openSession();
1081    
1082                                    Query q = session.createQuery(sql);
1083    
1084                                    QueryPos qPos = QueryPos.getInstance(q);
1085    
1086                                    if (uuid != null) {
1087                                            qPos.add(uuid);
1088                                    }
1089    
1090                                    list = (List<SocialRequest>)QueryUtil.list(q, getDialect(),
1091                                                    start, end);
1092                            }
1093                            catch (Exception e) {
1094                                    throw processException(e);
1095                            }
1096                            finally {
1097                                    if (list == null) {
1098                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1099                                    }
1100                                    else {
1101                                            cacheResult(list);
1102    
1103                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1104                                    }
1105    
1106                                    closeSession(session);
1107                            }
1108                    }
1109    
1110                    return list;
1111            }
1112    
1113            /**
1114             * Returns the first social request in the ordered set where uuid = &#63;.
1115             *
1116             * @param uuid the uuid
1117             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1118             * @return the first matching social request
1119             * @throws com.liferay.portlet.social.NoSuchRequestException if a matching social request could not be found
1120             * @throws SystemException if a system exception occurred
1121             */
1122            public SocialRequest findByUuid_First(String uuid,
1123                    OrderByComparator orderByComparator)
1124                    throws NoSuchRequestException, SystemException {
1125                    SocialRequest socialRequest = fetchByUuid_First(uuid, orderByComparator);
1126    
1127                    if (socialRequest != null) {
1128                            return socialRequest;
1129                    }
1130    
1131                    StringBundler msg = new StringBundler(4);
1132    
1133                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1134    
1135                    msg.append("uuid=");
1136                    msg.append(uuid);
1137    
1138                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1139    
1140                    throw new NoSuchRequestException(msg.toString());
1141            }
1142    
1143            /**
1144             * Returns the first social request in the ordered set where uuid = &#63;.
1145             *
1146             * @param uuid the uuid
1147             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1148             * @return the first matching social request, or <code>null</code> if a matching social request could not be found
1149             * @throws SystemException if a system exception occurred
1150             */
1151            public SocialRequest fetchByUuid_First(String uuid,
1152                    OrderByComparator orderByComparator) throws SystemException {
1153                    List<SocialRequest> list = findByUuid(uuid, 0, 1, orderByComparator);
1154    
1155                    if (!list.isEmpty()) {
1156                            return list.get(0);
1157                    }
1158    
1159                    return null;
1160            }
1161    
1162            /**
1163             * Returns the last social request in the ordered set where uuid = &#63;.
1164             *
1165             * @param uuid the uuid
1166             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1167             * @return the last matching social request
1168             * @throws com.liferay.portlet.social.NoSuchRequestException if a matching social request could not be found
1169             * @throws SystemException if a system exception occurred
1170             */
1171            public SocialRequest findByUuid_Last(String uuid,
1172                    OrderByComparator orderByComparator)
1173                    throws NoSuchRequestException, SystemException {
1174                    SocialRequest socialRequest = fetchByUuid_Last(uuid, orderByComparator);
1175    
1176                    if (socialRequest != null) {
1177                            return socialRequest;
1178                    }
1179    
1180                    StringBundler msg = new StringBundler(4);
1181    
1182                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1183    
1184                    msg.append("uuid=");
1185                    msg.append(uuid);
1186    
1187                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1188    
1189                    throw new NoSuchRequestException(msg.toString());
1190            }
1191    
1192            /**
1193             * Returns the last social request in the ordered set where uuid = &#63;.
1194             *
1195             * @param uuid the uuid
1196             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1197             * @return the last matching social request, or <code>null</code> if a matching social request could not be found
1198             * @throws SystemException if a system exception occurred
1199             */
1200            public SocialRequest fetchByUuid_Last(String uuid,
1201                    OrderByComparator orderByComparator) throws SystemException {
1202                    int count = countByUuid(uuid);
1203    
1204                    List<SocialRequest> list = findByUuid(uuid, count - 1, count,
1205                                    orderByComparator);
1206    
1207                    if (!list.isEmpty()) {
1208                            return list.get(0);
1209                    }
1210    
1211                    return null;
1212            }
1213    
1214            /**
1215             * Returns the social requests before and after the current social request in the ordered set where uuid = &#63;.
1216             *
1217             * @param requestId the primary key of the current social request
1218             * @param uuid the uuid
1219             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1220             * @return the previous, current, and next social request
1221             * @throws com.liferay.portlet.social.NoSuchRequestException if a social request with the primary key could not be found
1222             * @throws SystemException if a system exception occurred
1223             */
1224            public SocialRequest[] findByUuid_PrevAndNext(long requestId, String uuid,
1225                    OrderByComparator orderByComparator)
1226                    throws NoSuchRequestException, SystemException {
1227                    SocialRequest socialRequest = findByPrimaryKey(requestId);
1228    
1229                    Session session = null;
1230    
1231                    try {
1232                            session = openSession();
1233    
1234                            SocialRequest[] array = new SocialRequestImpl[3];
1235    
1236                            array[0] = getByUuid_PrevAndNext(session, socialRequest, uuid,
1237                                            orderByComparator, true);
1238    
1239                            array[1] = socialRequest;
1240    
1241                            array[2] = getByUuid_PrevAndNext(session, socialRequest, uuid,
1242                                            orderByComparator, false);
1243    
1244                            return array;
1245                    }
1246                    catch (Exception e) {
1247                            throw processException(e);
1248                    }
1249                    finally {
1250                            closeSession(session);
1251                    }
1252            }
1253    
1254            protected SocialRequest getByUuid_PrevAndNext(Session session,
1255                    SocialRequest socialRequest, String uuid,
1256                    OrderByComparator orderByComparator, boolean previous) {
1257                    StringBundler query = null;
1258    
1259                    if (orderByComparator != null) {
1260                            query = new StringBundler(6 +
1261                                            (orderByComparator.getOrderByFields().length * 6));
1262                    }
1263                    else {
1264                            query = new StringBundler(3);
1265                    }
1266    
1267                    query.append(_SQL_SELECT_SOCIALREQUEST_WHERE);
1268    
1269                    if (uuid == null) {
1270                            query.append(_FINDER_COLUMN_UUID_UUID_1);
1271                    }
1272                    else {
1273                            if (uuid.equals(StringPool.BLANK)) {
1274                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
1275                            }
1276                            else {
1277                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
1278                            }
1279                    }
1280    
1281                    if (orderByComparator != null) {
1282                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1283    
1284                            if (orderByConditionFields.length > 0) {
1285                                    query.append(WHERE_AND);
1286                            }
1287    
1288                            for (int i = 0; i < orderByConditionFields.length; i++) {
1289                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1290                                    query.append(orderByConditionFields[i]);
1291    
1292                                    if ((i + 1) < orderByConditionFields.length) {
1293                                            if (orderByComparator.isAscending() ^ previous) {
1294                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1295                                            }
1296                                            else {
1297                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1298                                            }
1299                                    }
1300                                    else {
1301                                            if (orderByComparator.isAscending() ^ previous) {
1302                                                    query.append(WHERE_GREATER_THAN);
1303                                            }
1304                                            else {
1305                                                    query.append(WHERE_LESSER_THAN);
1306                                            }
1307                                    }
1308                            }
1309    
1310                            query.append(ORDER_BY_CLAUSE);
1311    
1312                            String[] orderByFields = orderByComparator.getOrderByFields();
1313    
1314                            for (int i = 0; i < orderByFields.length; i++) {
1315                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1316                                    query.append(orderByFields[i]);
1317    
1318                                    if ((i + 1) < orderByFields.length) {
1319                                            if (orderByComparator.isAscending() ^ previous) {
1320                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1321                                            }
1322                                            else {
1323                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1324                                            }
1325                                    }
1326                                    else {
1327                                            if (orderByComparator.isAscending() ^ previous) {
1328                                                    query.append(ORDER_BY_ASC);
1329                                            }
1330                                            else {
1331                                                    query.append(ORDER_BY_DESC);
1332                                            }
1333                                    }
1334                            }
1335                    }
1336    
1337                    else {
1338                            query.append(SocialRequestModelImpl.ORDER_BY_JPQL);
1339                    }
1340    
1341                    String sql = query.toString();
1342    
1343                    Query q = session.createQuery(sql);
1344    
1345                    q.setFirstResult(0);
1346                    q.setMaxResults(2);
1347    
1348                    QueryPos qPos = QueryPos.getInstance(q);
1349    
1350                    if (uuid != null) {
1351                            qPos.add(uuid);
1352                    }
1353    
1354                    if (orderByComparator != null) {
1355                            Object[] values = orderByComparator.getOrderByConditionValues(socialRequest);
1356    
1357                            for (Object value : values) {
1358                                    qPos.add(value);
1359                            }
1360                    }
1361    
1362                    List<SocialRequest> list = q.list();
1363    
1364                    if (list.size() == 2) {
1365                            return list.get(1);
1366                    }
1367                    else {
1368                            return null;
1369                    }
1370            }
1371    
1372            /**
1373             * Returns the social request where uuid = &#63; and groupId = &#63; or throws a {@link com.liferay.portlet.social.NoSuchRequestException} if it could not be found.
1374             *
1375             * @param uuid the uuid
1376             * @param groupId the group ID
1377             * @return the matching social request
1378             * @throws com.liferay.portlet.social.NoSuchRequestException if a matching social request could not be found
1379             * @throws SystemException if a system exception occurred
1380             */
1381            public SocialRequest findByUUID_G(String uuid, long groupId)
1382                    throws NoSuchRequestException, SystemException {
1383                    SocialRequest socialRequest = fetchByUUID_G(uuid, groupId);
1384    
1385                    if (socialRequest == null) {
1386                            StringBundler msg = new StringBundler(6);
1387    
1388                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1389    
1390                            msg.append("uuid=");
1391                            msg.append(uuid);
1392    
1393                            msg.append(", groupId=");
1394                            msg.append(groupId);
1395    
1396                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1397    
1398                            if (_log.isWarnEnabled()) {
1399                                    _log.warn(msg.toString());
1400                            }
1401    
1402                            throw new NoSuchRequestException(msg.toString());
1403                    }
1404    
1405                    return socialRequest;
1406            }
1407    
1408            /**
1409             * Returns the social request where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
1410             *
1411             * @param uuid the uuid
1412             * @param groupId the group ID
1413             * @return the matching social request, or <code>null</code> if a matching social request could not be found
1414             * @throws SystemException if a system exception occurred
1415             */
1416            public SocialRequest fetchByUUID_G(String uuid, long groupId)
1417                    throws SystemException {
1418                    return fetchByUUID_G(uuid, groupId, true);
1419            }
1420    
1421            /**
1422             * Returns the social request where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
1423             *
1424             * @param uuid the uuid
1425             * @param groupId the group ID
1426             * @param retrieveFromCache whether to use the finder cache
1427             * @return the matching social request, or <code>null</code> if a matching social request could not be found
1428             * @throws SystemException if a system exception occurred
1429             */
1430            public SocialRequest fetchByUUID_G(String uuid, long groupId,
1431                    boolean retrieveFromCache) throws SystemException {
1432                    Object[] finderArgs = new Object[] { uuid, groupId };
1433    
1434                    Object result = null;
1435    
1436                    if (retrieveFromCache) {
1437                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
1438                                            finderArgs, this);
1439                    }
1440    
1441                    if (result instanceof SocialRequest) {
1442                            SocialRequest socialRequest = (SocialRequest)result;
1443    
1444                            if (!Validator.equals(uuid, socialRequest.getUuid()) ||
1445                                            (groupId != socialRequest.getGroupId())) {
1446                                    result = null;
1447                            }
1448                    }
1449    
1450                    if (result == null) {
1451                            StringBundler query = new StringBundler(4);
1452    
1453                            query.append(_SQL_SELECT_SOCIALREQUEST_WHERE);
1454    
1455                            if (uuid == null) {
1456                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
1457                            }
1458                            else {
1459                                    if (uuid.equals(StringPool.BLANK)) {
1460                                            query.append(_FINDER_COLUMN_UUID_G_UUID_3);
1461                                    }
1462                                    else {
1463                                            query.append(_FINDER_COLUMN_UUID_G_UUID_2);
1464                                    }
1465                            }
1466    
1467                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
1468    
1469                            query.append(SocialRequestModelImpl.ORDER_BY_JPQL);
1470    
1471                            String sql = query.toString();
1472    
1473                            Session session = null;
1474    
1475                            try {
1476                                    session = openSession();
1477    
1478                                    Query q = session.createQuery(sql);
1479    
1480                                    QueryPos qPos = QueryPos.getInstance(q);
1481    
1482                                    if (uuid != null) {
1483                                            qPos.add(uuid);
1484                                    }
1485    
1486                                    qPos.add(groupId);
1487    
1488                                    List<SocialRequest> list = q.list();
1489    
1490                                    result = list;
1491    
1492                                    SocialRequest socialRequest = null;
1493    
1494                                    if (list.isEmpty()) {
1495                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1496                                                    finderArgs, list);
1497                                    }
1498                                    else {
1499                                            socialRequest = list.get(0);
1500    
1501                                            cacheResult(socialRequest);
1502    
1503                                            if ((socialRequest.getUuid() == null) ||
1504                                                            !socialRequest.getUuid().equals(uuid) ||
1505                                                            (socialRequest.getGroupId() != groupId)) {
1506                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1507                                                            finderArgs, socialRequest);
1508                                            }
1509                                    }
1510    
1511                                    return socialRequest;
1512                            }
1513                            catch (Exception e) {
1514                                    throw processException(e);
1515                            }
1516                            finally {
1517                                    if (result == null) {
1518                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
1519                                                    finderArgs);
1520                                    }
1521    
1522                                    closeSession(session);
1523                            }
1524                    }
1525                    else {
1526                            if (result instanceof List<?>) {
1527                                    return null;
1528                            }
1529                            else {
1530                                    return (SocialRequest)result;
1531                            }
1532                    }
1533            }
1534    
1535            /**
1536             * Returns all the social requests where companyId = &#63;.
1537             *
1538             * @param companyId the company ID
1539             * @return the matching social requests
1540             * @throws SystemException if a system exception occurred
1541             */
1542            public List<SocialRequest> findByCompanyId(long companyId)
1543                    throws SystemException {
1544                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1545                            null);
1546            }
1547    
1548            /**
1549             * Returns a range of all the social requests where companyId = &#63;.
1550             *
1551             * <p>
1552             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1553             * </p>
1554             *
1555             * @param companyId the company ID
1556             * @param start the lower bound of the range of social requests
1557             * @param end the upper bound of the range of social requests (not inclusive)
1558             * @return the range of matching social requests
1559             * @throws SystemException if a system exception occurred
1560             */
1561            public List<SocialRequest> findByCompanyId(long companyId, int start,
1562                    int end) throws SystemException {
1563                    return findByCompanyId(companyId, start, end, null);
1564            }
1565    
1566            /**
1567             * Returns an ordered range of all the social requests where companyId = &#63;.
1568             *
1569             * <p>
1570             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1571             * </p>
1572             *
1573             * @param companyId the company ID
1574             * @param start the lower bound of the range of social requests
1575             * @param end the upper bound of the range of social requests (not inclusive)
1576             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1577             * @return the ordered range of matching social requests
1578             * @throws SystemException if a system exception occurred
1579             */
1580            public List<SocialRequest> findByCompanyId(long companyId, int start,
1581                    int end, OrderByComparator orderByComparator) throws SystemException {
1582                    FinderPath finderPath = null;
1583                    Object[] finderArgs = null;
1584    
1585                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1586                                    (orderByComparator == null)) {
1587                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
1588                            finderArgs = new Object[] { companyId };
1589                    }
1590                    else {
1591                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
1592                            finderArgs = new Object[] { companyId, start, end, orderByComparator };
1593                    }
1594    
1595                    List<SocialRequest> list = (List<SocialRequest>)FinderCacheUtil.getResult(finderPath,
1596                                    finderArgs, this);
1597    
1598                    if ((list != null) && !list.isEmpty()) {
1599                            for (SocialRequest socialRequest : list) {
1600                                    if ((companyId != socialRequest.getCompanyId())) {
1601                                            list = null;
1602    
1603                                            break;
1604                                    }
1605                            }
1606                    }
1607    
1608                    if (list == null) {
1609                            StringBundler query = null;
1610    
1611                            if (orderByComparator != null) {
1612                                    query = new StringBundler(3 +
1613                                                    (orderByComparator.getOrderByFields().length * 3));
1614                            }
1615                            else {
1616                                    query = new StringBundler(3);
1617                            }
1618    
1619                            query.append(_SQL_SELECT_SOCIALREQUEST_WHERE);
1620    
1621                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1622    
1623                            if (orderByComparator != null) {
1624                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1625                                            orderByComparator);
1626                            }
1627    
1628                            else {
1629                                    query.append(SocialRequestModelImpl.ORDER_BY_JPQL);
1630                            }
1631    
1632                            String sql = query.toString();
1633    
1634                            Session session = null;
1635    
1636                            try {
1637                                    session = openSession();
1638    
1639                                    Query q = session.createQuery(sql);
1640    
1641                                    QueryPos qPos = QueryPos.getInstance(q);
1642    
1643                                    qPos.add(companyId);
1644    
1645                                    list = (List<SocialRequest>)QueryUtil.list(q, getDialect(),
1646                                                    start, end);
1647                            }
1648                            catch (Exception e) {
1649                                    throw processException(e);
1650                            }
1651                            finally {
1652                                    if (list == null) {
1653                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1654                                    }
1655                                    else {
1656                                            cacheResult(list);
1657    
1658                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1659                                    }
1660    
1661                                    closeSession(session);
1662                            }
1663                    }
1664    
1665                    return list;
1666            }
1667    
1668            /**
1669             * Returns the first social request in the ordered set where companyId = &#63;.
1670             *
1671             * @param companyId the company ID
1672             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1673             * @return the first matching social request
1674             * @throws com.liferay.portlet.social.NoSuchRequestException if a matching social request could not be found
1675             * @throws SystemException if a system exception occurred
1676             */
1677            public SocialRequest findByCompanyId_First(long companyId,
1678                    OrderByComparator orderByComparator)
1679                    throws NoSuchRequestException, SystemException {
1680                    SocialRequest socialRequest = fetchByCompanyId_First(companyId,
1681                                    orderByComparator);
1682    
1683                    if (socialRequest != null) {
1684                            return socialRequest;
1685                    }
1686    
1687                    StringBundler msg = new StringBundler(4);
1688    
1689                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1690    
1691                    msg.append("companyId=");
1692                    msg.append(companyId);
1693    
1694                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1695    
1696                    throw new NoSuchRequestException(msg.toString());
1697            }
1698    
1699            /**
1700             * Returns the first social request in the ordered set where companyId = &#63;.
1701             *
1702             * @param companyId the company ID
1703             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1704             * @return the first matching social request, or <code>null</code> if a matching social request could not be found
1705             * @throws SystemException if a system exception occurred
1706             */
1707            public SocialRequest fetchByCompanyId_First(long companyId,
1708                    OrderByComparator orderByComparator) throws SystemException {
1709                    List<SocialRequest> list = findByCompanyId(companyId, 0, 1,
1710                                    orderByComparator);
1711    
1712                    if (!list.isEmpty()) {
1713                            return list.get(0);
1714                    }
1715    
1716                    return null;
1717            }
1718    
1719            /**
1720             * Returns the last social request in the ordered set where companyId = &#63;.
1721             *
1722             * @param companyId the company ID
1723             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1724             * @return the last matching social request
1725             * @throws com.liferay.portlet.social.NoSuchRequestException if a matching social request could not be found
1726             * @throws SystemException if a system exception occurred
1727             */
1728            public SocialRequest findByCompanyId_Last(long companyId,
1729                    OrderByComparator orderByComparator)
1730                    throws NoSuchRequestException, SystemException {
1731                    SocialRequest socialRequest = fetchByCompanyId_Last(companyId,
1732                                    orderByComparator);
1733    
1734                    if (socialRequest != null) {
1735                            return socialRequest;
1736                    }
1737    
1738                    StringBundler msg = new StringBundler(4);
1739    
1740                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1741    
1742                    msg.append("companyId=");
1743                    msg.append(companyId);
1744    
1745                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1746    
1747                    throw new NoSuchRequestException(msg.toString());
1748            }
1749    
1750            /**
1751             * Returns the last social request in the ordered set where companyId = &#63;.
1752             *
1753             * @param companyId the company ID
1754             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1755             * @return the last matching social request, or <code>null</code> if a matching social request could not be found
1756             * @throws SystemException if a system exception occurred
1757             */
1758            public SocialRequest fetchByCompanyId_Last(long companyId,
1759                    OrderByComparator orderByComparator) throws SystemException {
1760                    int count = countByCompanyId(companyId);
1761    
1762                    List<SocialRequest> list = findByCompanyId(companyId, count - 1, count,
1763                                    orderByComparator);
1764    
1765                    if (!list.isEmpty()) {
1766                            return list.get(0);
1767                    }
1768    
1769                    return null;
1770            }
1771    
1772            /**
1773             * Returns the social requests before and after the current social request in the ordered set where companyId = &#63;.
1774             *
1775             * @param requestId the primary key of the current social request
1776             * @param companyId the company ID
1777             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1778             * @return the previous, current, and next social request
1779             * @throws com.liferay.portlet.social.NoSuchRequestException if a social request with the primary key could not be found
1780             * @throws SystemException if a system exception occurred
1781             */
1782            public SocialRequest[] findByCompanyId_PrevAndNext(long requestId,
1783                    long companyId, OrderByComparator orderByComparator)
1784                    throws NoSuchRequestException, SystemException {
1785                    SocialRequest socialRequest = findByPrimaryKey(requestId);
1786    
1787                    Session session = null;
1788    
1789                    try {
1790                            session = openSession();
1791    
1792                            SocialRequest[] array = new SocialRequestImpl[3];
1793    
1794                            array[0] = getByCompanyId_PrevAndNext(session, socialRequest,
1795                                            companyId, orderByComparator, true);
1796    
1797                            array[1] = socialRequest;
1798    
1799                            array[2] = getByCompanyId_PrevAndNext(session, socialRequest,
1800                                            companyId, orderByComparator, false);
1801    
1802                            return array;
1803                    }
1804                    catch (Exception e) {
1805                            throw processException(e);
1806                    }
1807                    finally {
1808                            closeSession(session);
1809                    }
1810            }
1811    
1812            protected SocialRequest getByCompanyId_PrevAndNext(Session session,
1813                    SocialRequest socialRequest, long companyId,
1814                    OrderByComparator orderByComparator, boolean previous) {
1815                    StringBundler query = null;
1816    
1817                    if (orderByComparator != null) {
1818                            query = new StringBundler(6 +
1819                                            (orderByComparator.getOrderByFields().length * 6));
1820                    }
1821                    else {
1822                            query = new StringBundler(3);
1823                    }
1824    
1825                    query.append(_SQL_SELECT_SOCIALREQUEST_WHERE);
1826    
1827                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1828    
1829                    if (orderByComparator != null) {
1830                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1831    
1832                            if (orderByConditionFields.length > 0) {
1833                                    query.append(WHERE_AND);
1834                            }
1835    
1836                            for (int i = 0; i < orderByConditionFields.length; i++) {
1837                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1838                                    query.append(orderByConditionFields[i]);
1839    
1840                                    if ((i + 1) < orderByConditionFields.length) {
1841                                            if (orderByComparator.isAscending() ^ previous) {
1842                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1843                                            }
1844                                            else {
1845                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1846                                            }
1847                                    }
1848                                    else {
1849                                            if (orderByComparator.isAscending() ^ previous) {
1850                                                    query.append(WHERE_GREATER_THAN);
1851                                            }
1852                                            else {
1853                                                    query.append(WHERE_LESSER_THAN);
1854                                            }
1855                                    }
1856                            }
1857    
1858                            query.append(ORDER_BY_CLAUSE);
1859    
1860                            String[] orderByFields = orderByComparator.getOrderByFields();
1861    
1862                            for (int i = 0; i < orderByFields.length; i++) {
1863                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1864                                    query.append(orderByFields[i]);
1865    
1866                                    if ((i + 1) < orderByFields.length) {
1867                                            if (orderByComparator.isAscending() ^ previous) {
1868                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1869                                            }
1870                                            else {
1871                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1872                                            }
1873                                    }
1874                                    else {
1875                                            if (orderByComparator.isAscending() ^ previous) {
1876                                                    query.append(ORDER_BY_ASC);
1877                                            }
1878                                            else {
1879                                                    query.append(ORDER_BY_DESC);
1880                                            }
1881                                    }
1882                            }
1883                    }
1884    
1885                    else {
1886                            query.append(SocialRequestModelImpl.ORDER_BY_JPQL);
1887                    }
1888    
1889                    String sql = query.toString();
1890    
1891                    Query q = session.createQuery(sql);
1892    
1893                    q.setFirstResult(0);
1894                    q.setMaxResults(2);
1895    
1896                    QueryPos qPos = QueryPos.getInstance(q);
1897    
1898                    qPos.add(companyId);
1899    
1900                    if (orderByComparator != null) {
1901                            Object[] values = orderByComparator.getOrderByConditionValues(socialRequest);
1902    
1903                            for (Object value : values) {
1904                                    qPos.add(value);
1905                            }
1906                    }
1907    
1908                    List<SocialRequest> list = q.list();
1909    
1910                    if (list.size() == 2) {
1911                            return list.get(1);
1912                    }
1913                    else {
1914                            return null;
1915                    }
1916            }
1917    
1918            /**
1919             * Returns all the social requests where userId = &#63;.
1920             *
1921             * @param userId the user ID
1922             * @return the matching social requests
1923             * @throws SystemException if a system exception occurred
1924             */
1925            public List<SocialRequest> findByUserId(long userId)
1926                    throws SystemException {
1927                    return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1928            }
1929    
1930            /**
1931             * Returns a range of all the social requests where userId = &#63;.
1932             *
1933             * <p>
1934             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1935             * </p>
1936             *
1937             * @param userId the user ID
1938             * @param start the lower bound of the range of social requests
1939             * @param end the upper bound of the range of social requests (not inclusive)
1940             * @return the range of matching social requests
1941             * @throws SystemException if a system exception occurred
1942             */
1943            public List<SocialRequest> findByUserId(long userId, int start, int end)
1944                    throws SystemException {
1945                    return findByUserId(userId, start, end, null);
1946            }
1947    
1948            /**
1949             * Returns an ordered range of all the social requests where userId = &#63;.
1950             *
1951             * <p>
1952             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1953             * </p>
1954             *
1955             * @param userId the user ID
1956             * @param start the lower bound of the range of social requests
1957             * @param end the upper bound of the range of social requests (not inclusive)
1958             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1959             * @return the ordered range of matching social requests
1960             * @throws SystemException if a system exception occurred
1961             */
1962            public List<SocialRequest> findByUserId(long userId, int start, int end,
1963                    OrderByComparator orderByComparator) throws SystemException {
1964                    FinderPath finderPath = null;
1965                    Object[] finderArgs = null;
1966    
1967                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1968                                    (orderByComparator == null)) {
1969                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID;
1970                            finderArgs = new Object[] { userId };
1971                    }
1972                    else {
1973                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID;
1974                            finderArgs = new Object[] { userId, start, end, orderByComparator };
1975                    }
1976    
1977                    List<SocialRequest> list = (List<SocialRequest>)FinderCacheUtil.getResult(finderPath,
1978                                    finderArgs, this);
1979    
1980                    if ((list != null) && !list.isEmpty()) {
1981                            for (SocialRequest socialRequest : list) {
1982                                    if ((userId != socialRequest.getUserId())) {
1983                                            list = null;
1984    
1985                                            break;
1986                                    }
1987                            }
1988                    }
1989    
1990                    if (list == null) {
1991                            StringBundler query = null;
1992    
1993                            if (orderByComparator != null) {
1994                                    query = new StringBundler(3 +
1995                                                    (orderByComparator.getOrderByFields().length * 3));
1996                            }
1997                            else {
1998                                    query = new StringBundler(3);
1999                            }
2000    
2001                            query.append(_SQL_SELECT_SOCIALREQUEST_WHERE);
2002    
2003                            query.append(_FINDER_COLUMN_USERID_USERID_2);
2004    
2005                            if (orderByComparator != null) {
2006                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2007                                            orderByComparator);
2008                            }
2009    
2010                            else {
2011                                    query.append(SocialRequestModelImpl.ORDER_BY_JPQL);
2012                            }
2013    
2014                            String sql = query.toString();
2015    
2016                            Session session = null;
2017    
2018                            try {
2019                                    session = openSession();
2020    
2021                                    Query q = session.createQuery(sql);
2022    
2023                                    QueryPos qPos = QueryPos.getInstance(q);
2024    
2025                                    qPos.add(userId);
2026    
2027                                    list = (List<SocialRequest>)QueryUtil.list(q, getDialect(),
2028                                                    start, end);
2029                            }
2030                            catch (Exception e) {
2031                                    throw processException(e);
2032                            }
2033                            finally {
2034                                    if (list == null) {
2035                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
2036                                    }
2037                                    else {
2038                                            cacheResult(list);
2039    
2040                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
2041                                    }
2042    
2043                                    closeSession(session);
2044                            }
2045                    }
2046    
2047                    return list;
2048            }
2049    
2050            /**
2051             * Returns the first social request in the ordered set where userId = &#63;.
2052             *
2053             * @param userId the user ID
2054             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2055             * @return the first matching social request
2056             * @throws com.liferay.portlet.social.NoSuchRequestException if a matching social request could not be found
2057             * @throws SystemException if a system exception occurred
2058             */
2059            public SocialRequest findByUserId_First(long userId,
2060                    OrderByComparator orderByComparator)
2061                    throws NoSuchRequestException, SystemException {
2062                    SocialRequest socialRequest = fetchByUserId_First(userId,
2063                                    orderByComparator);
2064    
2065                    if (socialRequest != null) {
2066                            return socialRequest;
2067                    }
2068    
2069                    StringBundler msg = new StringBundler(4);
2070    
2071                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2072    
2073                    msg.append("userId=");
2074                    msg.append(userId);
2075    
2076                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2077    
2078                    throw new NoSuchRequestException(msg.toString());
2079            }
2080    
2081            /**
2082             * Returns the first social request in the ordered set where userId = &#63;.
2083             *
2084             * @param userId the user ID
2085             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2086             * @return the first matching social request, or <code>null</code> if a matching social request could not be found
2087             * @throws SystemException if a system exception occurred
2088             */
2089            public SocialRequest fetchByUserId_First(long userId,
2090                    OrderByComparator orderByComparator) throws SystemException {
2091                    List<SocialRequest> list = findByUserId(userId, 0, 1, orderByComparator);
2092    
2093                    if (!list.isEmpty()) {
2094                            return list.get(0);
2095                    }
2096    
2097                    return null;
2098            }
2099    
2100            /**
2101             * Returns the last social request in the ordered set where userId = &#63;.
2102             *
2103             * @param userId the user ID
2104             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2105             * @return the last matching social request
2106             * @throws com.liferay.portlet.social.NoSuchRequestException if a matching social request could not be found
2107             * @throws SystemException if a system exception occurred
2108             */
2109            public SocialRequest findByUserId_Last(long userId,
2110                    OrderByComparator orderByComparator)
2111                    throws NoSuchRequestException, SystemException {
2112                    SocialRequest socialRequest = fetchByUserId_Last(userId,
2113                                    orderByComparator);
2114    
2115                    if (socialRequest != null) {
2116                            return socialRequest;
2117                    }
2118    
2119                    StringBundler msg = new StringBundler(4);
2120    
2121                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2122    
2123                    msg.append("userId=");
2124                    msg.append(userId);
2125    
2126                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2127    
2128                    throw new NoSuchRequestException(msg.toString());
2129            }
2130    
2131            /**
2132             * Returns the last social request in the ordered set where userId = &#63;.
2133             *
2134             * @param userId the user ID
2135             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2136             * @return the last matching social request, or <code>null</code> if a matching social request could not be found
2137             * @throws SystemException if a system exception occurred
2138             */
2139            public SocialRequest fetchByUserId_Last(long userId,
2140                    OrderByComparator orderByComparator) throws SystemException {
2141                    int count = countByUserId(userId);
2142    
2143                    List<SocialRequest> list = findByUserId(userId, count - 1, count,
2144                                    orderByComparator);
2145    
2146                    if (!list.isEmpty()) {
2147                            return list.get(0);
2148                    }
2149    
2150                    return null;
2151            }
2152    
2153            /**
2154             * Returns the social requests before and after the current social request in the ordered set where userId = &#63;.
2155             *
2156             * @param requestId the primary key of the current social request
2157             * @param userId the user ID
2158             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2159             * @return the previous, current, and next social request
2160             * @throws com.liferay.portlet.social.NoSuchRequestException if a social request with the primary key could not be found
2161             * @throws SystemException if a system exception occurred
2162             */
2163            public SocialRequest[] findByUserId_PrevAndNext(long requestId,
2164                    long userId, OrderByComparator orderByComparator)
2165                    throws NoSuchRequestException, SystemException {
2166                    SocialRequest socialRequest = findByPrimaryKey(requestId);
2167    
2168                    Session session = null;
2169    
2170                    try {
2171                            session = openSession();
2172    
2173                            SocialRequest[] array = new SocialRequestImpl[3];
2174    
2175                            array[0] = getByUserId_PrevAndNext(session, socialRequest, userId,
2176                                            orderByComparator, true);
2177    
2178                            array[1] = socialRequest;
2179    
2180                            array[2] = getByUserId_PrevAndNext(session, socialRequest, userId,
2181                                            orderByComparator, false);
2182    
2183                            return array;
2184                    }
2185                    catch (Exception e) {
2186                            throw processException(e);
2187                    }
2188                    finally {
2189                            closeSession(session);
2190                    }
2191            }
2192    
2193            protected SocialRequest getByUserId_PrevAndNext(Session session,
2194                    SocialRequest socialRequest, long userId,
2195                    OrderByComparator orderByComparator, boolean previous) {
2196                    StringBundler query = null;
2197    
2198                    if (orderByComparator != null) {
2199                            query = new StringBundler(6 +
2200                                            (orderByComparator.getOrderByFields().length * 6));
2201                    }
2202                    else {
2203                            query = new StringBundler(3);
2204                    }
2205    
2206                    query.append(_SQL_SELECT_SOCIALREQUEST_WHERE);
2207    
2208                    query.append(_FINDER_COLUMN_USERID_USERID_2);
2209    
2210                    if (orderByComparator != null) {
2211                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2212    
2213                            if (orderByConditionFields.length > 0) {
2214                                    query.append(WHERE_AND);
2215                            }
2216    
2217                            for (int i = 0; i < orderByConditionFields.length; i++) {
2218                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2219                                    query.append(orderByConditionFields[i]);
2220    
2221                                    if ((i + 1) < orderByConditionFields.length) {
2222                                            if (orderByComparator.isAscending() ^ previous) {
2223                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2224                                            }
2225                                            else {
2226                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2227                                            }
2228                                    }
2229                                    else {
2230                                            if (orderByComparator.isAscending() ^ previous) {
2231                                                    query.append(WHERE_GREATER_THAN);
2232                                            }
2233                                            else {
2234                                                    query.append(WHERE_LESSER_THAN);
2235                                            }
2236                                    }
2237                            }
2238    
2239                            query.append(ORDER_BY_CLAUSE);
2240    
2241                            String[] orderByFields = orderByComparator.getOrderByFields();
2242    
2243                            for (int i = 0; i < orderByFields.length; i++) {
2244                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2245                                    query.append(orderByFields[i]);
2246    
2247                                    if ((i + 1) < orderByFields.length) {
2248                                            if (orderByComparator.isAscending() ^ previous) {
2249                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2250                                            }
2251                                            else {
2252                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2253                                            }
2254                                    }
2255                                    else {
2256                                            if (orderByComparator.isAscending() ^ previous) {
2257                                                    query.append(ORDER_BY_ASC);
2258                                            }
2259                                            else {
2260                                                    query.append(ORDER_BY_DESC);
2261                                            }
2262                                    }
2263                            }
2264                    }
2265    
2266                    else {
2267                            query.append(SocialRequestModelImpl.ORDER_BY_JPQL);
2268                    }
2269    
2270                    String sql = query.toString();
2271    
2272                    Query q = session.createQuery(sql);
2273    
2274                    q.setFirstResult(0);
2275                    q.setMaxResults(2);
2276    
2277                    QueryPos qPos = QueryPos.getInstance(q);
2278    
2279                    qPos.add(userId);
2280    
2281                    if (orderByComparator != null) {
2282                            Object[] values = orderByComparator.getOrderByConditionValues(socialRequest);
2283    
2284                            for (Object value : values) {
2285                                    qPos.add(value);
2286                            }
2287                    }
2288    
2289                    List<SocialRequest> list = q.list();
2290    
2291                    if (list.size() == 2) {
2292                            return list.get(1);
2293                    }
2294                    else {
2295                            return null;
2296                    }
2297            }
2298    
2299            /**
2300             * Returns all the social requests where receiverUserId = &#63;.
2301             *
2302             * @param receiverUserId the receiver user ID
2303             * @return the matching social requests
2304             * @throws SystemException if a system exception occurred
2305             */
2306            public List<SocialRequest> findByReceiverUserId(long receiverUserId)
2307                    throws SystemException {
2308                    return findByReceiverUserId(receiverUserId, QueryUtil.ALL_POS,
2309                            QueryUtil.ALL_POS, null);
2310            }
2311    
2312            /**
2313             * Returns a range of all the social requests where receiverUserId = &#63;.
2314             *
2315             * <p>
2316             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2317             * </p>
2318             *
2319             * @param receiverUserId the receiver user ID
2320             * @param start the lower bound of the range of social requests
2321             * @param end the upper bound of the range of social requests (not inclusive)
2322             * @return the range of matching social requests
2323             * @throws SystemException if a system exception occurred
2324             */
2325            public List<SocialRequest> findByReceiverUserId(long receiverUserId,
2326                    int start, int end) throws SystemException {
2327                    return findByReceiverUserId(receiverUserId, start, end, null);
2328            }
2329    
2330            /**
2331             * Returns an ordered range of all the social requests where receiverUserId = &#63;.
2332             *
2333             * <p>
2334             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2335             * </p>
2336             *
2337             * @param receiverUserId the receiver user ID
2338             * @param start the lower bound of the range of social requests
2339             * @param end the upper bound of the range of social requests (not inclusive)
2340             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2341             * @return the ordered range of matching social requests
2342             * @throws SystemException if a system exception occurred
2343             */
2344            public List<SocialRequest> findByReceiverUserId(long receiverUserId,
2345                    int start, int end, OrderByComparator orderByComparator)
2346                    throws SystemException {
2347                    FinderPath finderPath = null;
2348                    Object[] finderArgs = null;
2349    
2350                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2351                                    (orderByComparator == null)) {
2352                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RECEIVERUSERID;
2353                            finderArgs = new Object[] { receiverUserId };
2354                    }
2355                    else {
2356                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_RECEIVERUSERID;
2357                            finderArgs = new Object[] {
2358                                            receiverUserId,
2359                                            
2360                                            start, end, orderByComparator
2361                                    };
2362                    }
2363    
2364                    List<SocialRequest> list = (List<SocialRequest>)FinderCacheUtil.getResult(finderPath,
2365                                    finderArgs, this);
2366    
2367                    if ((list != null) && !list.isEmpty()) {
2368                            for (SocialRequest socialRequest : list) {
2369                                    if ((receiverUserId != socialRequest.getReceiverUserId())) {
2370                                            list = null;
2371    
2372                                            break;
2373                                    }
2374                            }
2375                    }
2376    
2377                    if (list == null) {
2378                            StringBundler query = null;
2379    
2380                            if (orderByComparator != null) {
2381                                    query = new StringBundler(3 +
2382                                                    (orderByComparator.getOrderByFields().length * 3));
2383                            }
2384                            else {
2385                                    query = new StringBundler(3);
2386                            }
2387    
2388                            query.append(_SQL_SELECT_SOCIALREQUEST_WHERE);
2389    
2390                            query.append(_FINDER_COLUMN_RECEIVERUSERID_RECEIVERUSERID_2);
2391    
2392                            if (orderByComparator != null) {
2393                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2394                                            orderByComparator);
2395                            }
2396    
2397                            else {
2398                                    query.append(SocialRequestModelImpl.ORDER_BY_JPQL);
2399                            }
2400    
2401                            String sql = query.toString();
2402    
2403                            Session session = null;
2404    
2405                            try {
2406                                    session = openSession();
2407    
2408                                    Query q = session.createQuery(sql);
2409    
2410                                    QueryPos qPos = QueryPos.getInstance(q);
2411    
2412                                    qPos.add(receiverUserId);
2413    
2414                                    list = (List<SocialRequest>)QueryUtil.list(q, getDialect(),
2415                                                    start, end);
2416                            }
2417                            catch (Exception e) {
2418                                    throw processException(e);
2419                            }
2420                            finally {
2421                                    if (list == null) {
2422                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
2423                                    }
2424                                    else {
2425                                            cacheResult(list);
2426    
2427                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
2428                                    }
2429    
2430                                    closeSession(session);
2431                            }
2432                    }
2433    
2434                    return list;
2435            }
2436    
2437            /**
2438             * Returns the first social request in the ordered set where receiverUserId = &#63;.
2439             *
2440             * @param receiverUserId the receiver user ID
2441             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2442             * @return the first matching social request
2443             * @throws com.liferay.portlet.social.NoSuchRequestException if a matching social request could not be found
2444             * @throws SystemException if a system exception occurred
2445             */
2446            public SocialRequest findByReceiverUserId_First(long receiverUserId,
2447                    OrderByComparator orderByComparator)
2448                    throws NoSuchRequestException, SystemException {
2449                    SocialRequest socialRequest = fetchByReceiverUserId_First(receiverUserId,
2450                                    orderByComparator);
2451    
2452                    if (socialRequest != null) {
2453                            return socialRequest;
2454                    }
2455    
2456                    StringBundler msg = new StringBundler(4);
2457    
2458                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2459    
2460                    msg.append("receiverUserId=");
2461                    msg.append(receiverUserId);
2462    
2463                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2464    
2465                    throw new NoSuchRequestException(msg.toString());
2466            }
2467    
2468            /**
2469             * Returns the first social request in the ordered set where receiverUserId = &#63;.
2470             *
2471             * @param receiverUserId the receiver user ID
2472             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2473             * @return the first matching social request, or <code>null</code> if a matching social request could not be found
2474             * @throws SystemException if a system exception occurred
2475             */
2476            public SocialRequest fetchByReceiverUserId_First(long receiverUserId,
2477                    OrderByComparator orderByComparator) throws SystemException {
2478                    List<SocialRequest> list = findByReceiverUserId(receiverUserId, 0, 1,
2479                                    orderByComparator);
2480    
2481                    if (!list.isEmpty()) {
2482                            return list.get(0);
2483                    }
2484    
2485                    return null;
2486            }
2487    
2488            /**
2489             * Returns the last social request in the ordered set where receiverUserId = &#63;.
2490             *
2491             * @param receiverUserId the receiver user ID
2492             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2493             * @return the last matching social request
2494             * @throws com.liferay.portlet.social.NoSuchRequestException if a matching social request could not be found
2495             * @throws SystemException if a system exception occurred
2496             */
2497            public SocialRequest findByReceiverUserId_Last(long receiverUserId,
2498                    OrderByComparator orderByComparator)
2499                    throws NoSuchRequestException, SystemException {
2500                    SocialRequest socialRequest = fetchByReceiverUserId_Last(receiverUserId,
2501                                    orderByComparator);
2502    
2503                    if (socialRequest != null) {
2504                            return socialRequest;
2505                    }
2506    
2507                    StringBundler msg = new StringBundler(4);
2508    
2509                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2510    
2511                    msg.append("receiverUserId=");
2512                    msg.append(receiverUserId);
2513    
2514                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2515    
2516                    throw new NoSuchRequestException(msg.toString());
2517            }
2518    
2519            /**
2520             * Returns the last social request in the ordered set where receiverUserId = &#63;.
2521             *
2522             * @param receiverUserId the receiver user ID
2523             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2524             * @return the last matching social request, or <code>null</code> if a matching social request could not be found
2525             * @throws SystemException if a system exception occurred
2526             */
2527            public SocialRequest fetchByReceiverUserId_Last(long receiverUserId,
2528                    OrderByComparator orderByComparator) throws SystemException {
2529                    int count = countByReceiverUserId(receiverUserId);
2530    
2531                    List<SocialRequest> list = findByReceiverUserId(receiverUserId,
2532                                    count - 1, count, orderByComparator);
2533    
2534                    if (!list.isEmpty()) {
2535                            return list.get(0);
2536                    }
2537    
2538                    return null;
2539            }
2540    
2541            /**
2542             * Returns the social requests before and after the current social request in the ordered set where receiverUserId = &#63;.
2543             *
2544             * @param requestId the primary key of the current social request
2545             * @param receiverUserId the receiver user ID
2546             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2547             * @return the previous, current, and next social request
2548             * @throws com.liferay.portlet.social.NoSuchRequestException if a social request with the primary key could not be found
2549             * @throws SystemException if a system exception occurred
2550             */
2551            public SocialRequest[] findByReceiverUserId_PrevAndNext(long requestId,
2552                    long receiverUserId, OrderByComparator orderByComparator)
2553                    throws NoSuchRequestException, SystemException {
2554                    SocialRequest socialRequest = findByPrimaryKey(requestId);
2555    
2556                    Session session = null;
2557    
2558                    try {
2559                            session = openSession();
2560    
2561                            SocialRequest[] array = new SocialRequestImpl[3];
2562    
2563                            array[0] = getByReceiverUserId_PrevAndNext(session, socialRequest,
2564                                            receiverUserId, orderByComparator, true);
2565    
2566                            array[1] = socialRequest;
2567    
2568                            array[2] = getByReceiverUserId_PrevAndNext(session, socialRequest,
2569                                            receiverUserId, orderByComparator, false);
2570    
2571                            return array;
2572                    }
2573                    catch (Exception e) {
2574                            throw processException(e);
2575                    }
2576                    finally {
2577                            closeSession(session);
2578                    }
2579            }
2580    
2581            protected SocialRequest getByReceiverUserId_PrevAndNext(Session session,
2582                    SocialRequest socialRequest, long receiverUserId,
2583                    OrderByComparator orderByComparator, boolean previous) {
2584                    StringBundler query = null;
2585    
2586                    if (orderByComparator != null) {
2587                            query = new StringBundler(6 +
2588                                            (orderByComparator.getOrderByFields().length * 6));
2589                    }
2590                    else {
2591                            query = new StringBundler(3);
2592                    }
2593    
2594                    query.append(_SQL_SELECT_SOCIALREQUEST_WHERE);
2595    
2596                    query.append(_FINDER_COLUMN_RECEIVERUSERID_RECEIVERUSERID_2);
2597    
2598                    if (orderByComparator != null) {
2599                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2600    
2601                            if (orderByConditionFields.length > 0) {
2602                                    query.append(WHERE_AND);
2603                            }
2604    
2605                            for (int i = 0; i < orderByConditionFields.length; i++) {
2606                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2607                                    query.append(orderByConditionFields[i]);
2608    
2609                                    if ((i + 1) < orderByConditionFields.length) {
2610                                            if (orderByComparator.isAscending() ^ previous) {
2611                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2612                                            }
2613                                            else {
2614                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2615                                            }
2616                                    }
2617                                    else {
2618                                            if (orderByComparator.isAscending() ^ previous) {
2619                                                    query.append(WHERE_GREATER_THAN);
2620                                            }
2621                                            else {
2622                                                    query.append(WHERE_LESSER_THAN);
2623                                            }
2624                                    }
2625                            }
2626    
2627                            query.append(ORDER_BY_CLAUSE);
2628    
2629                            String[] orderByFields = orderByComparator.getOrderByFields();
2630    
2631                            for (int i = 0; i < orderByFields.length; i++) {
2632                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2633                                    query.append(orderByFields[i]);
2634    
2635                                    if ((i + 1) < orderByFields.length) {
2636                                            if (orderByComparator.isAscending() ^ previous) {
2637                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2638                                            }
2639                                            else {
2640                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2641                                            }
2642                                    }
2643                                    else {
2644                                            if (orderByComparator.isAscending() ^ previous) {
2645                                                    query.append(ORDER_BY_ASC);
2646                                            }
2647                                            else {
2648                                                    query.append(ORDER_BY_DESC);
2649                                            }
2650                                    }
2651                            }
2652                    }
2653    
2654                    else {
2655                            query.append(SocialRequestModelImpl.ORDER_BY_JPQL);
2656                    }
2657    
2658                    String sql = query.toString();
2659    
2660                    Query q = session.createQuery(sql);
2661    
2662                    q.setFirstResult(0);
2663                    q.setMaxResults(2);
2664    
2665                    QueryPos qPos = QueryPos.getInstance(q);
2666    
2667                    qPos.add(receiverUserId);
2668    
2669                    if (orderByComparator != null) {
2670                            Object[] values = orderByComparator.getOrderByConditionValues(socialRequest);
2671    
2672                            for (Object value : values) {
2673                                    qPos.add(value);
2674                            }
2675                    }
2676    
2677                    List<SocialRequest> list = q.list();
2678    
2679                    if (list.size() == 2) {
2680                            return list.get(1);
2681                    }
2682                    else {
2683                            return null;
2684                    }
2685            }
2686    
2687            /**
2688             * Returns all the social requests where userId = &#63; and status = &#63;.
2689             *
2690             * @param userId the user ID
2691             * @param status the status
2692             * @return the matching social requests
2693             * @throws SystemException if a system exception occurred
2694             */
2695            public List<SocialRequest> findByU_S(long userId, int status)
2696                    throws SystemException {
2697                    return findByU_S(userId, status, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2698                            null);
2699            }
2700    
2701            /**
2702             * Returns a range of all the social requests where userId = &#63; and status = &#63;.
2703             *
2704             * <p>
2705             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2706             * </p>
2707             *
2708             * @param userId the user ID
2709             * @param status the status
2710             * @param start the lower bound of the range of social requests
2711             * @param end the upper bound of the range of social requests (not inclusive)
2712             * @return the range of matching social requests
2713             * @throws SystemException if a system exception occurred
2714             */
2715            public List<SocialRequest> findByU_S(long userId, int status, int start,
2716                    int end) throws SystemException {
2717                    return findByU_S(userId, status, start, end, null);
2718            }
2719    
2720            /**
2721             * Returns an ordered range of all the social requests where userId = &#63; and status = &#63;.
2722             *
2723             * <p>
2724             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2725             * </p>
2726             *
2727             * @param userId the user ID
2728             * @param status the status
2729             * @param start the lower bound of the range of social requests
2730             * @param end the upper bound of the range of social requests (not inclusive)
2731             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2732             * @return the ordered range of matching social requests
2733             * @throws SystemException if a system exception occurred
2734             */
2735            public List<SocialRequest> findByU_S(long userId, int status, int start,
2736                    int end, OrderByComparator orderByComparator) throws SystemException {
2737                    FinderPath finderPath = null;
2738                    Object[] finderArgs = null;
2739    
2740                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2741                                    (orderByComparator == null)) {
2742                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_S;
2743                            finderArgs = new Object[] { userId, status };
2744                    }
2745                    else {
2746                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_S;
2747                            finderArgs = new Object[] {
2748                                            userId, status,
2749                                            
2750                                            start, end, orderByComparator
2751                                    };
2752                    }
2753    
2754                    List<SocialRequest> list = (List<SocialRequest>)FinderCacheUtil.getResult(finderPath,
2755                                    finderArgs, this);
2756    
2757                    if ((list != null) && !list.isEmpty()) {
2758                            for (SocialRequest socialRequest : list) {
2759                                    if ((userId != socialRequest.getUserId()) ||
2760                                                    (status != socialRequest.getStatus())) {
2761                                            list = null;
2762    
2763                                            break;
2764                                    }
2765                            }
2766                    }
2767    
2768                    if (list == null) {
2769                            StringBundler query = null;
2770    
2771                            if (orderByComparator != null) {
2772                                    query = new StringBundler(4 +
2773                                                    (orderByComparator.getOrderByFields().length * 3));
2774                            }
2775                            else {
2776                                    query = new StringBundler(4);
2777                            }
2778    
2779                            query.append(_SQL_SELECT_SOCIALREQUEST_WHERE);
2780    
2781                            query.append(_FINDER_COLUMN_U_S_USERID_2);
2782    
2783                            query.append(_FINDER_COLUMN_U_S_STATUS_2);
2784    
2785                            if (orderByComparator != null) {
2786                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2787                                            orderByComparator);
2788                            }
2789    
2790                            else {
2791                                    query.append(SocialRequestModelImpl.ORDER_BY_JPQL);
2792                            }
2793    
2794                            String sql = query.toString();
2795    
2796                            Session session = null;
2797    
2798                            try {
2799                                    session = openSession();
2800    
2801                                    Query q = session.createQuery(sql);
2802    
2803                                    QueryPos qPos = QueryPos.getInstance(q);
2804    
2805                                    qPos.add(userId);
2806    
2807                                    qPos.add(status);
2808    
2809                                    list = (List<SocialRequest>)QueryUtil.list(q, getDialect(),
2810                                                    start, end);
2811                            }
2812                            catch (Exception e) {
2813                                    throw processException(e);
2814                            }
2815                            finally {
2816                                    if (list == null) {
2817                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
2818                                    }
2819                                    else {
2820                                            cacheResult(list);
2821    
2822                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
2823                                    }
2824    
2825                                    closeSession(session);
2826                            }
2827                    }
2828    
2829                    return list;
2830            }
2831    
2832            /**
2833             * Returns the first social request in the ordered set where userId = &#63; and status = &#63;.
2834             *
2835             * @param userId the user ID
2836             * @param status the status
2837             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2838             * @return the first matching social request
2839             * @throws com.liferay.portlet.social.NoSuchRequestException if a matching social request could not be found
2840             * @throws SystemException if a system exception occurred
2841             */
2842            public SocialRequest findByU_S_First(long userId, int status,
2843                    OrderByComparator orderByComparator)
2844                    throws NoSuchRequestException, SystemException {
2845                    SocialRequest socialRequest = fetchByU_S_First(userId, status,
2846                                    orderByComparator);
2847    
2848                    if (socialRequest != null) {
2849                            return socialRequest;
2850                    }
2851    
2852                    StringBundler msg = new StringBundler(6);
2853    
2854                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2855    
2856                    msg.append("userId=");
2857                    msg.append(userId);
2858    
2859                    msg.append(", status=");
2860                    msg.append(status);
2861    
2862                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2863    
2864                    throw new NoSuchRequestException(msg.toString());
2865            }
2866    
2867            /**
2868             * Returns the first social request in the ordered set where userId = &#63; and status = &#63;.
2869             *
2870             * @param userId the user ID
2871             * @param status the status
2872             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2873             * @return the first matching social request, or <code>null</code> if a matching social request could not be found
2874             * @throws SystemException if a system exception occurred
2875             */
2876            public SocialRequest fetchByU_S_First(long userId, int status,
2877                    OrderByComparator orderByComparator) throws SystemException {
2878                    List<SocialRequest> list = findByU_S(userId, status, 0, 1,
2879                                    orderByComparator);
2880    
2881                    if (!list.isEmpty()) {
2882                            return list.get(0);
2883                    }
2884    
2885                    return null;
2886            }
2887    
2888            /**
2889             * Returns the last social request in the ordered set where userId = &#63; and status = &#63;.
2890             *
2891             * @param userId the user ID
2892             * @param status the status
2893             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2894             * @return the last matching social request
2895             * @throws com.liferay.portlet.social.NoSuchRequestException if a matching social request could not be found
2896             * @throws SystemException if a system exception occurred
2897             */
2898            public SocialRequest findByU_S_Last(long userId, int status,
2899                    OrderByComparator orderByComparator)
2900                    throws NoSuchRequestException, SystemException {
2901                    SocialRequest socialRequest = fetchByU_S_Last(userId, status,
2902                                    orderByComparator);
2903    
2904                    if (socialRequest != null) {
2905                            return socialRequest;
2906                    }
2907    
2908                    StringBundler msg = new StringBundler(6);
2909    
2910                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2911    
2912                    msg.append("userId=");
2913                    msg.append(userId);
2914    
2915                    msg.append(", status=");
2916                    msg.append(status);
2917    
2918                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2919    
2920                    throw new NoSuchRequestException(msg.toString());
2921            }
2922    
2923            /**
2924             * Returns the last social request in the ordered set where userId = &#63; and status = &#63;.
2925             *
2926             * @param userId the user ID
2927             * @param status the status
2928             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2929             * @return the last matching social request, or <code>null</code> if a matching social request could not be found
2930             * @throws SystemException if a system exception occurred
2931             */
2932            public SocialRequest fetchByU_S_Last(long userId, int status,
2933                    OrderByComparator orderByComparator) throws SystemException {
2934                    int count = countByU_S(userId, status);
2935    
2936                    List<SocialRequest> list = findByU_S(userId, status, count - 1, count,
2937                                    orderByComparator);
2938    
2939                    if (!list.isEmpty()) {
2940                            return list.get(0);
2941                    }
2942    
2943                    return null;
2944            }
2945    
2946            /**
2947             * Returns the social requests before and after the current social request in the ordered set where userId = &#63; and status = &#63;.
2948             *
2949             * @param requestId the primary key of the current social request
2950             * @param userId the user ID
2951             * @param status the status
2952             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2953             * @return the previous, current, and next social request
2954             * @throws com.liferay.portlet.social.NoSuchRequestException if a social request with the primary key could not be found
2955             * @throws SystemException if a system exception occurred
2956             */
2957            public SocialRequest[] findByU_S_PrevAndNext(long requestId, long userId,
2958                    int status, OrderByComparator orderByComparator)
2959                    throws NoSuchRequestException, SystemException {
2960                    SocialRequest socialRequest = findByPrimaryKey(requestId);
2961    
2962                    Session session = null;
2963    
2964                    try {
2965                            session = openSession();
2966    
2967                            SocialRequest[] array = new SocialRequestImpl[3];
2968    
2969                            array[0] = getByU_S_PrevAndNext(session, socialRequest, userId,
2970                                            status, orderByComparator, true);
2971    
2972                            array[1] = socialRequest;
2973    
2974                            array[2] = getByU_S_PrevAndNext(session, socialRequest, userId,
2975                                            status, orderByComparator, false);
2976    
2977                            return array;
2978                    }
2979                    catch (Exception e) {
2980                            throw processException(e);
2981                    }
2982                    finally {
2983                            closeSession(session);
2984                    }
2985            }
2986    
2987            protected SocialRequest getByU_S_PrevAndNext(Session session,
2988                    SocialRequest socialRequest, long userId, int status,
2989                    OrderByComparator orderByComparator, boolean previous) {
2990                    StringBundler query = null;
2991    
2992                    if (orderByComparator != null) {
2993                            query = new StringBundler(6 +
2994                                            (orderByComparator.getOrderByFields().length * 6));
2995                    }
2996                    else {
2997                            query = new StringBundler(3);
2998                    }
2999    
3000                    query.append(_SQL_SELECT_SOCIALREQUEST_WHERE);
3001    
3002                    query.append(_FINDER_COLUMN_U_S_USERID_2);
3003    
3004                    query.append(_FINDER_COLUMN_U_S_STATUS_2);
3005    
3006                    if (orderByComparator != null) {
3007                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3008    
3009                            if (orderByConditionFields.length > 0) {
3010                                    query.append(WHERE_AND);
3011                            }
3012    
3013                            for (int i = 0; i < orderByConditionFields.length; i++) {
3014                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3015                                    query.append(orderByConditionFields[i]);
3016    
3017                                    if ((i + 1) < orderByConditionFields.length) {
3018                                            if (orderByComparator.isAscending() ^ previous) {
3019                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3020                                            }
3021                                            else {
3022                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3023                                            }
3024                                    }
3025                                    else {
3026                                            if (orderByComparator.isAscending() ^ previous) {
3027                                                    query.append(WHERE_GREATER_THAN);
3028                                            }
3029                                            else {
3030                                                    query.append(WHERE_LESSER_THAN);
3031                                            }
3032                                    }
3033                            }
3034    
3035                            query.append(ORDER_BY_CLAUSE);
3036    
3037                            String[] orderByFields = orderByComparator.getOrderByFields();
3038    
3039                            for (int i = 0; i < orderByFields.length; i++) {
3040                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3041                                    query.append(orderByFields[i]);
3042    
3043                                    if ((i + 1) < orderByFields.length) {
3044                                            if (orderByComparator.isAscending() ^ previous) {
3045                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3046                                            }
3047                                            else {
3048                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3049                                            }
3050                                    }
3051                                    else {
3052                                            if (orderByComparator.isAscending() ^ previous) {
3053                                                    query.append(ORDER_BY_ASC);
3054                                            }
3055                                            else {
3056                                                    query.append(ORDER_BY_DESC);
3057                                            }
3058                                    }
3059                            }
3060                    }
3061    
3062                    else {
3063                            query.append(SocialRequestModelImpl.ORDER_BY_JPQL);
3064                    }
3065    
3066                    String sql = query.toString();
3067    
3068                    Query q = session.createQuery(sql);
3069    
3070                    q.setFirstResult(0);
3071                    q.setMaxResults(2);
3072    
3073                    QueryPos qPos = QueryPos.getInstance(q);
3074    
3075                    qPos.add(userId);
3076    
3077                    qPos.add(status);
3078    
3079                    if (orderByComparator != null) {
3080                            Object[] values = orderByComparator.getOrderByConditionValues(socialRequest);
3081    
3082                            for (Object value : values) {
3083                                    qPos.add(value);
3084                            }
3085                    }
3086    
3087                    List<SocialRequest> list = q.list();
3088    
3089                    if (list.size() == 2) {
3090                            return list.get(1);
3091                    }
3092                    else {
3093                            return null;
3094                    }
3095            }
3096    
3097            /**
3098             * Returns all the social requests where receiverUserId = &#63; and status = &#63;.
3099             *
3100             * @param receiverUserId the receiver user ID
3101             * @param status the status
3102             * @return the matching social requests
3103             * @throws SystemException if a system exception occurred
3104             */
3105            public List<SocialRequest> findByR_S(long receiverUserId, int status)
3106                    throws SystemException {
3107                    return findByR_S(receiverUserId, status, QueryUtil.ALL_POS,
3108                            QueryUtil.ALL_POS, null);
3109            }
3110    
3111            /**
3112             * Returns a range of all the social requests where receiverUserId = &#63; and status = &#63;.
3113             *
3114             * <p>
3115             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3116             * </p>
3117             *
3118             * @param receiverUserId the receiver user ID
3119             * @param status the status
3120             * @param start the lower bound of the range of social requests
3121             * @param end the upper bound of the range of social requests (not inclusive)
3122             * @return the range of matching social requests
3123             * @throws SystemException if a system exception occurred
3124             */
3125            public List<SocialRequest> findByR_S(long receiverUserId, int status,
3126                    int start, int end) throws SystemException {
3127                    return findByR_S(receiverUserId, status, start, end, null);
3128            }
3129    
3130            /**
3131             * Returns an ordered range of all the social requests where receiverUserId = &#63; and status = &#63;.
3132             *
3133             * <p>
3134             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3135             * </p>
3136             *
3137             * @param receiverUserId the receiver user ID
3138             * @param status the status
3139             * @param start the lower bound of the range of social requests
3140             * @param end the upper bound of the range of social requests (not inclusive)
3141             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3142             * @return the ordered range of matching social requests
3143             * @throws SystemException if a system exception occurred
3144             */
3145            public List<SocialRequest> findByR_S(long receiverUserId, int status,
3146                    int start, int end, OrderByComparator orderByComparator)
3147                    throws SystemException {
3148                    FinderPath finderPath = null;
3149                    Object[] finderArgs = null;
3150    
3151                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3152                                    (orderByComparator == null)) {
3153                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_S;
3154                            finderArgs = new Object[] { receiverUserId, status };
3155                    }
3156                    else {
3157                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_R_S;
3158                            finderArgs = new Object[] {
3159                                            receiverUserId, status,
3160                                            
3161                                            start, end, orderByComparator
3162                                    };
3163                    }
3164    
3165                    List<SocialRequest> list = (List<SocialRequest>)FinderCacheUtil.getResult(finderPath,
3166                                    finderArgs, this);
3167    
3168                    if ((list != null) && !list.isEmpty()) {
3169                            for (SocialRequest socialRequest : list) {
3170                                    if ((receiverUserId != socialRequest.getReceiverUserId()) ||
3171                                                    (status != socialRequest.getStatus())) {
3172                                            list = null;
3173    
3174                                            break;
3175                                    }
3176                            }
3177                    }
3178    
3179                    if (list == null) {
3180                            StringBundler query = null;
3181    
3182                            if (orderByComparator != null) {
3183                                    query = new StringBundler(4 +
3184                                                    (orderByComparator.getOrderByFields().length * 3));
3185                            }
3186                            else {
3187                                    query = new StringBundler(4);
3188                            }
3189    
3190                            query.append(_SQL_SELECT_SOCIALREQUEST_WHERE);
3191    
3192                            query.append(_FINDER_COLUMN_R_S_RECEIVERUSERID_2);
3193    
3194                            query.append(_FINDER_COLUMN_R_S_STATUS_2);
3195    
3196                            if (orderByComparator != null) {
3197                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3198                                            orderByComparator);
3199                            }
3200    
3201                            else {
3202                                    query.append(SocialRequestModelImpl.ORDER_BY_JPQL);
3203                            }
3204    
3205                            String sql = query.toString();
3206    
3207                            Session session = null;
3208    
3209                            try {
3210                                    session = openSession();
3211    
3212                                    Query q = session.createQuery(sql);
3213    
3214                                    QueryPos qPos = QueryPos.getInstance(q);
3215    
3216                                    qPos.add(receiverUserId);
3217    
3218                                    qPos.add(status);
3219    
3220                                    list = (List<SocialRequest>)QueryUtil.list(q, getDialect(),
3221                                                    start, end);
3222                            }
3223                            catch (Exception e) {
3224                                    throw processException(e);
3225                            }
3226                            finally {
3227                                    if (list == null) {
3228                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
3229                                    }
3230                                    else {
3231                                            cacheResult(list);
3232    
3233                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
3234                                    }
3235    
3236                                    closeSession(session);
3237                            }
3238                    }
3239    
3240                    return list;
3241            }
3242    
3243            /**
3244             * Returns the first social request in the ordered set where receiverUserId = &#63; and status = &#63;.
3245             *
3246             * @param receiverUserId the receiver user ID
3247             * @param status the status
3248             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3249             * @return the first matching social request
3250             * @throws com.liferay.portlet.social.NoSuchRequestException if a matching social request could not be found
3251             * @throws SystemException if a system exception occurred
3252             */
3253            public SocialRequest findByR_S_First(long receiverUserId, int status,
3254                    OrderByComparator orderByComparator)
3255                    throws NoSuchRequestException, SystemException {
3256                    SocialRequest socialRequest = fetchByR_S_First(receiverUserId, status,
3257                                    orderByComparator);
3258    
3259                    if (socialRequest != null) {
3260                            return socialRequest;
3261                    }
3262    
3263                    StringBundler msg = new StringBundler(6);
3264    
3265                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3266    
3267                    msg.append("receiverUserId=");
3268                    msg.append(receiverUserId);
3269    
3270                    msg.append(", status=");
3271                    msg.append(status);
3272    
3273                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3274    
3275                    throw new NoSuchRequestException(msg.toString());
3276            }
3277    
3278            /**
3279             * Returns the first social request in the ordered set where receiverUserId = &#63; and status = &#63;.
3280             *
3281             * @param receiverUserId the receiver user ID
3282             * @param status the status
3283             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3284             * @return the first matching social request, or <code>null</code> if a matching social request could not be found
3285             * @throws SystemException if a system exception occurred
3286             */
3287            public SocialRequest fetchByR_S_First(long receiverUserId, int status,
3288                    OrderByComparator orderByComparator) throws SystemException {
3289                    List<SocialRequest> list = findByR_S(receiverUserId, status, 0, 1,
3290                                    orderByComparator);
3291    
3292                    if (!list.isEmpty()) {
3293                            return list.get(0);
3294                    }
3295    
3296                    return null;
3297            }
3298    
3299            /**
3300             * Returns the last social request in the ordered set where receiverUserId = &#63; and status = &#63;.
3301             *
3302             * @param receiverUserId the receiver user ID
3303             * @param status the status
3304             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3305             * @return the last matching social request
3306             * @throws com.liferay.portlet.social.NoSuchRequestException if a matching social request could not be found
3307             * @throws SystemException if a system exception occurred
3308             */
3309            public SocialRequest findByR_S_Last(long receiverUserId, int status,
3310                    OrderByComparator orderByComparator)
3311                    throws NoSuchRequestException, SystemException {
3312                    SocialRequest socialRequest = fetchByR_S_Last(receiverUserId, status,
3313                                    orderByComparator);
3314    
3315                    if (socialRequest != null) {
3316                            return socialRequest;
3317                    }
3318    
3319                    StringBundler msg = new StringBundler(6);
3320    
3321                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3322    
3323                    msg.append("receiverUserId=");
3324                    msg.append(receiverUserId);
3325    
3326                    msg.append(", status=");
3327                    msg.append(status);
3328    
3329                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3330    
3331                    throw new NoSuchRequestException(msg.toString());
3332            }
3333    
3334            /**
3335             * Returns the last social request in the ordered set where receiverUserId = &#63; and status = &#63;.
3336             *
3337             * @param receiverUserId the receiver user ID
3338             * @param status the status
3339             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3340             * @return the last matching social request, or <code>null</code> if a matching social request could not be found
3341             * @throws SystemException if a system exception occurred
3342             */
3343            public SocialRequest fetchByR_S_Last(long receiverUserId, int status,
3344                    OrderByComparator orderByComparator) throws SystemException {
3345                    int count = countByR_S(receiverUserId, status);
3346    
3347                    List<SocialRequest> list = findByR_S(receiverUserId, status, count - 1,
3348                                    count, orderByComparator);
3349    
3350                    if (!list.isEmpty()) {
3351                            return list.get(0);
3352                    }
3353    
3354                    return null;
3355            }
3356    
3357            /**
3358             * Returns the social requests before and after the current social request in the ordered set where receiverUserId = &#63; and status = &#63;.
3359             *
3360             * @param requestId the primary key of the current social request
3361             * @param receiverUserId the receiver user ID
3362             * @param status the status
3363             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3364             * @return the previous, current, and next social request
3365             * @throws com.liferay.portlet.social.NoSuchRequestException if a social request with the primary key could not be found
3366             * @throws SystemException if a system exception occurred
3367             */
3368            public SocialRequest[] findByR_S_PrevAndNext(long requestId,
3369                    long receiverUserId, int status, OrderByComparator orderByComparator)
3370                    throws NoSuchRequestException, SystemException {
3371                    SocialRequest socialRequest = findByPrimaryKey(requestId);
3372    
3373                    Session session = null;
3374    
3375                    try {
3376                            session = openSession();
3377    
3378                            SocialRequest[] array = new SocialRequestImpl[3];
3379    
3380                            array[0] = getByR_S_PrevAndNext(session, socialRequest,
3381                                            receiverUserId, status, orderByComparator, true);
3382    
3383                            array[1] = socialRequest;
3384    
3385                            array[2] = getByR_S_PrevAndNext(session, socialRequest,
3386                                            receiverUserId, status, orderByComparator, false);
3387    
3388                            return array;
3389                    }
3390                    catch (Exception e) {
3391                            throw processException(e);
3392                    }
3393                    finally {
3394                            closeSession(session);
3395                    }
3396            }
3397    
3398            protected SocialRequest getByR_S_PrevAndNext(Session session,
3399                    SocialRequest socialRequest, long receiverUserId, int status,
3400                    OrderByComparator orderByComparator, boolean previous) {
3401                    StringBundler query = null;
3402    
3403                    if (orderByComparator != null) {
3404                            query = new StringBundler(6 +
3405                                            (orderByComparator.getOrderByFields().length * 6));
3406                    }
3407                    else {
3408                            query = new StringBundler(3);
3409                    }
3410    
3411                    query.append(_SQL_SELECT_SOCIALREQUEST_WHERE);
3412    
3413                    query.append(_FINDER_COLUMN_R_S_RECEIVERUSERID_2);
3414    
3415                    query.append(_FINDER_COLUMN_R_S_STATUS_2);
3416    
3417                    if (orderByComparator != null) {
3418                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3419    
3420                            if (orderByConditionFields.length > 0) {
3421                                    query.append(WHERE_AND);
3422                            }
3423    
3424                            for (int i = 0; i < orderByConditionFields.length; i++) {
3425                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3426                                    query.append(orderByConditionFields[i]);
3427    
3428                                    if ((i + 1) < orderByConditionFields.length) {
3429                                            if (orderByComparator.isAscending() ^ previous) {
3430                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3431                                            }
3432                                            else {
3433                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3434                                            }
3435                                    }
3436                                    else {
3437                                            if (orderByComparator.isAscending() ^ previous) {
3438                                                    query.append(WHERE_GREATER_THAN);
3439                                            }
3440                                            else {
3441                                                    query.append(WHERE_LESSER_THAN);
3442                                            }
3443                                    }
3444                            }
3445    
3446                            query.append(ORDER_BY_CLAUSE);
3447    
3448                            String[] orderByFields = orderByComparator.getOrderByFields();
3449    
3450                            for (int i = 0; i < orderByFields.length; i++) {
3451                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3452                                    query.append(orderByFields[i]);
3453    
3454                                    if ((i + 1) < orderByFields.length) {
3455                                            if (orderByComparator.isAscending() ^ previous) {
3456                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3457                                            }
3458                                            else {
3459                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3460                                            }
3461                                    }
3462                                    else {
3463                                            if (orderByComparator.isAscending() ^ previous) {
3464                                                    query.append(ORDER_BY_ASC);
3465                                            }
3466                                            else {
3467                                                    query.append(ORDER_BY_DESC);
3468                                            }
3469                                    }
3470                            }
3471                    }
3472    
3473                    else {
3474                            query.append(SocialRequestModelImpl.ORDER_BY_JPQL);
3475                    }
3476    
3477                    String sql = query.toString();
3478    
3479                    Query q = session.createQuery(sql);
3480    
3481                    q.setFirstResult(0);
3482                    q.setMaxResults(2);
3483    
3484                    QueryPos qPos = QueryPos.getInstance(q);
3485    
3486                    qPos.add(receiverUserId);
3487    
3488                    qPos.add(status);
3489    
3490                    if (orderByComparator != null) {
3491                            Object[] values = orderByComparator.getOrderByConditionValues(socialRequest);
3492    
3493                            for (Object value : values) {
3494                                    qPos.add(value);
3495                            }
3496                    }
3497    
3498                    List<SocialRequest> list = q.list();
3499    
3500                    if (list.size() == 2) {
3501                            return list.get(1);
3502                    }
3503                    else {
3504                            return null;
3505                    }
3506            }
3507    
3508            /**
3509             * Returns the social request where userId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63; and receiverUserId = &#63; or throws a {@link com.liferay.portlet.social.NoSuchRequestException} if it could not be found.
3510             *
3511             * @param userId the user ID
3512             * @param classNameId the class name ID
3513             * @param classPK the class p k
3514             * @param type the type
3515             * @param receiverUserId the receiver user ID
3516             * @return the matching social request
3517             * @throws com.liferay.portlet.social.NoSuchRequestException if a matching social request could not be found
3518             * @throws SystemException if a system exception occurred
3519             */
3520            public SocialRequest findByU_C_C_T_R(long userId, long classNameId,
3521                    long classPK, int type, long receiverUserId)
3522                    throws NoSuchRequestException, SystemException {
3523                    SocialRequest socialRequest = fetchByU_C_C_T_R(userId, classNameId,
3524                                    classPK, type, receiverUserId);
3525    
3526                    if (socialRequest == null) {
3527                            StringBundler msg = new StringBundler(12);
3528    
3529                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3530    
3531                            msg.append("userId=");
3532                            msg.append(userId);
3533    
3534                            msg.append(", classNameId=");
3535                            msg.append(classNameId);
3536    
3537                            msg.append(", classPK=");
3538                            msg.append(classPK);
3539    
3540                            msg.append(", type=");
3541                            msg.append(type);
3542    
3543                            msg.append(", receiverUserId=");
3544                            msg.append(receiverUserId);
3545    
3546                            msg.append(StringPool.CLOSE_CURLY_BRACE);
3547    
3548                            if (_log.isWarnEnabled()) {
3549                                    _log.warn(msg.toString());
3550                            }
3551    
3552                            throw new NoSuchRequestException(msg.toString());
3553                    }
3554    
3555                    return socialRequest;
3556            }
3557    
3558            /**
3559             * Returns the social request where userId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63; and receiverUserId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
3560             *
3561             * @param userId the user ID
3562             * @param classNameId the class name ID
3563             * @param classPK the class p k
3564             * @param type the type
3565             * @param receiverUserId the receiver user ID
3566             * @return the matching social request, or <code>null</code> if a matching social request could not be found
3567             * @throws SystemException if a system exception occurred
3568             */
3569            public SocialRequest fetchByU_C_C_T_R(long userId, long classNameId,
3570                    long classPK, int type, long receiverUserId) throws SystemException {
3571                    return fetchByU_C_C_T_R(userId, classNameId, classPK, type,
3572                            receiverUserId, true);
3573            }
3574    
3575            /**
3576             * Returns the social request where userId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63; and receiverUserId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
3577             *
3578             * @param userId the user ID
3579             * @param classNameId the class name ID
3580             * @param classPK the class p k
3581             * @param type the type
3582             * @param receiverUserId the receiver user ID
3583             * @param retrieveFromCache whether to use the finder cache
3584             * @return the matching social request, or <code>null</code> if a matching social request could not be found
3585             * @throws SystemException if a system exception occurred
3586             */
3587            public SocialRequest fetchByU_C_C_T_R(long userId, long classNameId,
3588                    long classPK, int type, long receiverUserId, boolean retrieveFromCache)
3589                    throws SystemException {
3590                    Object[] finderArgs = new Object[] {
3591                                    userId, classNameId, classPK, type, receiverUserId
3592                            };
3593    
3594                    Object result = null;
3595    
3596                    if (retrieveFromCache) {
3597                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_U_C_C_T_R,
3598                                            finderArgs, this);
3599                    }
3600    
3601                    if (result instanceof SocialRequest) {
3602                            SocialRequest socialRequest = (SocialRequest)result;
3603    
3604                            if ((userId != socialRequest.getUserId()) ||
3605                                            (classNameId != socialRequest.getClassNameId()) ||
3606                                            (classPK != socialRequest.getClassPK()) ||
3607                                            (type != socialRequest.getType()) ||
3608                                            (receiverUserId != socialRequest.getReceiverUserId())) {
3609                                    result = null;
3610                            }
3611                    }
3612    
3613                    if (result == null) {
3614                            StringBundler query = new StringBundler(7);
3615    
3616                            query.append(_SQL_SELECT_SOCIALREQUEST_WHERE);
3617    
3618                            query.append(_FINDER_COLUMN_U_C_C_T_R_USERID_2);
3619    
3620                            query.append(_FINDER_COLUMN_U_C_C_T_R_CLASSNAMEID_2);
3621    
3622                            query.append(_FINDER_COLUMN_U_C_C_T_R_CLASSPK_2);
3623    
3624                            query.append(_FINDER_COLUMN_U_C_C_T_R_TYPE_2);
3625    
3626                            query.append(_FINDER_COLUMN_U_C_C_T_R_RECEIVERUSERID_2);
3627    
3628                            query.append(SocialRequestModelImpl.ORDER_BY_JPQL);
3629    
3630                            String sql = query.toString();
3631    
3632                            Session session = null;
3633    
3634                            try {
3635                                    session = openSession();
3636    
3637                                    Query q = session.createQuery(sql);
3638    
3639                                    QueryPos qPos = QueryPos.getInstance(q);
3640    
3641                                    qPos.add(userId);
3642    
3643                                    qPos.add(classNameId);
3644    
3645                                    qPos.add(classPK);
3646    
3647                                    qPos.add(type);
3648    
3649                                    qPos.add(receiverUserId);
3650    
3651                                    List<SocialRequest> list = q.list();
3652    
3653                                    result = list;
3654    
3655                                    SocialRequest socialRequest = null;
3656    
3657                                    if (list.isEmpty()) {
3658                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C_T_R,
3659                                                    finderArgs, list);
3660                                    }
3661                                    else {
3662                                            socialRequest = list.get(0);
3663    
3664                                            cacheResult(socialRequest);
3665    
3666                                            if ((socialRequest.getUserId() != userId) ||
3667                                                            (socialRequest.getClassNameId() != classNameId) ||
3668                                                            (socialRequest.getClassPK() != classPK) ||
3669                                                            (socialRequest.getType() != type) ||
3670                                                            (socialRequest.getReceiverUserId() != receiverUserId)) {
3671                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C_T_R,
3672                                                            finderArgs, socialRequest);
3673                                            }
3674                                    }
3675    
3676                                    return socialRequest;
3677                            }
3678                            catch (Exception e) {
3679                                    throw processException(e);
3680                            }
3681                            finally {
3682                                    if (result == null) {
3683                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_C_C_T_R,
3684                                                    finderArgs);
3685                                    }
3686    
3687                                    closeSession(session);
3688                            }
3689                    }
3690                    else {
3691                            if (result instanceof List<?>) {
3692                                    return null;
3693                            }
3694                            else {
3695                                    return (SocialRequest)result;
3696                            }
3697                    }
3698            }
3699    
3700            /**
3701             * Returns all the social requests where userId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63; and status = &#63;.
3702             *
3703             * @param userId the user ID
3704             * @param classNameId the class name ID
3705             * @param classPK the class p k
3706             * @param type the type
3707             * @param status the status
3708             * @return the matching social requests
3709             * @throws SystemException if a system exception occurred
3710             */
3711            public List<SocialRequest> findByU_C_C_T_S(long userId, long classNameId,
3712                    long classPK, int type, int status) throws SystemException {
3713                    return findByU_C_C_T_S(userId, classNameId, classPK, type, status,
3714                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3715            }
3716    
3717            /**
3718             * Returns a range of all the social requests where userId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63; and status = &#63;.
3719             *
3720             * <p>
3721             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3722             * </p>
3723             *
3724             * @param userId the user ID
3725             * @param classNameId the class name ID
3726             * @param classPK the class p k
3727             * @param type the type
3728             * @param status the status
3729             * @param start the lower bound of the range of social requests
3730             * @param end the upper bound of the range of social requests (not inclusive)
3731             * @return the range of matching social requests
3732             * @throws SystemException if a system exception occurred
3733             */
3734            public List<SocialRequest> findByU_C_C_T_S(long userId, long classNameId,
3735                    long classPK, int type, int status, int start, int end)
3736                    throws SystemException {
3737                    return findByU_C_C_T_S(userId, classNameId, classPK, type, status,
3738                            start, end, null);
3739            }
3740    
3741            /**
3742             * Returns an ordered range of all the social requests where userId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63; and status = &#63;.
3743             *
3744             * <p>
3745             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3746             * </p>
3747             *
3748             * @param userId the user ID
3749             * @param classNameId the class name ID
3750             * @param classPK the class p k
3751             * @param type the type
3752             * @param status the status
3753             * @param start the lower bound of the range of social requests
3754             * @param end the upper bound of the range of social requests (not inclusive)
3755             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3756             * @return the ordered range of matching social requests
3757             * @throws SystemException if a system exception occurred
3758             */
3759            public List<SocialRequest> findByU_C_C_T_S(long userId, long classNameId,
3760                    long classPK, int type, int status, int start, int end,
3761                    OrderByComparator orderByComparator) throws SystemException {
3762                    FinderPath finderPath = null;
3763                    Object[] finderArgs = null;
3764    
3765                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3766                                    (orderByComparator == null)) {
3767                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_T_S;
3768                            finderArgs = new Object[] { userId, classNameId, classPK, type, status };
3769                    }
3770                    else {
3771                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_C_T_S;
3772                            finderArgs = new Object[] {
3773                                            userId, classNameId, classPK, type, status,
3774                                            
3775                                            start, end, orderByComparator
3776                                    };
3777                    }
3778    
3779                    List<SocialRequest> list = (List<SocialRequest>)FinderCacheUtil.getResult(finderPath,
3780                                    finderArgs, this);
3781    
3782                    if ((list != null) && !list.isEmpty()) {
3783                            for (SocialRequest socialRequest : list) {
3784                                    if ((userId != socialRequest.getUserId()) ||
3785                                                    (classNameId != socialRequest.getClassNameId()) ||
3786                                                    (classPK != socialRequest.getClassPK()) ||
3787                                                    (type != socialRequest.getType()) ||
3788                                                    (status != socialRequest.getStatus())) {
3789                                            list = null;
3790    
3791                                            break;
3792                                    }
3793                            }
3794                    }
3795    
3796                    if (list == null) {
3797                            StringBundler query = null;
3798    
3799                            if (orderByComparator != null) {
3800                                    query = new StringBundler(7 +
3801                                                    (orderByComparator.getOrderByFields().length * 3));
3802                            }
3803                            else {
3804                                    query = new StringBundler(7);
3805                            }
3806    
3807                            query.append(_SQL_SELECT_SOCIALREQUEST_WHERE);
3808    
3809                            query.append(_FINDER_COLUMN_U_C_C_T_S_USERID_2);
3810    
3811                            query.append(_FINDER_COLUMN_U_C_C_T_S_CLASSNAMEID_2);
3812    
3813                            query.append(_FINDER_COLUMN_U_C_C_T_S_CLASSPK_2);
3814    
3815                            query.append(_FINDER_COLUMN_U_C_C_T_S_TYPE_2);
3816    
3817                            query.append(_FINDER_COLUMN_U_C_C_T_S_STATUS_2);
3818    
3819                            if (orderByComparator != null) {
3820                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3821                                            orderByComparator);
3822                            }
3823    
3824                            else {
3825                                    query.append(SocialRequestModelImpl.ORDER_BY_JPQL);
3826                            }
3827    
3828                            String sql = query.toString();
3829    
3830                            Session session = null;
3831    
3832                            try {
3833                                    session = openSession();
3834    
3835                                    Query q = session.createQuery(sql);
3836    
3837                                    QueryPos qPos = QueryPos.getInstance(q);
3838    
3839                                    qPos.add(userId);
3840    
3841                                    qPos.add(classNameId);
3842    
3843                                    qPos.add(classPK);
3844    
3845                                    qPos.add(type);
3846    
3847                                    qPos.add(status);
3848    
3849                                    list = (List<SocialRequest>)QueryUtil.list(q, getDialect(),
3850                                                    start, end);
3851                            }
3852                            catch (Exception e) {
3853                                    throw processException(e);
3854                            }
3855                            finally {
3856                                    if (list == null) {
3857                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
3858                                    }
3859                                    else {
3860                                            cacheResult(list);
3861    
3862                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
3863                                    }
3864    
3865                                    closeSession(session);
3866                            }
3867                    }
3868    
3869                    return list;
3870            }
3871    
3872            /**
3873             * Returns the first social request in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63; and status = &#63;.
3874             *
3875             * @param userId the user ID
3876             * @param classNameId the class name ID
3877             * @param classPK the class p k
3878             * @param type the type
3879             * @param status the status
3880             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3881             * @return the first matching social request
3882             * @throws com.liferay.portlet.social.NoSuchRequestException if a matching social request could not be found
3883             * @throws SystemException if a system exception occurred
3884             */
3885            public SocialRequest findByU_C_C_T_S_First(long userId, long classNameId,
3886                    long classPK, int type, int status, OrderByComparator orderByComparator)
3887                    throws NoSuchRequestException, SystemException {
3888                    SocialRequest socialRequest = fetchByU_C_C_T_S_First(userId,
3889                                    classNameId, classPK, type, status, orderByComparator);
3890    
3891                    if (socialRequest != null) {
3892                            return socialRequest;
3893                    }
3894    
3895                    StringBundler msg = new StringBundler(12);
3896    
3897                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3898    
3899                    msg.append("userId=");
3900                    msg.append(userId);
3901    
3902                    msg.append(", classNameId=");
3903                    msg.append(classNameId);
3904    
3905                    msg.append(", classPK=");
3906                    msg.append(classPK);
3907    
3908                    msg.append(", type=");
3909                    msg.append(type);
3910    
3911                    msg.append(", status=");
3912                    msg.append(status);
3913    
3914                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3915    
3916                    throw new NoSuchRequestException(msg.toString());
3917            }
3918    
3919            /**
3920             * Returns the first social request in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63; and status = &#63;.
3921             *
3922             * @param userId the user ID
3923             * @param classNameId the class name ID
3924             * @param classPK the class p k
3925             * @param type the type
3926             * @param status the status
3927             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3928             * @return the first matching social request, or <code>null</code> if a matching social request could not be found
3929             * @throws SystemException if a system exception occurred
3930             */
3931            public SocialRequest fetchByU_C_C_T_S_First(long userId, long classNameId,
3932                    long classPK, int type, int status, OrderByComparator orderByComparator)
3933                    throws SystemException {
3934                    List<SocialRequest> list = findByU_C_C_T_S(userId, classNameId,
3935                                    classPK, type, status, 0, 1, orderByComparator);
3936    
3937                    if (!list.isEmpty()) {
3938                            return list.get(0);
3939                    }
3940    
3941                    return null;
3942            }
3943    
3944            /**
3945             * Returns the last social request in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63; and status = &#63;.
3946             *
3947             * @param userId the user ID
3948             * @param classNameId the class name ID
3949             * @param classPK the class p k
3950             * @param type the type
3951             * @param status the status
3952             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3953             * @return the last matching social request
3954             * @throws com.liferay.portlet.social.NoSuchRequestException if a matching social request could not be found
3955             * @throws SystemException if a system exception occurred
3956             */
3957            public SocialRequest findByU_C_C_T_S_Last(long userId, long classNameId,
3958                    long classPK, int type, int status, OrderByComparator orderByComparator)
3959                    throws NoSuchRequestException, SystemException {
3960                    SocialRequest socialRequest = fetchByU_C_C_T_S_Last(userId,
3961                                    classNameId, classPK, type, status, orderByComparator);
3962    
3963                    if (socialRequest != null) {
3964                            return socialRequest;
3965                    }
3966    
3967                    StringBundler msg = new StringBundler(12);
3968    
3969                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3970    
3971                    msg.append("userId=");
3972                    msg.append(userId);
3973    
3974                    msg.append(", classNameId=");
3975                    msg.append(classNameId);
3976    
3977                    msg.append(", classPK=");
3978                    msg.append(classPK);
3979    
3980                    msg.append(", type=");
3981                    msg.append(type);
3982    
3983                    msg.append(", status=");
3984                    msg.append(status);
3985    
3986                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3987    
3988                    throw new NoSuchRequestException(msg.toString());
3989            }
3990    
3991            /**
3992             * Returns the last social request in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63; and status = &#63;.
3993             *
3994             * @param userId the user ID
3995             * @param classNameId the class name ID
3996             * @param classPK the class p k
3997             * @param type the type
3998             * @param status the status
3999             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4000             * @return the last matching social request, or <code>null</code> if a matching social request could not be found
4001             * @throws SystemException if a system exception occurred
4002             */
4003            public SocialRequest fetchByU_C_C_T_S_Last(long userId, long classNameId,
4004                    long classPK, int type, int status, OrderByComparator orderByComparator)
4005                    throws SystemException {
4006                    int count = countByU_C_C_T_S(userId, classNameId, classPK, type, status);
4007    
4008                    List<SocialRequest> list = findByU_C_C_T_S(userId, classNameId,
4009                                    classPK, type, status, count - 1, count, orderByComparator);
4010    
4011                    if (!list.isEmpty()) {
4012                            return list.get(0);
4013                    }
4014    
4015                    return null;
4016            }
4017    
4018            /**
4019             * Returns the social requests before and after the current social request in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63; and status = &#63;.
4020             *
4021             * @param requestId the primary key of the current social request
4022             * @param userId the user ID
4023             * @param classNameId the class name ID
4024             * @param classPK the class p k
4025             * @param type the type
4026             * @param status the status
4027             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4028             * @return the previous, current, and next social request
4029             * @throws com.liferay.portlet.social.NoSuchRequestException if a social request with the primary key could not be found
4030             * @throws SystemException if a system exception occurred
4031             */
4032            public SocialRequest[] findByU_C_C_T_S_PrevAndNext(long requestId,
4033                    long userId, long classNameId, long classPK, int type, int status,
4034                    OrderByComparator orderByComparator)
4035                    throws NoSuchRequestException, SystemException {
4036                    SocialRequest socialRequest = findByPrimaryKey(requestId);
4037    
4038                    Session session = null;
4039    
4040                    try {
4041                            session = openSession();
4042    
4043                            SocialRequest[] array = new SocialRequestImpl[3];
4044    
4045                            array[0] = getByU_C_C_T_S_PrevAndNext(session, socialRequest,
4046                                            userId, classNameId, classPK, type, status,
4047                                            orderByComparator, true);
4048    
4049                            array[1] = socialRequest;
4050    
4051                            array[2] = getByU_C_C_T_S_PrevAndNext(session, socialRequest,
4052                                            userId, classNameId, classPK, type, status,
4053                                            orderByComparator, false);
4054    
4055                            return array;
4056                    }
4057                    catch (Exception e) {
4058                            throw processException(e);
4059                    }
4060                    finally {
4061                            closeSession(session);
4062                    }
4063            }
4064    
4065            protected SocialRequest getByU_C_C_T_S_PrevAndNext(Session session,
4066                    SocialRequest socialRequest, long userId, long classNameId,
4067                    long classPK, int type, int status,
4068                    OrderByComparator orderByComparator, boolean previous) {
4069                    StringBundler query = null;
4070    
4071                    if (orderByComparator != null) {
4072                            query = new StringBundler(6 +
4073                                            (orderByComparator.getOrderByFields().length * 6));
4074                    }
4075                    else {
4076                            query = new StringBundler(3);
4077                    }
4078    
4079                    query.append(_SQL_SELECT_SOCIALREQUEST_WHERE);
4080    
4081                    query.append(_FINDER_COLUMN_U_C_C_T_S_USERID_2);
4082    
4083                    query.append(_FINDER_COLUMN_U_C_C_T_S_CLASSNAMEID_2);
4084    
4085                    query.append(_FINDER_COLUMN_U_C_C_T_S_CLASSPK_2);
4086    
4087                    query.append(_FINDER_COLUMN_U_C_C_T_S_TYPE_2);
4088    
4089                    query.append(_FINDER_COLUMN_U_C_C_T_S_STATUS_2);
4090    
4091                    if (orderByComparator != null) {
4092                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4093    
4094                            if (orderByConditionFields.length > 0) {
4095                                    query.append(WHERE_AND);
4096                            }
4097    
4098                            for (int i = 0; i < orderByConditionFields.length; i++) {
4099                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4100                                    query.append(orderByConditionFields[i]);
4101    
4102                                    if ((i + 1) < orderByConditionFields.length) {
4103                                            if (orderByComparator.isAscending() ^ previous) {
4104                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4105                                            }
4106                                            else {
4107                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4108                                            }
4109                                    }
4110                                    else {
4111                                            if (orderByComparator.isAscending() ^ previous) {
4112                                                    query.append(WHERE_GREATER_THAN);
4113                                            }
4114                                            else {
4115                                                    query.append(WHERE_LESSER_THAN);
4116                                            }
4117                                    }
4118                            }
4119    
4120                            query.append(ORDER_BY_CLAUSE);
4121    
4122                            String[] orderByFields = orderByComparator.getOrderByFields();
4123    
4124                            for (int i = 0; i < orderByFields.length; i++) {
4125                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4126                                    query.append(orderByFields[i]);
4127    
4128                                    if ((i + 1) < orderByFields.length) {
4129                                            if (orderByComparator.isAscending() ^ previous) {
4130                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4131                                            }
4132                                            else {
4133                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4134                                            }
4135                                    }
4136                                    else {
4137                                            if (orderByComparator.isAscending() ^ previous) {
4138                                                    query.append(ORDER_BY_ASC);
4139                                            }
4140                                            else {
4141                                                    query.append(ORDER_BY_DESC);
4142                                            }
4143                                    }
4144                            }
4145                    }
4146    
4147                    else {
4148                            query.append(SocialRequestModelImpl.ORDER_BY_JPQL);
4149                    }
4150    
4151                    String sql = query.toString();
4152    
4153                    Query q = session.createQuery(sql);
4154    
4155                    q.setFirstResult(0);
4156                    q.setMaxResults(2);
4157    
4158                    QueryPos qPos = QueryPos.getInstance(q);
4159    
4160                    qPos.add(userId);
4161    
4162                    qPos.add(classNameId);
4163    
4164                    qPos.add(classPK);
4165    
4166                    qPos.add(type);
4167    
4168                    qPos.add(status);
4169    
4170                    if (orderByComparator != null) {
4171                            Object[] values = orderByComparator.getOrderByConditionValues(socialRequest);
4172    
4173                            for (Object value : values) {
4174                                    qPos.add(value);
4175                            }
4176                    }
4177    
4178                    List<SocialRequest> list = q.list();
4179    
4180                    if (list.size() == 2) {
4181                            return list.get(1);
4182                    }
4183                    else {
4184                            return null;
4185                    }
4186            }
4187    
4188            /**
4189             * Returns all the social requests where classNameId = &#63; and classPK = &#63; and type = &#63; and receiverUserId = &#63; and status = &#63;.
4190             *
4191             * @param classNameId the class name ID
4192             * @param classPK the class p k
4193             * @param type the type
4194             * @param receiverUserId the receiver user ID
4195             * @param status the status
4196             * @return the matching social requests
4197             * @throws SystemException if a system exception occurred
4198             */
4199            public List<SocialRequest> findByC_C_T_R_S(long classNameId, long classPK,
4200                    int type, long receiverUserId, int status) throws SystemException {
4201                    return findByC_C_T_R_S(classNameId, classPK, type, receiverUserId,
4202                            status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
4203            }
4204    
4205            /**
4206             * Returns a range of all the social requests where classNameId = &#63; and classPK = &#63; and type = &#63; and receiverUserId = &#63; and status = &#63;.
4207             *
4208             * <p>
4209             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4210             * </p>
4211             *
4212             * @param classNameId the class name ID
4213             * @param classPK the class p k
4214             * @param type the type
4215             * @param receiverUserId the receiver user ID
4216             * @param status the status
4217             * @param start the lower bound of the range of social requests
4218             * @param end the upper bound of the range of social requests (not inclusive)
4219             * @return the range of matching social requests
4220             * @throws SystemException if a system exception occurred
4221             */
4222            public List<SocialRequest> findByC_C_T_R_S(long classNameId, long classPK,
4223                    int type, long receiverUserId, int status, int start, int end)
4224                    throws SystemException {
4225                    return findByC_C_T_R_S(classNameId, classPK, type, receiverUserId,
4226                            status, start, end, null);
4227            }
4228    
4229            /**
4230             * Returns an ordered range of all the social requests where classNameId = &#63; and classPK = &#63; and type = &#63; and receiverUserId = &#63; and status = &#63;.
4231             *
4232             * <p>
4233             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4234             * </p>
4235             *
4236             * @param classNameId the class name ID
4237             * @param classPK the class p k
4238             * @param type the type
4239             * @param receiverUserId the receiver user ID
4240             * @param status the status
4241             * @param start the lower bound of the range of social requests
4242             * @param end the upper bound of the range of social requests (not inclusive)
4243             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4244             * @return the ordered range of matching social requests
4245             * @throws SystemException if a system exception occurred
4246             */
4247            public List<SocialRequest> findByC_C_T_R_S(long classNameId, long classPK,
4248                    int type, long receiverUserId, int status, int start, int end,
4249                    OrderByComparator orderByComparator) throws SystemException {
4250                    FinderPath finderPath = null;
4251                    Object[] finderArgs = null;
4252    
4253                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4254                                    (orderByComparator == null)) {
4255                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_T_R_S;
4256                            finderArgs = new Object[] {
4257                                            classNameId, classPK, type, receiverUserId, status
4258                                    };
4259                    }
4260                    else {
4261                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_T_R_S;
4262                            finderArgs = new Object[] {
4263                                            classNameId, classPK, type, receiverUserId, status,
4264                                            
4265                                            start, end, orderByComparator
4266                                    };
4267                    }
4268    
4269                    List<SocialRequest> list = (List<SocialRequest>)FinderCacheUtil.getResult(finderPath,
4270                                    finderArgs, this);
4271    
4272                    if ((list != null) && !list.isEmpty()) {
4273                            for (SocialRequest socialRequest : list) {
4274                                    if ((classNameId != socialRequest.getClassNameId()) ||
4275                                                    (classPK != socialRequest.getClassPK()) ||
4276                                                    (type != socialRequest.getType()) ||
4277                                                    (receiverUserId != socialRequest.getReceiverUserId()) ||
4278                                                    (status != socialRequest.getStatus())) {
4279                                            list = null;
4280    
4281                                            break;
4282                                    }
4283                            }
4284                    }
4285    
4286                    if (list == null) {
4287                            StringBundler query = null;
4288    
4289                            if (orderByComparator != null) {
4290                                    query = new StringBundler(7 +
4291                                                    (orderByComparator.getOrderByFields().length * 3));
4292                            }
4293                            else {
4294                                    query = new StringBundler(7);
4295                            }
4296    
4297                            query.append(_SQL_SELECT_SOCIALREQUEST_WHERE);
4298    
4299                            query.append(_FINDER_COLUMN_C_C_T_R_S_CLASSNAMEID_2);
4300    
4301                            query.append(_FINDER_COLUMN_C_C_T_R_S_CLASSPK_2);
4302    
4303                            query.append(_FINDER_COLUMN_C_C_T_R_S_TYPE_2);
4304    
4305                            query.append(_FINDER_COLUMN_C_C_T_R_S_RECEIVERUSERID_2);
4306    
4307                            query.append(_FINDER_COLUMN_C_C_T_R_S_STATUS_2);
4308    
4309                            if (orderByComparator != null) {
4310                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4311                                            orderByComparator);
4312                            }
4313    
4314                            else {
4315                                    query.append(SocialRequestModelImpl.ORDER_BY_JPQL);
4316                            }
4317    
4318                            String sql = query.toString();
4319    
4320                            Session session = null;
4321    
4322                            try {
4323                                    session = openSession();
4324    
4325                                    Query q = session.createQuery(sql);
4326    
4327                                    QueryPos qPos = QueryPos.getInstance(q);
4328    
4329                                    qPos.add(classNameId);
4330    
4331                                    qPos.add(classPK);
4332    
4333                                    qPos.add(type);
4334    
4335                                    qPos.add(receiverUserId);
4336    
4337                                    qPos.add(status);
4338    
4339                                    list = (List<SocialRequest>)QueryUtil.list(q, getDialect(),
4340                                                    start, end);
4341                            }
4342                            catch (Exception e) {
4343                                    throw processException(e);
4344                            }
4345                            finally {
4346                                    if (list == null) {
4347                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
4348                                    }
4349                                    else {
4350                                            cacheResult(list);
4351    
4352                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
4353                                    }
4354    
4355                                    closeSession(session);
4356                            }
4357                    }
4358    
4359                    return list;
4360            }
4361    
4362            /**
4363             * Returns the first social request in the ordered set where classNameId = &#63; and classPK = &#63; and type = &#63; and receiverUserId = &#63; and status = &#63;.
4364             *
4365             * @param classNameId the class name ID
4366             * @param classPK the class p k
4367             * @param type the type
4368             * @param receiverUserId the receiver user ID
4369             * @param status the status
4370             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4371             * @return the first matching social request
4372             * @throws com.liferay.portlet.social.NoSuchRequestException if a matching social request could not be found
4373             * @throws SystemException if a system exception occurred
4374             */
4375            public SocialRequest findByC_C_T_R_S_First(long classNameId, long classPK,
4376                    int type, long receiverUserId, int status,
4377                    OrderByComparator orderByComparator)
4378                    throws NoSuchRequestException, SystemException {
4379                    SocialRequest socialRequest = fetchByC_C_T_R_S_First(classNameId,
4380                                    classPK, type, receiverUserId, status, orderByComparator);
4381    
4382                    if (socialRequest != null) {
4383                            return socialRequest;
4384                    }
4385    
4386                    StringBundler msg = new StringBundler(12);
4387    
4388                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4389    
4390                    msg.append("classNameId=");
4391                    msg.append(classNameId);
4392    
4393                    msg.append(", classPK=");
4394                    msg.append(classPK);
4395    
4396                    msg.append(", type=");
4397                    msg.append(type);
4398    
4399                    msg.append(", receiverUserId=");
4400                    msg.append(receiverUserId);
4401    
4402                    msg.append(", status=");
4403                    msg.append(status);
4404    
4405                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4406    
4407                    throw new NoSuchRequestException(msg.toString());
4408            }
4409    
4410            /**
4411             * Returns the first social request in the ordered set where classNameId = &#63; and classPK = &#63; and type = &#63; and receiverUserId = &#63; and status = &#63;.
4412             *
4413             * @param classNameId the class name ID
4414             * @param classPK the class p k
4415             * @param type the type
4416             * @param receiverUserId the receiver user ID
4417             * @param status the status
4418             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4419             * @return the first matching social request, or <code>null</code> if a matching social request could not be found
4420             * @throws SystemException if a system exception occurred
4421             */
4422            public SocialRequest fetchByC_C_T_R_S_First(long classNameId, long classPK,
4423                    int type, long receiverUserId, int status,
4424                    OrderByComparator orderByComparator) throws SystemException {
4425                    List<SocialRequest> list = findByC_C_T_R_S(classNameId, classPK, type,
4426                                    receiverUserId, status, 0, 1, orderByComparator);
4427    
4428                    if (!list.isEmpty()) {
4429                            return list.get(0);
4430                    }
4431    
4432                    return null;
4433            }
4434    
4435            /**
4436             * Returns the last social request in the ordered set where classNameId = &#63; and classPK = &#63; and type = &#63; and receiverUserId = &#63; and status = &#63;.
4437             *
4438             * @param classNameId the class name ID
4439             * @param classPK the class p k
4440             * @param type the type
4441             * @param receiverUserId the receiver user ID
4442             * @param status the status
4443             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4444             * @return the last matching social request
4445             * @throws com.liferay.portlet.social.NoSuchRequestException if a matching social request could not be found
4446             * @throws SystemException if a system exception occurred
4447             */
4448            public SocialRequest findByC_C_T_R_S_Last(long classNameId, long classPK,
4449                    int type, long receiverUserId, int status,
4450                    OrderByComparator orderByComparator)
4451                    throws NoSuchRequestException, SystemException {
4452                    SocialRequest socialRequest = fetchByC_C_T_R_S_Last(classNameId,
4453                                    classPK, type, receiverUserId, status, orderByComparator);
4454    
4455                    if (socialRequest != null) {
4456                            return socialRequest;
4457                    }
4458    
4459                    StringBundler msg = new StringBundler(12);
4460    
4461                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4462    
4463                    msg.append("classNameId=");
4464                    msg.append(classNameId);
4465    
4466                    msg.append(", classPK=");
4467                    msg.append(classPK);
4468    
4469                    msg.append(", type=");
4470                    msg.append(type);
4471    
4472                    msg.append(", receiverUserId=");
4473                    msg.append(receiverUserId);
4474    
4475                    msg.append(", status=");
4476                    msg.append(status);
4477    
4478                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4479    
4480                    throw new NoSuchRequestException(msg.toString());
4481            }
4482    
4483            /**
4484             * Returns the last social request in the ordered set where classNameId = &#63; and classPK = &#63; and type = &#63; and receiverUserId = &#63; and status = &#63;.
4485             *
4486             * @param classNameId the class name ID
4487             * @param classPK the class p k
4488             * @param type the type
4489             * @param receiverUserId the receiver user ID
4490             * @param status the status
4491             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4492             * @return the last matching social request, or <code>null</code> if a matching social request could not be found
4493             * @throws SystemException if a system exception occurred
4494             */
4495            public SocialRequest fetchByC_C_T_R_S_Last(long classNameId, long classPK,
4496                    int type, long receiverUserId, int status,
4497                    OrderByComparator orderByComparator) throws SystemException {
4498                    int count = countByC_C_T_R_S(classNameId, classPK, type,
4499                                    receiverUserId, status);
4500    
4501                    List<SocialRequest> list = findByC_C_T_R_S(classNameId, classPK, type,
4502                                    receiverUserId, status, count - 1, count, orderByComparator);
4503    
4504                    if (!list.isEmpty()) {
4505                            return list.get(0);
4506                    }
4507    
4508                    return null;
4509            }
4510    
4511            /**
4512             * Returns the social requests before and after the current social request in the ordered set where classNameId = &#63; and classPK = &#63; and type = &#63; and receiverUserId = &#63; and status = &#63;.
4513             *
4514             * @param requestId the primary key of the current social request
4515             * @param classNameId the class name ID
4516             * @param classPK the class p k
4517             * @param type the type
4518             * @param receiverUserId the receiver user ID
4519             * @param status the status
4520             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4521             * @return the previous, current, and next social request
4522             * @throws com.liferay.portlet.social.NoSuchRequestException if a social request with the primary key could not be found
4523             * @throws SystemException if a system exception occurred
4524             */
4525            public SocialRequest[] findByC_C_T_R_S_PrevAndNext(long requestId,
4526                    long classNameId, long classPK, int type, long receiverUserId,
4527                    int status, OrderByComparator orderByComparator)
4528                    throws NoSuchRequestException, SystemException {
4529                    SocialRequest socialRequest = findByPrimaryKey(requestId);
4530    
4531                    Session session = null;
4532    
4533                    try {
4534                            session = openSession();
4535    
4536                            SocialRequest[] array = new SocialRequestImpl[3];
4537    
4538                            array[0] = getByC_C_T_R_S_PrevAndNext(session, socialRequest,
4539                                            classNameId, classPK, type, receiverUserId, status,
4540                                            orderByComparator, true);
4541    
4542                            array[1] = socialRequest;
4543    
4544                            array[2] = getByC_C_T_R_S_PrevAndNext(session, socialRequest,
4545                                            classNameId, classPK, type, receiverUserId, status,
4546                                            orderByComparator, false);
4547    
4548                            return array;
4549                    }
4550                    catch (Exception e) {
4551                            throw processException(e);
4552                    }
4553                    finally {
4554                            closeSession(session);
4555                    }
4556            }
4557    
4558            protected SocialRequest getByC_C_T_R_S_PrevAndNext(Session session,
4559                    SocialRequest socialRequest, long classNameId, long classPK, int type,
4560                    long receiverUserId, int status, OrderByComparator orderByComparator,
4561                    boolean previous) {
4562                    StringBundler query = null;
4563    
4564                    if (orderByComparator != null) {
4565                            query = new StringBundler(6 +
4566                                            (orderByComparator.getOrderByFields().length * 6));
4567                    }
4568                    else {
4569                            query = new StringBundler(3);
4570                    }
4571    
4572                    query.append(_SQL_SELECT_SOCIALREQUEST_WHERE);
4573    
4574                    query.append(_FINDER_COLUMN_C_C_T_R_S_CLASSNAMEID_2);
4575    
4576                    query.append(_FINDER_COLUMN_C_C_T_R_S_CLASSPK_2);
4577    
4578                    query.append(_FINDER_COLUMN_C_C_T_R_S_TYPE_2);
4579    
4580                    query.append(_FINDER_COLUMN_C_C_T_R_S_RECEIVERUSERID_2);
4581    
4582                    query.append(_FINDER_COLUMN_C_C_T_R_S_STATUS_2);
4583    
4584                    if (orderByComparator != null) {
4585                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4586    
4587                            if (orderByConditionFields.length > 0) {
4588                                    query.append(WHERE_AND);
4589                            }
4590    
4591                            for (int i = 0; i < orderByConditionFields.length; i++) {
4592                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4593                                    query.append(orderByConditionFields[i]);
4594    
4595                                    if ((i + 1) < orderByConditionFields.length) {
4596                                            if (orderByComparator.isAscending() ^ previous) {
4597                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4598                                            }
4599                                            else {
4600                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4601                                            }
4602                                    }
4603                                    else {
4604                                            if (orderByComparator.isAscending() ^ previous) {
4605                                                    query.append(WHERE_GREATER_THAN);
4606                                            }
4607                                            else {
4608                                                    query.append(WHERE_LESSER_THAN);
4609                                            }
4610                                    }
4611                            }
4612    
4613                            query.append(ORDER_BY_CLAUSE);
4614    
4615                            String[] orderByFields = orderByComparator.getOrderByFields();
4616    
4617                            for (int i = 0; i < orderByFields.length; i++) {
4618                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4619                                    query.append(orderByFields[i]);
4620    
4621                                    if ((i + 1) < orderByFields.length) {
4622                                            if (orderByComparator.isAscending() ^ previous) {
4623                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4624                                            }
4625                                            else {
4626                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4627                                            }
4628                                    }
4629                                    else {
4630                                            if (orderByComparator.isAscending() ^ previous) {
4631                                                    query.append(ORDER_BY_ASC);
4632                                            }
4633                                            else {
4634                                                    query.append(ORDER_BY_DESC);
4635                                            }
4636                                    }
4637                            }
4638                    }
4639    
4640                    else {
4641                            query.append(SocialRequestModelImpl.ORDER_BY_JPQL);
4642                    }
4643    
4644                    String sql = query.toString();
4645    
4646                    Query q = session.createQuery(sql);
4647    
4648                    q.setFirstResult(0);
4649                    q.setMaxResults(2);
4650    
4651                    QueryPos qPos = QueryPos.getInstance(q);
4652    
4653                    qPos.add(classNameId);
4654    
4655                    qPos.add(classPK);
4656    
4657                    qPos.add(type);
4658    
4659                    qPos.add(receiverUserId);
4660    
4661                    qPos.add(status);
4662    
4663                    if (orderByComparator != null) {
4664                            Object[] values = orderByComparator.getOrderByConditionValues(socialRequest);
4665    
4666                            for (Object value : values) {
4667                                    qPos.add(value);
4668                            }
4669                    }
4670    
4671                    List<SocialRequest> list = q.list();
4672    
4673                    if (list.size() == 2) {
4674                            return list.get(1);
4675                    }
4676                    else {
4677                            return null;
4678                    }
4679            }
4680    
4681            /**
4682             * Returns all the social requests.
4683             *
4684             * @return the social requests
4685             * @throws SystemException if a system exception occurred
4686             */
4687            public List<SocialRequest> findAll() throws SystemException {
4688                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
4689            }
4690    
4691            /**
4692             * Returns a range of all the social requests.
4693             *
4694             * <p>
4695             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4696             * </p>
4697             *
4698             * @param start the lower bound of the range of social requests
4699             * @param end the upper bound of the range of social requests (not inclusive)
4700             * @return the range of social requests
4701             * @throws SystemException if a system exception occurred
4702             */
4703            public List<SocialRequest> findAll(int start, int end)
4704                    throws SystemException {
4705                    return findAll(start, end, null);
4706            }
4707    
4708            /**
4709             * Returns an ordered range of all the social requests.
4710             *
4711             * <p>
4712             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4713             * </p>
4714             *
4715             * @param start the lower bound of the range of social requests
4716             * @param end the upper bound of the range of social requests (not inclusive)
4717             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4718             * @return the ordered range of social requests
4719             * @throws SystemException if a system exception occurred
4720             */
4721            public List<SocialRequest> findAll(int start, int end,
4722                    OrderByComparator orderByComparator) throws SystemException {
4723                    FinderPath finderPath = null;
4724                    Object[] finderArgs = new Object[] { start, end, orderByComparator };
4725    
4726                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4727                                    (orderByComparator == null)) {
4728                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
4729                            finderArgs = FINDER_ARGS_EMPTY;
4730                    }
4731                    else {
4732                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
4733                            finderArgs = new Object[] { start, end, orderByComparator };
4734                    }
4735    
4736                    List<SocialRequest> list = (List<SocialRequest>)FinderCacheUtil.getResult(finderPath,
4737                                    finderArgs, this);
4738    
4739                    if (list == null) {
4740                            StringBundler query = null;
4741                            String sql = null;
4742    
4743                            if (orderByComparator != null) {
4744                                    query = new StringBundler(2 +
4745                                                    (orderByComparator.getOrderByFields().length * 3));
4746    
4747                                    query.append(_SQL_SELECT_SOCIALREQUEST);
4748    
4749                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4750                                            orderByComparator);
4751    
4752                                    sql = query.toString();
4753                            }
4754                            else {
4755                                    sql = _SQL_SELECT_SOCIALREQUEST.concat(SocialRequestModelImpl.ORDER_BY_JPQL);
4756                            }
4757    
4758                            Session session = null;
4759    
4760                            try {
4761                                    session = openSession();
4762    
4763                                    Query q = session.createQuery(sql);
4764    
4765                                    if (orderByComparator == null) {
4766                                            list = (List<SocialRequest>)QueryUtil.list(q, getDialect(),
4767                                                            start, end, false);
4768    
4769                                            Collections.sort(list);
4770                                    }
4771                                    else {
4772                                            list = (List<SocialRequest>)QueryUtil.list(q, getDialect(),
4773                                                            start, end);
4774                                    }
4775                            }
4776                            catch (Exception e) {
4777                                    throw processException(e);
4778                            }
4779                            finally {
4780                                    if (list == null) {
4781                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
4782                                    }
4783                                    else {
4784                                            cacheResult(list);
4785    
4786                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
4787                                    }
4788    
4789                                    closeSession(session);
4790                            }
4791                    }
4792    
4793                    return list;
4794            }
4795    
4796            /**
4797             * Removes all the social requests where uuid = &#63; from the database.
4798             *
4799             * @param uuid the uuid
4800             * @throws SystemException if a system exception occurred
4801             */
4802            public void removeByUuid(String uuid) throws SystemException {
4803                    for (SocialRequest socialRequest : findByUuid(uuid)) {
4804                            remove(socialRequest);
4805                    }
4806            }
4807    
4808            /**
4809             * Removes the social request where uuid = &#63; and groupId = &#63; from the database.
4810             *
4811             * @param uuid the uuid
4812             * @param groupId the group ID
4813             * @return the social request that was removed
4814             * @throws SystemException if a system exception occurred
4815             */
4816            public SocialRequest removeByUUID_G(String uuid, long groupId)
4817                    throws NoSuchRequestException, SystemException {
4818                    SocialRequest socialRequest = findByUUID_G(uuid, groupId);
4819    
4820                    return remove(socialRequest);
4821            }
4822    
4823            /**
4824             * Removes all the social requests where companyId = &#63; from the database.
4825             *
4826             * @param companyId the company ID
4827             * @throws SystemException if a system exception occurred
4828             */
4829            public void removeByCompanyId(long companyId) throws SystemException {
4830                    for (SocialRequest socialRequest : findByCompanyId(companyId)) {
4831                            remove(socialRequest);
4832                    }
4833            }
4834    
4835            /**
4836             * Removes all the social requests where userId = &#63; from the database.
4837             *
4838             * @param userId the user ID
4839             * @throws SystemException if a system exception occurred
4840             */
4841            public void removeByUserId(long userId) throws SystemException {
4842                    for (SocialRequest socialRequest : findByUserId(userId)) {
4843                            remove(socialRequest);
4844                    }
4845            }
4846    
4847            /**
4848             * Removes all the social requests where receiverUserId = &#63; from the database.
4849             *
4850             * @param receiverUserId the receiver user ID
4851             * @throws SystemException if a system exception occurred
4852             */
4853            public void removeByReceiverUserId(long receiverUserId)
4854                    throws SystemException {
4855                    for (SocialRequest socialRequest : findByReceiverUserId(receiverUserId)) {
4856                            remove(socialRequest);
4857                    }
4858            }
4859    
4860            /**
4861             * Removes all the social requests where userId = &#63; and status = &#63; from the database.
4862             *
4863             * @param userId the user ID
4864             * @param status the status
4865             * @throws SystemException if a system exception occurred
4866             */
4867            public void removeByU_S(long userId, int status) throws SystemException {
4868                    for (SocialRequest socialRequest : findByU_S(userId, status)) {
4869                            remove(socialRequest);
4870                    }
4871            }
4872    
4873            /**
4874             * Removes all the social requests where receiverUserId = &#63; and status = &#63; from the database.
4875             *
4876             * @param receiverUserId the receiver user ID
4877             * @param status the status
4878             * @throws SystemException if a system exception occurred
4879             */
4880            public void removeByR_S(long receiverUserId, int status)
4881                    throws SystemException {
4882                    for (SocialRequest socialRequest : findByR_S(receiverUserId, status)) {
4883                            remove(socialRequest);
4884                    }
4885            }
4886    
4887            /**
4888             * Removes the social request where userId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63; and receiverUserId = &#63; from the database.
4889             *
4890             * @param userId the user ID
4891             * @param classNameId the class name ID
4892             * @param classPK the class p k
4893             * @param type the type
4894             * @param receiverUserId the receiver user ID
4895             * @return the social request that was removed
4896             * @throws SystemException if a system exception occurred
4897             */
4898            public SocialRequest removeByU_C_C_T_R(long userId, long classNameId,
4899                    long classPK, int type, long receiverUserId)
4900                    throws NoSuchRequestException, SystemException {
4901                    SocialRequest socialRequest = findByU_C_C_T_R(userId, classNameId,
4902                                    classPK, type, receiverUserId);
4903    
4904                    return remove(socialRequest);
4905            }
4906    
4907            /**
4908             * Removes all the social requests where userId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63; and status = &#63; from the database.
4909             *
4910             * @param userId the user ID
4911             * @param classNameId the class name ID
4912             * @param classPK the class p k
4913             * @param type the type
4914             * @param status the status
4915             * @throws SystemException if a system exception occurred
4916             */
4917            public void removeByU_C_C_T_S(long userId, long classNameId, long classPK,
4918                    int type, int status) throws SystemException {
4919                    for (SocialRequest socialRequest : findByU_C_C_T_S(userId, classNameId,
4920                                    classPK, type, status)) {
4921                            remove(socialRequest);
4922                    }
4923            }
4924    
4925            /**
4926             * Removes all the social requests where classNameId = &#63; and classPK = &#63; and type = &#63; and receiverUserId = &#63; and status = &#63; from the database.
4927             *
4928             * @param classNameId the class name ID
4929             * @param classPK the class p k
4930             * @param type the type
4931             * @param receiverUserId the receiver user ID
4932             * @param status the status
4933             * @throws SystemException if a system exception occurred
4934             */
4935            public void removeByC_C_T_R_S(long classNameId, long classPK, int type,
4936                    long receiverUserId, int status) throws SystemException {
4937                    for (SocialRequest socialRequest : findByC_C_T_R_S(classNameId,
4938                                    classPK, type, receiverUserId, status)) {
4939                            remove(socialRequest);
4940                    }
4941            }
4942    
4943            /**
4944             * Removes all the social requests from the database.
4945             *
4946             * @throws SystemException if a system exception occurred
4947             */
4948            public void removeAll() throws SystemException {
4949                    for (SocialRequest socialRequest : findAll()) {
4950                            remove(socialRequest);
4951                    }
4952            }
4953    
4954            /**
4955             * Returns the number of social requests where uuid = &#63;.
4956             *
4957             * @param uuid the uuid
4958             * @return the number of matching social requests
4959             * @throws SystemException if a system exception occurred
4960             */
4961            public int countByUuid(String uuid) throws SystemException {
4962                    Object[] finderArgs = new Object[] { uuid };
4963    
4964                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
4965                                    finderArgs, this);
4966    
4967                    if (count == null) {
4968                            StringBundler query = new StringBundler(2);
4969    
4970                            query.append(_SQL_COUNT_SOCIALREQUEST_WHERE);
4971    
4972                            if (uuid == null) {
4973                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
4974                            }
4975                            else {
4976                                    if (uuid.equals(StringPool.BLANK)) {
4977                                            query.append(_FINDER_COLUMN_UUID_UUID_3);
4978                                    }
4979                                    else {
4980                                            query.append(_FINDER_COLUMN_UUID_UUID_2);
4981                                    }
4982                            }
4983    
4984                            String sql = query.toString();
4985    
4986                            Session session = null;
4987    
4988                            try {
4989                                    session = openSession();
4990    
4991                                    Query q = session.createQuery(sql);
4992    
4993                                    QueryPos qPos = QueryPos.getInstance(q);
4994    
4995                                    if (uuid != null) {
4996                                            qPos.add(uuid);
4997                                    }
4998    
4999                                    count = (Long)q.uniqueResult();
5000                            }
5001                            catch (Exception e) {
5002                                    throw processException(e);
5003                            }
5004                            finally {
5005                                    if (count == null) {
5006                                            count = Long.valueOf(0);
5007                                    }
5008    
5009                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
5010                                            finderArgs, count);
5011    
5012                                    closeSession(session);
5013                            }
5014                    }
5015    
5016                    return count.intValue();
5017            }
5018    
5019            /**
5020             * Returns the number of social requests where uuid = &#63; and groupId = &#63;.
5021             *
5022             * @param uuid the uuid
5023             * @param groupId the group ID
5024             * @return the number of matching social requests
5025             * @throws SystemException if a system exception occurred
5026             */
5027            public int countByUUID_G(String uuid, long groupId)
5028                    throws SystemException {
5029                    Object[] finderArgs = new Object[] { uuid, groupId };
5030    
5031                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
5032                                    finderArgs, this);
5033    
5034                    if (count == null) {
5035                            StringBundler query = new StringBundler(3);
5036    
5037                            query.append(_SQL_COUNT_SOCIALREQUEST_WHERE);
5038    
5039                            if (uuid == null) {
5040                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
5041                            }
5042                            else {
5043                                    if (uuid.equals(StringPool.BLANK)) {
5044                                            query.append(_FINDER_COLUMN_UUID_G_UUID_3);
5045                                    }
5046                                    else {
5047                                            query.append(_FINDER_COLUMN_UUID_G_UUID_2);
5048                                    }
5049                            }
5050    
5051                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
5052    
5053                            String sql = query.toString();
5054    
5055                            Session session = null;
5056    
5057                            try {
5058                                    session = openSession();
5059    
5060                                    Query q = session.createQuery(sql);
5061    
5062                                    QueryPos qPos = QueryPos.getInstance(q);
5063    
5064                                    if (uuid != null) {
5065                                            qPos.add(uuid);
5066                                    }
5067    
5068                                    qPos.add(groupId);
5069    
5070                                    count = (Long)q.uniqueResult();
5071                            }
5072                            catch (Exception e) {
5073                                    throw processException(e);
5074                            }
5075                            finally {
5076                                    if (count == null) {
5077                                            count = Long.valueOf(0);
5078                                    }
5079    
5080                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
5081                                            finderArgs, count);
5082    
5083                                    closeSession(session);
5084                            }
5085                    }
5086    
5087                    return count.intValue();
5088            }
5089    
5090            /**
5091             * Returns the number of social requests where companyId = &#63;.
5092             *
5093             * @param companyId the company ID
5094             * @return the number of matching social requests
5095             * @throws SystemException if a system exception occurred
5096             */
5097            public int countByCompanyId(long companyId) throws SystemException {
5098                    Object[] finderArgs = new Object[] { companyId };
5099    
5100                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
5101                                    finderArgs, this);
5102    
5103                    if (count == null) {
5104                            StringBundler query = new StringBundler(2);
5105    
5106                            query.append(_SQL_COUNT_SOCIALREQUEST_WHERE);
5107    
5108                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
5109    
5110                            String sql = query.toString();
5111    
5112                            Session session = null;
5113    
5114                            try {
5115                                    session = openSession();
5116    
5117                                    Query q = session.createQuery(sql);
5118    
5119                                    QueryPos qPos = QueryPos.getInstance(q);
5120    
5121                                    qPos.add(companyId);
5122    
5123                                    count = (Long)q.uniqueResult();
5124                            }
5125                            catch (Exception e) {
5126                                    throw processException(e);
5127                            }
5128                            finally {
5129                                    if (count == null) {
5130                                            count = Long.valueOf(0);
5131                                    }
5132    
5133                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
5134                                            finderArgs, count);
5135    
5136                                    closeSession(session);
5137                            }
5138                    }
5139    
5140                    return count.intValue();
5141            }
5142    
5143            /**
5144             * Returns the number of social requests where userId = &#63;.
5145             *
5146             * @param userId the user ID
5147             * @return the number of matching social requests
5148             * @throws SystemException if a system exception occurred
5149             */
5150            public int countByUserId(long userId) throws SystemException {
5151                    Object[] finderArgs = new Object[] { userId };
5152    
5153                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID,
5154                                    finderArgs, this);
5155    
5156                    if (count == null) {
5157                            StringBundler query = new StringBundler(2);
5158    
5159                            query.append(_SQL_COUNT_SOCIALREQUEST_WHERE);
5160    
5161                            query.append(_FINDER_COLUMN_USERID_USERID_2);
5162    
5163                            String sql = query.toString();
5164    
5165                            Session session = null;
5166    
5167                            try {
5168                                    session = openSession();
5169    
5170                                    Query q = session.createQuery(sql);
5171    
5172                                    QueryPos qPos = QueryPos.getInstance(q);
5173    
5174                                    qPos.add(userId);
5175    
5176                                    count = (Long)q.uniqueResult();
5177                            }
5178                            catch (Exception e) {
5179                                    throw processException(e);
5180                            }
5181                            finally {
5182                                    if (count == null) {
5183                                            count = Long.valueOf(0);
5184                                    }
5185    
5186                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID,
5187                                            finderArgs, count);
5188    
5189                                    closeSession(session);
5190                            }
5191                    }
5192    
5193                    return count.intValue();
5194            }
5195    
5196            /**
5197             * Returns the number of social requests where receiverUserId = &#63;.
5198             *
5199             * @param receiverUserId the receiver user ID
5200             * @return the number of matching social requests
5201             * @throws SystemException if a system exception occurred
5202             */
5203            public int countByReceiverUserId(long receiverUserId)
5204                    throws SystemException {
5205                    Object[] finderArgs = new Object[] { receiverUserId };
5206    
5207                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_RECEIVERUSERID,
5208                                    finderArgs, this);
5209    
5210                    if (count == null) {
5211                            StringBundler query = new StringBundler(2);
5212    
5213                            query.append(_SQL_COUNT_SOCIALREQUEST_WHERE);
5214    
5215                            query.append(_FINDER_COLUMN_RECEIVERUSERID_RECEIVERUSERID_2);
5216    
5217                            String sql = query.toString();
5218    
5219                            Session session = null;
5220    
5221                            try {
5222                                    session = openSession();
5223    
5224                                    Query q = session.createQuery(sql);
5225    
5226                                    QueryPos qPos = QueryPos.getInstance(q);
5227    
5228                                    qPos.add(receiverUserId);
5229    
5230                                    count = (Long)q.uniqueResult();
5231                            }
5232                            catch (Exception e) {
5233                                    throw processException(e);
5234                            }
5235                            finally {
5236                                    if (count == null) {
5237                                            count = Long.valueOf(0);
5238                                    }
5239    
5240                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_RECEIVERUSERID,
5241                                            finderArgs, count);
5242    
5243                                    closeSession(session);
5244                            }
5245                    }
5246    
5247                    return count.intValue();
5248            }
5249    
5250            /**
5251             * Returns the number of social requests where userId = &#63; and status = &#63;.
5252             *
5253             * @param userId the user ID
5254             * @param status the status
5255             * @return the number of matching social requests
5256             * @throws SystemException if a system exception occurred
5257             */
5258            public int countByU_S(long userId, int status) throws SystemException {
5259                    Object[] finderArgs = new Object[] { userId, status };
5260    
5261                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U_S,
5262                                    finderArgs, this);
5263    
5264                    if (count == null) {
5265                            StringBundler query = new StringBundler(3);
5266    
5267                            query.append(_SQL_COUNT_SOCIALREQUEST_WHERE);
5268    
5269                            query.append(_FINDER_COLUMN_U_S_USERID_2);
5270    
5271                            query.append(_FINDER_COLUMN_U_S_STATUS_2);
5272    
5273                            String sql = query.toString();
5274    
5275                            Session session = null;
5276    
5277                            try {
5278                                    session = openSession();
5279    
5280                                    Query q = session.createQuery(sql);
5281    
5282                                    QueryPos qPos = QueryPos.getInstance(q);
5283    
5284                                    qPos.add(userId);
5285    
5286                                    qPos.add(status);
5287    
5288                                    count = (Long)q.uniqueResult();
5289                            }
5290                            catch (Exception e) {
5291                                    throw processException(e);
5292                            }
5293                            finally {
5294                                    if (count == null) {
5295                                            count = Long.valueOf(0);
5296                                    }
5297    
5298                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_S, finderArgs,
5299                                            count);
5300    
5301                                    closeSession(session);
5302                            }
5303                    }
5304    
5305                    return count.intValue();
5306            }
5307    
5308            /**
5309             * Returns the number of social requests where receiverUserId = &#63; and status = &#63;.
5310             *
5311             * @param receiverUserId the receiver user ID
5312             * @param status the status
5313             * @return the number of matching social requests
5314             * @throws SystemException if a system exception occurred
5315             */
5316            public int countByR_S(long receiverUserId, int status)
5317                    throws SystemException {
5318                    Object[] finderArgs = new Object[] { receiverUserId, status };
5319    
5320                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_R_S,
5321                                    finderArgs, this);
5322    
5323                    if (count == null) {
5324                            StringBundler query = new StringBundler(3);
5325    
5326                            query.append(_SQL_COUNT_SOCIALREQUEST_WHERE);
5327    
5328                            query.append(_FINDER_COLUMN_R_S_RECEIVERUSERID_2);
5329    
5330                            query.append(_FINDER_COLUMN_R_S_STATUS_2);
5331    
5332                            String sql = query.toString();
5333    
5334                            Session session = null;
5335    
5336                            try {
5337                                    session = openSession();
5338    
5339                                    Query q = session.createQuery(sql);
5340    
5341                                    QueryPos qPos = QueryPos.getInstance(q);
5342    
5343                                    qPos.add(receiverUserId);
5344    
5345                                    qPos.add(status);
5346    
5347                                    count = (Long)q.uniqueResult();
5348                            }
5349                            catch (Exception e) {
5350                                    throw processException(e);
5351                            }
5352                            finally {
5353                                    if (count == null) {
5354                                            count = Long.valueOf(0);
5355                                    }
5356    
5357                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_R_S, finderArgs,
5358                                            count);
5359    
5360                                    closeSession(session);
5361                            }
5362                    }
5363    
5364                    return count.intValue();
5365            }
5366    
5367            /**
5368             * Returns the number of social requests where userId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63; and receiverUserId = &#63;.
5369             *
5370             * @param userId the user ID
5371             * @param classNameId the class name ID
5372             * @param classPK the class p k
5373             * @param type the type
5374             * @param receiverUserId the receiver user ID
5375             * @return the number of matching social requests
5376             * @throws SystemException if a system exception occurred
5377             */
5378            public int countByU_C_C_T_R(long userId, long classNameId, long classPK,
5379                    int type, long receiverUserId) throws SystemException {
5380                    Object[] finderArgs = new Object[] {
5381                                    userId, classNameId, classPK, type, receiverUserId
5382                            };
5383    
5384                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U_C_C_T_R,
5385                                    finderArgs, this);
5386    
5387                    if (count == null) {
5388                            StringBundler query = new StringBundler(6);
5389    
5390                            query.append(_SQL_COUNT_SOCIALREQUEST_WHERE);
5391    
5392                            query.append(_FINDER_COLUMN_U_C_C_T_R_USERID_2);
5393    
5394                            query.append(_FINDER_COLUMN_U_C_C_T_R_CLASSNAMEID_2);
5395    
5396                            query.append(_FINDER_COLUMN_U_C_C_T_R_CLASSPK_2);
5397    
5398                            query.append(_FINDER_COLUMN_U_C_C_T_R_TYPE_2);
5399    
5400                            query.append(_FINDER_COLUMN_U_C_C_T_R_RECEIVERUSERID_2);
5401    
5402                            String sql = query.toString();
5403    
5404                            Session session = null;
5405    
5406                            try {
5407                                    session = openSession();
5408    
5409                                    Query q = session.createQuery(sql);
5410    
5411                                    QueryPos qPos = QueryPos.getInstance(q);
5412    
5413                                    qPos.add(userId);
5414    
5415                                    qPos.add(classNameId);
5416    
5417                                    qPos.add(classPK);
5418    
5419                                    qPos.add(type);
5420    
5421                                    qPos.add(receiverUserId);
5422    
5423                                    count = (Long)q.uniqueResult();
5424                            }
5425                            catch (Exception e) {
5426                                    throw processException(e);
5427                            }
5428                            finally {
5429                                    if (count == null) {
5430                                            count = Long.valueOf(0);
5431                                    }
5432    
5433                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_C_C_T_R,
5434                                            finderArgs, count);
5435    
5436                                    closeSession(session);
5437                            }
5438                    }
5439    
5440                    return count.intValue();
5441            }
5442    
5443            /**
5444             * Returns the number of social requests where userId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63; and status = &#63;.
5445             *
5446             * @param userId the user ID
5447             * @param classNameId the class name ID
5448             * @param classPK the class p k
5449             * @param type the type
5450             * @param status the status
5451             * @return the number of matching social requests
5452             * @throws SystemException if a system exception occurred
5453             */
5454            public int countByU_C_C_T_S(long userId, long classNameId, long classPK,
5455                    int type, int status) throws SystemException {
5456                    Object[] finderArgs = new Object[] {
5457                                    userId, classNameId, classPK, type, status
5458                            };
5459    
5460                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U_C_C_T_S,
5461                                    finderArgs, this);
5462    
5463                    if (count == null) {
5464                            StringBundler query = new StringBundler(6);
5465    
5466                            query.append(_SQL_COUNT_SOCIALREQUEST_WHERE);
5467    
5468                            query.append(_FINDER_COLUMN_U_C_C_T_S_USERID_2);
5469    
5470                            query.append(_FINDER_COLUMN_U_C_C_T_S_CLASSNAMEID_2);
5471    
5472                            query.append(_FINDER_COLUMN_U_C_C_T_S_CLASSPK_2);
5473    
5474                            query.append(_FINDER_COLUMN_U_C_C_T_S_TYPE_2);
5475    
5476                            query.append(_FINDER_COLUMN_U_C_C_T_S_STATUS_2);
5477    
5478                            String sql = query.toString();
5479    
5480                            Session session = null;
5481    
5482                            try {
5483                                    session = openSession();
5484    
5485                                    Query q = session.createQuery(sql);
5486    
5487                                    QueryPos qPos = QueryPos.getInstance(q);
5488    
5489                                    qPos.add(userId);
5490    
5491                                    qPos.add(classNameId);
5492    
5493                                    qPos.add(classPK);
5494    
5495                                    qPos.add(type);
5496    
5497                                    qPos.add(status);
5498    
5499                                    count = (Long)q.uniqueResult();
5500                            }
5501                            catch (Exception e) {
5502                                    throw processException(e);
5503                            }
5504                            finally {
5505                                    if (count == null) {
5506                                            count = Long.valueOf(0);
5507                                    }
5508    
5509                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_C_C_T_S,
5510                                            finderArgs, count);
5511    
5512                                    closeSession(session);
5513                            }
5514                    }
5515    
5516                    return count.intValue();
5517            }
5518    
5519            /**
5520             * Returns the number of social requests where classNameId = &#63; and classPK = &#63; and type = &#63; and receiverUserId = &#63; and status = &#63;.
5521             *
5522             * @param classNameId the class name ID
5523             * @param classPK the class p k
5524             * @param type the type
5525             * @param receiverUserId the receiver user ID
5526             * @param status the status
5527             * @return the number of matching social requests
5528             * @throws SystemException if a system exception occurred
5529             */
5530            public int countByC_C_T_R_S(long classNameId, long classPK, int type,
5531                    long receiverUserId, int status) throws SystemException {
5532                    Object[] finderArgs = new Object[] {
5533                                    classNameId, classPK, type, receiverUserId, status
5534                            };
5535    
5536                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C_T_R_S,
5537                                    finderArgs, this);
5538    
5539                    if (count == null) {
5540                            StringBundler query = new StringBundler(6);
5541    
5542                            query.append(_SQL_COUNT_SOCIALREQUEST_WHERE);
5543    
5544                            query.append(_FINDER_COLUMN_C_C_T_R_S_CLASSNAMEID_2);
5545    
5546                            query.append(_FINDER_COLUMN_C_C_T_R_S_CLASSPK_2);
5547    
5548                            query.append(_FINDER_COLUMN_C_C_T_R_S_TYPE_2);
5549    
5550                            query.append(_FINDER_COLUMN_C_C_T_R_S_RECEIVERUSERID_2);
5551    
5552                            query.append(_FINDER_COLUMN_C_C_T_R_S_STATUS_2);
5553    
5554                            String sql = query.toString();
5555    
5556                            Session session = null;
5557    
5558                            try {
5559                                    session = openSession();
5560    
5561                                    Query q = session.createQuery(sql);
5562    
5563                                    QueryPos qPos = QueryPos.getInstance(q);
5564    
5565                                    qPos.add(classNameId);
5566    
5567                                    qPos.add(classPK);
5568    
5569                                    qPos.add(type);
5570    
5571                                    qPos.add(receiverUserId);
5572    
5573                                    qPos.add(status);
5574    
5575                                    count = (Long)q.uniqueResult();
5576                            }
5577                            catch (Exception e) {
5578                                    throw processException(e);
5579                            }
5580                            finally {
5581                                    if (count == null) {
5582                                            count = Long.valueOf(0);
5583                                    }
5584    
5585                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C_T_R_S,
5586                                            finderArgs, count);
5587    
5588                                    closeSession(session);
5589                            }
5590                    }
5591    
5592                    return count.intValue();
5593            }
5594    
5595            /**
5596             * Returns the number of social requests.
5597             *
5598             * @return the number of social requests
5599             * @throws SystemException if a system exception occurred
5600             */
5601            public int countAll() throws SystemException {
5602                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
5603                                    FINDER_ARGS_EMPTY, this);
5604    
5605                    if (count == null) {
5606                            Session session = null;
5607    
5608                            try {
5609                                    session = openSession();
5610    
5611                                    Query q = session.createQuery(_SQL_COUNT_SOCIALREQUEST);
5612    
5613                                    count = (Long)q.uniqueResult();
5614                            }
5615                            catch (Exception e) {
5616                                    throw processException(e);
5617                            }
5618                            finally {
5619                                    if (count == null) {
5620                                            count = Long.valueOf(0);
5621                                    }
5622    
5623                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
5624                                            FINDER_ARGS_EMPTY, count);
5625    
5626                                    closeSession(session);
5627                            }
5628                    }
5629    
5630                    return count.intValue();
5631            }
5632    
5633            /**
5634             * Initializes the social request persistence.
5635             */
5636            public void afterPropertiesSet() {
5637                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
5638                                            com.liferay.portal.util.PropsUtil.get(
5639                                                    "value.object.listener.com.liferay.portlet.social.model.SocialRequest")));
5640    
5641                    if (listenerClassNames.length > 0) {
5642                            try {
5643                                    List<ModelListener<SocialRequest>> listenersList = new ArrayList<ModelListener<SocialRequest>>();
5644    
5645                                    for (String listenerClassName : listenerClassNames) {
5646                                            Class<?> clazz = getClass();
5647    
5648                                            listenersList.add((ModelListener<SocialRequest>)InstanceFactory.newInstance(
5649                                                            clazz.getClassLoader(), listenerClassName));
5650                                    }
5651    
5652                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
5653                            }
5654                            catch (Exception e) {
5655                                    _log.error(e);
5656                            }
5657                    }
5658            }
5659    
5660            public void destroy() {
5661                    EntityCacheUtil.removeCache(SocialRequestImpl.class.getName());
5662                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
5663                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
5664            }
5665    
5666            @BeanReference(type = SocialActivityPersistence.class)
5667            protected SocialActivityPersistence socialActivityPersistence;
5668            @BeanReference(type = SocialActivityAchievementPersistence.class)
5669            protected SocialActivityAchievementPersistence socialActivityAchievementPersistence;
5670            @BeanReference(type = SocialActivityCounterPersistence.class)
5671            protected SocialActivityCounterPersistence socialActivityCounterPersistence;
5672            @BeanReference(type = SocialActivityLimitPersistence.class)
5673            protected SocialActivityLimitPersistence socialActivityLimitPersistence;
5674            @BeanReference(type = SocialActivitySettingPersistence.class)
5675            protected SocialActivitySettingPersistence socialActivitySettingPersistence;
5676            @BeanReference(type = SocialRelationPersistence.class)
5677            protected SocialRelationPersistence socialRelationPersistence;
5678            @BeanReference(type = SocialRequestPersistence.class)
5679            protected SocialRequestPersistence socialRequestPersistence;
5680            @BeanReference(type = ResourcePersistence.class)
5681            protected ResourcePersistence resourcePersistence;
5682            @BeanReference(type = UserPersistence.class)
5683            protected UserPersistence userPersistence;
5684            private static final String _SQL_SELECT_SOCIALREQUEST = "SELECT socialRequest FROM SocialRequest socialRequest";
5685            private static final String _SQL_SELECT_SOCIALREQUEST_WHERE = "SELECT socialRequest FROM SocialRequest socialRequest WHERE ";
5686            private static final String _SQL_COUNT_SOCIALREQUEST = "SELECT COUNT(socialRequest) FROM SocialRequest socialRequest";
5687            private static final String _SQL_COUNT_SOCIALREQUEST_WHERE = "SELECT COUNT(socialRequest) FROM SocialRequest socialRequest WHERE ";
5688            private static final String _FINDER_COLUMN_UUID_UUID_1 = "socialRequest.uuid IS NULL";
5689            private static final String _FINDER_COLUMN_UUID_UUID_2 = "socialRequest.uuid = ?";
5690            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(socialRequest.uuid IS NULL OR socialRequest.uuid = ?)";
5691            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "socialRequest.uuid IS NULL AND ";
5692            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "socialRequest.uuid = ? AND ";
5693            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(socialRequest.uuid IS NULL OR socialRequest.uuid = ?) AND ";
5694            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "socialRequest.groupId = ?";
5695            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "socialRequest.companyId = ?";
5696            private static final String _FINDER_COLUMN_USERID_USERID_2 = "socialRequest.userId = ?";
5697            private static final String _FINDER_COLUMN_RECEIVERUSERID_RECEIVERUSERID_2 = "socialRequest.receiverUserId = ?";
5698            private static final String _FINDER_COLUMN_U_S_USERID_2 = "socialRequest.userId = ? AND ";
5699            private static final String _FINDER_COLUMN_U_S_STATUS_2 = "socialRequest.status = ?";
5700            private static final String _FINDER_COLUMN_R_S_RECEIVERUSERID_2 = "socialRequest.receiverUserId = ? AND ";
5701            private static final String _FINDER_COLUMN_R_S_STATUS_2 = "socialRequest.status = ?";
5702            private static final String _FINDER_COLUMN_U_C_C_T_R_USERID_2 = "socialRequest.userId = ? AND ";
5703            private static final String _FINDER_COLUMN_U_C_C_T_R_CLASSNAMEID_2 = "socialRequest.classNameId = ? AND ";
5704            private static final String _FINDER_COLUMN_U_C_C_T_R_CLASSPK_2 = "socialRequest.classPK = ? AND ";
5705            private static final String _FINDER_COLUMN_U_C_C_T_R_TYPE_2 = "socialRequest.type = ? AND ";
5706            private static final String _FINDER_COLUMN_U_C_C_T_R_RECEIVERUSERID_2 = "socialRequest.receiverUserId = ?";
5707            private static final String _FINDER_COLUMN_U_C_C_T_S_USERID_2 = "socialRequest.userId = ? AND ";
5708            private static final String _FINDER_COLUMN_U_C_C_T_S_CLASSNAMEID_2 = "socialRequest.classNameId = ? AND ";
5709            private static final String _FINDER_COLUMN_U_C_C_T_S_CLASSPK_2 = "socialRequest.classPK = ? AND ";
5710            private static final String _FINDER_COLUMN_U_C_C_T_S_TYPE_2 = "socialRequest.type = ? AND ";
5711            private static final String _FINDER_COLUMN_U_C_C_T_S_STATUS_2 = "socialRequest.status = ?";
5712            private static final String _FINDER_COLUMN_C_C_T_R_S_CLASSNAMEID_2 = "socialRequest.classNameId = ? AND ";
5713            private static final String _FINDER_COLUMN_C_C_T_R_S_CLASSPK_2 = "socialRequest.classPK = ? AND ";
5714            private static final String _FINDER_COLUMN_C_C_T_R_S_TYPE_2 = "socialRequest.type = ? AND ";
5715            private static final String _FINDER_COLUMN_C_C_T_R_S_RECEIVERUSERID_2 = "socialRequest.receiverUserId = ? AND ";
5716            private static final String _FINDER_COLUMN_C_C_T_R_S_STATUS_2 = "socialRequest.status = ?";
5717            private static final String _ORDER_BY_ENTITY_ALIAS = "socialRequest.";
5718            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No SocialRequest exists with the primary key ";
5719            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No SocialRequest exists with the key {";
5720            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
5721            private static Log _log = LogFactoryUtil.getLog(SocialRequestPersistenceImpl.class);
5722            private static SocialRequest _nullSocialRequest = new SocialRequestImpl() {
5723                            @Override
5724                            public Object clone() {
5725                                    return this;
5726                            }
5727    
5728                            @Override
5729                            public CacheModel<SocialRequest> toCacheModel() {
5730                                    return _nullSocialRequestCacheModel;
5731                            }
5732                    };
5733    
5734            private static CacheModel<SocialRequest> _nullSocialRequestCacheModel = new CacheModel<SocialRequest>() {
5735                            public SocialRequest toEntityModel() {
5736                                    return _nullSocialRequest;
5737                            }
5738                    };
5739    }