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