001
014
015 package com.liferay.portlet.social.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
018 import com.liferay.portal.kernel.bean.BeanReference;
019 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderPath;
023 import com.liferay.portal.kernel.dao.orm.Query;
024 import com.liferay.portal.kernel.dao.orm.QueryPos;
025 import com.liferay.portal.kernel.dao.orm.QueryUtil;
026 import com.liferay.portal.kernel.dao.orm.Session;
027 import com.liferay.portal.kernel.exception.SystemException;
028 import com.liferay.portal.kernel.log.Log;
029 import com.liferay.portal.kernel.log.LogFactoryUtil;
030 import com.liferay.portal.kernel.util.GetterUtil;
031 import com.liferay.portal.kernel.util.InstanceFactory;
032 import com.liferay.portal.kernel.util.OrderByComparator;
033 import com.liferay.portal.kernel.util.StringBundler;
034 import com.liferay.portal.kernel.util.StringPool;
035 import com.liferay.portal.kernel.util.StringUtil;
036 import com.liferay.portal.kernel.util.Validator;
037 import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
038 import com.liferay.portal.model.CacheModel;
039 import com.liferay.portal.model.ModelListener;
040 import com.liferay.portal.service.persistence.BatchSessionUtil;
041 import com.liferay.portal.service.persistence.ResourcePersistence;
042 import com.liferay.portal.service.persistence.UserPersistence;
043 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
044
045 import com.liferay.portlet.social.NoSuchRelationException;
046 import com.liferay.portlet.social.model.SocialRelation;
047 import com.liferay.portlet.social.model.impl.SocialRelationImpl;
048 import com.liferay.portlet.social.model.impl.SocialRelationModelImpl;
049
050 import java.io.Serializable;
051
052 import java.util.ArrayList;
053 import java.util.Collections;
054 import java.util.List;
055
056
068 public class SocialRelationPersistenceImpl extends BasePersistenceImpl<SocialRelation>
069 implements SocialRelationPersistence {
070
075 public static final String FINDER_CLASS_NAME_ENTITY = SocialRelationImpl.class.getName();
076 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
077 ".List1";
078 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
079 ".List2";
080 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
081 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
082 SocialRelationImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
083 "findByUuid",
084 new String[] {
085 String.class.getName(),
086
087 "java.lang.Integer", "java.lang.Integer",
088 "com.liferay.portal.kernel.util.OrderByComparator"
089 });
090 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
091 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
092 SocialRelationImpl.class,
093 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
094 new String[] { String.class.getName() },
095 SocialRelationModelImpl.UUID_COLUMN_BITMASK);
096 public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
097 SocialRelationModelImpl.FINDER_CACHE_ENABLED, Long.class,
098 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
099 new String[] { String.class.getName() });
100 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
101 new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
102 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
103 SocialRelationImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
104 "findByCompanyId",
105 new String[] {
106 Long.class.getName(),
107
108 "java.lang.Integer", "java.lang.Integer",
109 "com.liferay.portal.kernel.util.OrderByComparator"
110 });
111 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
112 new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
113 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
114 SocialRelationImpl.class,
115 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
116 new String[] { Long.class.getName() },
117 SocialRelationModelImpl.COMPANYID_COLUMN_BITMASK);
118 public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
119 SocialRelationModelImpl.FINDER_CACHE_ENABLED, Long.class,
120 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
121 new String[] { Long.class.getName() });
122 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID1 = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
123 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
124 SocialRelationImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
125 "findByUserId1",
126 new String[] {
127 Long.class.getName(),
128
129 "java.lang.Integer", "java.lang.Integer",
130 "com.liferay.portal.kernel.util.OrderByComparator"
131 });
132 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID1 =
133 new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
134 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
135 SocialRelationImpl.class,
136 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserId1",
137 new String[] { Long.class.getName() },
138 SocialRelationModelImpl.USERID1_COLUMN_BITMASK);
139 public static final FinderPath FINDER_PATH_COUNT_BY_USERID1 = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
140 SocialRelationModelImpl.FINDER_CACHE_ENABLED, Long.class,
141 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId1",
142 new String[] { Long.class.getName() });
143 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID2 = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
144 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
145 SocialRelationImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
146 "findByUserId2",
147 new String[] {
148 Long.class.getName(),
149
150 "java.lang.Integer", "java.lang.Integer",
151 "com.liferay.portal.kernel.util.OrderByComparator"
152 });
153 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID2 =
154 new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
155 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
156 SocialRelationImpl.class,
157 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserId2",
158 new String[] { Long.class.getName() },
159 SocialRelationModelImpl.USERID2_COLUMN_BITMASK);
160 public static final FinderPath FINDER_PATH_COUNT_BY_USERID2 = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
161 SocialRelationModelImpl.FINDER_CACHE_ENABLED, Long.class,
162 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId2",
163 new String[] { Long.class.getName() });
164 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_TYPE = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
165 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
166 SocialRelationImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
167 "findByType",
168 new String[] {
169 Integer.class.getName(),
170
171 "java.lang.Integer", "java.lang.Integer",
172 "com.liferay.portal.kernel.util.OrderByComparator"
173 });
174 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
175 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
176 SocialRelationImpl.class,
177 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByType",
178 new String[] { Integer.class.getName() },
179 SocialRelationModelImpl.TYPE_COLUMN_BITMASK);
180 public static final FinderPath FINDER_PATH_COUNT_BY_TYPE = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
181 SocialRelationModelImpl.FINDER_CACHE_ENABLED, Long.class,
182 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByType",
183 new String[] { Integer.class.getName() });
184 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
185 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
186 SocialRelationImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
187 "findByC_T",
188 new String[] {
189 Long.class.getName(), Integer.class.getName(),
190
191 "java.lang.Integer", "java.lang.Integer",
192 "com.liferay.portal.kernel.util.OrderByComparator"
193 });
194 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
195 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
196 SocialRelationImpl.class,
197 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_T",
198 new String[] { Long.class.getName(), Integer.class.getName() },
199 SocialRelationModelImpl.COMPANYID_COLUMN_BITMASK |
200 SocialRelationModelImpl.TYPE_COLUMN_BITMASK);
201 public static final FinderPath FINDER_PATH_COUNT_BY_C_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
202 SocialRelationModelImpl.FINDER_CACHE_ENABLED, Long.class,
203 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_T",
204 new String[] { Long.class.getName(), Integer.class.getName() });
205 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U1_U2 = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
206 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
207 SocialRelationImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
208 "findByU1_U2",
209 new String[] {
210 Long.class.getName(), Long.class.getName(),
211
212 "java.lang.Integer", "java.lang.Integer",
213 "com.liferay.portal.kernel.util.OrderByComparator"
214 });
215 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U1_U2 = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
216 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
217 SocialRelationImpl.class,
218 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU1_U2",
219 new String[] { Long.class.getName(), Long.class.getName() },
220 SocialRelationModelImpl.USERID1_COLUMN_BITMASK |
221 SocialRelationModelImpl.USERID2_COLUMN_BITMASK);
222 public static final FinderPath FINDER_PATH_COUNT_BY_U1_U2 = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
223 SocialRelationModelImpl.FINDER_CACHE_ENABLED, Long.class,
224 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU1_U2",
225 new String[] { Long.class.getName(), Long.class.getName() });
226 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U1_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
227 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
228 SocialRelationImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
229 "findByU1_T",
230 new String[] {
231 Long.class.getName(), Integer.class.getName(),
232
233 "java.lang.Integer", "java.lang.Integer",
234 "com.liferay.portal.kernel.util.OrderByComparator"
235 });
236 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U1_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
237 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
238 SocialRelationImpl.class,
239 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU1_T",
240 new String[] { Long.class.getName(), Integer.class.getName() },
241 SocialRelationModelImpl.USERID1_COLUMN_BITMASK |
242 SocialRelationModelImpl.TYPE_COLUMN_BITMASK);
243 public static final FinderPath FINDER_PATH_COUNT_BY_U1_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
244 SocialRelationModelImpl.FINDER_CACHE_ENABLED, Long.class,
245 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU1_T",
246 new String[] { Long.class.getName(), Integer.class.getName() });
247 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U2_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
248 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
249 SocialRelationImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
250 "findByU2_T",
251 new String[] {
252 Long.class.getName(), Integer.class.getName(),
253
254 "java.lang.Integer", "java.lang.Integer",
255 "com.liferay.portal.kernel.util.OrderByComparator"
256 });
257 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U2_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
258 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
259 SocialRelationImpl.class,
260 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU2_T",
261 new String[] { Long.class.getName(), Integer.class.getName() },
262 SocialRelationModelImpl.USERID2_COLUMN_BITMASK |
263 SocialRelationModelImpl.TYPE_COLUMN_BITMASK);
264 public static final FinderPath FINDER_PATH_COUNT_BY_U2_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
265 SocialRelationModelImpl.FINDER_CACHE_ENABLED, Long.class,
266 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU2_T",
267 new String[] { Long.class.getName(), Integer.class.getName() });
268 public static final FinderPath FINDER_PATH_FETCH_BY_U1_U2_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
269 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
270 SocialRelationImpl.class, FINDER_CLASS_NAME_ENTITY,
271 "fetchByU1_U2_T",
272 new String[] {
273 Long.class.getName(), Long.class.getName(),
274 Integer.class.getName()
275 },
276 SocialRelationModelImpl.USERID1_COLUMN_BITMASK |
277 SocialRelationModelImpl.USERID2_COLUMN_BITMASK |
278 SocialRelationModelImpl.TYPE_COLUMN_BITMASK);
279 public static final FinderPath FINDER_PATH_COUNT_BY_U1_U2_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
280 SocialRelationModelImpl.FINDER_CACHE_ENABLED, Long.class,
281 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU1_U2_T",
282 new String[] {
283 Long.class.getName(), Long.class.getName(),
284 Integer.class.getName()
285 });
286 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
287 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
288 SocialRelationImpl.class,
289 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
290 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
291 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
292 SocialRelationImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
293 "findAll", new String[0]);
294 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
295 SocialRelationModelImpl.FINDER_CACHE_ENABLED, Long.class,
296 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
297
298
303 public void cacheResult(SocialRelation socialRelation) {
304 EntityCacheUtil.putResult(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
305 SocialRelationImpl.class, socialRelation.getPrimaryKey(),
306 socialRelation);
307
308 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U1_U2_T,
309 new Object[] {
310 Long.valueOf(socialRelation.getUserId1()),
311 Long.valueOf(socialRelation.getUserId2()),
312 Integer.valueOf(socialRelation.getType())
313 }, socialRelation);
314
315 socialRelation.resetOriginalValues();
316 }
317
318
323 public void cacheResult(List<SocialRelation> socialRelations) {
324 for (SocialRelation socialRelation : socialRelations) {
325 if (EntityCacheUtil.getResult(
326 SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
327 SocialRelationImpl.class, socialRelation.getPrimaryKey()) == null) {
328 cacheResult(socialRelation);
329 }
330 else {
331 socialRelation.resetOriginalValues();
332 }
333 }
334 }
335
336
343 @Override
344 public void clearCache() {
345 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
346 CacheRegistryUtil.clear(SocialRelationImpl.class.getName());
347 }
348
349 EntityCacheUtil.clearCache(SocialRelationImpl.class.getName());
350
351 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
352 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
353 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
354 }
355
356
363 @Override
364 public void clearCache(SocialRelation socialRelation) {
365 EntityCacheUtil.removeResult(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
366 SocialRelationImpl.class, socialRelation.getPrimaryKey());
367
368 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
369 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
370
371 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U1_U2_T,
372 new Object[] {
373 Long.valueOf(socialRelation.getUserId1()),
374 Long.valueOf(socialRelation.getUserId2()),
375 Integer.valueOf(socialRelation.getType())
376 });
377 }
378
379
385 public SocialRelation create(long relationId) {
386 SocialRelation socialRelation = new SocialRelationImpl();
387
388 socialRelation.setNew(true);
389 socialRelation.setPrimaryKey(relationId);
390
391 String uuid = PortalUUIDUtil.generate();
392
393 socialRelation.setUuid(uuid);
394
395 return socialRelation;
396 }
397
398
406 @Override
407 public SocialRelation remove(Serializable primaryKey)
408 throws NoSuchModelException, SystemException {
409 return remove(((Long)primaryKey).longValue());
410 }
411
412
420 public SocialRelation remove(long relationId)
421 throws NoSuchRelationException, SystemException {
422 Session session = null;
423
424 try {
425 session = openSession();
426
427 SocialRelation socialRelation = (SocialRelation)session.get(SocialRelationImpl.class,
428 Long.valueOf(relationId));
429
430 if (socialRelation == null) {
431 if (_log.isWarnEnabled()) {
432 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + relationId);
433 }
434
435 throw new NoSuchRelationException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
436 relationId);
437 }
438
439 return socialRelationPersistence.remove(socialRelation);
440 }
441 catch (NoSuchRelationException nsee) {
442 throw nsee;
443 }
444 catch (Exception e) {
445 throw processException(e);
446 }
447 finally {
448 closeSession(session);
449 }
450 }
451
452
459 @Override
460 public SocialRelation remove(SocialRelation socialRelation)
461 throws SystemException {
462 return super.remove(socialRelation);
463 }
464
465 @Override
466 protected SocialRelation removeImpl(SocialRelation socialRelation)
467 throws SystemException {
468 socialRelation = toUnwrappedModel(socialRelation);
469
470 Session session = null;
471
472 try {
473 session = openSession();
474
475 BatchSessionUtil.delete(session, socialRelation);
476 }
477 catch (Exception e) {
478 throw processException(e);
479 }
480 finally {
481 closeSession(session);
482 }
483
484 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
485 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
486
487 SocialRelationModelImpl socialRelationModelImpl = (SocialRelationModelImpl)socialRelation;
488
489 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U1_U2_T,
490 new Object[] {
491 Long.valueOf(socialRelationModelImpl.getUserId1()),
492 Long.valueOf(socialRelationModelImpl.getUserId2()),
493 Integer.valueOf(socialRelationModelImpl.getType())
494 });
495
496 EntityCacheUtil.removeResult(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
497 SocialRelationImpl.class, socialRelation.getPrimaryKey());
498
499 return socialRelation;
500 }
501
502 @Override
503 public SocialRelation updateImpl(
504 com.liferay.portlet.social.model.SocialRelation socialRelation,
505 boolean merge) throws SystemException {
506 socialRelation = toUnwrappedModel(socialRelation);
507
508 boolean isNew = socialRelation.isNew();
509
510 SocialRelationModelImpl socialRelationModelImpl = (SocialRelationModelImpl)socialRelation;
511
512 if (Validator.isNull(socialRelation.getUuid())) {
513 String uuid = PortalUUIDUtil.generate();
514
515 socialRelation.setUuid(uuid);
516 }
517
518 Session session = null;
519
520 try {
521 session = openSession();
522
523 BatchSessionUtil.update(session, socialRelation, merge);
524
525 socialRelation.setNew(false);
526 }
527 catch (Exception e) {
528 throw processException(e);
529 }
530 finally {
531 closeSession(session);
532 }
533
534 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
535
536 if (isNew || !SocialRelationModelImpl.COLUMN_BITMASK_ENABLED) {
537 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
538 }
539
540 else {
541 if ((socialRelationModelImpl.getColumnBitmask() &
542 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
543 Object[] args = new Object[] {
544 socialRelationModelImpl.getOriginalUuid()
545 };
546
547 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
548 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
549 args);
550
551 args = new Object[] { socialRelationModelImpl.getUuid() };
552
553 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
554 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
555 args);
556 }
557
558 if ((socialRelationModelImpl.getColumnBitmask() &
559 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
560 Object[] args = new Object[] {
561 Long.valueOf(socialRelationModelImpl.getOriginalCompanyId())
562 };
563
564 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
565 args);
566 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
567 args);
568
569 args = new Object[] {
570 Long.valueOf(socialRelationModelImpl.getCompanyId())
571 };
572
573 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
574 args);
575 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
576 args);
577 }
578
579 if ((socialRelationModelImpl.getColumnBitmask() &
580 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID1.getColumnBitmask()) != 0) {
581 Object[] args = new Object[] {
582 Long.valueOf(socialRelationModelImpl.getOriginalUserId1())
583 };
584
585 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID1, args);
586 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID1,
587 args);
588
589 args = new Object[] {
590 Long.valueOf(socialRelationModelImpl.getUserId1())
591 };
592
593 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID1, args);
594 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID1,
595 args);
596 }
597
598 if ((socialRelationModelImpl.getColumnBitmask() &
599 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID2.getColumnBitmask()) != 0) {
600 Object[] args = new Object[] {
601 Long.valueOf(socialRelationModelImpl.getOriginalUserId2())
602 };
603
604 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID2, args);
605 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID2,
606 args);
607
608 args = new Object[] {
609 Long.valueOf(socialRelationModelImpl.getUserId2())
610 };
611
612 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID2, args);
613 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID2,
614 args);
615 }
616
617 if ((socialRelationModelImpl.getColumnBitmask() &
618 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE.getColumnBitmask()) != 0) {
619 Object[] args = new Object[] {
620 Integer.valueOf(socialRelationModelImpl.getOriginalType())
621 };
622
623 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TYPE, args);
624 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE,
625 args);
626
627 args = new Object[] {
628 Integer.valueOf(socialRelationModelImpl.getType())
629 };
630
631 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TYPE, args);
632 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE,
633 args);
634 }
635
636 if ((socialRelationModelImpl.getColumnBitmask() &
637 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_T.getColumnBitmask()) != 0) {
638 Object[] args = new Object[] {
639 Long.valueOf(socialRelationModelImpl.getOriginalCompanyId()),
640 Integer.valueOf(socialRelationModelImpl.getOriginalType())
641 };
642
643 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_T, args);
644 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_T,
645 args);
646
647 args = new Object[] {
648 Long.valueOf(socialRelationModelImpl.getCompanyId()),
649 Integer.valueOf(socialRelationModelImpl.getType())
650 };
651
652 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_T, args);
653 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_T,
654 args);
655 }
656
657 if ((socialRelationModelImpl.getColumnBitmask() &
658 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U1_U2.getColumnBitmask()) != 0) {
659 Object[] args = new Object[] {
660 Long.valueOf(socialRelationModelImpl.getOriginalUserId1()),
661 Long.valueOf(socialRelationModelImpl.getOriginalUserId2())
662 };
663
664 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U1_U2, args);
665 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U1_U2,
666 args);
667
668 args = new Object[] {
669 Long.valueOf(socialRelationModelImpl.getUserId1()),
670 Long.valueOf(socialRelationModelImpl.getUserId2())
671 };
672
673 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U1_U2, args);
674 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U1_U2,
675 args);
676 }
677
678 if ((socialRelationModelImpl.getColumnBitmask() &
679 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U1_T.getColumnBitmask()) != 0) {
680 Object[] args = new Object[] {
681 Long.valueOf(socialRelationModelImpl.getOriginalUserId1()),
682 Integer.valueOf(socialRelationModelImpl.getOriginalType())
683 };
684
685 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U1_T, args);
686 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U1_T,
687 args);
688
689 args = new Object[] {
690 Long.valueOf(socialRelationModelImpl.getUserId1()),
691 Integer.valueOf(socialRelationModelImpl.getType())
692 };
693
694 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U1_T, args);
695 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U1_T,
696 args);
697 }
698
699 if ((socialRelationModelImpl.getColumnBitmask() &
700 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U2_T.getColumnBitmask()) != 0) {
701 Object[] args = new Object[] {
702 Long.valueOf(socialRelationModelImpl.getOriginalUserId2()),
703 Integer.valueOf(socialRelationModelImpl.getOriginalType())
704 };
705
706 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U2_T, args);
707 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U2_T,
708 args);
709
710 args = new Object[] {
711 Long.valueOf(socialRelationModelImpl.getUserId2()),
712 Integer.valueOf(socialRelationModelImpl.getType())
713 };
714
715 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U2_T, args);
716 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U2_T,
717 args);
718 }
719 }
720
721 EntityCacheUtil.putResult(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
722 SocialRelationImpl.class, socialRelation.getPrimaryKey(),
723 socialRelation);
724
725 if (isNew) {
726 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U1_U2_T,
727 new Object[] {
728 Long.valueOf(socialRelation.getUserId1()),
729 Long.valueOf(socialRelation.getUserId2()),
730 Integer.valueOf(socialRelation.getType())
731 }, socialRelation);
732 }
733 else {
734 if ((socialRelationModelImpl.getColumnBitmask() &
735 FINDER_PATH_FETCH_BY_U1_U2_T.getColumnBitmask()) != 0) {
736 Object[] args = new Object[] {
737 Long.valueOf(socialRelationModelImpl.getOriginalUserId1()),
738 Long.valueOf(socialRelationModelImpl.getOriginalUserId2()),
739 Integer.valueOf(socialRelationModelImpl.getOriginalType())
740 };
741
742 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U1_U2_T, args);
743 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U1_U2_T, args);
744
745 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U1_U2_T,
746 new Object[] {
747 Long.valueOf(socialRelation.getUserId1()),
748 Long.valueOf(socialRelation.getUserId2()),
749 Integer.valueOf(socialRelation.getType())
750 }, socialRelation);
751 }
752 }
753
754 return socialRelation;
755 }
756
757 protected SocialRelation toUnwrappedModel(SocialRelation socialRelation) {
758 if (socialRelation instanceof SocialRelationImpl) {
759 return socialRelation;
760 }
761
762 SocialRelationImpl socialRelationImpl = new SocialRelationImpl();
763
764 socialRelationImpl.setNew(socialRelation.isNew());
765 socialRelationImpl.setPrimaryKey(socialRelation.getPrimaryKey());
766
767 socialRelationImpl.setUuid(socialRelation.getUuid());
768 socialRelationImpl.setRelationId(socialRelation.getRelationId());
769 socialRelationImpl.setCompanyId(socialRelation.getCompanyId());
770 socialRelationImpl.setCreateDate(socialRelation.getCreateDate());
771 socialRelationImpl.setUserId1(socialRelation.getUserId1());
772 socialRelationImpl.setUserId2(socialRelation.getUserId2());
773 socialRelationImpl.setType(socialRelation.getType());
774
775 return socialRelationImpl;
776 }
777
778
786 @Override
787 public SocialRelation findByPrimaryKey(Serializable primaryKey)
788 throws NoSuchModelException, SystemException {
789 return findByPrimaryKey(((Long)primaryKey).longValue());
790 }
791
792
800 public SocialRelation findByPrimaryKey(long relationId)
801 throws NoSuchRelationException, SystemException {
802 SocialRelation socialRelation = fetchByPrimaryKey(relationId);
803
804 if (socialRelation == null) {
805 if (_log.isWarnEnabled()) {
806 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + relationId);
807 }
808
809 throw new NoSuchRelationException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
810 relationId);
811 }
812
813 return socialRelation;
814 }
815
816
823 @Override
824 public SocialRelation fetchByPrimaryKey(Serializable primaryKey)
825 throws SystemException {
826 return fetchByPrimaryKey(((Long)primaryKey).longValue());
827 }
828
829
836 public SocialRelation fetchByPrimaryKey(long relationId)
837 throws SystemException {
838 SocialRelation socialRelation = (SocialRelation)EntityCacheUtil.getResult(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
839 SocialRelationImpl.class, relationId);
840
841 if (socialRelation == _nullSocialRelation) {
842 return null;
843 }
844
845 if (socialRelation == null) {
846 Session session = null;
847
848 boolean hasException = false;
849
850 try {
851 session = openSession();
852
853 socialRelation = (SocialRelation)session.get(SocialRelationImpl.class,
854 Long.valueOf(relationId));
855 }
856 catch (Exception e) {
857 hasException = true;
858
859 throw processException(e);
860 }
861 finally {
862 if (socialRelation != null) {
863 cacheResult(socialRelation);
864 }
865 else if (!hasException) {
866 EntityCacheUtil.putResult(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
867 SocialRelationImpl.class, relationId,
868 _nullSocialRelation);
869 }
870
871 closeSession(session);
872 }
873 }
874
875 return socialRelation;
876 }
877
878
885 public List<SocialRelation> findByUuid(String uuid)
886 throws SystemException {
887 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
888 }
889
890
903 public List<SocialRelation> findByUuid(String uuid, int start, int end)
904 throws SystemException {
905 return findByUuid(uuid, start, end, null);
906 }
907
908
922 public List<SocialRelation> findByUuid(String uuid, int start, int end,
923 OrderByComparator orderByComparator) throws SystemException {
924 FinderPath finderPath = null;
925 Object[] finderArgs = null;
926
927 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
928 (orderByComparator == null)) {
929 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
930 finderArgs = new Object[] { uuid };
931 }
932 else {
933 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
934 finderArgs = new Object[] { uuid, start, end, orderByComparator };
935 }
936
937 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(finderPath,
938 finderArgs, this);
939
940 if (list == null) {
941 StringBundler query = null;
942
943 if (orderByComparator != null) {
944 query = new StringBundler(3 +
945 (orderByComparator.getOrderByFields().length * 3));
946 }
947 else {
948 query = new StringBundler(2);
949 }
950
951 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
952
953 if (uuid == null) {
954 query.append(_FINDER_COLUMN_UUID_UUID_1);
955 }
956 else {
957 if (uuid.equals(StringPool.BLANK)) {
958 query.append(_FINDER_COLUMN_UUID_UUID_3);
959 }
960 else {
961 query.append(_FINDER_COLUMN_UUID_UUID_2);
962 }
963 }
964
965 if (orderByComparator != null) {
966 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
967 orderByComparator);
968 }
969
970 String sql = query.toString();
971
972 Session session = null;
973
974 try {
975 session = openSession();
976
977 Query q = session.createQuery(sql);
978
979 QueryPos qPos = QueryPos.getInstance(q);
980
981 if (uuid != null) {
982 qPos.add(uuid);
983 }
984
985 list = (List<SocialRelation>)QueryUtil.list(q, getDialect(),
986 start, end);
987 }
988 catch (Exception e) {
989 throw processException(e);
990 }
991 finally {
992 if (list == null) {
993 FinderCacheUtil.removeResult(finderPath, finderArgs);
994 }
995 else {
996 cacheResult(list);
997
998 FinderCacheUtil.putResult(finderPath, finderArgs, list);
999 }
1000
1001 closeSession(session);
1002 }
1003 }
1004
1005 return list;
1006 }
1007
1008
1021 public SocialRelation findByUuid_First(String uuid,
1022 OrderByComparator orderByComparator)
1023 throws NoSuchRelationException, SystemException {
1024 List<SocialRelation> list = findByUuid(uuid, 0, 1, orderByComparator);
1025
1026 if (list.isEmpty()) {
1027 StringBundler msg = new StringBundler(4);
1028
1029 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1030
1031 msg.append("uuid=");
1032 msg.append(uuid);
1033
1034 msg.append(StringPool.CLOSE_CURLY_BRACE);
1035
1036 throw new NoSuchRelationException(msg.toString());
1037 }
1038 else {
1039 return list.get(0);
1040 }
1041 }
1042
1043
1056 public SocialRelation findByUuid_Last(String uuid,
1057 OrderByComparator orderByComparator)
1058 throws NoSuchRelationException, SystemException {
1059 int count = countByUuid(uuid);
1060
1061 List<SocialRelation> list = findByUuid(uuid, count - 1, count,
1062 orderByComparator);
1063
1064 if (list.isEmpty()) {
1065 StringBundler msg = new StringBundler(4);
1066
1067 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1068
1069 msg.append("uuid=");
1070 msg.append(uuid);
1071
1072 msg.append(StringPool.CLOSE_CURLY_BRACE);
1073
1074 throw new NoSuchRelationException(msg.toString());
1075 }
1076 else {
1077 return list.get(0);
1078 }
1079 }
1080
1081
1095 public SocialRelation[] findByUuid_PrevAndNext(long relationId,
1096 String uuid, OrderByComparator orderByComparator)
1097 throws NoSuchRelationException, SystemException {
1098 SocialRelation socialRelation = findByPrimaryKey(relationId);
1099
1100 Session session = null;
1101
1102 try {
1103 session = openSession();
1104
1105 SocialRelation[] array = new SocialRelationImpl[3];
1106
1107 array[0] = getByUuid_PrevAndNext(session, socialRelation, uuid,
1108 orderByComparator, true);
1109
1110 array[1] = socialRelation;
1111
1112 array[2] = getByUuid_PrevAndNext(session, socialRelation, uuid,
1113 orderByComparator, false);
1114
1115 return array;
1116 }
1117 catch (Exception e) {
1118 throw processException(e);
1119 }
1120 finally {
1121 closeSession(session);
1122 }
1123 }
1124
1125 protected SocialRelation getByUuid_PrevAndNext(Session session,
1126 SocialRelation socialRelation, String uuid,
1127 OrderByComparator orderByComparator, boolean previous) {
1128 StringBundler query = null;
1129
1130 if (orderByComparator != null) {
1131 query = new StringBundler(6 +
1132 (orderByComparator.getOrderByFields().length * 6));
1133 }
1134 else {
1135 query = new StringBundler(3);
1136 }
1137
1138 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
1139
1140 if (uuid == null) {
1141 query.append(_FINDER_COLUMN_UUID_UUID_1);
1142 }
1143 else {
1144 if (uuid.equals(StringPool.BLANK)) {
1145 query.append(_FINDER_COLUMN_UUID_UUID_3);
1146 }
1147 else {
1148 query.append(_FINDER_COLUMN_UUID_UUID_2);
1149 }
1150 }
1151
1152 if (orderByComparator != null) {
1153 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1154
1155 if (orderByConditionFields.length > 0) {
1156 query.append(WHERE_AND);
1157 }
1158
1159 for (int i = 0; i < orderByConditionFields.length; i++) {
1160 query.append(_ORDER_BY_ENTITY_ALIAS);
1161 query.append(orderByConditionFields[i]);
1162
1163 if ((i + 1) < orderByConditionFields.length) {
1164 if (orderByComparator.isAscending() ^ previous) {
1165 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1166 }
1167 else {
1168 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1169 }
1170 }
1171 else {
1172 if (orderByComparator.isAscending() ^ previous) {
1173 query.append(WHERE_GREATER_THAN);
1174 }
1175 else {
1176 query.append(WHERE_LESSER_THAN);
1177 }
1178 }
1179 }
1180
1181 query.append(ORDER_BY_CLAUSE);
1182
1183 String[] orderByFields = orderByComparator.getOrderByFields();
1184
1185 for (int i = 0; i < orderByFields.length; i++) {
1186 query.append(_ORDER_BY_ENTITY_ALIAS);
1187 query.append(orderByFields[i]);
1188
1189 if ((i + 1) < orderByFields.length) {
1190 if (orderByComparator.isAscending() ^ previous) {
1191 query.append(ORDER_BY_ASC_HAS_NEXT);
1192 }
1193 else {
1194 query.append(ORDER_BY_DESC_HAS_NEXT);
1195 }
1196 }
1197 else {
1198 if (orderByComparator.isAscending() ^ previous) {
1199 query.append(ORDER_BY_ASC);
1200 }
1201 else {
1202 query.append(ORDER_BY_DESC);
1203 }
1204 }
1205 }
1206 }
1207
1208 String sql = query.toString();
1209
1210 Query q = session.createQuery(sql);
1211
1212 q.setFirstResult(0);
1213 q.setMaxResults(2);
1214
1215 QueryPos qPos = QueryPos.getInstance(q);
1216
1217 if (uuid != null) {
1218 qPos.add(uuid);
1219 }
1220
1221 if (orderByComparator != null) {
1222 Object[] values = orderByComparator.getOrderByConditionValues(socialRelation);
1223
1224 for (Object value : values) {
1225 qPos.add(value);
1226 }
1227 }
1228
1229 List<SocialRelation> list = q.list();
1230
1231 if (list.size() == 2) {
1232 return list.get(1);
1233 }
1234 else {
1235 return null;
1236 }
1237 }
1238
1239
1246 public List<SocialRelation> findByCompanyId(long companyId)
1247 throws SystemException {
1248 return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1249 null);
1250 }
1251
1252
1265 public List<SocialRelation> findByCompanyId(long companyId, int start,
1266 int end) throws SystemException {
1267 return findByCompanyId(companyId, start, end, null);
1268 }
1269
1270
1284 public List<SocialRelation> findByCompanyId(long companyId, int start,
1285 int end, OrderByComparator orderByComparator) throws SystemException {
1286 FinderPath finderPath = null;
1287 Object[] finderArgs = null;
1288
1289 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1290 (orderByComparator == null)) {
1291 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
1292 finderArgs = new Object[] { companyId };
1293 }
1294 else {
1295 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
1296 finderArgs = new Object[] { companyId, start, end, orderByComparator };
1297 }
1298
1299 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(finderPath,
1300 finderArgs, this);
1301
1302 if (list == null) {
1303 StringBundler query = null;
1304
1305 if (orderByComparator != null) {
1306 query = new StringBundler(3 +
1307 (orderByComparator.getOrderByFields().length * 3));
1308 }
1309 else {
1310 query = new StringBundler(2);
1311 }
1312
1313 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
1314
1315 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1316
1317 if (orderByComparator != null) {
1318 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1319 orderByComparator);
1320 }
1321
1322 String sql = query.toString();
1323
1324 Session session = null;
1325
1326 try {
1327 session = openSession();
1328
1329 Query q = session.createQuery(sql);
1330
1331 QueryPos qPos = QueryPos.getInstance(q);
1332
1333 qPos.add(companyId);
1334
1335 list = (List<SocialRelation>)QueryUtil.list(q, getDialect(),
1336 start, end);
1337 }
1338 catch (Exception e) {
1339 throw processException(e);
1340 }
1341 finally {
1342 if (list == null) {
1343 FinderCacheUtil.removeResult(finderPath, finderArgs);
1344 }
1345 else {
1346 cacheResult(list);
1347
1348 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1349 }
1350
1351 closeSession(session);
1352 }
1353 }
1354
1355 return list;
1356 }
1357
1358
1371 public SocialRelation findByCompanyId_First(long companyId,
1372 OrderByComparator orderByComparator)
1373 throws NoSuchRelationException, SystemException {
1374 List<SocialRelation> list = findByCompanyId(companyId, 0, 1,
1375 orderByComparator);
1376
1377 if (list.isEmpty()) {
1378 StringBundler msg = new StringBundler(4);
1379
1380 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1381
1382 msg.append("companyId=");
1383 msg.append(companyId);
1384
1385 msg.append(StringPool.CLOSE_CURLY_BRACE);
1386
1387 throw new NoSuchRelationException(msg.toString());
1388 }
1389 else {
1390 return list.get(0);
1391 }
1392 }
1393
1394
1407 public SocialRelation findByCompanyId_Last(long companyId,
1408 OrderByComparator orderByComparator)
1409 throws NoSuchRelationException, SystemException {
1410 int count = countByCompanyId(companyId);
1411
1412 List<SocialRelation> list = findByCompanyId(companyId, count - 1,
1413 count, orderByComparator);
1414
1415 if (list.isEmpty()) {
1416 StringBundler msg = new StringBundler(4);
1417
1418 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1419
1420 msg.append("companyId=");
1421 msg.append(companyId);
1422
1423 msg.append(StringPool.CLOSE_CURLY_BRACE);
1424
1425 throw new NoSuchRelationException(msg.toString());
1426 }
1427 else {
1428 return list.get(0);
1429 }
1430 }
1431
1432
1446 public SocialRelation[] findByCompanyId_PrevAndNext(long relationId,
1447 long companyId, OrderByComparator orderByComparator)
1448 throws NoSuchRelationException, SystemException {
1449 SocialRelation socialRelation = findByPrimaryKey(relationId);
1450
1451 Session session = null;
1452
1453 try {
1454 session = openSession();
1455
1456 SocialRelation[] array = new SocialRelationImpl[3];
1457
1458 array[0] = getByCompanyId_PrevAndNext(session, socialRelation,
1459 companyId, orderByComparator, true);
1460
1461 array[1] = socialRelation;
1462
1463 array[2] = getByCompanyId_PrevAndNext(session, socialRelation,
1464 companyId, orderByComparator, false);
1465
1466 return array;
1467 }
1468 catch (Exception e) {
1469 throw processException(e);
1470 }
1471 finally {
1472 closeSession(session);
1473 }
1474 }
1475
1476 protected SocialRelation getByCompanyId_PrevAndNext(Session session,
1477 SocialRelation socialRelation, long companyId,
1478 OrderByComparator orderByComparator, boolean previous) {
1479 StringBundler query = null;
1480
1481 if (orderByComparator != null) {
1482 query = new StringBundler(6 +
1483 (orderByComparator.getOrderByFields().length * 6));
1484 }
1485 else {
1486 query = new StringBundler(3);
1487 }
1488
1489 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
1490
1491 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1492
1493 if (orderByComparator != null) {
1494 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1495
1496 if (orderByConditionFields.length > 0) {
1497 query.append(WHERE_AND);
1498 }
1499
1500 for (int i = 0; i < orderByConditionFields.length; i++) {
1501 query.append(_ORDER_BY_ENTITY_ALIAS);
1502 query.append(orderByConditionFields[i]);
1503
1504 if ((i + 1) < orderByConditionFields.length) {
1505 if (orderByComparator.isAscending() ^ previous) {
1506 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1507 }
1508 else {
1509 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1510 }
1511 }
1512 else {
1513 if (orderByComparator.isAscending() ^ previous) {
1514 query.append(WHERE_GREATER_THAN);
1515 }
1516 else {
1517 query.append(WHERE_LESSER_THAN);
1518 }
1519 }
1520 }
1521
1522 query.append(ORDER_BY_CLAUSE);
1523
1524 String[] orderByFields = orderByComparator.getOrderByFields();
1525
1526 for (int i = 0; i < orderByFields.length; i++) {
1527 query.append(_ORDER_BY_ENTITY_ALIAS);
1528 query.append(orderByFields[i]);
1529
1530 if ((i + 1) < orderByFields.length) {
1531 if (orderByComparator.isAscending() ^ previous) {
1532 query.append(ORDER_BY_ASC_HAS_NEXT);
1533 }
1534 else {
1535 query.append(ORDER_BY_DESC_HAS_NEXT);
1536 }
1537 }
1538 else {
1539 if (orderByComparator.isAscending() ^ previous) {
1540 query.append(ORDER_BY_ASC);
1541 }
1542 else {
1543 query.append(ORDER_BY_DESC);
1544 }
1545 }
1546 }
1547 }
1548
1549 String sql = query.toString();
1550
1551 Query q = session.createQuery(sql);
1552
1553 q.setFirstResult(0);
1554 q.setMaxResults(2);
1555
1556 QueryPos qPos = QueryPos.getInstance(q);
1557
1558 qPos.add(companyId);
1559
1560 if (orderByComparator != null) {
1561 Object[] values = orderByComparator.getOrderByConditionValues(socialRelation);
1562
1563 for (Object value : values) {
1564 qPos.add(value);
1565 }
1566 }
1567
1568 List<SocialRelation> list = q.list();
1569
1570 if (list.size() == 2) {
1571 return list.get(1);
1572 }
1573 else {
1574 return null;
1575 }
1576 }
1577
1578
1585 public List<SocialRelation> findByUserId1(long userId1)
1586 throws SystemException {
1587 return findByUserId1(userId1, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1588 }
1589
1590
1603 public List<SocialRelation> findByUserId1(long userId1, int start, int end)
1604 throws SystemException {
1605 return findByUserId1(userId1, start, end, null);
1606 }
1607
1608
1622 public List<SocialRelation> findByUserId1(long userId1, int start, int end,
1623 OrderByComparator orderByComparator) throws SystemException {
1624 FinderPath finderPath = null;
1625 Object[] finderArgs = null;
1626
1627 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1628 (orderByComparator == null)) {
1629 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID1;
1630 finderArgs = new Object[] { userId1 };
1631 }
1632 else {
1633 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID1;
1634 finderArgs = new Object[] { userId1, start, end, orderByComparator };
1635 }
1636
1637 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(finderPath,
1638 finderArgs, this);
1639
1640 if (list == null) {
1641 StringBundler query = null;
1642
1643 if (orderByComparator != null) {
1644 query = new StringBundler(3 +
1645 (orderByComparator.getOrderByFields().length * 3));
1646 }
1647 else {
1648 query = new StringBundler(2);
1649 }
1650
1651 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
1652
1653 query.append(_FINDER_COLUMN_USERID1_USERID1_2);
1654
1655 if (orderByComparator != null) {
1656 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1657 orderByComparator);
1658 }
1659
1660 String sql = query.toString();
1661
1662 Session session = null;
1663
1664 try {
1665 session = openSession();
1666
1667 Query q = session.createQuery(sql);
1668
1669 QueryPos qPos = QueryPos.getInstance(q);
1670
1671 qPos.add(userId1);
1672
1673 list = (List<SocialRelation>)QueryUtil.list(q, getDialect(),
1674 start, end);
1675 }
1676 catch (Exception e) {
1677 throw processException(e);
1678 }
1679 finally {
1680 if (list == null) {
1681 FinderCacheUtil.removeResult(finderPath, finderArgs);
1682 }
1683 else {
1684 cacheResult(list);
1685
1686 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1687 }
1688
1689 closeSession(session);
1690 }
1691 }
1692
1693 return list;
1694 }
1695
1696
1709 public SocialRelation findByUserId1_First(long userId1,
1710 OrderByComparator orderByComparator)
1711 throws NoSuchRelationException, SystemException {
1712 List<SocialRelation> list = findByUserId1(userId1, 0, 1,
1713 orderByComparator);
1714
1715 if (list.isEmpty()) {
1716 StringBundler msg = new StringBundler(4);
1717
1718 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1719
1720 msg.append("userId1=");
1721 msg.append(userId1);
1722
1723 msg.append(StringPool.CLOSE_CURLY_BRACE);
1724
1725 throw new NoSuchRelationException(msg.toString());
1726 }
1727 else {
1728 return list.get(0);
1729 }
1730 }
1731
1732
1745 public SocialRelation findByUserId1_Last(long userId1,
1746 OrderByComparator orderByComparator)
1747 throws NoSuchRelationException, SystemException {
1748 int count = countByUserId1(userId1);
1749
1750 List<SocialRelation> list = findByUserId1(userId1, count - 1, count,
1751 orderByComparator);
1752
1753 if (list.isEmpty()) {
1754 StringBundler msg = new StringBundler(4);
1755
1756 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1757
1758 msg.append("userId1=");
1759 msg.append(userId1);
1760
1761 msg.append(StringPool.CLOSE_CURLY_BRACE);
1762
1763 throw new NoSuchRelationException(msg.toString());
1764 }
1765 else {
1766 return list.get(0);
1767 }
1768 }
1769
1770
1784 public SocialRelation[] findByUserId1_PrevAndNext(long relationId,
1785 long userId1, OrderByComparator orderByComparator)
1786 throws NoSuchRelationException, SystemException {
1787 SocialRelation socialRelation = findByPrimaryKey(relationId);
1788
1789 Session session = null;
1790
1791 try {
1792 session = openSession();
1793
1794 SocialRelation[] array = new SocialRelationImpl[3];
1795
1796 array[0] = getByUserId1_PrevAndNext(session, socialRelation,
1797 userId1, orderByComparator, true);
1798
1799 array[1] = socialRelation;
1800
1801 array[2] = getByUserId1_PrevAndNext(session, socialRelation,
1802 userId1, orderByComparator, false);
1803
1804 return array;
1805 }
1806 catch (Exception e) {
1807 throw processException(e);
1808 }
1809 finally {
1810 closeSession(session);
1811 }
1812 }
1813
1814 protected SocialRelation getByUserId1_PrevAndNext(Session session,
1815 SocialRelation socialRelation, long userId1,
1816 OrderByComparator orderByComparator, boolean previous) {
1817 StringBundler query = null;
1818
1819 if (orderByComparator != null) {
1820 query = new StringBundler(6 +
1821 (orderByComparator.getOrderByFields().length * 6));
1822 }
1823 else {
1824 query = new StringBundler(3);
1825 }
1826
1827 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
1828
1829 query.append(_FINDER_COLUMN_USERID1_USERID1_2);
1830
1831 if (orderByComparator != null) {
1832 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1833
1834 if (orderByConditionFields.length > 0) {
1835 query.append(WHERE_AND);
1836 }
1837
1838 for (int i = 0; i < orderByConditionFields.length; i++) {
1839 query.append(_ORDER_BY_ENTITY_ALIAS);
1840 query.append(orderByConditionFields[i]);
1841
1842 if ((i + 1) < orderByConditionFields.length) {
1843 if (orderByComparator.isAscending() ^ previous) {
1844 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1845 }
1846 else {
1847 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1848 }
1849 }
1850 else {
1851 if (orderByComparator.isAscending() ^ previous) {
1852 query.append(WHERE_GREATER_THAN);
1853 }
1854 else {
1855 query.append(WHERE_LESSER_THAN);
1856 }
1857 }
1858 }
1859
1860 query.append(ORDER_BY_CLAUSE);
1861
1862 String[] orderByFields = orderByComparator.getOrderByFields();
1863
1864 for (int i = 0; i < orderByFields.length; i++) {
1865 query.append(_ORDER_BY_ENTITY_ALIAS);
1866 query.append(orderByFields[i]);
1867
1868 if ((i + 1) < orderByFields.length) {
1869 if (orderByComparator.isAscending() ^ previous) {
1870 query.append(ORDER_BY_ASC_HAS_NEXT);
1871 }
1872 else {
1873 query.append(ORDER_BY_DESC_HAS_NEXT);
1874 }
1875 }
1876 else {
1877 if (orderByComparator.isAscending() ^ previous) {
1878 query.append(ORDER_BY_ASC);
1879 }
1880 else {
1881 query.append(ORDER_BY_DESC);
1882 }
1883 }
1884 }
1885 }
1886
1887 String sql = query.toString();
1888
1889 Query q = session.createQuery(sql);
1890
1891 q.setFirstResult(0);
1892 q.setMaxResults(2);
1893
1894 QueryPos qPos = QueryPos.getInstance(q);
1895
1896 qPos.add(userId1);
1897
1898 if (orderByComparator != null) {
1899 Object[] values = orderByComparator.getOrderByConditionValues(socialRelation);
1900
1901 for (Object value : values) {
1902 qPos.add(value);
1903 }
1904 }
1905
1906 List<SocialRelation> list = q.list();
1907
1908 if (list.size() == 2) {
1909 return list.get(1);
1910 }
1911 else {
1912 return null;
1913 }
1914 }
1915
1916
1923 public List<SocialRelation> findByUserId2(long userId2)
1924 throws SystemException {
1925 return findByUserId2(userId2, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1926 }
1927
1928
1941 public List<SocialRelation> findByUserId2(long userId2, int start, int end)
1942 throws SystemException {
1943 return findByUserId2(userId2, start, end, null);
1944 }
1945
1946
1960 public List<SocialRelation> findByUserId2(long userId2, int start, int end,
1961 OrderByComparator orderByComparator) throws SystemException {
1962 FinderPath finderPath = null;
1963 Object[] finderArgs = null;
1964
1965 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1966 (orderByComparator == null)) {
1967 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID2;
1968 finderArgs = new Object[] { userId2 };
1969 }
1970 else {
1971 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID2;
1972 finderArgs = new Object[] { userId2, start, end, orderByComparator };
1973 }
1974
1975 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(finderPath,
1976 finderArgs, this);
1977
1978 if (list == null) {
1979 StringBundler query = null;
1980
1981 if (orderByComparator != null) {
1982 query = new StringBundler(3 +
1983 (orderByComparator.getOrderByFields().length * 3));
1984 }
1985 else {
1986 query = new StringBundler(2);
1987 }
1988
1989 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
1990
1991 query.append(_FINDER_COLUMN_USERID2_USERID2_2);
1992
1993 if (orderByComparator != null) {
1994 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1995 orderByComparator);
1996 }
1997
1998 String sql = query.toString();
1999
2000 Session session = null;
2001
2002 try {
2003 session = openSession();
2004
2005 Query q = session.createQuery(sql);
2006
2007 QueryPos qPos = QueryPos.getInstance(q);
2008
2009 qPos.add(userId2);
2010
2011 list = (List<SocialRelation>)QueryUtil.list(q, getDialect(),
2012 start, end);
2013 }
2014 catch (Exception e) {
2015 throw processException(e);
2016 }
2017 finally {
2018 if (list == null) {
2019 FinderCacheUtil.removeResult(finderPath, finderArgs);
2020 }
2021 else {
2022 cacheResult(list);
2023
2024 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2025 }
2026
2027 closeSession(session);
2028 }
2029 }
2030
2031 return list;
2032 }
2033
2034
2047 public SocialRelation findByUserId2_First(long userId2,
2048 OrderByComparator orderByComparator)
2049 throws NoSuchRelationException, SystemException {
2050 List<SocialRelation> list = findByUserId2(userId2, 0, 1,
2051 orderByComparator);
2052
2053 if (list.isEmpty()) {
2054 StringBundler msg = new StringBundler(4);
2055
2056 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2057
2058 msg.append("userId2=");
2059 msg.append(userId2);
2060
2061 msg.append(StringPool.CLOSE_CURLY_BRACE);
2062
2063 throw new NoSuchRelationException(msg.toString());
2064 }
2065 else {
2066 return list.get(0);
2067 }
2068 }
2069
2070
2083 public SocialRelation findByUserId2_Last(long userId2,
2084 OrderByComparator orderByComparator)
2085 throws NoSuchRelationException, SystemException {
2086 int count = countByUserId2(userId2);
2087
2088 List<SocialRelation> list = findByUserId2(userId2, count - 1, count,
2089 orderByComparator);
2090
2091 if (list.isEmpty()) {
2092 StringBundler msg = new StringBundler(4);
2093
2094 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2095
2096 msg.append("userId2=");
2097 msg.append(userId2);
2098
2099 msg.append(StringPool.CLOSE_CURLY_BRACE);
2100
2101 throw new NoSuchRelationException(msg.toString());
2102 }
2103 else {
2104 return list.get(0);
2105 }
2106 }
2107
2108
2122 public SocialRelation[] findByUserId2_PrevAndNext(long relationId,
2123 long userId2, OrderByComparator orderByComparator)
2124 throws NoSuchRelationException, SystemException {
2125 SocialRelation socialRelation = findByPrimaryKey(relationId);
2126
2127 Session session = null;
2128
2129 try {
2130 session = openSession();
2131
2132 SocialRelation[] array = new SocialRelationImpl[3];
2133
2134 array[0] = getByUserId2_PrevAndNext(session, socialRelation,
2135 userId2, orderByComparator, true);
2136
2137 array[1] = socialRelation;
2138
2139 array[2] = getByUserId2_PrevAndNext(session, socialRelation,
2140 userId2, orderByComparator, false);
2141
2142 return array;
2143 }
2144 catch (Exception e) {
2145 throw processException(e);
2146 }
2147 finally {
2148 closeSession(session);
2149 }
2150 }
2151
2152 protected SocialRelation getByUserId2_PrevAndNext(Session session,
2153 SocialRelation socialRelation, long userId2,
2154 OrderByComparator orderByComparator, boolean previous) {
2155 StringBundler query = null;
2156
2157 if (orderByComparator != null) {
2158 query = new StringBundler(6 +
2159 (orderByComparator.getOrderByFields().length * 6));
2160 }
2161 else {
2162 query = new StringBundler(3);
2163 }
2164
2165 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
2166
2167 query.append(_FINDER_COLUMN_USERID2_USERID2_2);
2168
2169 if (orderByComparator != null) {
2170 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2171
2172 if (orderByConditionFields.length > 0) {
2173 query.append(WHERE_AND);
2174 }
2175
2176 for (int i = 0; i < orderByConditionFields.length; i++) {
2177 query.append(_ORDER_BY_ENTITY_ALIAS);
2178 query.append(orderByConditionFields[i]);
2179
2180 if ((i + 1) < orderByConditionFields.length) {
2181 if (orderByComparator.isAscending() ^ previous) {
2182 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2183 }
2184 else {
2185 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2186 }
2187 }
2188 else {
2189 if (orderByComparator.isAscending() ^ previous) {
2190 query.append(WHERE_GREATER_THAN);
2191 }
2192 else {
2193 query.append(WHERE_LESSER_THAN);
2194 }
2195 }
2196 }
2197
2198 query.append(ORDER_BY_CLAUSE);
2199
2200 String[] orderByFields = orderByComparator.getOrderByFields();
2201
2202 for (int i = 0; i < orderByFields.length; i++) {
2203 query.append(_ORDER_BY_ENTITY_ALIAS);
2204 query.append(orderByFields[i]);
2205
2206 if ((i + 1) < orderByFields.length) {
2207 if (orderByComparator.isAscending() ^ previous) {
2208 query.append(ORDER_BY_ASC_HAS_NEXT);
2209 }
2210 else {
2211 query.append(ORDER_BY_DESC_HAS_NEXT);
2212 }
2213 }
2214 else {
2215 if (orderByComparator.isAscending() ^ previous) {
2216 query.append(ORDER_BY_ASC);
2217 }
2218 else {
2219 query.append(ORDER_BY_DESC);
2220 }
2221 }
2222 }
2223 }
2224
2225 String sql = query.toString();
2226
2227 Query q = session.createQuery(sql);
2228
2229 q.setFirstResult(0);
2230 q.setMaxResults(2);
2231
2232 QueryPos qPos = QueryPos.getInstance(q);
2233
2234 qPos.add(userId2);
2235
2236 if (orderByComparator != null) {
2237 Object[] values = orderByComparator.getOrderByConditionValues(socialRelation);
2238
2239 for (Object value : values) {
2240 qPos.add(value);
2241 }
2242 }
2243
2244 List<SocialRelation> list = q.list();
2245
2246 if (list.size() == 2) {
2247 return list.get(1);
2248 }
2249 else {
2250 return null;
2251 }
2252 }
2253
2254
2261 public List<SocialRelation> findByType(int type) throws SystemException {
2262 return findByType(type, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2263 }
2264
2265
2278 public List<SocialRelation> findByType(int type, int start, int end)
2279 throws SystemException {
2280 return findByType(type, start, end, null);
2281 }
2282
2283
2297 public List<SocialRelation> findByType(int type, int start, int end,
2298 OrderByComparator orderByComparator) throws SystemException {
2299 FinderPath finderPath = null;
2300 Object[] finderArgs = null;
2301
2302 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2303 (orderByComparator == null)) {
2304 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE;
2305 finderArgs = new Object[] { type };
2306 }
2307 else {
2308 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_TYPE;
2309 finderArgs = new Object[] { type, start, end, orderByComparator };
2310 }
2311
2312 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(finderPath,
2313 finderArgs, this);
2314
2315 if (list == null) {
2316 StringBundler query = null;
2317
2318 if (orderByComparator != null) {
2319 query = new StringBundler(3 +
2320 (orderByComparator.getOrderByFields().length * 3));
2321 }
2322 else {
2323 query = new StringBundler(2);
2324 }
2325
2326 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
2327
2328 query.append(_FINDER_COLUMN_TYPE_TYPE_2);
2329
2330 if (orderByComparator != null) {
2331 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2332 orderByComparator);
2333 }
2334
2335 String sql = query.toString();
2336
2337 Session session = null;
2338
2339 try {
2340 session = openSession();
2341
2342 Query q = session.createQuery(sql);
2343
2344 QueryPos qPos = QueryPos.getInstance(q);
2345
2346 qPos.add(type);
2347
2348 list = (List<SocialRelation>)QueryUtil.list(q, getDialect(),
2349 start, end);
2350 }
2351 catch (Exception e) {
2352 throw processException(e);
2353 }
2354 finally {
2355 if (list == null) {
2356 FinderCacheUtil.removeResult(finderPath, finderArgs);
2357 }
2358 else {
2359 cacheResult(list);
2360
2361 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2362 }
2363
2364 closeSession(session);
2365 }
2366 }
2367
2368 return list;
2369 }
2370
2371
2384 public SocialRelation findByType_First(int type,
2385 OrderByComparator orderByComparator)
2386 throws NoSuchRelationException, SystemException {
2387 List<SocialRelation> list = findByType(type, 0, 1, orderByComparator);
2388
2389 if (list.isEmpty()) {
2390 StringBundler msg = new StringBundler(4);
2391
2392 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2393
2394 msg.append("type=");
2395 msg.append(type);
2396
2397 msg.append(StringPool.CLOSE_CURLY_BRACE);
2398
2399 throw new NoSuchRelationException(msg.toString());
2400 }
2401 else {
2402 return list.get(0);
2403 }
2404 }
2405
2406
2419 public SocialRelation findByType_Last(int type,
2420 OrderByComparator orderByComparator)
2421 throws NoSuchRelationException, SystemException {
2422 int count = countByType(type);
2423
2424 List<SocialRelation> list = findByType(type, count - 1, count,
2425 orderByComparator);
2426
2427 if (list.isEmpty()) {
2428 StringBundler msg = new StringBundler(4);
2429
2430 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2431
2432 msg.append("type=");
2433 msg.append(type);
2434
2435 msg.append(StringPool.CLOSE_CURLY_BRACE);
2436
2437 throw new NoSuchRelationException(msg.toString());
2438 }
2439 else {
2440 return list.get(0);
2441 }
2442 }
2443
2444
2458 public SocialRelation[] findByType_PrevAndNext(long relationId, int type,
2459 OrderByComparator orderByComparator)
2460 throws NoSuchRelationException, SystemException {
2461 SocialRelation socialRelation = findByPrimaryKey(relationId);
2462
2463 Session session = null;
2464
2465 try {
2466 session = openSession();
2467
2468 SocialRelation[] array = new SocialRelationImpl[3];
2469
2470 array[0] = getByType_PrevAndNext(session, socialRelation, type,
2471 orderByComparator, true);
2472
2473 array[1] = socialRelation;
2474
2475 array[2] = getByType_PrevAndNext(session, socialRelation, type,
2476 orderByComparator, false);
2477
2478 return array;
2479 }
2480 catch (Exception e) {
2481 throw processException(e);
2482 }
2483 finally {
2484 closeSession(session);
2485 }
2486 }
2487
2488 protected SocialRelation getByType_PrevAndNext(Session session,
2489 SocialRelation socialRelation, int type,
2490 OrderByComparator orderByComparator, boolean previous) {
2491 StringBundler query = null;
2492
2493 if (orderByComparator != null) {
2494 query = new StringBundler(6 +
2495 (orderByComparator.getOrderByFields().length * 6));
2496 }
2497 else {
2498 query = new StringBundler(3);
2499 }
2500
2501 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
2502
2503 query.append(_FINDER_COLUMN_TYPE_TYPE_2);
2504
2505 if (orderByComparator != null) {
2506 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2507
2508 if (orderByConditionFields.length > 0) {
2509 query.append(WHERE_AND);
2510 }
2511
2512 for (int i = 0; i < orderByConditionFields.length; i++) {
2513 query.append(_ORDER_BY_ENTITY_ALIAS);
2514 query.append(orderByConditionFields[i]);
2515
2516 if ((i + 1) < orderByConditionFields.length) {
2517 if (orderByComparator.isAscending() ^ previous) {
2518 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2519 }
2520 else {
2521 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2522 }
2523 }
2524 else {
2525 if (orderByComparator.isAscending() ^ previous) {
2526 query.append(WHERE_GREATER_THAN);
2527 }
2528 else {
2529 query.append(WHERE_LESSER_THAN);
2530 }
2531 }
2532 }
2533
2534 query.append(ORDER_BY_CLAUSE);
2535
2536 String[] orderByFields = orderByComparator.getOrderByFields();
2537
2538 for (int i = 0; i < orderByFields.length; i++) {
2539 query.append(_ORDER_BY_ENTITY_ALIAS);
2540 query.append(orderByFields[i]);
2541
2542 if ((i + 1) < orderByFields.length) {
2543 if (orderByComparator.isAscending() ^ previous) {
2544 query.append(ORDER_BY_ASC_HAS_NEXT);
2545 }
2546 else {
2547 query.append(ORDER_BY_DESC_HAS_NEXT);
2548 }
2549 }
2550 else {
2551 if (orderByComparator.isAscending() ^ previous) {
2552 query.append(ORDER_BY_ASC);
2553 }
2554 else {
2555 query.append(ORDER_BY_DESC);
2556 }
2557 }
2558 }
2559 }
2560
2561 String sql = query.toString();
2562
2563 Query q = session.createQuery(sql);
2564
2565 q.setFirstResult(0);
2566 q.setMaxResults(2);
2567
2568 QueryPos qPos = QueryPos.getInstance(q);
2569
2570 qPos.add(type);
2571
2572 if (orderByComparator != null) {
2573 Object[] values = orderByComparator.getOrderByConditionValues(socialRelation);
2574
2575 for (Object value : values) {
2576 qPos.add(value);
2577 }
2578 }
2579
2580 List<SocialRelation> list = q.list();
2581
2582 if (list.size() == 2) {
2583 return list.get(1);
2584 }
2585 else {
2586 return null;
2587 }
2588 }
2589
2590
2598 public List<SocialRelation> findByC_T(long companyId, int type)
2599 throws SystemException {
2600 return findByC_T(companyId, type, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2601 null);
2602 }
2603
2604
2618 public List<SocialRelation> findByC_T(long companyId, int type, int start,
2619 int end) throws SystemException {
2620 return findByC_T(companyId, type, start, end, null);
2621 }
2622
2623
2638 public List<SocialRelation> findByC_T(long companyId, int type, int start,
2639 int end, OrderByComparator orderByComparator) throws SystemException {
2640 FinderPath finderPath = null;
2641 Object[] finderArgs = null;
2642
2643 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2644 (orderByComparator == null)) {
2645 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_T;
2646 finderArgs = new Object[] { companyId, type };
2647 }
2648 else {
2649 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_T;
2650 finderArgs = new Object[] {
2651 companyId, type,
2652
2653 start, end, orderByComparator
2654 };
2655 }
2656
2657 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(finderPath,
2658 finderArgs, this);
2659
2660 if (list == null) {
2661 StringBundler query = null;
2662
2663 if (orderByComparator != null) {
2664 query = new StringBundler(4 +
2665 (orderByComparator.getOrderByFields().length * 3));
2666 }
2667 else {
2668 query = new StringBundler(3);
2669 }
2670
2671 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
2672
2673 query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
2674
2675 query.append(_FINDER_COLUMN_C_T_TYPE_2);
2676
2677 if (orderByComparator != null) {
2678 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2679 orderByComparator);
2680 }
2681
2682 String sql = query.toString();
2683
2684 Session session = null;
2685
2686 try {
2687 session = openSession();
2688
2689 Query q = session.createQuery(sql);
2690
2691 QueryPos qPos = QueryPos.getInstance(q);
2692
2693 qPos.add(companyId);
2694
2695 qPos.add(type);
2696
2697 list = (List<SocialRelation>)QueryUtil.list(q, getDialect(),
2698 start, end);
2699 }
2700 catch (Exception e) {
2701 throw processException(e);
2702 }
2703 finally {
2704 if (list == null) {
2705 FinderCacheUtil.removeResult(finderPath, finderArgs);
2706 }
2707 else {
2708 cacheResult(list);
2709
2710 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2711 }
2712
2713 closeSession(session);
2714 }
2715 }
2716
2717 return list;
2718 }
2719
2720
2734 public SocialRelation findByC_T_First(long companyId, int type,
2735 OrderByComparator orderByComparator)
2736 throws NoSuchRelationException, SystemException {
2737 List<SocialRelation> list = findByC_T(companyId, type, 0, 1,
2738 orderByComparator);
2739
2740 if (list.isEmpty()) {
2741 StringBundler msg = new StringBundler(6);
2742
2743 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2744
2745 msg.append("companyId=");
2746 msg.append(companyId);
2747
2748 msg.append(", type=");
2749 msg.append(type);
2750
2751 msg.append(StringPool.CLOSE_CURLY_BRACE);
2752
2753 throw new NoSuchRelationException(msg.toString());
2754 }
2755 else {
2756 return list.get(0);
2757 }
2758 }
2759
2760
2774 public SocialRelation findByC_T_Last(long companyId, int type,
2775 OrderByComparator orderByComparator)
2776 throws NoSuchRelationException, SystemException {
2777 int count = countByC_T(companyId, type);
2778
2779 List<SocialRelation> list = findByC_T(companyId, type, count - 1,
2780 count, orderByComparator);
2781
2782 if (list.isEmpty()) {
2783 StringBundler msg = new StringBundler(6);
2784
2785 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2786
2787 msg.append("companyId=");
2788 msg.append(companyId);
2789
2790 msg.append(", type=");
2791 msg.append(type);
2792
2793 msg.append(StringPool.CLOSE_CURLY_BRACE);
2794
2795 throw new NoSuchRelationException(msg.toString());
2796 }
2797 else {
2798 return list.get(0);
2799 }
2800 }
2801
2802
2817 public SocialRelation[] findByC_T_PrevAndNext(long relationId,
2818 long companyId, int type, OrderByComparator orderByComparator)
2819 throws NoSuchRelationException, SystemException {
2820 SocialRelation socialRelation = findByPrimaryKey(relationId);
2821
2822 Session session = null;
2823
2824 try {
2825 session = openSession();
2826
2827 SocialRelation[] array = new SocialRelationImpl[3];
2828
2829 array[0] = getByC_T_PrevAndNext(session, socialRelation, companyId,
2830 type, orderByComparator, true);
2831
2832 array[1] = socialRelation;
2833
2834 array[2] = getByC_T_PrevAndNext(session, socialRelation, companyId,
2835 type, orderByComparator, false);
2836
2837 return array;
2838 }
2839 catch (Exception e) {
2840 throw processException(e);
2841 }
2842 finally {
2843 closeSession(session);
2844 }
2845 }
2846
2847 protected SocialRelation getByC_T_PrevAndNext(Session session,
2848 SocialRelation socialRelation, long companyId, int type,
2849 OrderByComparator orderByComparator, boolean previous) {
2850 StringBundler query = null;
2851
2852 if (orderByComparator != null) {
2853 query = new StringBundler(6 +
2854 (orderByComparator.getOrderByFields().length * 6));
2855 }
2856 else {
2857 query = new StringBundler(3);
2858 }
2859
2860 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
2861
2862 query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
2863
2864 query.append(_FINDER_COLUMN_C_T_TYPE_2);
2865
2866 if (orderByComparator != null) {
2867 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2868
2869 if (orderByConditionFields.length > 0) {
2870 query.append(WHERE_AND);
2871 }
2872
2873 for (int i = 0; i < orderByConditionFields.length; i++) {
2874 query.append(_ORDER_BY_ENTITY_ALIAS);
2875 query.append(orderByConditionFields[i]);
2876
2877 if ((i + 1) < orderByConditionFields.length) {
2878 if (orderByComparator.isAscending() ^ previous) {
2879 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2880 }
2881 else {
2882 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2883 }
2884 }
2885 else {
2886 if (orderByComparator.isAscending() ^ previous) {
2887 query.append(WHERE_GREATER_THAN);
2888 }
2889 else {
2890 query.append(WHERE_LESSER_THAN);
2891 }
2892 }
2893 }
2894
2895 query.append(ORDER_BY_CLAUSE);
2896
2897 String[] orderByFields = orderByComparator.getOrderByFields();
2898
2899 for (int i = 0; i < orderByFields.length; i++) {
2900 query.append(_ORDER_BY_ENTITY_ALIAS);
2901 query.append(orderByFields[i]);
2902
2903 if ((i + 1) < orderByFields.length) {
2904 if (orderByComparator.isAscending() ^ previous) {
2905 query.append(ORDER_BY_ASC_HAS_NEXT);
2906 }
2907 else {
2908 query.append(ORDER_BY_DESC_HAS_NEXT);
2909 }
2910 }
2911 else {
2912 if (orderByComparator.isAscending() ^ previous) {
2913 query.append(ORDER_BY_ASC);
2914 }
2915 else {
2916 query.append(ORDER_BY_DESC);
2917 }
2918 }
2919 }
2920 }
2921
2922 String sql = query.toString();
2923
2924 Query q = session.createQuery(sql);
2925
2926 q.setFirstResult(0);
2927 q.setMaxResults(2);
2928
2929 QueryPos qPos = QueryPos.getInstance(q);
2930
2931 qPos.add(companyId);
2932
2933 qPos.add(type);
2934
2935 if (orderByComparator != null) {
2936 Object[] values = orderByComparator.getOrderByConditionValues(socialRelation);
2937
2938 for (Object value : values) {
2939 qPos.add(value);
2940 }
2941 }
2942
2943 List<SocialRelation> list = q.list();
2944
2945 if (list.size() == 2) {
2946 return list.get(1);
2947 }
2948 else {
2949 return null;
2950 }
2951 }
2952
2953
2961 public List<SocialRelation> findByU1_U2(long userId1, long userId2)
2962 throws SystemException {
2963 return findByU1_U2(userId1, userId2, QueryUtil.ALL_POS,
2964 QueryUtil.ALL_POS, null);
2965 }
2966
2967
2981 public List<SocialRelation> findByU1_U2(long userId1, long userId2,
2982 int start, int end) throws SystemException {
2983 return findByU1_U2(userId1, userId2, start, end, null);
2984 }
2985
2986
3001 public List<SocialRelation> findByU1_U2(long userId1, long userId2,
3002 int start, int end, OrderByComparator orderByComparator)
3003 throws SystemException {
3004 FinderPath finderPath = null;
3005 Object[] finderArgs = null;
3006
3007 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3008 (orderByComparator == null)) {
3009 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U1_U2;
3010 finderArgs = new Object[] { userId1, userId2 };
3011 }
3012 else {
3013 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U1_U2;
3014 finderArgs = new Object[] {
3015 userId1, userId2,
3016
3017 start, end, orderByComparator
3018 };
3019 }
3020
3021 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(finderPath,
3022 finderArgs, this);
3023
3024 if (list == null) {
3025 StringBundler query = null;
3026
3027 if (orderByComparator != null) {
3028 query = new StringBundler(4 +
3029 (orderByComparator.getOrderByFields().length * 3));
3030 }
3031 else {
3032 query = new StringBundler(3);
3033 }
3034
3035 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
3036
3037 query.append(_FINDER_COLUMN_U1_U2_USERID1_2);
3038
3039 query.append(_FINDER_COLUMN_U1_U2_USERID2_2);
3040
3041 if (orderByComparator != null) {
3042 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3043 orderByComparator);
3044 }
3045
3046 String sql = query.toString();
3047
3048 Session session = null;
3049
3050 try {
3051 session = openSession();
3052
3053 Query q = session.createQuery(sql);
3054
3055 QueryPos qPos = QueryPos.getInstance(q);
3056
3057 qPos.add(userId1);
3058
3059 qPos.add(userId2);
3060
3061 list = (List<SocialRelation>)QueryUtil.list(q, getDialect(),
3062 start, end);
3063 }
3064 catch (Exception e) {
3065 throw processException(e);
3066 }
3067 finally {
3068 if (list == null) {
3069 FinderCacheUtil.removeResult(finderPath, finderArgs);
3070 }
3071 else {
3072 cacheResult(list);
3073
3074 FinderCacheUtil.putResult(finderPath, finderArgs, list);
3075 }
3076
3077 closeSession(session);
3078 }
3079 }
3080
3081 return list;
3082 }
3083
3084
3098 public SocialRelation findByU1_U2_First(long userId1, long userId2,
3099 OrderByComparator orderByComparator)
3100 throws NoSuchRelationException, SystemException {
3101 List<SocialRelation> list = findByU1_U2(userId1, userId2, 0, 1,
3102 orderByComparator);
3103
3104 if (list.isEmpty()) {
3105 StringBundler msg = new StringBundler(6);
3106
3107 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3108
3109 msg.append("userId1=");
3110 msg.append(userId1);
3111
3112 msg.append(", userId2=");
3113 msg.append(userId2);
3114
3115 msg.append(StringPool.CLOSE_CURLY_BRACE);
3116
3117 throw new NoSuchRelationException(msg.toString());
3118 }
3119 else {
3120 return list.get(0);
3121 }
3122 }
3123
3124
3138 public SocialRelation findByU1_U2_Last(long userId1, long userId2,
3139 OrderByComparator orderByComparator)
3140 throws NoSuchRelationException, SystemException {
3141 int count = countByU1_U2(userId1, userId2);
3142
3143 List<SocialRelation> list = findByU1_U2(userId1, userId2, count - 1,
3144 count, orderByComparator);
3145
3146 if (list.isEmpty()) {
3147 StringBundler msg = new StringBundler(6);
3148
3149 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3150
3151 msg.append("userId1=");
3152 msg.append(userId1);
3153
3154 msg.append(", userId2=");
3155 msg.append(userId2);
3156
3157 msg.append(StringPool.CLOSE_CURLY_BRACE);
3158
3159 throw new NoSuchRelationException(msg.toString());
3160 }
3161 else {
3162 return list.get(0);
3163 }
3164 }
3165
3166
3181 public SocialRelation[] findByU1_U2_PrevAndNext(long relationId,
3182 long userId1, long userId2, OrderByComparator orderByComparator)
3183 throws NoSuchRelationException, SystemException {
3184 SocialRelation socialRelation = findByPrimaryKey(relationId);
3185
3186 Session session = null;
3187
3188 try {
3189 session = openSession();
3190
3191 SocialRelation[] array = new SocialRelationImpl[3];
3192
3193 array[0] = getByU1_U2_PrevAndNext(session, socialRelation, userId1,
3194 userId2, orderByComparator, true);
3195
3196 array[1] = socialRelation;
3197
3198 array[2] = getByU1_U2_PrevAndNext(session, socialRelation, userId1,
3199 userId2, orderByComparator, false);
3200
3201 return array;
3202 }
3203 catch (Exception e) {
3204 throw processException(e);
3205 }
3206 finally {
3207 closeSession(session);
3208 }
3209 }
3210
3211 protected SocialRelation getByU1_U2_PrevAndNext(Session session,
3212 SocialRelation socialRelation, long userId1, long userId2,
3213 OrderByComparator orderByComparator, boolean previous) {
3214 StringBundler query = null;
3215
3216 if (orderByComparator != null) {
3217 query = new StringBundler(6 +
3218 (orderByComparator.getOrderByFields().length * 6));
3219 }
3220 else {
3221 query = new StringBundler(3);
3222 }
3223
3224 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
3225
3226 query.append(_FINDER_COLUMN_U1_U2_USERID1_2);
3227
3228 query.append(_FINDER_COLUMN_U1_U2_USERID2_2);
3229
3230 if (orderByComparator != null) {
3231 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3232
3233 if (orderByConditionFields.length > 0) {
3234 query.append(WHERE_AND);
3235 }
3236
3237 for (int i = 0; i < orderByConditionFields.length; i++) {
3238 query.append(_ORDER_BY_ENTITY_ALIAS);
3239 query.append(orderByConditionFields[i]);
3240
3241 if ((i + 1) < orderByConditionFields.length) {
3242 if (orderByComparator.isAscending() ^ previous) {
3243 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3244 }
3245 else {
3246 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3247 }
3248 }
3249 else {
3250 if (orderByComparator.isAscending() ^ previous) {
3251 query.append(WHERE_GREATER_THAN);
3252 }
3253 else {
3254 query.append(WHERE_LESSER_THAN);
3255 }
3256 }
3257 }
3258
3259 query.append(ORDER_BY_CLAUSE);
3260
3261 String[] orderByFields = orderByComparator.getOrderByFields();
3262
3263 for (int i = 0; i < orderByFields.length; i++) {
3264 query.append(_ORDER_BY_ENTITY_ALIAS);
3265 query.append(orderByFields[i]);
3266
3267 if ((i + 1) < orderByFields.length) {
3268 if (orderByComparator.isAscending() ^ previous) {
3269 query.append(ORDER_BY_ASC_HAS_NEXT);
3270 }
3271 else {
3272 query.append(ORDER_BY_DESC_HAS_NEXT);
3273 }
3274 }
3275 else {
3276 if (orderByComparator.isAscending() ^ previous) {
3277 query.append(ORDER_BY_ASC);
3278 }
3279 else {
3280 query.append(ORDER_BY_DESC);
3281 }
3282 }
3283 }
3284 }
3285
3286 String sql = query.toString();
3287
3288 Query q = session.createQuery(sql);
3289
3290 q.setFirstResult(0);
3291 q.setMaxResults(2);
3292
3293 QueryPos qPos = QueryPos.getInstance(q);
3294
3295 qPos.add(userId1);
3296
3297 qPos.add(userId2);
3298
3299 if (orderByComparator != null) {
3300 Object[] values = orderByComparator.getOrderByConditionValues(socialRelation);
3301
3302 for (Object value : values) {
3303 qPos.add(value);
3304 }
3305 }
3306
3307 List<SocialRelation> list = q.list();
3308
3309 if (list.size() == 2) {
3310 return list.get(1);
3311 }
3312 else {
3313 return null;
3314 }
3315 }
3316
3317
3325 public List<SocialRelation> findByU1_T(long userId1, int type)
3326 throws SystemException {
3327 return findByU1_T(userId1, type, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
3328 null);
3329 }
3330
3331
3345 public List<SocialRelation> findByU1_T(long userId1, int type, int start,
3346 int end) throws SystemException {
3347 return findByU1_T(userId1, type, start, end, null);
3348 }
3349
3350
3365 public List<SocialRelation> findByU1_T(long userId1, int type, int start,
3366 int end, OrderByComparator orderByComparator) throws SystemException {
3367 FinderPath finderPath = null;
3368 Object[] finderArgs = null;
3369
3370 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3371 (orderByComparator == null)) {
3372 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U1_T;
3373 finderArgs = new Object[] { userId1, type };
3374 }
3375 else {
3376 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U1_T;
3377 finderArgs = new Object[] {
3378 userId1, type,
3379
3380 start, end, orderByComparator
3381 };
3382 }
3383
3384 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(finderPath,
3385 finderArgs, this);
3386
3387 if (list == null) {
3388 StringBundler query = null;
3389
3390 if (orderByComparator != null) {
3391 query = new StringBundler(4 +
3392 (orderByComparator.getOrderByFields().length * 3));
3393 }
3394 else {
3395 query = new StringBundler(3);
3396 }
3397
3398 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
3399
3400 query.append(_FINDER_COLUMN_U1_T_USERID1_2);
3401
3402 query.append(_FINDER_COLUMN_U1_T_TYPE_2);
3403
3404 if (orderByComparator != null) {
3405 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3406 orderByComparator);
3407 }
3408
3409 String sql = query.toString();
3410
3411 Session session = null;
3412
3413 try {
3414 session = openSession();
3415
3416 Query q = session.createQuery(sql);
3417
3418 QueryPos qPos = QueryPos.getInstance(q);
3419
3420 qPos.add(userId1);
3421
3422 qPos.add(type);
3423
3424 list = (List<SocialRelation>)QueryUtil.list(q, getDialect(),
3425 start, end);
3426 }
3427 catch (Exception e) {
3428 throw processException(e);
3429 }
3430 finally {
3431 if (list == null) {
3432 FinderCacheUtil.removeResult(finderPath, finderArgs);
3433 }
3434 else {
3435 cacheResult(list);
3436
3437 FinderCacheUtil.putResult(finderPath, finderArgs, list);
3438 }
3439
3440 closeSession(session);
3441 }
3442 }
3443
3444 return list;
3445 }
3446
3447
3461 public SocialRelation findByU1_T_First(long userId1, int type,
3462 OrderByComparator orderByComparator)
3463 throws NoSuchRelationException, SystemException {
3464 List<SocialRelation> list = findByU1_T(userId1, type, 0, 1,
3465 orderByComparator);
3466
3467 if (list.isEmpty()) {
3468 StringBundler msg = new StringBundler(6);
3469
3470 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3471
3472 msg.append("userId1=");
3473 msg.append(userId1);
3474
3475 msg.append(", type=");
3476 msg.append(type);
3477
3478 msg.append(StringPool.CLOSE_CURLY_BRACE);
3479
3480 throw new NoSuchRelationException(msg.toString());
3481 }
3482 else {
3483 return list.get(0);
3484 }
3485 }
3486
3487
3501 public SocialRelation findByU1_T_Last(long userId1, int type,
3502 OrderByComparator orderByComparator)
3503 throws NoSuchRelationException, SystemException {
3504 int count = countByU1_T(userId1, type);
3505
3506 List<SocialRelation> list = findByU1_T(userId1, type, count - 1, count,
3507 orderByComparator);
3508
3509 if (list.isEmpty()) {
3510 StringBundler msg = new StringBundler(6);
3511
3512 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3513
3514 msg.append("userId1=");
3515 msg.append(userId1);
3516
3517 msg.append(", type=");
3518 msg.append(type);
3519
3520 msg.append(StringPool.CLOSE_CURLY_BRACE);
3521
3522 throw new NoSuchRelationException(msg.toString());
3523 }
3524 else {
3525 return list.get(0);
3526 }
3527 }
3528
3529
3544 public SocialRelation[] findByU1_T_PrevAndNext(long relationId,
3545 long userId1, int type, OrderByComparator orderByComparator)
3546 throws NoSuchRelationException, SystemException {
3547 SocialRelation socialRelation = findByPrimaryKey(relationId);
3548
3549 Session session = null;
3550
3551 try {
3552 session = openSession();
3553
3554 SocialRelation[] array = new SocialRelationImpl[3];
3555
3556 array[0] = getByU1_T_PrevAndNext(session, socialRelation, userId1,
3557 type, orderByComparator, true);
3558
3559 array[1] = socialRelation;
3560
3561 array[2] = getByU1_T_PrevAndNext(session, socialRelation, userId1,
3562 type, orderByComparator, false);
3563
3564 return array;
3565 }
3566 catch (Exception e) {
3567 throw processException(e);
3568 }
3569 finally {
3570 closeSession(session);
3571 }
3572 }
3573
3574 protected SocialRelation getByU1_T_PrevAndNext(Session session,
3575 SocialRelation socialRelation, long userId1, int type,
3576 OrderByComparator orderByComparator, boolean previous) {
3577 StringBundler query = null;
3578
3579 if (orderByComparator != null) {
3580 query = new StringBundler(6 +
3581 (orderByComparator.getOrderByFields().length * 6));
3582 }
3583 else {
3584 query = new StringBundler(3);
3585 }
3586
3587 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
3588
3589 query.append(_FINDER_COLUMN_U1_T_USERID1_2);
3590
3591 query.append(_FINDER_COLUMN_U1_T_TYPE_2);
3592
3593 if (orderByComparator != null) {
3594 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3595
3596 if (orderByConditionFields.length > 0) {
3597 query.append(WHERE_AND);
3598 }
3599
3600 for (int i = 0; i < orderByConditionFields.length; i++) {
3601 query.append(_ORDER_BY_ENTITY_ALIAS);
3602 query.append(orderByConditionFields[i]);
3603
3604 if ((i + 1) < orderByConditionFields.length) {
3605 if (orderByComparator.isAscending() ^ previous) {
3606 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3607 }
3608 else {
3609 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3610 }
3611 }
3612 else {
3613 if (orderByComparator.isAscending() ^ previous) {
3614 query.append(WHERE_GREATER_THAN);
3615 }
3616 else {
3617 query.append(WHERE_LESSER_THAN);
3618 }
3619 }
3620 }
3621
3622 query.append(ORDER_BY_CLAUSE);
3623
3624 String[] orderByFields = orderByComparator.getOrderByFields();
3625
3626 for (int i = 0; i < orderByFields.length; i++) {
3627 query.append(_ORDER_BY_ENTITY_ALIAS);
3628 query.append(orderByFields[i]);
3629
3630 if ((i + 1) < orderByFields.length) {
3631 if (orderByComparator.isAscending() ^ previous) {
3632 query.append(ORDER_BY_ASC_HAS_NEXT);
3633 }
3634 else {
3635 query.append(ORDER_BY_DESC_HAS_NEXT);
3636 }
3637 }
3638 else {
3639 if (orderByComparator.isAscending() ^ previous) {
3640 query.append(ORDER_BY_ASC);
3641 }
3642 else {
3643 query.append(ORDER_BY_DESC);
3644 }
3645 }
3646 }
3647 }
3648
3649 String sql = query.toString();
3650
3651 Query q = session.createQuery(sql);
3652
3653 q.setFirstResult(0);
3654 q.setMaxResults(2);
3655
3656 QueryPos qPos = QueryPos.getInstance(q);
3657
3658 qPos.add(userId1);
3659
3660 qPos.add(type);
3661
3662 if (orderByComparator != null) {
3663 Object[] values = orderByComparator.getOrderByConditionValues(socialRelation);
3664
3665 for (Object value : values) {
3666 qPos.add(value);
3667 }
3668 }
3669
3670 List<SocialRelation> list = q.list();
3671
3672 if (list.size() == 2) {
3673 return list.get(1);
3674 }
3675 else {
3676 return null;
3677 }
3678 }
3679
3680
3688 public List<SocialRelation> findByU2_T(long userId2, int type)
3689 throws SystemException {
3690 return findByU2_T(userId2, type, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
3691 null);
3692 }
3693
3694
3708 public List<SocialRelation> findByU2_T(long userId2, int type, int start,
3709 int end) throws SystemException {
3710 return findByU2_T(userId2, type, start, end, null);
3711 }
3712
3713
3728 public List<SocialRelation> findByU2_T(long userId2, int type, int start,
3729 int end, OrderByComparator orderByComparator) throws SystemException {
3730 FinderPath finderPath = null;
3731 Object[] finderArgs = null;
3732
3733 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3734 (orderByComparator == null)) {
3735 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U2_T;
3736 finderArgs = new Object[] { userId2, type };
3737 }
3738 else {
3739 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U2_T;
3740 finderArgs = new Object[] {
3741 userId2, type,
3742
3743 start, end, orderByComparator
3744 };
3745 }
3746
3747 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(finderPath,
3748 finderArgs, this);
3749
3750 if (list == null) {
3751 StringBundler query = null;
3752
3753 if (orderByComparator != null) {
3754 query = new StringBundler(4 +
3755 (orderByComparator.getOrderByFields().length * 3));
3756 }
3757 else {
3758 query = new StringBundler(3);
3759 }
3760
3761 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
3762
3763 query.append(_FINDER_COLUMN_U2_T_USERID2_2);
3764
3765 query.append(_FINDER_COLUMN_U2_T_TYPE_2);
3766
3767 if (orderByComparator != null) {
3768 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3769 orderByComparator);
3770 }
3771
3772 String sql = query.toString();
3773
3774 Session session = null;
3775
3776 try {
3777 session = openSession();
3778
3779 Query q = session.createQuery(sql);
3780
3781 QueryPos qPos = QueryPos.getInstance(q);
3782
3783 qPos.add(userId2);
3784
3785 qPos.add(type);
3786
3787 list = (List<SocialRelation>)QueryUtil.list(q, getDialect(),
3788 start, end);
3789 }
3790 catch (Exception e) {
3791 throw processException(e);
3792 }
3793 finally {
3794 if (list == null) {
3795 FinderCacheUtil.removeResult(finderPath, finderArgs);
3796 }
3797 else {
3798 cacheResult(list);
3799
3800 FinderCacheUtil.putResult(finderPath, finderArgs, list);
3801 }
3802
3803 closeSession(session);
3804 }
3805 }
3806
3807 return list;
3808 }
3809
3810
3824 public SocialRelation findByU2_T_First(long userId2, int type,
3825 OrderByComparator orderByComparator)
3826 throws NoSuchRelationException, SystemException {
3827 List<SocialRelation> list = findByU2_T(userId2, type, 0, 1,
3828 orderByComparator);
3829
3830 if (list.isEmpty()) {
3831 StringBundler msg = new StringBundler(6);
3832
3833 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3834
3835 msg.append("userId2=");
3836 msg.append(userId2);
3837
3838 msg.append(", type=");
3839 msg.append(type);
3840
3841 msg.append(StringPool.CLOSE_CURLY_BRACE);
3842
3843 throw new NoSuchRelationException(msg.toString());
3844 }
3845 else {
3846 return list.get(0);
3847 }
3848 }
3849
3850
3864 public SocialRelation findByU2_T_Last(long userId2, int type,
3865 OrderByComparator orderByComparator)
3866 throws NoSuchRelationException, SystemException {
3867 int count = countByU2_T(userId2, type);
3868
3869 List<SocialRelation> list = findByU2_T(userId2, type, count - 1, count,
3870 orderByComparator);
3871
3872 if (list.isEmpty()) {
3873 StringBundler msg = new StringBundler(6);
3874
3875 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3876
3877 msg.append("userId2=");
3878 msg.append(userId2);
3879
3880 msg.append(", type=");
3881 msg.append(type);
3882
3883 msg.append(StringPool.CLOSE_CURLY_BRACE);
3884
3885 throw new NoSuchRelationException(msg.toString());
3886 }
3887 else {
3888 return list.get(0);
3889 }
3890 }
3891
3892
3907 public SocialRelation[] findByU2_T_PrevAndNext(long relationId,
3908 long userId2, int type, OrderByComparator orderByComparator)
3909 throws NoSuchRelationException, SystemException {
3910 SocialRelation socialRelation = findByPrimaryKey(relationId);
3911
3912 Session session = null;
3913
3914 try {
3915 session = openSession();
3916
3917 SocialRelation[] array = new SocialRelationImpl[3];
3918
3919 array[0] = getByU2_T_PrevAndNext(session, socialRelation, userId2,
3920 type, orderByComparator, true);
3921
3922 array[1] = socialRelation;
3923
3924 array[2] = getByU2_T_PrevAndNext(session, socialRelation, userId2,
3925 type, orderByComparator, false);
3926
3927 return array;
3928 }
3929 catch (Exception e) {
3930 throw processException(e);
3931 }
3932 finally {
3933 closeSession(session);
3934 }
3935 }
3936
3937 protected SocialRelation getByU2_T_PrevAndNext(Session session,
3938 SocialRelation socialRelation, long userId2, int type,
3939 OrderByComparator orderByComparator, boolean previous) {
3940 StringBundler query = null;
3941
3942 if (orderByComparator != null) {
3943 query = new StringBundler(6 +
3944 (orderByComparator.getOrderByFields().length * 6));
3945 }
3946 else {
3947 query = new StringBundler(3);
3948 }
3949
3950 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
3951
3952 query.append(_FINDER_COLUMN_U2_T_USERID2_2);
3953
3954 query.append(_FINDER_COLUMN_U2_T_TYPE_2);
3955
3956 if (orderByComparator != null) {
3957 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3958
3959 if (orderByConditionFields.length > 0) {
3960 query.append(WHERE_AND);
3961 }
3962
3963 for (int i = 0; i < orderByConditionFields.length; i++) {
3964 query.append(_ORDER_BY_ENTITY_ALIAS);
3965 query.append(orderByConditionFields[i]);
3966
3967 if ((i + 1) < orderByConditionFields.length) {
3968 if (orderByComparator.isAscending() ^ previous) {
3969 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3970 }
3971 else {
3972 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3973 }
3974 }
3975 else {
3976 if (orderByComparator.isAscending() ^ previous) {
3977 query.append(WHERE_GREATER_THAN);
3978 }
3979 else {
3980 query.append(WHERE_LESSER_THAN);
3981 }
3982 }
3983 }
3984
3985 query.append(ORDER_BY_CLAUSE);
3986
3987 String[] orderByFields = orderByComparator.getOrderByFields();
3988
3989 for (int i = 0; i < orderByFields.length; i++) {
3990 query.append(_ORDER_BY_ENTITY_ALIAS);
3991 query.append(orderByFields[i]);
3992
3993 if ((i + 1) < orderByFields.length) {
3994 if (orderByComparator.isAscending() ^ previous) {
3995 query.append(ORDER_BY_ASC_HAS_NEXT);
3996 }
3997 else {
3998 query.append(ORDER_BY_DESC_HAS_NEXT);
3999 }
4000 }
4001 else {
4002 if (orderByComparator.isAscending() ^ previous) {
4003 query.append(ORDER_BY_ASC);
4004 }
4005 else {
4006 query.append(ORDER_BY_DESC);
4007 }
4008 }
4009 }
4010 }
4011
4012 String sql = query.toString();
4013
4014 Query q = session.createQuery(sql);
4015
4016 q.setFirstResult(0);
4017 q.setMaxResults(2);
4018
4019 QueryPos qPos = QueryPos.getInstance(q);
4020
4021 qPos.add(userId2);
4022
4023 qPos.add(type);
4024
4025 if (orderByComparator != null) {
4026 Object[] values = orderByComparator.getOrderByConditionValues(socialRelation);
4027
4028 for (Object value : values) {
4029 qPos.add(value);
4030 }
4031 }
4032
4033 List<SocialRelation> list = q.list();
4034
4035 if (list.size() == 2) {
4036 return list.get(1);
4037 }
4038 else {
4039 return null;
4040 }
4041 }
4042
4043
4053 public SocialRelation findByU1_U2_T(long userId1, long userId2, int type)
4054 throws NoSuchRelationException, SystemException {
4055 SocialRelation socialRelation = fetchByU1_U2_T(userId1, userId2, type);
4056
4057 if (socialRelation == null) {
4058 StringBundler msg = new StringBundler(8);
4059
4060 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4061
4062 msg.append("userId1=");
4063 msg.append(userId1);
4064
4065 msg.append(", userId2=");
4066 msg.append(userId2);
4067
4068 msg.append(", type=");
4069 msg.append(type);
4070
4071 msg.append(StringPool.CLOSE_CURLY_BRACE);
4072
4073 if (_log.isWarnEnabled()) {
4074 _log.warn(msg.toString());
4075 }
4076
4077 throw new NoSuchRelationException(msg.toString());
4078 }
4079
4080 return socialRelation;
4081 }
4082
4083
4092 public SocialRelation fetchByU1_U2_T(long userId1, long userId2, int type)
4093 throws SystemException {
4094 return fetchByU1_U2_T(userId1, userId2, type, true);
4095 }
4096
4097
4107 public SocialRelation fetchByU1_U2_T(long userId1, long userId2, int type,
4108 boolean retrieveFromCache) throws SystemException {
4109 Object[] finderArgs = new Object[] { userId1, userId2, type };
4110
4111 Object result = null;
4112
4113 if (retrieveFromCache) {
4114 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_U1_U2_T,
4115 finderArgs, this);
4116 }
4117
4118 if (result == null) {
4119 StringBundler query = new StringBundler(4);
4120
4121 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
4122
4123 query.append(_FINDER_COLUMN_U1_U2_T_USERID1_2);
4124
4125 query.append(_FINDER_COLUMN_U1_U2_T_USERID2_2);
4126
4127 query.append(_FINDER_COLUMN_U1_U2_T_TYPE_2);
4128
4129 String sql = query.toString();
4130
4131 Session session = null;
4132
4133 try {
4134 session = openSession();
4135
4136 Query q = session.createQuery(sql);
4137
4138 QueryPos qPos = QueryPos.getInstance(q);
4139
4140 qPos.add(userId1);
4141
4142 qPos.add(userId2);
4143
4144 qPos.add(type);
4145
4146 List<SocialRelation> list = q.list();
4147
4148 result = list;
4149
4150 SocialRelation socialRelation = null;
4151
4152 if (list.isEmpty()) {
4153 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U1_U2_T,
4154 finderArgs, list);
4155 }
4156 else {
4157 socialRelation = list.get(0);
4158
4159 cacheResult(socialRelation);
4160
4161 if ((socialRelation.getUserId1() != userId1) ||
4162 (socialRelation.getUserId2() != userId2) ||
4163 (socialRelation.getType() != type)) {
4164 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U1_U2_T,
4165 finderArgs, socialRelation);
4166 }
4167 }
4168
4169 return socialRelation;
4170 }
4171 catch (Exception e) {
4172 throw processException(e);
4173 }
4174 finally {
4175 if (result == null) {
4176 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U1_U2_T,
4177 finderArgs);
4178 }
4179
4180 closeSession(session);
4181 }
4182 }
4183 else {
4184 if (result instanceof List<?>) {
4185 return null;
4186 }
4187 else {
4188 return (SocialRelation)result;
4189 }
4190 }
4191 }
4192
4193
4199 public List<SocialRelation> findAll() throws SystemException {
4200 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
4201 }
4202
4203
4215 public List<SocialRelation> findAll(int start, int end)
4216 throws SystemException {
4217 return findAll(start, end, null);
4218 }
4219
4220
4233 public List<SocialRelation> findAll(int start, int end,
4234 OrderByComparator orderByComparator) throws SystemException {
4235 FinderPath finderPath = null;
4236 Object[] finderArgs = new Object[] { start, end, orderByComparator };
4237
4238 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4239 (orderByComparator == null)) {
4240 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
4241 finderArgs = FINDER_ARGS_EMPTY;
4242 }
4243 else {
4244 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
4245 finderArgs = new Object[] { start, end, orderByComparator };
4246 }
4247
4248 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(finderPath,
4249 finderArgs, this);
4250
4251 if (list == null) {
4252 StringBundler query = null;
4253 String sql = null;
4254
4255 if (orderByComparator != null) {
4256 query = new StringBundler(2 +
4257 (orderByComparator.getOrderByFields().length * 3));
4258
4259 query.append(_SQL_SELECT_SOCIALRELATION);
4260
4261 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4262 orderByComparator);
4263
4264 sql = query.toString();
4265 }
4266 else {
4267 sql = _SQL_SELECT_SOCIALRELATION;
4268 }
4269
4270 Session session = null;
4271
4272 try {
4273 session = openSession();
4274
4275 Query q = session.createQuery(sql);
4276
4277 if (orderByComparator == null) {
4278 list = (List<SocialRelation>)QueryUtil.list(q,
4279 getDialect(), start, end, false);
4280
4281 Collections.sort(list);
4282 }
4283 else {
4284 list = (List<SocialRelation>)QueryUtil.list(q,
4285 getDialect(), start, end);
4286 }
4287 }
4288 catch (Exception e) {
4289 throw processException(e);
4290 }
4291 finally {
4292 if (list == null) {
4293 FinderCacheUtil.removeResult(finderPath, finderArgs);
4294 }
4295 else {
4296 cacheResult(list);
4297
4298 FinderCacheUtil.putResult(finderPath, finderArgs, list);
4299 }
4300
4301 closeSession(session);
4302 }
4303 }
4304
4305 return list;
4306 }
4307
4308
4314 public void removeByUuid(String uuid) throws SystemException {
4315 for (SocialRelation socialRelation : findByUuid(uuid)) {
4316 socialRelationPersistence.remove(socialRelation);
4317 }
4318 }
4319
4320
4326 public void removeByCompanyId(long companyId) throws SystemException {
4327 for (SocialRelation socialRelation : findByCompanyId(companyId)) {
4328 socialRelationPersistence.remove(socialRelation);
4329 }
4330 }
4331
4332
4338 public void removeByUserId1(long userId1) throws SystemException {
4339 for (SocialRelation socialRelation : findByUserId1(userId1)) {
4340 socialRelationPersistence.remove(socialRelation);
4341 }
4342 }
4343
4344
4350 public void removeByUserId2(long userId2) throws SystemException {
4351 for (SocialRelation socialRelation : findByUserId2(userId2)) {
4352 socialRelationPersistence.remove(socialRelation);
4353 }
4354 }
4355
4356
4362 public void removeByType(int type) throws SystemException {
4363 for (SocialRelation socialRelation : findByType(type)) {
4364 socialRelationPersistence.remove(socialRelation);
4365 }
4366 }
4367
4368
4375 public void removeByC_T(long companyId, int type) throws SystemException {
4376 for (SocialRelation socialRelation : findByC_T(companyId, type)) {
4377 socialRelationPersistence.remove(socialRelation);
4378 }
4379 }
4380
4381
4388 public void removeByU1_U2(long userId1, long userId2)
4389 throws SystemException {
4390 for (SocialRelation socialRelation : findByU1_U2(userId1, userId2)) {
4391 socialRelationPersistence.remove(socialRelation);
4392 }
4393 }
4394
4395
4402 public void removeByU1_T(long userId1, int type) throws SystemException {
4403 for (SocialRelation socialRelation : findByU1_T(userId1, type)) {
4404 socialRelationPersistence.remove(socialRelation);
4405 }
4406 }
4407
4408
4415 public void removeByU2_T(long userId2, int type) throws SystemException {
4416 for (SocialRelation socialRelation : findByU2_T(userId2, type)) {
4417 socialRelationPersistence.remove(socialRelation);
4418 }
4419 }
4420
4421
4429 public void removeByU1_U2_T(long userId1, long userId2, int type)
4430 throws NoSuchRelationException, SystemException {
4431 SocialRelation socialRelation = findByU1_U2_T(userId1, userId2, type);
4432
4433 socialRelationPersistence.remove(socialRelation);
4434 }
4435
4436
4441 public void removeAll() throws SystemException {
4442 for (SocialRelation socialRelation : findAll()) {
4443 socialRelationPersistence.remove(socialRelation);
4444 }
4445 }
4446
4447
4454 public int countByUuid(String uuid) throws SystemException {
4455 Object[] finderArgs = new Object[] { uuid };
4456
4457 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
4458 finderArgs, this);
4459
4460 if (count == null) {
4461 StringBundler query = new StringBundler(2);
4462
4463 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
4464
4465 if (uuid == null) {
4466 query.append(_FINDER_COLUMN_UUID_UUID_1);
4467 }
4468 else {
4469 if (uuid.equals(StringPool.BLANK)) {
4470 query.append(_FINDER_COLUMN_UUID_UUID_3);
4471 }
4472 else {
4473 query.append(_FINDER_COLUMN_UUID_UUID_2);
4474 }
4475 }
4476
4477 String sql = query.toString();
4478
4479 Session session = null;
4480
4481 try {
4482 session = openSession();
4483
4484 Query q = session.createQuery(sql);
4485
4486 QueryPos qPos = QueryPos.getInstance(q);
4487
4488 if (uuid != null) {
4489 qPos.add(uuid);
4490 }
4491
4492 count = (Long)q.uniqueResult();
4493 }
4494 catch (Exception e) {
4495 throw processException(e);
4496 }
4497 finally {
4498 if (count == null) {
4499 count = Long.valueOf(0);
4500 }
4501
4502 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
4503 finderArgs, count);
4504
4505 closeSession(session);
4506 }
4507 }
4508
4509 return count.intValue();
4510 }
4511
4512
4519 public int countByCompanyId(long companyId) throws SystemException {
4520 Object[] finderArgs = new Object[] { companyId };
4521
4522 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
4523 finderArgs, this);
4524
4525 if (count == null) {
4526 StringBundler query = new StringBundler(2);
4527
4528 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
4529
4530 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
4531
4532 String sql = query.toString();
4533
4534 Session session = null;
4535
4536 try {
4537 session = openSession();
4538
4539 Query q = session.createQuery(sql);
4540
4541 QueryPos qPos = QueryPos.getInstance(q);
4542
4543 qPos.add(companyId);
4544
4545 count = (Long)q.uniqueResult();
4546 }
4547 catch (Exception e) {
4548 throw processException(e);
4549 }
4550 finally {
4551 if (count == null) {
4552 count = Long.valueOf(0);
4553 }
4554
4555 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
4556 finderArgs, count);
4557
4558 closeSession(session);
4559 }
4560 }
4561
4562 return count.intValue();
4563 }
4564
4565
4572 public int countByUserId1(long userId1) throws SystemException {
4573 Object[] finderArgs = new Object[] { userId1 };
4574
4575 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID1,
4576 finderArgs, this);
4577
4578 if (count == null) {
4579 StringBundler query = new StringBundler(2);
4580
4581 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
4582
4583 query.append(_FINDER_COLUMN_USERID1_USERID1_2);
4584
4585 String sql = query.toString();
4586
4587 Session session = null;
4588
4589 try {
4590 session = openSession();
4591
4592 Query q = session.createQuery(sql);
4593
4594 QueryPos qPos = QueryPos.getInstance(q);
4595
4596 qPos.add(userId1);
4597
4598 count = (Long)q.uniqueResult();
4599 }
4600 catch (Exception e) {
4601 throw processException(e);
4602 }
4603 finally {
4604 if (count == null) {
4605 count = Long.valueOf(0);
4606 }
4607
4608 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID1,
4609 finderArgs, count);
4610
4611 closeSession(session);
4612 }
4613 }
4614
4615 return count.intValue();
4616 }
4617
4618
4625 public int countByUserId2(long userId2) throws SystemException {
4626 Object[] finderArgs = new Object[] { userId2 };
4627
4628 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID2,
4629 finderArgs, this);
4630
4631 if (count == null) {
4632 StringBundler query = new StringBundler(2);
4633
4634 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
4635
4636 query.append(_FINDER_COLUMN_USERID2_USERID2_2);
4637
4638 String sql = query.toString();
4639
4640 Session session = null;
4641
4642 try {
4643 session = openSession();
4644
4645 Query q = session.createQuery(sql);
4646
4647 QueryPos qPos = QueryPos.getInstance(q);
4648
4649 qPos.add(userId2);
4650
4651 count = (Long)q.uniqueResult();
4652 }
4653 catch (Exception e) {
4654 throw processException(e);
4655 }
4656 finally {
4657 if (count == null) {
4658 count = Long.valueOf(0);
4659 }
4660
4661 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID2,
4662 finderArgs, count);
4663
4664 closeSession(session);
4665 }
4666 }
4667
4668 return count.intValue();
4669 }
4670
4671
4678 public int countByType(int type) throws SystemException {
4679 Object[] finderArgs = new Object[] { type };
4680
4681 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_TYPE,
4682 finderArgs, this);
4683
4684 if (count == null) {
4685 StringBundler query = new StringBundler(2);
4686
4687 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
4688
4689 query.append(_FINDER_COLUMN_TYPE_TYPE_2);
4690
4691 String sql = query.toString();
4692
4693 Session session = null;
4694
4695 try {
4696 session = openSession();
4697
4698 Query q = session.createQuery(sql);
4699
4700 QueryPos qPos = QueryPos.getInstance(q);
4701
4702 qPos.add(type);
4703
4704 count = (Long)q.uniqueResult();
4705 }
4706 catch (Exception e) {
4707 throw processException(e);
4708 }
4709 finally {
4710 if (count == null) {
4711 count = Long.valueOf(0);
4712 }
4713
4714 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_TYPE,
4715 finderArgs, count);
4716
4717 closeSession(session);
4718 }
4719 }
4720
4721 return count.intValue();
4722 }
4723
4724
4732 public int countByC_T(long companyId, int type) throws SystemException {
4733 Object[] finderArgs = new Object[] { companyId, type };
4734
4735 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_T,
4736 finderArgs, this);
4737
4738 if (count == null) {
4739 StringBundler query = new StringBundler(3);
4740
4741 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
4742
4743 query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
4744
4745 query.append(_FINDER_COLUMN_C_T_TYPE_2);
4746
4747 String sql = query.toString();
4748
4749 Session session = null;
4750
4751 try {
4752 session = openSession();
4753
4754 Query q = session.createQuery(sql);
4755
4756 QueryPos qPos = QueryPos.getInstance(q);
4757
4758 qPos.add(companyId);
4759
4760 qPos.add(type);
4761
4762 count = (Long)q.uniqueResult();
4763 }
4764 catch (Exception e) {
4765 throw processException(e);
4766 }
4767 finally {
4768 if (count == null) {
4769 count = Long.valueOf(0);
4770 }
4771
4772 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_T, finderArgs,
4773 count);
4774
4775 closeSession(session);
4776 }
4777 }
4778
4779 return count.intValue();
4780 }
4781
4782
4790 public int countByU1_U2(long userId1, long userId2)
4791 throws SystemException {
4792 Object[] finderArgs = new Object[] { userId1, userId2 };
4793
4794 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U1_U2,
4795 finderArgs, this);
4796
4797 if (count == null) {
4798 StringBundler query = new StringBundler(3);
4799
4800 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
4801
4802 query.append(_FINDER_COLUMN_U1_U2_USERID1_2);
4803
4804 query.append(_FINDER_COLUMN_U1_U2_USERID2_2);
4805
4806 String sql = query.toString();
4807
4808 Session session = null;
4809
4810 try {
4811 session = openSession();
4812
4813 Query q = session.createQuery(sql);
4814
4815 QueryPos qPos = QueryPos.getInstance(q);
4816
4817 qPos.add(userId1);
4818
4819 qPos.add(userId2);
4820
4821 count = (Long)q.uniqueResult();
4822 }
4823 catch (Exception e) {
4824 throw processException(e);
4825 }
4826 finally {
4827 if (count == null) {
4828 count = Long.valueOf(0);
4829 }
4830
4831 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U1_U2,
4832 finderArgs, count);
4833
4834 closeSession(session);
4835 }
4836 }
4837
4838 return count.intValue();
4839 }
4840
4841
4849 public int countByU1_T(long userId1, int type) throws SystemException {
4850 Object[] finderArgs = new Object[] { userId1, type };
4851
4852 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U1_T,
4853 finderArgs, this);
4854
4855 if (count == null) {
4856 StringBundler query = new StringBundler(3);
4857
4858 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
4859
4860 query.append(_FINDER_COLUMN_U1_T_USERID1_2);
4861
4862 query.append(_FINDER_COLUMN_U1_T_TYPE_2);
4863
4864 String sql = query.toString();
4865
4866 Session session = null;
4867
4868 try {
4869 session = openSession();
4870
4871 Query q = session.createQuery(sql);
4872
4873 QueryPos qPos = QueryPos.getInstance(q);
4874
4875 qPos.add(userId1);
4876
4877 qPos.add(type);
4878
4879 count = (Long)q.uniqueResult();
4880 }
4881 catch (Exception e) {
4882 throw processException(e);
4883 }
4884 finally {
4885 if (count == null) {
4886 count = Long.valueOf(0);
4887 }
4888
4889 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U1_T,
4890 finderArgs, count);
4891
4892 closeSession(session);
4893 }
4894 }
4895
4896 return count.intValue();
4897 }
4898
4899
4907 public int countByU2_T(long userId2, int type) throws SystemException {
4908 Object[] finderArgs = new Object[] { userId2, type };
4909
4910 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U2_T,
4911 finderArgs, this);
4912
4913 if (count == null) {
4914 StringBundler query = new StringBundler(3);
4915
4916 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
4917
4918 query.append(_FINDER_COLUMN_U2_T_USERID2_2);
4919
4920 query.append(_FINDER_COLUMN_U2_T_TYPE_2);
4921
4922 String sql = query.toString();
4923
4924 Session session = null;
4925
4926 try {
4927 session = openSession();
4928
4929 Query q = session.createQuery(sql);
4930
4931 QueryPos qPos = QueryPos.getInstance(q);
4932
4933 qPos.add(userId2);
4934
4935 qPos.add(type);
4936
4937 count = (Long)q.uniqueResult();
4938 }
4939 catch (Exception e) {
4940 throw processException(e);
4941 }
4942 finally {
4943 if (count == null) {
4944 count = Long.valueOf(0);
4945 }
4946
4947 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U2_T,
4948 finderArgs, count);
4949
4950 closeSession(session);
4951 }
4952 }
4953
4954 return count.intValue();
4955 }
4956
4957
4966 public int countByU1_U2_T(long userId1, long userId2, int type)
4967 throws SystemException {
4968 Object[] finderArgs = new Object[] { userId1, userId2, type };
4969
4970 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U1_U2_T,
4971 finderArgs, this);
4972
4973 if (count == null) {
4974 StringBundler query = new StringBundler(4);
4975
4976 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
4977
4978 query.append(_FINDER_COLUMN_U1_U2_T_USERID1_2);
4979
4980 query.append(_FINDER_COLUMN_U1_U2_T_USERID2_2);
4981
4982 query.append(_FINDER_COLUMN_U1_U2_T_TYPE_2);
4983
4984 String sql = query.toString();
4985
4986 Session session = null;
4987
4988 try {
4989 session = openSession();
4990
4991 Query q = session.createQuery(sql);
4992
4993 QueryPos qPos = QueryPos.getInstance(q);
4994
4995 qPos.add(userId1);
4996
4997 qPos.add(userId2);
4998
4999 qPos.add(type);
5000
5001 count = (Long)q.uniqueResult();
5002 }
5003 catch (Exception e) {
5004 throw processException(e);
5005 }
5006 finally {
5007 if (count == null) {
5008 count = Long.valueOf(0);
5009 }
5010
5011 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U1_U2_T,
5012 finderArgs, count);
5013
5014 closeSession(session);
5015 }
5016 }
5017
5018 return count.intValue();
5019 }
5020
5021
5027 public int countAll() throws SystemException {
5028 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
5029 FINDER_ARGS_EMPTY, this);
5030
5031 if (count == null) {
5032 Session session = null;
5033
5034 try {
5035 session = openSession();
5036
5037 Query q = session.createQuery(_SQL_COUNT_SOCIALRELATION);
5038
5039 count = (Long)q.uniqueResult();
5040 }
5041 catch (Exception e) {
5042 throw processException(e);
5043 }
5044 finally {
5045 if (count == null) {
5046 count = Long.valueOf(0);
5047 }
5048
5049 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
5050 FINDER_ARGS_EMPTY, count);
5051
5052 closeSession(session);
5053 }
5054 }
5055
5056 return count.intValue();
5057 }
5058
5059
5062 public void afterPropertiesSet() {
5063 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
5064 com.liferay.portal.util.PropsUtil.get(
5065 "value.object.listener.com.liferay.portlet.social.model.SocialRelation")));
5066
5067 if (listenerClassNames.length > 0) {
5068 try {
5069 List<ModelListener<SocialRelation>> listenersList = new ArrayList<ModelListener<SocialRelation>>();
5070
5071 for (String listenerClassName : listenerClassNames) {
5072 listenersList.add((ModelListener<SocialRelation>)InstanceFactory.newInstance(
5073 listenerClassName));
5074 }
5075
5076 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
5077 }
5078 catch (Exception e) {
5079 _log.error(e);
5080 }
5081 }
5082 }
5083
5084 public void destroy() {
5085 EntityCacheUtil.removeCache(SocialRelationImpl.class.getName());
5086 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
5087 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
5088 }
5089
5090 @BeanReference(type = SocialActivityPersistence.class)
5091 protected SocialActivityPersistence socialActivityPersistence;
5092 @BeanReference(type = SocialActivityAchievementPersistence.class)
5093 protected SocialActivityAchievementPersistence socialActivityAchievementPersistence;
5094 @BeanReference(type = SocialActivityCounterPersistence.class)
5095 protected SocialActivityCounterPersistence socialActivityCounterPersistence;
5096 @BeanReference(type = SocialActivityLimitPersistence.class)
5097 protected SocialActivityLimitPersistence socialActivityLimitPersistence;
5098 @BeanReference(type = SocialActivitySettingPersistence.class)
5099 protected SocialActivitySettingPersistence socialActivitySettingPersistence;
5100 @BeanReference(type = SocialRelationPersistence.class)
5101 protected SocialRelationPersistence socialRelationPersistence;
5102 @BeanReference(type = SocialRequestPersistence.class)
5103 protected SocialRequestPersistence socialRequestPersistence;
5104 @BeanReference(type = ResourcePersistence.class)
5105 protected ResourcePersistence resourcePersistence;
5106 @BeanReference(type = UserPersistence.class)
5107 protected UserPersistence userPersistence;
5108 private static final String _SQL_SELECT_SOCIALRELATION = "SELECT socialRelation FROM SocialRelation socialRelation";
5109 private static final String _SQL_SELECT_SOCIALRELATION_WHERE = "SELECT socialRelation FROM SocialRelation socialRelation WHERE ";
5110 private static final String _SQL_COUNT_SOCIALRELATION = "SELECT COUNT(socialRelation) FROM SocialRelation socialRelation";
5111 private static final String _SQL_COUNT_SOCIALRELATION_WHERE = "SELECT COUNT(socialRelation) FROM SocialRelation socialRelation WHERE ";
5112 private static final String _FINDER_COLUMN_UUID_UUID_1 = "socialRelation.uuid IS NULL";
5113 private static final String _FINDER_COLUMN_UUID_UUID_2 = "socialRelation.uuid = ?";
5114 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(socialRelation.uuid IS NULL OR socialRelation.uuid = ?)";
5115 private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "socialRelation.companyId = ?";
5116 private static final String _FINDER_COLUMN_USERID1_USERID1_2 = "socialRelation.userId1 = ?";
5117 private static final String _FINDER_COLUMN_USERID2_USERID2_2 = "socialRelation.userId2 = ?";
5118 private static final String _FINDER_COLUMN_TYPE_TYPE_2 = "socialRelation.type = ?";
5119 private static final String _FINDER_COLUMN_C_T_COMPANYID_2 = "socialRelation.companyId = ? AND ";
5120 private static final String _FINDER_COLUMN_C_T_TYPE_2 = "socialRelation.type = ?";
5121 private static final String _FINDER_COLUMN_U1_U2_USERID1_2 = "socialRelation.userId1 = ? AND ";
5122 private static final String _FINDER_COLUMN_U1_U2_USERID2_2 = "socialRelation.userId2 = ?";
5123 private static final String _FINDER_COLUMN_U1_T_USERID1_2 = "socialRelation.userId1 = ? AND ";
5124 private static final String _FINDER_COLUMN_U1_T_TYPE_2 = "socialRelation.type = ?";
5125 private static final String _FINDER_COLUMN_U2_T_USERID2_2 = "socialRelation.userId2 = ? AND ";
5126 private static final String _FINDER_COLUMN_U2_T_TYPE_2 = "socialRelation.type = ?";
5127 private static final String _FINDER_COLUMN_U1_U2_T_USERID1_2 = "socialRelation.userId1 = ? AND ";
5128 private static final String _FINDER_COLUMN_U1_U2_T_USERID2_2 = "socialRelation.userId2 = ? AND ";
5129 private static final String _FINDER_COLUMN_U1_U2_T_TYPE_2 = "socialRelation.type = ?";
5130 private static final String _ORDER_BY_ENTITY_ALIAS = "socialRelation.";
5131 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No SocialRelation exists with the primary key ";
5132 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No SocialRelation exists with the key {";
5133 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
5134 private static Log _log = LogFactoryUtil.getLog(SocialRelationPersistenceImpl.class);
5135 private static SocialRelation _nullSocialRelation = new SocialRelationImpl() {
5136 @Override
5137 public Object clone() {
5138 return this;
5139 }
5140
5141 @Override
5142 public CacheModel<SocialRelation> toCacheModel() {
5143 return _nullSocialRelationCacheModel;
5144 }
5145 };
5146
5147 private static CacheModel<SocialRelation> _nullSocialRelationCacheModel = new CacheModel<SocialRelation>() {
5148 public SocialRelation toEntityModel() {
5149 return _nullSocialRelation;
5150 }
5151 };
5152 }