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