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