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