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