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