001    /**
002     * Copyright (c) 2000-2010 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;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.kernel.annotation.BeanReference;
019    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderPath;
023    import com.liferay.portal.kernel.dao.orm.Query;
024    import com.liferay.portal.kernel.dao.orm.QueryPos;
025    import com.liferay.portal.kernel.dao.orm.QueryUtil;
026    import com.liferay.portal.kernel.dao.orm.Session;
027    import com.liferay.portal.kernel.exception.SystemException;
028    import com.liferay.portal.kernel.log.Log;
029    import com.liferay.portal.kernel.log.LogFactoryUtil;
030    import com.liferay.portal.kernel.util.GetterUtil;
031    import com.liferay.portal.kernel.util.InstanceFactory;
032    import com.liferay.portal.kernel.util.OrderByComparator;
033    import com.liferay.portal.kernel.util.StringBundler;
034    import com.liferay.portal.kernel.util.StringPool;
035    import com.liferay.portal.kernel.util.StringUtil;
036    import com.liferay.portal.kernel.util.Validator;
037    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
038    import com.liferay.portal.model.ModelListener;
039    import com.liferay.portal.service.persistence.BatchSessionUtil;
040    import com.liferay.portal.service.persistence.ResourcePersistence;
041    import com.liferay.portal.service.persistence.UserPersistence;
042    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
043    
044    import com.liferay.portlet.social.NoSuchRelationException;
045    import com.liferay.portlet.social.model.SocialRelation;
046    import com.liferay.portlet.social.model.impl.SocialRelationImpl;
047    import com.liferay.portlet.social.model.impl.SocialRelationModelImpl;
048    
049    import java.io.Serializable;
050    
051    import java.util.ArrayList;
052    import java.util.Collections;
053    import java.util.List;
054    
055    /**
056     * @author    Brian Wing Shun Chan
057     * @see       SocialRelationPersistence
058     * @see       SocialRelationUtil
059     * @generated
060     */
061    public class SocialRelationPersistenceImpl extends BasePersistenceImpl<SocialRelation>
062            implements SocialRelationPersistence {
063            public static final String FINDER_CLASS_NAME_ENTITY = SocialRelationImpl.class.getName();
064            public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
065                    ".List";
066            public static final FinderPath FINDER_PATH_FIND_BY_UUID = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
067                            SocialRelationModelImpl.FINDER_CACHE_ENABLED,
068                            FINDER_CLASS_NAME_LIST, "findByUuid",
069                            new String[] {
070                                    String.class.getName(),
071                                    
072                            "java.lang.Integer", "java.lang.Integer",
073                                    "com.liferay.portal.kernel.util.OrderByComparator"
074                            });
075            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
076                            SocialRelationModelImpl.FINDER_CACHE_ENABLED,
077                            FINDER_CLASS_NAME_LIST, "countByUuid",
078                            new String[] { String.class.getName() });
079            public static final FinderPath FINDER_PATH_FIND_BY_COMPANYID = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
080                            SocialRelationModelImpl.FINDER_CACHE_ENABLED,
081                            FINDER_CLASS_NAME_LIST, "findByCompanyId",
082                            new String[] {
083                                    Long.class.getName(),
084                                    
085                            "java.lang.Integer", "java.lang.Integer",
086                                    "com.liferay.portal.kernel.util.OrderByComparator"
087                            });
088            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
089                            SocialRelationModelImpl.FINDER_CACHE_ENABLED,
090                            FINDER_CLASS_NAME_LIST, "countByCompanyId",
091                            new String[] { Long.class.getName() });
092            public static final FinderPath FINDER_PATH_FIND_BY_USERID1 = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
093                            SocialRelationModelImpl.FINDER_CACHE_ENABLED,
094                            FINDER_CLASS_NAME_LIST, "findByUserId1",
095                            new String[] {
096                                    Long.class.getName(),
097                                    
098                            "java.lang.Integer", "java.lang.Integer",
099                                    "com.liferay.portal.kernel.util.OrderByComparator"
100                            });
101            public static final FinderPath FINDER_PATH_COUNT_BY_USERID1 = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
102                            SocialRelationModelImpl.FINDER_CACHE_ENABLED,
103                            FINDER_CLASS_NAME_LIST, "countByUserId1",
104                            new String[] { Long.class.getName() });
105            public static final FinderPath FINDER_PATH_FIND_BY_USERID2 = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
106                            SocialRelationModelImpl.FINDER_CACHE_ENABLED,
107                            FINDER_CLASS_NAME_LIST, "findByUserId2",
108                            new String[] {
109                                    Long.class.getName(),
110                                    
111                            "java.lang.Integer", "java.lang.Integer",
112                                    "com.liferay.portal.kernel.util.OrderByComparator"
113                            });
114            public static final FinderPath FINDER_PATH_COUNT_BY_USERID2 = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
115                            SocialRelationModelImpl.FINDER_CACHE_ENABLED,
116                            FINDER_CLASS_NAME_LIST, "countByUserId2",
117                            new String[] { Long.class.getName() });
118            public static final FinderPath FINDER_PATH_FIND_BY_TYPE = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
119                            SocialRelationModelImpl.FINDER_CACHE_ENABLED,
120                            FINDER_CLASS_NAME_LIST, "findByType",
121                            new String[] {
122                                    Integer.class.getName(),
123                                    
124                            "java.lang.Integer", "java.lang.Integer",
125                                    "com.liferay.portal.kernel.util.OrderByComparator"
126                            });
127            public static final FinderPath FINDER_PATH_COUNT_BY_TYPE = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
128                            SocialRelationModelImpl.FINDER_CACHE_ENABLED,
129                            FINDER_CLASS_NAME_LIST, "countByType",
130                            new String[] { Integer.class.getName() });
131            public static final FinderPath FINDER_PATH_FIND_BY_C_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
132                            SocialRelationModelImpl.FINDER_CACHE_ENABLED,
133                            FINDER_CLASS_NAME_LIST, "findByC_T",
134                            new String[] {
135                                    Long.class.getName(), Integer.class.getName(),
136                                    
137                            "java.lang.Integer", "java.lang.Integer",
138                                    "com.liferay.portal.kernel.util.OrderByComparator"
139                            });
140            public static final FinderPath FINDER_PATH_COUNT_BY_C_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
141                            SocialRelationModelImpl.FINDER_CACHE_ENABLED,
142                            FINDER_CLASS_NAME_LIST, "countByC_T",
143                            new String[] { Long.class.getName(), Integer.class.getName() });
144            public static final FinderPath FINDER_PATH_FIND_BY_U1_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
145                            SocialRelationModelImpl.FINDER_CACHE_ENABLED,
146                            FINDER_CLASS_NAME_LIST, "findByU1_T",
147                            new String[] {
148                                    Long.class.getName(), Integer.class.getName(),
149                                    
150                            "java.lang.Integer", "java.lang.Integer",
151                                    "com.liferay.portal.kernel.util.OrderByComparator"
152                            });
153            public static final FinderPath FINDER_PATH_COUNT_BY_U1_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
154                            SocialRelationModelImpl.FINDER_CACHE_ENABLED,
155                            FINDER_CLASS_NAME_LIST, "countByU1_T",
156                            new String[] { Long.class.getName(), Integer.class.getName() });
157            public static final FinderPath FINDER_PATH_FIND_BY_U2_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
158                            SocialRelationModelImpl.FINDER_CACHE_ENABLED,
159                            FINDER_CLASS_NAME_LIST, "findByU2_T",
160                            new String[] {
161                                    Long.class.getName(), Integer.class.getName(),
162                                    
163                            "java.lang.Integer", "java.lang.Integer",
164                                    "com.liferay.portal.kernel.util.OrderByComparator"
165                            });
166            public static final FinderPath FINDER_PATH_COUNT_BY_U2_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
167                            SocialRelationModelImpl.FINDER_CACHE_ENABLED,
168                            FINDER_CLASS_NAME_LIST, "countByU2_T",
169                            new String[] { Long.class.getName(), Integer.class.getName() });
170            public static final FinderPath FINDER_PATH_FETCH_BY_U1_U2_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
171                            SocialRelationModelImpl.FINDER_CACHE_ENABLED,
172                            FINDER_CLASS_NAME_ENTITY, "fetchByU1_U2_T",
173                            new String[] {
174                                    Long.class.getName(), Long.class.getName(),
175                                    Integer.class.getName()
176                            });
177            public static final FinderPath FINDER_PATH_COUNT_BY_U1_U2_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
178                            SocialRelationModelImpl.FINDER_CACHE_ENABLED,
179                            FINDER_CLASS_NAME_LIST, "countByU1_U2_T",
180                            new String[] {
181                                    Long.class.getName(), Long.class.getName(),
182                                    Integer.class.getName()
183                            });
184            public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
185                            SocialRelationModelImpl.FINDER_CACHE_ENABLED,
186                            FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
187            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
188                            SocialRelationModelImpl.FINDER_CACHE_ENABLED,
189                            FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
190    
191            public void cacheResult(SocialRelation socialRelation) {
192                    EntityCacheUtil.putResult(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
193                            SocialRelationImpl.class, socialRelation.getPrimaryKey(),
194                            socialRelation);
195    
196                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U1_U2_T,
197                            new Object[] {
198                                    new Long(socialRelation.getUserId1()),
199                                    new Long(socialRelation.getUserId2()),
200                                    new Integer(socialRelation.getType())
201                            }, socialRelation);
202            }
203    
204            public void cacheResult(List<SocialRelation> socialRelations) {
205                    for (SocialRelation socialRelation : socialRelations) {
206                            if (EntityCacheUtil.getResult(
207                                                    SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
208                                                    SocialRelationImpl.class,
209                                                    socialRelation.getPrimaryKey(), this) == null) {
210                                    cacheResult(socialRelation);
211                            }
212                    }
213            }
214    
215            public void clearCache() {
216                    CacheRegistryUtil.clear(SocialRelationImpl.class.getName());
217                    EntityCacheUtil.clearCache(SocialRelationImpl.class.getName());
218                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
219                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
220            }
221    
222            public void clearCache(SocialRelation socialRelation) {
223                    EntityCacheUtil.removeResult(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
224                            SocialRelationImpl.class, socialRelation.getPrimaryKey());
225    
226                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U1_U2_T,
227                            new Object[] {
228                                    new Long(socialRelation.getUserId1()),
229                                    new Long(socialRelation.getUserId2()),
230                                    new Integer(socialRelation.getType())
231                            });
232            }
233    
234            public SocialRelation create(long relationId) {
235                    SocialRelation socialRelation = new SocialRelationImpl();
236    
237                    socialRelation.setNew(true);
238                    socialRelation.setPrimaryKey(relationId);
239    
240                    String uuid = PortalUUIDUtil.generate();
241    
242                    socialRelation.setUuid(uuid);
243    
244                    return socialRelation;
245            }
246    
247            public SocialRelation remove(Serializable primaryKey)
248                    throws NoSuchModelException, SystemException {
249                    return remove(((Long)primaryKey).longValue());
250            }
251    
252            public SocialRelation remove(long relationId)
253                    throws NoSuchRelationException, SystemException {
254                    Session session = null;
255    
256                    try {
257                            session = openSession();
258    
259                            SocialRelation socialRelation = (SocialRelation)session.get(SocialRelationImpl.class,
260                                            new Long(relationId));
261    
262                            if (socialRelation == null) {
263                                    if (_log.isWarnEnabled()) {
264                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + relationId);
265                                    }
266    
267                                    throw new NoSuchRelationException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
268                                            relationId);
269                            }
270    
271                            return remove(socialRelation);
272                    }
273                    catch (NoSuchRelationException nsee) {
274                            throw nsee;
275                    }
276                    catch (Exception e) {
277                            throw processException(e);
278                    }
279                    finally {
280                            closeSession(session);
281                    }
282            }
283    
284            protected SocialRelation removeImpl(SocialRelation socialRelation)
285                    throws SystemException {
286                    socialRelation = toUnwrappedModel(socialRelation);
287    
288                    Session session = null;
289    
290                    try {
291                            session = openSession();
292    
293                            if (socialRelation.isCachedModel() || BatchSessionUtil.isEnabled()) {
294                                    Object staleObject = session.get(SocialRelationImpl.class,
295                                                    socialRelation.getPrimaryKeyObj());
296    
297                                    if (staleObject != null) {
298                                            session.evict(staleObject);
299                                    }
300                            }
301    
302                            session.delete(socialRelation);
303    
304                            session.flush();
305                    }
306                    catch (Exception e) {
307                            throw processException(e);
308                    }
309                    finally {
310                            closeSession(session);
311                    }
312    
313                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
314    
315                    SocialRelationModelImpl socialRelationModelImpl = (SocialRelationModelImpl)socialRelation;
316    
317                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U1_U2_T,
318                            new Object[] {
319                                    new Long(socialRelationModelImpl.getOriginalUserId1()),
320                                    new Long(socialRelationModelImpl.getOriginalUserId2()),
321                                    new Integer(socialRelationModelImpl.getOriginalType())
322                            });
323    
324                    EntityCacheUtil.removeResult(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
325                            SocialRelationImpl.class, socialRelation.getPrimaryKey());
326    
327                    return socialRelation;
328            }
329    
330            public SocialRelation updateImpl(
331                    com.liferay.portlet.social.model.SocialRelation socialRelation,
332                    boolean merge) throws SystemException {
333                    socialRelation = toUnwrappedModel(socialRelation);
334    
335                    boolean isNew = socialRelation.isNew();
336    
337                    SocialRelationModelImpl socialRelationModelImpl = (SocialRelationModelImpl)socialRelation;
338    
339                    if (Validator.isNull(socialRelation.getUuid())) {
340                            String uuid = PortalUUIDUtil.generate();
341    
342                            socialRelation.setUuid(uuid);
343                    }
344    
345                    Session session = null;
346    
347                    try {
348                            session = openSession();
349    
350                            BatchSessionUtil.update(session, socialRelation, merge);
351    
352                            socialRelation.setNew(false);
353                    }
354                    catch (Exception e) {
355                            throw processException(e);
356                    }
357                    finally {
358                            closeSession(session);
359                    }
360    
361                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
362    
363                    EntityCacheUtil.putResult(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
364                            SocialRelationImpl.class, socialRelation.getPrimaryKey(),
365                            socialRelation);
366    
367                    if (!isNew &&
368                                    ((socialRelation.getUserId1() != socialRelationModelImpl.getOriginalUserId1()) ||
369                                    (socialRelation.getUserId2() != socialRelationModelImpl.getOriginalUserId2()) ||
370                                    (socialRelation.getType() != socialRelationModelImpl.getOriginalType()))) {
371                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U1_U2_T,
372                                    new Object[] {
373                                            new Long(socialRelationModelImpl.getOriginalUserId1()),
374                                            new Long(socialRelationModelImpl.getOriginalUserId2()),
375                                            new Integer(socialRelationModelImpl.getOriginalType())
376                                    });
377                    }
378    
379                    if (isNew ||
380                                    ((socialRelation.getUserId1() != socialRelationModelImpl.getOriginalUserId1()) ||
381                                    (socialRelation.getUserId2() != socialRelationModelImpl.getOriginalUserId2()) ||
382                                    (socialRelation.getType() != socialRelationModelImpl.getOriginalType()))) {
383                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U1_U2_T,
384                                    new Object[] {
385                                            new Long(socialRelation.getUserId1()),
386                                            new Long(socialRelation.getUserId2()),
387                                            new Integer(socialRelation.getType())
388                                    }, socialRelation);
389                    }
390    
391                    return socialRelation;
392            }
393    
394            protected SocialRelation toUnwrappedModel(SocialRelation socialRelation) {
395                    if (socialRelation instanceof SocialRelationImpl) {
396                            return socialRelation;
397                    }
398    
399                    SocialRelationImpl socialRelationImpl = new SocialRelationImpl();
400    
401                    socialRelationImpl.setNew(socialRelation.isNew());
402                    socialRelationImpl.setPrimaryKey(socialRelation.getPrimaryKey());
403    
404                    socialRelationImpl.setUuid(socialRelation.getUuid());
405                    socialRelationImpl.setRelationId(socialRelation.getRelationId());
406                    socialRelationImpl.setCompanyId(socialRelation.getCompanyId());
407                    socialRelationImpl.setCreateDate(socialRelation.getCreateDate());
408                    socialRelationImpl.setUserId1(socialRelation.getUserId1());
409                    socialRelationImpl.setUserId2(socialRelation.getUserId2());
410                    socialRelationImpl.setType(socialRelation.getType());
411    
412                    return socialRelationImpl;
413            }
414    
415            public SocialRelation findByPrimaryKey(Serializable primaryKey)
416                    throws NoSuchModelException, SystemException {
417                    return findByPrimaryKey(((Long)primaryKey).longValue());
418            }
419    
420            public SocialRelation findByPrimaryKey(long relationId)
421                    throws NoSuchRelationException, SystemException {
422                    SocialRelation socialRelation = fetchByPrimaryKey(relationId);
423    
424                    if (socialRelation == null) {
425                            if (_log.isWarnEnabled()) {
426                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + relationId);
427                            }
428    
429                            throw new NoSuchRelationException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
430                                    relationId);
431                    }
432    
433                    return socialRelation;
434            }
435    
436            public SocialRelation fetchByPrimaryKey(Serializable primaryKey)
437                    throws SystemException {
438                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
439            }
440    
441            public SocialRelation fetchByPrimaryKey(long relationId)
442                    throws SystemException {
443                    SocialRelation socialRelation = (SocialRelation)EntityCacheUtil.getResult(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
444                                    SocialRelationImpl.class, relationId, this);
445    
446                    if (socialRelation == null) {
447                            Session session = null;
448    
449                            try {
450                                    session = openSession();
451    
452                                    socialRelation = (SocialRelation)session.get(SocialRelationImpl.class,
453                                                    new Long(relationId));
454                            }
455                            catch (Exception e) {
456                                    throw processException(e);
457                            }
458                            finally {
459                                    if (socialRelation != null) {
460                                            cacheResult(socialRelation);
461                                    }
462    
463                                    closeSession(session);
464                            }
465                    }
466    
467                    return socialRelation;
468            }
469    
470            public List<SocialRelation> findByUuid(String uuid)
471                    throws SystemException {
472                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
473            }
474    
475            public List<SocialRelation> findByUuid(String uuid, int start, int end)
476                    throws SystemException {
477                    return findByUuid(uuid, start, end, null);
478            }
479    
480            public List<SocialRelation> findByUuid(String uuid, int start, int end,
481                    OrderByComparator orderByComparator) throws SystemException {
482                    Object[] finderArgs = new Object[] {
483                                    uuid,
484                                    
485                                    String.valueOf(start), String.valueOf(end),
486                                    String.valueOf(orderByComparator)
487                            };
488    
489                    List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_UUID,
490                                    finderArgs, this);
491    
492                    if (list == null) {
493                            Session session = null;
494    
495                            try {
496                                    session = openSession();
497    
498                                    StringBundler query = null;
499    
500                                    if (orderByComparator != null) {
501                                            query = new StringBundler(3 +
502                                                            (orderByComparator.getOrderByFields().length * 3));
503                                    }
504                                    else {
505                                            query = new StringBundler(2);
506                                    }
507    
508                                    query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
509    
510                                    if (uuid == null) {
511                                            query.append(_FINDER_COLUMN_UUID_UUID_1);
512                                    }
513                                    else {
514                                            if (uuid.equals(StringPool.BLANK)) {
515                                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
516                                            }
517                                            else {
518                                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
519                                            }
520                                    }
521    
522                                    if (orderByComparator != null) {
523                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
524                                                    orderByComparator);
525                                    }
526    
527                                    String sql = query.toString();
528    
529                                    Query q = session.createQuery(sql);
530    
531                                    QueryPos qPos = QueryPos.getInstance(q);
532    
533                                    if (uuid != null) {
534                                            qPos.add(uuid);
535                                    }
536    
537                                    list = (List<SocialRelation>)QueryUtil.list(q, getDialect(),
538                                                    start, end);
539                            }
540                            catch (Exception e) {
541                                    throw processException(e);
542                            }
543                            finally {
544                                    if (list == null) {
545                                            list = new ArrayList<SocialRelation>();
546                                    }
547    
548                                    cacheResult(list);
549    
550                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_UUID, finderArgs,
551                                            list);
552    
553                                    closeSession(session);
554                            }
555                    }
556    
557                    return list;
558            }
559    
560            public SocialRelation findByUuid_First(String uuid,
561                    OrderByComparator orderByComparator)
562                    throws NoSuchRelationException, SystemException {
563                    List<SocialRelation> list = findByUuid(uuid, 0, 1, orderByComparator);
564    
565                    if (list.isEmpty()) {
566                            StringBundler msg = new StringBundler(4);
567    
568                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
569    
570                            msg.append("uuid=");
571                            msg.append(uuid);
572    
573                            msg.append(StringPool.CLOSE_CURLY_BRACE);
574    
575                            throw new NoSuchRelationException(msg.toString());
576                    }
577                    else {
578                            return list.get(0);
579                    }
580            }
581    
582            public SocialRelation findByUuid_Last(String uuid,
583                    OrderByComparator orderByComparator)
584                    throws NoSuchRelationException, SystemException {
585                    int count = countByUuid(uuid);
586    
587                    List<SocialRelation> list = findByUuid(uuid, count - 1, count,
588                                    orderByComparator);
589    
590                    if (list.isEmpty()) {
591                            StringBundler msg = new StringBundler(4);
592    
593                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
594    
595                            msg.append("uuid=");
596                            msg.append(uuid);
597    
598                            msg.append(StringPool.CLOSE_CURLY_BRACE);
599    
600                            throw new NoSuchRelationException(msg.toString());
601                    }
602                    else {
603                            return list.get(0);
604                    }
605            }
606    
607            public SocialRelation[] findByUuid_PrevAndNext(long relationId,
608                    String uuid, OrderByComparator orderByComparator)
609                    throws NoSuchRelationException, SystemException {
610                    SocialRelation socialRelation = findByPrimaryKey(relationId);
611    
612                    Session session = null;
613    
614                    try {
615                            session = openSession();
616    
617                            SocialRelation[] array = new SocialRelationImpl[3];
618    
619                            array[0] = getByUuid_PrevAndNext(session, socialRelation, uuid,
620                                            orderByComparator, true);
621    
622                            array[1] = socialRelation;
623    
624                            array[2] = getByUuid_PrevAndNext(session, socialRelation, uuid,
625                                            orderByComparator, false);
626    
627                            return array;
628                    }
629                    catch (Exception e) {
630                            throw processException(e);
631                    }
632                    finally {
633                            closeSession(session);
634                    }
635            }
636    
637            protected SocialRelation getByUuid_PrevAndNext(Session session,
638                    SocialRelation socialRelation, String uuid,
639                    OrderByComparator orderByComparator, boolean previous) {
640                    StringBundler query = null;
641    
642                    if (orderByComparator != null) {
643                            query = new StringBundler(6 +
644                                            (orderByComparator.getOrderByFields().length * 6));
645                    }
646                    else {
647                            query = new StringBundler(3);
648                    }
649    
650                    query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
651    
652                    if (uuid == null) {
653                            query.append(_FINDER_COLUMN_UUID_UUID_1);
654                    }
655                    else {
656                            if (uuid.equals(StringPool.BLANK)) {
657                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
658                            }
659                            else {
660                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
661                            }
662                    }
663    
664                    if (orderByComparator != null) {
665                            String[] orderByFields = orderByComparator.getOrderByFields();
666    
667                            if (orderByFields.length > 0) {
668                                    query.append(WHERE_AND);
669                            }
670    
671                            for (int i = 0; i < orderByFields.length; i++) {
672                                    query.append(_ORDER_BY_ENTITY_ALIAS);
673                                    query.append(orderByFields[i]);
674    
675                                    if ((i + 1) < orderByFields.length) {
676                                            if (orderByComparator.isAscending() ^ previous) {
677                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
678                                            }
679                                            else {
680                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
681                                            }
682                                    }
683                                    else {
684                                            if (orderByComparator.isAscending() ^ previous) {
685                                                    query.append(WHERE_GREATER_THAN);
686                                            }
687                                            else {
688                                                    query.append(WHERE_LESSER_THAN);
689                                            }
690                                    }
691                            }
692    
693                            query.append(ORDER_BY_CLAUSE);
694    
695                            for (int i = 0; i < orderByFields.length; i++) {
696                                    query.append(_ORDER_BY_ENTITY_ALIAS);
697                                    query.append(orderByFields[i]);
698    
699                                    if ((i + 1) < orderByFields.length) {
700                                            if (orderByComparator.isAscending() ^ previous) {
701                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
702                                            }
703                                            else {
704                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
705                                            }
706                                    }
707                                    else {
708                                            if (orderByComparator.isAscending() ^ previous) {
709                                                    query.append(ORDER_BY_ASC);
710                                            }
711                                            else {
712                                                    query.append(ORDER_BY_DESC);
713                                            }
714                                    }
715                            }
716                    }
717    
718                    String sql = query.toString();
719    
720                    Query q = session.createQuery(sql);
721    
722                    q.setFirstResult(0);
723                    q.setMaxResults(2);
724    
725                    QueryPos qPos = QueryPos.getInstance(q);
726    
727                    if (uuid != null) {
728                            qPos.add(uuid);
729                    }
730    
731                    if (orderByComparator != null) {
732                            Object[] values = orderByComparator.getOrderByValues(socialRelation);
733    
734                            for (Object value : values) {
735                                    qPos.add(value);
736                            }
737                    }
738    
739                    List<SocialRelation> list = q.list();
740    
741                    if (list.size() == 2) {
742                            return list.get(1);
743                    }
744                    else {
745                            return null;
746                    }
747            }
748    
749            public List<SocialRelation> findByCompanyId(long companyId)
750                    throws SystemException {
751                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
752                            null);
753            }
754    
755            public List<SocialRelation> findByCompanyId(long companyId, int start,
756                    int end) throws SystemException {
757                    return findByCompanyId(companyId, start, end, null);
758            }
759    
760            public List<SocialRelation> findByCompanyId(long companyId, int start,
761                    int end, OrderByComparator orderByComparator) throws SystemException {
762                    Object[] finderArgs = new Object[] {
763                                    companyId,
764                                    
765                                    String.valueOf(start), String.valueOf(end),
766                                    String.valueOf(orderByComparator)
767                            };
768    
769                    List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_COMPANYID,
770                                    finderArgs, this);
771    
772                    if (list == null) {
773                            Session session = null;
774    
775                            try {
776                                    session = openSession();
777    
778                                    StringBundler query = null;
779    
780                                    if (orderByComparator != null) {
781                                            query = new StringBundler(3 +
782                                                            (orderByComparator.getOrderByFields().length * 3));
783                                    }
784                                    else {
785                                            query = new StringBundler(2);
786                                    }
787    
788                                    query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
789    
790                                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
791    
792                                    if (orderByComparator != null) {
793                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
794                                                    orderByComparator);
795                                    }
796    
797                                    String sql = query.toString();
798    
799                                    Query q = session.createQuery(sql);
800    
801                                    QueryPos qPos = QueryPos.getInstance(q);
802    
803                                    qPos.add(companyId);
804    
805                                    list = (List<SocialRelation>)QueryUtil.list(q, getDialect(),
806                                                    start, end);
807                            }
808                            catch (Exception e) {
809                                    throw processException(e);
810                            }
811                            finally {
812                                    if (list == null) {
813                                            list = new ArrayList<SocialRelation>();
814                                    }
815    
816                                    cacheResult(list);
817    
818                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_COMPANYID,
819                                            finderArgs, list);
820    
821                                    closeSession(session);
822                            }
823                    }
824    
825                    return list;
826            }
827    
828            public SocialRelation findByCompanyId_First(long companyId,
829                    OrderByComparator orderByComparator)
830                    throws NoSuchRelationException, SystemException {
831                    List<SocialRelation> list = findByCompanyId(companyId, 0, 1,
832                                    orderByComparator);
833    
834                    if (list.isEmpty()) {
835                            StringBundler msg = new StringBundler(4);
836    
837                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
838    
839                            msg.append("companyId=");
840                            msg.append(companyId);
841    
842                            msg.append(StringPool.CLOSE_CURLY_BRACE);
843    
844                            throw new NoSuchRelationException(msg.toString());
845                    }
846                    else {
847                            return list.get(0);
848                    }
849            }
850    
851            public SocialRelation findByCompanyId_Last(long companyId,
852                    OrderByComparator orderByComparator)
853                    throws NoSuchRelationException, SystemException {
854                    int count = countByCompanyId(companyId);
855    
856                    List<SocialRelation> list = findByCompanyId(companyId, count - 1,
857                                    count, orderByComparator);
858    
859                    if (list.isEmpty()) {
860                            StringBundler msg = new StringBundler(4);
861    
862                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
863    
864                            msg.append("companyId=");
865                            msg.append(companyId);
866    
867                            msg.append(StringPool.CLOSE_CURLY_BRACE);
868    
869                            throw new NoSuchRelationException(msg.toString());
870                    }
871                    else {
872                            return list.get(0);
873                    }
874            }
875    
876            public SocialRelation[] findByCompanyId_PrevAndNext(long relationId,
877                    long companyId, OrderByComparator orderByComparator)
878                    throws NoSuchRelationException, SystemException {
879                    SocialRelation socialRelation = findByPrimaryKey(relationId);
880    
881                    Session session = null;
882    
883                    try {
884                            session = openSession();
885    
886                            SocialRelation[] array = new SocialRelationImpl[3];
887    
888                            array[0] = getByCompanyId_PrevAndNext(session, socialRelation,
889                                            companyId, orderByComparator, true);
890    
891                            array[1] = socialRelation;
892    
893                            array[2] = getByCompanyId_PrevAndNext(session, socialRelation,
894                                            companyId, orderByComparator, false);
895    
896                            return array;
897                    }
898                    catch (Exception e) {
899                            throw processException(e);
900                    }
901                    finally {
902                            closeSession(session);
903                    }
904            }
905    
906            protected SocialRelation getByCompanyId_PrevAndNext(Session session,
907                    SocialRelation socialRelation, long companyId,
908                    OrderByComparator orderByComparator, boolean previous) {
909                    StringBundler query = null;
910    
911                    if (orderByComparator != null) {
912                            query = new StringBundler(6 +
913                                            (orderByComparator.getOrderByFields().length * 6));
914                    }
915                    else {
916                            query = new StringBundler(3);
917                    }
918    
919                    query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
920    
921                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
922    
923                    if (orderByComparator != null) {
924                            String[] orderByFields = orderByComparator.getOrderByFields();
925    
926                            if (orderByFields.length > 0) {
927                                    query.append(WHERE_AND);
928                            }
929    
930                            for (int i = 0; i < orderByFields.length; i++) {
931                                    query.append(_ORDER_BY_ENTITY_ALIAS);
932                                    query.append(orderByFields[i]);
933    
934                                    if ((i + 1) < orderByFields.length) {
935                                            if (orderByComparator.isAscending() ^ previous) {
936                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
937                                            }
938                                            else {
939                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
940                                            }
941                                    }
942                                    else {
943                                            if (orderByComparator.isAscending() ^ previous) {
944                                                    query.append(WHERE_GREATER_THAN);
945                                            }
946                                            else {
947                                                    query.append(WHERE_LESSER_THAN);
948                                            }
949                                    }
950                            }
951    
952                            query.append(ORDER_BY_CLAUSE);
953    
954                            for (int i = 0; i < orderByFields.length; i++) {
955                                    query.append(_ORDER_BY_ENTITY_ALIAS);
956                                    query.append(orderByFields[i]);
957    
958                                    if ((i + 1) < orderByFields.length) {
959                                            if (orderByComparator.isAscending() ^ previous) {
960                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
961                                            }
962                                            else {
963                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
964                                            }
965                                    }
966                                    else {
967                                            if (orderByComparator.isAscending() ^ previous) {
968                                                    query.append(ORDER_BY_ASC);
969                                            }
970                                            else {
971                                                    query.append(ORDER_BY_DESC);
972                                            }
973                                    }
974                            }
975                    }
976    
977                    String sql = query.toString();
978    
979                    Query q = session.createQuery(sql);
980    
981                    q.setFirstResult(0);
982                    q.setMaxResults(2);
983    
984                    QueryPos qPos = QueryPos.getInstance(q);
985    
986                    qPos.add(companyId);
987    
988                    if (orderByComparator != null) {
989                            Object[] values = orderByComparator.getOrderByValues(socialRelation);
990    
991                            for (Object value : values) {
992                                    qPos.add(value);
993                            }
994                    }
995    
996                    List<SocialRelation> list = q.list();
997    
998                    if (list.size() == 2) {
999                            return list.get(1);
1000                    }
1001                    else {
1002                            return null;
1003                    }
1004            }
1005    
1006            public List<SocialRelation> findByUserId1(long userId1)
1007                    throws SystemException {
1008                    return findByUserId1(userId1, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1009            }
1010    
1011            public List<SocialRelation> findByUserId1(long userId1, int start, int end)
1012                    throws SystemException {
1013                    return findByUserId1(userId1, start, end, null);
1014            }
1015    
1016            public List<SocialRelation> findByUserId1(long userId1, int start, int end,
1017                    OrderByComparator orderByComparator) throws SystemException {
1018                    Object[] finderArgs = new Object[] {
1019                                    userId1,
1020                                    
1021                                    String.valueOf(start), String.valueOf(end),
1022                                    String.valueOf(orderByComparator)
1023                            };
1024    
1025                    List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_USERID1,
1026                                    finderArgs, this);
1027    
1028                    if (list == null) {
1029                            Session session = null;
1030    
1031                            try {
1032                                    session = openSession();
1033    
1034                                    StringBundler query = null;
1035    
1036                                    if (orderByComparator != null) {
1037                                            query = new StringBundler(3 +
1038                                                            (orderByComparator.getOrderByFields().length * 3));
1039                                    }
1040                                    else {
1041                                            query = new StringBundler(2);
1042                                    }
1043    
1044                                    query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
1045    
1046                                    query.append(_FINDER_COLUMN_USERID1_USERID1_2);
1047    
1048                                    if (orderByComparator != null) {
1049                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1050                                                    orderByComparator);
1051                                    }
1052    
1053                                    String sql = query.toString();
1054    
1055                                    Query q = session.createQuery(sql);
1056    
1057                                    QueryPos qPos = QueryPos.getInstance(q);
1058    
1059                                    qPos.add(userId1);
1060    
1061                                    list = (List<SocialRelation>)QueryUtil.list(q, getDialect(),
1062                                                    start, end);
1063                            }
1064                            catch (Exception e) {
1065                                    throw processException(e);
1066                            }
1067                            finally {
1068                                    if (list == null) {
1069                                            list = new ArrayList<SocialRelation>();
1070                                    }
1071    
1072                                    cacheResult(list);
1073    
1074                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_USERID1,
1075                                            finderArgs, list);
1076    
1077                                    closeSession(session);
1078                            }
1079                    }
1080    
1081                    return list;
1082            }
1083    
1084            public SocialRelation findByUserId1_First(long userId1,
1085                    OrderByComparator orderByComparator)
1086                    throws NoSuchRelationException, SystemException {
1087                    List<SocialRelation> list = findByUserId1(userId1, 0, 1,
1088                                    orderByComparator);
1089    
1090                    if (list.isEmpty()) {
1091                            StringBundler msg = new StringBundler(4);
1092    
1093                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1094    
1095                            msg.append("userId1=");
1096                            msg.append(userId1);
1097    
1098                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1099    
1100                            throw new NoSuchRelationException(msg.toString());
1101                    }
1102                    else {
1103                            return list.get(0);
1104                    }
1105            }
1106    
1107            public SocialRelation findByUserId1_Last(long userId1,
1108                    OrderByComparator orderByComparator)
1109                    throws NoSuchRelationException, SystemException {
1110                    int count = countByUserId1(userId1);
1111    
1112                    List<SocialRelation> list = findByUserId1(userId1, count - 1, count,
1113                                    orderByComparator);
1114    
1115                    if (list.isEmpty()) {
1116                            StringBundler msg = new StringBundler(4);
1117    
1118                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1119    
1120                            msg.append("userId1=");
1121                            msg.append(userId1);
1122    
1123                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1124    
1125                            throw new NoSuchRelationException(msg.toString());
1126                    }
1127                    else {
1128                            return list.get(0);
1129                    }
1130            }
1131    
1132            public SocialRelation[] findByUserId1_PrevAndNext(long relationId,
1133                    long userId1, OrderByComparator orderByComparator)
1134                    throws NoSuchRelationException, SystemException {
1135                    SocialRelation socialRelation = findByPrimaryKey(relationId);
1136    
1137                    Session session = null;
1138    
1139                    try {
1140                            session = openSession();
1141    
1142                            SocialRelation[] array = new SocialRelationImpl[3];
1143    
1144                            array[0] = getByUserId1_PrevAndNext(session, socialRelation,
1145                                            userId1, orderByComparator, true);
1146    
1147                            array[1] = socialRelation;
1148    
1149                            array[2] = getByUserId1_PrevAndNext(session, socialRelation,
1150                                            userId1, orderByComparator, false);
1151    
1152                            return array;
1153                    }
1154                    catch (Exception e) {
1155                            throw processException(e);
1156                    }
1157                    finally {
1158                            closeSession(session);
1159                    }
1160            }
1161    
1162            protected SocialRelation getByUserId1_PrevAndNext(Session session,
1163                    SocialRelation socialRelation, long userId1,
1164                    OrderByComparator orderByComparator, boolean previous) {
1165                    StringBundler query = null;
1166    
1167                    if (orderByComparator != null) {
1168                            query = new StringBundler(6 +
1169                                            (orderByComparator.getOrderByFields().length * 6));
1170                    }
1171                    else {
1172                            query = new StringBundler(3);
1173                    }
1174    
1175                    query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
1176    
1177                    query.append(_FINDER_COLUMN_USERID1_USERID1_2);
1178    
1179                    if (orderByComparator != null) {
1180                            String[] orderByFields = orderByComparator.getOrderByFields();
1181    
1182                            if (orderByFields.length > 0) {
1183                                    query.append(WHERE_AND);
1184                            }
1185    
1186                            for (int i = 0; i < orderByFields.length; i++) {
1187                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1188                                    query.append(orderByFields[i]);
1189    
1190                                    if ((i + 1) < orderByFields.length) {
1191                                            if (orderByComparator.isAscending() ^ previous) {
1192                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1193                                            }
1194                                            else {
1195                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1196                                            }
1197                                    }
1198                                    else {
1199                                            if (orderByComparator.isAscending() ^ previous) {
1200                                                    query.append(WHERE_GREATER_THAN);
1201                                            }
1202                                            else {
1203                                                    query.append(WHERE_LESSER_THAN);
1204                                            }
1205                                    }
1206                            }
1207    
1208                            query.append(ORDER_BY_CLAUSE);
1209    
1210                            for (int i = 0; i < orderByFields.length; i++) {
1211                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1212                                    query.append(orderByFields[i]);
1213    
1214                                    if ((i + 1) < orderByFields.length) {
1215                                            if (orderByComparator.isAscending() ^ previous) {
1216                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1217                                            }
1218                                            else {
1219                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1220                                            }
1221                                    }
1222                                    else {
1223                                            if (orderByComparator.isAscending() ^ previous) {
1224                                                    query.append(ORDER_BY_ASC);
1225                                            }
1226                                            else {
1227                                                    query.append(ORDER_BY_DESC);
1228                                            }
1229                                    }
1230                            }
1231                    }
1232    
1233                    String sql = query.toString();
1234    
1235                    Query q = session.createQuery(sql);
1236    
1237                    q.setFirstResult(0);
1238                    q.setMaxResults(2);
1239    
1240                    QueryPos qPos = QueryPos.getInstance(q);
1241    
1242                    qPos.add(userId1);
1243    
1244                    if (orderByComparator != null) {
1245                            Object[] values = orderByComparator.getOrderByValues(socialRelation);
1246    
1247                            for (Object value : values) {
1248                                    qPos.add(value);
1249                            }
1250                    }
1251    
1252                    List<SocialRelation> list = q.list();
1253    
1254                    if (list.size() == 2) {
1255                            return list.get(1);
1256                    }
1257                    else {
1258                            return null;
1259                    }
1260            }
1261    
1262            public List<SocialRelation> findByUserId2(long userId2)
1263                    throws SystemException {
1264                    return findByUserId2(userId2, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1265            }
1266    
1267            public List<SocialRelation> findByUserId2(long userId2, int start, int end)
1268                    throws SystemException {
1269                    return findByUserId2(userId2, start, end, null);
1270            }
1271    
1272            public List<SocialRelation> findByUserId2(long userId2, int start, int end,
1273                    OrderByComparator orderByComparator) throws SystemException {
1274                    Object[] finderArgs = new Object[] {
1275                                    userId2,
1276                                    
1277                                    String.valueOf(start), String.valueOf(end),
1278                                    String.valueOf(orderByComparator)
1279                            };
1280    
1281                    List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_USERID2,
1282                                    finderArgs, this);
1283    
1284                    if (list == null) {
1285                            Session session = null;
1286    
1287                            try {
1288                                    session = openSession();
1289    
1290                                    StringBundler query = null;
1291    
1292                                    if (orderByComparator != null) {
1293                                            query = new StringBundler(3 +
1294                                                            (orderByComparator.getOrderByFields().length * 3));
1295                                    }
1296                                    else {
1297                                            query = new StringBundler(2);
1298                                    }
1299    
1300                                    query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
1301    
1302                                    query.append(_FINDER_COLUMN_USERID2_USERID2_2);
1303    
1304                                    if (orderByComparator != null) {
1305                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1306                                                    orderByComparator);
1307                                    }
1308    
1309                                    String sql = query.toString();
1310    
1311                                    Query q = session.createQuery(sql);
1312    
1313                                    QueryPos qPos = QueryPos.getInstance(q);
1314    
1315                                    qPos.add(userId2);
1316    
1317                                    list = (List<SocialRelation>)QueryUtil.list(q, getDialect(),
1318                                                    start, end);
1319                            }
1320                            catch (Exception e) {
1321                                    throw processException(e);
1322                            }
1323                            finally {
1324                                    if (list == null) {
1325                                            list = new ArrayList<SocialRelation>();
1326                                    }
1327    
1328                                    cacheResult(list);
1329    
1330                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_USERID2,
1331                                            finderArgs, list);
1332    
1333                                    closeSession(session);
1334                            }
1335                    }
1336    
1337                    return list;
1338            }
1339    
1340            public SocialRelation findByUserId2_First(long userId2,
1341                    OrderByComparator orderByComparator)
1342                    throws NoSuchRelationException, SystemException {
1343                    List<SocialRelation> list = findByUserId2(userId2, 0, 1,
1344                                    orderByComparator);
1345    
1346                    if (list.isEmpty()) {
1347                            StringBundler msg = new StringBundler(4);
1348    
1349                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1350    
1351                            msg.append("userId2=");
1352                            msg.append(userId2);
1353    
1354                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1355    
1356                            throw new NoSuchRelationException(msg.toString());
1357                    }
1358                    else {
1359                            return list.get(0);
1360                    }
1361            }
1362    
1363            public SocialRelation findByUserId2_Last(long userId2,
1364                    OrderByComparator orderByComparator)
1365                    throws NoSuchRelationException, SystemException {
1366                    int count = countByUserId2(userId2);
1367    
1368                    List<SocialRelation> list = findByUserId2(userId2, count - 1, count,
1369                                    orderByComparator);
1370    
1371                    if (list.isEmpty()) {
1372                            StringBundler msg = new StringBundler(4);
1373    
1374                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1375    
1376                            msg.append("userId2=");
1377                            msg.append(userId2);
1378    
1379                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1380    
1381                            throw new NoSuchRelationException(msg.toString());
1382                    }
1383                    else {
1384                            return list.get(0);
1385                    }
1386            }
1387    
1388            public SocialRelation[] findByUserId2_PrevAndNext(long relationId,
1389                    long userId2, OrderByComparator orderByComparator)
1390                    throws NoSuchRelationException, SystemException {
1391                    SocialRelation socialRelation = findByPrimaryKey(relationId);
1392    
1393                    Session session = null;
1394    
1395                    try {
1396                            session = openSession();
1397    
1398                            SocialRelation[] array = new SocialRelationImpl[3];
1399    
1400                            array[0] = getByUserId2_PrevAndNext(session, socialRelation,
1401                                            userId2, orderByComparator, true);
1402    
1403                            array[1] = socialRelation;
1404    
1405                            array[2] = getByUserId2_PrevAndNext(session, socialRelation,
1406                                            userId2, orderByComparator, false);
1407    
1408                            return array;
1409                    }
1410                    catch (Exception e) {
1411                            throw processException(e);
1412                    }
1413                    finally {
1414                            closeSession(session);
1415                    }
1416            }
1417    
1418            protected SocialRelation getByUserId2_PrevAndNext(Session session,
1419                    SocialRelation socialRelation, long userId2,
1420                    OrderByComparator orderByComparator, boolean previous) {
1421                    StringBundler query = null;
1422    
1423                    if (orderByComparator != null) {
1424                            query = new StringBundler(6 +
1425                                            (orderByComparator.getOrderByFields().length * 6));
1426                    }
1427                    else {
1428                            query = new StringBundler(3);
1429                    }
1430    
1431                    query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
1432    
1433                    query.append(_FINDER_COLUMN_USERID2_USERID2_2);
1434    
1435                    if (orderByComparator != null) {
1436                            String[] orderByFields = orderByComparator.getOrderByFields();
1437    
1438                            if (orderByFields.length > 0) {
1439                                    query.append(WHERE_AND);
1440                            }
1441    
1442                            for (int i = 0; i < orderByFields.length; i++) {
1443                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1444                                    query.append(orderByFields[i]);
1445    
1446                                    if ((i + 1) < orderByFields.length) {
1447                                            if (orderByComparator.isAscending() ^ previous) {
1448                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1449                                            }
1450                                            else {
1451                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1452                                            }
1453                                    }
1454                                    else {
1455                                            if (orderByComparator.isAscending() ^ previous) {
1456                                                    query.append(WHERE_GREATER_THAN);
1457                                            }
1458                                            else {
1459                                                    query.append(WHERE_LESSER_THAN);
1460                                            }
1461                                    }
1462                            }
1463    
1464                            query.append(ORDER_BY_CLAUSE);
1465    
1466                            for (int i = 0; i < orderByFields.length; i++) {
1467                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1468                                    query.append(orderByFields[i]);
1469    
1470                                    if ((i + 1) < orderByFields.length) {
1471                                            if (orderByComparator.isAscending() ^ previous) {
1472                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1473                                            }
1474                                            else {
1475                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1476                                            }
1477                                    }
1478                                    else {
1479                                            if (orderByComparator.isAscending() ^ previous) {
1480                                                    query.append(ORDER_BY_ASC);
1481                                            }
1482                                            else {
1483                                                    query.append(ORDER_BY_DESC);
1484                                            }
1485                                    }
1486                            }
1487                    }
1488    
1489                    String sql = query.toString();
1490    
1491                    Query q = session.createQuery(sql);
1492    
1493                    q.setFirstResult(0);
1494                    q.setMaxResults(2);
1495    
1496                    QueryPos qPos = QueryPos.getInstance(q);
1497    
1498                    qPos.add(userId2);
1499    
1500                    if (orderByComparator != null) {
1501                            Object[] values = orderByComparator.getOrderByValues(socialRelation);
1502    
1503                            for (Object value : values) {
1504                                    qPos.add(value);
1505                            }
1506                    }
1507    
1508                    List<SocialRelation> list = q.list();
1509    
1510                    if (list.size() == 2) {
1511                            return list.get(1);
1512                    }
1513                    else {
1514                            return null;
1515                    }
1516            }
1517    
1518            public List<SocialRelation> findByType(int type) throws SystemException {
1519                    return findByType(type, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1520            }
1521    
1522            public List<SocialRelation> findByType(int type, int start, int end)
1523                    throws SystemException {
1524                    return findByType(type, start, end, null);
1525            }
1526    
1527            public List<SocialRelation> findByType(int type, int start, int end,
1528                    OrderByComparator orderByComparator) throws SystemException {
1529                    Object[] finderArgs = new Object[] {
1530                                    type,
1531                                    
1532                                    String.valueOf(start), String.valueOf(end),
1533                                    String.valueOf(orderByComparator)
1534                            };
1535    
1536                    List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_TYPE,
1537                                    finderArgs, this);
1538    
1539                    if (list == null) {
1540                            Session session = null;
1541    
1542                            try {
1543                                    session = openSession();
1544    
1545                                    StringBundler query = null;
1546    
1547                                    if (orderByComparator != null) {
1548                                            query = new StringBundler(3 +
1549                                                            (orderByComparator.getOrderByFields().length * 3));
1550                                    }
1551                                    else {
1552                                            query = new StringBundler(2);
1553                                    }
1554    
1555                                    query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
1556    
1557                                    query.append(_FINDER_COLUMN_TYPE_TYPE_2);
1558    
1559                                    if (orderByComparator != null) {
1560                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1561                                                    orderByComparator);
1562                                    }
1563    
1564                                    String sql = query.toString();
1565    
1566                                    Query q = session.createQuery(sql);
1567    
1568                                    QueryPos qPos = QueryPos.getInstance(q);
1569    
1570                                    qPos.add(type);
1571    
1572                                    list = (List<SocialRelation>)QueryUtil.list(q, getDialect(),
1573                                                    start, end);
1574                            }
1575                            catch (Exception e) {
1576                                    throw processException(e);
1577                            }
1578                            finally {
1579                                    if (list == null) {
1580                                            list = new ArrayList<SocialRelation>();
1581                                    }
1582    
1583                                    cacheResult(list);
1584    
1585                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_TYPE, finderArgs,
1586                                            list);
1587    
1588                                    closeSession(session);
1589                            }
1590                    }
1591    
1592                    return list;
1593            }
1594    
1595            public SocialRelation findByType_First(int type,
1596                    OrderByComparator orderByComparator)
1597                    throws NoSuchRelationException, SystemException {
1598                    List<SocialRelation> list = findByType(type, 0, 1, orderByComparator);
1599    
1600                    if (list.isEmpty()) {
1601                            StringBundler msg = new StringBundler(4);
1602    
1603                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1604    
1605                            msg.append("type=");
1606                            msg.append(type);
1607    
1608                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1609    
1610                            throw new NoSuchRelationException(msg.toString());
1611                    }
1612                    else {
1613                            return list.get(0);
1614                    }
1615            }
1616    
1617            public SocialRelation findByType_Last(int type,
1618                    OrderByComparator orderByComparator)
1619                    throws NoSuchRelationException, SystemException {
1620                    int count = countByType(type);
1621    
1622                    List<SocialRelation> list = findByType(type, count - 1, count,
1623                                    orderByComparator);
1624    
1625                    if (list.isEmpty()) {
1626                            StringBundler msg = new StringBundler(4);
1627    
1628                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1629    
1630                            msg.append("type=");
1631                            msg.append(type);
1632    
1633                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1634    
1635                            throw new NoSuchRelationException(msg.toString());
1636                    }
1637                    else {
1638                            return list.get(0);
1639                    }
1640            }
1641    
1642            public SocialRelation[] findByType_PrevAndNext(long relationId, int type,
1643                    OrderByComparator orderByComparator)
1644                    throws NoSuchRelationException, SystemException {
1645                    SocialRelation socialRelation = findByPrimaryKey(relationId);
1646    
1647                    Session session = null;
1648    
1649                    try {
1650                            session = openSession();
1651    
1652                            SocialRelation[] array = new SocialRelationImpl[3];
1653    
1654                            array[0] = getByType_PrevAndNext(session, socialRelation, type,
1655                                            orderByComparator, true);
1656    
1657                            array[1] = socialRelation;
1658    
1659                            array[2] = getByType_PrevAndNext(session, socialRelation, type,
1660                                            orderByComparator, false);
1661    
1662                            return array;
1663                    }
1664                    catch (Exception e) {
1665                            throw processException(e);
1666                    }
1667                    finally {
1668                            closeSession(session);
1669                    }
1670            }
1671    
1672            protected SocialRelation getByType_PrevAndNext(Session session,
1673                    SocialRelation socialRelation, int type,
1674                    OrderByComparator orderByComparator, boolean previous) {
1675                    StringBundler query = null;
1676    
1677                    if (orderByComparator != null) {
1678                            query = new StringBundler(6 +
1679                                            (orderByComparator.getOrderByFields().length * 6));
1680                    }
1681                    else {
1682                            query = new StringBundler(3);
1683                    }
1684    
1685                    query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
1686    
1687                    query.append(_FINDER_COLUMN_TYPE_TYPE_2);
1688    
1689                    if (orderByComparator != null) {
1690                            String[] orderByFields = orderByComparator.getOrderByFields();
1691    
1692                            if (orderByFields.length > 0) {
1693                                    query.append(WHERE_AND);
1694                            }
1695    
1696                            for (int i = 0; i < orderByFields.length; i++) {
1697                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1698                                    query.append(orderByFields[i]);
1699    
1700                                    if ((i + 1) < orderByFields.length) {
1701                                            if (orderByComparator.isAscending() ^ previous) {
1702                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1703                                            }
1704                                            else {
1705                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1706                                            }
1707                                    }
1708                                    else {
1709                                            if (orderByComparator.isAscending() ^ previous) {
1710                                                    query.append(WHERE_GREATER_THAN);
1711                                            }
1712                                            else {
1713                                                    query.append(WHERE_LESSER_THAN);
1714                                            }
1715                                    }
1716                            }
1717    
1718                            query.append(ORDER_BY_CLAUSE);
1719    
1720                            for (int i = 0; i < orderByFields.length; i++) {
1721                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1722                                    query.append(orderByFields[i]);
1723    
1724                                    if ((i + 1) < orderByFields.length) {
1725                                            if (orderByComparator.isAscending() ^ previous) {
1726                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1727                                            }
1728                                            else {
1729                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1730                                            }
1731                                    }
1732                                    else {
1733                                            if (orderByComparator.isAscending() ^ previous) {
1734                                                    query.append(ORDER_BY_ASC);
1735                                            }
1736                                            else {
1737                                                    query.append(ORDER_BY_DESC);
1738                                            }
1739                                    }
1740                            }
1741                    }
1742    
1743                    String sql = query.toString();
1744    
1745                    Query q = session.createQuery(sql);
1746    
1747                    q.setFirstResult(0);
1748                    q.setMaxResults(2);
1749    
1750                    QueryPos qPos = QueryPos.getInstance(q);
1751    
1752                    qPos.add(type);
1753    
1754                    if (orderByComparator != null) {
1755                            Object[] values = orderByComparator.getOrderByValues(socialRelation);
1756    
1757                            for (Object value : values) {
1758                                    qPos.add(value);
1759                            }
1760                    }
1761    
1762                    List<SocialRelation> list = q.list();
1763    
1764                    if (list.size() == 2) {
1765                            return list.get(1);
1766                    }
1767                    else {
1768                            return null;
1769                    }
1770            }
1771    
1772            public List<SocialRelation> findByC_T(long companyId, int type)
1773                    throws SystemException {
1774                    return findByC_T(companyId, type, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1775                            null);
1776            }
1777    
1778            public List<SocialRelation> findByC_T(long companyId, int type, int start,
1779                    int end) throws SystemException {
1780                    return findByC_T(companyId, type, start, end, null);
1781            }
1782    
1783            public List<SocialRelation> findByC_T(long companyId, int type, int start,
1784                    int end, OrderByComparator orderByComparator) throws SystemException {
1785                    Object[] finderArgs = new Object[] {
1786                                    companyId, type,
1787                                    
1788                                    String.valueOf(start), String.valueOf(end),
1789                                    String.valueOf(orderByComparator)
1790                            };
1791    
1792                    List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_T,
1793                                    finderArgs, this);
1794    
1795                    if (list == null) {
1796                            Session session = null;
1797    
1798                            try {
1799                                    session = openSession();
1800    
1801                                    StringBundler query = null;
1802    
1803                                    if (orderByComparator != null) {
1804                                            query = new StringBundler(4 +
1805                                                            (orderByComparator.getOrderByFields().length * 3));
1806                                    }
1807                                    else {
1808                                            query = new StringBundler(3);
1809                                    }
1810    
1811                                    query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
1812    
1813                                    query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
1814    
1815                                    query.append(_FINDER_COLUMN_C_T_TYPE_2);
1816    
1817                                    if (orderByComparator != null) {
1818                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1819                                                    orderByComparator);
1820                                    }
1821    
1822                                    String sql = query.toString();
1823    
1824                                    Query q = session.createQuery(sql);
1825    
1826                                    QueryPos qPos = QueryPos.getInstance(q);
1827    
1828                                    qPos.add(companyId);
1829    
1830                                    qPos.add(type);
1831    
1832                                    list = (List<SocialRelation>)QueryUtil.list(q, getDialect(),
1833                                                    start, end);
1834                            }
1835                            catch (Exception e) {
1836                                    throw processException(e);
1837                            }
1838                            finally {
1839                                    if (list == null) {
1840                                            list = new ArrayList<SocialRelation>();
1841                                    }
1842    
1843                                    cacheResult(list);
1844    
1845                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_T, finderArgs,
1846                                            list);
1847    
1848                                    closeSession(session);
1849                            }
1850                    }
1851    
1852                    return list;
1853            }
1854    
1855            public SocialRelation findByC_T_First(long companyId, int type,
1856                    OrderByComparator orderByComparator)
1857                    throws NoSuchRelationException, SystemException {
1858                    List<SocialRelation> list = findByC_T(companyId, type, 0, 1,
1859                                    orderByComparator);
1860    
1861                    if (list.isEmpty()) {
1862                            StringBundler msg = new StringBundler(6);
1863    
1864                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1865    
1866                            msg.append("companyId=");
1867                            msg.append(companyId);
1868    
1869                            msg.append(", type=");
1870                            msg.append(type);
1871    
1872                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1873    
1874                            throw new NoSuchRelationException(msg.toString());
1875                    }
1876                    else {
1877                            return list.get(0);
1878                    }
1879            }
1880    
1881            public SocialRelation findByC_T_Last(long companyId, int type,
1882                    OrderByComparator orderByComparator)
1883                    throws NoSuchRelationException, SystemException {
1884                    int count = countByC_T(companyId, type);
1885    
1886                    List<SocialRelation> list = findByC_T(companyId, type, count - 1,
1887                                    count, orderByComparator);
1888    
1889                    if (list.isEmpty()) {
1890                            StringBundler msg = new StringBundler(6);
1891    
1892                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1893    
1894                            msg.append("companyId=");
1895                            msg.append(companyId);
1896    
1897                            msg.append(", type=");
1898                            msg.append(type);
1899    
1900                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1901    
1902                            throw new NoSuchRelationException(msg.toString());
1903                    }
1904                    else {
1905                            return list.get(0);
1906                    }
1907            }
1908    
1909            public SocialRelation[] findByC_T_PrevAndNext(long relationId,
1910                    long companyId, int type, OrderByComparator orderByComparator)
1911                    throws NoSuchRelationException, SystemException {
1912                    SocialRelation socialRelation = findByPrimaryKey(relationId);
1913    
1914                    Session session = null;
1915    
1916                    try {
1917                            session = openSession();
1918    
1919                            SocialRelation[] array = new SocialRelationImpl[3];
1920    
1921                            array[0] = getByC_T_PrevAndNext(session, socialRelation, companyId,
1922                                            type, orderByComparator, true);
1923    
1924                            array[1] = socialRelation;
1925    
1926                            array[2] = getByC_T_PrevAndNext(session, socialRelation, companyId,
1927                                            type, orderByComparator, false);
1928    
1929                            return array;
1930                    }
1931                    catch (Exception e) {
1932                            throw processException(e);
1933                    }
1934                    finally {
1935                            closeSession(session);
1936                    }
1937            }
1938    
1939            protected SocialRelation getByC_T_PrevAndNext(Session session,
1940                    SocialRelation socialRelation, long companyId, int type,
1941                    OrderByComparator orderByComparator, boolean previous) {
1942                    StringBundler query = null;
1943    
1944                    if (orderByComparator != null) {
1945                            query = new StringBundler(6 +
1946                                            (orderByComparator.getOrderByFields().length * 6));
1947                    }
1948                    else {
1949                            query = new StringBundler(3);
1950                    }
1951    
1952                    query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
1953    
1954                    query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
1955    
1956                    query.append(_FINDER_COLUMN_C_T_TYPE_2);
1957    
1958                    if (orderByComparator != null) {
1959                            String[] orderByFields = orderByComparator.getOrderByFields();
1960    
1961                            if (orderByFields.length > 0) {
1962                                    query.append(WHERE_AND);
1963                            }
1964    
1965                            for (int i = 0; i < orderByFields.length; i++) {
1966                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1967                                    query.append(orderByFields[i]);
1968    
1969                                    if ((i + 1) < orderByFields.length) {
1970                                            if (orderByComparator.isAscending() ^ previous) {
1971                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1972                                            }
1973                                            else {
1974                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1975                                            }
1976                                    }
1977                                    else {
1978                                            if (orderByComparator.isAscending() ^ previous) {
1979                                                    query.append(WHERE_GREATER_THAN);
1980                                            }
1981                                            else {
1982                                                    query.append(WHERE_LESSER_THAN);
1983                                            }
1984                                    }
1985                            }
1986    
1987                            query.append(ORDER_BY_CLAUSE);
1988    
1989                            for (int i = 0; i < orderByFields.length; i++) {
1990                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1991                                    query.append(orderByFields[i]);
1992    
1993                                    if ((i + 1) < orderByFields.length) {
1994                                            if (orderByComparator.isAscending() ^ previous) {
1995                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1996                                            }
1997                                            else {
1998                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1999                                            }
2000                                    }
2001                                    else {
2002                                            if (orderByComparator.isAscending() ^ previous) {
2003                                                    query.append(ORDER_BY_ASC);
2004                                            }
2005                                            else {
2006                                                    query.append(ORDER_BY_DESC);
2007                                            }
2008                                    }
2009                            }
2010                    }
2011    
2012                    String sql = query.toString();
2013    
2014                    Query q = session.createQuery(sql);
2015    
2016                    q.setFirstResult(0);
2017                    q.setMaxResults(2);
2018    
2019                    QueryPos qPos = QueryPos.getInstance(q);
2020    
2021                    qPos.add(companyId);
2022    
2023                    qPos.add(type);
2024    
2025                    if (orderByComparator != null) {
2026                            Object[] values = orderByComparator.getOrderByValues(socialRelation);
2027    
2028                            for (Object value : values) {
2029                                    qPos.add(value);
2030                            }
2031                    }
2032    
2033                    List<SocialRelation> list = q.list();
2034    
2035                    if (list.size() == 2) {
2036                            return list.get(1);
2037                    }
2038                    else {
2039                            return null;
2040                    }
2041            }
2042    
2043            public List<SocialRelation> findByU1_T(long userId1, int type)
2044                    throws SystemException {
2045                    return findByU1_T(userId1, type, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2046                            null);
2047            }
2048    
2049            public List<SocialRelation> findByU1_T(long userId1, int type, int start,
2050                    int end) throws SystemException {
2051                    return findByU1_T(userId1, type, start, end, null);
2052            }
2053    
2054            public List<SocialRelation> findByU1_T(long userId1, int type, int start,
2055                    int end, OrderByComparator orderByComparator) throws SystemException {
2056                    Object[] finderArgs = new Object[] {
2057                                    userId1, type,
2058                                    
2059                                    String.valueOf(start), String.valueOf(end),
2060                                    String.valueOf(orderByComparator)
2061                            };
2062    
2063                    List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_U1_T,
2064                                    finderArgs, this);
2065    
2066                    if (list == null) {
2067                            Session session = null;
2068    
2069                            try {
2070                                    session = openSession();
2071    
2072                                    StringBundler query = null;
2073    
2074                                    if (orderByComparator != null) {
2075                                            query = new StringBundler(4 +
2076                                                            (orderByComparator.getOrderByFields().length * 3));
2077                                    }
2078                                    else {
2079                                            query = new StringBundler(3);
2080                                    }
2081    
2082                                    query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
2083    
2084                                    query.append(_FINDER_COLUMN_U1_T_USERID1_2);
2085    
2086                                    query.append(_FINDER_COLUMN_U1_T_TYPE_2);
2087    
2088                                    if (orderByComparator != null) {
2089                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2090                                                    orderByComparator);
2091                                    }
2092    
2093                                    String sql = query.toString();
2094    
2095                                    Query q = session.createQuery(sql);
2096    
2097                                    QueryPos qPos = QueryPos.getInstance(q);
2098    
2099                                    qPos.add(userId1);
2100    
2101                                    qPos.add(type);
2102    
2103                                    list = (List<SocialRelation>)QueryUtil.list(q, getDialect(),
2104                                                    start, end);
2105                            }
2106                            catch (Exception e) {
2107                                    throw processException(e);
2108                            }
2109                            finally {
2110                                    if (list == null) {
2111                                            list = new ArrayList<SocialRelation>();
2112                                    }
2113    
2114                                    cacheResult(list);
2115    
2116                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_U1_T, finderArgs,
2117                                            list);
2118    
2119                                    closeSession(session);
2120                            }
2121                    }
2122    
2123                    return list;
2124            }
2125    
2126            public SocialRelation findByU1_T_First(long userId1, int type,
2127                    OrderByComparator orderByComparator)
2128                    throws NoSuchRelationException, SystemException {
2129                    List<SocialRelation> list = findByU1_T(userId1, type, 0, 1,
2130                                    orderByComparator);
2131    
2132                    if (list.isEmpty()) {
2133                            StringBundler msg = new StringBundler(6);
2134    
2135                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2136    
2137                            msg.append("userId1=");
2138                            msg.append(userId1);
2139    
2140                            msg.append(", type=");
2141                            msg.append(type);
2142    
2143                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2144    
2145                            throw new NoSuchRelationException(msg.toString());
2146                    }
2147                    else {
2148                            return list.get(0);
2149                    }
2150            }
2151    
2152            public SocialRelation findByU1_T_Last(long userId1, int type,
2153                    OrderByComparator orderByComparator)
2154                    throws NoSuchRelationException, SystemException {
2155                    int count = countByU1_T(userId1, type);
2156    
2157                    List<SocialRelation> list = findByU1_T(userId1, type, count - 1, count,
2158                                    orderByComparator);
2159    
2160                    if (list.isEmpty()) {
2161                            StringBundler msg = new StringBundler(6);
2162    
2163                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2164    
2165                            msg.append("userId1=");
2166                            msg.append(userId1);
2167    
2168                            msg.append(", type=");
2169                            msg.append(type);
2170    
2171                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2172    
2173                            throw new NoSuchRelationException(msg.toString());
2174                    }
2175                    else {
2176                            return list.get(0);
2177                    }
2178            }
2179    
2180            public SocialRelation[] findByU1_T_PrevAndNext(long relationId,
2181                    long userId1, int type, OrderByComparator orderByComparator)
2182                    throws NoSuchRelationException, SystemException {
2183                    SocialRelation socialRelation = findByPrimaryKey(relationId);
2184    
2185                    Session session = null;
2186    
2187                    try {
2188                            session = openSession();
2189    
2190                            SocialRelation[] array = new SocialRelationImpl[3];
2191    
2192                            array[0] = getByU1_T_PrevAndNext(session, socialRelation, userId1,
2193                                            type, orderByComparator, true);
2194    
2195                            array[1] = socialRelation;
2196    
2197                            array[2] = getByU1_T_PrevAndNext(session, socialRelation, userId1,
2198                                            type, orderByComparator, false);
2199    
2200                            return array;
2201                    }
2202                    catch (Exception e) {
2203                            throw processException(e);
2204                    }
2205                    finally {
2206                            closeSession(session);
2207                    }
2208            }
2209    
2210            protected SocialRelation getByU1_T_PrevAndNext(Session session,
2211                    SocialRelation socialRelation, long userId1, int type,
2212                    OrderByComparator orderByComparator, boolean previous) {
2213                    StringBundler query = null;
2214    
2215                    if (orderByComparator != null) {
2216                            query = new StringBundler(6 +
2217                                            (orderByComparator.getOrderByFields().length * 6));
2218                    }
2219                    else {
2220                            query = new StringBundler(3);
2221                    }
2222    
2223                    query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
2224    
2225                    query.append(_FINDER_COLUMN_U1_T_USERID1_2);
2226    
2227                    query.append(_FINDER_COLUMN_U1_T_TYPE_2);
2228    
2229                    if (orderByComparator != null) {
2230                            String[] orderByFields = orderByComparator.getOrderByFields();
2231    
2232                            if (orderByFields.length > 0) {
2233                                    query.append(WHERE_AND);
2234                            }
2235    
2236                            for (int i = 0; i < orderByFields.length; i++) {
2237                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2238                                    query.append(orderByFields[i]);
2239    
2240                                    if ((i + 1) < orderByFields.length) {
2241                                            if (orderByComparator.isAscending() ^ previous) {
2242                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2243                                            }
2244                                            else {
2245                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2246                                            }
2247                                    }
2248                                    else {
2249                                            if (orderByComparator.isAscending() ^ previous) {
2250                                                    query.append(WHERE_GREATER_THAN);
2251                                            }
2252                                            else {
2253                                                    query.append(WHERE_LESSER_THAN);
2254                                            }
2255                                    }
2256                            }
2257    
2258                            query.append(ORDER_BY_CLAUSE);
2259    
2260                            for (int i = 0; i < orderByFields.length; i++) {
2261                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2262                                    query.append(orderByFields[i]);
2263    
2264                                    if ((i + 1) < orderByFields.length) {
2265                                            if (orderByComparator.isAscending() ^ previous) {
2266                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2267                                            }
2268                                            else {
2269                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2270                                            }
2271                                    }
2272                                    else {
2273                                            if (orderByComparator.isAscending() ^ previous) {
2274                                                    query.append(ORDER_BY_ASC);
2275                                            }
2276                                            else {
2277                                                    query.append(ORDER_BY_DESC);
2278                                            }
2279                                    }
2280                            }
2281                    }
2282    
2283                    String sql = query.toString();
2284    
2285                    Query q = session.createQuery(sql);
2286    
2287                    q.setFirstResult(0);
2288                    q.setMaxResults(2);
2289    
2290                    QueryPos qPos = QueryPos.getInstance(q);
2291    
2292                    qPos.add(userId1);
2293    
2294                    qPos.add(type);
2295    
2296                    if (orderByComparator != null) {
2297                            Object[] values = orderByComparator.getOrderByValues(socialRelation);
2298    
2299                            for (Object value : values) {
2300                                    qPos.add(value);
2301                            }
2302                    }
2303    
2304                    List<SocialRelation> list = q.list();
2305    
2306                    if (list.size() == 2) {
2307                            return list.get(1);
2308                    }
2309                    else {
2310                            return null;
2311                    }
2312            }
2313    
2314            public List<SocialRelation> findByU2_T(long userId2, int type)
2315                    throws SystemException {
2316                    return findByU2_T(userId2, type, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2317                            null);
2318            }
2319    
2320            public List<SocialRelation> findByU2_T(long userId2, int type, int start,
2321                    int end) throws SystemException {
2322                    return findByU2_T(userId2, type, start, end, null);
2323            }
2324    
2325            public List<SocialRelation> findByU2_T(long userId2, int type, int start,
2326                    int end, OrderByComparator orderByComparator) throws SystemException {
2327                    Object[] finderArgs = new Object[] {
2328                                    userId2, type,
2329                                    
2330                                    String.valueOf(start), String.valueOf(end),
2331                                    String.valueOf(orderByComparator)
2332                            };
2333    
2334                    List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_U2_T,
2335                                    finderArgs, this);
2336    
2337                    if (list == null) {
2338                            Session session = null;
2339    
2340                            try {
2341                                    session = openSession();
2342    
2343                                    StringBundler query = null;
2344    
2345                                    if (orderByComparator != null) {
2346                                            query = new StringBundler(4 +
2347                                                            (orderByComparator.getOrderByFields().length * 3));
2348                                    }
2349                                    else {
2350                                            query = new StringBundler(3);
2351                                    }
2352    
2353                                    query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
2354    
2355                                    query.append(_FINDER_COLUMN_U2_T_USERID2_2);
2356    
2357                                    query.append(_FINDER_COLUMN_U2_T_TYPE_2);
2358    
2359                                    if (orderByComparator != null) {
2360                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2361                                                    orderByComparator);
2362                                    }
2363    
2364                                    String sql = query.toString();
2365    
2366                                    Query q = session.createQuery(sql);
2367    
2368                                    QueryPos qPos = QueryPos.getInstance(q);
2369    
2370                                    qPos.add(userId2);
2371    
2372                                    qPos.add(type);
2373    
2374                                    list = (List<SocialRelation>)QueryUtil.list(q, getDialect(),
2375                                                    start, end);
2376                            }
2377                            catch (Exception e) {
2378                                    throw processException(e);
2379                            }
2380                            finally {
2381                                    if (list == null) {
2382                                            list = new ArrayList<SocialRelation>();
2383                                    }
2384    
2385                                    cacheResult(list);
2386    
2387                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_U2_T, finderArgs,
2388                                            list);
2389    
2390                                    closeSession(session);
2391                            }
2392                    }
2393    
2394                    return list;
2395            }
2396    
2397            public SocialRelation findByU2_T_First(long userId2, int type,
2398                    OrderByComparator orderByComparator)
2399                    throws NoSuchRelationException, SystemException {
2400                    List<SocialRelation> list = findByU2_T(userId2, type, 0, 1,
2401                                    orderByComparator);
2402    
2403                    if (list.isEmpty()) {
2404                            StringBundler msg = new StringBundler(6);
2405    
2406                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2407    
2408                            msg.append("userId2=");
2409                            msg.append(userId2);
2410    
2411                            msg.append(", type=");
2412                            msg.append(type);
2413    
2414                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2415    
2416                            throw new NoSuchRelationException(msg.toString());
2417                    }
2418                    else {
2419                            return list.get(0);
2420                    }
2421            }
2422    
2423            public SocialRelation findByU2_T_Last(long userId2, int type,
2424                    OrderByComparator orderByComparator)
2425                    throws NoSuchRelationException, SystemException {
2426                    int count = countByU2_T(userId2, type);
2427    
2428                    List<SocialRelation> list = findByU2_T(userId2, type, count - 1, count,
2429                                    orderByComparator);
2430    
2431                    if (list.isEmpty()) {
2432                            StringBundler msg = new StringBundler(6);
2433    
2434                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2435    
2436                            msg.append("userId2=");
2437                            msg.append(userId2);
2438    
2439                            msg.append(", type=");
2440                            msg.append(type);
2441    
2442                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2443    
2444                            throw new NoSuchRelationException(msg.toString());
2445                    }
2446                    else {
2447                            return list.get(0);
2448                    }
2449            }
2450    
2451            public SocialRelation[] findByU2_T_PrevAndNext(long relationId,
2452                    long userId2, int type, OrderByComparator orderByComparator)
2453                    throws NoSuchRelationException, SystemException {
2454                    SocialRelation socialRelation = findByPrimaryKey(relationId);
2455    
2456                    Session session = null;
2457    
2458                    try {
2459                            session = openSession();
2460    
2461                            SocialRelation[] array = new SocialRelationImpl[3];
2462    
2463                            array[0] = getByU2_T_PrevAndNext(session, socialRelation, userId2,
2464                                            type, orderByComparator, true);
2465    
2466                            array[1] = socialRelation;
2467    
2468                            array[2] = getByU2_T_PrevAndNext(session, socialRelation, userId2,
2469                                            type, orderByComparator, false);
2470    
2471                            return array;
2472                    }
2473                    catch (Exception e) {
2474                            throw processException(e);
2475                    }
2476                    finally {
2477                            closeSession(session);
2478                    }
2479            }
2480    
2481            protected SocialRelation getByU2_T_PrevAndNext(Session session,
2482                    SocialRelation socialRelation, long userId2, int type,
2483                    OrderByComparator orderByComparator, boolean previous) {
2484                    StringBundler query = null;
2485    
2486                    if (orderByComparator != null) {
2487                            query = new StringBundler(6 +
2488                                            (orderByComparator.getOrderByFields().length * 6));
2489                    }
2490                    else {
2491                            query = new StringBundler(3);
2492                    }
2493    
2494                    query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
2495    
2496                    query.append(_FINDER_COLUMN_U2_T_USERID2_2);
2497    
2498                    query.append(_FINDER_COLUMN_U2_T_TYPE_2);
2499    
2500                    if (orderByComparator != null) {
2501                            String[] orderByFields = orderByComparator.getOrderByFields();
2502    
2503                            if (orderByFields.length > 0) {
2504                                    query.append(WHERE_AND);
2505                            }
2506    
2507                            for (int i = 0; i < orderByFields.length; i++) {
2508                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2509                                    query.append(orderByFields[i]);
2510    
2511                                    if ((i + 1) < orderByFields.length) {
2512                                            if (orderByComparator.isAscending() ^ previous) {
2513                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2514                                            }
2515                                            else {
2516                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2517                                            }
2518                                    }
2519                                    else {
2520                                            if (orderByComparator.isAscending() ^ previous) {
2521                                                    query.append(WHERE_GREATER_THAN);
2522                                            }
2523                                            else {
2524                                                    query.append(WHERE_LESSER_THAN);
2525                                            }
2526                                    }
2527                            }
2528    
2529                            query.append(ORDER_BY_CLAUSE);
2530    
2531                            for (int i = 0; i < orderByFields.length; i++) {
2532                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2533                                    query.append(orderByFields[i]);
2534    
2535                                    if ((i + 1) < orderByFields.length) {
2536                                            if (orderByComparator.isAscending() ^ previous) {
2537                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2538                                            }
2539                                            else {
2540                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2541                                            }
2542                                    }
2543                                    else {
2544                                            if (orderByComparator.isAscending() ^ previous) {
2545                                                    query.append(ORDER_BY_ASC);
2546                                            }
2547                                            else {
2548                                                    query.append(ORDER_BY_DESC);
2549                                            }
2550                                    }
2551                            }
2552                    }
2553    
2554                    String sql = query.toString();
2555    
2556                    Query q = session.createQuery(sql);
2557    
2558                    q.setFirstResult(0);
2559                    q.setMaxResults(2);
2560    
2561                    QueryPos qPos = QueryPos.getInstance(q);
2562    
2563                    qPos.add(userId2);
2564    
2565                    qPos.add(type);
2566    
2567                    if (orderByComparator != null) {
2568                            Object[] values = orderByComparator.getOrderByValues(socialRelation);
2569    
2570                            for (Object value : values) {
2571                                    qPos.add(value);
2572                            }
2573                    }
2574    
2575                    List<SocialRelation> list = q.list();
2576    
2577                    if (list.size() == 2) {
2578                            return list.get(1);
2579                    }
2580                    else {
2581                            return null;
2582                    }
2583            }
2584    
2585            public SocialRelation findByU1_U2_T(long userId1, long userId2, int type)
2586                    throws NoSuchRelationException, SystemException {
2587                    SocialRelation socialRelation = fetchByU1_U2_T(userId1, userId2, type);
2588    
2589                    if (socialRelation == null) {
2590                            StringBundler msg = new StringBundler(8);
2591    
2592                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2593    
2594                            msg.append("userId1=");
2595                            msg.append(userId1);
2596    
2597                            msg.append(", userId2=");
2598                            msg.append(userId2);
2599    
2600                            msg.append(", type=");
2601                            msg.append(type);
2602    
2603                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2604    
2605                            if (_log.isWarnEnabled()) {
2606                                    _log.warn(msg.toString());
2607                            }
2608    
2609                            throw new NoSuchRelationException(msg.toString());
2610                    }
2611    
2612                    return socialRelation;
2613            }
2614    
2615            public SocialRelation fetchByU1_U2_T(long userId1, long userId2, int type)
2616                    throws SystemException {
2617                    return fetchByU1_U2_T(userId1, userId2, type, true);
2618            }
2619    
2620            public SocialRelation fetchByU1_U2_T(long userId1, long userId2, int type,
2621                    boolean retrieveFromCache) throws SystemException {
2622                    Object[] finderArgs = new Object[] { userId1, userId2, type };
2623    
2624                    Object result = null;
2625    
2626                    if (retrieveFromCache) {
2627                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_U1_U2_T,
2628                                            finderArgs, this);
2629                    }
2630    
2631                    if (result == null) {
2632                            Session session = null;
2633    
2634                            try {
2635                                    session = openSession();
2636    
2637                                    StringBundler query = new StringBundler(4);
2638    
2639                                    query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
2640    
2641                                    query.append(_FINDER_COLUMN_U1_U2_T_USERID1_2);
2642    
2643                                    query.append(_FINDER_COLUMN_U1_U2_T_USERID2_2);
2644    
2645                                    query.append(_FINDER_COLUMN_U1_U2_T_TYPE_2);
2646    
2647                                    String sql = query.toString();
2648    
2649                                    Query q = session.createQuery(sql);
2650    
2651                                    QueryPos qPos = QueryPos.getInstance(q);
2652    
2653                                    qPos.add(userId1);
2654    
2655                                    qPos.add(userId2);
2656    
2657                                    qPos.add(type);
2658    
2659                                    List<SocialRelation> list = q.list();
2660    
2661                                    result = list;
2662    
2663                                    SocialRelation socialRelation = null;
2664    
2665                                    if (list.isEmpty()) {
2666                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U1_U2_T,
2667                                                    finderArgs, list);
2668                                    }
2669                                    else {
2670                                            socialRelation = list.get(0);
2671    
2672                                            cacheResult(socialRelation);
2673    
2674                                            if ((socialRelation.getUserId1() != userId1) ||
2675                                                            (socialRelation.getUserId2() != userId2) ||
2676                                                            (socialRelation.getType() != type)) {
2677                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U1_U2_T,
2678                                                            finderArgs, socialRelation);
2679                                            }
2680                                    }
2681    
2682                                    return socialRelation;
2683                            }
2684                            catch (Exception e) {
2685                                    throw processException(e);
2686                            }
2687                            finally {
2688                                    if (result == null) {
2689                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U1_U2_T,
2690                                                    finderArgs, new ArrayList<SocialRelation>());
2691                                    }
2692    
2693                                    closeSession(session);
2694                            }
2695                    }
2696                    else {
2697                            if (result instanceof List<?>) {
2698                                    return null;
2699                            }
2700                            else {
2701                                    return (SocialRelation)result;
2702                            }
2703                    }
2704            }
2705    
2706            public List<SocialRelation> findAll() throws SystemException {
2707                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2708            }
2709    
2710            public List<SocialRelation> findAll(int start, int end)
2711                    throws SystemException {
2712                    return findAll(start, end, null);
2713            }
2714    
2715            public List<SocialRelation> findAll(int start, int end,
2716                    OrderByComparator orderByComparator) throws SystemException {
2717                    Object[] finderArgs = new Object[] {
2718                                    String.valueOf(start), String.valueOf(end),
2719                                    String.valueOf(orderByComparator)
2720                            };
2721    
2722                    List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
2723                                    finderArgs, this);
2724    
2725                    if (list == null) {
2726                            Session session = null;
2727    
2728                            try {
2729                                    session = openSession();
2730    
2731                                    StringBundler query = null;
2732                                    String sql = null;
2733    
2734                                    if (orderByComparator != null) {
2735                                            query = new StringBundler(2 +
2736                                                            (orderByComparator.getOrderByFields().length * 3));
2737    
2738                                            query.append(_SQL_SELECT_SOCIALRELATION);
2739    
2740                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2741                                                    orderByComparator);
2742    
2743                                            sql = query.toString();
2744                                    }
2745                                    else {
2746                                            sql = _SQL_SELECT_SOCIALRELATION;
2747                                    }
2748    
2749                                    Query q = session.createQuery(sql);
2750    
2751                                    if (orderByComparator == null) {
2752                                            list = (List<SocialRelation>)QueryUtil.list(q,
2753                                                            getDialect(), start, end, false);
2754    
2755                                            Collections.sort(list);
2756                                    }
2757                                    else {
2758                                            list = (List<SocialRelation>)QueryUtil.list(q,
2759                                                            getDialect(), start, end);
2760                                    }
2761                            }
2762                            catch (Exception e) {
2763                                    throw processException(e);
2764                            }
2765                            finally {
2766                                    if (list == null) {
2767                                            list = new ArrayList<SocialRelation>();
2768                                    }
2769    
2770                                    cacheResult(list);
2771    
2772                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
2773    
2774                                    closeSession(session);
2775                            }
2776                    }
2777    
2778                    return list;
2779            }
2780    
2781            public void removeByUuid(String uuid) throws SystemException {
2782                    for (SocialRelation socialRelation : findByUuid(uuid)) {
2783                            remove(socialRelation);
2784                    }
2785            }
2786    
2787            public void removeByCompanyId(long companyId) throws SystemException {
2788                    for (SocialRelation socialRelation : findByCompanyId(companyId)) {
2789                            remove(socialRelation);
2790                    }
2791            }
2792    
2793            public void removeByUserId1(long userId1) throws SystemException {
2794                    for (SocialRelation socialRelation : findByUserId1(userId1)) {
2795                            remove(socialRelation);
2796                    }
2797            }
2798    
2799            public void removeByUserId2(long userId2) throws SystemException {
2800                    for (SocialRelation socialRelation : findByUserId2(userId2)) {
2801                            remove(socialRelation);
2802                    }
2803            }
2804    
2805            public void removeByType(int type) throws SystemException {
2806                    for (SocialRelation socialRelation : findByType(type)) {
2807                            remove(socialRelation);
2808                    }
2809            }
2810    
2811            public void removeByC_T(long companyId, int type) throws SystemException {
2812                    for (SocialRelation socialRelation : findByC_T(companyId, type)) {
2813                            remove(socialRelation);
2814                    }
2815            }
2816    
2817            public void removeByU1_T(long userId1, int type) throws SystemException {
2818                    for (SocialRelation socialRelation : findByU1_T(userId1, type)) {
2819                            remove(socialRelation);
2820                    }
2821            }
2822    
2823            public void removeByU2_T(long userId2, int type) throws SystemException {
2824                    for (SocialRelation socialRelation : findByU2_T(userId2, type)) {
2825                            remove(socialRelation);
2826                    }
2827            }
2828    
2829            public void removeByU1_U2_T(long userId1, long userId2, int type)
2830                    throws NoSuchRelationException, SystemException {
2831                    SocialRelation socialRelation = findByU1_U2_T(userId1, userId2, type);
2832    
2833                    remove(socialRelation);
2834            }
2835    
2836            public void removeAll() throws SystemException {
2837                    for (SocialRelation socialRelation : findAll()) {
2838                            remove(socialRelation);
2839                    }
2840            }
2841    
2842            public int countByUuid(String uuid) throws SystemException {
2843                    Object[] finderArgs = new Object[] { uuid };
2844    
2845                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
2846                                    finderArgs, this);
2847    
2848                    if (count == null) {
2849                            Session session = null;
2850    
2851                            try {
2852                                    session = openSession();
2853    
2854                                    StringBundler query = new StringBundler(2);
2855    
2856                                    query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
2857    
2858                                    if (uuid == null) {
2859                                            query.append(_FINDER_COLUMN_UUID_UUID_1);
2860                                    }
2861                                    else {
2862                                            if (uuid.equals(StringPool.BLANK)) {
2863                                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
2864                                            }
2865                                            else {
2866                                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
2867                                            }
2868                                    }
2869    
2870                                    String sql = query.toString();
2871    
2872                                    Query q = session.createQuery(sql);
2873    
2874                                    QueryPos qPos = QueryPos.getInstance(q);
2875    
2876                                    if (uuid != null) {
2877                                            qPos.add(uuid);
2878                                    }
2879    
2880                                    count = (Long)q.uniqueResult();
2881                            }
2882                            catch (Exception e) {
2883                                    throw processException(e);
2884                            }
2885                            finally {
2886                                    if (count == null) {
2887                                            count = Long.valueOf(0);
2888                                    }
2889    
2890                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
2891                                            finderArgs, count);
2892    
2893                                    closeSession(session);
2894                            }
2895                    }
2896    
2897                    return count.intValue();
2898            }
2899    
2900            public int countByCompanyId(long companyId) throws SystemException {
2901                    Object[] finderArgs = new Object[] { companyId };
2902    
2903                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
2904                                    finderArgs, this);
2905    
2906                    if (count == null) {
2907                            Session session = null;
2908    
2909                            try {
2910                                    session = openSession();
2911    
2912                                    StringBundler query = new StringBundler(2);
2913    
2914                                    query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
2915    
2916                                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2917    
2918                                    String sql = query.toString();
2919    
2920                                    Query q = session.createQuery(sql);
2921    
2922                                    QueryPos qPos = QueryPos.getInstance(q);
2923    
2924                                    qPos.add(companyId);
2925    
2926                                    count = (Long)q.uniqueResult();
2927                            }
2928                            catch (Exception e) {
2929                                    throw processException(e);
2930                            }
2931                            finally {
2932                                    if (count == null) {
2933                                            count = Long.valueOf(0);
2934                                    }
2935    
2936                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
2937                                            finderArgs, count);
2938    
2939                                    closeSession(session);
2940                            }
2941                    }
2942    
2943                    return count.intValue();
2944            }
2945    
2946            public int countByUserId1(long userId1) throws SystemException {
2947                    Object[] finderArgs = new Object[] { userId1 };
2948    
2949                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID1,
2950                                    finderArgs, this);
2951    
2952                    if (count == null) {
2953                            Session session = null;
2954    
2955                            try {
2956                                    session = openSession();
2957    
2958                                    StringBundler query = new StringBundler(2);
2959    
2960                                    query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
2961    
2962                                    query.append(_FINDER_COLUMN_USERID1_USERID1_2);
2963    
2964                                    String sql = query.toString();
2965    
2966                                    Query q = session.createQuery(sql);
2967    
2968                                    QueryPos qPos = QueryPos.getInstance(q);
2969    
2970                                    qPos.add(userId1);
2971    
2972                                    count = (Long)q.uniqueResult();
2973                            }
2974                            catch (Exception e) {
2975                                    throw processException(e);
2976                            }
2977                            finally {
2978                                    if (count == null) {
2979                                            count = Long.valueOf(0);
2980                                    }
2981    
2982                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID1,
2983                                            finderArgs, count);
2984    
2985                                    closeSession(session);
2986                            }
2987                    }
2988    
2989                    return count.intValue();
2990            }
2991    
2992            public int countByUserId2(long userId2) throws SystemException {
2993                    Object[] finderArgs = new Object[] { userId2 };
2994    
2995                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID2,
2996                                    finderArgs, this);
2997    
2998                    if (count == null) {
2999                            Session session = null;
3000    
3001                            try {
3002                                    session = openSession();
3003    
3004                                    StringBundler query = new StringBundler(2);
3005    
3006                                    query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
3007    
3008                                    query.append(_FINDER_COLUMN_USERID2_USERID2_2);
3009    
3010                                    String sql = query.toString();
3011    
3012                                    Query q = session.createQuery(sql);
3013    
3014                                    QueryPos qPos = QueryPos.getInstance(q);
3015    
3016                                    qPos.add(userId2);
3017    
3018                                    count = (Long)q.uniqueResult();
3019                            }
3020                            catch (Exception e) {
3021                                    throw processException(e);
3022                            }
3023                            finally {
3024                                    if (count == null) {
3025                                            count = Long.valueOf(0);
3026                                    }
3027    
3028                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID2,
3029                                            finderArgs, count);
3030    
3031                                    closeSession(session);
3032                            }
3033                    }
3034    
3035                    return count.intValue();
3036            }
3037    
3038            public int countByType(int type) throws SystemException {
3039                    Object[] finderArgs = new Object[] { type };
3040    
3041                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_TYPE,
3042                                    finderArgs, this);
3043    
3044                    if (count == null) {
3045                            Session session = null;
3046    
3047                            try {
3048                                    session = openSession();
3049    
3050                                    StringBundler query = new StringBundler(2);
3051    
3052                                    query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
3053    
3054                                    query.append(_FINDER_COLUMN_TYPE_TYPE_2);
3055    
3056                                    String sql = query.toString();
3057    
3058                                    Query q = session.createQuery(sql);
3059    
3060                                    QueryPos qPos = QueryPos.getInstance(q);
3061    
3062                                    qPos.add(type);
3063    
3064                                    count = (Long)q.uniqueResult();
3065                            }
3066                            catch (Exception e) {
3067                                    throw processException(e);
3068                            }
3069                            finally {
3070                                    if (count == null) {
3071                                            count = Long.valueOf(0);
3072                                    }
3073    
3074                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_TYPE,
3075                                            finderArgs, count);
3076    
3077                                    closeSession(session);
3078                            }
3079                    }
3080    
3081                    return count.intValue();
3082            }
3083    
3084            public int countByC_T(long companyId, int type) throws SystemException {
3085                    Object[] finderArgs = new Object[] { companyId, type };
3086    
3087                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_T,
3088                                    finderArgs, this);
3089    
3090                    if (count == null) {
3091                            Session session = null;
3092    
3093                            try {
3094                                    session = openSession();
3095    
3096                                    StringBundler query = new StringBundler(3);
3097    
3098                                    query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
3099    
3100                                    query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
3101    
3102                                    query.append(_FINDER_COLUMN_C_T_TYPE_2);
3103    
3104                                    String sql = query.toString();
3105    
3106                                    Query q = session.createQuery(sql);
3107    
3108                                    QueryPos qPos = QueryPos.getInstance(q);
3109    
3110                                    qPos.add(companyId);
3111    
3112                                    qPos.add(type);
3113    
3114                                    count = (Long)q.uniqueResult();
3115                            }
3116                            catch (Exception e) {
3117                                    throw processException(e);
3118                            }
3119                            finally {
3120                                    if (count == null) {
3121                                            count = Long.valueOf(0);
3122                                    }
3123    
3124                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_T, finderArgs,
3125                                            count);
3126    
3127                                    closeSession(session);
3128                            }
3129                    }
3130    
3131                    return count.intValue();
3132            }
3133    
3134            public int countByU1_T(long userId1, int type) throws SystemException {
3135                    Object[] finderArgs = new Object[] { userId1, type };
3136    
3137                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U1_T,
3138                                    finderArgs, this);
3139    
3140                    if (count == null) {
3141                            Session session = null;
3142    
3143                            try {
3144                                    session = openSession();
3145    
3146                                    StringBundler query = new StringBundler(3);
3147    
3148                                    query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
3149    
3150                                    query.append(_FINDER_COLUMN_U1_T_USERID1_2);
3151    
3152                                    query.append(_FINDER_COLUMN_U1_T_TYPE_2);
3153    
3154                                    String sql = query.toString();
3155    
3156                                    Query q = session.createQuery(sql);
3157    
3158                                    QueryPos qPos = QueryPos.getInstance(q);
3159    
3160                                    qPos.add(userId1);
3161    
3162                                    qPos.add(type);
3163    
3164                                    count = (Long)q.uniqueResult();
3165                            }
3166                            catch (Exception e) {
3167                                    throw processException(e);
3168                            }
3169                            finally {
3170                                    if (count == null) {
3171                                            count = Long.valueOf(0);
3172                                    }
3173    
3174                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U1_T,
3175                                            finderArgs, count);
3176    
3177                                    closeSession(session);
3178                            }
3179                    }
3180    
3181                    return count.intValue();
3182            }
3183    
3184            public int countByU2_T(long userId2, int type) throws SystemException {
3185                    Object[] finderArgs = new Object[] { userId2, type };
3186    
3187                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U2_T,
3188                                    finderArgs, this);
3189    
3190                    if (count == null) {
3191                            Session session = null;
3192    
3193                            try {
3194                                    session = openSession();
3195    
3196                                    StringBundler query = new StringBundler(3);
3197    
3198                                    query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
3199    
3200                                    query.append(_FINDER_COLUMN_U2_T_USERID2_2);
3201    
3202                                    query.append(_FINDER_COLUMN_U2_T_TYPE_2);
3203    
3204                                    String sql = query.toString();
3205    
3206                                    Query q = session.createQuery(sql);
3207    
3208                                    QueryPos qPos = QueryPos.getInstance(q);
3209    
3210                                    qPos.add(userId2);
3211    
3212                                    qPos.add(type);
3213    
3214                                    count = (Long)q.uniqueResult();
3215                            }
3216                            catch (Exception e) {
3217                                    throw processException(e);
3218                            }
3219                            finally {
3220                                    if (count == null) {
3221                                            count = Long.valueOf(0);
3222                                    }
3223    
3224                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U2_T,
3225                                            finderArgs, count);
3226    
3227                                    closeSession(session);
3228                            }
3229                    }
3230    
3231                    return count.intValue();
3232            }
3233    
3234            public int countByU1_U2_T(long userId1, long userId2, int type)
3235                    throws SystemException {
3236                    Object[] finderArgs = new Object[] { userId1, userId2, type };
3237    
3238                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U1_U2_T,
3239                                    finderArgs, this);
3240    
3241                    if (count == null) {
3242                            Session session = null;
3243    
3244                            try {
3245                                    session = openSession();
3246    
3247                                    StringBundler query = new StringBundler(4);
3248    
3249                                    query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
3250    
3251                                    query.append(_FINDER_COLUMN_U1_U2_T_USERID1_2);
3252    
3253                                    query.append(_FINDER_COLUMN_U1_U2_T_USERID2_2);
3254    
3255                                    query.append(_FINDER_COLUMN_U1_U2_T_TYPE_2);
3256    
3257                                    String sql = query.toString();
3258    
3259                                    Query q = session.createQuery(sql);
3260    
3261                                    QueryPos qPos = QueryPos.getInstance(q);
3262    
3263                                    qPos.add(userId1);
3264    
3265                                    qPos.add(userId2);
3266    
3267                                    qPos.add(type);
3268    
3269                                    count = (Long)q.uniqueResult();
3270                            }
3271                            catch (Exception e) {
3272                                    throw processException(e);
3273                            }
3274                            finally {
3275                                    if (count == null) {
3276                                            count = Long.valueOf(0);
3277                                    }
3278    
3279                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U1_U2_T,
3280                                            finderArgs, count);
3281    
3282                                    closeSession(session);
3283                            }
3284                    }
3285    
3286                    return count.intValue();
3287            }
3288    
3289            public int countAll() throws SystemException {
3290                    Object[] finderArgs = new Object[0];
3291    
3292                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
3293                                    finderArgs, this);
3294    
3295                    if (count == null) {
3296                            Session session = null;
3297    
3298                            try {
3299                                    session = openSession();
3300    
3301                                    Query q = session.createQuery(_SQL_COUNT_SOCIALRELATION);
3302    
3303                                    count = (Long)q.uniqueResult();
3304                            }
3305                            catch (Exception e) {
3306                                    throw processException(e);
3307                            }
3308                            finally {
3309                                    if (count == null) {
3310                                            count = Long.valueOf(0);
3311                                    }
3312    
3313                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
3314                                            count);
3315    
3316                                    closeSession(session);
3317                            }
3318                    }
3319    
3320                    return count.intValue();
3321            }
3322    
3323            public void afterPropertiesSet() {
3324                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
3325                                            com.liferay.portal.util.PropsUtil.get(
3326                                                    "value.object.listener.com.liferay.portlet.social.model.SocialRelation")));
3327    
3328                    if (listenerClassNames.length > 0) {
3329                            try {
3330                                    List<ModelListener<SocialRelation>> listenersList = new ArrayList<ModelListener<SocialRelation>>();
3331    
3332                                    for (String listenerClassName : listenerClassNames) {
3333                                            listenersList.add((ModelListener<SocialRelation>)InstanceFactory.newInstance(
3334                                                            listenerClassName));
3335                                    }
3336    
3337                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
3338                            }
3339                            catch (Exception e) {
3340                                    _log.error(e);
3341                            }
3342                    }
3343            }
3344    
3345            @BeanReference(type = SocialActivityPersistence.class)
3346            protected SocialActivityPersistence socialActivityPersistence;
3347            @BeanReference(type = SocialEquityAssetEntryPersistence.class)
3348            protected SocialEquityAssetEntryPersistence socialEquityAssetEntryPersistence;
3349            @BeanReference(type = SocialEquityHistoryPersistence.class)
3350            protected SocialEquityHistoryPersistence socialEquityHistoryPersistence;
3351            @BeanReference(type = SocialEquityLogPersistence.class)
3352            protected SocialEquityLogPersistence socialEquityLogPersistence;
3353            @BeanReference(type = SocialEquitySettingPersistence.class)
3354            protected SocialEquitySettingPersistence socialEquitySettingPersistence;
3355            @BeanReference(type = SocialEquityUserPersistence.class)
3356            protected SocialEquityUserPersistence socialEquityUserPersistence;
3357            @BeanReference(type = SocialRelationPersistence.class)
3358            protected SocialRelationPersistence socialRelationPersistence;
3359            @BeanReference(type = SocialRequestPersistence.class)
3360            protected SocialRequestPersistence socialRequestPersistence;
3361            @BeanReference(type = ResourcePersistence.class)
3362            protected ResourcePersistence resourcePersistence;
3363            @BeanReference(type = UserPersistence.class)
3364            protected UserPersistence userPersistence;
3365            private static final String _SQL_SELECT_SOCIALRELATION = "SELECT socialRelation FROM SocialRelation socialRelation";
3366            private static final String _SQL_SELECT_SOCIALRELATION_WHERE = "SELECT socialRelation FROM SocialRelation socialRelation WHERE ";
3367            private static final String _SQL_COUNT_SOCIALRELATION = "SELECT COUNT(socialRelation) FROM SocialRelation socialRelation";
3368            private static final String _SQL_COUNT_SOCIALRELATION_WHERE = "SELECT COUNT(socialRelation) FROM SocialRelation socialRelation WHERE ";
3369            private static final String _FINDER_COLUMN_UUID_UUID_1 = "socialRelation.uuid IS NULL";
3370            private static final String _FINDER_COLUMN_UUID_UUID_2 = "socialRelation.uuid = ?";
3371            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(socialRelation.uuid IS NULL OR socialRelation.uuid = ?)";
3372            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "socialRelation.companyId = ?";
3373            private static final String _FINDER_COLUMN_USERID1_USERID1_2 = "socialRelation.userId1 = ?";
3374            private static final String _FINDER_COLUMN_USERID2_USERID2_2 = "socialRelation.userId2 = ?";
3375            private static final String _FINDER_COLUMN_TYPE_TYPE_2 = "socialRelation.type = ?";
3376            private static final String _FINDER_COLUMN_C_T_COMPANYID_2 = "socialRelation.companyId = ? AND ";
3377            private static final String _FINDER_COLUMN_C_T_TYPE_2 = "socialRelation.type = ?";
3378            private static final String _FINDER_COLUMN_U1_T_USERID1_2 = "socialRelation.userId1 = ? AND ";
3379            private static final String _FINDER_COLUMN_U1_T_TYPE_2 = "socialRelation.type = ?";
3380            private static final String _FINDER_COLUMN_U2_T_USERID2_2 = "socialRelation.userId2 = ? AND ";
3381            private static final String _FINDER_COLUMN_U2_T_TYPE_2 = "socialRelation.type = ?";
3382            private static final String _FINDER_COLUMN_U1_U2_T_USERID1_2 = "socialRelation.userId1 = ? AND ";
3383            private static final String _FINDER_COLUMN_U1_U2_T_USERID2_2 = "socialRelation.userId2 = ? AND ";
3384            private static final String _FINDER_COLUMN_U1_U2_T_TYPE_2 = "socialRelation.type = ?";
3385            private static final String _ORDER_BY_ENTITY_ALIAS = "socialRelation.";
3386            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No SocialRelation exists with the primary key ";
3387            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No SocialRelation exists with the key {";
3388            private static Log _log = LogFactoryUtil.getLog(SocialRelationPersistenceImpl.class);
3389    }