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