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, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
289 "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,
293 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "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 clearUniqueFindersCache(socialRelation);
372 }
373
374 @Override
375 public void clearCache(List<SocialRelation> socialRelations) {
376 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
377 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
378
379 for (SocialRelation socialRelation : socialRelations) {
380 EntityCacheUtil.removeResult(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
381 SocialRelationImpl.class, socialRelation.getPrimaryKey());
382
383 clearUniqueFindersCache(socialRelation);
384 }
385 }
386
387 protected void cacheUniqueFindersCache(SocialRelation socialRelation) {
388 if (socialRelation.isNew()) {
389 Object[] args = new Object[] {
390 Long.valueOf(socialRelation.getUserId1()),
391 Long.valueOf(socialRelation.getUserId2()),
392 Integer.valueOf(socialRelation.getType())
393 };
394
395 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U1_U2_T, args,
396 Long.valueOf(1));
397 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U1_U2_T, args,
398 socialRelation);
399 }
400 else {
401 SocialRelationModelImpl socialRelationModelImpl = (SocialRelationModelImpl)socialRelation;
402
403 if ((socialRelationModelImpl.getColumnBitmask() &
404 FINDER_PATH_FETCH_BY_U1_U2_T.getColumnBitmask()) != 0) {
405 Object[] args = new Object[] {
406 Long.valueOf(socialRelation.getUserId1()),
407 Long.valueOf(socialRelation.getUserId2()),
408 Integer.valueOf(socialRelation.getType())
409 };
410
411 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U1_U2_T, args,
412 Long.valueOf(1));
413 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U1_U2_T, args,
414 socialRelation);
415 }
416 }
417 }
418
419 protected void clearUniqueFindersCache(SocialRelation socialRelation) {
420 SocialRelationModelImpl socialRelationModelImpl = (SocialRelationModelImpl)socialRelation;
421
422 Object[] args = new Object[] {
423 Long.valueOf(socialRelation.getUserId1()),
424 Long.valueOf(socialRelation.getUserId2()),
425 Integer.valueOf(socialRelation.getType())
426 };
427
428 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U1_U2_T, args);
429 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U1_U2_T, args);
430
431 if ((socialRelationModelImpl.getColumnBitmask() &
432 FINDER_PATH_FETCH_BY_U1_U2_T.getColumnBitmask()) != 0) {
433 args = new Object[] {
434 Long.valueOf(socialRelationModelImpl.getOriginalUserId1()),
435 Long.valueOf(socialRelationModelImpl.getOriginalUserId2()),
436 Integer.valueOf(socialRelationModelImpl.getOriginalType())
437 };
438
439 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U1_U2_T, args);
440 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U1_U2_T, args);
441 }
442 }
443
444
450 public SocialRelation create(long relationId) {
451 SocialRelation socialRelation = new SocialRelationImpl();
452
453 socialRelation.setNew(true);
454 socialRelation.setPrimaryKey(relationId);
455
456 String uuid = PortalUUIDUtil.generate();
457
458 socialRelation.setUuid(uuid);
459
460 return socialRelation;
461 }
462
463
471 public SocialRelation remove(long relationId)
472 throws NoSuchRelationException, SystemException {
473 return remove(Long.valueOf(relationId));
474 }
475
476
484 @Override
485 public SocialRelation remove(Serializable primaryKey)
486 throws NoSuchRelationException, SystemException {
487 Session session = null;
488
489 try {
490 session = openSession();
491
492 SocialRelation socialRelation = (SocialRelation)session.get(SocialRelationImpl.class,
493 primaryKey);
494
495 if (socialRelation == null) {
496 if (_log.isWarnEnabled()) {
497 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
498 }
499
500 throw new NoSuchRelationException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
501 primaryKey);
502 }
503
504 return remove(socialRelation);
505 }
506 catch (NoSuchRelationException nsee) {
507 throw nsee;
508 }
509 catch (Exception e) {
510 throw processException(e);
511 }
512 finally {
513 closeSession(session);
514 }
515 }
516
517 @Override
518 protected SocialRelation removeImpl(SocialRelation socialRelation)
519 throws SystemException {
520 socialRelation = toUnwrappedModel(socialRelation);
521
522 Session session = null;
523
524 try {
525 session = openSession();
526
527 BatchSessionUtil.delete(session, socialRelation);
528 }
529 catch (Exception e) {
530 throw processException(e);
531 }
532 finally {
533 closeSession(session);
534 }
535
536 clearCache(socialRelation);
537
538 return socialRelation;
539 }
540
541 @Override
542 public SocialRelation updateImpl(
543 com.liferay.portlet.social.model.SocialRelation socialRelation,
544 boolean merge) throws SystemException {
545 socialRelation = toUnwrappedModel(socialRelation);
546
547 boolean isNew = socialRelation.isNew();
548
549 SocialRelationModelImpl socialRelationModelImpl = (SocialRelationModelImpl)socialRelation;
550
551 if (Validator.isNull(socialRelation.getUuid())) {
552 String uuid = PortalUUIDUtil.generate();
553
554 socialRelation.setUuid(uuid);
555 }
556
557 Session session = null;
558
559 try {
560 session = openSession();
561
562 BatchSessionUtil.update(session, socialRelation, merge);
563
564 socialRelation.setNew(false);
565 }
566 catch (Exception e) {
567 throw processException(e);
568 }
569 finally {
570 closeSession(session);
571 }
572
573 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
574
575 if (isNew || !SocialRelationModelImpl.COLUMN_BITMASK_ENABLED) {
576 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
577 }
578
579 else {
580 if ((socialRelationModelImpl.getColumnBitmask() &
581 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
582 Object[] args = new Object[] {
583 socialRelationModelImpl.getOriginalUuid()
584 };
585
586 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
587 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
588 args);
589
590 args = new Object[] { socialRelationModelImpl.getUuid() };
591
592 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
593 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
594 args);
595 }
596
597 if ((socialRelationModelImpl.getColumnBitmask() &
598 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
599 Object[] args = new Object[] {
600 Long.valueOf(socialRelationModelImpl.getOriginalCompanyId())
601 };
602
603 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
604 args);
605 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
606 args);
607
608 args = new Object[] {
609 Long.valueOf(socialRelationModelImpl.getCompanyId())
610 };
611
612 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
613 args);
614 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
615 args);
616 }
617
618 if ((socialRelationModelImpl.getColumnBitmask() &
619 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID1.getColumnBitmask()) != 0) {
620 Object[] args = new Object[] {
621 Long.valueOf(socialRelationModelImpl.getOriginalUserId1())
622 };
623
624 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID1, args);
625 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID1,
626 args);
627
628 args = new Object[] {
629 Long.valueOf(socialRelationModelImpl.getUserId1())
630 };
631
632 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID1, args);
633 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID1,
634 args);
635 }
636
637 if ((socialRelationModelImpl.getColumnBitmask() &
638 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID2.getColumnBitmask()) != 0) {
639 Object[] args = new Object[] {
640 Long.valueOf(socialRelationModelImpl.getOriginalUserId2())
641 };
642
643 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID2, args);
644 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID2,
645 args);
646
647 args = new Object[] {
648 Long.valueOf(socialRelationModelImpl.getUserId2())
649 };
650
651 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID2, args);
652 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID2,
653 args);
654 }
655
656 if ((socialRelationModelImpl.getColumnBitmask() &
657 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE.getColumnBitmask()) != 0) {
658 Object[] args = new Object[] {
659 Integer.valueOf(socialRelationModelImpl.getOriginalType())
660 };
661
662 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TYPE, args);
663 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE,
664 args);
665
666 args = new Object[] {
667 Integer.valueOf(socialRelationModelImpl.getType())
668 };
669
670 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TYPE, args);
671 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE,
672 args);
673 }
674
675 if ((socialRelationModelImpl.getColumnBitmask() &
676 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_T.getColumnBitmask()) != 0) {
677 Object[] args = new Object[] {
678 Long.valueOf(socialRelationModelImpl.getOriginalCompanyId()),
679 Integer.valueOf(socialRelationModelImpl.getOriginalType())
680 };
681
682 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_T, args);
683 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_T,
684 args);
685
686 args = new Object[] {
687 Long.valueOf(socialRelationModelImpl.getCompanyId()),
688 Integer.valueOf(socialRelationModelImpl.getType())
689 };
690
691 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_T, args);
692 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_T,
693 args);
694 }
695
696 if ((socialRelationModelImpl.getColumnBitmask() &
697 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U1_U2.getColumnBitmask()) != 0) {
698 Object[] args = new Object[] {
699 Long.valueOf(socialRelationModelImpl.getOriginalUserId1()),
700 Long.valueOf(socialRelationModelImpl.getOriginalUserId2())
701 };
702
703 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U1_U2, args);
704 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U1_U2,
705 args);
706
707 args = new Object[] {
708 Long.valueOf(socialRelationModelImpl.getUserId1()),
709 Long.valueOf(socialRelationModelImpl.getUserId2())
710 };
711
712 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U1_U2, args);
713 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U1_U2,
714 args);
715 }
716
717 if ((socialRelationModelImpl.getColumnBitmask() &
718 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U1_T.getColumnBitmask()) != 0) {
719 Object[] args = new Object[] {
720 Long.valueOf(socialRelationModelImpl.getOriginalUserId1()),
721 Integer.valueOf(socialRelationModelImpl.getOriginalType())
722 };
723
724 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U1_T, args);
725 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U1_T,
726 args);
727
728 args = new Object[] {
729 Long.valueOf(socialRelationModelImpl.getUserId1()),
730 Integer.valueOf(socialRelationModelImpl.getType())
731 };
732
733 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U1_T, args);
734 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U1_T,
735 args);
736 }
737
738 if ((socialRelationModelImpl.getColumnBitmask() &
739 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U2_T.getColumnBitmask()) != 0) {
740 Object[] args = new Object[] {
741 Long.valueOf(socialRelationModelImpl.getOriginalUserId2()),
742 Integer.valueOf(socialRelationModelImpl.getOriginalType())
743 };
744
745 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U2_T, args);
746 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U2_T,
747 args);
748
749 args = new Object[] {
750 Long.valueOf(socialRelationModelImpl.getUserId2()),
751 Integer.valueOf(socialRelationModelImpl.getType())
752 };
753
754 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U2_T, args);
755 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U2_T,
756 args);
757 }
758 }
759
760 EntityCacheUtil.putResult(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
761 SocialRelationImpl.class, socialRelation.getPrimaryKey(),
762 socialRelation);
763
764 clearUniqueFindersCache(socialRelation);
765 cacheUniqueFindersCache(socialRelation);
766
767 return socialRelation;
768 }
769
770 protected SocialRelation toUnwrappedModel(SocialRelation socialRelation) {
771 if (socialRelation instanceof SocialRelationImpl) {
772 return socialRelation;
773 }
774
775 SocialRelationImpl socialRelationImpl = new SocialRelationImpl();
776
777 socialRelationImpl.setNew(socialRelation.isNew());
778 socialRelationImpl.setPrimaryKey(socialRelation.getPrimaryKey());
779
780 socialRelationImpl.setUuid(socialRelation.getUuid());
781 socialRelationImpl.setRelationId(socialRelation.getRelationId());
782 socialRelationImpl.setCompanyId(socialRelation.getCompanyId());
783 socialRelationImpl.setCreateDate(socialRelation.getCreateDate());
784 socialRelationImpl.setUserId1(socialRelation.getUserId1());
785 socialRelationImpl.setUserId2(socialRelation.getUserId2());
786 socialRelationImpl.setType(socialRelation.getType());
787
788 return socialRelationImpl;
789 }
790
791
799 @Override
800 public SocialRelation findByPrimaryKey(Serializable primaryKey)
801 throws NoSuchModelException, SystemException {
802 return findByPrimaryKey(((Long)primaryKey).longValue());
803 }
804
805
813 public SocialRelation findByPrimaryKey(long relationId)
814 throws NoSuchRelationException, SystemException {
815 SocialRelation socialRelation = fetchByPrimaryKey(relationId);
816
817 if (socialRelation == null) {
818 if (_log.isWarnEnabled()) {
819 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + relationId);
820 }
821
822 throw new NoSuchRelationException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
823 relationId);
824 }
825
826 return socialRelation;
827 }
828
829
836 @Override
837 public SocialRelation fetchByPrimaryKey(Serializable primaryKey)
838 throws SystemException {
839 return fetchByPrimaryKey(((Long)primaryKey).longValue());
840 }
841
842
849 public SocialRelation fetchByPrimaryKey(long relationId)
850 throws SystemException {
851 SocialRelation socialRelation = (SocialRelation)EntityCacheUtil.getResult(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
852 SocialRelationImpl.class, relationId);
853
854 if (socialRelation == _nullSocialRelation) {
855 return null;
856 }
857
858 if (socialRelation == null) {
859 Session session = null;
860
861 boolean hasException = false;
862
863 try {
864 session = openSession();
865
866 socialRelation = (SocialRelation)session.get(SocialRelationImpl.class,
867 Long.valueOf(relationId));
868 }
869 catch (Exception e) {
870 hasException = true;
871
872 throw processException(e);
873 }
874 finally {
875 if (socialRelation != null) {
876 cacheResult(socialRelation);
877 }
878 else if (!hasException) {
879 EntityCacheUtil.putResult(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
880 SocialRelationImpl.class, relationId,
881 _nullSocialRelation);
882 }
883
884 closeSession(session);
885 }
886 }
887
888 return socialRelation;
889 }
890
891
898 public List<SocialRelation> findByUuid(String uuid)
899 throws SystemException {
900 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
901 }
902
903
916 public List<SocialRelation> findByUuid(String uuid, int start, int end)
917 throws SystemException {
918 return findByUuid(uuid, start, end, null);
919 }
920
921
935 public List<SocialRelation> findByUuid(String uuid, int start, int end,
936 OrderByComparator orderByComparator) throws SystemException {
937 FinderPath finderPath = null;
938 Object[] finderArgs = null;
939
940 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
941 (orderByComparator == null)) {
942 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
943 finderArgs = new Object[] { uuid };
944 }
945 else {
946 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
947 finderArgs = new Object[] { uuid, start, end, orderByComparator };
948 }
949
950 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(finderPath,
951 finderArgs, this);
952
953 if ((list != null) && !list.isEmpty()) {
954 for (SocialRelation socialRelation : list) {
955 if (!Validator.equals(uuid, socialRelation.getUuid())) {
956 list = null;
957
958 break;
959 }
960 }
961 }
962
963 if (list == null) {
964 StringBundler query = null;
965
966 if (orderByComparator != null) {
967 query = new StringBundler(3 +
968 (orderByComparator.getOrderByFields().length * 3));
969 }
970 else {
971 query = new StringBundler(2);
972 }
973
974 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
975
976 if (uuid == null) {
977 query.append(_FINDER_COLUMN_UUID_UUID_1);
978 }
979 else {
980 if (uuid.equals(StringPool.BLANK)) {
981 query.append(_FINDER_COLUMN_UUID_UUID_3);
982 }
983 else {
984 query.append(_FINDER_COLUMN_UUID_UUID_2);
985 }
986 }
987
988 if (orderByComparator != null) {
989 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
990 orderByComparator);
991 }
992
993 String sql = query.toString();
994
995 Session session = null;
996
997 try {
998 session = openSession();
999
1000 Query q = session.createQuery(sql);
1001
1002 QueryPos qPos = QueryPos.getInstance(q);
1003
1004 if (uuid != null) {
1005 qPos.add(uuid);
1006 }
1007
1008 list = (List<SocialRelation>)QueryUtil.list(q, getDialect(),
1009 start, end);
1010 }
1011 catch (Exception e) {
1012 throw processException(e);
1013 }
1014 finally {
1015 if (list == null) {
1016 FinderCacheUtil.removeResult(finderPath, finderArgs);
1017 }
1018 else {
1019 cacheResult(list);
1020
1021 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1022 }
1023
1024 closeSession(session);
1025 }
1026 }
1027
1028 return list;
1029 }
1030
1031
1040 public SocialRelation findByUuid_First(String uuid,
1041 OrderByComparator orderByComparator)
1042 throws NoSuchRelationException, SystemException {
1043 SocialRelation socialRelation = fetchByUuid_First(uuid,
1044 orderByComparator);
1045
1046 if (socialRelation != null) {
1047 return socialRelation;
1048 }
1049
1050 StringBundler msg = new StringBundler(4);
1051
1052 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1053
1054 msg.append("uuid=");
1055 msg.append(uuid);
1056
1057 msg.append(StringPool.CLOSE_CURLY_BRACE);
1058
1059 throw new NoSuchRelationException(msg.toString());
1060 }
1061
1062
1070 public SocialRelation fetchByUuid_First(String uuid,
1071 OrderByComparator orderByComparator) throws SystemException {
1072 List<SocialRelation> list = findByUuid(uuid, 0, 1, orderByComparator);
1073
1074 if (!list.isEmpty()) {
1075 return list.get(0);
1076 }
1077
1078 return null;
1079 }
1080
1081
1090 public SocialRelation findByUuid_Last(String uuid,
1091 OrderByComparator orderByComparator)
1092 throws NoSuchRelationException, SystemException {
1093 SocialRelation socialRelation = fetchByUuid_Last(uuid, orderByComparator);
1094
1095 if (socialRelation != null) {
1096 return socialRelation;
1097 }
1098
1099 StringBundler msg = new StringBundler(4);
1100
1101 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1102
1103 msg.append("uuid=");
1104 msg.append(uuid);
1105
1106 msg.append(StringPool.CLOSE_CURLY_BRACE);
1107
1108 throw new NoSuchRelationException(msg.toString());
1109 }
1110
1111
1119 public SocialRelation fetchByUuid_Last(String uuid,
1120 OrderByComparator orderByComparator) throws SystemException {
1121 int count = countByUuid(uuid);
1122
1123 List<SocialRelation> list = findByUuid(uuid, count - 1, count,
1124 orderByComparator);
1125
1126 if (!list.isEmpty()) {
1127 return list.get(0);
1128 }
1129
1130 return null;
1131 }
1132
1133
1143 public SocialRelation[] findByUuid_PrevAndNext(long relationId,
1144 String uuid, OrderByComparator orderByComparator)
1145 throws NoSuchRelationException, SystemException {
1146 SocialRelation socialRelation = findByPrimaryKey(relationId);
1147
1148 Session session = null;
1149
1150 try {
1151 session = openSession();
1152
1153 SocialRelation[] array = new SocialRelationImpl[3];
1154
1155 array[0] = getByUuid_PrevAndNext(session, socialRelation, uuid,
1156 orderByComparator, true);
1157
1158 array[1] = socialRelation;
1159
1160 array[2] = getByUuid_PrevAndNext(session, socialRelation, uuid,
1161 orderByComparator, false);
1162
1163 return array;
1164 }
1165 catch (Exception e) {
1166 throw processException(e);
1167 }
1168 finally {
1169 closeSession(session);
1170 }
1171 }
1172
1173 protected SocialRelation getByUuid_PrevAndNext(Session session,
1174 SocialRelation socialRelation, String uuid,
1175 OrderByComparator orderByComparator, boolean previous) {
1176 StringBundler query = null;
1177
1178 if (orderByComparator != null) {
1179 query = new StringBundler(6 +
1180 (orderByComparator.getOrderByFields().length * 6));
1181 }
1182 else {
1183 query = new StringBundler(3);
1184 }
1185
1186 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
1187
1188 if (uuid == null) {
1189 query.append(_FINDER_COLUMN_UUID_UUID_1);
1190 }
1191 else {
1192 if (uuid.equals(StringPool.BLANK)) {
1193 query.append(_FINDER_COLUMN_UUID_UUID_3);
1194 }
1195 else {
1196 query.append(_FINDER_COLUMN_UUID_UUID_2);
1197 }
1198 }
1199
1200 if (orderByComparator != null) {
1201 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1202
1203 if (orderByConditionFields.length > 0) {
1204 query.append(WHERE_AND);
1205 }
1206
1207 for (int i = 0; i < orderByConditionFields.length; i++) {
1208 query.append(_ORDER_BY_ENTITY_ALIAS);
1209 query.append(orderByConditionFields[i]);
1210
1211 if ((i + 1) < orderByConditionFields.length) {
1212 if (orderByComparator.isAscending() ^ previous) {
1213 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1214 }
1215 else {
1216 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1217 }
1218 }
1219 else {
1220 if (orderByComparator.isAscending() ^ previous) {
1221 query.append(WHERE_GREATER_THAN);
1222 }
1223 else {
1224 query.append(WHERE_LESSER_THAN);
1225 }
1226 }
1227 }
1228
1229 query.append(ORDER_BY_CLAUSE);
1230
1231 String[] orderByFields = orderByComparator.getOrderByFields();
1232
1233 for (int i = 0; i < orderByFields.length; i++) {
1234 query.append(_ORDER_BY_ENTITY_ALIAS);
1235 query.append(orderByFields[i]);
1236
1237 if ((i + 1) < orderByFields.length) {
1238 if (orderByComparator.isAscending() ^ previous) {
1239 query.append(ORDER_BY_ASC_HAS_NEXT);
1240 }
1241 else {
1242 query.append(ORDER_BY_DESC_HAS_NEXT);
1243 }
1244 }
1245 else {
1246 if (orderByComparator.isAscending() ^ previous) {
1247 query.append(ORDER_BY_ASC);
1248 }
1249 else {
1250 query.append(ORDER_BY_DESC);
1251 }
1252 }
1253 }
1254 }
1255
1256 String sql = query.toString();
1257
1258 Query q = session.createQuery(sql);
1259
1260 q.setFirstResult(0);
1261 q.setMaxResults(2);
1262
1263 QueryPos qPos = QueryPos.getInstance(q);
1264
1265 if (uuid != null) {
1266 qPos.add(uuid);
1267 }
1268
1269 if (orderByComparator != null) {
1270 Object[] values = orderByComparator.getOrderByConditionValues(socialRelation);
1271
1272 for (Object value : values) {
1273 qPos.add(value);
1274 }
1275 }
1276
1277 List<SocialRelation> list = q.list();
1278
1279 if (list.size() == 2) {
1280 return list.get(1);
1281 }
1282 else {
1283 return null;
1284 }
1285 }
1286
1287
1294 public List<SocialRelation> findByCompanyId(long companyId)
1295 throws SystemException {
1296 return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1297 null);
1298 }
1299
1300
1313 public List<SocialRelation> findByCompanyId(long companyId, int start,
1314 int end) throws SystemException {
1315 return findByCompanyId(companyId, start, end, null);
1316 }
1317
1318
1332 public List<SocialRelation> findByCompanyId(long companyId, int start,
1333 int end, OrderByComparator orderByComparator) throws SystemException {
1334 FinderPath finderPath = null;
1335 Object[] finderArgs = null;
1336
1337 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1338 (orderByComparator == null)) {
1339 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
1340 finderArgs = new Object[] { companyId };
1341 }
1342 else {
1343 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
1344 finderArgs = new Object[] { companyId, start, end, orderByComparator };
1345 }
1346
1347 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(finderPath,
1348 finderArgs, this);
1349
1350 if ((list != null) && !list.isEmpty()) {
1351 for (SocialRelation socialRelation : list) {
1352 if ((companyId != socialRelation.getCompanyId())) {
1353 list = null;
1354
1355 break;
1356 }
1357 }
1358 }
1359
1360 if (list == null) {
1361 StringBundler query = null;
1362
1363 if (orderByComparator != null) {
1364 query = new StringBundler(3 +
1365 (orderByComparator.getOrderByFields().length * 3));
1366 }
1367 else {
1368 query = new StringBundler(2);
1369 }
1370
1371 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
1372
1373 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1374
1375 if (orderByComparator != null) {
1376 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1377 orderByComparator);
1378 }
1379
1380 String sql = query.toString();
1381
1382 Session session = null;
1383
1384 try {
1385 session = openSession();
1386
1387 Query q = session.createQuery(sql);
1388
1389 QueryPos qPos = QueryPos.getInstance(q);
1390
1391 qPos.add(companyId);
1392
1393 list = (List<SocialRelation>)QueryUtil.list(q, getDialect(),
1394 start, end);
1395 }
1396 catch (Exception e) {
1397 throw processException(e);
1398 }
1399 finally {
1400 if (list == null) {
1401 FinderCacheUtil.removeResult(finderPath, finderArgs);
1402 }
1403 else {
1404 cacheResult(list);
1405
1406 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1407 }
1408
1409 closeSession(session);
1410 }
1411 }
1412
1413 return list;
1414 }
1415
1416
1425 public SocialRelation findByCompanyId_First(long companyId,
1426 OrderByComparator orderByComparator)
1427 throws NoSuchRelationException, SystemException {
1428 SocialRelation socialRelation = fetchByCompanyId_First(companyId,
1429 orderByComparator);
1430
1431 if (socialRelation != null) {
1432 return socialRelation;
1433 }
1434
1435 StringBundler msg = new StringBundler(4);
1436
1437 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1438
1439 msg.append("companyId=");
1440 msg.append(companyId);
1441
1442 msg.append(StringPool.CLOSE_CURLY_BRACE);
1443
1444 throw new NoSuchRelationException(msg.toString());
1445 }
1446
1447
1455 public SocialRelation fetchByCompanyId_First(long companyId,
1456 OrderByComparator orderByComparator) throws SystemException {
1457 List<SocialRelation> list = findByCompanyId(companyId, 0, 1,
1458 orderByComparator);
1459
1460 if (!list.isEmpty()) {
1461 return list.get(0);
1462 }
1463
1464 return null;
1465 }
1466
1467
1476 public SocialRelation findByCompanyId_Last(long companyId,
1477 OrderByComparator orderByComparator)
1478 throws NoSuchRelationException, SystemException {
1479 SocialRelation socialRelation = fetchByCompanyId_Last(companyId,
1480 orderByComparator);
1481
1482 if (socialRelation != null) {
1483 return socialRelation;
1484 }
1485
1486 StringBundler msg = new StringBundler(4);
1487
1488 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1489
1490 msg.append("companyId=");
1491 msg.append(companyId);
1492
1493 msg.append(StringPool.CLOSE_CURLY_BRACE);
1494
1495 throw new NoSuchRelationException(msg.toString());
1496 }
1497
1498
1506 public SocialRelation fetchByCompanyId_Last(long companyId,
1507 OrderByComparator orderByComparator) throws SystemException {
1508 int count = countByCompanyId(companyId);
1509
1510 List<SocialRelation> list = findByCompanyId(companyId, count - 1,
1511 count, orderByComparator);
1512
1513 if (!list.isEmpty()) {
1514 return list.get(0);
1515 }
1516
1517 return null;
1518 }
1519
1520
1530 public SocialRelation[] findByCompanyId_PrevAndNext(long relationId,
1531 long companyId, OrderByComparator orderByComparator)
1532 throws NoSuchRelationException, SystemException {
1533 SocialRelation socialRelation = findByPrimaryKey(relationId);
1534
1535 Session session = null;
1536
1537 try {
1538 session = openSession();
1539
1540 SocialRelation[] array = new SocialRelationImpl[3];
1541
1542 array[0] = getByCompanyId_PrevAndNext(session, socialRelation,
1543 companyId, orderByComparator, true);
1544
1545 array[1] = socialRelation;
1546
1547 array[2] = getByCompanyId_PrevAndNext(session, socialRelation,
1548 companyId, orderByComparator, false);
1549
1550 return array;
1551 }
1552 catch (Exception e) {
1553 throw processException(e);
1554 }
1555 finally {
1556 closeSession(session);
1557 }
1558 }
1559
1560 protected SocialRelation getByCompanyId_PrevAndNext(Session session,
1561 SocialRelation socialRelation, long companyId,
1562 OrderByComparator orderByComparator, boolean previous) {
1563 StringBundler query = null;
1564
1565 if (orderByComparator != null) {
1566 query = new StringBundler(6 +
1567 (orderByComparator.getOrderByFields().length * 6));
1568 }
1569 else {
1570 query = new StringBundler(3);
1571 }
1572
1573 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
1574
1575 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1576
1577 if (orderByComparator != null) {
1578 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1579
1580 if (orderByConditionFields.length > 0) {
1581 query.append(WHERE_AND);
1582 }
1583
1584 for (int i = 0; i < orderByConditionFields.length; i++) {
1585 query.append(_ORDER_BY_ENTITY_ALIAS);
1586 query.append(orderByConditionFields[i]);
1587
1588 if ((i + 1) < orderByConditionFields.length) {
1589 if (orderByComparator.isAscending() ^ previous) {
1590 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1591 }
1592 else {
1593 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1594 }
1595 }
1596 else {
1597 if (orderByComparator.isAscending() ^ previous) {
1598 query.append(WHERE_GREATER_THAN);
1599 }
1600 else {
1601 query.append(WHERE_LESSER_THAN);
1602 }
1603 }
1604 }
1605
1606 query.append(ORDER_BY_CLAUSE);
1607
1608 String[] orderByFields = orderByComparator.getOrderByFields();
1609
1610 for (int i = 0; i < orderByFields.length; i++) {
1611 query.append(_ORDER_BY_ENTITY_ALIAS);
1612 query.append(orderByFields[i]);
1613
1614 if ((i + 1) < orderByFields.length) {
1615 if (orderByComparator.isAscending() ^ previous) {
1616 query.append(ORDER_BY_ASC_HAS_NEXT);
1617 }
1618 else {
1619 query.append(ORDER_BY_DESC_HAS_NEXT);
1620 }
1621 }
1622 else {
1623 if (orderByComparator.isAscending() ^ previous) {
1624 query.append(ORDER_BY_ASC);
1625 }
1626 else {
1627 query.append(ORDER_BY_DESC);
1628 }
1629 }
1630 }
1631 }
1632
1633 String sql = query.toString();
1634
1635 Query q = session.createQuery(sql);
1636
1637 q.setFirstResult(0);
1638 q.setMaxResults(2);
1639
1640 QueryPos qPos = QueryPos.getInstance(q);
1641
1642 qPos.add(companyId);
1643
1644 if (orderByComparator != null) {
1645 Object[] values = orderByComparator.getOrderByConditionValues(socialRelation);
1646
1647 for (Object value : values) {
1648 qPos.add(value);
1649 }
1650 }
1651
1652 List<SocialRelation> list = q.list();
1653
1654 if (list.size() == 2) {
1655 return list.get(1);
1656 }
1657 else {
1658 return null;
1659 }
1660 }
1661
1662
1669 public List<SocialRelation> findByUserId1(long userId1)
1670 throws SystemException {
1671 return findByUserId1(userId1, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1672 }
1673
1674
1687 public List<SocialRelation> findByUserId1(long userId1, int start, int end)
1688 throws SystemException {
1689 return findByUserId1(userId1, start, end, null);
1690 }
1691
1692
1706 public List<SocialRelation> findByUserId1(long userId1, int start, int end,
1707 OrderByComparator orderByComparator) throws SystemException {
1708 FinderPath finderPath = null;
1709 Object[] finderArgs = null;
1710
1711 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1712 (orderByComparator == null)) {
1713 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID1;
1714 finderArgs = new Object[] { userId1 };
1715 }
1716 else {
1717 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID1;
1718 finderArgs = new Object[] { userId1, start, end, orderByComparator };
1719 }
1720
1721 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(finderPath,
1722 finderArgs, this);
1723
1724 if ((list != null) && !list.isEmpty()) {
1725 for (SocialRelation socialRelation : list) {
1726 if ((userId1 != socialRelation.getUserId1())) {
1727 list = null;
1728
1729 break;
1730 }
1731 }
1732 }
1733
1734 if (list == null) {
1735 StringBundler query = null;
1736
1737 if (orderByComparator != null) {
1738 query = new StringBundler(3 +
1739 (orderByComparator.getOrderByFields().length * 3));
1740 }
1741 else {
1742 query = new StringBundler(2);
1743 }
1744
1745 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
1746
1747 query.append(_FINDER_COLUMN_USERID1_USERID1_2);
1748
1749 if (orderByComparator != null) {
1750 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1751 orderByComparator);
1752 }
1753
1754 String sql = query.toString();
1755
1756 Session session = null;
1757
1758 try {
1759 session = openSession();
1760
1761 Query q = session.createQuery(sql);
1762
1763 QueryPos qPos = QueryPos.getInstance(q);
1764
1765 qPos.add(userId1);
1766
1767 list = (List<SocialRelation>)QueryUtil.list(q, getDialect(),
1768 start, end);
1769 }
1770 catch (Exception e) {
1771 throw processException(e);
1772 }
1773 finally {
1774 if (list == null) {
1775 FinderCacheUtil.removeResult(finderPath, finderArgs);
1776 }
1777 else {
1778 cacheResult(list);
1779
1780 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1781 }
1782
1783 closeSession(session);
1784 }
1785 }
1786
1787 return list;
1788 }
1789
1790
1799 public SocialRelation findByUserId1_First(long userId1,
1800 OrderByComparator orderByComparator)
1801 throws NoSuchRelationException, SystemException {
1802 SocialRelation socialRelation = fetchByUserId1_First(userId1,
1803 orderByComparator);
1804
1805 if (socialRelation != null) {
1806 return socialRelation;
1807 }
1808
1809 StringBundler msg = new StringBundler(4);
1810
1811 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1812
1813 msg.append("userId1=");
1814 msg.append(userId1);
1815
1816 msg.append(StringPool.CLOSE_CURLY_BRACE);
1817
1818 throw new NoSuchRelationException(msg.toString());
1819 }
1820
1821
1829 public SocialRelation fetchByUserId1_First(long userId1,
1830 OrderByComparator orderByComparator) throws SystemException {
1831 List<SocialRelation> list = findByUserId1(userId1, 0, 1,
1832 orderByComparator);
1833
1834 if (!list.isEmpty()) {
1835 return list.get(0);
1836 }
1837
1838 return null;
1839 }
1840
1841
1850 public SocialRelation findByUserId1_Last(long userId1,
1851 OrderByComparator orderByComparator)
1852 throws NoSuchRelationException, SystemException {
1853 SocialRelation socialRelation = fetchByUserId1_Last(userId1,
1854 orderByComparator);
1855
1856 if (socialRelation != null) {
1857 return socialRelation;
1858 }
1859
1860 StringBundler msg = new StringBundler(4);
1861
1862 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1863
1864 msg.append("userId1=");
1865 msg.append(userId1);
1866
1867 msg.append(StringPool.CLOSE_CURLY_BRACE);
1868
1869 throw new NoSuchRelationException(msg.toString());
1870 }
1871
1872
1880 public SocialRelation fetchByUserId1_Last(long userId1,
1881 OrderByComparator orderByComparator) throws SystemException {
1882 int count = countByUserId1(userId1);
1883
1884 List<SocialRelation> list = findByUserId1(userId1, count - 1, count,
1885 orderByComparator);
1886
1887 if (!list.isEmpty()) {
1888 return list.get(0);
1889 }
1890
1891 return null;
1892 }
1893
1894
1904 public SocialRelation[] findByUserId1_PrevAndNext(long relationId,
1905 long userId1, OrderByComparator orderByComparator)
1906 throws NoSuchRelationException, SystemException {
1907 SocialRelation socialRelation = findByPrimaryKey(relationId);
1908
1909 Session session = null;
1910
1911 try {
1912 session = openSession();
1913
1914 SocialRelation[] array = new SocialRelationImpl[3];
1915
1916 array[0] = getByUserId1_PrevAndNext(session, socialRelation,
1917 userId1, orderByComparator, true);
1918
1919 array[1] = socialRelation;
1920
1921 array[2] = getByUserId1_PrevAndNext(session, socialRelation,
1922 userId1, orderByComparator, false);
1923
1924 return array;
1925 }
1926 catch (Exception e) {
1927 throw processException(e);
1928 }
1929 finally {
1930 closeSession(session);
1931 }
1932 }
1933
1934 protected SocialRelation getByUserId1_PrevAndNext(Session session,
1935 SocialRelation socialRelation, long userId1,
1936 OrderByComparator orderByComparator, boolean previous) {
1937 StringBundler query = null;
1938
1939 if (orderByComparator != null) {
1940 query = new StringBundler(6 +
1941 (orderByComparator.getOrderByFields().length * 6));
1942 }
1943 else {
1944 query = new StringBundler(3);
1945 }
1946
1947 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
1948
1949 query.append(_FINDER_COLUMN_USERID1_USERID1_2);
1950
1951 if (orderByComparator != null) {
1952 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1953
1954 if (orderByConditionFields.length > 0) {
1955 query.append(WHERE_AND);
1956 }
1957
1958 for (int i = 0; i < orderByConditionFields.length; i++) {
1959 query.append(_ORDER_BY_ENTITY_ALIAS);
1960 query.append(orderByConditionFields[i]);
1961
1962 if ((i + 1) < orderByConditionFields.length) {
1963 if (orderByComparator.isAscending() ^ previous) {
1964 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1965 }
1966 else {
1967 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1968 }
1969 }
1970 else {
1971 if (orderByComparator.isAscending() ^ previous) {
1972 query.append(WHERE_GREATER_THAN);
1973 }
1974 else {
1975 query.append(WHERE_LESSER_THAN);
1976 }
1977 }
1978 }
1979
1980 query.append(ORDER_BY_CLAUSE);
1981
1982 String[] orderByFields = orderByComparator.getOrderByFields();
1983
1984 for (int i = 0; i < orderByFields.length; i++) {
1985 query.append(_ORDER_BY_ENTITY_ALIAS);
1986 query.append(orderByFields[i]);
1987
1988 if ((i + 1) < orderByFields.length) {
1989 if (orderByComparator.isAscending() ^ previous) {
1990 query.append(ORDER_BY_ASC_HAS_NEXT);
1991 }
1992 else {
1993 query.append(ORDER_BY_DESC_HAS_NEXT);
1994 }
1995 }
1996 else {
1997 if (orderByComparator.isAscending() ^ previous) {
1998 query.append(ORDER_BY_ASC);
1999 }
2000 else {
2001 query.append(ORDER_BY_DESC);
2002 }
2003 }
2004 }
2005 }
2006
2007 String sql = query.toString();
2008
2009 Query q = session.createQuery(sql);
2010
2011 q.setFirstResult(0);
2012 q.setMaxResults(2);
2013
2014 QueryPos qPos = QueryPos.getInstance(q);
2015
2016 qPos.add(userId1);
2017
2018 if (orderByComparator != null) {
2019 Object[] values = orderByComparator.getOrderByConditionValues(socialRelation);
2020
2021 for (Object value : values) {
2022 qPos.add(value);
2023 }
2024 }
2025
2026 List<SocialRelation> list = q.list();
2027
2028 if (list.size() == 2) {
2029 return list.get(1);
2030 }
2031 else {
2032 return null;
2033 }
2034 }
2035
2036
2043 public List<SocialRelation> findByUserId2(long userId2)
2044 throws SystemException {
2045 return findByUserId2(userId2, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2046 }
2047
2048
2061 public List<SocialRelation> findByUserId2(long userId2, int start, int end)
2062 throws SystemException {
2063 return findByUserId2(userId2, start, end, null);
2064 }
2065
2066
2080 public List<SocialRelation> findByUserId2(long userId2, int start, int end,
2081 OrderByComparator orderByComparator) throws SystemException {
2082 FinderPath finderPath = null;
2083 Object[] finderArgs = null;
2084
2085 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2086 (orderByComparator == null)) {
2087 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID2;
2088 finderArgs = new Object[] { userId2 };
2089 }
2090 else {
2091 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID2;
2092 finderArgs = new Object[] { userId2, start, end, orderByComparator };
2093 }
2094
2095 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(finderPath,
2096 finderArgs, this);
2097
2098 if ((list != null) && !list.isEmpty()) {
2099 for (SocialRelation socialRelation : list) {
2100 if ((userId2 != socialRelation.getUserId2())) {
2101 list = null;
2102
2103 break;
2104 }
2105 }
2106 }
2107
2108 if (list == null) {
2109 StringBundler query = null;
2110
2111 if (orderByComparator != null) {
2112 query = new StringBundler(3 +
2113 (orderByComparator.getOrderByFields().length * 3));
2114 }
2115 else {
2116 query = new StringBundler(2);
2117 }
2118
2119 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
2120
2121 query.append(_FINDER_COLUMN_USERID2_USERID2_2);
2122
2123 if (orderByComparator != null) {
2124 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2125 orderByComparator);
2126 }
2127
2128 String sql = query.toString();
2129
2130 Session session = null;
2131
2132 try {
2133 session = openSession();
2134
2135 Query q = session.createQuery(sql);
2136
2137 QueryPos qPos = QueryPos.getInstance(q);
2138
2139 qPos.add(userId2);
2140
2141 list = (List<SocialRelation>)QueryUtil.list(q, getDialect(),
2142 start, end);
2143 }
2144 catch (Exception e) {
2145 throw processException(e);
2146 }
2147 finally {
2148 if (list == null) {
2149 FinderCacheUtil.removeResult(finderPath, finderArgs);
2150 }
2151 else {
2152 cacheResult(list);
2153
2154 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2155 }
2156
2157 closeSession(session);
2158 }
2159 }
2160
2161 return list;
2162 }
2163
2164
2173 public SocialRelation findByUserId2_First(long userId2,
2174 OrderByComparator orderByComparator)
2175 throws NoSuchRelationException, SystemException {
2176 SocialRelation socialRelation = fetchByUserId2_First(userId2,
2177 orderByComparator);
2178
2179 if (socialRelation != null) {
2180 return socialRelation;
2181 }
2182
2183 StringBundler msg = new StringBundler(4);
2184
2185 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2186
2187 msg.append("userId2=");
2188 msg.append(userId2);
2189
2190 msg.append(StringPool.CLOSE_CURLY_BRACE);
2191
2192 throw new NoSuchRelationException(msg.toString());
2193 }
2194
2195
2203 public SocialRelation fetchByUserId2_First(long userId2,
2204 OrderByComparator orderByComparator) throws SystemException {
2205 List<SocialRelation> list = findByUserId2(userId2, 0, 1,
2206 orderByComparator);
2207
2208 if (!list.isEmpty()) {
2209 return list.get(0);
2210 }
2211
2212 return null;
2213 }
2214
2215
2224 public SocialRelation findByUserId2_Last(long userId2,
2225 OrderByComparator orderByComparator)
2226 throws NoSuchRelationException, SystemException {
2227 SocialRelation socialRelation = fetchByUserId2_Last(userId2,
2228 orderByComparator);
2229
2230 if (socialRelation != null) {
2231 return socialRelation;
2232 }
2233
2234 StringBundler msg = new StringBundler(4);
2235
2236 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2237
2238 msg.append("userId2=");
2239 msg.append(userId2);
2240
2241 msg.append(StringPool.CLOSE_CURLY_BRACE);
2242
2243 throw new NoSuchRelationException(msg.toString());
2244 }
2245
2246
2254 public SocialRelation fetchByUserId2_Last(long userId2,
2255 OrderByComparator orderByComparator) throws SystemException {
2256 int count = countByUserId2(userId2);
2257
2258 List<SocialRelation> list = findByUserId2(userId2, count - 1, count,
2259 orderByComparator);
2260
2261 if (!list.isEmpty()) {
2262 return list.get(0);
2263 }
2264
2265 return null;
2266 }
2267
2268
2278 public SocialRelation[] findByUserId2_PrevAndNext(long relationId,
2279 long userId2, OrderByComparator orderByComparator)
2280 throws NoSuchRelationException, SystemException {
2281 SocialRelation socialRelation = findByPrimaryKey(relationId);
2282
2283 Session session = null;
2284
2285 try {
2286 session = openSession();
2287
2288 SocialRelation[] array = new SocialRelationImpl[3];
2289
2290 array[0] = getByUserId2_PrevAndNext(session, socialRelation,
2291 userId2, orderByComparator, true);
2292
2293 array[1] = socialRelation;
2294
2295 array[2] = getByUserId2_PrevAndNext(session, socialRelation,
2296 userId2, orderByComparator, false);
2297
2298 return array;
2299 }
2300 catch (Exception e) {
2301 throw processException(e);
2302 }
2303 finally {
2304 closeSession(session);
2305 }
2306 }
2307
2308 protected SocialRelation getByUserId2_PrevAndNext(Session session,
2309 SocialRelation socialRelation, long userId2,
2310 OrderByComparator orderByComparator, boolean previous) {
2311 StringBundler query = null;
2312
2313 if (orderByComparator != null) {
2314 query = new StringBundler(6 +
2315 (orderByComparator.getOrderByFields().length * 6));
2316 }
2317 else {
2318 query = new StringBundler(3);
2319 }
2320
2321 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
2322
2323 query.append(_FINDER_COLUMN_USERID2_USERID2_2);
2324
2325 if (orderByComparator != null) {
2326 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2327
2328 if (orderByConditionFields.length > 0) {
2329 query.append(WHERE_AND);
2330 }
2331
2332 for (int i = 0; i < orderByConditionFields.length; i++) {
2333 query.append(_ORDER_BY_ENTITY_ALIAS);
2334 query.append(orderByConditionFields[i]);
2335
2336 if ((i + 1) < orderByConditionFields.length) {
2337 if (orderByComparator.isAscending() ^ previous) {
2338 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2339 }
2340 else {
2341 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2342 }
2343 }
2344 else {
2345 if (orderByComparator.isAscending() ^ previous) {
2346 query.append(WHERE_GREATER_THAN);
2347 }
2348 else {
2349 query.append(WHERE_LESSER_THAN);
2350 }
2351 }
2352 }
2353
2354 query.append(ORDER_BY_CLAUSE);
2355
2356 String[] orderByFields = orderByComparator.getOrderByFields();
2357
2358 for (int i = 0; i < orderByFields.length; i++) {
2359 query.append(_ORDER_BY_ENTITY_ALIAS);
2360 query.append(orderByFields[i]);
2361
2362 if ((i + 1) < orderByFields.length) {
2363 if (orderByComparator.isAscending() ^ previous) {
2364 query.append(ORDER_BY_ASC_HAS_NEXT);
2365 }
2366 else {
2367 query.append(ORDER_BY_DESC_HAS_NEXT);
2368 }
2369 }
2370 else {
2371 if (orderByComparator.isAscending() ^ previous) {
2372 query.append(ORDER_BY_ASC);
2373 }
2374 else {
2375 query.append(ORDER_BY_DESC);
2376 }
2377 }
2378 }
2379 }
2380
2381 String sql = query.toString();
2382
2383 Query q = session.createQuery(sql);
2384
2385 q.setFirstResult(0);
2386 q.setMaxResults(2);
2387
2388 QueryPos qPos = QueryPos.getInstance(q);
2389
2390 qPos.add(userId2);
2391
2392 if (orderByComparator != null) {
2393 Object[] values = orderByComparator.getOrderByConditionValues(socialRelation);
2394
2395 for (Object value : values) {
2396 qPos.add(value);
2397 }
2398 }
2399
2400 List<SocialRelation> list = q.list();
2401
2402 if (list.size() == 2) {
2403 return list.get(1);
2404 }
2405 else {
2406 return null;
2407 }
2408 }
2409
2410
2417 public List<SocialRelation> findByType(int type) throws SystemException {
2418 return findByType(type, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2419 }
2420
2421
2434 public List<SocialRelation> findByType(int type, int start, int end)
2435 throws SystemException {
2436 return findByType(type, start, end, null);
2437 }
2438
2439
2453 public List<SocialRelation> findByType(int type, int start, int end,
2454 OrderByComparator orderByComparator) throws SystemException {
2455 FinderPath finderPath = null;
2456 Object[] finderArgs = null;
2457
2458 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2459 (orderByComparator == null)) {
2460 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE;
2461 finderArgs = new Object[] { type };
2462 }
2463 else {
2464 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_TYPE;
2465 finderArgs = new Object[] { type, start, end, orderByComparator };
2466 }
2467
2468 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(finderPath,
2469 finderArgs, this);
2470
2471 if ((list != null) && !list.isEmpty()) {
2472 for (SocialRelation socialRelation : list) {
2473 if ((type != socialRelation.getType())) {
2474 list = null;
2475
2476 break;
2477 }
2478 }
2479 }
2480
2481 if (list == null) {
2482 StringBundler query = null;
2483
2484 if (orderByComparator != null) {
2485 query = new StringBundler(3 +
2486 (orderByComparator.getOrderByFields().length * 3));
2487 }
2488 else {
2489 query = new StringBundler(2);
2490 }
2491
2492 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
2493
2494 query.append(_FINDER_COLUMN_TYPE_TYPE_2);
2495
2496 if (orderByComparator != null) {
2497 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2498 orderByComparator);
2499 }
2500
2501 String sql = query.toString();
2502
2503 Session session = null;
2504
2505 try {
2506 session = openSession();
2507
2508 Query q = session.createQuery(sql);
2509
2510 QueryPos qPos = QueryPos.getInstance(q);
2511
2512 qPos.add(type);
2513
2514 list = (List<SocialRelation>)QueryUtil.list(q, getDialect(),
2515 start, end);
2516 }
2517 catch (Exception e) {
2518 throw processException(e);
2519 }
2520 finally {
2521 if (list == null) {
2522 FinderCacheUtil.removeResult(finderPath, finderArgs);
2523 }
2524 else {
2525 cacheResult(list);
2526
2527 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2528 }
2529
2530 closeSession(session);
2531 }
2532 }
2533
2534 return list;
2535 }
2536
2537
2546 public SocialRelation findByType_First(int type,
2547 OrderByComparator orderByComparator)
2548 throws NoSuchRelationException, SystemException {
2549 SocialRelation socialRelation = fetchByType_First(type,
2550 orderByComparator);
2551
2552 if (socialRelation != null) {
2553 return socialRelation;
2554 }
2555
2556 StringBundler msg = new StringBundler(4);
2557
2558 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2559
2560 msg.append("type=");
2561 msg.append(type);
2562
2563 msg.append(StringPool.CLOSE_CURLY_BRACE);
2564
2565 throw new NoSuchRelationException(msg.toString());
2566 }
2567
2568
2576 public SocialRelation fetchByType_First(int type,
2577 OrderByComparator orderByComparator) throws SystemException {
2578 List<SocialRelation> list = findByType(type, 0, 1, orderByComparator);
2579
2580 if (!list.isEmpty()) {
2581 return list.get(0);
2582 }
2583
2584 return null;
2585 }
2586
2587
2596 public SocialRelation findByType_Last(int type,
2597 OrderByComparator orderByComparator)
2598 throws NoSuchRelationException, SystemException {
2599 SocialRelation socialRelation = fetchByType_Last(type, orderByComparator);
2600
2601 if (socialRelation != null) {
2602 return socialRelation;
2603 }
2604
2605 StringBundler msg = new StringBundler(4);
2606
2607 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2608
2609 msg.append("type=");
2610 msg.append(type);
2611
2612 msg.append(StringPool.CLOSE_CURLY_BRACE);
2613
2614 throw new NoSuchRelationException(msg.toString());
2615 }
2616
2617
2625 public SocialRelation fetchByType_Last(int type,
2626 OrderByComparator orderByComparator) throws SystemException {
2627 int count = countByType(type);
2628
2629 List<SocialRelation> list = findByType(type, count - 1, count,
2630 orderByComparator);
2631
2632 if (!list.isEmpty()) {
2633 return list.get(0);
2634 }
2635
2636 return null;
2637 }
2638
2639
2649 public SocialRelation[] findByType_PrevAndNext(long relationId, int type,
2650 OrderByComparator orderByComparator)
2651 throws NoSuchRelationException, SystemException {
2652 SocialRelation socialRelation = findByPrimaryKey(relationId);
2653
2654 Session session = null;
2655
2656 try {
2657 session = openSession();
2658
2659 SocialRelation[] array = new SocialRelationImpl[3];
2660
2661 array[0] = getByType_PrevAndNext(session, socialRelation, type,
2662 orderByComparator, true);
2663
2664 array[1] = socialRelation;
2665
2666 array[2] = getByType_PrevAndNext(session, socialRelation, type,
2667 orderByComparator, false);
2668
2669 return array;
2670 }
2671 catch (Exception e) {
2672 throw processException(e);
2673 }
2674 finally {
2675 closeSession(session);
2676 }
2677 }
2678
2679 protected SocialRelation getByType_PrevAndNext(Session session,
2680 SocialRelation socialRelation, int type,
2681 OrderByComparator orderByComparator, boolean previous) {
2682 StringBundler query = null;
2683
2684 if (orderByComparator != null) {
2685 query = new StringBundler(6 +
2686 (orderByComparator.getOrderByFields().length * 6));
2687 }
2688 else {
2689 query = new StringBundler(3);
2690 }
2691
2692 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
2693
2694 query.append(_FINDER_COLUMN_TYPE_TYPE_2);
2695
2696 if (orderByComparator != null) {
2697 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2698
2699 if (orderByConditionFields.length > 0) {
2700 query.append(WHERE_AND);
2701 }
2702
2703 for (int i = 0; i < orderByConditionFields.length; i++) {
2704 query.append(_ORDER_BY_ENTITY_ALIAS);
2705 query.append(orderByConditionFields[i]);
2706
2707 if ((i + 1) < orderByConditionFields.length) {
2708 if (orderByComparator.isAscending() ^ previous) {
2709 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2710 }
2711 else {
2712 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2713 }
2714 }
2715 else {
2716 if (orderByComparator.isAscending() ^ previous) {
2717 query.append(WHERE_GREATER_THAN);
2718 }
2719 else {
2720 query.append(WHERE_LESSER_THAN);
2721 }
2722 }
2723 }
2724
2725 query.append(ORDER_BY_CLAUSE);
2726
2727 String[] orderByFields = orderByComparator.getOrderByFields();
2728
2729 for (int i = 0; i < orderByFields.length; i++) {
2730 query.append(_ORDER_BY_ENTITY_ALIAS);
2731 query.append(orderByFields[i]);
2732
2733 if ((i + 1) < orderByFields.length) {
2734 if (orderByComparator.isAscending() ^ previous) {
2735 query.append(ORDER_BY_ASC_HAS_NEXT);
2736 }
2737 else {
2738 query.append(ORDER_BY_DESC_HAS_NEXT);
2739 }
2740 }
2741 else {
2742 if (orderByComparator.isAscending() ^ previous) {
2743 query.append(ORDER_BY_ASC);
2744 }
2745 else {
2746 query.append(ORDER_BY_DESC);
2747 }
2748 }
2749 }
2750 }
2751
2752 String sql = query.toString();
2753
2754 Query q = session.createQuery(sql);
2755
2756 q.setFirstResult(0);
2757 q.setMaxResults(2);
2758
2759 QueryPos qPos = QueryPos.getInstance(q);
2760
2761 qPos.add(type);
2762
2763 if (orderByComparator != null) {
2764 Object[] values = orderByComparator.getOrderByConditionValues(socialRelation);
2765
2766 for (Object value : values) {
2767 qPos.add(value);
2768 }
2769 }
2770
2771 List<SocialRelation> list = q.list();
2772
2773 if (list.size() == 2) {
2774 return list.get(1);
2775 }
2776 else {
2777 return null;
2778 }
2779 }
2780
2781
2789 public List<SocialRelation> findByC_T(long companyId, int type)
2790 throws SystemException {
2791 return findByC_T(companyId, type, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2792 null);
2793 }
2794
2795
2809 public List<SocialRelation> findByC_T(long companyId, int type, int start,
2810 int end) throws SystemException {
2811 return findByC_T(companyId, type, start, end, null);
2812 }
2813
2814
2829 public List<SocialRelation> findByC_T(long companyId, int type, int start,
2830 int end, OrderByComparator orderByComparator) throws SystemException {
2831 FinderPath finderPath = null;
2832 Object[] finderArgs = null;
2833
2834 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2835 (orderByComparator == null)) {
2836 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_T;
2837 finderArgs = new Object[] { companyId, type };
2838 }
2839 else {
2840 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_T;
2841 finderArgs = new Object[] {
2842 companyId, type,
2843
2844 start, end, orderByComparator
2845 };
2846 }
2847
2848 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(finderPath,
2849 finderArgs, this);
2850
2851 if ((list != null) && !list.isEmpty()) {
2852 for (SocialRelation socialRelation : list) {
2853 if ((companyId != socialRelation.getCompanyId()) ||
2854 (type != socialRelation.getType())) {
2855 list = null;
2856
2857 break;
2858 }
2859 }
2860 }
2861
2862 if (list == null) {
2863 StringBundler query = null;
2864
2865 if (orderByComparator != null) {
2866 query = new StringBundler(4 +
2867 (orderByComparator.getOrderByFields().length * 3));
2868 }
2869 else {
2870 query = new StringBundler(3);
2871 }
2872
2873 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
2874
2875 query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
2876
2877 query.append(_FINDER_COLUMN_C_T_TYPE_2);
2878
2879 if (orderByComparator != null) {
2880 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2881 orderByComparator);
2882 }
2883
2884 String sql = query.toString();
2885
2886 Session session = null;
2887
2888 try {
2889 session = openSession();
2890
2891 Query q = session.createQuery(sql);
2892
2893 QueryPos qPos = QueryPos.getInstance(q);
2894
2895 qPos.add(companyId);
2896
2897 qPos.add(type);
2898
2899 list = (List<SocialRelation>)QueryUtil.list(q, getDialect(),
2900 start, end);
2901 }
2902 catch (Exception e) {
2903 throw processException(e);
2904 }
2905 finally {
2906 if (list == null) {
2907 FinderCacheUtil.removeResult(finderPath, finderArgs);
2908 }
2909 else {
2910 cacheResult(list);
2911
2912 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2913 }
2914
2915 closeSession(session);
2916 }
2917 }
2918
2919 return list;
2920 }
2921
2922
2932 public SocialRelation findByC_T_First(long companyId, int type,
2933 OrderByComparator orderByComparator)
2934 throws NoSuchRelationException, SystemException {
2935 SocialRelation socialRelation = fetchByC_T_First(companyId, type,
2936 orderByComparator);
2937
2938 if (socialRelation != null) {
2939 return socialRelation;
2940 }
2941
2942 StringBundler msg = new StringBundler(6);
2943
2944 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2945
2946 msg.append("companyId=");
2947 msg.append(companyId);
2948
2949 msg.append(", type=");
2950 msg.append(type);
2951
2952 msg.append(StringPool.CLOSE_CURLY_BRACE);
2953
2954 throw new NoSuchRelationException(msg.toString());
2955 }
2956
2957
2966 public SocialRelation fetchByC_T_First(long companyId, int type,
2967 OrderByComparator orderByComparator) throws SystemException {
2968 List<SocialRelation> list = findByC_T(companyId, type, 0, 1,
2969 orderByComparator);
2970
2971 if (!list.isEmpty()) {
2972 return list.get(0);
2973 }
2974
2975 return null;
2976 }
2977
2978
2988 public SocialRelation findByC_T_Last(long companyId, int type,
2989 OrderByComparator orderByComparator)
2990 throws NoSuchRelationException, SystemException {
2991 SocialRelation socialRelation = fetchByC_T_Last(companyId, type,
2992 orderByComparator);
2993
2994 if (socialRelation != null) {
2995 return socialRelation;
2996 }
2997
2998 StringBundler msg = new StringBundler(6);
2999
3000 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3001
3002 msg.append("companyId=");
3003 msg.append(companyId);
3004
3005 msg.append(", type=");
3006 msg.append(type);
3007
3008 msg.append(StringPool.CLOSE_CURLY_BRACE);
3009
3010 throw new NoSuchRelationException(msg.toString());
3011 }
3012
3013
3022 public SocialRelation fetchByC_T_Last(long companyId, int type,
3023 OrderByComparator orderByComparator) throws SystemException {
3024 int count = countByC_T(companyId, type);
3025
3026 List<SocialRelation> list = findByC_T(companyId, type, count - 1,
3027 count, orderByComparator);
3028
3029 if (!list.isEmpty()) {
3030 return list.get(0);
3031 }
3032
3033 return null;
3034 }
3035
3036
3047 public SocialRelation[] findByC_T_PrevAndNext(long relationId,
3048 long companyId, int type, OrderByComparator orderByComparator)
3049 throws NoSuchRelationException, SystemException {
3050 SocialRelation socialRelation = findByPrimaryKey(relationId);
3051
3052 Session session = null;
3053
3054 try {
3055 session = openSession();
3056
3057 SocialRelation[] array = new SocialRelationImpl[3];
3058
3059 array[0] = getByC_T_PrevAndNext(session, socialRelation, companyId,
3060 type, orderByComparator, true);
3061
3062 array[1] = socialRelation;
3063
3064 array[2] = getByC_T_PrevAndNext(session, socialRelation, companyId,
3065 type, orderByComparator, false);
3066
3067 return array;
3068 }
3069 catch (Exception e) {
3070 throw processException(e);
3071 }
3072 finally {
3073 closeSession(session);
3074 }
3075 }
3076
3077 protected SocialRelation getByC_T_PrevAndNext(Session session,
3078 SocialRelation socialRelation, long companyId, int type,
3079 OrderByComparator orderByComparator, boolean previous) {
3080 StringBundler query = null;
3081
3082 if (orderByComparator != null) {
3083 query = new StringBundler(6 +
3084 (orderByComparator.getOrderByFields().length * 6));
3085 }
3086 else {
3087 query = new StringBundler(3);
3088 }
3089
3090 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
3091
3092 query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
3093
3094 query.append(_FINDER_COLUMN_C_T_TYPE_2);
3095
3096 if (orderByComparator != null) {
3097 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3098
3099 if (orderByConditionFields.length > 0) {
3100 query.append(WHERE_AND);
3101 }
3102
3103 for (int i = 0; i < orderByConditionFields.length; i++) {
3104 query.append(_ORDER_BY_ENTITY_ALIAS);
3105 query.append(orderByConditionFields[i]);
3106
3107 if ((i + 1) < orderByConditionFields.length) {
3108 if (orderByComparator.isAscending() ^ previous) {
3109 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3110 }
3111 else {
3112 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3113 }
3114 }
3115 else {
3116 if (orderByComparator.isAscending() ^ previous) {
3117 query.append(WHERE_GREATER_THAN);
3118 }
3119 else {
3120 query.append(WHERE_LESSER_THAN);
3121 }
3122 }
3123 }
3124
3125 query.append(ORDER_BY_CLAUSE);
3126
3127 String[] orderByFields = orderByComparator.getOrderByFields();
3128
3129 for (int i = 0; i < orderByFields.length; i++) {
3130 query.append(_ORDER_BY_ENTITY_ALIAS);
3131 query.append(orderByFields[i]);
3132
3133 if ((i + 1) < orderByFields.length) {
3134 if (orderByComparator.isAscending() ^ previous) {
3135 query.append(ORDER_BY_ASC_HAS_NEXT);
3136 }
3137 else {
3138 query.append(ORDER_BY_DESC_HAS_NEXT);
3139 }
3140 }
3141 else {
3142 if (orderByComparator.isAscending() ^ previous) {
3143 query.append(ORDER_BY_ASC);
3144 }
3145 else {
3146 query.append(ORDER_BY_DESC);
3147 }
3148 }
3149 }
3150 }
3151
3152 String sql = query.toString();
3153
3154 Query q = session.createQuery(sql);
3155
3156 q.setFirstResult(0);
3157 q.setMaxResults(2);
3158
3159 QueryPos qPos = QueryPos.getInstance(q);
3160
3161 qPos.add(companyId);
3162
3163 qPos.add(type);
3164
3165 if (orderByComparator != null) {
3166 Object[] values = orderByComparator.getOrderByConditionValues(socialRelation);
3167
3168 for (Object value : values) {
3169 qPos.add(value);
3170 }
3171 }
3172
3173 List<SocialRelation> list = q.list();
3174
3175 if (list.size() == 2) {
3176 return list.get(1);
3177 }
3178 else {
3179 return null;
3180 }
3181 }
3182
3183
3191 public List<SocialRelation> findByU1_U2(long userId1, long userId2)
3192 throws SystemException {
3193 return findByU1_U2(userId1, userId2, QueryUtil.ALL_POS,
3194 QueryUtil.ALL_POS, null);
3195 }
3196
3197
3211 public List<SocialRelation> findByU1_U2(long userId1, long userId2,
3212 int start, int end) throws SystemException {
3213 return findByU1_U2(userId1, userId2, start, end, null);
3214 }
3215
3216
3231 public List<SocialRelation> findByU1_U2(long userId1, long userId2,
3232 int start, int end, OrderByComparator orderByComparator)
3233 throws SystemException {
3234 FinderPath finderPath = null;
3235 Object[] finderArgs = null;
3236
3237 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3238 (orderByComparator == null)) {
3239 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U1_U2;
3240 finderArgs = new Object[] { userId1, userId2 };
3241 }
3242 else {
3243 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U1_U2;
3244 finderArgs = new Object[] {
3245 userId1, userId2,
3246
3247 start, end, orderByComparator
3248 };
3249 }
3250
3251 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(finderPath,
3252 finderArgs, this);
3253
3254 if ((list != null) && !list.isEmpty()) {
3255 for (SocialRelation socialRelation : list) {
3256 if ((userId1 != socialRelation.getUserId1()) ||
3257 (userId2 != socialRelation.getUserId2())) {
3258 list = null;
3259
3260 break;
3261 }
3262 }
3263 }
3264
3265 if (list == null) {
3266 StringBundler query = null;
3267
3268 if (orderByComparator != null) {
3269 query = new StringBundler(4 +
3270 (orderByComparator.getOrderByFields().length * 3));
3271 }
3272 else {
3273 query = new StringBundler(3);
3274 }
3275
3276 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
3277
3278 query.append(_FINDER_COLUMN_U1_U2_USERID1_2);
3279
3280 query.append(_FINDER_COLUMN_U1_U2_USERID2_2);
3281
3282 if (orderByComparator != null) {
3283 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3284 orderByComparator);
3285 }
3286
3287 String sql = query.toString();
3288
3289 Session session = null;
3290
3291 try {
3292 session = openSession();
3293
3294 Query q = session.createQuery(sql);
3295
3296 QueryPos qPos = QueryPos.getInstance(q);
3297
3298 qPos.add(userId1);
3299
3300 qPos.add(userId2);
3301
3302 list = (List<SocialRelation>)QueryUtil.list(q, getDialect(),
3303 start, end);
3304 }
3305 catch (Exception e) {
3306 throw processException(e);
3307 }
3308 finally {
3309 if (list == null) {
3310 FinderCacheUtil.removeResult(finderPath, finderArgs);
3311 }
3312 else {
3313 cacheResult(list);
3314
3315 FinderCacheUtil.putResult(finderPath, finderArgs, list);
3316 }
3317
3318 closeSession(session);
3319 }
3320 }
3321
3322 return list;
3323 }
3324
3325
3335 public SocialRelation findByU1_U2_First(long userId1, long userId2,
3336 OrderByComparator orderByComparator)
3337 throws NoSuchRelationException, SystemException {
3338 SocialRelation socialRelation = fetchByU1_U2_First(userId1, userId2,
3339 orderByComparator);
3340
3341 if (socialRelation != null) {
3342 return socialRelation;
3343 }
3344
3345 StringBundler msg = new StringBundler(6);
3346
3347 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3348
3349 msg.append("userId1=");
3350 msg.append(userId1);
3351
3352 msg.append(", userId2=");
3353 msg.append(userId2);
3354
3355 msg.append(StringPool.CLOSE_CURLY_BRACE);
3356
3357 throw new NoSuchRelationException(msg.toString());
3358 }
3359
3360
3369 public SocialRelation fetchByU1_U2_First(long userId1, long userId2,
3370 OrderByComparator orderByComparator) throws SystemException {
3371 List<SocialRelation> list = findByU1_U2(userId1, userId2, 0, 1,
3372 orderByComparator);
3373
3374 if (!list.isEmpty()) {
3375 return list.get(0);
3376 }
3377
3378 return null;
3379 }
3380
3381
3391 public SocialRelation findByU1_U2_Last(long userId1, long userId2,
3392 OrderByComparator orderByComparator)
3393 throws NoSuchRelationException, SystemException {
3394 SocialRelation socialRelation = fetchByU1_U2_Last(userId1, userId2,
3395 orderByComparator);
3396
3397 if (socialRelation != null) {
3398 return socialRelation;
3399 }
3400
3401 StringBundler msg = new StringBundler(6);
3402
3403 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3404
3405 msg.append("userId1=");
3406 msg.append(userId1);
3407
3408 msg.append(", userId2=");
3409 msg.append(userId2);
3410
3411 msg.append(StringPool.CLOSE_CURLY_BRACE);
3412
3413 throw new NoSuchRelationException(msg.toString());
3414 }
3415
3416
3425 public SocialRelation fetchByU1_U2_Last(long userId1, long userId2,
3426 OrderByComparator orderByComparator) throws SystemException {
3427 int count = countByU1_U2(userId1, userId2);
3428
3429 List<SocialRelation> list = findByU1_U2(userId1, userId2, count - 1,
3430 count, orderByComparator);
3431
3432 if (!list.isEmpty()) {
3433 return list.get(0);
3434 }
3435
3436 return null;
3437 }
3438
3439
3450 public SocialRelation[] findByU1_U2_PrevAndNext(long relationId,
3451 long userId1, long userId2, OrderByComparator orderByComparator)
3452 throws NoSuchRelationException, SystemException {
3453 SocialRelation socialRelation = findByPrimaryKey(relationId);
3454
3455 Session session = null;
3456
3457 try {
3458 session = openSession();
3459
3460 SocialRelation[] array = new SocialRelationImpl[3];
3461
3462 array[0] = getByU1_U2_PrevAndNext(session, socialRelation, userId1,
3463 userId2, orderByComparator, true);
3464
3465 array[1] = socialRelation;
3466
3467 array[2] = getByU1_U2_PrevAndNext(session, socialRelation, userId1,
3468 userId2, orderByComparator, false);
3469
3470 return array;
3471 }
3472 catch (Exception e) {
3473 throw processException(e);
3474 }
3475 finally {
3476 closeSession(session);
3477 }
3478 }
3479
3480 protected SocialRelation getByU1_U2_PrevAndNext(Session session,
3481 SocialRelation socialRelation, long userId1, long userId2,
3482 OrderByComparator orderByComparator, boolean previous) {
3483 StringBundler query = null;
3484
3485 if (orderByComparator != null) {
3486 query = new StringBundler(6 +
3487 (orderByComparator.getOrderByFields().length * 6));
3488 }
3489 else {
3490 query = new StringBundler(3);
3491 }
3492
3493 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
3494
3495 query.append(_FINDER_COLUMN_U1_U2_USERID1_2);
3496
3497 query.append(_FINDER_COLUMN_U1_U2_USERID2_2);
3498
3499 if (orderByComparator != null) {
3500 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3501
3502 if (orderByConditionFields.length > 0) {
3503 query.append(WHERE_AND);
3504 }
3505
3506 for (int i = 0; i < orderByConditionFields.length; i++) {
3507 query.append(_ORDER_BY_ENTITY_ALIAS);
3508 query.append(orderByConditionFields[i]);
3509
3510 if ((i + 1) < orderByConditionFields.length) {
3511 if (orderByComparator.isAscending() ^ previous) {
3512 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3513 }
3514 else {
3515 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3516 }
3517 }
3518 else {
3519 if (orderByComparator.isAscending() ^ previous) {
3520 query.append(WHERE_GREATER_THAN);
3521 }
3522 else {
3523 query.append(WHERE_LESSER_THAN);
3524 }
3525 }
3526 }
3527
3528 query.append(ORDER_BY_CLAUSE);
3529
3530 String[] orderByFields = orderByComparator.getOrderByFields();
3531
3532 for (int i = 0; i < orderByFields.length; i++) {
3533 query.append(_ORDER_BY_ENTITY_ALIAS);
3534 query.append(orderByFields[i]);
3535
3536 if ((i + 1) < orderByFields.length) {
3537 if (orderByComparator.isAscending() ^ previous) {
3538 query.append(ORDER_BY_ASC_HAS_NEXT);
3539 }
3540 else {
3541 query.append(ORDER_BY_DESC_HAS_NEXT);
3542 }
3543 }
3544 else {
3545 if (orderByComparator.isAscending() ^ previous) {
3546 query.append(ORDER_BY_ASC);
3547 }
3548 else {
3549 query.append(ORDER_BY_DESC);
3550 }
3551 }
3552 }
3553 }
3554
3555 String sql = query.toString();
3556
3557 Query q = session.createQuery(sql);
3558
3559 q.setFirstResult(0);
3560 q.setMaxResults(2);
3561
3562 QueryPos qPos = QueryPos.getInstance(q);
3563
3564 qPos.add(userId1);
3565
3566 qPos.add(userId2);
3567
3568 if (orderByComparator != null) {
3569 Object[] values = orderByComparator.getOrderByConditionValues(socialRelation);
3570
3571 for (Object value : values) {
3572 qPos.add(value);
3573 }
3574 }
3575
3576 List<SocialRelation> list = q.list();
3577
3578 if (list.size() == 2) {
3579 return list.get(1);
3580 }
3581 else {
3582 return null;
3583 }
3584 }
3585
3586
3594 public List<SocialRelation> findByU1_T(long userId1, int type)
3595 throws SystemException {
3596 return findByU1_T(userId1, type, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
3597 null);
3598 }
3599
3600
3614 public List<SocialRelation> findByU1_T(long userId1, int type, int start,
3615 int end) throws SystemException {
3616 return findByU1_T(userId1, type, start, end, null);
3617 }
3618
3619
3634 public List<SocialRelation> findByU1_T(long userId1, int type, int start,
3635 int end, OrderByComparator orderByComparator) throws SystemException {
3636 FinderPath finderPath = null;
3637 Object[] finderArgs = null;
3638
3639 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3640 (orderByComparator == null)) {
3641 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U1_T;
3642 finderArgs = new Object[] { userId1, type };
3643 }
3644 else {
3645 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U1_T;
3646 finderArgs = new Object[] {
3647 userId1, type,
3648
3649 start, end, orderByComparator
3650 };
3651 }
3652
3653 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(finderPath,
3654 finderArgs, this);
3655
3656 if ((list != null) && !list.isEmpty()) {
3657 for (SocialRelation socialRelation : list) {
3658 if ((userId1 != socialRelation.getUserId1()) ||
3659 (type != socialRelation.getType())) {
3660 list = null;
3661
3662 break;
3663 }
3664 }
3665 }
3666
3667 if (list == null) {
3668 StringBundler query = null;
3669
3670 if (orderByComparator != null) {
3671 query = new StringBundler(4 +
3672 (orderByComparator.getOrderByFields().length * 3));
3673 }
3674 else {
3675 query = new StringBundler(3);
3676 }
3677
3678 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
3679
3680 query.append(_FINDER_COLUMN_U1_T_USERID1_2);
3681
3682 query.append(_FINDER_COLUMN_U1_T_TYPE_2);
3683
3684 if (orderByComparator != null) {
3685 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3686 orderByComparator);
3687 }
3688
3689 String sql = query.toString();
3690
3691 Session session = null;
3692
3693 try {
3694 session = openSession();
3695
3696 Query q = session.createQuery(sql);
3697
3698 QueryPos qPos = QueryPos.getInstance(q);
3699
3700 qPos.add(userId1);
3701
3702 qPos.add(type);
3703
3704 list = (List<SocialRelation>)QueryUtil.list(q, getDialect(),
3705 start, end);
3706 }
3707 catch (Exception e) {
3708 throw processException(e);
3709 }
3710 finally {
3711 if (list == null) {
3712 FinderCacheUtil.removeResult(finderPath, finderArgs);
3713 }
3714 else {
3715 cacheResult(list);
3716
3717 FinderCacheUtil.putResult(finderPath, finderArgs, list);
3718 }
3719
3720 closeSession(session);
3721 }
3722 }
3723
3724 return list;
3725 }
3726
3727
3737 public SocialRelation findByU1_T_First(long userId1, int type,
3738 OrderByComparator orderByComparator)
3739 throws NoSuchRelationException, SystemException {
3740 SocialRelation socialRelation = fetchByU1_T_First(userId1, type,
3741 orderByComparator);
3742
3743 if (socialRelation != null) {
3744 return socialRelation;
3745 }
3746
3747 StringBundler msg = new StringBundler(6);
3748
3749 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3750
3751 msg.append("userId1=");
3752 msg.append(userId1);
3753
3754 msg.append(", type=");
3755 msg.append(type);
3756
3757 msg.append(StringPool.CLOSE_CURLY_BRACE);
3758
3759 throw new NoSuchRelationException(msg.toString());
3760 }
3761
3762
3771 public SocialRelation fetchByU1_T_First(long userId1, int type,
3772 OrderByComparator orderByComparator) throws SystemException {
3773 List<SocialRelation> list = findByU1_T(userId1, type, 0, 1,
3774 orderByComparator);
3775
3776 if (!list.isEmpty()) {
3777 return list.get(0);
3778 }
3779
3780 return null;
3781 }
3782
3783
3793 public SocialRelation findByU1_T_Last(long userId1, int type,
3794 OrderByComparator orderByComparator)
3795 throws NoSuchRelationException, SystemException {
3796 SocialRelation socialRelation = fetchByU1_T_Last(userId1, type,
3797 orderByComparator);
3798
3799 if (socialRelation != null) {
3800 return socialRelation;
3801 }
3802
3803 StringBundler msg = new StringBundler(6);
3804
3805 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3806
3807 msg.append("userId1=");
3808 msg.append(userId1);
3809
3810 msg.append(", type=");
3811 msg.append(type);
3812
3813 msg.append(StringPool.CLOSE_CURLY_BRACE);
3814
3815 throw new NoSuchRelationException(msg.toString());
3816 }
3817
3818
3827 public SocialRelation fetchByU1_T_Last(long userId1, int type,
3828 OrderByComparator orderByComparator) throws SystemException {
3829 int count = countByU1_T(userId1, type);
3830
3831 List<SocialRelation> list = findByU1_T(userId1, type, count - 1, count,
3832 orderByComparator);
3833
3834 if (!list.isEmpty()) {
3835 return list.get(0);
3836 }
3837
3838 return null;
3839 }
3840
3841
3852 public SocialRelation[] findByU1_T_PrevAndNext(long relationId,
3853 long userId1, int type, OrderByComparator orderByComparator)
3854 throws NoSuchRelationException, SystemException {
3855 SocialRelation socialRelation = findByPrimaryKey(relationId);
3856
3857 Session session = null;
3858
3859 try {
3860 session = openSession();
3861
3862 SocialRelation[] array = new SocialRelationImpl[3];
3863
3864 array[0] = getByU1_T_PrevAndNext(session, socialRelation, userId1,
3865 type, orderByComparator, true);
3866
3867 array[1] = socialRelation;
3868
3869 array[2] = getByU1_T_PrevAndNext(session, socialRelation, userId1,
3870 type, orderByComparator, false);
3871
3872 return array;
3873 }
3874 catch (Exception e) {
3875 throw processException(e);
3876 }
3877 finally {
3878 closeSession(session);
3879 }
3880 }
3881
3882 protected SocialRelation getByU1_T_PrevAndNext(Session session,
3883 SocialRelation socialRelation, long userId1, int type,
3884 OrderByComparator orderByComparator, boolean previous) {
3885 StringBundler query = null;
3886
3887 if (orderByComparator != null) {
3888 query = new StringBundler(6 +
3889 (orderByComparator.getOrderByFields().length * 6));
3890 }
3891 else {
3892 query = new StringBundler(3);
3893 }
3894
3895 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
3896
3897 query.append(_FINDER_COLUMN_U1_T_USERID1_2);
3898
3899 query.append(_FINDER_COLUMN_U1_T_TYPE_2);
3900
3901 if (orderByComparator != null) {
3902 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3903
3904 if (orderByConditionFields.length > 0) {
3905 query.append(WHERE_AND);
3906 }
3907
3908 for (int i = 0; i < orderByConditionFields.length; i++) {
3909 query.append(_ORDER_BY_ENTITY_ALIAS);
3910 query.append(orderByConditionFields[i]);
3911
3912 if ((i + 1) < orderByConditionFields.length) {
3913 if (orderByComparator.isAscending() ^ previous) {
3914 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3915 }
3916 else {
3917 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3918 }
3919 }
3920 else {
3921 if (orderByComparator.isAscending() ^ previous) {
3922 query.append(WHERE_GREATER_THAN);
3923 }
3924 else {
3925 query.append(WHERE_LESSER_THAN);
3926 }
3927 }
3928 }
3929
3930 query.append(ORDER_BY_CLAUSE);
3931
3932 String[] orderByFields = orderByComparator.getOrderByFields();
3933
3934 for (int i = 0; i < orderByFields.length; i++) {
3935 query.append(_ORDER_BY_ENTITY_ALIAS);
3936 query.append(orderByFields[i]);
3937
3938 if ((i + 1) < orderByFields.length) {
3939 if (orderByComparator.isAscending() ^ previous) {
3940 query.append(ORDER_BY_ASC_HAS_NEXT);
3941 }
3942 else {
3943 query.append(ORDER_BY_DESC_HAS_NEXT);
3944 }
3945 }
3946 else {
3947 if (orderByComparator.isAscending() ^ previous) {
3948 query.append(ORDER_BY_ASC);
3949 }
3950 else {
3951 query.append(ORDER_BY_DESC);
3952 }
3953 }
3954 }
3955 }
3956
3957 String sql = query.toString();
3958
3959 Query q = session.createQuery(sql);
3960
3961 q.setFirstResult(0);
3962 q.setMaxResults(2);
3963
3964 QueryPos qPos = QueryPos.getInstance(q);
3965
3966 qPos.add(userId1);
3967
3968 qPos.add(type);
3969
3970 if (orderByComparator != null) {
3971 Object[] values = orderByComparator.getOrderByConditionValues(socialRelation);
3972
3973 for (Object value : values) {
3974 qPos.add(value);
3975 }
3976 }
3977
3978 List<SocialRelation> list = q.list();
3979
3980 if (list.size() == 2) {
3981 return list.get(1);
3982 }
3983 else {
3984 return null;
3985 }
3986 }
3987
3988
3996 public List<SocialRelation> findByU2_T(long userId2, int type)
3997 throws SystemException {
3998 return findByU2_T(userId2, type, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
3999 null);
4000 }
4001
4002
4016 public List<SocialRelation> findByU2_T(long userId2, int type, int start,
4017 int end) throws SystemException {
4018 return findByU2_T(userId2, type, start, end, null);
4019 }
4020
4021
4036 public List<SocialRelation> findByU2_T(long userId2, int type, int start,
4037 int end, OrderByComparator orderByComparator) throws SystemException {
4038 FinderPath finderPath = null;
4039 Object[] finderArgs = null;
4040
4041 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4042 (orderByComparator == null)) {
4043 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U2_T;
4044 finderArgs = new Object[] { userId2, type };
4045 }
4046 else {
4047 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U2_T;
4048 finderArgs = new Object[] {
4049 userId2, type,
4050
4051 start, end, orderByComparator
4052 };
4053 }
4054
4055 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(finderPath,
4056 finderArgs, this);
4057
4058 if ((list != null) && !list.isEmpty()) {
4059 for (SocialRelation socialRelation : list) {
4060 if ((userId2 != socialRelation.getUserId2()) ||
4061 (type != socialRelation.getType())) {
4062 list = null;
4063
4064 break;
4065 }
4066 }
4067 }
4068
4069 if (list == null) {
4070 StringBundler query = null;
4071
4072 if (orderByComparator != null) {
4073 query = new StringBundler(4 +
4074 (orderByComparator.getOrderByFields().length * 3));
4075 }
4076 else {
4077 query = new StringBundler(3);
4078 }
4079
4080 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
4081
4082 query.append(_FINDER_COLUMN_U2_T_USERID2_2);
4083
4084 query.append(_FINDER_COLUMN_U2_T_TYPE_2);
4085
4086 if (orderByComparator != null) {
4087 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4088 orderByComparator);
4089 }
4090
4091 String sql = query.toString();
4092
4093 Session session = null;
4094
4095 try {
4096 session = openSession();
4097
4098 Query q = session.createQuery(sql);
4099
4100 QueryPos qPos = QueryPos.getInstance(q);
4101
4102 qPos.add(userId2);
4103
4104 qPos.add(type);
4105
4106 list = (List<SocialRelation>)QueryUtil.list(q, getDialect(),
4107 start, end);
4108 }
4109 catch (Exception e) {
4110 throw processException(e);
4111 }
4112 finally {
4113 if (list == null) {
4114 FinderCacheUtil.removeResult(finderPath, finderArgs);
4115 }
4116 else {
4117 cacheResult(list);
4118
4119 FinderCacheUtil.putResult(finderPath, finderArgs, list);
4120 }
4121
4122 closeSession(session);
4123 }
4124 }
4125
4126 return list;
4127 }
4128
4129
4139 public SocialRelation findByU2_T_First(long userId2, int type,
4140 OrderByComparator orderByComparator)
4141 throws NoSuchRelationException, SystemException {
4142 SocialRelation socialRelation = fetchByU2_T_First(userId2, type,
4143 orderByComparator);
4144
4145 if (socialRelation != null) {
4146 return socialRelation;
4147 }
4148
4149 StringBundler msg = new StringBundler(6);
4150
4151 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4152
4153 msg.append("userId2=");
4154 msg.append(userId2);
4155
4156 msg.append(", type=");
4157 msg.append(type);
4158
4159 msg.append(StringPool.CLOSE_CURLY_BRACE);
4160
4161 throw new NoSuchRelationException(msg.toString());
4162 }
4163
4164
4173 public SocialRelation fetchByU2_T_First(long userId2, int type,
4174 OrderByComparator orderByComparator) throws SystemException {
4175 List<SocialRelation> list = findByU2_T(userId2, type, 0, 1,
4176 orderByComparator);
4177
4178 if (!list.isEmpty()) {
4179 return list.get(0);
4180 }
4181
4182 return null;
4183 }
4184
4185
4195 public SocialRelation findByU2_T_Last(long userId2, int type,
4196 OrderByComparator orderByComparator)
4197 throws NoSuchRelationException, SystemException {
4198 SocialRelation socialRelation = fetchByU2_T_Last(userId2, type,
4199 orderByComparator);
4200
4201 if (socialRelation != null) {
4202 return socialRelation;
4203 }
4204
4205 StringBundler msg = new StringBundler(6);
4206
4207 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4208
4209 msg.append("userId2=");
4210 msg.append(userId2);
4211
4212 msg.append(", type=");
4213 msg.append(type);
4214
4215 msg.append(StringPool.CLOSE_CURLY_BRACE);
4216
4217 throw new NoSuchRelationException(msg.toString());
4218 }
4219
4220
4229 public SocialRelation fetchByU2_T_Last(long userId2, int type,
4230 OrderByComparator orderByComparator) throws SystemException {
4231 int count = countByU2_T(userId2, type);
4232
4233 List<SocialRelation> list = findByU2_T(userId2, type, count - 1, count,
4234 orderByComparator);
4235
4236 if (!list.isEmpty()) {
4237 return list.get(0);
4238 }
4239
4240 return null;
4241 }
4242
4243
4254 public SocialRelation[] findByU2_T_PrevAndNext(long relationId,
4255 long userId2, int type, OrderByComparator orderByComparator)
4256 throws NoSuchRelationException, SystemException {
4257 SocialRelation socialRelation = findByPrimaryKey(relationId);
4258
4259 Session session = null;
4260
4261 try {
4262 session = openSession();
4263
4264 SocialRelation[] array = new SocialRelationImpl[3];
4265
4266 array[0] = getByU2_T_PrevAndNext(session, socialRelation, userId2,
4267 type, orderByComparator, true);
4268
4269 array[1] = socialRelation;
4270
4271 array[2] = getByU2_T_PrevAndNext(session, socialRelation, userId2,
4272 type, orderByComparator, false);
4273
4274 return array;
4275 }
4276 catch (Exception e) {
4277 throw processException(e);
4278 }
4279 finally {
4280 closeSession(session);
4281 }
4282 }
4283
4284 protected SocialRelation getByU2_T_PrevAndNext(Session session,
4285 SocialRelation socialRelation, long userId2, int type,
4286 OrderByComparator orderByComparator, boolean previous) {
4287 StringBundler query = null;
4288
4289 if (orderByComparator != null) {
4290 query = new StringBundler(6 +
4291 (orderByComparator.getOrderByFields().length * 6));
4292 }
4293 else {
4294 query = new StringBundler(3);
4295 }
4296
4297 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
4298
4299 query.append(_FINDER_COLUMN_U2_T_USERID2_2);
4300
4301 query.append(_FINDER_COLUMN_U2_T_TYPE_2);
4302
4303 if (orderByComparator != null) {
4304 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4305
4306 if (orderByConditionFields.length > 0) {
4307 query.append(WHERE_AND);
4308 }
4309
4310 for (int i = 0; i < orderByConditionFields.length; i++) {
4311 query.append(_ORDER_BY_ENTITY_ALIAS);
4312 query.append(orderByConditionFields[i]);
4313
4314 if ((i + 1) < orderByConditionFields.length) {
4315 if (orderByComparator.isAscending() ^ previous) {
4316 query.append(WHERE_GREATER_THAN_HAS_NEXT);
4317 }
4318 else {
4319 query.append(WHERE_LESSER_THAN_HAS_NEXT);
4320 }
4321 }
4322 else {
4323 if (orderByComparator.isAscending() ^ previous) {
4324 query.append(WHERE_GREATER_THAN);
4325 }
4326 else {
4327 query.append(WHERE_LESSER_THAN);
4328 }
4329 }
4330 }
4331
4332 query.append(ORDER_BY_CLAUSE);
4333
4334 String[] orderByFields = orderByComparator.getOrderByFields();
4335
4336 for (int i = 0; i < orderByFields.length; i++) {
4337 query.append(_ORDER_BY_ENTITY_ALIAS);
4338 query.append(orderByFields[i]);
4339
4340 if ((i + 1) < orderByFields.length) {
4341 if (orderByComparator.isAscending() ^ previous) {
4342 query.append(ORDER_BY_ASC_HAS_NEXT);
4343 }
4344 else {
4345 query.append(ORDER_BY_DESC_HAS_NEXT);
4346 }
4347 }
4348 else {
4349 if (orderByComparator.isAscending() ^ previous) {
4350 query.append(ORDER_BY_ASC);
4351 }
4352 else {
4353 query.append(ORDER_BY_DESC);
4354 }
4355 }
4356 }
4357 }
4358
4359 String sql = query.toString();
4360
4361 Query q = session.createQuery(sql);
4362
4363 q.setFirstResult(0);
4364 q.setMaxResults(2);
4365
4366 QueryPos qPos = QueryPos.getInstance(q);
4367
4368 qPos.add(userId2);
4369
4370 qPos.add(type);
4371
4372 if (orderByComparator != null) {
4373 Object[] values = orderByComparator.getOrderByConditionValues(socialRelation);
4374
4375 for (Object value : values) {
4376 qPos.add(value);
4377 }
4378 }
4379
4380 List<SocialRelation> list = q.list();
4381
4382 if (list.size() == 2) {
4383 return list.get(1);
4384 }
4385 else {
4386 return null;
4387 }
4388 }
4389
4390
4400 public SocialRelation findByU1_U2_T(long userId1, long userId2, int type)
4401 throws NoSuchRelationException, SystemException {
4402 SocialRelation socialRelation = fetchByU1_U2_T(userId1, userId2, type);
4403
4404 if (socialRelation == null) {
4405 StringBundler msg = new StringBundler(8);
4406
4407 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4408
4409 msg.append("userId1=");
4410 msg.append(userId1);
4411
4412 msg.append(", userId2=");
4413 msg.append(userId2);
4414
4415 msg.append(", type=");
4416 msg.append(type);
4417
4418 msg.append(StringPool.CLOSE_CURLY_BRACE);
4419
4420 if (_log.isWarnEnabled()) {
4421 _log.warn(msg.toString());
4422 }
4423
4424 throw new NoSuchRelationException(msg.toString());
4425 }
4426
4427 return socialRelation;
4428 }
4429
4430
4439 public SocialRelation fetchByU1_U2_T(long userId1, long userId2, int type)
4440 throws SystemException {
4441 return fetchByU1_U2_T(userId1, userId2, type, true);
4442 }
4443
4444
4454 public SocialRelation fetchByU1_U2_T(long userId1, long userId2, int type,
4455 boolean retrieveFromCache) throws SystemException {
4456 Object[] finderArgs = new Object[] { userId1, userId2, type };
4457
4458 Object result = null;
4459
4460 if (retrieveFromCache) {
4461 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_U1_U2_T,
4462 finderArgs, this);
4463 }
4464
4465 if (result instanceof SocialRelation) {
4466 SocialRelation socialRelation = (SocialRelation)result;
4467
4468 if ((userId1 != socialRelation.getUserId1()) ||
4469 (userId2 != socialRelation.getUserId2()) ||
4470 (type != socialRelation.getType())) {
4471 result = null;
4472 }
4473 }
4474
4475 if (result == null) {
4476 StringBundler query = new StringBundler(4);
4477
4478 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
4479
4480 query.append(_FINDER_COLUMN_U1_U2_T_USERID1_2);
4481
4482 query.append(_FINDER_COLUMN_U1_U2_T_USERID2_2);
4483
4484 query.append(_FINDER_COLUMN_U1_U2_T_TYPE_2);
4485
4486 String sql = query.toString();
4487
4488 Session session = null;
4489
4490 try {
4491 session = openSession();
4492
4493 Query q = session.createQuery(sql);
4494
4495 QueryPos qPos = QueryPos.getInstance(q);
4496
4497 qPos.add(userId1);
4498
4499 qPos.add(userId2);
4500
4501 qPos.add(type);
4502
4503 List<SocialRelation> list = q.list();
4504
4505 result = list;
4506
4507 SocialRelation socialRelation = null;
4508
4509 if (list.isEmpty()) {
4510 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U1_U2_T,
4511 finderArgs, list);
4512 }
4513 else {
4514 socialRelation = list.get(0);
4515
4516 cacheResult(socialRelation);
4517
4518 if ((socialRelation.getUserId1() != userId1) ||
4519 (socialRelation.getUserId2() != userId2) ||
4520 (socialRelation.getType() != type)) {
4521 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U1_U2_T,
4522 finderArgs, socialRelation);
4523 }
4524 }
4525
4526 return socialRelation;
4527 }
4528 catch (Exception e) {
4529 throw processException(e);
4530 }
4531 finally {
4532 if (result == null) {
4533 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U1_U2_T,
4534 finderArgs);
4535 }
4536
4537 closeSession(session);
4538 }
4539 }
4540 else {
4541 if (result instanceof List<?>) {
4542 return null;
4543 }
4544 else {
4545 return (SocialRelation)result;
4546 }
4547 }
4548 }
4549
4550
4556 public List<SocialRelation> findAll() throws SystemException {
4557 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
4558 }
4559
4560
4572 public List<SocialRelation> findAll(int start, int end)
4573 throws SystemException {
4574 return findAll(start, end, null);
4575 }
4576
4577
4590 public List<SocialRelation> findAll(int start, int end,
4591 OrderByComparator orderByComparator) throws SystemException {
4592 FinderPath finderPath = null;
4593 Object[] finderArgs = new Object[] { start, end, orderByComparator };
4594
4595 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4596 (orderByComparator == null)) {
4597 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
4598 finderArgs = FINDER_ARGS_EMPTY;
4599 }
4600 else {
4601 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
4602 finderArgs = new Object[] { start, end, orderByComparator };
4603 }
4604
4605 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(finderPath,
4606 finderArgs, this);
4607
4608 if (list == null) {
4609 StringBundler query = null;
4610 String sql = null;
4611
4612 if (orderByComparator != null) {
4613 query = new StringBundler(2 +
4614 (orderByComparator.getOrderByFields().length * 3));
4615
4616 query.append(_SQL_SELECT_SOCIALRELATION);
4617
4618 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4619 orderByComparator);
4620
4621 sql = query.toString();
4622 }
4623 else {
4624 sql = _SQL_SELECT_SOCIALRELATION;
4625 }
4626
4627 Session session = null;
4628
4629 try {
4630 session = openSession();
4631
4632 Query q = session.createQuery(sql);
4633
4634 if (orderByComparator == null) {
4635 list = (List<SocialRelation>)QueryUtil.list(q,
4636 getDialect(), start, end, false);
4637
4638 Collections.sort(list);
4639 }
4640 else {
4641 list = (List<SocialRelation>)QueryUtil.list(q,
4642 getDialect(), start, end);
4643 }
4644 }
4645 catch (Exception e) {
4646 throw processException(e);
4647 }
4648 finally {
4649 if (list == null) {
4650 FinderCacheUtil.removeResult(finderPath, finderArgs);
4651 }
4652 else {
4653 cacheResult(list);
4654
4655 FinderCacheUtil.putResult(finderPath, finderArgs, list);
4656 }
4657
4658 closeSession(session);
4659 }
4660 }
4661
4662 return list;
4663 }
4664
4665
4671 public void removeByUuid(String uuid) throws SystemException {
4672 for (SocialRelation socialRelation : findByUuid(uuid)) {
4673 remove(socialRelation);
4674 }
4675 }
4676
4677
4683 public void removeByCompanyId(long companyId) throws SystemException {
4684 for (SocialRelation socialRelation : findByCompanyId(companyId)) {
4685 remove(socialRelation);
4686 }
4687 }
4688
4689
4695 public void removeByUserId1(long userId1) throws SystemException {
4696 for (SocialRelation socialRelation : findByUserId1(userId1)) {
4697 remove(socialRelation);
4698 }
4699 }
4700
4701
4707 public void removeByUserId2(long userId2) throws SystemException {
4708 for (SocialRelation socialRelation : findByUserId2(userId2)) {
4709 remove(socialRelation);
4710 }
4711 }
4712
4713
4719 public void removeByType(int type) throws SystemException {
4720 for (SocialRelation socialRelation : findByType(type)) {
4721 remove(socialRelation);
4722 }
4723 }
4724
4725
4732 public void removeByC_T(long companyId, int type) throws SystemException {
4733 for (SocialRelation socialRelation : findByC_T(companyId, type)) {
4734 remove(socialRelation);
4735 }
4736 }
4737
4738
4745 public void removeByU1_U2(long userId1, long userId2)
4746 throws SystemException {
4747 for (SocialRelation socialRelation : findByU1_U2(userId1, userId2)) {
4748 remove(socialRelation);
4749 }
4750 }
4751
4752
4759 public void removeByU1_T(long userId1, int type) throws SystemException {
4760 for (SocialRelation socialRelation : findByU1_T(userId1, type)) {
4761 remove(socialRelation);
4762 }
4763 }
4764
4765
4772 public void removeByU2_T(long userId2, int type) throws SystemException {
4773 for (SocialRelation socialRelation : findByU2_T(userId2, type)) {
4774 remove(socialRelation);
4775 }
4776 }
4777
4778
4787 public SocialRelation removeByU1_U2_T(long userId1, long userId2, int type)
4788 throws NoSuchRelationException, SystemException {
4789 SocialRelation socialRelation = findByU1_U2_T(userId1, userId2, type);
4790
4791 return remove(socialRelation);
4792 }
4793
4794
4799 public void removeAll() throws SystemException {
4800 for (SocialRelation socialRelation : findAll()) {
4801 remove(socialRelation);
4802 }
4803 }
4804
4805
4812 public int countByUuid(String uuid) throws SystemException {
4813 Object[] finderArgs = new Object[] { uuid };
4814
4815 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
4816 finderArgs, this);
4817
4818 if (count == null) {
4819 StringBundler query = new StringBundler(2);
4820
4821 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
4822
4823 if (uuid == null) {
4824 query.append(_FINDER_COLUMN_UUID_UUID_1);
4825 }
4826 else {
4827 if (uuid.equals(StringPool.BLANK)) {
4828 query.append(_FINDER_COLUMN_UUID_UUID_3);
4829 }
4830 else {
4831 query.append(_FINDER_COLUMN_UUID_UUID_2);
4832 }
4833 }
4834
4835 String sql = query.toString();
4836
4837 Session session = null;
4838
4839 try {
4840 session = openSession();
4841
4842 Query q = session.createQuery(sql);
4843
4844 QueryPos qPos = QueryPos.getInstance(q);
4845
4846 if (uuid != null) {
4847 qPos.add(uuid);
4848 }
4849
4850 count = (Long)q.uniqueResult();
4851 }
4852 catch (Exception e) {
4853 throw processException(e);
4854 }
4855 finally {
4856 if (count == null) {
4857 count = Long.valueOf(0);
4858 }
4859
4860 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
4861 finderArgs, count);
4862
4863 closeSession(session);
4864 }
4865 }
4866
4867 return count.intValue();
4868 }
4869
4870
4877 public int countByCompanyId(long companyId) throws SystemException {
4878 Object[] finderArgs = new Object[] { companyId };
4879
4880 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
4881 finderArgs, this);
4882
4883 if (count == null) {
4884 StringBundler query = new StringBundler(2);
4885
4886 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
4887
4888 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
4889
4890 String sql = query.toString();
4891
4892 Session session = null;
4893
4894 try {
4895 session = openSession();
4896
4897 Query q = session.createQuery(sql);
4898
4899 QueryPos qPos = QueryPos.getInstance(q);
4900
4901 qPos.add(companyId);
4902
4903 count = (Long)q.uniqueResult();
4904 }
4905 catch (Exception e) {
4906 throw processException(e);
4907 }
4908 finally {
4909 if (count == null) {
4910 count = Long.valueOf(0);
4911 }
4912
4913 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
4914 finderArgs, count);
4915
4916 closeSession(session);
4917 }
4918 }
4919
4920 return count.intValue();
4921 }
4922
4923
4930 public int countByUserId1(long userId1) throws SystemException {
4931 Object[] finderArgs = new Object[] { userId1 };
4932
4933 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID1,
4934 finderArgs, this);
4935
4936 if (count == null) {
4937 StringBundler query = new StringBundler(2);
4938
4939 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
4940
4941 query.append(_FINDER_COLUMN_USERID1_USERID1_2);
4942
4943 String sql = query.toString();
4944
4945 Session session = null;
4946
4947 try {
4948 session = openSession();
4949
4950 Query q = session.createQuery(sql);
4951
4952 QueryPos qPos = QueryPos.getInstance(q);
4953
4954 qPos.add(userId1);
4955
4956 count = (Long)q.uniqueResult();
4957 }
4958 catch (Exception e) {
4959 throw processException(e);
4960 }
4961 finally {
4962 if (count == null) {
4963 count = Long.valueOf(0);
4964 }
4965
4966 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID1,
4967 finderArgs, count);
4968
4969 closeSession(session);
4970 }
4971 }
4972
4973 return count.intValue();
4974 }
4975
4976
4983 public int countByUserId2(long userId2) throws SystemException {
4984 Object[] finderArgs = new Object[] { userId2 };
4985
4986 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID2,
4987 finderArgs, this);
4988
4989 if (count == null) {
4990 StringBundler query = new StringBundler(2);
4991
4992 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
4993
4994 query.append(_FINDER_COLUMN_USERID2_USERID2_2);
4995
4996 String sql = query.toString();
4997
4998 Session session = null;
4999
5000 try {
5001 session = openSession();
5002
5003 Query q = session.createQuery(sql);
5004
5005 QueryPos qPos = QueryPos.getInstance(q);
5006
5007 qPos.add(userId2);
5008
5009 count = (Long)q.uniqueResult();
5010 }
5011 catch (Exception e) {
5012 throw processException(e);
5013 }
5014 finally {
5015 if (count == null) {
5016 count = Long.valueOf(0);
5017 }
5018
5019 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID2,
5020 finderArgs, count);
5021
5022 closeSession(session);
5023 }
5024 }
5025
5026 return count.intValue();
5027 }
5028
5029
5036 public int countByType(int type) throws SystemException {
5037 Object[] finderArgs = new Object[] { type };
5038
5039 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_TYPE,
5040 finderArgs, this);
5041
5042 if (count == null) {
5043 StringBundler query = new StringBundler(2);
5044
5045 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
5046
5047 query.append(_FINDER_COLUMN_TYPE_TYPE_2);
5048
5049 String sql = query.toString();
5050
5051 Session session = null;
5052
5053 try {
5054 session = openSession();
5055
5056 Query q = session.createQuery(sql);
5057
5058 QueryPos qPos = QueryPos.getInstance(q);
5059
5060 qPos.add(type);
5061
5062 count = (Long)q.uniqueResult();
5063 }
5064 catch (Exception e) {
5065 throw processException(e);
5066 }
5067 finally {
5068 if (count == null) {
5069 count = Long.valueOf(0);
5070 }
5071
5072 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_TYPE,
5073 finderArgs, count);
5074
5075 closeSession(session);
5076 }
5077 }
5078
5079 return count.intValue();
5080 }
5081
5082
5090 public int countByC_T(long companyId, int type) throws SystemException {
5091 Object[] finderArgs = new Object[] { companyId, type };
5092
5093 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_T,
5094 finderArgs, this);
5095
5096 if (count == null) {
5097 StringBundler query = new StringBundler(3);
5098
5099 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
5100
5101 query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
5102
5103 query.append(_FINDER_COLUMN_C_T_TYPE_2);
5104
5105 String sql = query.toString();
5106
5107 Session session = null;
5108
5109 try {
5110 session = openSession();
5111
5112 Query q = session.createQuery(sql);
5113
5114 QueryPos qPos = QueryPos.getInstance(q);
5115
5116 qPos.add(companyId);
5117
5118 qPos.add(type);
5119
5120 count = (Long)q.uniqueResult();
5121 }
5122 catch (Exception e) {
5123 throw processException(e);
5124 }
5125 finally {
5126 if (count == null) {
5127 count = Long.valueOf(0);
5128 }
5129
5130 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_T, finderArgs,
5131 count);
5132
5133 closeSession(session);
5134 }
5135 }
5136
5137 return count.intValue();
5138 }
5139
5140
5148 public int countByU1_U2(long userId1, long userId2)
5149 throws SystemException {
5150 Object[] finderArgs = new Object[] { userId1, userId2 };
5151
5152 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U1_U2,
5153 finderArgs, this);
5154
5155 if (count == null) {
5156 StringBundler query = new StringBundler(3);
5157
5158 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
5159
5160 query.append(_FINDER_COLUMN_U1_U2_USERID1_2);
5161
5162 query.append(_FINDER_COLUMN_U1_U2_USERID2_2);
5163
5164 String sql = query.toString();
5165
5166 Session session = null;
5167
5168 try {
5169 session = openSession();
5170
5171 Query q = session.createQuery(sql);
5172
5173 QueryPos qPos = QueryPos.getInstance(q);
5174
5175 qPos.add(userId1);
5176
5177 qPos.add(userId2);
5178
5179 count = (Long)q.uniqueResult();
5180 }
5181 catch (Exception e) {
5182 throw processException(e);
5183 }
5184 finally {
5185 if (count == null) {
5186 count = Long.valueOf(0);
5187 }
5188
5189 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U1_U2,
5190 finderArgs, count);
5191
5192 closeSession(session);
5193 }
5194 }
5195
5196 return count.intValue();
5197 }
5198
5199
5207 public int countByU1_T(long userId1, int type) throws SystemException {
5208 Object[] finderArgs = new Object[] { userId1, type };
5209
5210 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U1_T,
5211 finderArgs, this);
5212
5213 if (count == null) {
5214 StringBundler query = new StringBundler(3);
5215
5216 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
5217
5218 query.append(_FINDER_COLUMN_U1_T_USERID1_2);
5219
5220 query.append(_FINDER_COLUMN_U1_T_TYPE_2);
5221
5222 String sql = query.toString();
5223
5224 Session session = null;
5225
5226 try {
5227 session = openSession();
5228
5229 Query q = session.createQuery(sql);
5230
5231 QueryPos qPos = QueryPos.getInstance(q);
5232
5233 qPos.add(userId1);
5234
5235 qPos.add(type);
5236
5237 count = (Long)q.uniqueResult();
5238 }
5239 catch (Exception e) {
5240 throw processException(e);
5241 }
5242 finally {
5243 if (count == null) {
5244 count = Long.valueOf(0);
5245 }
5246
5247 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U1_T,
5248 finderArgs, count);
5249
5250 closeSession(session);
5251 }
5252 }
5253
5254 return count.intValue();
5255 }
5256
5257
5265 public int countByU2_T(long userId2, int type) throws SystemException {
5266 Object[] finderArgs = new Object[] { userId2, type };
5267
5268 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U2_T,
5269 finderArgs, this);
5270
5271 if (count == null) {
5272 StringBundler query = new StringBundler(3);
5273
5274 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
5275
5276 query.append(_FINDER_COLUMN_U2_T_USERID2_2);
5277
5278 query.append(_FINDER_COLUMN_U2_T_TYPE_2);
5279
5280 String sql = query.toString();
5281
5282 Session session = null;
5283
5284 try {
5285 session = openSession();
5286
5287 Query q = session.createQuery(sql);
5288
5289 QueryPos qPos = QueryPos.getInstance(q);
5290
5291 qPos.add(userId2);
5292
5293 qPos.add(type);
5294
5295 count = (Long)q.uniqueResult();
5296 }
5297 catch (Exception e) {
5298 throw processException(e);
5299 }
5300 finally {
5301 if (count == null) {
5302 count = Long.valueOf(0);
5303 }
5304
5305 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U2_T,
5306 finderArgs, count);
5307
5308 closeSession(session);
5309 }
5310 }
5311
5312 return count.intValue();
5313 }
5314
5315
5324 public int countByU1_U2_T(long userId1, long userId2, int type)
5325 throws SystemException {
5326 Object[] finderArgs = new Object[] { userId1, userId2, type };
5327
5328 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U1_U2_T,
5329 finderArgs, this);
5330
5331 if (count == null) {
5332 StringBundler query = new StringBundler(4);
5333
5334 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
5335
5336 query.append(_FINDER_COLUMN_U1_U2_T_USERID1_2);
5337
5338 query.append(_FINDER_COLUMN_U1_U2_T_USERID2_2);
5339
5340 query.append(_FINDER_COLUMN_U1_U2_T_TYPE_2);
5341
5342 String sql = query.toString();
5343
5344 Session session = null;
5345
5346 try {
5347 session = openSession();
5348
5349 Query q = session.createQuery(sql);
5350
5351 QueryPos qPos = QueryPos.getInstance(q);
5352
5353 qPos.add(userId1);
5354
5355 qPos.add(userId2);
5356
5357 qPos.add(type);
5358
5359 count = (Long)q.uniqueResult();
5360 }
5361 catch (Exception e) {
5362 throw processException(e);
5363 }
5364 finally {
5365 if (count == null) {
5366 count = Long.valueOf(0);
5367 }
5368
5369 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U1_U2_T,
5370 finderArgs, count);
5371
5372 closeSession(session);
5373 }
5374 }
5375
5376 return count.intValue();
5377 }
5378
5379
5385 public int countAll() throws SystemException {
5386 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
5387 FINDER_ARGS_EMPTY, this);
5388
5389 if (count == null) {
5390 Session session = null;
5391
5392 try {
5393 session = openSession();
5394
5395 Query q = session.createQuery(_SQL_COUNT_SOCIALRELATION);
5396
5397 count = (Long)q.uniqueResult();
5398 }
5399 catch (Exception e) {
5400 throw processException(e);
5401 }
5402 finally {
5403 if (count == null) {
5404 count = Long.valueOf(0);
5405 }
5406
5407 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
5408 FINDER_ARGS_EMPTY, count);
5409
5410 closeSession(session);
5411 }
5412 }
5413
5414 return count.intValue();
5415 }
5416
5417
5420 public void afterPropertiesSet() {
5421 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
5422 com.liferay.portal.util.PropsUtil.get(
5423 "value.object.listener.com.liferay.portlet.social.model.SocialRelation")));
5424
5425 if (listenerClassNames.length > 0) {
5426 try {
5427 List<ModelListener<SocialRelation>> listenersList = new ArrayList<ModelListener<SocialRelation>>();
5428
5429 for (String listenerClassName : listenerClassNames) {
5430 Class<?> clazz = getClass();
5431
5432 listenersList.add((ModelListener<SocialRelation>)InstanceFactory.newInstance(
5433 clazz.getClassLoader(), listenerClassName));
5434 }
5435
5436 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
5437 }
5438 catch (Exception e) {
5439 _log.error(e);
5440 }
5441 }
5442 }
5443
5444 public void destroy() {
5445 EntityCacheUtil.removeCache(SocialRelationImpl.class.getName());
5446 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
5447 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
5448 }
5449
5450 @BeanReference(type = SocialActivityPersistence.class)
5451 protected SocialActivityPersistence socialActivityPersistence;
5452 @BeanReference(type = SocialActivityAchievementPersistence.class)
5453 protected SocialActivityAchievementPersistence socialActivityAchievementPersistence;
5454 @BeanReference(type = SocialActivityCounterPersistence.class)
5455 protected SocialActivityCounterPersistence socialActivityCounterPersistence;
5456 @BeanReference(type = SocialActivityLimitPersistence.class)
5457 protected SocialActivityLimitPersistence socialActivityLimitPersistence;
5458 @BeanReference(type = SocialActivitySettingPersistence.class)
5459 protected SocialActivitySettingPersistence socialActivitySettingPersistence;
5460 @BeanReference(type = SocialRelationPersistence.class)
5461 protected SocialRelationPersistence socialRelationPersistence;
5462 @BeanReference(type = SocialRequestPersistence.class)
5463 protected SocialRequestPersistence socialRequestPersistence;
5464 @BeanReference(type = ResourcePersistence.class)
5465 protected ResourcePersistence resourcePersistence;
5466 @BeanReference(type = UserPersistence.class)
5467 protected UserPersistence userPersistence;
5468 private static final String _SQL_SELECT_SOCIALRELATION = "SELECT socialRelation FROM SocialRelation socialRelation";
5469 private static final String _SQL_SELECT_SOCIALRELATION_WHERE = "SELECT socialRelation FROM SocialRelation socialRelation WHERE ";
5470 private static final String _SQL_COUNT_SOCIALRELATION = "SELECT COUNT(socialRelation) FROM SocialRelation socialRelation";
5471 private static final String _SQL_COUNT_SOCIALRELATION_WHERE = "SELECT COUNT(socialRelation) FROM SocialRelation socialRelation WHERE ";
5472 private static final String _FINDER_COLUMN_UUID_UUID_1 = "socialRelation.uuid IS NULL";
5473 private static final String _FINDER_COLUMN_UUID_UUID_2 = "socialRelation.uuid = ?";
5474 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(socialRelation.uuid IS NULL OR socialRelation.uuid = ?)";
5475 private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "socialRelation.companyId = ?";
5476 private static final String _FINDER_COLUMN_USERID1_USERID1_2 = "socialRelation.userId1 = ?";
5477 private static final String _FINDER_COLUMN_USERID2_USERID2_2 = "socialRelation.userId2 = ?";
5478 private static final String _FINDER_COLUMN_TYPE_TYPE_2 = "socialRelation.type = ?";
5479 private static final String _FINDER_COLUMN_C_T_COMPANYID_2 = "socialRelation.companyId = ? AND ";
5480 private static final String _FINDER_COLUMN_C_T_TYPE_2 = "socialRelation.type = ?";
5481 private static final String _FINDER_COLUMN_U1_U2_USERID1_2 = "socialRelation.userId1 = ? AND ";
5482 private static final String _FINDER_COLUMN_U1_U2_USERID2_2 = "socialRelation.userId2 = ?";
5483 private static final String _FINDER_COLUMN_U1_T_USERID1_2 = "socialRelation.userId1 = ? AND ";
5484 private static final String _FINDER_COLUMN_U1_T_TYPE_2 = "socialRelation.type = ?";
5485 private static final String _FINDER_COLUMN_U2_T_USERID2_2 = "socialRelation.userId2 = ? AND ";
5486 private static final String _FINDER_COLUMN_U2_T_TYPE_2 = "socialRelation.type = ?";
5487 private static final String _FINDER_COLUMN_U1_U2_T_USERID1_2 = "socialRelation.userId1 = ? AND ";
5488 private static final String _FINDER_COLUMN_U1_U2_T_USERID2_2 = "socialRelation.userId2 = ? AND ";
5489 private static final String _FINDER_COLUMN_U1_U2_T_TYPE_2 = "socialRelation.type = ?";
5490 private static final String _ORDER_BY_ENTITY_ALIAS = "socialRelation.";
5491 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No SocialRelation exists with the primary key ";
5492 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No SocialRelation exists with the key {";
5493 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
5494 private static Log _log = LogFactoryUtil.getLog(SocialRelationPersistenceImpl.class);
5495 private static SocialRelation _nullSocialRelation = new SocialRelationImpl() {
5496 @Override
5497 public Object clone() {
5498 return this;
5499 }
5500
5501 @Override
5502 public CacheModel<SocialRelation> toCacheModel() {
5503 return _nullSocialRelationCacheModel;
5504 }
5505 };
5506
5507 private static CacheModel<SocialRelation> _nullSocialRelationCacheModel = new CacheModel<SocialRelation>() {
5508 public SocialRelation toEntityModel() {
5509 return _nullSocialRelation;
5510 }
5511 };
5512 }