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