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