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