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