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