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