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