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     * The persistence implementation for the social relation service.
057     *
058     * <p>
059     * Never modify or reference this class directly. Always use {@link SocialRelationUtil} to access the social relation persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
060     * </p>
061     *
062     * <p>
063     * Caching information and settings can be found in <code>portal.properties</code>
064     * </p>
065     *
066     * @author Brian Wing Shun Chan
067     * @see SocialRelationPersistence
068     * @see SocialRelationUtil
069     * @generated
070     */
071    public class SocialRelationPersistenceImpl extends BasePersistenceImpl<SocialRelation>
072            implements SocialRelationPersistence {
073            public static final String FINDER_CLASS_NAME_ENTITY = SocialRelationImpl.class.getName();
074            public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
075                    ".List";
076            public static final FinderPath FINDER_PATH_FIND_BY_UUID = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
077                            SocialRelationModelImpl.FINDER_CACHE_ENABLED,
078                            FINDER_CLASS_NAME_LIST, "findByUuid",
079                            new String[] {
080                                    String.class.getName(),
081                                    
082                            "java.lang.Integer", "java.lang.Integer",
083                                    "com.liferay.portal.kernel.util.OrderByComparator"
084                            });
085            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
086                            SocialRelationModelImpl.FINDER_CACHE_ENABLED,
087                            FINDER_CLASS_NAME_LIST, "countByUuid",
088                            new String[] { String.class.getName() });
089            public static final FinderPath FINDER_PATH_FIND_BY_COMPANYID = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
090                            SocialRelationModelImpl.FINDER_CACHE_ENABLED,
091                            FINDER_CLASS_NAME_LIST, "findByCompanyId",
092                            new String[] {
093                                    Long.class.getName(),
094                                    
095                            "java.lang.Integer", "java.lang.Integer",
096                                    "com.liferay.portal.kernel.util.OrderByComparator"
097                            });
098            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
099                            SocialRelationModelImpl.FINDER_CACHE_ENABLED,
100                            FINDER_CLASS_NAME_LIST, "countByCompanyId",
101                            new String[] { Long.class.getName() });
102            public static final FinderPath FINDER_PATH_FIND_BY_USERID1 = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
103                            SocialRelationModelImpl.FINDER_CACHE_ENABLED,
104                            FINDER_CLASS_NAME_LIST, "findByUserId1",
105                            new String[] {
106                                    Long.class.getName(),
107                                    
108                            "java.lang.Integer", "java.lang.Integer",
109                                    "com.liferay.portal.kernel.util.OrderByComparator"
110                            });
111            public static final FinderPath FINDER_PATH_COUNT_BY_USERID1 = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
112                            SocialRelationModelImpl.FINDER_CACHE_ENABLED,
113                            FINDER_CLASS_NAME_LIST, "countByUserId1",
114                            new String[] { Long.class.getName() });
115            public static final FinderPath FINDER_PATH_FIND_BY_USERID2 = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
116                            SocialRelationModelImpl.FINDER_CACHE_ENABLED,
117                            FINDER_CLASS_NAME_LIST, "findByUserId2",
118                            new String[] {
119                                    Long.class.getName(),
120                                    
121                            "java.lang.Integer", "java.lang.Integer",
122                                    "com.liferay.portal.kernel.util.OrderByComparator"
123                            });
124            public static final FinderPath FINDER_PATH_COUNT_BY_USERID2 = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
125                            SocialRelationModelImpl.FINDER_CACHE_ENABLED,
126                            FINDER_CLASS_NAME_LIST, "countByUserId2",
127                            new String[] { Long.class.getName() });
128            public static final FinderPath FINDER_PATH_FIND_BY_TYPE = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
129                            SocialRelationModelImpl.FINDER_CACHE_ENABLED,
130                            FINDER_CLASS_NAME_LIST, "findByType",
131                            new String[] {
132                                    Integer.class.getName(),
133                                    
134                            "java.lang.Integer", "java.lang.Integer",
135                                    "com.liferay.portal.kernel.util.OrderByComparator"
136                            });
137            public static final FinderPath FINDER_PATH_COUNT_BY_TYPE = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
138                            SocialRelationModelImpl.FINDER_CACHE_ENABLED,
139                            FINDER_CLASS_NAME_LIST, "countByType",
140                            new String[] { Integer.class.getName() });
141            public static final FinderPath FINDER_PATH_FIND_BY_C_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
142                            SocialRelationModelImpl.FINDER_CACHE_ENABLED,
143                            FINDER_CLASS_NAME_LIST, "findByC_T",
144                            new String[] {
145                                    Long.class.getName(), Integer.class.getName(),
146                                    
147                            "java.lang.Integer", "java.lang.Integer",
148                                    "com.liferay.portal.kernel.util.OrderByComparator"
149                            });
150            public static final FinderPath FINDER_PATH_COUNT_BY_C_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
151                            SocialRelationModelImpl.FINDER_CACHE_ENABLED,
152                            FINDER_CLASS_NAME_LIST, "countByC_T",
153                            new String[] { Long.class.getName(), Integer.class.getName() });
154            public static final FinderPath FINDER_PATH_FIND_BY_U1_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
155                            SocialRelationModelImpl.FINDER_CACHE_ENABLED,
156                            FINDER_CLASS_NAME_LIST, "findByU1_T",
157                            new String[] {
158                                    Long.class.getName(), Integer.class.getName(),
159                                    
160                            "java.lang.Integer", "java.lang.Integer",
161                                    "com.liferay.portal.kernel.util.OrderByComparator"
162                            });
163            public static final FinderPath FINDER_PATH_COUNT_BY_U1_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
164                            SocialRelationModelImpl.FINDER_CACHE_ENABLED,
165                            FINDER_CLASS_NAME_LIST, "countByU1_T",
166                            new String[] { Long.class.getName(), Integer.class.getName() });
167            public static final FinderPath FINDER_PATH_FIND_BY_U2_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
168                            SocialRelationModelImpl.FINDER_CACHE_ENABLED,
169                            FINDER_CLASS_NAME_LIST, "findByU2_T",
170                            new String[] {
171                                    Long.class.getName(), Integer.class.getName(),
172                                    
173                            "java.lang.Integer", "java.lang.Integer",
174                                    "com.liferay.portal.kernel.util.OrderByComparator"
175                            });
176            public static final FinderPath FINDER_PATH_COUNT_BY_U2_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
177                            SocialRelationModelImpl.FINDER_CACHE_ENABLED,
178                            FINDER_CLASS_NAME_LIST, "countByU2_T",
179                            new String[] { Long.class.getName(), Integer.class.getName() });
180            public static final FinderPath FINDER_PATH_FETCH_BY_U1_U2_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
181                            SocialRelationModelImpl.FINDER_CACHE_ENABLED,
182                            FINDER_CLASS_NAME_ENTITY, "fetchByU1_U2_T",
183                            new String[] {
184                                    Long.class.getName(), Long.class.getName(),
185                                    Integer.class.getName()
186                            });
187            public static final FinderPath FINDER_PATH_COUNT_BY_U1_U2_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
188                            SocialRelationModelImpl.FINDER_CACHE_ENABLED,
189                            FINDER_CLASS_NAME_LIST, "countByU1_U2_T",
190                            new String[] {
191                                    Long.class.getName(), Long.class.getName(),
192                                    Integer.class.getName()
193                            });
194            public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
195                            SocialRelationModelImpl.FINDER_CACHE_ENABLED,
196                            FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
197            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
198                            SocialRelationModelImpl.FINDER_CACHE_ENABLED,
199                            FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
200    
201            /**
202             * Caches the social relation in the entity cache if it is enabled.
203             *
204             * @param socialRelation the social relation to cache
205             */
206            public void cacheResult(SocialRelation socialRelation) {
207                    EntityCacheUtil.putResult(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
208                            SocialRelationImpl.class, socialRelation.getPrimaryKey(),
209                            socialRelation);
210    
211                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U1_U2_T,
212                            new Object[] {
213                                    new Long(socialRelation.getUserId1()),
214                                    new Long(socialRelation.getUserId2()),
215                                    new Integer(socialRelation.getType())
216                            }, socialRelation);
217            }
218    
219            /**
220             * Caches the social relations in the entity cache if it is enabled.
221             *
222             * @param socialRelations the social relations to cache
223             */
224            public void cacheResult(List<SocialRelation> socialRelations) {
225                    for (SocialRelation socialRelation : socialRelations) {
226                            if (EntityCacheUtil.getResult(
227                                                    SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
228                                                    SocialRelationImpl.class,
229                                                    socialRelation.getPrimaryKey(), this) == null) {
230                                    cacheResult(socialRelation);
231                            }
232                    }
233            }
234    
235            /**
236             * Clears the cache for all social relations.
237             *
238             * <p>
239             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
240             * </p>
241             */
242            public void clearCache() {
243                    CacheRegistryUtil.clear(SocialRelationImpl.class.getName());
244                    EntityCacheUtil.clearCache(SocialRelationImpl.class.getName());
245                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
246                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
247            }
248    
249            /**
250             * Clears the cache for the social relation.
251             *
252             * <p>
253             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
254             * </p>
255             */
256            public void clearCache(SocialRelation socialRelation) {
257                    EntityCacheUtil.removeResult(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
258                            SocialRelationImpl.class, socialRelation.getPrimaryKey());
259    
260                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U1_U2_T,
261                            new Object[] {
262                                    new Long(socialRelation.getUserId1()),
263                                    new Long(socialRelation.getUserId2()),
264                                    new Integer(socialRelation.getType())
265                            });
266            }
267    
268            /**
269             * Creates a new social relation with the primary key. Does not add the social relation to the database.
270             *
271             * @param relationId the primary key for the new social relation
272             * @return the new social relation
273             */
274            public SocialRelation create(long relationId) {
275                    SocialRelation socialRelation = new SocialRelationImpl();
276    
277                    socialRelation.setNew(true);
278                    socialRelation.setPrimaryKey(relationId);
279    
280                    String uuid = PortalUUIDUtil.generate();
281    
282                    socialRelation.setUuid(uuid);
283    
284                    return socialRelation;
285            }
286    
287            /**
288             * Removes the social relation with the primary key from the database. Also notifies the appropriate model listeners.
289             *
290             * @param primaryKey the primary key of the social relation to remove
291             * @return the social relation that was removed
292             * @throws com.liferay.portal.NoSuchModelException if a social relation with the primary key could not be found
293             * @throws SystemException if a system exception occurred
294             */
295            public SocialRelation remove(Serializable primaryKey)
296                    throws NoSuchModelException, SystemException {
297                    return remove(((Long)primaryKey).longValue());
298            }
299    
300            /**
301             * Removes the social relation with the primary key from the database. Also notifies the appropriate model listeners.
302             *
303             * @param relationId the primary key of the social relation to remove
304             * @return the social relation that was removed
305             * @throws com.liferay.portlet.social.NoSuchRelationException if a social relation with the primary key could not be found
306             * @throws SystemException if a system exception occurred
307             */
308            public SocialRelation remove(long relationId)
309                    throws NoSuchRelationException, SystemException {
310                    Session session = null;
311    
312                    try {
313                            session = openSession();
314    
315                            SocialRelation socialRelation = (SocialRelation)session.get(SocialRelationImpl.class,
316                                            new Long(relationId));
317    
318                            if (socialRelation == null) {
319                                    if (_log.isWarnEnabled()) {
320                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + relationId);
321                                    }
322    
323                                    throw new NoSuchRelationException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
324                                            relationId);
325                            }
326    
327                            return remove(socialRelation);
328                    }
329                    catch (NoSuchRelationException nsee) {
330                            throw nsee;
331                    }
332                    catch (Exception e) {
333                            throw processException(e);
334                    }
335                    finally {
336                            closeSession(session);
337                    }
338            }
339    
340            protected SocialRelation removeImpl(SocialRelation socialRelation)
341                    throws SystemException {
342                    socialRelation = toUnwrappedModel(socialRelation);
343    
344                    Session session = null;
345    
346                    try {
347                            session = openSession();
348    
349                            if (socialRelation.isCachedModel() || BatchSessionUtil.isEnabled()) {
350                                    Object staleObject = session.get(SocialRelationImpl.class,
351                                                    socialRelation.getPrimaryKeyObj());
352    
353                                    if (staleObject != null) {
354                                            session.evict(staleObject);
355                                    }
356                            }
357    
358                            session.delete(socialRelation);
359    
360                            session.flush();
361                    }
362                    catch (Exception e) {
363                            throw processException(e);
364                    }
365                    finally {
366                            closeSession(session);
367                    }
368    
369                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
370    
371                    SocialRelationModelImpl socialRelationModelImpl = (SocialRelationModelImpl)socialRelation;
372    
373                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U1_U2_T,
374                            new Object[] {
375                                    new Long(socialRelationModelImpl.getOriginalUserId1()),
376                                    new Long(socialRelationModelImpl.getOriginalUserId2()),
377                                    new Integer(socialRelationModelImpl.getOriginalType())
378                            });
379    
380                    EntityCacheUtil.removeResult(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
381                            SocialRelationImpl.class, socialRelation.getPrimaryKey());
382    
383                    return socialRelation;
384            }
385    
386            public SocialRelation updateImpl(
387                    com.liferay.portlet.social.model.SocialRelation socialRelation,
388                    boolean merge) throws SystemException {
389                    socialRelation = toUnwrappedModel(socialRelation);
390    
391                    boolean isNew = socialRelation.isNew();
392    
393                    SocialRelationModelImpl socialRelationModelImpl = (SocialRelationModelImpl)socialRelation;
394    
395                    if (Validator.isNull(socialRelation.getUuid())) {
396                            String uuid = PortalUUIDUtil.generate();
397    
398                            socialRelation.setUuid(uuid);
399                    }
400    
401                    Session session = null;
402    
403                    try {
404                            session = openSession();
405    
406                            BatchSessionUtil.update(session, socialRelation, merge);
407    
408                            socialRelation.setNew(false);
409                    }
410                    catch (Exception e) {
411                            throw processException(e);
412                    }
413                    finally {
414                            closeSession(session);
415                    }
416    
417                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
418    
419                    EntityCacheUtil.putResult(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
420                            SocialRelationImpl.class, socialRelation.getPrimaryKey(),
421                            socialRelation);
422    
423                    if (!isNew &&
424                                    ((socialRelation.getUserId1() != socialRelationModelImpl.getOriginalUserId1()) ||
425                                    (socialRelation.getUserId2() != socialRelationModelImpl.getOriginalUserId2()) ||
426                                    (socialRelation.getType() != socialRelationModelImpl.getOriginalType()))) {
427                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U1_U2_T,
428                                    new Object[] {
429                                            new Long(socialRelationModelImpl.getOriginalUserId1()),
430                                            new Long(socialRelationModelImpl.getOriginalUserId2()),
431                                            new Integer(socialRelationModelImpl.getOriginalType())
432                                    });
433                    }
434    
435                    if (isNew ||
436                                    ((socialRelation.getUserId1() != socialRelationModelImpl.getOriginalUserId1()) ||
437                                    (socialRelation.getUserId2() != socialRelationModelImpl.getOriginalUserId2()) ||
438                                    (socialRelation.getType() != socialRelationModelImpl.getOriginalType()))) {
439                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U1_U2_T,
440                                    new Object[] {
441                                            new Long(socialRelation.getUserId1()),
442                                            new Long(socialRelation.getUserId2()),
443                                            new Integer(socialRelation.getType())
444                                    }, socialRelation);
445                    }
446    
447                    return socialRelation;
448            }
449    
450            protected SocialRelation toUnwrappedModel(SocialRelation socialRelation) {
451                    if (socialRelation instanceof SocialRelationImpl) {
452                            return socialRelation;
453                    }
454    
455                    SocialRelationImpl socialRelationImpl = new SocialRelationImpl();
456    
457                    socialRelationImpl.setNew(socialRelation.isNew());
458                    socialRelationImpl.setPrimaryKey(socialRelation.getPrimaryKey());
459    
460                    socialRelationImpl.setUuid(socialRelation.getUuid());
461                    socialRelationImpl.setRelationId(socialRelation.getRelationId());
462                    socialRelationImpl.setCompanyId(socialRelation.getCompanyId());
463                    socialRelationImpl.setCreateDate(socialRelation.getCreateDate());
464                    socialRelationImpl.setUserId1(socialRelation.getUserId1());
465                    socialRelationImpl.setUserId2(socialRelation.getUserId2());
466                    socialRelationImpl.setType(socialRelation.getType());
467    
468                    return socialRelationImpl;
469            }
470    
471            /**
472             * Finds the social relation with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
473             *
474             * @param primaryKey the primary key of the social relation to find
475             * @return the social relation
476             * @throws com.liferay.portal.NoSuchModelException if a social relation with the primary key could not be found
477             * @throws SystemException if a system exception occurred
478             */
479            public SocialRelation findByPrimaryKey(Serializable primaryKey)
480                    throws NoSuchModelException, SystemException {
481                    return findByPrimaryKey(((Long)primaryKey).longValue());
482            }
483    
484            /**
485             * Finds the social relation with the primary key or throws a {@link com.liferay.portlet.social.NoSuchRelationException} if it could not be found.
486             *
487             * @param relationId the primary key of the social relation to find
488             * @return the social relation
489             * @throws com.liferay.portlet.social.NoSuchRelationException if a social relation with the primary key could not be found
490             * @throws SystemException if a system exception occurred
491             */
492            public SocialRelation findByPrimaryKey(long relationId)
493                    throws NoSuchRelationException, SystemException {
494                    SocialRelation socialRelation = fetchByPrimaryKey(relationId);
495    
496                    if (socialRelation == null) {
497                            if (_log.isWarnEnabled()) {
498                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + relationId);
499                            }
500    
501                            throw new NoSuchRelationException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
502                                    relationId);
503                    }
504    
505                    return socialRelation;
506            }
507    
508            /**
509             * Finds the social relation with the primary key or returns <code>null</code> if it could not be found.
510             *
511             * @param primaryKey the primary key of the social relation to find
512             * @return the social relation, or <code>null</code> if a social relation with the primary key could not be found
513             * @throws SystemException if a system exception occurred
514             */
515            public SocialRelation fetchByPrimaryKey(Serializable primaryKey)
516                    throws SystemException {
517                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
518            }
519    
520            /**
521             * Finds the social relation with the primary key or returns <code>null</code> if it could not be found.
522             *
523             * @param relationId the primary key of the social relation to find
524             * @return the social relation, or <code>null</code> if a social relation with the primary key could not be found
525             * @throws SystemException if a system exception occurred
526             */
527            public SocialRelation fetchByPrimaryKey(long relationId)
528                    throws SystemException {
529                    SocialRelation socialRelation = (SocialRelation)EntityCacheUtil.getResult(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
530                                    SocialRelationImpl.class, relationId, this);
531    
532                    if (socialRelation == null) {
533                            Session session = null;
534    
535                            try {
536                                    session = openSession();
537    
538                                    socialRelation = (SocialRelation)session.get(SocialRelationImpl.class,
539                                                    new Long(relationId));
540                            }
541                            catch (Exception e) {
542                                    throw processException(e);
543                            }
544                            finally {
545                                    if (socialRelation != null) {
546                                            cacheResult(socialRelation);
547                                    }
548    
549                                    closeSession(session);
550                            }
551                    }
552    
553                    return socialRelation;
554            }
555    
556            /**
557             * Finds all the social relations where uuid = &#63;.
558             *
559             * @param uuid the uuid to search with
560             * @return the matching social relations
561             * @throws SystemException if a system exception occurred
562             */
563            public List<SocialRelation> findByUuid(String uuid)
564                    throws SystemException {
565                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
566            }
567    
568            /**
569             * Finds a range of all the social relations where uuid = &#63;.
570             *
571             * <p>
572             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
573             * </p>
574             *
575             * @param uuid the uuid to search with
576             * @param start the lower bound of the range of social relations to return
577             * @param end the upper bound of the range of social relations to return (not inclusive)
578             * @return the range of matching social relations
579             * @throws SystemException if a system exception occurred
580             */
581            public List<SocialRelation> findByUuid(String uuid, int start, int end)
582                    throws SystemException {
583                    return findByUuid(uuid, start, end, null);
584            }
585    
586            /**
587             * Finds an ordered range of all the social relations where uuid = &#63;.
588             *
589             * <p>
590             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
591             * </p>
592             *
593             * @param uuid the uuid to search with
594             * @param start the lower bound of the range of social relations to return
595             * @param end the upper bound of the range of social relations to return (not inclusive)
596             * @param orderByComparator the comparator to order the results by
597             * @return the ordered range of matching social relations
598             * @throws SystemException if a system exception occurred
599             */
600            public List<SocialRelation> findByUuid(String uuid, int start, int end,
601                    OrderByComparator orderByComparator) throws SystemException {
602                    Object[] finderArgs = new Object[] {
603                                    uuid,
604                                    
605                                    String.valueOf(start), String.valueOf(end),
606                                    String.valueOf(orderByComparator)
607                            };
608    
609                    List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_UUID,
610                                    finderArgs, this);
611    
612                    if (list == null) {
613                            Session session = null;
614    
615                            try {
616                                    session = openSession();
617    
618                                    StringBundler query = null;
619    
620                                    if (orderByComparator != null) {
621                                            query = new StringBundler(3 +
622                                                            (orderByComparator.getOrderByFields().length * 3));
623                                    }
624                                    else {
625                                            query = new StringBundler(2);
626                                    }
627    
628                                    query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
629    
630                                    if (uuid == null) {
631                                            query.append(_FINDER_COLUMN_UUID_UUID_1);
632                                    }
633                                    else {
634                                            if (uuid.equals(StringPool.BLANK)) {
635                                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
636                                            }
637                                            else {
638                                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
639                                            }
640                                    }
641    
642                                    if (orderByComparator != null) {
643                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
644                                                    orderByComparator);
645                                    }
646    
647                                    String sql = query.toString();
648    
649                                    Query q = session.createQuery(sql);
650    
651                                    QueryPos qPos = QueryPos.getInstance(q);
652    
653                                    if (uuid != null) {
654                                            qPos.add(uuid);
655                                    }
656    
657                                    list = (List<SocialRelation>)QueryUtil.list(q, getDialect(),
658                                                    start, end);
659                            }
660                            catch (Exception e) {
661                                    throw processException(e);
662                            }
663                            finally {
664                                    if (list == null) {
665                                            list = new ArrayList<SocialRelation>();
666                                    }
667    
668                                    cacheResult(list);
669    
670                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_UUID, finderArgs,
671                                            list);
672    
673                                    closeSession(session);
674                            }
675                    }
676    
677                    return list;
678            }
679    
680            /**
681             * Finds the first social relation in the ordered set where uuid = &#63;.
682             *
683             * <p>
684             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
685             * </p>
686             *
687             * @param uuid the uuid to search with
688             * @param orderByComparator the comparator to order the set by
689             * @return the first matching social relation
690             * @throws com.liferay.portlet.social.NoSuchRelationException if a matching social relation could not be found
691             * @throws SystemException if a system exception occurred
692             */
693            public SocialRelation findByUuid_First(String uuid,
694                    OrderByComparator orderByComparator)
695                    throws NoSuchRelationException, SystemException {
696                    List<SocialRelation> list = findByUuid(uuid, 0, 1, orderByComparator);
697    
698                    if (list.isEmpty()) {
699                            StringBundler msg = new StringBundler(4);
700    
701                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
702    
703                            msg.append("uuid=");
704                            msg.append(uuid);
705    
706                            msg.append(StringPool.CLOSE_CURLY_BRACE);
707    
708                            throw new NoSuchRelationException(msg.toString());
709                    }
710                    else {
711                            return list.get(0);
712                    }
713            }
714    
715            /**
716             * Finds the last social relation in the ordered set where uuid = &#63;.
717             *
718             * <p>
719             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
720             * </p>
721             *
722             * @param uuid the uuid to search with
723             * @param orderByComparator the comparator to order the set by
724             * @return the last matching social relation
725             * @throws com.liferay.portlet.social.NoSuchRelationException if a matching social relation could not be found
726             * @throws SystemException if a system exception occurred
727             */
728            public SocialRelation findByUuid_Last(String uuid,
729                    OrderByComparator orderByComparator)
730                    throws NoSuchRelationException, SystemException {
731                    int count = countByUuid(uuid);
732    
733                    List<SocialRelation> list = findByUuid(uuid, count - 1, count,
734                                    orderByComparator);
735    
736                    if (list.isEmpty()) {
737                            StringBundler msg = new StringBundler(4);
738    
739                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
740    
741                            msg.append("uuid=");
742                            msg.append(uuid);
743    
744                            msg.append(StringPool.CLOSE_CURLY_BRACE);
745    
746                            throw new NoSuchRelationException(msg.toString());
747                    }
748                    else {
749                            return list.get(0);
750                    }
751            }
752    
753            /**
754             * Finds the social relations before and after the current social relation in the ordered set where uuid = &#63;.
755             *
756             * <p>
757             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
758             * </p>
759             *
760             * @param relationId the primary key of the current social relation
761             * @param uuid the uuid to search with
762             * @param orderByComparator the comparator to order the set by
763             * @return the previous, current, and next social relation
764             * @throws com.liferay.portlet.social.NoSuchRelationException if a social relation with the primary key could not be found
765             * @throws SystemException if a system exception occurred
766             */
767            public SocialRelation[] findByUuid_PrevAndNext(long relationId,
768                    String uuid, OrderByComparator orderByComparator)
769                    throws NoSuchRelationException, SystemException {
770                    SocialRelation socialRelation = findByPrimaryKey(relationId);
771    
772                    Session session = null;
773    
774                    try {
775                            session = openSession();
776    
777                            SocialRelation[] array = new SocialRelationImpl[3];
778    
779                            array[0] = getByUuid_PrevAndNext(session, socialRelation, uuid,
780                                            orderByComparator, true);
781    
782                            array[1] = socialRelation;
783    
784                            array[2] = getByUuid_PrevAndNext(session, socialRelation, uuid,
785                                            orderByComparator, false);
786    
787                            return array;
788                    }
789                    catch (Exception e) {
790                            throw processException(e);
791                    }
792                    finally {
793                            closeSession(session);
794                    }
795            }
796    
797            protected SocialRelation getByUuid_PrevAndNext(Session session,
798                    SocialRelation socialRelation, String uuid,
799                    OrderByComparator orderByComparator, boolean previous) {
800                    StringBundler query = null;
801    
802                    if (orderByComparator != null) {
803                            query = new StringBundler(6 +
804                                            (orderByComparator.getOrderByFields().length * 6));
805                    }
806                    else {
807                            query = new StringBundler(3);
808                    }
809    
810                    query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
811    
812                    if (uuid == null) {
813                            query.append(_FINDER_COLUMN_UUID_UUID_1);
814                    }
815                    else {
816                            if (uuid.equals(StringPool.BLANK)) {
817                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
818                            }
819                            else {
820                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
821                            }
822                    }
823    
824                    if (orderByComparator != null) {
825                            String[] orderByFields = orderByComparator.getOrderByFields();
826    
827                            if (orderByFields.length > 0) {
828                                    query.append(WHERE_AND);
829                            }
830    
831                            for (int i = 0; i < orderByFields.length; i++) {
832                                    query.append(_ORDER_BY_ENTITY_ALIAS);
833                                    query.append(orderByFields[i]);
834    
835                                    if ((i + 1) < orderByFields.length) {
836                                            if (orderByComparator.isAscending() ^ previous) {
837                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
838                                            }
839                                            else {
840                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
841                                            }
842                                    }
843                                    else {
844                                            if (orderByComparator.isAscending() ^ previous) {
845                                                    query.append(WHERE_GREATER_THAN);
846                                            }
847                                            else {
848                                                    query.append(WHERE_LESSER_THAN);
849                                            }
850                                    }
851                            }
852    
853                            query.append(ORDER_BY_CLAUSE);
854    
855                            for (int i = 0; i < orderByFields.length; i++) {
856                                    query.append(_ORDER_BY_ENTITY_ALIAS);
857                                    query.append(orderByFields[i]);
858    
859                                    if ((i + 1) < orderByFields.length) {
860                                            if (orderByComparator.isAscending() ^ previous) {
861                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
862                                            }
863                                            else {
864                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
865                                            }
866                                    }
867                                    else {
868                                            if (orderByComparator.isAscending() ^ previous) {
869                                                    query.append(ORDER_BY_ASC);
870                                            }
871                                            else {
872                                                    query.append(ORDER_BY_DESC);
873                                            }
874                                    }
875                            }
876                    }
877    
878                    String sql = query.toString();
879    
880                    Query q = session.createQuery(sql);
881    
882                    q.setFirstResult(0);
883                    q.setMaxResults(2);
884    
885                    QueryPos qPos = QueryPos.getInstance(q);
886    
887                    if (uuid != null) {
888                            qPos.add(uuid);
889                    }
890    
891                    if (orderByComparator != null) {
892                            Object[] values = orderByComparator.getOrderByValues(socialRelation);
893    
894                            for (Object value : values) {
895                                    qPos.add(value);
896                            }
897                    }
898    
899                    List<SocialRelation> list = q.list();
900    
901                    if (list.size() == 2) {
902                            return list.get(1);
903                    }
904                    else {
905                            return null;
906                    }
907            }
908    
909            /**
910             * Finds all the social relations where companyId = &#63;.
911             *
912             * @param companyId the company id to search with
913             * @return the matching social relations
914             * @throws SystemException if a system exception occurred
915             */
916            public List<SocialRelation> findByCompanyId(long companyId)
917                    throws SystemException {
918                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
919                            null);
920            }
921    
922            /**
923             * Finds a range of all the social relations where companyId = &#63;.
924             *
925             * <p>
926             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
927             * </p>
928             *
929             * @param companyId the company id to search with
930             * @param start the lower bound of the range of social relations to return
931             * @param end the upper bound of the range of social relations to return (not inclusive)
932             * @return the range of matching social relations
933             * @throws SystemException if a system exception occurred
934             */
935            public List<SocialRelation> findByCompanyId(long companyId, int start,
936                    int end) throws SystemException {
937                    return findByCompanyId(companyId, start, end, null);
938            }
939    
940            /**
941             * Finds an ordered range of all the social relations where companyId = &#63;.
942             *
943             * <p>
944             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
945             * </p>
946             *
947             * @param companyId the company id to search with
948             * @param start the lower bound of the range of social relations to return
949             * @param end the upper bound of the range of social relations to return (not inclusive)
950             * @param orderByComparator the comparator to order the results by
951             * @return the ordered range of matching social relations
952             * @throws SystemException if a system exception occurred
953             */
954            public List<SocialRelation> findByCompanyId(long companyId, int start,
955                    int end, OrderByComparator orderByComparator) throws SystemException {
956                    Object[] finderArgs = new Object[] {
957                                    companyId,
958                                    
959                                    String.valueOf(start), String.valueOf(end),
960                                    String.valueOf(orderByComparator)
961                            };
962    
963                    List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_COMPANYID,
964                                    finderArgs, this);
965    
966                    if (list == null) {
967                            Session session = null;
968    
969                            try {
970                                    session = openSession();
971    
972                                    StringBundler query = null;
973    
974                                    if (orderByComparator != null) {
975                                            query = new StringBundler(3 +
976                                                            (orderByComparator.getOrderByFields().length * 3));
977                                    }
978                                    else {
979                                            query = new StringBundler(2);
980                                    }
981    
982                                    query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
983    
984                                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
985    
986                                    if (orderByComparator != null) {
987                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
988                                                    orderByComparator);
989                                    }
990    
991                                    String sql = query.toString();
992    
993                                    Query q = session.createQuery(sql);
994    
995                                    QueryPos qPos = QueryPos.getInstance(q);
996    
997                                    qPos.add(companyId);
998    
999                                    list = (List<SocialRelation>)QueryUtil.list(q, getDialect(),
1000                                                    start, end);
1001                            }
1002                            catch (Exception e) {
1003                                    throw processException(e);
1004                            }
1005                            finally {
1006                                    if (list == null) {
1007                                            list = new ArrayList<SocialRelation>();
1008                                    }
1009    
1010                                    cacheResult(list);
1011    
1012                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_COMPANYID,
1013                                            finderArgs, list);
1014    
1015                                    closeSession(session);
1016                            }
1017                    }
1018    
1019                    return list;
1020            }
1021    
1022            /**
1023             * Finds the first social relation in the ordered set where companyId = &#63;.
1024             *
1025             * <p>
1026             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1027             * </p>
1028             *
1029             * @param companyId the company id to search with
1030             * @param orderByComparator the comparator to order the set by
1031             * @return the first matching social relation
1032             * @throws com.liferay.portlet.social.NoSuchRelationException if a matching social relation could not be found
1033             * @throws SystemException if a system exception occurred
1034             */
1035            public SocialRelation findByCompanyId_First(long companyId,
1036                    OrderByComparator orderByComparator)
1037                    throws NoSuchRelationException, SystemException {
1038                    List<SocialRelation> list = findByCompanyId(companyId, 0, 1,
1039                                    orderByComparator);
1040    
1041                    if (list.isEmpty()) {
1042                            StringBundler msg = new StringBundler(4);
1043    
1044                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1045    
1046                            msg.append("companyId=");
1047                            msg.append(companyId);
1048    
1049                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1050    
1051                            throw new NoSuchRelationException(msg.toString());
1052                    }
1053                    else {
1054                            return list.get(0);
1055                    }
1056            }
1057    
1058            /**
1059             * Finds the last social relation in the ordered set where companyId = &#63;.
1060             *
1061             * <p>
1062             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1063             * </p>
1064             *
1065             * @param companyId the company id to search with
1066             * @param orderByComparator the comparator to order the set by
1067             * @return the last matching social relation
1068             * @throws com.liferay.portlet.social.NoSuchRelationException if a matching social relation could not be found
1069             * @throws SystemException if a system exception occurred
1070             */
1071            public SocialRelation findByCompanyId_Last(long companyId,
1072                    OrderByComparator orderByComparator)
1073                    throws NoSuchRelationException, SystemException {
1074                    int count = countByCompanyId(companyId);
1075    
1076                    List<SocialRelation> list = findByCompanyId(companyId, count - 1,
1077                                    count, orderByComparator);
1078    
1079                    if (list.isEmpty()) {
1080                            StringBundler msg = new StringBundler(4);
1081    
1082                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1083    
1084                            msg.append("companyId=");
1085                            msg.append(companyId);
1086    
1087                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1088    
1089                            throw new NoSuchRelationException(msg.toString());
1090                    }
1091                    else {
1092                            return list.get(0);
1093                    }
1094            }
1095    
1096            /**
1097             * Finds the social relations before and after the current social relation in the ordered set where companyId = &#63;.
1098             *
1099             * <p>
1100             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1101             * </p>
1102             *
1103             * @param relationId the primary key of the current social relation
1104             * @param companyId the company id to search with
1105             * @param orderByComparator the comparator to order the set by
1106             * @return the previous, current, and next social relation
1107             * @throws com.liferay.portlet.social.NoSuchRelationException if a social relation with the primary key could not be found
1108             * @throws SystemException if a system exception occurred
1109             */
1110            public SocialRelation[] findByCompanyId_PrevAndNext(long relationId,
1111                    long companyId, OrderByComparator orderByComparator)
1112                    throws NoSuchRelationException, SystemException {
1113                    SocialRelation socialRelation = findByPrimaryKey(relationId);
1114    
1115                    Session session = null;
1116    
1117                    try {
1118                            session = openSession();
1119    
1120                            SocialRelation[] array = new SocialRelationImpl[3];
1121    
1122                            array[0] = getByCompanyId_PrevAndNext(session, socialRelation,
1123                                            companyId, orderByComparator, true);
1124    
1125                            array[1] = socialRelation;
1126    
1127                            array[2] = getByCompanyId_PrevAndNext(session, socialRelation,
1128                                            companyId, orderByComparator, false);
1129    
1130                            return array;
1131                    }
1132                    catch (Exception e) {
1133                            throw processException(e);
1134                    }
1135                    finally {
1136                            closeSession(session);
1137                    }
1138            }
1139    
1140            protected SocialRelation getByCompanyId_PrevAndNext(Session session,
1141                    SocialRelation socialRelation, long companyId,
1142                    OrderByComparator orderByComparator, boolean previous) {
1143                    StringBundler query = null;
1144    
1145                    if (orderByComparator != null) {
1146                            query = new StringBundler(6 +
1147                                            (orderByComparator.getOrderByFields().length * 6));
1148                    }
1149                    else {
1150                            query = new StringBundler(3);
1151                    }
1152    
1153                    query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
1154    
1155                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1156    
1157                    if (orderByComparator != null) {
1158                            String[] orderByFields = orderByComparator.getOrderByFields();
1159    
1160                            if (orderByFields.length > 0) {
1161                                    query.append(WHERE_AND);
1162                            }
1163    
1164                            for (int i = 0; i < orderByFields.length; i++) {
1165                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1166                                    query.append(orderByFields[i]);
1167    
1168                                    if ((i + 1) < orderByFields.length) {
1169                                            if (orderByComparator.isAscending() ^ previous) {
1170                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1171                                            }
1172                                            else {
1173                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1174                                            }
1175                                    }
1176                                    else {
1177                                            if (orderByComparator.isAscending() ^ previous) {
1178                                                    query.append(WHERE_GREATER_THAN);
1179                                            }
1180                                            else {
1181                                                    query.append(WHERE_LESSER_THAN);
1182                                            }
1183                                    }
1184                            }
1185    
1186                            query.append(ORDER_BY_CLAUSE);
1187    
1188                            for (int i = 0; i < orderByFields.length; i++) {
1189                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1190                                    query.append(orderByFields[i]);
1191    
1192                                    if ((i + 1) < orderByFields.length) {
1193                                            if (orderByComparator.isAscending() ^ previous) {
1194                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1195                                            }
1196                                            else {
1197                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1198                                            }
1199                                    }
1200                                    else {
1201                                            if (orderByComparator.isAscending() ^ previous) {
1202                                                    query.append(ORDER_BY_ASC);
1203                                            }
1204                                            else {
1205                                                    query.append(ORDER_BY_DESC);
1206                                            }
1207                                    }
1208                            }
1209                    }
1210    
1211                    String sql = query.toString();
1212    
1213                    Query q = session.createQuery(sql);
1214    
1215                    q.setFirstResult(0);
1216                    q.setMaxResults(2);
1217    
1218                    QueryPos qPos = QueryPos.getInstance(q);
1219    
1220                    qPos.add(companyId);
1221    
1222                    if (orderByComparator != null) {
1223                            Object[] values = orderByComparator.getOrderByValues(socialRelation);
1224    
1225                            for (Object value : values) {
1226                                    qPos.add(value);
1227                            }
1228                    }
1229    
1230                    List<SocialRelation> list = q.list();
1231    
1232                    if (list.size() == 2) {
1233                            return list.get(1);
1234                    }
1235                    else {
1236                            return null;
1237                    }
1238            }
1239    
1240            /**
1241             * Finds all the social relations where userId1 = &#63;.
1242             *
1243             * @param userId1 the user id1 to search with
1244             * @return the matching social relations
1245             * @throws SystemException if a system exception occurred
1246             */
1247            public List<SocialRelation> findByUserId1(long userId1)
1248                    throws SystemException {
1249                    return findByUserId1(userId1, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1250            }
1251    
1252            /**
1253             * Finds a range of all the social relations where userId1 = &#63;.
1254             *
1255             * <p>
1256             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1257             * </p>
1258             *
1259             * @param userId1 the user id1 to search with
1260             * @param start the lower bound of the range of social relations to return
1261             * @param end the upper bound of the range of social relations to return (not inclusive)
1262             * @return the range of matching social relations
1263             * @throws SystemException if a system exception occurred
1264             */
1265            public List<SocialRelation> findByUserId1(long userId1, int start, int end)
1266                    throws SystemException {
1267                    return findByUserId1(userId1, start, end, null);
1268            }
1269    
1270            /**
1271             * Finds an ordered range of all the social relations where userId1 = &#63;.
1272             *
1273             * <p>
1274             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1275             * </p>
1276             *
1277             * @param userId1 the user id1 to search with
1278             * @param start the lower bound of the range of social relations to return
1279             * @param end the upper bound of the range of social relations to return (not inclusive)
1280             * @param orderByComparator the comparator to order the results by
1281             * @return the ordered range of matching social relations
1282             * @throws SystemException if a system exception occurred
1283             */
1284            public List<SocialRelation> findByUserId1(long userId1, int start, int end,
1285                    OrderByComparator orderByComparator) throws SystemException {
1286                    Object[] finderArgs = new Object[] {
1287                                    userId1,
1288                                    
1289                                    String.valueOf(start), String.valueOf(end),
1290                                    String.valueOf(orderByComparator)
1291                            };
1292    
1293                    List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_USERID1,
1294                                    finderArgs, this);
1295    
1296                    if (list == null) {
1297                            Session session = null;
1298    
1299                            try {
1300                                    session = openSession();
1301    
1302                                    StringBundler query = null;
1303    
1304                                    if (orderByComparator != null) {
1305                                            query = new StringBundler(3 +
1306                                                            (orderByComparator.getOrderByFields().length * 3));
1307                                    }
1308                                    else {
1309                                            query = new StringBundler(2);
1310                                    }
1311    
1312                                    query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
1313    
1314                                    query.append(_FINDER_COLUMN_USERID1_USERID1_2);
1315    
1316                                    if (orderByComparator != null) {
1317                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1318                                                    orderByComparator);
1319                                    }
1320    
1321                                    String sql = query.toString();
1322    
1323                                    Query q = session.createQuery(sql);
1324    
1325                                    QueryPos qPos = QueryPos.getInstance(q);
1326    
1327                                    qPos.add(userId1);
1328    
1329                                    list = (List<SocialRelation>)QueryUtil.list(q, getDialect(),
1330                                                    start, end);
1331                            }
1332                            catch (Exception e) {
1333                                    throw processException(e);
1334                            }
1335                            finally {
1336                                    if (list == null) {
1337                                            list = new ArrayList<SocialRelation>();
1338                                    }
1339    
1340                                    cacheResult(list);
1341    
1342                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_USERID1,
1343                                            finderArgs, list);
1344    
1345                                    closeSession(session);
1346                            }
1347                    }
1348    
1349                    return list;
1350            }
1351    
1352            /**
1353             * Finds the first social relation in the ordered set where userId1 = &#63;.
1354             *
1355             * <p>
1356             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1357             * </p>
1358             *
1359             * @param userId1 the user id1 to search with
1360             * @param orderByComparator the comparator to order the set by
1361             * @return the first matching social relation
1362             * @throws com.liferay.portlet.social.NoSuchRelationException if a matching social relation could not be found
1363             * @throws SystemException if a system exception occurred
1364             */
1365            public SocialRelation findByUserId1_First(long userId1,
1366                    OrderByComparator orderByComparator)
1367                    throws NoSuchRelationException, SystemException {
1368                    List<SocialRelation> list = findByUserId1(userId1, 0, 1,
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("userId1=");
1377                            msg.append(userId1);
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            /**
1389             * Finds the last social relation in the ordered set where userId1 = &#63;.
1390             *
1391             * <p>
1392             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1393             * </p>
1394             *
1395             * @param userId1 the user id1 to search with
1396             * @param orderByComparator the comparator to order the set by
1397             * @return the last matching social relation
1398             * @throws com.liferay.portlet.social.NoSuchRelationException if a matching social relation could not be found
1399             * @throws SystemException if a system exception occurred
1400             */
1401            public SocialRelation findByUserId1_Last(long userId1,
1402                    OrderByComparator orderByComparator)
1403                    throws NoSuchRelationException, SystemException {
1404                    int count = countByUserId1(userId1);
1405    
1406                    List<SocialRelation> list = findByUserId1(userId1, count - 1, count,
1407                                    orderByComparator);
1408    
1409                    if (list.isEmpty()) {
1410                            StringBundler msg = new StringBundler(4);
1411    
1412                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1413    
1414                            msg.append("userId1=");
1415                            msg.append(userId1);
1416    
1417                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1418    
1419                            throw new NoSuchRelationException(msg.toString());
1420                    }
1421                    else {
1422                            return list.get(0);
1423                    }
1424            }
1425    
1426            /**
1427             * Finds the social relations before and after the current social relation in the ordered set where userId1 = &#63;.
1428             *
1429             * <p>
1430             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1431             * </p>
1432             *
1433             * @param relationId the primary key of the current social relation
1434             * @param userId1 the user id1 to search with
1435             * @param orderByComparator the comparator to order the set by
1436             * @return the previous, current, and next social relation
1437             * @throws com.liferay.portlet.social.NoSuchRelationException if a social relation with the primary key could not be found
1438             * @throws SystemException if a system exception occurred
1439             */
1440            public SocialRelation[] findByUserId1_PrevAndNext(long relationId,
1441                    long userId1, OrderByComparator orderByComparator)
1442                    throws NoSuchRelationException, SystemException {
1443                    SocialRelation socialRelation = findByPrimaryKey(relationId);
1444    
1445                    Session session = null;
1446    
1447                    try {
1448                            session = openSession();
1449    
1450                            SocialRelation[] array = new SocialRelationImpl[3];
1451    
1452                            array[0] = getByUserId1_PrevAndNext(session, socialRelation,
1453                                            userId1, orderByComparator, true);
1454    
1455                            array[1] = socialRelation;
1456    
1457                            array[2] = getByUserId1_PrevAndNext(session, socialRelation,
1458                                            userId1, orderByComparator, false);
1459    
1460                            return array;
1461                    }
1462                    catch (Exception e) {
1463                            throw processException(e);
1464                    }
1465                    finally {
1466                            closeSession(session);
1467                    }
1468            }
1469    
1470            protected SocialRelation getByUserId1_PrevAndNext(Session session,
1471                    SocialRelation socialRelation, long userId1,
1472                    OrderByComparator orderByComparator, boolean previous) {
1473                    StringBundler query = null;
1474    
1475                    if (orderByComparator != null) {
1476                            query = new StringBundler(6 +
1477                                            (orderByComparator.getOrderByFields().length * 6));
1478                    }
1479                    else {
1480                            query = new StringBundler(3);
1481                    }
1482    
1483                    query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
1484    
1485                    query.append(_FINDER_COLUMN_USERID1_USERID1_2);
1486    
1487                    if (orderByComparator != null) {
1488                            String[] orderByFields = orderByComparator.getOrderByFields();
1489    
1490                            if (orderByFields.length > 0) {
1491                                    query.append(WHERE_AND);
1492                            }
1493    
1494                            for (int i = 0; i < orderByFields.length; i++) {
1495                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1496                                    query.append(orderByFields[i]);
1497    
1498                                    if ((i + 1) < orderByFields.length) {
1499                                            if (orderByComparator.isAscending() ^ previous) {
1500                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1501                                            }
1502                                            else {
1503                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1504                                            }
1505                                    }
1506                                    else {
1507                                            if (orderByComparator.isAscending() ^ previous) {
1508                                                    query.append(WHERE_GREATER_THAN);
1509                                            }
1510                                            else {
1511                                                    query.append(WHERE_LESSER_THAN);
1512                                            }
1513                                    }
1514                            }
1515    
1516                            query.append(ORDER_BY_CLAUSE);
1517    
1518                            for (int i = 0; i < orderByFields.length; i++) {
1519                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1520                                    query.append(orderByFields[i]);
1521    
1522                                    if ((i + 1) < orderByFields.length) {
1523                                            if (orderByComparator.isAscending() ^ previous) {
1524                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1525                                            }
1526                                            else {
1527                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1528                                            }
1529                                    }
1530                                    else {
1531                                            if (orderByComparator.isAscending() ^ previous) {
1532                                                    query.append(ORDER_BY_ASC);
1533                                            }
1534                                            else {
1535                                                    query.append(ORDER_BY_DESC);
1536                                            }
1537                                    }
1538                            }
1539                    }
1540    
1541                    String sql = query.toString();
1542    
1543                    Query q = session.createQuery(sql);
1544    
1545                    q.setFirstResult(0);
1546                    q.setMaxResults(2);
1547    
1548                    QueryPos qPos = QueryPos.getInstance(q);
1549    
1550                    qPos.add(userId1);
1551    
1552                    if (orderByComparator != null) {
1553                            Object[] values = orderByComparator.getOrderByValues(socialRelation);
1554    
1555                            for (Object value : values) {
1556                                    qPos.add(value);
1557                            }
1558                    }
1559    
1560                    List<SocialRelation> list = q.list();
1561    
1562                    if (list.size() == 2) {
1563                            return list.get(1);
1564                    }
1565                    else {
1566                            return null;
1567                    }
1568            }
1569    
1570            /**
1571             * Finds all the social relations where userId2 = &#63;.
1572             *
1573             * @param userId2 the user id2 to search with
1574             * @return the matching social relations
1575             * @throws SystemException if a system exception occurred
1576             */
1577            public List<SocialRelation> findByUserId2(long userId2)
1578                    throws SystemException {
1579                    return findByUserId2(userId2, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1580            }
1581    
1582            /**
1583             * Finds a range of all the social relations where userId2 = &#63;.
1584             *
1585             * <p>
1586             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1587             * </p>
1588             *
1589             * @param userId2 the user id2 to search with
1590             * @param start the lower bound of the range of social relations to return
1591             * @param end the upper bound of the range of social relations to return (not inclusive)
1592             * @return the range of matching social relations
1593             * @throws SystemException if a system exception occurred
1594             */
1595            public List<SocialRelation> findByUserId2(long userId2, int start, int end)
1596                    throws SystemException {
1597                    return findByUserId2(userId2, start, end, null);
1598            }
1599    
1600            /**
1601             * Finds an ordered range of all the social relations where userId2 = &#63;.
1602             *
1603             * <p>
1604             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1605             * </p>
1606             *
1607             * @param userId2 the user id2 to search with
1608             * @param start the lower bound of the range of social relations to return
1609             * @param end the upper bound of the range of social relations to return (not inclusive)
1610             * @param orderByComparator the comparator to order the results by
1611             * @return the ordered range of matching social relations
1612             * @throws SystemException if a system exception occurred
1613             */
1614            public List<SocialRelation> findByUserId2(long userId2, int start, int end,
1615                    OrderByComparator orderByComparator) throws SystemException {
1616                    Object[] finderArgs = new Object[] {
1617                                    userId2,
1618                                    
1619                                    String.valueOf(start), String.valueOf(end),
1620                                    String.valueOf(orderByComparator)
1621                            };
1622    
1623                    List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_USERID2,
1624                                    finderArgs, this);
1625    
1626                    if (list == null) {
1627                            Session session = null;
1628    
1629                            try {
1630                                    session = openSession();
1631    
1632                                    StringBundler query = null;
1633    
1634                                    if (orderByComparator != null) {
1635                                            query = new StringBundler(3 +
1636                                                            (orderByComparator.getOrderByFields().length * 3));
1637                                    }
1638                                    else {
1639                                            query = new StringBundler(2);
1640                                    }
1641    
1642                                    query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
1643    
1644                                    query.append(_FINDER_COLUMN_USERID2_USERID2_2);
1645    
1646                                    if (orderByComparator != null) {
1647                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1648                                                    orderByComparator);
1649                                    }
1650    
1651                                    String sql = query.toString();
1652    
1653                                    Query q = session.createQuery(sql);
1654    
1655                                    QueryPos qPos = QueryPos.getInstance(q);
1656    
1657                                    qPos.add(userId2);
1658    
1659                                    list = (List<SocialRelation>)QueryUtil.list(q, getDialect(),
1660                                                    start, end);
1661                            }
1662                            catch (Exception e) {
1663                                    throw processException(e);
1664                            }
1665                            finally {
1666                                    if (list == null) {
1667                                            list = new ArrayList<SocialRelation>();
1668                                    }
1669    
1670                                    cacheResult(list);
1671    
1672                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_USERID2,
1673                                            finderArgs, list);
1674    
1675                                    closeSession(session);
1676                            }
1677                    }
1678    
1679                    return list;
1680            }
1681    
1682            /**
1683             * Finds the first social relation in the ordered set where userId2 = &#63;.
1684             *
1685             * <p>
1686             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1687             * </p>
1688             *
1689             * @param userId2 the user id2 to search with
1690             * @param orderByComparator the comparator to order the set by
1691             * @return the first matching social relation
1692             * @throws com.liferay.portlet.social.NoSuchRelationException if a matching social relation could not be found
1693             * @throws SystemException if a system exception occurred
1694             */
1695            public SocialRelation findByUserId2_First(long userId2,
1696                    OrderByComparator orderByComparator)
1697                    throws NoSuchRelationException, SystemException {
1698                    List<SocialRelation> list = findByUserId2(userId2, 0, 1,
1699                                    orderByComparator);
1700    
1701                    if (list.isEmpty()) {
1702                            StringBundler msg = new StringBundler(4);
1703    
1704                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1705    
1706                            msg.append("userId2=");
1707                            msg.append(userId2);
1708    
1709                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1710    
1711                            throw new NoSuchRelationException(msg.toString());
1712                    }
1713                    else {
1714                            return list.get(0);
1715                    }
1716            }
1717    
1718            /**
1719             * Finds the last social relation in the ordered set where userId2 = &#63;.
1720             *
1721             * <p>
1722             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1723             * </p>
1724             *
1725             * @param userId2 the user id2 to search with
1726             * @param orderByComparator the comparator to order the set by
1727             * @return the last matching social relation
1728             * @throws com.liferay.portlet.social.NoSuchRelationException if a matching social relation could not be found
1729             * @throws SystemException if a system exception occurred
1730             */
1731            public SocialRelation findByUserId2_Last(long userId2,
1732                    OrderByComparator orderByComparator)
1733                    throws NoSuchRelationException, SystemException {
1734                    int count = countByUserId2(userId2);
1735    
1736                    List<SocialRelation> list = findByUserId2(userId2, count - 1, count,
1737                                    orderByComparator);
1738    
1739                    if (list.isEmpty()) {
1740                            StringBundler msg = new StringBundler(4);
1741    
1742                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1743    
1744                            msg.append("userId2=");
1745                            msg.append(userId2);
1746    
1747                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1748    
1749                            throw new NoSuchRelationException(msg.toString());
1750                    }
1751                    else {
1752                            return list.get(0);
1753                    }
1754            }
1755    
1756            /**
1757             * Finds the social relations before and after the current social relation in the ordered set where userId2 = &#63;.
1758             *
1759             * <p>
1760             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1761             * </p>
1762             *
1763             * @param relationId the primary key of the current social relation
1764             * @param userId2 the user id2 to search with
1765             * @param orderByComparator the comparator to order the set by
1766             * @return the previous, current, and next social relation
1767             * @throws com.liferay.portlet.social.NoSuchRelationException if a social relation with the primary key could not be found
1768             * @throws SystemException if a system exception occurred
1769             */
1770            public SocialRelation[] findByUserId2_PrevAndNext(long relationId,
1771                    long userId2, OrderByComparator orderByComparator)
1772                    throws NoSuchRelationException, SystemException {
1773                    SocialRelation socialRelation = findByPrimaryKey(relationId);
1774    
1775                    Session session = null;
1776    
1777                    try {
1778                            session = openSession();
1779    
1780                            SocialRelation[] array = new SocialRelationImpl[3];
1781    
1782                            array[0] = getByUserId2_PrevAndNext(session, socialRelation,
1783                                            userId2, orderByComparator, true);
1784    
1785                            array[1] = socialRelation;
1786    
1787                            array[2] = getByUserId2_PrevAndNext(session, socialRelation,
1788                                            userId2, orderByComparator, false);
1789    
1790                            return array;
1791                    }
1792                    catch (Exception e) {
1793                            throw processException(e);
1794                    }
1795                    finally {
1796                            closeSession(session);
1797                    }
1798            }
1799    
1800            protected SocialRelation getByUserId2_PrevAndNext(Session session,
1801                    SocialRelation socialRelation, long userId2,
1802                    OrderByComparator orderByComparator, boolean previous) {
1803                    StringBundler query = null;
1804    
1805                    if (orderByComparator != null) {
1806                            query = new StringBundler(6 +
1807                                            (orderByComparator.getOrderByFields().length * 6));
1808                    }
1809                    else {
1810                            query = new StringBundler(3);
1811                    }
1812    
1813                    query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
1814    
1815                    query.append(_FINDER_COLUMN_USERID2_USERID2_2);
1816    
1817                    if (orderByComparator != null) {
1818                            String[] orderByFields = orderByComparator.getOrderByFields();
1819    
1820                            if (orderByFields.length > 0) {
1821                                    query.append(WHERE_AND);
1822                            }
1823    
1824                            for (int i = 0; i < orderByFields.length; i++) {
1825                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1826                                    query.append(orderByFields[i]);
1827    
1828                                    if ((i + 1) < orderByFields.length) {
1829                                            if (orderByComparator.isAscending() ^ previous) {
1830                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1831                                            }
1832                                            else {
1833                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1834                                            }
1835                                    }
1836                                    else {
1837                                            if (orderByComparator.isAscending() ^ previous) {
1838                                                    query.append(WHERE_GREATER_THAN);
1839                                            }
1840                                            else {
1841                                                    query.append(WHERE_LESSER_THAN);
1842                                            }
1843                                    }
1844                            }
1845    
1846                            query.append(ORDER_BY_CLAUSE);
1847    
1848                            for (int i = 0; i < orderByFields.length; i++) {
1849                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1850                                    query.append(orderByFields[i]);
1851    
1852                                    if ((i + 1) < orderByFields.length) {
1853                                            if (orderByComparator.isAscending() ^ previous) {
1854                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1855                                            }
1856                                            else {
1857                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1858                                            }
1859                                    }
1860                                    else {
1861                                            if (orderByComparator.isAscending() ^ previous) {
1862                                                    query.append(ORDER_BY_ASC);
1863                                            }
1864                                            else {
1865                                                    query.append(ORDER_BY_DESC);
1866                                            }
1867                                    }
1868                            }
1869                    }
1870    
1871                    String sql = query.toString();
1872    
1873                    Query q = session.createQuery(sql);
1874    
1875                    q.setFirstResult(0);
1876                    q.setMaxResults(2);
1877    
1878                    QueryPos qPos = QueryPos.getInstance(q);
1879    
1880                    qPos.add(userId2);
1881    
1882                    if (orderByComparator != null) {
1883                            Object[] values = orderByComparator.getOrderByValues(socialRelation);
1884    
1885                            for (Object value : values) {
1886                                    qPos.add(value);
1887                            }
1888                    }
1889    
1890                    List<SocialRelation> list = q.list();
1891    
1892                    if (list.size() == 2) {
1893                            return list.get(1);
1894                    }
1895                    else {
1896                            return null;
1897                    }
1898            }
1899    
1900            /**
1901             * Finds all the social relations where type = &#63;.
1902             *
1903             * @param type the type to search with
1904             * @return the matching social relations
1905             * @throws SystemException if a system exception occurred
1906             */
1907            public List<SocialRelation> findByType(int type) throws SystemException {
1908                    return findByType(type, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1909            }
1910    
1911            /**
1912             * Finds a range of all the social relations where type = &#63;.
1913             *
1914             * <p>
1915             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1916             * </p>
1917             *
1918             * @param type the type to search with
1919             * @param start the lower bound of the range of social relations to return
1920             * @param end the upper bound of the range of social relations to return (not inclusive)
1921             * @return the range of matching social relations
1922             * @throws SystemException if a system exception occurred
1923             */
1924            public List<SocialRelation> findByType(int type, int start, int end)
1925                    throws SystemException {
1926                    return findByType(type, start, end, null);
1927            }
1928    
1929            /**
1930             * Finds an ordered range of all the social relations where type = &#63;.
1931             *
1932             * <p>
1933             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1934             * </p>
1935             *
1936             * @param type the type to search with
1937             * @param start the lower bound of the range of social relations to return
1938             * @param end the upper bound of the range of social relations to return (not inclusive)
1939             * @param orderByComparator the comparator to order the results by
1940             * @return the ordered range of matching social relations
1941             * @throws SystemException if a system exception occurred
1942             */
1943            public List<SocialRelation> findByType(int type, int start, int end,
1944                    OrderByComparator orderByComparator) throws SystemException {
1945                    Object[] finderArgs = new Object[] {
1946                                    type,
1947                                    
1948                                    String.valueOf(start), String.valueOf(end),
1949                                    String.valueOf(orderByComparator)
1950                            };
1951    
1952                    List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_TYPE,
1953                                    finderArgs, this);
1954    
1955                    if (list == null) {
1956                            Session session = null;
1957    
1958                            try {
1959                                    session = openSession();
1960    
1961                                    StringBundler query = null;
1962    
1963                                    if (orderByComparator != null) {
1964                                            query = new StringBundler(3 +
1965                                                            (orderByComparator.getOrderByFields().length * 3));
1966                                    }
1967                                    else {
1968                                            query = new StringBundler(2);
1969                                    }
1970    
1971                                    query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
1972    
1973                                    query.append(_FINDER_COLUMN_TYPE_TYPE_2);
1974    
1975                                    if (orderByComparator != null) {
1976                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1977                                                    orderByComparator);
1978                                    }
1979    
1980                                    String sql = query.toString();
1981    
1982                                    Query q = session.createQuery(sql);
1983    
1984                                    QueryPos qPos = QueryPos.getInstance(q);
1985    
1986                                    qPos.add(type);
1987    
1988                                    list = (List<SocialRelation>)QueryUtil.list(q, getDialect(),
1989                                                    start, end);
1990                            }
1991                            catch (Exception e) {
1992                                    throw processException(e);
1993                            }
1994                            finally {
1995                                    if (list == null) {
1996                                            list = new ArrayList<SocialRelation>();
1997                                    }
1998    
1999                                    cacheResult(list);
2000    
2001                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_TYPE, finderArgs,
2002                                            list);
2003    
2004                                    closeSession(session);
2005                            }
2006                    }
2007    
2008                    return list;
2009            }
2010    
2011            /**
2012             * Finds the first social relation in the ordered set where type = &#63;.
2013             *
2014             * <p>
2015             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2016             * </p>
2017             *
2018             * @param type the type to search with
2019             * @param orderByComparator the comparator to order the set by
2020             * @return the first matching social relation
2021             * @throws com.liferay.portlet.social.NoSuchRelationException if a matching social relation could not be found
2022             * @throws SystemException if a system exception occurred
2023             */
2024            public SocialRelation findByType_First(int type,
2025                    OrderByComparator orderByComparator)
2026                    throws NoSuchRelationException, SystemException {
2027                    List<SocialRelation> list = findByType(type, 0, 1, orderByComparator);
2028    
2029                    if (list.isEmpty()) {
2030                            StringBundler msg = new StringBundler(4);
2031    
2032                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2033    
2034                            msg.append("type=");
2035                            msg.append(type);
2036    
2037                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2038    
2039                            throw new NoSuchRelationException(msg.toString());
2040                    }
2041                    else {
2042                            return list.get(0);
2043                    }
2044            }
2045    
2046            /**
2047             * Finds the last social relation in the ordered set where type = &#63;.
2048             *
2049             * <p>
2050             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2051             * </p>
2052             *
2053             * @param type the type to search with
2054             * @param orderByComparator the comparator to order the set by
2055             * @return the last matching social relation
2056             * @throws com.liferay.portlet.social.NoSuchRelationException if a matching social relation could not be found
2057             * @throws SystemException if a system exception occurred
2058             */
2059            public SocialRelation findByType_Last(int type,
2060                    OrderByComparator orderByComparator)
2061                    throws NoSuchRelationException, SystemException {
2062                    int count = countByType(type);
2063    
2064                    List<SocialRelation> list = findByType(type, count - 1, count,
2065                                    orderByComparator);
2066    
2067                    if (list.isEmpty()) {
2068                            StringBundler msg = new StringBundler(4);
2069    
2070                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2071    
2072                            msg.append("type=");
2073                            msg.append(type);
2074    
2075                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2076    
2077                            throw new NoSuchRelationException(msg.toString());
2078                    }
2079                    else {
2080                            return list.get(0);
2081                    }
2082            }
2083    
2084            /**
2085             * Finds the social relations before and after the current social relation in the ordered set where type = &#63;.
2086             *
2087             * <p>
2088             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2089             * </p>
2090             *
2091             * @param relationId the primary key of the current social relation
2092             * @param type the type to search with
2093             * @param orderByComparator the comparator to order the set by
2094             * @return the previous, current, and next social relation
2095             * @throws com.liferay.portlet.social.NoSuchRelationException if a social relation with the primary key could not be found
2096             * @throws SystemException if a system exception occurred
2097             */
2098            public SocialRelation[] findByType_PrevAndNext(long relationId, int type,
2099                    OrderByComparator orderByComparator)
2100                    throws NoSuchRelationException, SystemException {
2101                    SocialRelation socialRelation = findByPrimaryKey(relationId);
2102    
2103                    Session session = null;
2104    
2105                    try {
2106                            session = openSession();
2107    
2108                            SocialRelation[] array = new SocialRelationImpl[3];
2109    
2110                            array[0] = getByType_PrevAndNext(session, socialRelation, type,
2111                                            orderByComparator, true);
2112    
2113                            array[1] = socialRelation;
2114    
2115                            array[2] = getByType_PrevAndNext(session, socialRelation, type,
2116                                            orderByComparator, false);
2117    
2118                            return array;
2119                    }
2120                    catch (Exception e) {
2121                            throw processException(e);
2122                    }
2123                    finally {
2124                            closeSession(session);
2125                    }
2126            }
2127    
2128            protected SocialRelation getByType_PrevAndNext(Session session,
2129                    SocialRelation socialRelation, int type,
2130                    OrderByComparator orderByComparator, boolean previous) {
2131                    StringBundler query = null;
2132    
2133                    if (orderByComparator != null) {
2134                            query = new StringBundler(6 +
2135                                            (orderByComparator.getOrderByFields().length * 6));
2136                    }
2137                    else {
2138                            query = new StringBundler(3);
2139                    }
2140    
2141                    query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
2142    
2143                    query.append(_FINDER_COLUMN_TYPE_TYPE_2);
2144    
2145                    if (orderByComparator != null) {
2146                            String[] orderByFields = orderByComparator.getOrderByFields();
2147    
2148                            if (orderByFields.length > 0) {
2149                                    query.append(WHERE_AND);
2150                            }
2151    
2152                            for (int i = 0; i < orderByFields.length; i++) {
2153                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2154                                    query.append(orderByFields[i]);
2155    
2156                                    if ((i + 1) < orderByFields.length) {
2157                                            if (orderByComparator.isAscending() ^ previous) {
2158                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2159                                            }
2160                                            else {
2161                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2162                                            }
2163                                    }
2164                                    else {
2165                                            if (orderByComparator.isAscending() ^ previous) {
2166                                                    query.append(WHERE_GREATER_THAN);
2167                                            }
2168                                            else {
2169                                                    query.append(WHERE_LESSER_THAN);
2170                                            }
2171                                    }
2172                            }
2173    
2174                            query.append(ORDER_BY_CLAUSE);
2175    
2176                            for (int i = 0; i < orderByFields.length; i++) {
2177                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2178                                    query.append(orderByFields[i]);
2179    
2180                                    if ((i + 1) < orderByFields.length) {
2181                                            if (orderByComparator.isAscending() ^ previous) {
2182                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2183                                            }
2184                                            else {
2185                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2186                                            }
2187                                    }
2188                                    else {
2189                                            if (orderByComparator.isAscending() ^ previous) {
2190                                                    query.append(ORDER_BY_ASC);
2191                                            }
2192                                            else {
2193                                                    query.append(ORDER_BY_DESC);
2194                                            }
2195                                    }
2196                            }
2197                    }
2198    
2199                    String sql = query.toString();
2200    
2201                    Query q = session.createQuery(sql);
2202    
2203                    q.setFirstResult(0);
2204                    q.setMaxResults(2);
2205    
2206                    QueryPos qPos = QueryPos.getInstance(q);
2207    
2208                    qPos.add(type);
2209    
2210                    if (orderByComparator != null) {
2211                            Object[] values = orderByComparator.getOrderByValues(socialRelation);
2212    
2213                            for (Object value : values) {
2214                                    qPos.add(value);
2215                            }
2216                    }
2217    
2218                    List<SocialRelation> list = q.list();
2219    
2220                    if (list.size() == 2) {
2221                            return list.get(1);
2222                    }
2223                    else {
2224                            return null;
2225                    }
2226            }
2227    
2228            /**
2229             * Finds all the social relations where companyId = &#63; and type = &#63;.
2230             *
2231             * @param companyId the company id to search with
2232             * @param type the type to search with
2233             * @return the matching social relations
2234             * @throws SystemException if a system exception occurred
2235             */
2236            public List<SocialRelation> findByC_T(long companyId, int type)
2237                    throws SystemException {
2238                    return findByC_T(companyId, type, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2239                            null);
2240            }
2241    
2242            /**
2243             * Finds a range of all the social relations where companyId = &#63; and type = &#63;.
2244             *
2245             * <p>
2246             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2247             * </p>
2248             *
2249             * @param companyId the company id to search with
2250             * @param type the type to search with
2251             * @param start the lower bound of the range of social relations to return
2252             * @param end the upper bound of the range of social relations to return (not inclusive)
2253             * @return the range of matching social relations
2254             * @throws SystemException if a system exception occurred
2255             */
2256            public List<SocialRelation> findByC_T(long companyId, int type, int start,
2257                    int end) throws SystemException {
2258                    return findByC_T(companyId, type, start, end, null);
2259            }
2260    
2261            /**
2262             * Finds an ordered range of all the social relations where companyId = &#63; and type = &#63;.
2263             *
2264             * <p>
2265             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2266             * </p>
2267             *
2268             * @param companyId the company id to search with
2269             * @param type the type to search with
2270             * @param start the lower bound of the range of social relations to return
2271             * @param end the upper bound of the range of social relations to return (not inclusive)
2272             * @param orderByComparator the comparator to order the results by
2273             * @return the ordered range of matching social relations
2274             * @throws SystemException if a system exception occurred
2275             */
2276            public List<SocialRelation> findByC_T(long companyId, int type, int start,
2277                    int end, OrderByComparator orderByComparator) throws SystemException {
2278                    Object[] finderArgs = new Object[] {
2279                                    companyId, type,
2280                                    
2281                                    String.valueOf(start), String.valueOf(end),
2282                                    String.valueOf(orderByComparator)
2283                            };
2284    
2285                    List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_T,
2286                                    finderArgs, this);
2287    
2288                    if (list == null) {
2289                            Session session = null;
2290    
2291                            try {
2292                                    session = openSession();
2293    
2294                                    StringBundler query = null;
2295    
2296                                    if (orderByComparator != null) {
2297                                            query = new StringBundler(4 +
2298                                                            (orderByComparator.getOrderByFields().length * 3));
2299                                    }
2300                                    else {
2301                                            query = new StringBundler(3);
2302                                    }
2303    
2304                                    query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
2305    
2306                                    query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
2307    
2308                                    query.append(_FINDER_COLUMN_C_T_TYPE_2);
2309    
2310                                    if (orderByComparator != null) {
2311                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2312                                                    orderByComparator);
2313                                    }
2314    
2315                                    String sql = query.toString();
2316    
2317                                    Query q = session.createQuery(sql);
2318    
2319                                    QueryPos qPos = QueryPos.getInstance(q);
2320    
2321                                    qPos.add(companyId);
2322    
2323                                    qPos.add(type);
2324    
2325                                    list = (List<SocialRelation>)QueryUtil.list(q, getDialect(),
2326                                                    start, end);
2327                            }
2328                            catch (Exception e) {
2329                                    throw processException(e);
2330                            }
2331                            finally {
2332                                    if (list == null) {
2333                                            list = new ArrayList<SocialRelation>();
2334                                    }
2335    
2336                                    cacheResult(list);
2337    
2338                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_T, finderArgs,
2339                                            list);
2340    
2341                                    closeSession(session);
2342                            }
2343                    }
2344    
2345                    return list;
2346            }
2347    
2348            /**
2349             * Finds the first social relation in the ordered set where companyId = &#63; and type = &#63;.
2350             *
2351             * <p>
2352             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2353             * </p>
2354             *
2355             * @param companyId the company id to search with
2356             * @param type the type to search with
2357             * @param orderByComparator the comparator to order the set by
2358             * @return the first matching social relation
2359             * @throws com.liferay.portlet.social.NoSuchRelationException if a matching social relation could not be found
2360             * @throws SystemException if a system exception occurred
2361             */
2362            public SocialRelation findByC_T_First(long companyId, int type,
2363                    OrderByComparator orderByComparator)
2364                    throws NoSuchRelationException, SystemException {
2365                    List<SocialRelation> list = findByC_T(companyId, type, 0, 1,
2366                                    orderByComparator);
2367    
2368                    if (list.isEmpty()) {
2369                            StringBundler msg = new StringBundler(6);
2370    
2371                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2372    
2373                            msg.append("companyId=");
2374                            msg.append(companyId);
2375    
2376                            msg.append(", type=");
2377                            msg.append(type);
2378    
2379                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2380    
2381                            throw new NoSuchRelationException(msg.toString());
2382                    }
2383                    else {
2384                            return list.get(0);
2385                    }
2386            }
2387    
2388            /**
2389             * Finds the last social relation in the ordered set where companyId = &#63; and type = &#63;.
2390             *
2391             * <p>
2392             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2393             * </p>
2394             *
2395             * @param companyId the company id to search with
2396             * @param type the type to search with
2397             * @param orderByComparator the comparator to order the set by
2398             * @return the last matching social relation
2399             * @throws com.liferay.portlet.social.NoSuchRelationException if a matching social relation could not be found
2400             * @throws SystemException if a system exception occurred
2401             */
2402            public SocialRelation findByC_T_Last(long companyId, int type,
2403                    OrderByComparator orderByComparator)
2404                    throws NoSuchRelationException, SystemException {
2405                    int count = countByC_T(companyId, type);
2406    
2407                    List<SocialRelation> list = findByC_T(companyId, type, count - 1,
2408                                    count, orderByComparator);
2409    
2410                    if (list.isEmpty()) {
2411                            StringBundler msg = new StringBundler(6);
2412    
2413                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2414    
2415                            msg.append("companyId=");
2416                            msg.append(companyId);
2417    
2418                            msg.append(", type=");
2419                            msg.append(type);
2420    
2421                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2422    
2423                            throw new NoSuchRelationException(msg.toString());
2424                    }
2425                    else {
2426                            return list.get(0);
2427                    }
2428            }
2429    
2430            /**
2431             * Finds the social relations before and after the current social relation in the ordered set where companyId = &#63; and type = &#63;.
2432             *
2433             * <p>
2434             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2435             * </p>
2436             *
2437             * @param relationId the primary key of the current social relation
2438             * @param companyId the company id to search with
2439             * @param type the type to search with
2440             * @param orderByComparator the comparator to order the set by
2441             * @return the previous, current, and next social relation
2442             * @throws com.liferay.portlet.social.NoSuchRelationException if a social relation with the primary key could not be found
2443             * @throws SystemException if a system exception occurred
2444             */
2445            public SocialRelation[] findByC_T_PrevAndNext(long relationId,
2446                    long companyId, int type, OrderByComparator orderByComparator)
2447                    throws NoSuchRelationException, SystemException {
2448                    SocialRelation socialRelation = findByPrimaryKey(relationId);
2449    
2450                    Session session = null;
2451    
2452                    try {
2453                            session = openSession();
2454    
2455                            SocialRelation[] array = new SocialRelationImpl[3];
2456    
2457                            array[0] = getByC_T_PrevAndNext(session, socialRelation, companyId,
2458                                            type, orderByComparator, true);
2459    
2460                            array[1] = socialRelation;
2461    
2462                            array[2] = getByC_T_PrevAndNext(session, socialRelation, companyId,
2463                                            type, orderByComparator, false);
2464    
2465                            return array;
2466                    }
2467                    catch (Exception e) {
2468                            throw processException(e);
2469                    }
2470                    finally {
2471                            closeSession(session);
2472                    }
2473            }
2474    
2475            protected SocialRelation getByC_T_PrevAndNext(Session session,
2476                    SocialRelation socialRelation, long companyId, int type,
2477                    OrderByComparator orderByComparator, boolean previous) {
2478                    StringBundler query = null;
2479    
2480                    if (orderByComparator != null) {
2481                            query = new StringBundler(6 +
2482                                            (orderByComparator.getOrderByFields().length * 6));
2483                    }
2484                    else {
2485                            query = new StringBundler(3);
2486                    }
2487    
2488                    query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
2489    
2490                    query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
2491    
2492                    query.append(_FINDER_COLUMN_C_T_TYPE_2);
2493    
2494                    if (orderByComparator != null) {
2495                            String[] orderByFields = orderByComparator.getOrderByFields();
2496    
2497                            if (orderByFields.length > 0) {
2498                                    query.append(WHERE_AND);
2499                            }
2500    
2501                            for (int i = 0; i < orderByFields.length; i++) {
2502                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2503                                    query.append(orderByFields[i]);
2504    
2505                                    if ((i + 1) < orderByFields.length) {
2506                                            if (orderByComparator.isAscending() ^ previous) {
2507                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2508                                            }
2509                                            else {
2510                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2511                                            }
2512                                    }
2513                                    else {
2514                                            if (orderByComparator.isAscending() ^ previous) {
2515                                                    query.append(WHERE_GREATER_THAN);
2516                                            }
2517                                            else {
2518                                                    query.append(WHERE_LESSER_THAN);
2519                                            }
2520                                    }
2521                            }
2522    
2523                            query.append(ORDER_BY_CLAUSE);
2524    
2525                            for (int i = 0; i < orderByFields.length; i++) {
2526                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2527                                    query.append(orderByFields[i]);
2528    
2529                                    if ((i + 1) < orderByFields.length) {
2530                                            if (orderByComparator.isAscending() ^ previous) {
2531                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2532                                            }
2533                                            else {
2534                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2535                                            }
2536                                    }
2537                                    else {
2538                                            if (orderByComparator.isAscending() ^ previous) {
2539                                                    query.append(ORDER_BY_ASC);
2540                                            }
2541                                            else {
2542                                                    query.append(ORDER_BY_DESC);
2543                                            }
2544                                    }
2545                            }
2546                    }
2547    
2548                    String sql = query.toString();
2549    
2550                    Query q = session.createQuery(sql);
2551    
2552                    q.setFirstResult(0);
2553                    q.setMaxResults(2);
2554    
2555                    QueryPos qPos = QueryPos.getInstance(q);
2556    
2557                    qPos.add(companyId);
2558    
2559                    qPos.add(type);
2560    
2561                    if (orderByComparator != null) {
2562                            Object[] values = orderByComparator.getOrderByValues(socialRelation);
2563    
2564                            for (Object value : values) {
2565                                    qPos.add(value);
2566                            }
2567                    }
2568    
2569                    List<SocialRelation> list = q.list();
2570    
2571                    if (list.size() == 2) {
2572                            return list.get(1);
2573                    }
2574                    else {
2575                            return null;
2576                    }
2577            }
2578    
2579            /**
2580             * Finds all the social relations where userId1 = &#63; and type = &#63;.
2581             *
2582             * @param userId1 the user id1 to search with
2583             * @param type the type to search with
2584             * @return the matching social relations
2585             * @throws SystemException if a system exception occurred
2586             */
2587            public List<SocialRelation> findByU1_T(long userId1, int type)
2588                    throws SystemException {
2589                    return findByU1_T(userId1, type, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2590                            null);
2591            }
2592    
2593            /**
2594             * Finds a range of all the social relations where userId1 = &#63; and type = &#63;.
2595             *
2596             * <p>
2597             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2598             * </p>
2599             *
2600             * @param userId1 the user id1 to search with
2601             * @param type the type to search with
2602             * @param start the lower bound of the range of social relations to return
2603             * @param end the upper bound of the range of social relations to return (not inclusive)
2604             * @return the range of matching social relations
2605             * @throws SystemException if a system exception occurred
2606             */
2607            public List<SocialRelation> findByU1_T(long userId1, int type, int start,
2608                    int end) throws SystemException {
2609                    return findByU1_T(userId1, type, start, end, null);
2610            }
2611    
2612            /**
2613             * Finds an ordered range of all the social relations where userId1 = &#63; and type = &#63;.
2614             *
2615             * <p>
2616             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2617             * </p>
2618             *
2619             * @param userId1 the user id1 to search with
2620             * @param type the type to search with
2621             * @param start the lower bound of the range of social relations to return
2622             * @param end the upper bound of the range of social relations to return (not inclusive)
2623             * @param orderByComparator the comparator to order the results by
2624             * @return the ordered range of matching social relations
2625             * @throws SystemException if a system exception occurred
2626             */
2627            public List<SocialRelation> findByU1_T(long userId1, int type, int start,
2628                    int end, OrderByComparator orderByComparator) throws SystemException {
2629                    Object[] finderArgs = new Object[] {
2630                                    userId1, type,
2631                                    
2632                                    String.valueOf(start), String.valueOf(end),
2633                                    String.valueOf(orderByComparator)
2634                            };
2635    
2636                    List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_U1_T,
2637                                    finderArgs, this);
2638    
2639                    if (list == null) {
2640                            Session session = null;
2641    
2642                            try {
2643                                    session = openSession();
2644    
2645                                    StringBundler query = null;
2646    
2647                                    if (orderByComparator != null) {
2648                                            query = new StringBundler(4 +
2649                                                            (orderByComparator.getOrderByFields().length * 3));
2650                                    }
2651                                    else {
2652                                            query = new StringBundler(3);
2653                                    }
2654    
2655                                    query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
2656    
2657                                    query.append(_FINDER_COLUMN_U1_T_USERID1_2);
2658    
2659                                    query.append(_FINDER_COLUMN_U1_T_TYPE_2);
2660    
2661                                    if (orderByComparator != null) {
2662                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2663                                                    orderByComparator);
2664                                    }
2665    
2666                                    String sql = query.toString();
2667    
2668                                    Query q = session.createQuery(sql);
2669    
2670                                    QueryPos qPos = QueryPos.getInstance(q);
2671    
2672                                    qPos.add(userId1);
2673    
2674                                    qPos.add(type);
2675    
2676                                    list = (List<SocialRelation>)QueryUtil.list(q, getDialect(),
2677                                                    start, end);
2678                            }
2679                            catch (Exception e) {
2680                                    throw processException(e);
2681                            }
2682                            finally {
2683                                    if (list == null) {
2684                                            list = new ArrayList<SocialRelation>();
2685                                    }
2686    
2687                                    cacheResult(list);
2688    
2689                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_U1_T, finderArgs,
2690                                            list);
2691    
2692                                    closeSession(session);
2693                            }
2694                    }
2695    
2696                    return list;
2697            }
2698    
2699            /**
2700             * Finds the first social relation in the ordered set where userId1 = &#63; and type = &#63;.
2701             *
2702             * <p>
2703             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2704             * </p>
2705             *
2706             * @param userId1 the user id1 to search with
2707             * @param type the type to search with
2708             * @param orderByComparator the comparator to order the set by
2709             * @return the first matching social relation
2710             * @throws com.liferay.portlet.social.NoSuchRelationException if a matching social relation could not be found
2711             * @throws SystemException if a system exception occurred
2712             */
2713            public SocialRelation findByU1_T_First(long userId1, int type,
2714                    OrderByComparator orderByComparator)
2715                    throws NoSuchRelationException, SystemException {
2716                    List<SocialRelation> list = findByU1_T(userId1, type, 0, 1,
2717                                    orderByComparator);
2718    
2719                    if (list.isEmpty()) {
2720                            StringBundler msg = new StringBundler(6);
2721    
2722                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2723    
2724                            msg.append("userId1=");
2725                            msg.append(userId1);
2726    
2727                            msg.append(", type=");
2728                            msg.append(type);
2729    
2730                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2731    
2732                            throw new NoSuchRelationException(msg.toString());
2733                    }
2734                    else {
2735                            return list.get(0);
2736                    }
2737            }
2738    
2739            /**
2740             * Finds the last social relation in the ordered set where userId1 = &#63; and type = &#63;.
2741             *
2742             * <p>
2743             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2744             * </p>
2745             *
2746             * @param userId1 the user id1 to search with
2747             * @param type the type to search with
2748             * @param orderByComparator the comparator to order the set by
2749             * @return the last matching social relation
2750             * @throws com.liferay.portlet.social.NoSuchRelationException if a matching social relation could not be found
2751             * @throws SystemException if a system exception occurred
2752             */
2753            public SocialRelation findByU1_T_Last(long userId1, int type,
2754                    OrderByComparator orderByComparator)
2755                    throws NoSuchRelationException, SystemException {
2756                    int count = countByU1_T(userId1, type);
2757    
2758                    List<SocialRelation> list = findByU1_T(userId1, type, count - 1, count,
2759                                    orderByComparator);
2760    
2761                    if (list.isEmpty()) {
2762                            StringBundler msg = new StringBundler(6);
2763    
2764                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2765    
2766                            msg.append("userId1=");
2767                            msg.append(userId1);
2768    
2769                            msg.append(", type=");
2770                            msg.append(type);
2771    
2772                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2773    
2774                            throw new NoSuchRelationException(msg.toString());
2775                    }
2776                    else {
2777                            return list.get(0);
2778                    }
2779            }
2780    
2781            /**
2782             * Finds the social relations before and after the current social relation in the ordered set where userId1 = &#63; and type = &#63;.
2783             *
2784             * <p>
2785             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2786             * </p>
2787             *
2788             * @param relationId the primary key of the current social relation
2789             * @param userId1 the user id1 to search with
2790             * @param type the type to search with
2791             * @param orderByComparator the comparator to order the set by
2792             * @return the previous, current, and next social relation
2793             * @throws com.liferay.portlet.social.NoSuchRelationException if a social relation with the primary key could not be found
2794             * @throws SystemException if a system exception occurred
2795             */
2796            public SocialRelation[] findByU1_T_PrevAndNext(long relationId,
2797                    long userId1, int type, OrderByComparator orderByComparator)
2798                    throws NoSuchRelationException, SystemException {
2799                    SocialRelation socialRelation = findByPrimaryKey(relationId);
2800    
2801                    Session session = null;
2802    
2803                    try {
2804                            session = openSession();
2805    
2806                            SocialRelation[] array = new SocialRelationImpl[3];
2807    
2808                            array[0] = getByU1_T_PrevAndNext(session, socialRelation, userId1,
2809                                            type, orderByComparator, true);
2810    
2811                            array[1] = socialRelation;
2812    
2813                            array[2] = getByU1_T_PrevAndNext(session, socialRelation, userId1,
2814                                            type, orderByComparator, false);
2815    
2816                            return array;
2817                    }
2818                    catch (Exception e) {
2819                            throw processException(e);
2820                    }
2821                    finally {
2822                            closeSession(session);
2823                    }
2824            }
2825    
2826            protected SocialRelation getByU1_T_PrevAndNext(Session session,
2827                    SocialRelation socialRelation, long userId1, int type,
2828                    OrderByComparator orderByComparator, boolean previous) {
2829                    StringBundler query = null;
2830    
2831                    if (orderByComparator != null) {
2832                            query = new StringBundler(6 +
2833                                            (orderByComparator.getOrderByFields().length * 6));
2834                    }
2835                    else {
2836                            query = new StringBundler(3);
2837                    }
2838    
2839                    query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
2840    
2841                    query.append(_FINDER_COLUMN_U1_T_USERID1_2);
2842    
2843                    query.append(_FINDER_COLUMN_U1_T_TYPE_2);
2844    
2845                    if (orderByComparator != null) {
2846                            String[] orderByFields = orderByComparator.getOrderByFields();
2847    
2848                            if (orderByFields.length > 0) {
2849                                    query.append(WHERE_AND);
2850                            }
2851    
2852                            for (int i = 0; i < orderByFields.length; i++) {
2853                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2854                                    query.append(orderByFields[i]);
2855    
2856                                    if ((i + 1) < orderByFields.length) {
2857                                            if (orderByComparator.isAscending() ^ previous) {
2858                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2859                                            }
2860                                            else {
2861                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2862                                            }
2863                                    }
2864                                    else {
2865                                            if (orderByComparator.isAscending() ^ previous) {
2866                                                    query.append(WHERE_GREATER_THAN);
2867                                            }
2868                                            else {
2869                                                    query.append(WHERE_LESSER_THAN);
2870                                            }
2871                                    }
2872                            }
2873    
2874                            query.append(ORDER_BY_CLAUSE);
2875    
2876                            for (int i = 0; i < orderByFields.length; i++) {
2877                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2878                                    query.append(orderByFields[i]);
2879    
2880                                    if ((i + 1) < orderByFields.length) {
2881                                            if (orderByComparator.isAscending() ^ previous) {
2882                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2883                                            }
2884                                            else {
2885                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2886                                            }
2887                                    }
2888                                    else {
2889                                            if (orderByComparator.isAscending() ^ previous) {
2890                                                    query.append(ORDER_BY_ASC);
2891                                            }
2892                                            else {
2893                                                    query.append(ORDER_BY_DESC);
2894                                            }
2895                                    }
2896                            }
2897                    }
2898    
2899                    String sql = query.toString();
2900    
2901                    Query q = session.createQuery(sql);
2902    
2903                    q.setFirstResult(0);
2904                    q.setMaxResults(2);
2905    
2906                    QueryPos qPos = QueryPos.getInstance(q);
2907    
2908                    qPos.add(userId1);
2909    
2910                    qPos.add(type);
2911    
2912                    if (orderByComparator != null) {
2913                            Object[] values = orderByComparator.getOrderByValues(socialRelation);
2914    
2915                            for (Object value : values) {
2916                                    qPos.add(value);
2917                            }
2918                    }
2919    
2920                    List<SocialRelation> list = q.list();
2921    
2922                    if (list.size() == 2) {
2923                            return list.get(1);
2924                    }
2925                    else {
2926                            return null;
2927                    }
2928            }
2929    
2930            /**
2931             * Finds all the social relations where userId2 = &#63; and type = &#63;.
2932             *
2933             * @param userId2 the user id2 to search with
2934             * @param type the type to search with
2935             * @return the matching social relations
2936             * @throws SystemException if a system exception occurred
2937             */
2938            public List<SocialRelation> findByU2_T(long userId2, int type)
2939                    throws SystemException {
2940                    return findByU2_T(userId2, type, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2941                            null);
2942            }
2943    
2944            /**
2945             * Finds a range of all the social relations where userId2 = &#63; and type = &#63;.
2946             *
2947             * <p>
2948             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2949             * </p>
2950             *
2951             * @param userId2 the user id2 to search with
2952             * @param type the type to search with
2953             * @param start the lower bound of the range of social relations to return
2954             * @param end the upper bound of the range of social relations to return (not inclusive)
2955             * @return the range of matching social relations
2956             * @throws SystemException if a system exception occurred
2957             */
2958            public List<SocialRelation> findByU2_T(long userId2, int type, int start,
2959                    int end) throws SystemException {
2960                    return findByU2_T(userId2, type, start, end, null);
2961            }
2962    
2963            /**
2964             * Finds an ordered range of all the social relations where userId2 = &#63; and type = &#63;.
2965             *
2966             * <p>
2967             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2968             * </p>
2969             *
2970             * @param userId2 the user id2 to search with
2971             * @param type the type to search with
2972             * @param start the lower bound of the range of social relations to return
2973             * @param end the upper bound of the range of social relations to return (not inclusive)
2974             * @param orderByComparator the comparator to order the results by
2975             * @return the ordered range of matching social relations
2976             * @throws SystemException if a system exception occurred
2977             */
2978            public List<SocialRelation> findByU2_T(long userId2, int type, int start,
2979                    int end, OrderByComparator orderByComparator) throws SystemException {
2980                    Object[] finderArgs = new Object[] {
2981                                    userId2, type,
2982                                    
2983                                    String.valueOf(start), String.valueOf(end),
2984                                    String.valueOf(orderByComparator)
2985                            };
2986    
2987                    List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_U2_T,
2988                                    finderArgs, this);
2989    
2990                    if (list == null) {
2991                            Session session = null;
2992    
2993                            try {
2994                                    session = openSession();
2995    
2996                                    StringBundler query = null;
2997    
2998                                    if (orderByComparator != null) {
2999                                            query = new StringBundler(4 +
3000                                                            (orderByComparator.getOrderByFields().length * 3));
3001                                    }
3002                                    else {
3003                                            query = new StringBundler(3);
3004                                    }
3005    
3006                                    query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
3007    
3008                                    query.append(_FINDER_COLUMN_U2_T_USERID2_2);
3009    
3010                                    query.append(_FINDER_COLUMN_U2_T_TYPE_2);
3011    
3012                                    if (orderByComparator != null) {
3013                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3014                                                    orderByComparator);
3015                                    }
3016    
3017                                    String sql = query.toString();
3018    
3019                                    Query q = session.createQuery(sql);
3020    
3021                                    QueryPos qPos = QueryPos.getInstance(q);
3022    
3023                                    qPos.add(userId2);
3024    
3025                                    qPos.add(type);
3026    
3027                                    list = (List<SocialRelation>)QueryUtil.list(q, getDialect(),
3028                                                    start, end);
3029                            }
3030                            catch (Exception e) {
3031                                    throw processException(e);
3032                            }
3033                            finally {
3034                                    if (list == null) {
3035                                            list = new ArrayList<SocialRelation>();
3036                                    }
3037    
3038                                    cacheResult(list);
3039    
3040                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_U2_T, finderArgs,
3041                                            list);
3042    
3043                                    closeSession(session);
3044                            }
3045                    }
3046    
3047                    return list;
3048            }
3049    
3050            /**
3051             * Finds the first social relation in the ordered set where userId2 = &#63; and type = &#63;.
3052             *
3053             * <p>
3054             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3055             * </p>
3056             *
3057             * @param userId2 the user id2 to search with
3058             * @param type the type to search with
3059             * @param orderByComparator the comparator to order the set by
3060             * @return the first matching social relation
3061             * @throws com.liferay.portlet.social.NoSuchRelationException if a matching social relation could not be found
3062             * @throws SystemException if a system exception occurred
3063             */
3064            public SocialRelation findByU2_T_First(long userId2, int type,
3065                    OrderByComparator orderByComparator)
3066                    throws NoSuchRelationException, SystemException {
3067                    List<SocialRelation> list = findByU2_T(userId2, type, 0, 1,
3068                                    orderByComparator);
3069    
3070                    if (list.isEmpty()) {
3071                            StringBundler msg = new StringBundler(6);
3072    
3073                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3074    
3075                            msg.append("userId2=");
3076                            msg.append(userId2);
3077    
3078                            msg.append(", type=");
3079                            msg.append(type);
3080    
3081                            msg.append(StringPool.CLOSE_CURLY_BRACE);
3082    
3083                            throw new NoSuchRelationException(msg.toString());
3084                    }
3085                    else {
3086                            return list.get(0);
3087                    }
3088            }
3089    
3090            /**
3091             * Finds the last social relation in the ordered set where userId2 = &#63; and type = &#63;.
3092             *
3093             * <p>
3094             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3095             * </p>
3096             *
3097             * @param userId2 the user id2 to search with
3098             * @param type the type to search with
3099             * @param orderByComparator the comparator to order the set by
3100             * @return the last matching social relation
3101             * @throws com.liferay.portlet.social.NoSuchRelationException if a matching social relation could not be found
3102             * @throws SystemException if a system exception occurred
3103             */
3104            public SocialRelation findByU2_T_Last(long userId2, int type,
3105                    OrderByComparator orderByComparator)
3106                    throws NoSuchRelationException, SystemException {
3107                    int count = countByU2_T(userId2, type);
3108    
3109                    List<SocialRelation> list = findByU2_T(userId2, type, count - 1, count,
3110                                    orderByComparator);
3111    
3112                    if (list.isEmpty()) {
3113                            StringBundler msg = new StringBundler(6);
3114    
3115                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3116    
3117                            msg.append("userId2=");
3118                            msg.append(userId2);
3119    
3120                            msg.append(", type=");
3121                            msg.append(type);
3122    
3123                            msg.append(StringPool.CLOSE_CURLY_BRACE);
3124    
3125                            throw new NoSuchRelationException(msg.toString());
3126                    }
3127                    else {
3128                            return list.get(0);
3129                    }
3130            }
3131    
3132            /**
3133             * Finds the social relations before and after the current social relation in the ordered set where userId2 = &#63; and type = &#63;.
3134             *
3135             * <p>
3136             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3137             * </p>
3138             *
3139             * @param relationId the primary key of the current social relation
3140             * @param userId2 the user id2 to search with
3141             * @param type the type to search with
3142             * @param orderByComparator the comparator to order the set by
3143             * @return the previous, current, and next social relation
3144             * @throws com.liferay.portlet.social.NoSuchRelationException if a social relation with the primary key could not be found
3145             * @throws SystemException if a system exception occurred
3146             */
3147            public SocialRelation[] findByU2_T_PrevAndNext(long relationId,
3148                    long userId2, int type, OrderByComparator orderByComparator)
3149                    throws NoSuchRelationException, SystemException {
3150                    SocialRelation socialRelation = findByPrimaryKey(relationId);
3151    
3152                    Session session = null;
3153    
3154                    try {
3155                            session = openSession();
3156    
3157                            SocialRelation[] array = new SocialRelationImpl[3];
3158    
3159                            array[0] = getByU2_T_PrevAndNext(session, socialRelation, userId2,
3160                                            type, orderByComparator, true);
3161    
3162                            array[1] = socialRelation;
3163    
3164                            array[2] = getByU2_T_PrevAndNext(session, socialRelation, userId2,
3165                                            type, orderByComparator, false);
3166    
3167                            return array;
3168                    }
3169                    catch (Exception e) {
3170                            throw processException(e);
3171                    }
3172                    finally {
3173                            closeSession(session);
3174                    }
3175            }
3176    
3177            protected SocialRelation getByU2_T_PrevAndNext(Session session,
3178                    SocialRelation socialRelation, long userId2, int type,
3179                    OrderByComparator orderByComparator, boolean previous) {
3180                    StringBundler query = null;
3181    
3182                    if (orderByComparator != null) {
3183                            query = new StringBundler(6 +
3184                                            (orderByComparator.getOrderByFields().length * 6));
3185                    }
3186                    else {
3187                            query = new StringBundler(3);
3188                    }
3189    
3190                    query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
3191    
3192                    query.append(_FINDER_COLUMN_U2_T_USERID2_2);
3193    
3194                    query.append(_FINDER_COLUMN_U2_T_TYPE_2);
3195    
3196                    if (orderByComparator != null) {
3197                            String[] orderByFields = orderByComparator.getOrderByFields();
3198    
3199                            if (orderByFields.length > 0) {
3200                                    query.append(WHERE_AND);
3201                            }
3202    
3203                            for (int i = 0; i < orderByFields.length; i++) {
3204                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3205                                    query.append(orderByFields[i]);
3206    
3207                                    if ((i + 1) < orderByFields.length) {
3208                                            if (orderByComparator.isAscending() ^ previous) {
3209                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3210                                            }
3211                                            else {
3212                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3213                                            }
3214                                    }
3215                                    else {
3216                                            if (orderByComparator.isAscending() ^ previous) {
3217                                                    query.append(WHERE_GREATER_THAN);
3218                                            }
3219                                            else {
3220                                                    query.append(WHERE_LESSER_THAN);
3221                                            }
3222                                    }
3223                            }
3224    
3225                            query.append(ORDER_BY_CLAUSE);
3226    
3227                            for (int i = 0; i < orderByFields.length; i++) {
3228                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3229                                    query.append(orderByFields[i]);
3230    
3231                                    if ((i + 1) < orderByFields.length) {
3232                                            if (orderByComparator.isAscending() ^ previous) {
3233                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3234                                            }
3235                                            else {
3236                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3237                                            }
3238                                    }
3239                                    else {
3240                                            if (orderByComparator.isAscending() ^ previous) {
3241                                                    query.append(ORDER_BY_ASC);
3242                                            }
3243                                            else {
3244                                                    query.append(ORDER_BY_DESC);
3245                                            }
3246                                    }
3247                            }
3248                    }
3249    
3250                    String sql = query.toString();
3251    
3252                    Query q = session.createQuery(sql);
3253    
3254                    q.setFirstResult(0);
3255                    q.setMaxResults(2);
3256    
3257                    QueryPos qPos = QueryPos.getInstance(q);
3258    
3259                    qPos.add(userId2);
3260    
3261                    qPos.add(type);
3262    
3263                    if (orderByComparator != null) {
3264                            Object[] values = orderByComparator.getOrderByValues(socialRelation);
3265    
3266                            for (Object value : values) {
3267                                    qPos.add(value);
3268                            }
3269                    }
3270    
3271                    List<SocialRelation> list = q.list();
3272    
3273                    if (list.size() == 2) {
3274                            return list.get(1);
3275                    }
3276                    else {
3277                            return null;
3278                    }
3279            }
3280    
3281            /**
3282             * Finds the social relation where userId1 = &#63; and userId2 = &#63; and type = &#63; or throws a {@link com.liferay.portlet.social.NoSuchRelationException} if it could not be found.
3283             *
3284             * @param userId1 the user id1 to search with
3285             * @param userId2 the user id2 to search with
3286             * @param type the type to search with
3287             * @return the matching social relation
3288             * @throws com.liferay.portlet.social.NoSuchRelationException if a matching social relation could not be found
3289             * @throws SystemException if a system exception occurred
3290             */
3291            public SocialRelation findByU1_U2_T(long userId1, long userId2, int type)
3292                    throws NoSuchRelationException, SystemException {
3293                    SocialRelation socialRelation = fetchByU1_U2_T(userId1, userId2, type);
3294    
3295                    if (socialRelation == null) {
3296                            StringBundler msg = new StringBundler(8);
3297    
3298                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3299    
3300                            msg.append("userId1=");
3301                            msg.append(userId1);
3302    
3303                            msg.append(", userId2=");
3304                            msg.append(userId2);
3305    
3306                            msg.append(", type=");
3307                            msg.append(type);
3308    
3309                            msg.append(StringPool.CLOSE_CURLY_BRACE);
3310    
3311                            if (_log.isWarnEnabled()) {
3312                                    _log.warn(msg.toString());
3313                            }
3314    
3315                            throw new NoSuchRelationException(msg.toString());
3316                    }
3317    
3318                    return socialRelation;
3319            }
3320    
3321            /**
3322             * Finds the social relation where userId1 = &#63; and userId2 = &#63; and type = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
3323             *
3324             * @param userId1 the user id1 to search with
3325             * @param userId2 the user id2 to search with
3326             * @param type the type to search with
3327             * @return the matching social relation, or <code>null</code> if a matching social relation could not be found
3328             * @throws SystemException if a system exception occurred
3329             */
3330            public SocialRelation fetchByU1_U2_T(long userId1, long userId2, int type)
3331                    throws SystemException {
3332                    return fetchByU1_U2_T(userId1, userId2, type, true);
3333            }
3334    
3335            /**
3336             * Finds the social relation where userId1 = &#63; and userId2 = &#63; and type = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
3337             *
3338             * @param userId1 the user id1 to search with
3339             * @param userId2 the user id2 to search with
3340             * @param type the type to search with
3341             * @return the matching social relation, or <code>null</code> if a matching social relation could not be found
3342             * @throws SystemException if a system exception occurred
3343             */
3344            public SocialRelation fetchByU1_U2_T(long userId1, long userId2, int type,
3345                    boolean retrieveFromCache) throws SystemException {
3346                    Object[] finderArgs = new Object[] { userId1, userId2, type };
3347    
3348                    Object result = null;
3349    
3350                    if (retrieveFromCache) {
3351                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_U1_U2_T,
3352                                            finderArgs, this);
3353                    }
3354    
3355                    if (result == null) {
3356                            Session session = null;
3357    
3358                            try {
3359                                    session = openSession();
3360    
3361                                    StringBundler query = new StringBundler(4);
3362    
3363                                    query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
3364    
3365                                    query.append(_FINDER_COLUMN_U1_U2_T_USERID1_2);
3366    
3367                                    query.append(_FINDER_COLUMN_U1_U2_T_USERID2_2);
3368    
3369                                    query.append(_FINDER_COLUMN_U1_U2_T_TYPE_2);
3370    
3371                                    String sql = query.toString();
3372    
3373                                    Query q = session.createQuery(sql);
3374    
3375                                    QueryPos qPos = QueryPos.getInstance(q);
3376    
3377                                    qPos.add(userId1);
3378    
3379                                    qPos.add(userId2);
3380    
3381                                    qPos.add(type);
3382    
3383                                    List<SocialRelation> list = q.list();
3384    
3385                                    result = list;
3386    
3387                                    SocialRelation socialRelation = null;
3388    
3389                                    if (list.isEmpty()) {
3390                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U1_U2_T,
3391                                                    finderArgs, list);
3392                                    }
3393                                    else {
3394                                            socialRelation = list.get(0);
3395    
3396                                            cacheResult(socialRelation);
3397    
3398                                            if ((socialRelation.getUserId1() != userId1) ||
3399                                                            (socialRelation.getUserId2() != userId2) ||
3400                                                            (socialRelation.getType() != type)) {
3401                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U1_U2_T,
3402                                                            finderArgs, socialRelation);
3403                                            }
3404                                    }
3405    
3406                                    return socialRelation;
3407                            }
3408                            catch (Exception e) {
3409                                    throw processException(e);
3410                            }
3411                            finally {
3412                                    if (result == null) {
3413                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U1_U2_T,
3414                                                    finderArgs, new ArrayList<SocialRelation>());
3415                                    }
3416    
3417                                    closeSession(session);
3418                            }
3419                    }
3420                    else {
3421                            if (result instanceof List<?>) {
3422                                    return null;
3423                            }
3424                            else {
3425                                    return (SocialRelation)result;
3426                            }
3427                    }
3428            }
3429    
3430            /**
3431             * Finds all the social relations.
3432             *
3433             * @return the social relations
3434             * @throws SystemException if a system exception occurred
3435             */
3436            public List<SocialRelation> findAll() throws SystemException {
3437                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3438            }
3439    
3440            /**
3441             * Finds a range of all the social relations.
3442             *
3443             * <p>
3444             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3445             * </p>
3446             *
3447             * @param start the lower bound of the range of social relations to return
3448             * @param end the upper bound of the range of social relations to return (not inclusive)
3449             * @return the range of social relations
3450             * @throws SystemException if a system exception occurred
3451             */
3452            public List<SocialRelation> findAll(int start, int end)
3453                    throws SystemException {
3454                    return findAll(start, end, null);
3455            }
3456    
3457            /**
3458             * Finds an ordered range of all the social relations.
3459             *
3460             * <p>
3461             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3462             * </p>
3463             *
3464             * @param start the lower bound of the range of social relations to return
3465             * @param end the upper bound of the range of social relations to return (not inclusive)
3466             * @param orderByComparator the comparator to order the results by
3467             * @return the ordered range of social relations
3468             * @throws SystemException if a system exception occurred
3469             */
3470            public List<SocialRelation> findAll(int start, int end,
3471                    OrderByComparator orderByComparator) throws SystemException {
3472                    Object[] finderArgs = new Object[] {
3473                                    String.valueOf(start), String.valueOf(end),
3474                                    String.valueOf(orderByComparator)
3475                            };
3476    
3477                    List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
3478                                    finderArgs, this);
3479    
3480                    if (list == null) {
3481                            Session session = null;
3482    
3483                            try {
3484                                    session = openSession();
3485    
3486                                    StringBundler query = null;
3487                                    String sql = null;
3488    
3489                                    if (orderByComparator != null) {
3490                                            query = new StringBundler(2 +
3491                                                            (orderByComparator.getOrderByFields().length * 3));
3492    
3493                                            query.append(_SQL_SELECT_SOCIALRELATION);
3494    
3495                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3496                                                    orderByComparator);
3497    
3498                                            sql = query.toString();
3499                                    }
3500                                    else {
3501                                            sql = _SQL_SELECT_SOCIALRELATION;
3502                                    }
3503    
3504                                    Query q = session.createQuery(sql);
3505    
3506                                    if (orderByComparator == null) {
3507                                            list = (List<SocialRelation>)QueryUtil.list(q,
3508                                                            getDialect(), start, end, false);
3509    
3510                                            Collections.sort(list);
3511                                    }
3512                                    else {
3513                                            list = (List<SocialRelation>)QueryUtil.list(q,
3514                                                            getDialect(), start, end);
3515                                    }
3516                            }
3517                            catch (Exception e) {
3518                                    throw processException(e);
3519                            }
3520                            finally {
3521                                    if (list == null) {
3522                                            list = new ArrayList<SocialRelation>();
3523                                    }
3524    
3525                                    cacheResult(list);
3526    
3527                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
3528    
3529                                    closeSession(session);
3530                            }
3531                    }
3532    
3533                    return list;
3534            }
3535    
3536            /**
3537             * Removes all the social relations where uuid = &#63; from the database.
3538             *
3539             * @param uuid the uuid to search with
3540             * @throws SystemException if a system exception occurred
3541             */
3542            public void removeByUuid(String uuid) throws SystemException {
3543                    for (SocialRelation socialRelation : findByUuid(uuid)) {
3544                            remove(socialRelation);
3545                    }
3546            }
3547    
3548            /**
3549             * Removes all the social relations where companyId = &#63; from the database.
3550             *
3551             * @param companyId the company id to search with
3552             * @throws SystemException if a system exception occurred
3553             */
3554            public void removeByCompanyId(long companyId) throws SystemException {
3555                    for (SocialRelation socialRelation : findByCompanyId(companyId)) {
3556                            remove(socialRelation);
3557                    }
3558            }
3559    
3560            /**
3561             * Removes all the social relations where userId1 = &#63; from the database.
3562             *
3563             * @param userId1 the user id1 to search with
3564             * @throws SystemException if a system exception occurred
3565             */
3566            public void removeByUserId1(long userId1) throws SystemException {
3567                    for (SocialRelation socialRelation : findByUserId1(userId1)) {
3568                            remove(socialRelation);
3569                    }
3570            }
3571    
3572            /**
3573             * Removes all the social relations where userId2 = &#63; from the database.
3574             *
3575             * @param userId2 the user id2 to search with
3576             * @throws SystemException if a system exception occurred
3577             */
3578            public void removeByUserId2(long userId2) throws SystemException {
3579                    for (SocialRelation socialRelation : findByUserId2(userId2)) {
3580                            remove(socialRelation);
3581                    }
3582            }
3583    
3584            /**
3585             * Removes all the social relations where type = &#63; from the database.
3586             *
3587             * @param type the type to search with
3588             * @throws SystemException if a system exception occurred
3589             */
3590            public void removeByType(int type) throws SystemException {
3591                    for (SocialRelation socialRelation : findByType(type)) {
3592                            remove(socialRelation);
3593                    }
3594            }
3595    
3596            /**
3597             * Removes all the social relations where companyId = &#63; and type = &#63; from the database.
3598             *
3599             * @param companyId the company id to search with
3600             * @param type the type to search with
3601             * @throws SystemException if a system exception occurred
3602             */
3603            public void removeByC_T(long companyId, int type) throws SystemException {
3604                    for (SocialRelation socialRelation : findByC_T(companyId, type)) {
3605                            remove(socialRelation);
3606                    }
3607            }
3608    
3609            /**
3610             * Removes all the social relations where userId1 = &#63; and type = &#63; from the database.
3611             *
3612             * @param userId1 the user id1 to search with
3613             * @param type the type to search with
3614             * @throws SystemException if a system exception occurred
3615             */
3616            public void removeByU1_T(long userId1, int type) throws SystemException {
3617                    for (SocialRelation socialRelation : findByU1_T(userId1, type)) {
3618                            remove(socialRelation);
3619                    }
3620            }
3621    
3622            /**
3623             * Removes all the social relations where userId2 = &#63; and type = &#63; from the database.
3624             *
3625             * @param userId2 the user id2 to search with
3626             * @param type the type to search with
3627             * @throws SystemException if a system exception occurred
3628             */
3629            public void removeByU2_T(long userId2, int type) throws SystemException {
3630                    for (SocialRelation socialRelation : findByU2_T(userId2, type)) {
3631                            remove(socialRelation);
3632                    }
3633            }
3634    
3635            /**
3636             * Removes the social relation where userId1 = &#63; and userId2 = &#63; and type = &#63; from the database.
3637             *
3638             * @param userId1 the user id1 to search with
3639             * @param userId2 the user id2 to search with
3640             * @param type the type to search with
3641             * @throws SystemException if a system exception occurred
3642             */
3643            public void removeByU1_U2_T(long userId1, long userId2, int type)
3644                    throws NoSuchRelationException, SystemException {
3645                    SocialRelation socialRelation = findByU1_U2_T(userId1, userId2, type);
3646    
3647                    remove(socialRelation);
3648            }
3649    
3650            /**
3651             * Removes all the social relations from the database.
3652             *
3653             * @throws SystemException if a system exception occurred
3654             */
3655            public void removeAll() throws SystemException {
3656                    for (SocialRelation socialRelation : findAll()) {
3657                            remove(socialRelation);
3658                    }
3659            }
3660    
3661            /**
3662             * Counts all the social relations where uuid = &#63;.
3663             *
3664             * @param uuid the uuid to search with
3665             * @return the number of matching social relations
3666             * @throws SystemException if a system exception occurred
3667             */
3668            public int countByUuid(String uuid) throws SystemException {
3669                    Object[] finderArgs = new Object[] { uuid };
3670    
3671                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
3672                                    finderArgs, this);
3673    
3674                    if (count == null) {
3675                            Session session = null;
3676    
3677                            try {
3678                                    session = openSession();
3679    
3680                                    StringBundler query = new StringBundler(2);
3681    
3682                                    query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
3683    
3684                                    if (uuid == null) {
3685                                            query.append(_FINDER_COLUMN_UUID_UUID_1);
3686                                    }
3687                                    else {
3688                                            if (uuid.equals(StringPool.BLANK)) {
3689                                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
3690                                            }
3691                                            else {
3692                                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
3693                                            }
3694                                    }
3695    
3696                                    String sql = query.toString();
3697    
3698                                    Query q = session.createQuery(sql);
3699    
3700                                    QueryPos qPos = QueryPos.getInstance(q);
3701    
3702                                    if (uuid != null) {
3703                                            qPos.add(uuid);
3704                                    }
3705    
3706                                    count = (Long)q.uniqueResult();
3707                            }
3708                            catch (Exception e) {
3709                                    throw processException(e);
3710                            }
3711                            finally {
3712                                    if (count == null) {
3713                                            count = Long.valueOf(0);
3714                                    }
3715    
3716                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
3717                                            finderArgs, count);
3718    
3719                                    closeSession(session);
3720                            }
3721                    }
3722    
3723                    return count.intValue();
3724            }
3725    
3726            /**
3727             * Counts all the social relations where companyId = &#63;.
3728             *
3729             * @param companyId the company id to search with
3730             * @return the number of matching social relations
3731             * @throws SystemException if a system exception occurred
3732             */
3733            public int countByCompanyId(long companyId) throws SystemException {
3734                    Object[] finderArgs = new Object[] { companyId };
3735    
3736                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
3737                                    finderArgs, this);
3738    
3739                    if (count == null) {
3740                            Session session = null;
3741    
3742                            try {
3743                                    session = openSession();
3744    
3745                                    StringBundler query = new StringBundler(2);
3746    
3747                                    query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
3748    
3749                                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
3750    
3751                                    String sql = query.toString();
3752    
3753                                    Query q = session.createQuery(sql);
3754    
3755                                    QueryPos qPos = QueryPos.getInstance(q);
3756    
3757                                    qPos.add(companyId);
3758    
3759                                    count = (Long)q.uniqueResult();
3760                            }
3761                            catch (Exception e) {
3762                                    throw processException(e);
3763                            }
3764                            finally {
3765                                    if (count == null) {
3766                                            count = Long.valueOf(0);
3767                                    }
3768    
3769                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
3770                                            finderArgs, count);
3771    
3772                                    closeSession(session);
3773                            }
3774                    }
3775    
3776                    return count.intValue();
3777            }
3778    
3779            /**
3780             * Counts all the social relations where userId1 = &#63;.
3781             *
3782             * @param userId1 the user id1 to search with
3783             * @return the number of matching social relations
3784             * @throws SystemException if a system exception occurred
3785             */
3786            public int countByUserId1(long userId1) throws SystemException {
3787                    Object[] finderArgs = new Object[] { userId1 };
3788    
3789                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID1,
3790                                    finderArgs, this);
3791    
3792                    if (count == null) {
3793                            Session session = null;
3794    
3795                            try {
3796                                    session = openSession();
3797    
3798                                    StringBundler query = new StringBundler(2);
3799    
3800                                    query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
3801    
3802                                    query.append(_FINDER_COLUMN_USERID1_USERID1_2);
3803    
3804                                    String sql = query.toString();
3805    
3806                                    Query q = session.createQuery(sql);
3807    
3808                                    QueryPos qPos = QueryPos.getInstance(q);
3809    
3810                                    qPos.add(userId1);
3811    
3812                                    count = (Long)q.uniqueResult();
3813                            }
3814                            catch (Exception e) {
3815                                    throw processException(e);
3816                            }
3817                            finally {
3818                                    if (count == null) {
3819                                            count = Long.valueOf(0);
3820                                    }
3821    
3822                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID1,
3823                                            finderArgs, count);
3824    
3825                                    closeSession(session);
3826                            }
3827                    }
3828    
3829                    return count.intValue();
3830            }
3831    
3832            /**
3833             * Counts all the social relations where userId2 = &#63;.
3834             *
3835             * @param userId2 the user id2 to search with
3836             * @return the number of matching social relations
3837             * @throws SystemException if a system exception occurred
3838             */
3839            public int countByUserId2(long userId2) throws SystemException {
3840                    Object[] finderArgs = new Object[] { userId2 };
3841    
3842                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID2,
3843                                    finderArgs, this);
3844    
3845                    if (count == null) {
3846                            Session session = null;
3847    
3848                            try {
3849                                    session = openSession();
3850    
3851                                    StringBundler query = new StringBundler(2);
3852    
3853                                    query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
3854    
3855                                    query.append(_FINDER_COLUMN_USERID2_USERID2_2);
3856    
3857                                    String sql = query.toString();
3858    
3859                                    Query q = session.createQuery(sql);
3860    
3861                                    QueryPos qPos = QueryPos.getInstance(q);
3862    
3863                                    qPos.add(userId2);
3864    
3865                                    count = (Long)q.uniqueResult();
3866                            }
3867                            catch (Exception e) {
3868                                    throw processException(e);
3869                            }
3870                            finally {
3871                                    if (count == null) {
3872                                            count = Long.valueOf(0);
3873                                    }
3874    
3875                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID2,
3876                                            finderArgs, count);
3877    
3878                                    closeSession(session);
3879                            }
3880                    }
3881    
3882                    return count.intValue();
3883            }
3884    
3885            /**
3886             * Counts all the social relations where type = &#63;.
3887             *
3888             * @param type the type to search with
3889             * @return the number of matching social relations
3890             * @throws SystemException if a system exception occurred
3891             */
3892            public int countByType(int type) throws SystemException {
3893                    Object[] finderArgs = new Object[] { type };
3894    
3895                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_TYPE,
3896                                    finderArgs, this);
3897    
3898                    if (count == null) {
3899                            Session session = null;
3900    
3901                            try {
3902                                    session = openSession();
3903    
3904                                    StringBundler query = new StringBundler(2);
3905    
3906                                    query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
3907    
3908                                    query.append(_FINDER_COLUMN_TYPE_TYPE_2);
3909    
3910                                    String sql = query.toString();
3911    
3912                                    Query q = session.createQuery(sql);
3913    
3914                                    QueryPos qPos = QueryPos.getInstance(q);
3915    
3916                                    qPos.add(type);
3917    
3918                                    count = (Long)q.uniqueResult();
3919                            }
3920                            catch (Exception e) {
3921                                    throw processException(e);
3922                            }
3923                            finally {
3924                                    if (count == null) {
3925                                            count = Long.valueOf(0);
3926                                    }
3927    
3928                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_TYPE,
3929                                            finderArgs, count);
3930    
3931                                    closeSession(session);
3932                            }
3933                    }
3934    
3935                    return count.intValue();
3936            }
3937    
3938            /**
3939             * Counts all the social relations where companyId = &#63; and type = &#63;.
3940             *
3941             * @param companyId the company id to search with
3942             * @param type the type to search with
3943             * @return the number of matching social relations
3944             * @throws SystemException if a system exception occurred
3945             */
3946            public int countByC_T(long companyId, int type) throws SystemException {
3947                    Object[] finderArgs = new Object[] { companyId, type };
3948    
3949                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_T,
3950                                    finderArgs, this);
3951    
3952                    if (count == null) {
3953                            Session session = null;
3954    
3955                            try {
3956                                    session = openSession();
3957    
3958                                    StringBundler query = new StringBundler(3);
3959    
3960                                    query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
3961    
3962                                    query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
3963    
3964                                    query.append(_FINDER_COLUMN_C_T_TYPE_2);
3965    
3966                                    String sql = query.toString();
3967    
3968                                    Query q = session.createQuery(sql);
3969    
3970                                    QueryPos qPos = QueryPos.getInstance(q);
3971    
3972                                    qPos.add(companyId);
3973    
3974                                    qPos.add(type);
3975    
3976                                    count = (Long)q.uniqueResult();
3977                            }
3978                            catch (Exception e) {
3979                                    throw processException(e);
3980                            }
3981                            finally {
3982                                    if (count == null) {
3983                                            count = Long.valueOf(0);
3984                                    }
3985    
3986                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_T, finderArgs,
3987                                            count);
3988    
3989                                    closeSession(session);
3990                            }
3991                    }
3992    
3993                    return count.intValue();
3994            }
3995    
3996            /**
3997             * Counts all the social relations where userId1 = &#63; and type = &#63;.
3998             *
3999             * @param userId1 the user id1 to search with
4000             * @param type the type to search with
4001             * @return the number of matching social relations
4002             * @throws SystemException if a system exception occurred
4003             */
4004            public int countByU1_T(long userId1, int type) throws SystemException {
4005                    Object[] finderArgs = new Object[] { userId1, type };
4006    
4007                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U1_T,
4008                                    finderArgs, this);
4009    
4010                    if (count == null) {
4011                            Session session = null;
4012    
4013                            try {
4014                                    session = openSession();
4015    
4016                                    StringBundler query = new StringBundler(3);
4017    
4018                                    query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
4019    
4020                                    query.append(_FINDER_COLUMN_U1_T_USERID1_2);
4021    
4022                                    query.append(_FINDER_COLUMN_U1_T_TYPE_2);
4023    
4024                                    String sql = query.toString();
4025    
4026                                    Query q = session.createQuery(sql);
4027    
4028                                    QueryPos qPos = QueryPos.getInstance(q);
4029    
4030                                    qPos.add(userId1);
4031    
4032                                    qPos.add(type);
4033    
4034                                    count = (Long)q.uniqueResult();
4035                            }
4036                            catch (Exception e) {
4037                                    throw processException(e);
4038                            }
4039                            finally {
4040                                    if (count == null) {
4041                                            count = Long.valueOf(0);
4042                                    }
4043    
4044                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U1_T,
4045                                            finderArgs, count);
4046    
4047                                    closeSession(session);
4048                            }
4049                    }
4050    
4051                    return count.intValue();
4052            }
4053    
4054            /**
4055             * Counts all the social relations where userId2 = &#63; and type = &#63;.
4056             *
4057             * @param userId2 the user id2 to search with
4058             * @param type the type to search with
4059             * @return the number of matching social relations
4060             * @throws SystemException if a system exception occurred
4061             */
4062            public int countByU2_T(long userId2, int type) throws SystemException {
4063                    Object[] finderArgs = new Object[] { userId2, type };
4064    
4065                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U2_T,
4066                                    finderArgs, this);
4067    
4068                    if (count == null) {
4069                            Session session = null;
4070    
4071                            try {
4072                                    session = openSession();
4073    
4074                                    StringBundler query = new StringBundler(3);
4075    
4076                                    query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
4077    
4078                                    query.append(_FINDER_COLUMN_U2_T_USERID2_2);
4079    
4080                                    query.append(_FINDER_COLUMN_U2_T_TYPE_2);
4081    
4082                                    String sql = query.toString();
4083    
4084                                    Query q = session.createQuery(sql);
4085    
4086                                    QueryPos qPos = QueryPos.getInstance(q);
4087    
4088                                    qPos.add(userId2);
4089    
4090                                    qPos.add(type);
4091    
4092                                    count = (Long)q.uniqueResult();
4093                            }
4094                            catch (Exception e) {
4095                                    throw processException(e);
4096                            }
4097                            finally {
4098                                    if (count == null) {
4099                                            count = Long.valueOf(0);
4100                                    }
4101    
4102                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U2_T,
4103                                            finderArgs, count);
4104    
4105                                    closeSession(session);
4106                            }
4107                    }
4108    
4109                    return count.intValue();
4110            }
4111    
4112            /**
4113             * Counts all the social relations where userId1 = &#63; and userId2 = &#63; and type = &#63;.
4114             *
4115             * @param userId1 the user id1 to search with
4116             * @param userId2 the user id2 to search with
4117             * @param type the type to search with
4118             * @return the number of matching social relations
4119             * @throws SystemException if a system exception occurred
4120             */
4121            public int countByU1_U2_T(long userId1, long userId2, int type)
4122                    throws SystemException {
4123                    Object[] finderArgs = new Object[] { userId1, userId2, type };
4124    
4125                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U1_U2_T,
4126                                    finderArgs, this);
4127    
4128                    if (count == null) {
4129                            Session session = null;
4130    
4131                            try {
4132                                    session = openSession();
4133    
4134                                    StringBundler query = new StringBundler(4);
4135    
4136                                    query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
4137    
4138                                    query.append(_FINDER_COLUMN_U1_U2_T_USERID1_2);
4139    
4140                                    query.append(_FINDER_COLUMN_U1_U2_T_USERID2_2);
4141    
4142                                    query.append(_FINDER_COLUMN_U1_U2_T_TYPE_2);
4143    
4144                                    String sql = query.toString();
4145    
4146                                    Query q = session.createQuery(sql);
4147    
4148                                    QueryPos qPos = QueryPos.getInstance(q);
4149    
4150                                    qPos.add(userId1);
4151    
4152                                    qPos.add(userId2);
4153    
4154                                    qPos.add(type);
4155    
4156                                    count = (Long)q.uniqueResult();
4157                            }
4158                            catch (Exception e) {
4159                                    throw processException(e);
4160                            }
4161                            finally {
4162                                    if (count == null) {
4163                                            count = Long.valueOf(0);
4164                                    }
4165    
4166                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U1_U2_T,
4167                                            finderArgs, count);
4168    
4169                                    closeSession(session);
4170                            }
4171                    }
4172    
4173                    return count.intValue();
4174            }
4175    
4176            /**
4177             * Counts all the social relations.
4178             *
4179             * @return the number of social relations
4180             * @throws SystemException if a system exception occurred
4181             */
4182            public int countAll() throws SystemException {
4183                    Object[] finderArgs = new Object[0];
4184    
4185                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
4186                                    finderArgs, this);
4187    
4188                    if (count == null) {
4189                            Session session = null;
4190    
4191                            try {
4192                                    session = openSession();
4193    
4194                                    Query q = session.createQuery(_SQL_COUNT_SOCIALRELATION);
4195    
4196                                    count = (Long)q.uniqueResult();
4197                            }
4198                            catch (Exception e) {
4199                                    throw processException(e);
4200                            }
4201                            finally {
4202                                    if (count == null) {
4203                                            count = Long.valueOf(0);
4204                                    }
4205    
4206                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
4207                                            count);
4208    
4209                                    closeSession(session);
4210                            }
4211                    }
4212    
4213                    return count.intValue();
4214            }
4215    
4216            /**
4217             * Initializes the social relation persistence.
4218             */
4219            public void afterPropertiesSet() {
4220                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
4221                                            com.liferay.portal.util.PropsUtil.get(
4222                                                    "value.object.listener.com.liferay.portlet.social.model.SocialRelation")));
4223    
4224                    if (listenerClassNames.length > 0) {
4225                            try {
4226                                    List<ModelListener<SocialRelation>> listenersList = new ArrayList<ModelListener<SocialRelation>>();
4227    
4228                                    for (String listenerClassName : listenerClassNames) {
4229                                            listenersList.add((ModelListener<SocialRelation>)InstanceFactory.newInstance(
4230                                                            listenerClassName));
4231                                    }
4232    
4233                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
4234                            }
4235                            catch (Exception e) {
4236                                    _log.error(e);
4237                            }
4238                    }
4239            }
4240    
4241            @BeanReference(type = SocialActivityPersistence.class)
4242            protected SocialActivityPersistence socialActivityPersistence;
4243            @BeanReference(type = SocialEquityAssetEntryPersistence.class)
4244            protected SocialEquityAssetEntryPersistence socialEquityAssetEntryPersistence;
4245            @BeanReference(type = SocialEquityHistoryPersistence.class)
4246            protected SocialEquityHistoryPersistence socialEquityHistoryPersistence;
4247            @BeanReference(type = SocialEquityLogPersistence.class)
4248            protected SocialEquityLogPersistence socialEquityLogPersistence;
4249            @BeanReference(type = SocialEquitySettingPersistence.class)
4250            protected SocialEquitySettingPersistence socialEquitySettingPersistence;
4251            @BeanReference(type = SocialEquityUserPersistence.class)
4252            protected SocialEquityUserPersistence socialEquityUserPersistence;
4253            @BeanReference(type = SocialRelationPersistence.class)
4254            protected SocialRelationPersistence socialRelationPersistence;
4255            @BeanReference(type = SocialRequestPersistence.class)
4256            protected SocialRequestPersistence socialRequestPersistence;
4257            @BeanReference(type = ResourcePersistence.class)
4258            protected ResourcePersistence resourcePersistence;
4259            @BeanReference(type = UserPersistence.class)
4260            protected UserPersistence userPersistence;
4261            private static final String _SQL_SELECT_SOCIALRELATION = "SELECT socialRelation FROM SocialRelation socialRelation";
4262            private static final String _SQL_SELECT_SOCIALRELATION_WHERE = "SELECT socialRelation FROM SocialRelation socialRelation WHERE ";
4263            private static final String _SQL_COUNT_SOCIALRELATION = "SELECT COUNT(socialRelation) FROM SocialRelation socialRelation";
4264            private static final String _SQL_COUNT_SOCIALRELATION_WHERE = "SELECT COUNT(socialRelation) FROM SocialRelation socialRelation WHERE ";
4265            private static final String _FINDER_COLUMN_UUID_UUID_1 = "socialRelation.uuid IS NULL";
4266            private static final String _FINDER_COLUMN_UUID_UUID_2 = "socialRelation.uuid = ?";
4267            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(socialRelation.uuid IS NULL OR socialRelation.uuid = ?)";
4268            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "socialRelation.companyId = ?";
4269            private static final String _FINDER_COLUMN_USERID1_USERID1_2 = "socialRelation.userId1 = ?";
4270            private static final String _FINDER_COLUMN_USERID2_USERID2_2 = "socialRelation.userId2 = ?";
4271            private static final String _FINDER_COLUMN_TYPE_TYPE_2 = "socialRelation.type = ?";
4272            private static final String _FINDER_COLUMN_C_T_COMPANYID_2 = "socialRelation.companyId = ? AND ";
4273            private static final String _FINDER_COLUMN_C_T_TYPE_2 = "socialRelation.type = ?";
4274            private static final String _FINDER_COLUMN_U1_T_USERID1_2 = "socialRelation.userId1 = ? AND ";
4275            private static final String _FINDER_COLUMN_U1_T_TYPE_2 = "socialRelation.type = ?";
4276            private static final String _FINDER_COLUMN_U2_T_USERID2_2 = "socialRelation.userId2 = ? AND ";
4277            private static final String _FINDER_COLUMN_U2_T_TYPE_2 = "socialRelation.type = ?";
4278            private static final String _FINDER_COLUMN_U1_U2_T_USERID1_2 = "socialRelation.userId1 = ? AND ";
4279            private static final String _FINDER_COLUMN_U1_U2_T_USERID2_2 = "socialRelation.userId2 = ? AND ";
4280            private static final String _FINDER_COLUMN_U1_U2_T_TYPE_2 = "socialRelation.type = ?";
4281            private static final String _ORDER_BY_ENTITY_ALIAS = "socialRelation.";
4282            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No SocialRelation exists with the primary key ";
4283            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No SocialRelation exists with the key {";
4284            private static Log _log = LogFactoryUtil.getLog(SocialRelationPersistenceImpl.class);
4285    }