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