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