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