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