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