1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portlet.social.service.persistence;
24  
25  import com.liferay.portal.NoSuchModelException;
26  import com.liferay.portal.SystemException;
27  import com.liferay.portal.kernel.annotation.BeanReference;
28  import com.liferay.portal.kernel.cache.CacheRegistry;
29  import com.liferay.portal.kernel.dao.orm.DynamicQuery;
30  import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
31  import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
32  import com.liferay.portal.kernel.dao.orm.FinderPath;
33  import com.liferay.portal.kernel.dao.orm.Query;
34  import com.liferay.portal.kernel.dao.orm.QueryPos;
35  import com.liferay.portal.kernel.dao.orm.QueryUtil;
36  import com.liferay.portal.kernel.dao.orm.Session;
37  import com.liferay.portal.kernel.log.Log;
38  import com.liferay.portal.kernel.log.LogFactoryUtil;
39  import com.liferay.portal.kernel.util.GetterUtil;
40  import com.liferay.portal.kernel.util.OrderByComparator;
41  import com.liferay.portal.kernel.util.StringBundler;
42  import com.liferay.portal.kernel.util.StringPool;
43  import com.liferay.portal.kernel.util.StringUtil;
44  import com.liferay.portal.kernel.util.Validator;
45  import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
46  import com.liferay.portal.model.ModelListener;
47  import com.liferay.portal.service.persistence.BatchSessionUtil;
48  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
49  
50  import com.liferay.portlet.social.NoSuchRelationException;
51  import com.liferay.portlet.social.model.SocialRelation;
52  import com.liferay.portlet.social.model.impl.SocialRelationImpl;
53  import com.liferay.portlet.social.model.impl.SocialRelationModelImpl;
54  
55  import java.io.Serializable;
56  
57  import java.util.ArrayList;
58  import java.util.Collections;
59  import java.util.List;
60  
61  /**
62   * <a href="SocialRelationPersistenceImpl.java.html"><b><i>View Source</i></b></a>
63   *
64   * <p>
65   * ServiceBuilder generated this class. Modifications in this class will be
66   * overwritten the next time is generated.
67   * </p>
68   *
69   * @author    Brian Wing Shun Chan
70   * @see       SocialRelationPersistence
71   * @see       SocialRelationUtil
72   * @generated
73   */
74  public class SocialRelationPersistenceImpl extends BasePersistenceImpl<SocialRelation>
75      implements SocialRelationPersistence {
76      public static final String FINDER_CLASS_NAME_ENTITY = SocialRelationImpl.class.getName();
77      public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
78          ".List";
79      public static final FinderPath FINDER_PATH_FIND_BY_UUID = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
80              SocialRelationModelImpl.FINDER_CACHE_ENABLED,
81              FINDER_CLASS_NAME_LIST, "findByUuid",
82              new String[] { String.class.getName() });
83      public static final FinderPath FINDER_PATH_FIND_BY_OBC_UUID = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
84              SocialRelationModelImpl.FINDER_CACHE_ENABLED,
85              FINDER_CLASS_NAME_LIST, "findByUuid",
86              new String[] {
87                  String.class.getName(),
88                  
89              "java.lang.Integer", "java.lang.Integer",
90                  "com.liferay.portal.kernel.util.OrderByComparator"
91              });
92      public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
93              SocialRelationModelImpl.FINDER_CACHE_ENABLED,
94              FINDER_CLASS_NAME_LIST, "countByUuid",
95              new String[] { String.class.getName() });
96      public static final FinderPath FINDER_PATH_FIND_BY_COMPANYID = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
97              SocialRelationModelImpl.FINDER_CACHE_ENABLED,
98              FINDER_CLASS_NAME_LIST, "findByCompanyId",
99              new String[] { Long.class.getName() });
100     public static final FinderPath FINDER_PATH_FIND_BY_OBC_COMPANYID = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
101             SocialRelationModelImpl.FINDER_CACHE_ENABLED,
102             FINDER_CLASS_NAME_LIST, "findByCompanyId",
103             new String[] {
104                 Long.class.getName(),
105                 
106             "java.lang.Integer", "java.lang.Integer",
107                 "com.liferay.portal.kernel.util.OrderByComparator"
108             });
109     public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
110             SocialRelationModelImpl.FINDER_CACHE_ENABLED,
111             FINDER_CLASS_NAME_LIST, "countByCompanyId",
112             new String[] { Long.class.getName() });
113     public static final FinderPath FINDER_PATH_FIND_BY_USERID1 = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
114             SocialRelationModelImpl.FINDER_CACHE_ENABLED,
115             FINDER_CLASS_NAME_LIST, "findByUserId1",
116             new String[] { Long.class.getName() });
117     public static final FinderPath FINDER_PATH_FIND_BY_OBC_USERID1 = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
118             SocialRelationModelImpl.FINDER_CACHE_ENABLED,
119             FINDER_CLASS_NAME_LIST, "findByUserId1",
120             new String[] {
121                 Long.class.getName(),
122                 
123             "java.lang.Integer", "java.lang.Integer",
124                 "com.liferay.portal.kernel.util.OrderByComparator"
125             });
126     public static final FinderPath FINDER_PATH_COUNT_BY_USERID1 = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
127             SocialRelationModelImpl.FINDER_CACHE_ENABLED,
128             FINDER_CLASS_NAME_LIST, "countByUserId1",
129             new String[] { Long.class.getName() });
130     public static final FinderPath FINDER_PATH_FIND_BY_USERID2 = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
131             SocialRelationModelImpl.FINDER_CACHE_ENABLED,
132             FINDER_CLASS_NAME_LIST, "findByUserId2",
133             new String[] { Long.class.getName() });
134     public static final FinderPath FINDER_PATH_FIND_BY_OBC_USERID2 = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
135             SocialRelationModelImpl.FINDER_CACHE_ENABLED,
136             FINDER_CLASS_NAME_LIST, "findByUserId2",
137             new String[] {
138                 Long.class.getName(),
139                 
140             "java.lang.Integer", "java.lang.Integer",
141                 "com.liferay.portal.kernel.util.OrderByComparator"
142             });
143     public static final FinderPath FINDER_PATH_COUNT_BY_USERID2 = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
144             SocialRelationModelImpl.FINDER_CACHE_ENABLED,
145             FINDER_CLASS_NAME_LIST, "countByUserId2",
146             new String[] { Long.class.getName() });
147     public static final FinderPath FINDER_PATH_FIND_BY_TYPE = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
148             SocialRelationModelImpl.FINDER_CACHE_ENABLED,
149             FINDER_CLASS_NAME_LIST, "findByType",
150             new String[] { Integer.class.getName() });
151     public static final FinderPath FINDER_PATH_FIND_BY_OBC_TYPE = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
152             SocialRelationModelImpl.FINDER_CACHE_ENABLED,
153             FINDER_CLASS_NAME_LIST, "findByType",
154             new String[] {
155                 Integer.class.getName(),
156                 
157             "java.lang.Integer", "java.lang.Integer",
158                 "com.liferay.portal.kernel.util.OrderByComparator"
159             });
160     public static final FinderPath FINDER_PATH_COUNT_BY_TYPE = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
161             SocialRelationModelImpl.FINDER_CACHE_ENABLED,
162             FINDER_CLASS_NAME_LIST, "countByType",
163             new String[] { Integer.class.getName() });
164     public static final FinderPath FINDER_PATH_FIND_BY_C_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
165             SocialRelationModelImpl.FINDER_CACHE_ENABLED,
166             FINDER_CLASS_NAME_LIST, "findByC_T",
167             new String[] { Long.class.getName(), Integer.class.getName() });
168     public static final FinderPath FINDER_PATH_FIND_BY_OBC_C_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
169             SocialRelationModelImpl.FINDER_CACHE_ENABLED,
170             FINDER_CLASS_NAME_LIST, "findByC_T",
171             new String[] {
172                 Long.class.getName(), Integer.class.getName(),
173                 
174             "java.lang.Integer", "java.lang.Integer",
175                 "com.liferay.portal.kernel.util.OrderByComparator"
176             });
177     public static final FinderPath FINDER_PATH_COUNT_BY_C_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
178             SocialRelationModelImpl.FINDER_CACHE_ENABLED,
179             FINDER_CLASS_NAME_LIST, "countByC_T",
180             new String[] { Long.class.getName(), Integer.class.getName() });
181     public static final FinderPath FINDER_PATH_FIND_BY_U1_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
182             SocialRelationModelImpl.FINDER_CACHE_ENABLED,
183             FINDER_CLASS_NAME_LIST, "findByU1_T",
184             new String[] { Long.class.getName(), Integer.class.getName() });
185     public static final FinderPath FINDER_PATH_FIND_BY_OBC_U1_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
186             SocialRelationModelImpl.FINDER_CACHE_ENABLED,
187             FINDER_CLASS_NAME_LIST, "findByU1_T",
188             new String[] {
189                 Long.class.getName(), Integer.class.getName(),
190                 
191             "java.lang.Integer", "java.lang.Integer",
192                 "com.liferay.portal.kernel.util.OrderByComparator"
193             });
194     public static final FinderPath FINDER_PATH_COUNT_BY_U1_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
195             SocialRelationModelImpl.FINDER_CACHE_ENABLED,
196             FINDER_CLASS_NAME_LIST, "countByU1_T",
197             new String[] { Long.class.getName(), Integer.class.getName() });
198     public static final FinderPath FINDER_PATH_FIND_BY_U2_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
199             SocialRelationModelImpl.FINDER_CACHE_ENABLED,
200             FINDER_CLASS_NAME_LIST, "findByU2_T",
201             new String[] { Long.class.getName(), Integer.class.getName() });
202     public static final FinderPath FINDER_PATH_FIND_BY_OBC_U2_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
203             SocialRelationModelImpl.FINDER_CACHE_ENABLED,
204             FINDER_CLASS_NAME_LIST, "findByU2_T",
205             new String[] {
206                 Long.class.getName(), Integer.class.getName(),
207                 
208             "java.lang.Integer", "java.lang.Integer",
209                 "com.liferay.portal.kernel.util.OrderByComparator"
210             });
211     public static final FinderPath FINDER_PATH_COUNT_BY_U2_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
212             SocialRelationModelImpl.FINDER_CACHE_ENABLED,
213             FINDER_CLASS_NAME_LIST, "countByU2_T",
214             new String[] { Long.class.getName(), Integer.class.getName() });
215     public static final FinderPath FINDER_PATH_FETCH_BY_U1_U2_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
216             SocialRelationModelImpl.FINDER_CACHE_ENABLED,
217             FINDER_CLASS_NAME_ENTITY, "fetchByU1_U2_T",
218             new String[] {
219                 Long.class.getName(), Long.class.getName(),
220                 Integer.class.getName()
221             });
222     public static final FinderPath FINDER_PATH_COUNT_BY_U1_U2_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
223             SocialRelationModelImpl.FINDER_CACHE_ENABLED,
224             FINDER_CLASS_NAME_LIST, "countByU1_U2_T",
225             new String[] {
226                 Long.class.getName(), Long.class.getName(),
227                 Integer.class.getName()
228             });
229     public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
230             SocialRelationModelImpl.FINDER_CACHE_ENABLED,
231             FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
232     public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
233             SocialRelationModelImpl.FINDER_CACHE_ENABLED,
234             FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
235 
236     public void cacheResult(SocialRelation socialRelation) {
237         EntityCacheUtil.putResult(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
238             SocialRelationImpl.class, socialRelation.getPrimaryKey(),
239             socialRelation);
240 
241         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U1_U2_T,
242             new Object[] {
243                 new Long(socialRelation.getUserId1()),
244                 new Long(socialRelation.getUserId2()),
245                 new Integer(socialRelation.getType())
246             }, socialRelation);
247     }
248 
249     public void cacheResult(List<SocialRelation> socialRelations) {
250         for (SocialRelation socialRelation : socialRelations) {
251             if (EntityCacheUtil.getResult(
252                         SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
253                         SocialRelationImpl.class,
254                         socialRelation.getPrimaryKey(), this) == null) {
255                 cacheResult(socialRelation);
256             }
257         }
258     }
259 
260     public void clearCache() {
261         CacheRegistry.clear(SocialRelationImpl.class.getName());
262         EntityCacheUtil.clearCache(SocialRelationImpl.class.getName());
263         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
264         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
265     }
266 
267     public SocialRelation create(long relationId) {
268         SocialRelation socialRelation = new SocialRelationImpl();
269 
270         socialRelation.setNew(true);
271         socialRelation.setPrimaryKey(relationId);
272 
273         String uuid = PortalUUIDUtil.generate();
274 
275         socialRelation.setUuid(uuid);
276 
277         return socialRelation;
278     }
279 
280     public SocialRelation remove(Serializable primaryKey)
281         throws NoSuchModelException, SystemException {
282         return remove(((Long)primaryKey).longValue());
283     }
284 
285     public SocialRelation remove(long relationId)
286         throws NoSuchRelationException, SystemException {
287         Session session = null;
288 
289         try {
290             session = openSession();
291 
292             SocialRelation socialRelation = (SocialRelation)session.get(SocialRelationImpl.class,
293                     new Long(relationId));
294 
295             if (socialRelation == null) {
296                 if (_log.isWarnEnabled()) {
297                     _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + relationId);
298                 }
299 
300                 throw new NoSuchRelationException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
301                     relationId);
302             }
303 
304             return remove(socialRelation);
305         }
306         catch (NoSuchRelationException nsee) {
307             throw nsee;
308         }
309         catch (Exception e) {
310             throw processException(e);
311         }
312         finally {
313             closeSession(session);
314         }
315     }
316 
317     public SocialRelation remove(SocialRelation socialRelation)
318         throws SystemException {
319         for (ModelListener<SocialRelation> listener : listeners) {
320             listener.onBeforeRemove(socialRelation);
321         }
322 
323         socialRelation = removeImpl(socialRelation);
324 
325         for (ModelListener<SocialRelation> listener : listeners) {
326             listener.onAfterRemove(socialRelation);
327         }
328 
329         return socialRelation;
330     }
331 
332     protected SocialRelation removeImpl(SocialRelation socialRelation)
333         throws SystemException {
334         socialRelation = toUnwrappedModel(socialRelation);
335 
336         Session session = null;
337 
338         try {
339             session = openSession();
340 
341             if (socialRelation.isCachedModel() || BatchSessionUtil.isEnabled()) {
342                 Object staleObject = session.get(SocialRelationImpl.class,
343                         socialRelation.getPrimaryKeyObj());
344 
345                 if (staleObject != null) {
346                     session.evict(staleObject);
347                 }
348             }
349 
350             session.delete(socialRelation);
351 
352             session.flush();
353         }
354         catch (Exception e) {
355             throw processException(e);
356         }
357         finally {
358             closeSession(session);
359         }
360 
361         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
362 
363         SocialRelationModelImpl socialRelationModelImpl = (SocialRelationModelImpl)socialRelation;
364 
365         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U1_U2_T,
366             new Object[] {
367                 new Long(socialRelationModelImpl.getOriginalUserId1()),
368                 new Long(socialRelationModelImpl.getOriginalUserId2()),
369                 new Integer(socialRelationModelImpl.getOriginalType())
370             });
371 
372         EntityCacheUtil.removeResult(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
373             SocialRelationImpl.class, socialRelation.getPrimaryKey());
374 
375         return socialRelation;
376     }
377 
378     /**
379      * @deprecated Use {@link BasePersistence#update(com.liferay.portal.model.BaseModel, boolean)}.
380      */
381     public SocialRelation update(SocialRelation socialRelation)
382         throws SystemException {
383         if (_log.isWarnEnabled()) {
384             _log.warn(
385                 "Using the deprecated update(SocialRelation socialRelation) method. Use update(SocialRelation socialRelation, boolean merge) instead.");
386         }
387 
388         return update(socialRelation, false);
389     }
390 
391     public SocialRelation updateImpl(
392         com.liferay.portlet.social.model.SocialRelation socialRelation,
393         boolean merge) throws SystemException {
394         socialRelation = toUnwrappedModel(socialRelation);
395 
396         boolean isNew = socialRelation.isNew();
397 
398         SocialRelationModelImpl socialRelationModelImpl = (SocialRelationModelImpl)socialRelation;
399 
400         if (Validator.isNull(socialRelation.getUuid())) {
401             String uuid = PortalUUIDUtil.generate();
402 
403             socialRelation.setUuid(uuid);
404         }
405 
406         Session session = null;
407 
408         try {
409             session = openSession();
410 
411             BatchSessionUtil.update(session, socialRelation, merge);
412 
413             socialRelation.setNew(false);
414         }
415         catch (Exception e) {
416             throw processException(e);
417         }
418         finally {
419             closeSession(session);
420         }
421 
422         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
423 
424         EntityCacheUtil.putResult(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
425             SocialRelationImpl.class, socialRelation.getPrimaryKey(),
426             socialRelation);
427 
428         if (!isNew &&
429                 ((socialRelation.getUserId1() != socialRelationModelImpl.getOriginalUserId1()) ||
430                 (socialRelation.getUserId2() != socialRelationModelImpl.getOriginalUserId2()) ||
431                 (socialRelation.getType() != socialRelationModelImpl.getOriginalType()))) {
432             FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U1_U2_T,
433                 new Object[] {
434                     new Long(socialRelationModelImpl.getOriginalUserId1()),
435                     new Long(socialRelationModelImpl.getOriginalUserId2()),
436                     new Integer(socialRelationModelImpl.getOriginalType())
437                 });
438         }
439 
440         if (isNew ||
441                 ((socialRelation.getUserId1() != socialRelationModelImpl.getOriginalUserId1()) ||
442                 (socialRelation.getUserId2() != socialRelationModelImpl.getOriginalUserId2()) ||
443                 (socialRelation.getType() != socialRelationModelImpl.getOriginalType()))) {
444             FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U1_U2_T,
445                 new Object[] {
446                     new Long(socialRelation.getUserId1()),
447                     new Long(socialRelation.getUserId2()),
448                     new Integer(socialRelation.getType())
449                 }, socialRelation);
450         }
451 
452         return socialRelation;
453     }
454 
455     protected SocialRelation toUnwrappedModel(SocialRelation socialRelation) {
456         if (socialRelation instanceof SocialRelationImpl) {
457             return socialRelation;
458         }
459 
460         SocialRelationImpl socialRelationImpl = new SocialRelationImpl();
461 
462         socialRelationImpl.setNew(socialRelation.isNew());
463         socialRelationImpl.setPrimaryKey(socialRelation.getPrimaryKey());
464 
465         socialRelationImpl.setUuid(socialRelation.getUuid());
466         socialRelationImpl.setRelationId(socialRelation.getRelationId());
467         socialRelationImpl.setCompanyId(socialRelation.getCompanyId());
468         socialRelationImpl.setCreateDate(socialRelation.getCreateDate());
469         socialRelationImpl.setUserId1(socialRelation.getUserId1());
470         socialRelationImpl.setUserId2(socialRelation.getUserId2());
471         socialRelationImpl.setType(socialRelation.getType());
472 
473         return socialRelationImpl;
474     }
475 
476     public SocialRelation findByPrimaryKey(Serializable primaryKey)
477         throws NoSuchModelException, SystemException {
478         return findByPrimaryKey(((Long)primaryKey).longValue());
479     }
480 
481     public SocialRelation findByPrimaryKey(long relationId)
482         throws NoSuchRelationException, SystemException {
483         SocialRelation socialRelation = fetchByPrimaryKey(relationId);
484 
485         if (socialRelation == null) {
486             if (_log.isWarnEnabled()) {
487                 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + relationId);
488             }
489 
490             throw new NoSuchRelationException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
491                 relationId);
492         }
493 
494         return socialRelation;
495     }
496 
497     public SocialRelation fetchByPrimaryKey(Serializable primaryKey)
498         throws SystemException {
499         return fetchByPrimaryKey(((Long)primaryKey).longValue());
500     }
501 
502     public SocialRelation fetchByPrimaryKey(long relationId)
503         throws SystemException {
504         SocialRelation socialRelation = (SocialRelation)EntityCacheUtil.getResult(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
505                 SocialRelationImpl.class, relationId, this);
506 
507         if (socialRelation == null) {
508             Session session = null;
509 
510             try {
511                 session = openSession();
512 
513                 socialRelation = (SocialRelation)session.get(SocialRelationImpl.class,
514                         new Long(relationId));
515             }
516             catch (Exception e) {
517                 throw processException(e);
518             }
519             finally {
520                 if (socialRelation != null) {
521                     cacheResult(socialRelation);
522                 }
523 
524                 closeSession(session);
525             }
526         }
527 
528         return socialRelation;
529     }
530 
531     public List<SocialRelation> findByUuid(String uuid)
532         throws SystemException {
533         Object[] finderArgs = new Object[] { uuid };
534 
535         List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_UUID,
536                 finderArgs, this);
537 
538         if (list == null) {
539             Session session = null;
540 
541             try {
542                 session = openSession();
543 
544                 StringBundler query = new StringBundler(2);
545 
546                 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
547 
548                 if (uuid == null) {
549                     query.append(_FINDER_COLUMN_UUID_UUID_1);
550                 }
551                 else {
552                     if (uuid.equals(StringPool.BLANK)) {
553                         query.append(_FINDER_COLUMN_UUID_UUID_3);
554                     }
555                     else {
556                         query.append(_FINDER_COLUMN_UUID_UUID_2);
557                     }
558                 }
559 
560                 String sql = query.toString();
561 
562                 Query q = session.createQuery(sql);
563 
564                 QueryPos qPos = QueryPos.getInstance(q);
565 
566                 if (uuid != null) {
567                     qPos.add(uuid);
568                 }
569 
570                 list = q.list();
571             }
572             catch (Exception e) {
573                 throw processException(e);
574             }
575             finally {
576                 if (list == null) {
577                     list = new ArrayList<SocialRelation>();
578                 }
579 
580                 cacheResult(list);
581 
582                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_UUID, finderArgs,
583                     list);
584 
585                 closeSession(session);
586             }
587         }
588 
589         return list;
590     }
591 
592     public List<SocialRelation> findByUuid(String uuid, int start, int end)
593         throws SystemException {
594         return findByUuid(uuid, start, end, null);
595     }
596 
597     public List<SocialRelation> findByUuid(String uuid, int start, int end,
598         OrderByComparator obc) throws SystemException {
599         Object[] finderArgs = new Object[] {
600                 uuid,
601                 
602                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
603             };
604 
605         List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_UUID,
606                 finderArgs, this);
607 
608         if (list == null) {
609             Session session = null;
610 
611             try {
612                 session = openSession();
613 
614                 StringBundler query = null;
615 
616                 if (obc != null) {
617                     query = new StringBundler(3 +
618                             (obc.getOrderByFields().length * 3));
619                 }
620                 else {
621                     query = new StringBundler(2);
622                 }
623 
624                 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
625 
626                 if (uuid == null) {
627                     query.append(_FINDER_COLUMN_UUID_UUID_1);
628                 }
629                 else {
630                     if (uuid.equals(StringPool.BLANK)) {
631                         query.append(_FINDER_COLUMN_UUID_UUID_3);
632                     }
633                     else {
634                         query.append(_FINDER_COLUMN_UUID_UUID_2);
635                     }
636                 }
637 
638                 if (obc != null) {
639                     appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
640                 }
641 
642                 String sql = query.toString();
643 
644                 Query q = session.createQuery(sql);
645 
646                 QueryPos qPos = QueryPos.getInstance(q);
647 
648                 if (uuid != null) {
649                     qPos.add(uuid);
650                 }
651 
652                 list = (List<SocialRelation>)QueryUtil.list(q, getDialect(),
653                         start, end);
654             }
655             catch (Exception e) {
656                 throw processException(e);
657             }
658             finally {
659                 if (list == null) {
660                     list = new ArrayList<SocialRelation>();
661                 }
662 
663                 cacheResult(list);
664 
665                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_UUID,
666                     finderArgs, list);
667 
668                 closeSession(session);
669             }
670         }
671 
672         return list;
673     }
674 
675     public SocialRelation findByUuid_First(String uuid, OrderByComparator obc)
676         throws NoSuchRelationException, SystemException {
677         List<SocialRelation> list = findByUuid(uuid, 0, 1, obc);
678 
679         if (list.isEmpty()) {
680             StringBundler msg = new StringBundler(4);
681 
682             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
683 
684             msg.append("uuid=");
685             msg.append(uuid);
686 
687             msg.append(StringPool.CLOSE_CURLY_BRACE);
688 
689             throw new NoSuchRelationException(msg.toString());
690         }
691         else {
692             return list.get(0);
693         }
694     }
695 
696     public SocialRelation findByUuid_Last(String uuid, OrderByComparator obc)
697         throws NoSuchRelationException, SystemException {
698         int count = countByUuid(uuid);
699 
700         List<SocialRelation> list = findByUuid(uuid, count - 1, count, obc);
701 
702         if (list.isEmpty()) {
703             StringBundler msg = new StringBundler(4);
704 
705             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
706 
707             msg.append("uuid=");
708             msg.append(uuid);
709 
710             msg.append(StringPool.CLOSE_CURLY_BRACE);
711 
712             throw new NoSuchRelationException(msg.toString());
713         }
714         else {
715             return list.get(0);
716         }
717     }
718 
719     public SocialRelation[] findByUuid_PrevAndNext(long relationId,
720         String uuid, OrderByComparator obc)
721         throws NoSuchRelationException, SystemException {
722         SocialRelation socialRelation = findByPrimaryKey(relationId);
723 
724         int count = countByUuid(uuid);
725 
726         Session session = null;
727 
728         try {
729             session = openSession();
730 
731             StringBundler query = null;
732 
733             if (obc != null) {
734                 query = new StringBundler(3 +
735                         (obc.getOrderByFields().length * 3));
736             }
737             else {
738                 query = new StringBundler(2);
739             }
740 
741             query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
742 
743             if (uuid == null) {
744                 query.append(_FINDER_COLUMN_UUID_UUID_1);
745             }
746             else {
747                 if (uuid.equals(StringPool.BLANK)) {
748                     query.append(_FINDER_COLUMN_UUID_UUID_3);
749                 }
750                 else {
751                     query.append(_FINDER_COLUMN_UUID_UUID_2);
752                 }
753             }
754 
755             if (obc != null) {
756                 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
757             }
758 
759             String sql = query.toString();
760 
761             Query q = session.createQuery(sql);
762 
763             QueryPos qPos = QueryPos.getInstance(q);
764 
765             if (uuid != null) {
766                 qPos.add(uuid);
767             }
768 
769             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
770                     socialRelation);
771 
772             SocialRelation[] array = new SocialRelationImpl[3];
773 
774             array[0] = (SocialRelation)objArray[0];
775             array[1] = (SocialRelation)objArray[1];
776             array[2] = (SocialRelation)objArray[2];
777 
778             return array;
779         }
780         catch (Exception e) {
781             throw processException(e);
782         }
783         finally {
784             closeSession(session);
785         }
786     }
787 
788     public List<SocialRelation> findByCompanyId(long companyId)
789         throws SystemException {
790         Object[] finderArgs = new Object[] { new Long(companyId) };
791 
792         List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_COMPANYID,
793                 finderArgs, this);
794 
795         if (list == null) {
796             Session session = null;
797 
798             try {
799                 session = openSession();
800 
801                 StringBundler query = new StringBundler(2);
802 
803                 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
804 
805                 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
806 
807                 String sql = query.toString();
808 
809                 Query q = session.createQuery(sql);
810 
811                 QueryPos qPos = QueryPos.getInstance(q);
812 
813                 qPos.add(companyId);
814 
815                 list = q.list();
816             }
817             catch (Exception e) {
818                 throw processException(e);
819             }
820             finally {
821                 if (list == null) {
822                     list = new ArrayList<SocialRelation>();
823                 }
824 
825                 cacheResult(list);
826 
827                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_COMPANYID,
828                     finderArgs, list);
829 
830                 closeSession(session);
831             }
832         }
833 
834         return list;
835     }
836 
837     public List<SocialRelation> findByCompanyId(long companyId, int start,
838         int end) throws SystemException {
839         return findByCompanyId(companyId, start, end, null);
840     }
841 
842     public List<SocialRelation> findByCompanyId(long companyId, int start,
843         int end, OrderByComparator obc) throws SystemException {
844         Object[] finderArgs = new Object[] {
845                 new Long(companyId),
846                 
847                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
848             };
849 
850         List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_COMPANYID,
851                 finderArgs, this);
852 
853         if (list == null) {
854             Session session = null;
855 
856             try {
857                 session = openSession();
858 
859                 StringBundler query = null;
860 
861                 if (obc != null) {
862                     query = new StringBundler(3 +
863                             (obc.getOrderByFields().length * 3));
864                 }
865                 else {
866                     query = new StringBundler(2);
867                 }
868 
869                 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
870 
871                 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
872 
873                 if (obc != null) {
874                     appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
875                 }
876 
877                 String sql = query.toString();
878 
879                 Query q = session.createQuery(sql);
880 
881                 QueryPos qPos = QueryPos.getInstance(q);
882 
883                 qPos.add(companyId);
884 
885                 list = (List<SocialRelation>)QueryUtil.list(q, getDialect(),
886                         start, end);
887             }
888             catch (Exception e) {
889                 throw processException(e);
890             }
891             finally {
892                 if (list == null) {
893                     list = new ArrayList<SocialRelation>();
894                 }
895 
896                 cacheResult(list);
897 
898                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_COMPANYID,
899                     finderArgs, list);
900 
901                 closeSession(session);
902             }
903         }
904 
905         return list;
906     }
907 
908     public SocialRelation findByCompanyId_First(long companyId,
909         OrderByComparator obc) throws NoSuchRelationException, SystemException {
910         List<SocialRelation> list = findByCompanyId(companyId, 0, 1, obc);
911 
912         if (list.isEmpty()) {
913             StringBundler msg = new StringBundler(4);
914 
915             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
916 
917             msg.append("companyId=");
918             msg.append(companyId);
919 
920             msg.append(StringPool.CLOSE_CURLY_BRACE);
921 
922             throw new NoSuchRelationException(msg.toString());
923         }
924         else {
925             return list.get(0);
926         }
927     }
928 
929     public SocialRelation findByCompanyId_Last(long companyId,
930         OrderByComparator obc) throws NoSuchRelationException, SystemException {
931         int count = countByCompanyId(companyId);
932 
933         List<SocialRelation> list = findByCompanyId(companyId, count - 1,
934                 count, obc);
935 
936         if (list.isEmpty()) {
937             StringBundler msg = new StringBundler(4);
938 
939             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
940 
941             msg.append("companyId=");
942             msg.append(companyId);
943 
944             msg.append(StringPool.CLOSE_CURLY_BRACE);
945 
946             throw new NoSuchRelationException(msg.toString());
947         }
948         else {
949             return list.get(0);
950         }
951     }
952 
953     public SocialRelation[] findByCompanyId_PrevAndNext(long relationId,
954         long companyId, OrderByComparator obc)
955         throws NoSuchRelationException, SystemException {
956         SocialRelation socialRelation = findByPrimaryKey(relationId);
957 
958         int count = countByCompanyId(companyId);
959 
960         Session session = null;
961 
962         try {
963             session = openSession();
964 
965             StringBundler query = null;
966 
967             if (obc != null) {
968                 query = new StringBundler(3 +
969                         (obc.getOrderByFields().length * 3));
970             }
971             else {
972                 query = new StringBundler(2);
973             }
974 
975             query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
976 
977             query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
978 
979             if (obc != null) {
980                 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
981             }
982 
983             String sql = query.toString();
984 
985             Query q = session.createQuery(sql);
986 
987             QueryPos qPos = QueryPos.getInstance(q);
988 
989             qPos.add(companyId);
990 
991             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
992                     socialRelation);
993 
994             SocialRelation[] array = new SocialRelationImpl[3];
995 
996             array[0] = (SocialRelation)objArray[0];
997             array[1] = (SocialRelation)objArray[1];
998             array[2] = (SocialRelation)objArray[2];
999 
1000            return array;
1001        }
1002        catch (Exception e) {
1003            throw processException(e);
1004        }
1005        finally {
1006            closeSession(session);
1007        }
1008    }
1009
1010    public List<SocialRelation> findByUserId1(long userId1)
1011        throws SystemException {
1012        Object[] finderArgs = new Object[] { new Long(userId1) };
1013
1014        List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_USERID1,
1015                finderArgs, this);
1016
1017        if (list == null) {
1018            Session session = null;
1019
1020            try {
1021                session = openSession();
1022
1023                StringBundler query = new StringBundler(2);
1024
1025                query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
1026
1027                query.append(_FINDER_COLUMN_USERID1_USERID1_2);
1028
1029                String sql = query.toString();
1030
1031                Query q = session.createQuery(sql);
1032
1033                QueryPos qPos = QueryPos.getInstance(q);
1034
1035                qPos.add(userId1);
1036
1037                list = q.list();
1038            }
1039            catch (Exception e) {
1040                throw processException(e);
1041            }
1042            finally {
1043                if (list == null) {
1044                    list = new ArrayList<SocialRelation>();
1045                }
1046
1047                cacheResult(list);
1048
1049                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_USERID1,
1050                    finderArgs, list);
1051
1052                closeSession(session);
1053            }
1054        }
1055
1056        return list;
1057    }
1058
1059    public List<SocialRelation> findByUserId1(long userId1, int start, int end)
1060        throws SystemException {
1061        return findByUserId1(userId1, start, end, null);
1062    }
1063
1064    public List<SocialRelation> findByUserId1(long userId1, int start, int end,
1065        OrderByComparator obc) throws SystemException {
1066        Object[] finderArgs = new Object[] {
1067                new Long(userId1),
1068                
1069                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1070            };
1071
1072        List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_USERID1,
1073                finderArgs, this);
1074
1075        if (list == null) {
1076            Session session = null;
1077
1078            try {
1079                session = openSession();
1080
1081                StringBundler query = null;
1082
1083                if (obc != null) {
1084                    query = new StringBundler(3 +
1085                            (obc.getOrderByFields().length * 3));
1086                }
1087                else {
1088                    query = new StringBundler(2);
1089                }
1090
1091                query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
1092
1093                query.append(_FINDER_COLUMN_USERID1_USERID1_2);
1094
1095                if (obc != null) {
1096                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
1097                }
1098
1099                String sql = query.toString();
1100
1101                Query q = session.createQuery(sql);
1102
1103                QueryPos qPos = QueryPos.getInstance(q);
1104
1105                qPos.add(userId1);
1106
1107                list = (List<SocialRelation>)QueryUtil.list(q, getDialect(),
1108                        start, end);
1109            }
1110            catch (Exception e) {
1111                throw processException(e);
1112            }
1113            finally {
1114                if (list == null) {
1115                    list = new ArrayList<SocialRelation>();
1116                }
1117
1118                cacheResult(list);
1119
1120                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_USERID1,
1121                    finderArgs, list);
1122
1123                closeSession(session);
1124            }
1125        }
1126
1127        return list;
1128    }
1129
1130    public SocialRelation findByUserId1_First(long userId1,
1131        OrderByComparator obc) throws NoSuchRelationException, SystemException {
1132        List<SocialRelation> list = findByUserId1(userId1, 0, 1, obc);
1133
1134        if (list.isEmpty()) {
1135            StringBundler msg = new StringBundler(4);
1136
1137            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1138
1139            msg.append("userId1=");
1140            msg.append(userId1);
1141
1142            msg.append(StringPool.CLOSE_CURLY_BRACE);
1143
1144            throw new NoSuchRelationException(msg.toString());
1145        }
1146        else {
1147            return list.get(0);
1148        }
1149    }
1150
1151    public SocialRelation findByUserId1_Last(long userId1, OrderByComparator obc)
1152        throws NoSuchRelationException, SystemException {
1153        int count = countByUserId1(userId1);
1154
1155        List<SocialRelation> list = findByUserId1(userId1, count - 1, count, obc);
1156
1157        if (list.isEmpty()) {
1158            StringBundler msg = new StringBundler(4);
1159
1160            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1161
1162            msg.append("userId1=");
1163            msg.append(userId1);
1164
1165            msg.append(StringPool.CLOSE_CURLY_BRACE);
1166
1167            throw new NoSuchRelationException(msg.toString());
1168        }
1169        else {
1170            return list.get(0);
1171        }
1172    }
1173
1174    public SocialRelation[] findByUserId1_PrevAndNext(long relationId,
1175        long userId1, OrderByComparator obc)
1176        throws NoSuchRelationException, SystemException {
1177        SocialRelation socialRelation = findByPrimaryKey(relationId);
1178
1179        int count = countByUserId1(userId1);
1180
1181        Session session = null;
1182
1183        try {
1184            session = openSession();
1185
1186            StringBundler query = null;
1187
1188            if (obc != null) {
1189                query = new StringBundler(3 +
1190                        (obc.getOrderByFields().length * 3));
1191            }
1192            else {
1193                query = new StringBundler(2);
1194            }
1195
1196            query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
1197
1198            query.append(_FINDER_COLUMN_USERID1_USERID1_2);
1199
1200            if (obc != null) {
1201                appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
1202            }
1203
1204            String sql = query.toString();
1205
1206            Query q = session.createQuery(sql);
1207
1208            QueryPos qPos = QueryPos.getInstance(q);
1209
1210            qPos.add(userId1);
1211
1212            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1213                    socialRelation);
1214
1215            SocialRelation[] array = new SocialRelationImpl[3];
1216
1217            array[0] = (SocialRelation)objArray[0];
1218            array[1] = (SocialRelation)objArray[1];
1219            array[2] = (SocialRelation)objArray[2];
1220
1221            return array;
1222        }
1223        catch (Exception e) {
1224            throw processException(e);
1225        }
1226        finally {
1227            closeSession(session);
1228        }
1229    }
1230
1231    public List<SocialRelation> findByUserId2(long userId2)
1232        throws SystemException {
1233        Object[] finderArgs = new Object[] { new Long(userId2) };
1234
1235        List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_USERID2,
1236                finderArgs, this);
1237
1238        if (list == null) {
1239            Session session = null;
1240
1241            try {
1242                session = openSession();
1243
1244                StringBundler query = new StringBundler(2);
1245
1246                query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
1247
1248                query.append(_FINDER_COLUMN_USERID2_USERID2_2);
1249
1250                String sql = query.toString();
1251
1252                Query q = session.createQuery(sql);
1253
1254                QueryPos qPos = QueryPos.getInstance(q);
1255
1256                qPos.add(userId2);
1257
1258                list = q.list();
1259            }
1260            catch (Exception e) {
1261                throw processException(e);
1262            }
1263            finally {
1264                if (list == null) {
1265                    list = new ArrayList<SocialRelation>();
1266                }
1267
1268                cacheResult(list);
1269
1270                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_USERID2,
1271                    finderArgs, list);
1272
1273                closeSession(session);
1274            }
1275        }
1276
1277        return list;
1278    }
1279
1280    public List<SocialRelation> findByUserId2(long userId2, int start, int end)
1281        throws SystemException {
1282        return findByUserId2(userId2, start, end, null);
1283    }
1284
1285    public List<SocialRelation> findByUserId2(long userId2, int start, int end,
1286        OrderByComparator obc) throws SystemException {
1287        Object[] finderArgs = new Object[] {
1288                new Long(userId2),
1289                
1290                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1291            };
1292
1293        List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_USERID2,
1294                finderArgs, this);
1295
1296        if (list == null) {
1297            Session session = null;
1298
1299            try {
1300                session = openSession();
1301
1302                StringBundler query = null;
1303
1304                if (obc != null) {
1305                    query = new StringBundler(3 +
1306                            (obc.getOrderByFields().length * 3));
1307                }
1308                else {
1309                    query = new StringBundler(2);
1310                }
1311
1312                query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
1313
1314                query.append(_FINDER_COLUMN_USERID2_USERID2_2);
1315
1316                if (obc != null) {
1317                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
1318                }
1319
1320                String sql = query.toString();
1321
1322                Query q = session.createQuery(sql);
1323
1324                QueryPos qPos = QueryPos.getInstance(q);
1325
1326                qPos.add(userId2);
1327
1328                list = (List<SocialRelation>)QueryUtil.list(q, getDialect(),
1329                        start, end);
1330            }
1331            catch (Exception e) {
1332                throw processException(e);
1333            }
1334            finally {
1335                if (list == null) {
1336                    list = new ArrayList<SocialRelation>();
1337                }
1338
1339                cacheResult(list);
1340
1341                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_USERID2,
1342                    finderArgs, list);
1343
1344                closeSession(session);
1345            }
1346        }
1347
1348        return list;
1349    }
1350
1351    public SocialRelation findByUserId2_First(long userId2,
1352        OrderByComparator obc) throws NoSuchRelationException, SystemException {
1353        List<SocialRelation> list = findByUserId2(userId2, 0, 1, obc);
1354
1355        if (list.isEmpty()) {
1356            StringBundler msg = new StringBundler(4);
1357
1358            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1359
1360            msg.append("userId2=");
1361            msg.append(userId2);
1362
1363            msg.append(StringPool.CLOSE_CURLY_BRACE);
1364
1365            throw new NoSuchRelationException(msg.toString());
1366        }
1367        else {
1368            return list.get(0);
1369        }
1370    }
1371
1372    public SocialRelation findByUserId2_Last(long userId2, OrderByComparator obc)
1373        throws NoSuchRelationException, SystemException {
1374        int count = countByUserId2(userId2);
1375
1376        List<SocialRelation> list = findByUserId2(userId2, count - 1, count, obc);
1377
1378        if (list.isEmpty()) {
1379            StringBundler msg = new StringBundler(4);
1380
1381            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1382
1383            msg.append("userId2=");
1384            msg.append(userId2);
1385
1386            msg.append(StringPool.CLOSE_CURLY_BRACE);
1387
1388            throw new NoSuchRelationException(msg.toString());
1389        }
1390        else {
1391            return list.get(0);
1392        }
1393    }
1394
1395    public SocialRelation[] findByUserId2_PrevAndNext(long relationId,
1396        long userId2, OrderByComparator obc)
1397        throws NoSuchRelationException, SystemException {
1398        SocialRelation socialRelation = findByPrimaryKey(relationId);
1399
1400        int count = countByUserId2(userId2);
1401
1402        Session session = null;
1403
1404        try {
1405            session = openSession();
1406
1407            StringBundler query = null;
1408
1409            if (obc != null) {
1410                query = new StringBundler(3 +
1411                        (obc.getOrderByFields().length * 3));
1412            }
1413            else {
1414                query = new StringBundler(2);
1415            }
1416
1417            query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
1418
1419            query.append(_FINDER_COLUMN_USERID2_USERID2_2);
1420
1421            if (obc != null) {
1422                appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
1423            }
1424
1425            String sql = query.toString();
1426
1427            Query q = session.createQuery(sql);
1428
1429            QueryPos qPos = QueryPos.getInstance(q);
1430
1431            qPos.add(userId2);
1432
1433            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1434                    socialRelation);
1435
1436            SocialRelation[] array = new SocialRelationImpl[3];
1437
1438            array[0] = (SocialRelation)objArray[0];
1439            array[1] = (SocialRelation)objArray[1];
1440            array[2] = (SocialRelation)objArray[2];
1441
1442            return array;
1443        }
1444        catch (Exception e) {
1445            throw processException(e);
1446        }
1447        finally {
1448            closeSession(session);
1449        }
1450    }
1451
1452    public List<SocialRelation> findByType(int type) throws SystemException {
1453        Object[] finderArgs = new Object[] { new Integer(type) };
1454
1455        List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_TYPE,
1456                finderArgs, this);
1457
1458        if (list == null) {
1459            Session session = null;
1460
1461            try {
1462                session = openSession();
1463
1464                StringBundler query = new StringBundler(2);
1465
1466                query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
1467
1468                query.append(_FINDER_COLUMN_TYPE_TYPE_2);
1469
1470                String sql = query.toString();
1471
1472                Query q = session.createQuery(sql);
1473
1474                QueryPos qPos = QueryPos.getInstance(q);
1475
1476                qPos.add(type);
1477
1478                list = q.list();
1479            }
1480            catch (Exception e) {
1481                throw processException(e);
1482            }
1483            finally {
1484                if (list == null) {
1485                    list = new ArrayList<SocialRelation>();
1486                }
1487
1488                cacheResult(list);
1489
1490                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_TYPE, finderArgs,
1491                    list);
1492
1493                closeSession(session);
1494            }
1495        }
1496
1497        return list;
1498    }
1499
1500    public List<SocialRelation> findByType(int type, int start, int end)
1501        throws SystemException {
1502        return findByType(type, start, end, null);
1503    }
1504
1505    public List<SocialRelation> findByType(int type, int start, int end,
1506        OrderByComparator obc) throws SystemException {
1507        Object[] finderArgs = new Object[] {
1508                new Integer(type),
1509                
1510                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1511            };
1512
1513        List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_TYPE,
1514                finderArgs, this);
1515
1516        if (list == null) {
1517            Session session = null;
1518
1519            try {
1520                session = openSession();
1521
1522                StringBundler query = null;
1523
1524                if (obc != null) {
1525                    query = new StringBundler(3 +
1526                            (obc.getOrderByFields().length * 3));
1527                }
1528                else {
1529                    query = new StringBundler(2);
1530                }
1531
1532                query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
1533
1534                query.append(_FINDER_COLUMN_TYPE_TYPE_2);
1535
1536                if (obc != null) {
1537                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
1538                }
1539
1540                String sql = query.toString();
1541
1542                Query q = session.createQuery(sql);
1543
1544                QueryPos qPos = QueryPos.getInstance(q);
1545
1546                qPos.add(type);
1547
1548                list = (List<SocialRelation>)QueryUtil.list(q, getDialect(),
1549                        start, end);
1550            }
1551            catch (Exception e) {
1552                throw processException(e);
1553            }
1554            finally {
1555                if (list == null) {
1556                    list = new ArrayList<SocialRelation>();
1557                }
1558
1559                cacheResult(list);
1560
1561                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_TYPE,
1562                    finderArgs, list);
1563
1564                closeSession(session);
1565            }
1566        }
1567
1568        return list;
1569    }
1570
1571    public SocialRelation findByType_First(int type, OrderByComparator obc)
1572        throws NoSuchRelationException, SystemException {
1573        List<SocialRelation> list = findByType(type, 0, 1, obc);
1574
1575        if (list.isEmpty()) {
1576            StringBundler msg = new StringBundler(4);
1577
1578            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1579
1580            msg.append("type=");
1581            msg.append(type);
1582
1583            msg.append(StringPool.CLOSE_CURLY_BRACE);
1584
1585            throw new NoSuchRelationException(msg.toString());
1586        }
1587        else {
1588            return list.get(0);
1589        }
1590    }
1591
1592    public SocialRelation findByType_Last(int type, OrderByComparator obc)
1593        throws NoSuchRelationException, SystemException {
1594        int count = countByType(type);
1595
1596        List<SocialRelation> list = findByType(type, count - 1, count, obc);
1597
1598        if (list.isEmpty()) {
1599            StringBundler msg = new StringBundler(4);
1600
1601            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1602
1603            msg.append("type=");
1604            msg.append(type);
1605
1606            msg.append(StringPool.CLOSE_CURLY_BRACE);
1607
1608            throw new NoSuchRelationException(msg.toString());
1609        }
1610        else {
1611            return list.get(0);
1612        }
1613    }
1614
1615    public SocialRelation[] findByType_PrevAndNext(long relationId, int type,
1616        OrderByComparator obc) throws NoSuchRelationException, SystemException {
1617        SocialRelation socialRelation = findByPrimaryKey(relationId);
1618
1619        int count = countByType(type);
1620
1621        Session session = null;
1622
1623        try {
1624            session = openSession();
1625
1626            StringBundler query = null;
1627
1628            if (obc != null) {
1629                query = new StringBundler(3 +
1630                        (obc.getOrderByFields().length * 3));
1631            }
1632            else {
1633                query = new StringBundler(2);
1634            }
1635
1636            query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
1637
1638            query.append(_FINDER_COLUMN_TYPE_TYPE_2);
1639
1640            if (obc != null) {
1641                appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
1642            }
1643
1644            String sql = query.toString();
1645
1646            Query q = session.createQuery(sql);
1647
1648            QueryPos qPos = QueryPos.getInstance(q);
1649
1650            qPos.add(type);
1651
1652            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1653                    socialRelation);
1654
1655            SocialRelation[] array = new SocialRelationImpl[3];
1656
1657            array[0] = (SocialRelation)objArray[0];
1658            array[1] = (SocialRelation)objArray[1];
1659            array[2] = (SocialRelation)objArray[2];
1660
1661            return array;
1662        }
1663        catch (Exception e) {
1664            throw processException(e);
1665        }
1666        finally {
1667            closeSession(session);
1668        }
1669    }
1670
1671    public List<SocialRelation> findByC_T(long companyId, int type)
1672        throws SystemException {
1673        Object[] finderArgs = new Object[] {
1674                new Long(companyId), new Integer(type)
1675            };
1676
1677        List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_T,
1678                finderArgs, this);
1679
1680        if (list == null) {
1681            Session session = null;
1682
1683            try {
1684                session = openSession();
1685
1686                StringBundler query = new StringBundler(3);
1687
1688                query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
1689
1690                query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
1691
1692                query.append(_FINDER_COLUMN_C_T_TYPE_2);
1693
1694                String sql = query.toString();
1695
1696                Query q = session.createQuery(sql);
1697
1698                QueryPos qPos = QueryPos.getInstance(q);
1699
1700                qPos.add(companyId);
1701
1702                qPos.add(type);
1703
1704                list = q.list();
1705            }
1706            catch (Exception e) {
1707                throw processException(e);
1708            }
1709            finally {
1710                if (list == null) {
1711                    list = new ArrayList<SocialRelation>();
1712                }
1713
1714                cacheResult(list);
1715
1716                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_T, finderArgs,
1717                    list);
1718
1719                closeSession(session);
1720            }
1721        }
1722
1723        return list;
1724    }
1725
1726    public List<SocialRelation> findByC_T(long companyId, int type, int start,
1727        int end) throws SystemException {
1728        return findByC_T(companyId, type, start, end, null);
1729    }
1730
1731    public List<SocialRelation> findByC_T(long companyId, int type, int start,
1732        int end, OrderByComparator obc) throws SystemException {
1733        Object[] finderArgs = new Object[] {
1734                new Long(companyId), new Integer(type),
1735                
1736                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1737            };
1738
1739        List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_C_T,
1740                finderArgs, this);
1741
1742        if (list == null) {
1743            Session session = null;
1744
1745            try {
1746                session = openSession();
1747
1748                StringBundler query = null;
1749
1750                if (obc != null) {
1751                    query = new StringBundler(4 +
1752                            (obc.getOrderByFields().length * 3));
1753                }
1754                else {
1755                    query = new StringBundler(3);
1756                }
1757
1758                query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
1759
1760                query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
1761
1762                query.append(_FINDER_COLUMN_C_T_TYPE_2);
1763
1764                if (obc != null) {
1765                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
1766                }
1767
1768                String sql = query.toString();
1769
1770                Query q = session.createQuery(sql);
1771
1772                QueryPos qPos = QueryPos.getInstance(q);
1773
1774                qPos.add(companyId);
1775
1776                qPos.add(type);
1777
1778                list = (List<SocialRelation>)QueryUtil.list(q, getDialect(),
1779                        start, end);
1780            }
1781            catch (Exception e) {
1782                throw processException(e);
1783            }
1784            finally {
1785                if (list == null) {
1786                    list = new ArrayList<SocialRelation>();
1787                }
1788
1789                cacheResult(list);
1790
1791                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_C_T,
1792                    finderArgs, list);
1793
1794                closeSession(session);
1795            }
1796        }
1797
1798        return list;
1799    }
1800
1801    public SocialRelation findByC_T_First(long companyId, int type,
1802        OrderByComparator obc) throws NoSuchRelationException, SystemException {
1803        List<SocialRelation> list = findByC_T(companyId, type, 0, 1, obc);
1804
1805        if (list.isEmpty()) {
1806            StringBundler msg = new StringBundler(6);
1807
1808            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1809
1810            msg.append("companyId=");
1811            msg.append(companyId);
1812
1813            msg.append(", type=");
1814            msg.append(type);
1815
1816            msg.append(StringPool.CLOSE_CURLY_BRACE);
1817
1818            throw new NoSuchRelationException(msg.toString());
1819        }
1820        else {
1821            return list.get(0);
1822        }
1823    }
1824
1825    public SocialRelation findByC_T_Last(long companyId, int type,
1826        OrderByComparator obc) throws NoSuchRelationException, SystemException {
1827        int count = countByC_T(companyId, type);
1828
1829        List<SocialRelation> list = findByC_T(companyId, type, count - 1,
1830                count, obc);
1831
1832        if (list.isEmpty()) {
1833            StringBundler msg = new StringBundler(6);
1834
1835            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1836
1837            msg.append("companyId=");
1838            msg.append(companyId);
1839
1840            msg.append(", type=");
1841            msg.append(type);
1842
1843            msg.append(StringPool.CLOSE_CURLY_BRACE);
1844
1845            throw new NoSuchRelationException(msg.toString());
1846        }
1847        else {
1848            return list.get(0);
1849        }
1850    }
1851
1852    public SocialRelation[] findByC_T_PrevAndNext(long relationId,
1853        long companyId, int type, OrderByComparator obc)
1854        throws NoSuchRelationException, SystemException {
1855        SocialRelation socialRelation = findByPrimaryKey(relationId);
1856
1857        int count = countByC_T(companyId, type);
1858
1859        Session session = null;
1860
1861        try {
1862            session = openSession();
1863
1864            StringBundler query = null;
1865
1866            if (obc != null) {
1867                query = new StringBundler(4 +
1868                        (obc.getOrderByFields().length * 3));
1869            }
1870            else {
1871                query = new StringBundler(3);
1872            }
1873
1874            query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
1875
1876            query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
1877
1878            query.append(_FINDER_COLUMN_C_T_TYPE_2);
1879
1880            if (obc != null) {
1881                appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
1882            }
1883
1884            String sql = query.toString();
1885
1886            Query q = session.createQuery(sql);
1887
1888            QueryPos qPos = QueryPos.getInstance(q);
1889
1890            qPos.add(companyId);
1891
1892            qPos.add(type);
1893
1894            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1895                    socialRelation);
1896
1897            SocialRelation[] array = new SocialRelationImpl[3];
1898
1899            array[0] = (SocialRelation)objArray[0];
1900            array[1] = (SocialRelation)objArray[1];
1901            array[2] = (SocialRelation)objArray[2];
1902
1903            return array;
1904        }
1905        catch (Exception e) {
1906            throw processException(e);
1907        }
1908        finally {
1909            closeSession(session);
1910        }
1911    }
1912
1913    public List<SocialRelation> findByU1_T(long userId1, int type)
1914        throws SystemException {
1915        Object[] finderArgs = new Object[] { new Long(userId1), new Integer(type) };
1916
1917        List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_U1_T,
1918                finderArgs, this);
1919
1920        if (list == null) {
1921            Session session = null;
1922
1923            try {
1924                session = openSession();
1925
1926                StringBundler query = new StringBundler(3);
1927
1928                query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
1929
1930                query.append(_FINDER_COLUMN_U1_T_USERID1_2);
1931
1932                query.append(_FINDER_COLUMN_U1_T_TYPE_2);
1933
1934                String sql = query.toString();
1935
1936                Query q = session.createQuery(sql);
1937
1938                QueryPos qPos = QueryPos.getInstance(q);
1939
1940                qPos.add(userId1);
1941
1942                qPos.add(type);
1943
1944                list = q.list();
1945            }
1946            catch (Exception e) {
1947                throw processException(e);
1948            }
1949            finally {
1950                if (list == null) {
1951                    list = new ArrayList<SocialRelation>();
1952                }
1953
1954                cacheResult(list);
1955
1956                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_U1_T, finderArgs,
1957                    list);
1958
1959                closeSession(session);
1960            }
1961        }
1962
1963        return list;
1964    }
1965
1966    public List<SocialRelation> findByU1_T(long userId1, int type, int start,
1967        int end) throws SystemException {
1968        return findByU1_T(userId1, type, start, end, null);
1969    }
1970
1971    public List<SocialRelation> findByU1_T(long userId1, int type, int start,
1972        int end, OrderByComparator obc) throws SystemException {
1973        Object[] finderArgs = new Object[] {
1974                new Long(userId1), new Integer(type),
1975                
1976                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1977            };
1978
1979        List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_U1_T,
1980                finderArgs, this);
1981
1982        if (list == null) {
1983            Session session = null;
1984
1985            try {
1986                session = openSession();
1987
1988                StringBundler query = null;
1989
1990                if (obc != null) {
1991                    query = new StringBundler(4 +
1992                            (obc.getOrderByFields().length * 3));
1993                }
1994                else {
1995                    query = new StringBundler(3);
1996                }
1997
1998                query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
1999
2000                query.append(_FINDER_COLUMN_U1_T_USERID1_2);
2001
2002                query.append(_FINDER_COLUMN_U1_T_TYPE_2);
2003
2004                if (obc != null) {
2005                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
2006                }
2007
2008                String sql = query.toString();
2009
2010                Query q = session.createQuery(sql);
2011
2012                QueryPos qPos = QueryPos.getInstance(q);
2013
2014                qPos.add(userId1);
2015
2016                qPos.add(type);
2017
2018                list = (List<SocialRelation>)QueryUtil.list(q, getDialect(),
2019                        start, end);
2020            }
2021            catch (Exception e) {
2022                throw processException(e);
2023            }
2024            finally {
2025                if (list == null) {
2026                    list = new ArrayList<SocialRelation>();
2027                }
2028
2029                cacheResult(list);
2030
2031                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_U1_T,
2032                    finderArgs, list);
2033
2034                closeSession(session);
2035            }
2036        }
2037
2038        return list;
2039    }
2040
2041    public SocialRelation findByU1_T_First(long userId1, int type,
2042        OrderByComparator obc) throws NoSuchRelationException, SystemException {
2043        List<SocialRelation> list = findByU1_T(userId1, type, 0, 1, obc);
2044
2045        if (list.isEmpty()) {
2046            StringBundler msg = new StringBundler(6);
2047
2048            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2049
2050            msg.append("userId1=");
2051            msg.append(userId1);
2052
2053            msg.append(", type=");
2054            msg.append(type);
2055
2056            msg.append(StringPool.CLOSE_CURLY_BRACE);
2057
2058            throw new NoSuchRelationException(msg.toString());
2059        }
2060        else {
2061            return list.get(0);
2062        }
2063    }
2064
2065    public SocialRelation findByU1_T_Last(long userId1, int type,
2066        OrderByComparator obc) throws NoSuchRelationException, SystemException {
2067        int count = countByU1_T(userId1, type);
2068
2069        List<SocialRelation> list = findByU1_T(userId1, type, count - 1, count,
2070                obc);
2071
2072        if (list.isEmpty()) {
2073            StringBundler msg = new StringBundler(6);
2074
2075            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2076
2077            msg.append("userId1=");
2078            msg.append(userId1);
2079
2080            msg.append(", type=");
2081            msg.append(type);
2082
2083            msg.append(StringPool.CLOSE_CURLY_BRACE);
2084
2085            throw new NoSuchRelationException(msg.toString());
2086        }
2087        else {
2088            return list.get(0);
2089        }
2090    }
2091
2092    public SocialRelation[] findByU1_T_PrevAndNext(long relationId,
2093        long userId1, int type, OrderByComparator obc)
2094        throws NoSuchRelationException, SystemException {
2095        SocialRelation socialRelation = findByPrimaryKey(relationId);
2096
2097        int count = countByU1_T(userId1, type);
2098
2099        Session session = null;
2100
2101        try {
2102            session = openSession();
2103
2104            StringBundler query = null;
2105
2106            if (obc != null) {
2107                query = new StringBundler(4 +
2108                        (obc.getOrderByFields().length * 3));
2109            }
2110            else {
2111                query = new StringBundler(3);
2112            }
2113
2114            query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
2115
2116            query.append(_FINDER_COLUMN_U1_T_USERID1_2);
2117
2118            query.append(_FINDER_COLUMN_U1_T_TYPE_2);
2119
2120            if (obc != null) {
2121                appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
2122            }
2123
2124            String sql = query.toString();
2125
2126            Query q = session.createQuery(sql);
2127
2128            QueryPos qPos = QueryPos.getInstance(q);
2129
2130            qPos.add(userId1);
2131
2132            qPos.add(type);
2133
2134            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
2135                    socialRelation);
2136
2137            SocialRelation[] array = new SocialRelationImpl[3];
2138
2139            array[0] = (SocialRelation)objArray[0];
2140            array[1] = (SocialRelation)objArray[1];
2141            array[2] = (SocialRelation)objArray[2];
2142
2143            return array;
2144        }
2145        catch (Exception e) {
2146            throw processException(e);
2147        }
2148        finally {
2149            closeSession(session);
2150        }
2151    }
2152
2153    public List<SocialRelation> findByU2_T(long userId2, int type)
2154        throws SystemException {
2155        Object[] finderArgs = new Object[] { new Long(userId2), new Integer(type) };
2156
2157        List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_U2_T,
2158                finderArgs, this);
2159
2160        if (list == null) {
2161            Session session = null;
2162
2163            try {
2164                session = openSession();
2165
2166                StringBundler query = new StringBundler(3);
2167
2168                query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
2169
2170                query.append(_FINDER_COLUMN_U2_T_USERID2_2);
2171
2172                query.append(_FINDER_COLUMN_U2_T_TYPE_2);
2173
2174                String sql = query.toString();
2175
2176                Query q = session.createQuery(sql);
2177
2178                QueryPos qPos = QueryPos.getInstance(q);
2179
2180                qPos.add(userId2);
2181
2182                qPos.add(type);
2183
2184                list = q.list();
2185            }
2186            catch (Exception e) {
2187                throw processException(e);
2188            }
2189            finally {
2190                if (list == null) {
2191                    list = new ArrayList<SocialRelation>();
2192                }
2193
2194                cacheResult(list);
2195
2196                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_U2_T, finderArgs,
2197                    list);
2198
2199                closeSession(session);
2200            }
2201        }
2202
2203        return list;
2204    }
2205
2206    public List<SocialRelation> findByU2_T(long userId2, int type, int start,
2207        int end) throws SystemException {
2208        return findByU2_T(userId2, type, start, end, null);
2209    }
2210
2211    public List<SocialRelation> findByU2_T(long userId2, int type, int start,
2212        int end, OrderByComparator obc) throws SystemException {
2213        Object[] finderArgs = new Object[] {
2214                new Long(userId2), new Integer(type),
2215                
2216                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
2217            };
2218
2219        List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_U2_T,
2220                finderArgs, this);
2221
2222        if (list == null) {
2223            Session session = null;
2224
2225            try {
2226                session = openSession();
2227
2228                StringBundler query = null;
2229
2230                if (obc != null) {
2231                    query = new StringBundler(4 +
2232                            (obc.getOrderByFields().length * 3));
2233                }
2234                else {
2235                    query = new StringBundler(3);
2236                }
2237
2238                query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
2239
2240                query.append(_FINDER_COLUMN_U2_T_USERID2_2);
2241
2242                query.append(_FINDER_COLUMN_U2_T_TYPE_2);
2243
2244                if (obc != null) {
2245                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
2246                }
2247
2248                String sql = query.toString();
2249
2250                Query q = session.createQuery(sql);
2251
2252                QueryPos qPos = QueryPos.getInstance(q);
2253
2254                qPos.add(userId2);
2255
2256                qPos.add(type);
2257
2258                list = (List<SocialRelation>)QueryUtil.list(q, getDialect(),
2259                        start, end);
2260            }
2261            catch (Exception e) {
2262                throw processException(e);
2263            }
2264            finally {
2265                if (list == null) {
2266                    list = new ArrayList<SocialRelation>();
2267                }
2268
2269                cacheResult(list);
2270
2271                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_U2_T,
2272                    finderArgs, list);
2273
2274                closeSession(session);
2275            }
2276        }
2277
2278        return list;
2279    }
2280
2281    public SocialRelation findByU2_T_First(long userId2, int type,
2282        OrderByComparator obc) throws NoSuchRelationException, SystemException {
2283        List<SocialRelation> list = findByU2_T(userId2, type, 0, 1, obc);
2284
2285        if (list.isEmpty()) {
2286            StringBundler msg = new StringBundler(6);
2287
2288            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2289
2290            msg.append("userId2=");
2291            msg.append(userId2);
2292
2293            msg.append(", type=");
2294            msg.append(type);
2295
2296            msg.append(StringPool.CLOSE_CURLY_BRACE);
2297
2298            throw new NoSuchRelationException(msg.toString());
2299        }
2300        else {
2301            return list.get(0);
2302        }
2303    }
2304
2305    public SocialRelation findByU2_T_Last(long userId2, int type,
2306        OrderByComparator obc) throws NoSuchRelationException, SystemException {
2307        int count = countByU2_T(userId2, type);
2308
2309        List<SocialRelation> list = findByU2_T(userId2, type, count - 1, count,
2310                obc);
2311
2312        if (list.isEmpty()) {
2313            StringBundler msg = new StringBundler(6);
2314
2315            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2316
2317            msg.append("userId2=");
2318            msg.append(userId2);
2319
2320            msg.append(", type=");
2321            msg.append(type);
2322
2323            msg.append(StringPool.CLOSE_CURLY_BRACE);
2324
2325            throw new NoSuchRelationException(msg.toString());
2326        }
2327        else {
2328            return list.get(0);
2329        }
2330    }
2331
2332    public SocialRelation[] findByU2_T_PrevAndNext(long relationId,
2333        long userId2, int type, OrderByComparator obc)
2334        throws NoSuchRelationException, SystemException {
2335        SocialRelation socialRelation = findByPrimaryKey(relationId);
2336
2337        int count = countByU2_T(userId2, type);
2338
2339        Session session = null;
2340
2341        try {
2342            session = openSession();
2343
2344            StringBundler query = null;
2345
2346            if (obc != null) {
2347                query = new StringBundler(4 +
2348                        (obc.getOrderByFields().length * 3));
2349            }
2350            else {
2351                query = new StringBundler(3);
2352            }
2353
2354            query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
2355
2356            query.append(_FINDER_COLUMN_U2_T_USERID2_2);
2357
2358            query.append(_FINDER_COLUMN_U2_T_TYPE_2);
2359
2360            if (obc != null) {
2361                appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
2362            }
2363
2364            String sql = query.toString();
2365
2366            Query q = session.createQuery(sql);
2367
2368            QueryPos qPos = QueryPos.getInstance(q);
2369
2370            qPos.add(userId2);
2371
2372            qPos.add(type);
2373
2374            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
2375                    socialRelation);
2376
2377            SocialRelation[] array = new SocialRelationImpl[3];
2378
2379            array[0] = (SocialRelation)objArray[0];
2380            array[1] = (SocialRelation)objArray[1];
2381            array[2] = (SocialRelation)objArray[2];
2382
2383            return array;
2384        }
2385        catch (Exception e) {
2386            throw processException(e);
2387        }
2388        finally {
2389            closeSession(session);
2390        }
2391    }
2392
2393    public SocialRelation findByU1_U2_T(long userId1, long userId2, int type)
2394        throws NoSuchRelationException, SystemException {
2395        SocialRelation socialRelation = fetchByU1_U2_T(userId1, userId2, type);
2396
2397        if (socialRelation == null) {
2398            StringBundler msg = new StringBundler(8);
2399
2400            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2401
2402            msg.append("userId1=");
2403            msg.append(userId1);
2404
2405            msg.append(", userId2=");
2406            msg.append(userId2);
2407
2408            msg.append(", type=");
2409            msg.append(type);
2410
2411            msg.append(StringPool.CLOSE_CURLY_BRACE);
2412
2413            if (_log.isWarnEnabled()) {
2414                _log.warn(msg.toString());
2415            }
2416
2417            throw new NoSuchRelationException(msg.toString());
2418        }
2419
2420        return socialRelation;
2421    }
2422
2423    public SocialRelation fetchByU1_U2_T(long userId1, long userId2, int type)
2424        throws SystemException {
2425        return fetchByU1_U2_T(userId1, userId2, type, true);
2426    }
2427
2428    public SocialRelation fetchByU1_U2_T(long userId1, long userId2, int type,
2429        boolean retrieveFromCache) throws SystemException {
2430        Object[] finderArgs = new Object[] {
2431                new Long(userId1), new Long(userId2), new Integer(type)
2432            };
2433
2434        Object result = null;
2435
2436        if (retrieveFromCache) {
2437            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_U1_U2_T,
2438                    finderArgs, this);
2439        }
2440
2441        if (result == null) {
2442            Session session = null;
2443
2444            try {
2445                session = openSession();
2446
2447                StringBundler query = new StringBundler(4);
2448
2449                query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
2450
2451                query.append(_FINDER_COLUMN_U1_U2_T_USERID1_2);
2452
2453                query.append(_FINDER_COLUMN_U1_U2_T_USERID2_2);
2454
2455                query.append(_FINDER_COLUMN_U1_U2_T_TYPE_2);
2456
2457                String sql = query.toString();
2458
2459                Query q = session.createQuery(sql);
2460
2461                QueryPos qPos = QueryPos.getInstance(q);
2462
2463                qPos.add(userId1);
2464
2465                qPos.add(userId2);
2466
2467                qPos.add(type);
2468
2469                List<SocialRelation> list = q.list();
2470
2471                result = list;
2472
2473                SocialRelation socialRelation = null;
2474
2475                if (list.isEmpty()) {
2476                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U1_U2_T,
2477                        finderArgs, list);
2478                }
2479                else {
2480                    socialRelation = list.get(0);
2481
2482                    cacheResult(socialRelation);
2483
2484                    if ((socialRelation.getUserId1() != userId1) ||
2485                            (socialRelation.getUserId2() != userId2) ||
2486                            (socialRelation.getType() != type)) {
2487                        FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U1_U2_T,
2488                            finderArgs, socialRelation);
2489                    }
2490                }
2491
2492                return socialRelation;
2493            }
2494            catch (Exception e) {
2495                throw processException(e);
2496            }
2497            finally {
2498                if (result == null) {
2499                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U1_U2_T,
2500                        finderArgs, new ArrayList<SocialRelation>());
2501                }
2502
2503                closeSession(session);
2504            }
2505        }
2506        else {
2507            if (result instanceof List<?>) {
2508                return null;
2509            }
2510            else {
2511                return (SocialRelation)result;
2512            }
2513        }
2514    }
2515
2516    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
2517        throws SystemException {
2518        Session session = null;
2519
2520        try {
2521            session = openSession();
2522
2523            dynamicQuery.compile(session);
2524
2525            return dynamicQuery.list();
2526        }
2527        catch (Exception e) {
2528            throw processException(e);
2529        }
2530        finally {
2531            closeSession(session);
2532        }
2533    }
2534
2535    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
2536        int start, int end) throws SystemException {
2537        Session session = null;
2538
2539        try {
2540            session = openSession();
2541
2542            dynamicQuery.setLimit(start, end);
2543
2544            dynamicQuery.compile(session);
2545
2546            return dynamicQuery.list();
2547        }
2548        catch (Exception e) {
2549            throw processException(e);
2550        }
2551        finally {
2552            closeSession(session);
2553        }
2554    }
2555
2556    public List<SocialRelation> findAll() throws SystemException {
2557        return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2558    }
2559
2560    public List<SocialRelation> findAll(int start, int end)
2561        throws SystemException {
2562        return findAll(start, end, null);
2563    }
2564
2565    public List<SocialRelation> findAll(int start, int end,
2566        OrderByComparator obc) throws SystemException {
2567        Object[] finderArgs = new Object[] {
2568                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
2569            };
2570
2571        List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
2572                finderArgs, this);
2573
2574        if (list == null) {
2575            Session session = null;
2576
2577            try {
2578                session = openSession();
2579
2580                StringBundler query = null;
2581                String sql = null;
2582
2583                if (obc != null) {
2584                    query = new StringBundler(2 +
2585                            (obc.getOrderByFields().length * 3));
2586
2587                    query.append(_SQL_SELECT_SOCIALRELATION);
2588
2589                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
2590
2591                    sql = query.toString();
2592                }
2593
2594                sql = _SQL_SELECT_SOCIALRELATION;
2595
2596                Query q = session.createQuery(sql);
2597
2598                if (obc == null) {
2599                    list = (List<SocialRelation>)QueryUtil.list(q,
2600                            getDialect(), start, end, false);
2601
2602                    Collections.sort(list);
2603                }
2604                else {
2605                    list = (List<SocialRelation>)QueryUtil.list(q,
2606                            getDialect(), start, end);
2607                }
2608            }
2609            catch (Exception e) {
2610                throw processException(e);
2611            }
2612            finally {
2613                if (list == null) {
2614                    list = new ArrayList<SocialRelation>();
2615                }
2616
2617                cacheResult(list);
2618
2619                FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
2620
2621                closeSession(session);
2622            }
2623        }
2624
2625        return list;
2626    }
2627
2628    public void removeByUuid(String uuid) throws SystemException {
2629        for (SocialRelation socialRelation : findByUuid(uuid)) {
2630            remove(socialRelation);
2631        }
2632    }
2633
2634    public void removeByCompanyId(long companyId) throws SystemException {
2635        for (SocialRelation socialRelation : findByCompanyId(companyId)) {
2636            remove(socialRelation);
2637        }
2638    }
2639
2640    public void removeByUserId1(long userId1) throws SystemException {
2641        for (SocialRelation socialRelation : findByUserId1(userId1)) {
2642            remove(socialRelation);
2643        }
2644    }
2645
2646    public void removeByUserId2(long userId2) throws SystemException {
2647        for (SocialRelation socialRelation : findByUserId2(userId2)) {
2648            remove(socialRelation);
2649        }
2650    }
2651
2652    public void removeByType(int type) throws SystemException {
2653        for (SocialRelation socialRelation : findByType(type)) {
2654            remove(socialRelation);
2655        }
2656    }
2657
2658    public void removeByC_T(long companyId, int type) throws SystemException {
2659        for (SocialRelation socialRelation : findByC_T(companyId, type)) {
2660            remove(socialRelation);
2661        }
2662    }
2663
2664    public void removeByU1_T(long userId1, int type) throws SystemException {
2665        for (SocialRelation socialRelation : findByU1_T(userId1, type)) {
2666            remove(socialRelation);
2667        }
2668    }
2669
2670    public void removeByU2_T(long userId2, int type) throws SystemException {
2671        for (SocialRelation socialRelation : findByU2_T(userId2, type)) {
2672            remove(socialRelation);
2673        }
2674    }
2675
2676    public void removeByU1_U2_T(long userId1, long userId2, int type)
2677        throws NoSuchRelationException, SystemException {
2678        SocialRelation socialRelation = findByU1_U2_T(userId1, userId2, type);
2679
2680        remove(socialRelation);
2681    }
2682
2683    public void removeAll() throws SystemException {
2684        for (SocialRelation socialRelation : findAll()) {
2685            remove(socialRelation);
2686        }
2687    }
2688
2689    public int countByUuid(String uuid) throws SystemException {
2690        Object[] finderArgs = new Object[] { uuid };
2691
2692        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
2693                finderArgs, this);
2694
2695        if (count == null) {
2696            Session session = null;
2697
2698            try {
2699                session = openSession();
2700
2701                StringBundler query = new StringBundler(2);
2702
2703                query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
2704
2705                if (uuid == null) {
2706                    query.append(_FINDER_COLUMN_UUID_UUID_1);
2707                }
2708                else {
2709                    if (uuid.equals(StringPool.BLANK)) {
2710                        query.append(_FINDER_COLUMN_UUID_UUID_3);
2711                    }
2712                    else {
2713                        query.append(_FINDER_COLUMN_UUID_UUID_2);
2714                    }
2715                }
2716
2717                String sql = query.toString();
2718
2719                Query q = session.createQuery(sql);
2720
2721                QueryPos qPos = QueryPos.getInstance(q);
2722
2723                if (uuid != null) {
2724                    qPos.add(uuid);
2725                }
2726
2727                count = (Long)q.uniqueResult();
2728            }
2729            catch (Exception e) {
2730                throw processException(e);
2731            }
2732            finally {
2733                if (count == null) {
2734                    count = Long.valueOf(0);
2735                }
2736
2737                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
2738                    finderArgs, count);
2739
2740                closeSession(session);
2741            }
2742        }
2743
2744        return count.intValue();
2745    }
2746
2747    public int countByCompanyId(long companyId) throws SystemException {
2748        Object[] finderArgs = new Object[] { new Long(companyId) };
2749
2750        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
2751                finderArgs, this);
2752
2753        if (count == null) {
2754            Session session = null;
2755
2756            try {
2757                session = openSession();
2758
2759                StringBundler query = new StringBundler(2);
2760
2761                query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
2762
2763                query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2764
2765                String sql = query.toString();
2766
2767                Query q = session.createQuery(sql);
2768
2769                QueryPos qPos = QueryPos.getInstance(q);
2770
2771                qPos.add(companyId);
2772
2773                count = (Long)q.uniqueResult();
2774            }
2775            catch (Exception e) {
2776                throw processException(e);
2777            }
2778            finally {
2779                if (count == null) {
2780                    count = Long.valueOf(0);
2781                }
2782
2783                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
2784                    finderArgs, count);
2785
2786                closeSession(session);
2787            }
2788        }
2789
2790        return count.intValue();
2791    }
2792
2793    public int countByUserId1(long userId1) throws SystemException {
2794        Object[] finderArgs = new Object[] { new Long(userId1) };
2795
2796        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID1,
2797                finderArgs, this);
2798
2799        if (count == null) {
2800            Session session = null;
2801
2802            try {
2803                session = openSession();
2804
2805                StringBundler query = new StringBundler(2);
2806
2807                query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
2808
2809                query.append(_FINDER_COLUMN_USERID1_USERID1_2);
2810
2811                String sql = query.toString();
2812
2813                Query q = session.createQuery(sql);
2814
2815                QueryPos qPos = QueryPos.getInstance(q);
2816
2817                qPos.add(userId1);
2818
2819                count = (Long)q.uniqueResult();
2820            }
2821            catch (Exception e) {
2822                throw processException(e);
2823            }
2824            finally {
2825                if (count == null) {
2826                    count = Long.valueOf(0);
2827                }
2828
2829                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID1,
2830                    finderArgs, count);
2831
2832                closeSession(session);
2833            }
2834        }
2835
2836        return count.intValue();
2837    }
2838
2839    public int countByUserId2(long userId2) throws SystemException {
2840        Object[] finderArgs = new Object[] { new Long(userId2) };
2841
2842        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID2,
2843                finderArgs, this);
2844
2845        if (count == null) {
2846            Session session = null;
2847
2848            try {
2849                session = openSession();
2850
2851                StringBundler query = new StringBundler(2);
2852
2853                query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
2854
2855                query.append(_FINDER_COLUMN_USERID2_USERID2_2);
2856
2857                String sql = query.toString();
2858
2859                Query q = session.createQuery(sql);
2860
2861                QueryPos qPos = QueryPos.getInstance(q);
2862
2863                qPos.add(userId2);
2864
2865                count = (Long)q.uniqueResult();
2866            }
2867            catch (Exception e) {
2868                throw processException(e);
2869            }
2870            finally {
2871                if (count == null) {
2872                    count = Long.valueOf(0);
2873                }
2874
2875                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID2,
2876                    finderArgs, count);
2877
2878                closeSession(session);
2879            }
2880        }
2881
2882        return count.intValue();
2883    }
2884
2885    public int countByType(int type) throws SystemException {
2886        Object[] finderArgs = new Object[] { new Integer(type) };
2887
2888        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_TYPE,
2889                finderArgs, this);
2890
2891        if (count == null) {
2892            Session session = null;
2893
2894            try {
2895                session = openSession();
2896
2897                StringBundler query = new StringBundler(2);
2898
2899                query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
2900
2901                query.append(_FINDER_COLUMN_TYPE_TYPE_2);
2902
2903                String sql = query.toString();
2904
2905                Query q = session.createQuery(sql);
2906
2907                QueryPos qPos = QueryPos.getInstance(q);
2908
2909                qPos.add(type);
2910
2911                count = (Long)q.uniqueResult();
2912            }
2913            catch (Exception e) {
2914                throw processException(e);
2915            }
2916            finally {
2917                if (count == null) {
2918                    count = Long.valueOf(0);
2919                }
2920
2921                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_TYPE,
2922                    finderArgs, count);
2923
2924                closeSession(session);
2925            }
2926        }
2927
2928        return count.intValue();
2929    }
2930
2931    public int countByC_T(long companyId, int type) throws SystemException {
2932        Object[] finderArgs = new Object[] {
2933                new Long(companyId), new Integer(type)
2934            };
2935
2936        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_T,
2937                finderArgs, this);
2938
2939        if (count == null) {
2940            Session session = null;
2941
2942            try {
2943                session = openSession();
2944
2945                StringBundler query = new StringBundler(3);
2946
2947                query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
2948
2949                query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
2950
2951                query.append(_FINDER_COLUMN_C_T_TYPE_2);
2952
2953                String sql = query.toString();
2954
2955                Query q = session.createQuery(sql);
2956
2957                QueryPos qPos = QueryPos.getInstance(q);
2958
2959                qPos.add(companyId);
2960
2961                qPos.add(type);
2962
2963                count = (Long)q.uniqueResult();
2964            }
2965            catch (Exception e) {
2966                throw processException(e);
2967            }
2968            finally {
2969                if (count == null) {
2970                    count = Long.valueOf(0);
2971                }
2972
2973                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_T, finderArgs,
2974                    count);
2975
2976                closeSession(session);
2977            }
2978        }
2979
2980        return count.intValue();
2981    }
2982
2983    public int countByU1_T(long userId1, int type) throws SystemException {
2984        Object[] finderArgs = new Object[] { new Long(userId1), new Integer(type) };
2985
2986        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U1_T,
2987                finderArgs, this);
2988
2989        if (count == null) {
2990            Session session = null;
2991
2992            try {
2993                session = openSession();
2994
2995                StringBundler query = new StringBundler(3);
2996
2997                query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
2998
2999                query.append(_FINDER_COLUMN_U1_T_USERID1_2);
3000
3001                query.append(_FINDER_COLUMN_U1_T_TYPE_2);
3002
3003                String sql = query.toString();
3004
3005                Query q = session.createQuery(sql);
3006
3007                QueryPos qPos = QueryPos.getInstance(q);
3008
3009                qPos.add(userId1);
3010
3011                qPos.add(type);
3012
3013                count = (Long)q.uniqueResult();
3014            }
3015            catch (Exception e) {
3016                throw processException(e);
3017            }
3018            finally {
3019                if (count == null) {
3020                    count = Long.valueOf(0);
3021                }
3022
3023                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U1_T,
3024                    finderArgs, count);
3025
3026                closeSession(session);
3027            }
3028        }
3029
3030        return count.intValue();
3031    }
3032
3033    public int countByU2_T(long userId2, int type) throws SystemException {
3034        Object[] finderArgs = new Object[] { new Long(userId2), new Integer(type) };
3035
3036        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U2_T,
3037                finderArgs, this);
3038
3039        if (count == null) {
3040            Session session = null;
3041
3042            try {
3043                session = openSession();
3044
3045                StringBundler query = new StringBundler(3);
3046
3047                query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
3048
3049                query.append(_FINDER_COLUMN_U2_T_USERID2_2);
3050
3051                query.append(_FINDER_COLUMN_U2_T_TYPE_2);
3052
3053                String sql = query.toString();
3054
3055                Query q = session.createQuery(sql);
3056
3057                QueryPos qPos = QueryPos.getInstance(q);
3058
3059                qPos.add(userId2);
3060
3061                qPos.add(type);
3062
3063                count = (Long)q.uniqueResult();
3064            }
3065            catch (Exception e) {
3066                throw processException(e);
3067            }
3068            finally {
3069                if (count == null) {
3070                    count = Long.valueOf(0);
3071                }
3072
3073                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U2_T,
3074                    finderArgs, count);
3075
3076                closeSession(session);
3077            }
3078        }
3079
3080        return count.intValue();
3081    }
3082
3083    public int countByU1_U2_T(long userId1, long userId2, int type)
3084        throws SystemException {
3085        Object[] finderArgs = new Object[] {
3086                new Long(userId1), new Long(userId2), new Integer(type)
3087            };
3088
3089        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U1_U2_T,
3090                finderArgs, this);
3091
3092        if (count == null) {
3093            Session session = null;
3094
3095            try {
3096                session = openSession();
3097
3098                StringBundler query = new StringBundler(4);
3099
3100                query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
3101
3102                query.append(_FINDER_COLUMN_U1_U2_T_USERID1_2);
3103
3104                query.append(_FINDER_COLUMN_U1_U2_T_USERID2_2);
3105
3106                query.append(_FINDER_COLUMN_U1_U2_T_TYPE_2);
3107
3108                String sql = query.toString();
3109
3110                Query q = session.createQuery(sql);
3111
3112                QueryPos qPos = QueryPos.getInstance(q);
3113
3114                qPos.add(userId1);
3115
3116                qPos.add(userId2);
3117
3118                qPos.add(type);
3119
3120                count = (Long)q.uniqueResult();
3121            }
3122            catch (Exception e) {
3123                throw processException(e);
3124            }
3125            finally {
3126                if (count == null) {
3127                    count = Long.valueOf(0);
3128                }
3129
3130                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U1_U2_T,
3131                    finderArgs, count);
3132
3133                closeSession(session);
3134            }
3135        }
3136
3137        return count.intValue();
3138    }
3139
3140    public int countAll() throws SystemException {
3141        Object[] finderArgs = new Object[0];
3142
3143        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
3144                finderArgs, this);
3145
3146        if (count == null) {
3147            Session session = null;
3148
3149            try {
3150                session = openSession();
3151
3152                Query q = session.createQuery(_SQL_COUNT_SOCIALRELATION);
3153
3154                count = (Long)q.uniqueResult();
3155            }
3156            catch (Exception e) {
3157                throw processException(e);
3158            }
3159            finally {
3160                if (count == null) {
3161                    count = Long.valueOf(0);
3162                }
3163
3164                FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
3165                    count);
3166
3167                closeSession(session);
3168            }
3169        }
3170
3171        return count.intValue();
3172    }
3173
3174    public void afterPropertiesSet() {
3175        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
3176                    com.liferay.portal.util.PropsUtil.get(
3177                        "value.object.listener.com.liferay.portlet.social.model.SocialRelation")));
3178
3179        if (listenerClassNames.length > 0) {
3180            try {
3181                List<ModelListener<SocialRelation>> listenersList = new ArrayList<ModelListener<SocialRelation>>();
3182
3183                for (String listenerClassName : listenerClassNames) {
3184                    listenersList.add((ModelListener<SocialRelation>)Class.forName(
3185                            listenerClassName).newInstance());
3186                }
3187
3188                listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
3189            }
3190            catch (Exception e) {
3191                _log.error(e);
3192            }
3193        }
3194    }
3195
3196    @BeanReference(name = "com.liferay.portlet.social.service.persistence.SocialActivityPersistence")
3197    protected com.liferay.portlet.social.service.persistence.SocialActivityPersistence socialActivityPersistence;
3198    @BeanReference(name = "com.liferay.portlet.social.service.persistence.SocialRelationPersistence")
3199    protected com.liferay.portlet.social.service.persistence.SocialRelationPersistence socialRelationPersistence;
3200    @BeanReference(name = "com.liferay.portlet.social.service.persistence.SocialRequestPersistence")
3201    protected com.liferay.portlet.social.service.persistence.SocialRequestPersistence socialRequestPersistence;
3202    @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePersistence")
3203    protected com.liferay.portal.service.persistence.ResourcePersistence resourcePersistence;
3204    @BeanReference(name = "com.liferay.portal.service.persistence.UserPersistence")
3205    protected com.liferay.portal.service.persistence.UserPersistence userPersistence;
3206    private static final String _SQL_SELECT_SOCIALRELATION = "SELECT socialRelation FROM SocialRelation socialRelation";
3207    private static final String _SQL_SELECT_SOCIALRELATION_WHERE = "SELECT socialRelation FROM SocialRelation socialRelation WHERE ";
3208    private static final String _SQL_COUNT_SOCIALRELATION = "SELECT COUNT(socialRelation) FROM SocialRelation socialRelation";
3209    private static final String _SQL_COUNT_SOCIALRELATION_WHERE = "SELECT COUNT(socialRelation) FROM SocialRelation socialRelation WHERE ";
3210    private static final String _FINDER_COLUMN_UUID_UUID_1 = "socialRelation.uuid IS NULL";
3211    private static final String _FINDER_COLUMN_UUID_UUID_2 = "socialRelation.uuid = ?";
3212    private static final String _FINDER_COLUMN_UUID_UUID_3 = "(socialRelation.uuid IS NULL OR socialRelation.uuid = ?)";
3213    private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "socialRelation.companyId = ?";
3214    private static final String _FINDER_COLUMN_USERID1_USERID1_2 = "socialRelation.userId1 = ?";
3215    private static final String _FINDER_COLUMN_USERID2_USERID2_2 = "socialRelation.userId2 = ?";
3216    private static final String _FINDER_COLUMN_TYPE_TYPE_2 = "socialRelation.type = ?";
3217    private static final String _FINDER_COLUMN_C_T_COMPANYID_2 = "socialRelation.companyId = ? AND ";
3218    private static final String _FINDER_COLUMN_C_T_TYPE_2 = "socialRelation.type = ?";
3219    private static final String _FINDER_COLUMN_U1_T_USERID1_2 = "socialRelation.userId1 = ? AND ";
3220    private static final String _FINDER_COLUMN_U1_T_TYPE_2 = "socialRelation.type = ?";
3221    private static final String _FINDER_COLUMN_U2_T_USERID2_2 = "socialRelation.userId2 = ? AND ";
3222    private static final String _FINDER_COLUMN_U2_T_TYPE_2 = "socialRelation.type = ?";
3223    private static final String _FINDER_COLUMN_U1_U2_T_USERID1_2 = "socialRelation.userId1 = ? AND ";
3224    private static final String _FINDER_COLUMN_U1_U2_T_USERID2_2 = "socialRelation.userId2 = ? AND ";
3225    private static final String _FINDER_COLUMN_U1_U2_T_TYPE_2 = "socialRelation.type = ?";
3226    private static final String _ORDER_BY_ENTITY_ALIAS = "socialRelation.";
3227    private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No SocialRelation exists with the primary key ";
3228    private static final String _NO_SUCH_ENTITY_WITH_KEY = "No SocialRelation exists with the key {";
3229    private static Log _log = LogFactoryUtil.getLog(SocialRelationPersistenceImpl.class);
3230}