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