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 clearUniqueFindersCache(SocialRelation socialRelation) {
388 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U1_U2_T,
389 new Object[] {
390 Long.valueOf(socialRelation.getUserId1()),
391 Long.valueOf(socialRelation.getUserId2()),
392 Integer.valueOf(socialRelation.getType())
393 });
394 }
395
396
402 public SocialRelation create(long relationId) {
403 SocialRelation socialRelation = new SocialRelationImpl();
404
405 socialRelation.setNew(true);
406 socialRelation.setPrimaryKey(relationId);
407
408 String uuid = PortalUUIDUtil.generate();
409
410 socialRelation.setUuid(uuid);
411
412 return socialRelation;
413 }
414
415
423 public SocialRelation remove(long relationId)
424 throws NoSuchRelationException, SystemException {
425 return remove(Long.valueOf(relationId));
426 }
427
428
436 @Override
437 public SocialRelation remove(Serializable primaryKey)
438 throws NoSuchRelationException, SystemException {
439 Session session = null;
440
441 try {
442 session = openSession();
443
444 SocialRelation socialRelation = (SocialRelation)session.get(SocialRelationImpl.class,
445 primaryKey);
446
447 if (socialRelation == null) {
448 if (_log.isWarnEnabled()) {
449 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
450 }
451
452 throw new NoSuchRelationException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
453 primaryKey);
454 }
455
456 return remove(socialRelation);
457 }
458 catch (NoSuchRelationException nsee) {
459 throw nsee;
460 }
461 catch (Exception e) {
462 throw processException(e);
463 }
464 finally {
465 closeSession(session);
466 }
467 }
468
469 @Override
470 protected SocialRelation removeImpl(SocialRelation socialRelation)
471 throws SystemException {
472 socialRelation = toUnwrappedModel(socialRelation);
473
474 Session session = null;
475
476 try {
477 session = openSession();
478
479 BatchSessionUtil.delete(session, socialRelation);
480 }
481 catch (Exception e) {
482 throw processException(e);
483 }
484 finally {
485 closeSession(session);
486 }
487
488 clearCache(socialRelation);
489
490 return socialRelation;
491 }
492
493 @Override
494 public SocialRelation updateImpl(
495 com.liferay.portlet.social.model.SocialRelation socialRelation,
496 boolean merge) throws SystemException {
497 socialRelation = toUnwrappedModel(socialRelation);
498
499 boolean isNew = socialRelation.isNew();
500
501 SocialRelationModelImpl socialRelationModelImpl = (SocialRelationModelImpl)socialRelation;
502
503 if (Validator.isNull(socialRelation.getUuid())) {
504 String uuid = PortalUUIDUtil.generate();
505
506 socialRelation.setUuid(uuid);
507 }
508
509 Session session = null;
510
511 try {
512 session = openSession();
513
514 BatchSessionUtil.update(session, socialRelation, merge);
515
516 socialRelation.setNew(false);
517 }
518 catch (Exception e) {
519 throw processException(e);
520 }
521 finally {
522 closeSession(session);
523 }
524
525 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
526
527 if (isNew || !SocialRelationModelImpl.COLUMN_BITMASK_ENABLED) {
528 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
529 }
530
531 else {
532 if ((socialRelationModelImpl.getColumnBitmask() &
533 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
534 Object[] args = new Object[] {
535 socialRelationModelImpl.getOriginalUuid()
536 };
537
538 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
539 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
540 args);
541
542 args = new Object[] { socialRelationModelImpl.getUuid() };
543
544 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
545 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
546 args);
547 }
548
549 if ((socialRelationModelImpl.getColumnBitmask() &
550 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
551 Object[] args = new Object[] {
552 Long.valueOf(socialRelationModelImpl.getOriginalCompanyId())
553 };
554
555 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
556 args);
557 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
558 args);
559
560 args = new Object[] {
561 Long.valueOf(socialRelationModelImpl.getCompanyId())
562 };
563
564 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
565 args);
566 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
567 args);
568 }
569
570 if ((socialRelationModelImpl.getColumnBitmask() &
571 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID1.getColumnBitmask()) != 0) {
572 Object[] args = new Object[] {
573 Long.valueOf(socialRelationModelImpl.getOriginalUserId1())
574 };
575
576 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID1, args);
577 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID1,
578 args);
579
580 args = new Object[] {
581 Long.valueOf(socialRelationModelImpl.getUserId1())
582 };
583
584 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID1, args);
585 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID1,
586 args);
587 }
588
589 if ((socialRelationModelImpl.getColumnBitmask() &
590 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID2.getColumnBitmask()) != 0) {
591 Object[] args = new Object[] {
592 Long.valueOf(socialRelationModelImpl.getOriginalUserId2())
593 };
594
595 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID2, args);
596 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID2,
597 args);
598
599 args = new Object[] {
600 Long.valueOf(socialRelationModelImpl.getUserId2())
601 };
602
603 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID2, args);
604 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID2,
605 args);
606 }
607
608 if ((socialRelationModelImpl.getColumnBitmask() &
609 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE.getColumnBitmask()) != 0) {
610 Object[] args = new Object[] {
611 Integer.valueOf(socialRelationModelImpl.getOriginalType())
612 };
613
614 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TYPE, args);
615 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE,
616 args);
617
618 args = new Object[] {
619 Integer.valueOf(socialRelationModelImpl.getType())
620 };
621
622 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TYPE, args);
623 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE,
624 args);
625 }
626
627 if ((socialRelationModelImpl.getColumnBitmask() &
628 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_T.getColumnBitmask()) != 0) {
629 Object[] args = new Object[] {
630 Long.valueOf(socialRelationModelImpl.getOriginalCompanyId()),
631 Integer.valueOf(socialRelationModelImpl.getOriginalType())
632 };
633
634 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_T, args);
635 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_T,
636 args);
637
638 args = new Object[] {
639 Long.valueOf(socialRelationModelImpl.getCompanyId()),
640 Integer.valueOf(socialRelationModelImpl.getType())
641 };
642
643 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_T, args);
644 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_T,
645 args);
646 }
647
648 if ((socialRelationModelImpl.getColumnBitmask() &
649 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U1_U2.getColumnBitmask()) != 0) {
650 Object[] args = new Object[] {
651 Long.valueOf(socialRelationModelImpl.getOriginalUserId1()),
652 Long.valueOf(socialRelationModelImpl.getOriginalUserId2())
653 };
654
655 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U1_U2, args);
656 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U1_U2,
657 args);
658
659 args = new Object[] {
660 Long.valueOf(socialRelationModelImpl.getUserId1()),
661 Long.valueOf(socialRelationModelImpl.getUserId2())
662 };
663
664 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U1_U2, args);
665 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U1_U2,
666 args);
667 }
668
669 if ((socialRelationModelImpl.getColumnBitmask() &
670 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U1_T.getColumnBitmask()) != 0) {
671 Object[] args = new Object[] {
672 Long.valueOf(socialRelationModelImpl.getOriginalUserId1()),
673 Integer.valueOf(socialRelationModelImpl.getOriginalType())
674 };
675
676 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U1_T, args);
677 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U1_T,
678 args);
679
680 args = new Object[] {
681 Long.valueOf(socialRelationModelImpl.getUserId1()),
682 Integer.valueOf(socialRelationModelImpl.getType())
683 };
684
685 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U1_T, args);
686 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U1_T,
687 args);
688 }
689
690 if ((socialRelationModelImpl.getColumnBitmask() &
691 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U2_T.getColumnBitmask()) != 0) {
692 Object[] args = new Object[] {
693 Long.valueOf(socialRelationModelImpl.getOriginalUserId2()),
694 Integer.valueOf(socialRelationModelImpl.getOriginalType())
695 };
696
697 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U2_T, args);
698 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U2_T,
699 args);
700
701 args = new Object[] {
702 Long.valueOf(socialRelationModelImpl.getUserId2()),
703 Integer.valueOf(socialRelationModelImpl.getType())
704 };
705
706 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U2_T, args);
707 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U2_T,
708 args);
709 }
710 }
711
712 EntityCacheUtil.putResult(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
713 SocialRelationImpl.class, socialRelation.getPrimaryKey(),
714 socialRelation);
715
716 if (isNew) {
717 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U1_U2_T,
718 new Object[] {
719 Long.valueOf(socialRelation.getUserId1()),
720 Long.valueOf(socialRelation.getUserId2()),
721 Integer.valueOf(socialRelation.getType())
722 }, socialRelation);
723 }
724 else {
725 if ((socialRelationModelImpl.getColumnBitmask() &
726 FINDER_PATH_FETCH_BY_U1_U2_T.getColumnBitmask()) != 0) {
727 Object[] args = new Object[] {
728 Long.valueOf(socialRelationModelImpl.getOriginalUserId1()),
729 Long.valueOf(socialRelationModelImpl.getOriginalUserId2()),
730 Integer.valueOf(socialRelationModelImpl.getOriginalType())
731 };
732
733 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U1_U2_T, args);
734
735 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U1_U2_T, args);
736
737 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U1_U2_T,
738 new Object[] {
739 Long.valueOf(socialRelation.getUserId1()),
740 Long.valueOf(socialRelation.getUserId2()),
741 Integer.valueOf(socialRelation.getType())
742 }, socialRelation);
743 }
744 }
745
746 return socialRelation;
747 }
748
749 protected SocialRelation toUnwrappedModel(SocialRelation socialRelation) {
750 if (socialRelation instanceof SocialRelationImpl) {
751 return socialRelation;
752 }
753
754 SocialRelationImpl socialRelationImpl = new SocialRelationImpl();
755
756 socialRelationImpl.setNew(socialRelation.isNew());
757 socialRelationImpl.setPrimaryKey(socialRelation.getPrimaryKey());
758
759 socialRelationImpl.setUuid(socialRelation.getUuid());
760 socialRelationImpl.setRelationId(socialRelation.getRelationId());
761 socialRelationImpl.setCompanyId(socialRelation.getCompanyId());
762 socialRelationImpl.setCreateDate(socialRelation.getCreateDate());
763 socialRelationImpl.setUserId1(socialRelation.getUserId1());
764 socialRelationImpl.setUserId2(socialRelation.getUserId2());
765 socialRelationImpl.setType(socialRelation.getType());
766
767 return socialRelationImpl;
768 }
769
770
778 @Override
779 public SocialRelation findByPrimaryKey(Serializable primaryKey)
780 throws NoSuchModelException, SystemException {
781 return findByPrimaryKey(((Long)primaryKey).longValue());
782 }
783
784
792 public SocialRelation findByPrimaryKey(long relationId)
793 throws NoSuchRelationException, SystemException {
794 SocialRelation socialRelation = fetchByPrimaryKey(relationId);
795
796 if (socialRelation == null) {
797 if (_log.isWarnEnabled()) {
798 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + relationId);
799 }
800
801 throw new NoSuchRelationException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
802 relationId);
803 }
804
805 return socialRelation;
806 }
807
808
815 @Override
816 public SocialRelation fetchByPrimaryKey(Serializable primaryKey)
817 throws SystemException {
818 return fetchByPrimaryKey(((Long)primaryKey).longValue());
819 }
820
821
828 public SocialRelation fetchByPrimaryKey(long relationId)
829 throws SystemException {
830 SocialRelation socialRelation = (SocialRelation)EntityCacheUtil.getResult(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
831 SocialRelationImpl.class, relationId);
832
833 if (socialRelation == _nullSocialRelation) {
834 return null;
835 }
836
837 if (socialRelation == null) {
838 Session session = null;
839
840 boolean hasException = false;
841
842 try {
843 session = openSession();
844
845 socialRelation = (SocialRelation)session.get(SocialRelationImpl.class,
846 Long.valueOf(relationId));
847 }
848 catch (Exception e) {
849 hasException = true;
850
851 throw processException(e);
852 }
853 finally {
854 if (socialRelation != null) {
855 cacheResult(socialRelation);
856 }
857 else if (!hasException) {
858 EntityCacheUtil.putResult(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
859 SocialRelationImpl.class, relationId,
860 _nullSocialRelation);
861 }
862
863 closeSession(session);
864 }
865 }
866
867 return socialRelation;
868 }
869
870
877 public List<SocialRelation> findByUuid(String uuid)
878 throws SystemException {
879 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
880 }
881
882
895 public List<SocialRelation> findByUuid(String uuid, int start, int end)
896 throws SystemException {
897 return findByUuid(uuid, start, end, null);
898 }
899
900
914 public List<SocialRelation> findByUuid(String uuid, int start, int end,
915 OrderByComparator orderByComparator) throws SystemException {
916 FinderPath finderPath = null;
917 Object[] finderArgs = null;
918
919 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
920 (orderByComparator == null)) {
921 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
922 finderArgs = new Object[] { uuid };
923 }
924 else {
925 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
926 finderArgs = new Object[] { uuid, start, end, orderByComparator };
927 }
928
929 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(finderPath,
930 finderArgs, this);
931
932 if ((list != null) && !list.isEmpty()) {
933 for (SocialRelation socialRelation : list) {
934 if (!Validator.equals(uuid, socialRelation.getUuid())) {
935 list = null;
936
937 break;
938 }
939 }
940 }
941
942 if (list == null) {
943 StringBundler query = null;
944
945 if (orderByComparator != null) {
946 query = new StringBundler(3 +
947 (orderByComparator.getOrderByFields().length * 3));
948 }
949 else {
950 query = new StringBundler(2);
951 }
952
953 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
954
955 if (uuid == null) {
956 query.append(_FINDER_COLUMN_UUID_UUID_1);
957 }
958 else {
959 if (uuid.equals(StringPool.BLANK)) {
960 query.append(_FINDER_COLUMN_UUID_UUID_3);
961 }
962 else {
963 query.append(_FINDER_COLUMN_UUID_UUID_2);
964 }
965 }
966
967 if (orderByComparator != null) {
968 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
969 orderByComparator);
970 }
971
972 String sql = query.toString();
973
974 Session session = null;
975
976 try {
977 session = openSession();
978
979 Query q = session.createQuery(sql);
980
981 QueryPos qPos = QueryPos.getInstance(q);
982
983 if (uuid != null) {
984 qPos.add(uuid);
985 }
986
987 list = (List<SocialRelation>)QueryUtil.list(q, getDialect(),
988 start, end);
989 }
990 catch (Exception e) {
991 throw processException(e);
992 }
993 finally {
994 if (list == null) {
995 FinderCacheUtil.removeResult(finderPath, finderArgs);
996 }
997 else {
998 cacheResult(list);
999
1000 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1001 }
1002
1003 closeSession(session);
1004 }
1005 }
1006
1007 return list;
1008 }
1009
1010
1019 public SocialRelation findByUuid_First(String uuid,
1020 OrderByComparator orderByComparator)
1021 throws NoSuchRelationException, SystemException {
1022 SocialRelation socialRelation = fetchByUuid_First(uuid,
1023 orderByComparator);
1024
1025 if (socialRelation != null) {
1026 return socialRelation;
1027 }
1028
1029 StringBundler msg = new StringBundler(4);
1030
1031 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1032
1033 msg.append("uuid=");
1034 msg.append(uuid);
1035
1036 msg.append(StringPool.CLOSE_CURLY_BRACE);
1037
1038 throw new NoSuchRelationException(msg.toString());
1039 }
1040
1041
1049 public SocialRelation fetchByUuid_First(String uuid,
1050 OrderByComparator orderByComparator) throws SystemException {
1051 List<SocialRelation> list = findByUuid(uuid, 0, 1, orderByComparator);
1052
1053 if (!list.isEmpty()) {
1054 return list.get(0);
1055 }
1056
1057 return null;
1058 }
1059
1060
1069 public SocialRelation findByUuid_Last(String uuid,
1070 OrderByComparator orderByComparator)
1071 throws NoSuchRelationException, SystemException {
1072 SocialRelation socialRelation = fetchByUuid_Last(uuid, orderByComparator);
1073
1074 if (socialRelation != null) {
1075 return socialRelation;
1076 }
1077
1078 StringBundler msg = new StringBundler(4);
1079
1080 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1081
1082 msg.append("uuid=");
1083 msg.append(uuid);
1084
1085 msg.append(StringPool.CLOSE_CURLY_BRACE);
1086
1087 throw new NoSuchRelationException(msg.toString());
1088 }
1089
1090
1098 public SocialRelation fetchByUuid_Last(String uuid,
1099 OrderByComparator orderByComparator) throws SystemException {
1100 int count = countByUuid(uuid);
1101
1102 List<SocialRelation> list = findByUuid(uuid, count - 1, count,
1103 orderByComparator);
1104
1105 if (!list.isEmpty()) {
1106 return list.get(0);
1107 }
1108
1109 return null;
1110 }
1111
1112
1122 public SocialRelation[] findByUuid_PrevAndNext(long relationId,
1123 String uuid, OrderByComparator orderByComparator)
1124 throws NoSuchRelationException, SystemException {
1125 SocialRelation socialRelation = findByPrimaryKey(relationId);
1126
1127 Session session = null;
1128
1129 try {
1130 session = openSession();
1131
1132 SocialRelation[] array = new SocialRelationImpl[3];
1133
1134 array[0] = getByUuid_PrevAndNext(session, socialRelation, uuid,
1135 orderByComparator, true);
1136
1137 array[1] = socialRelation;
1138
1139 array[2] = getByUuid_PrevAndNext(session, socialRelation, uuid,
1140 orderByComparator, false);
1141
1142 return array;
1143 }
1144 catch (Exception e) {
1145 throw processException(e);
1146 }
1147 finally {
1148 closeSession(session);
1149 }
1150 }
1151
1152 protected SocialRelation getByUuid_PrevAndNext(Session session,
1153 SocialRelation socialRelation, String uuid,
1154 OrderByComparator orderByComparator, boolean previous) {
1155 StringBundler query = null;
1156
1157 if (orderByComparator != null) {
1158 query = new StringBundler(6 +
1159 (orderByComparator.getOrderByFields().length * 6));
1160 }
1161 else {
1162 query = new StringBundler(3);
1163 }
1164
1165 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
1166
1167 if (uuid == null) {
1168 query.append(_FINDER_COLUMN_UUID_UUID_1);
1169 }
1170 else {
1171 if (uuid.equals(StringPool.BLANK)) {
1172 query.append(_FINDER_COLUMN_UUID_UUID_3);
1173 }
1174 else {
1175 query.append(_FINDER_COLUMN_UUID_UUID_2);
1176 }
1177 }
1178
1179 if (orderByComparator != null) {
1180 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1181
1182 if (orderByConditionFields.length > 0) {
1183 query.append(WHERE_AND);
1184 }
1185
1186 for (int i = 0; i < orderByConditionFields.length; i++) {
1187 query.append(_ORDER_BY_ENTITY_ALIAS);
1188 query.append(orderByConditionFields[i]);
1189
1190 if ((i + 1) < orderByConditionFields.length) {
1191 if (orderByComparator.isAscending() ^ previous) {
1192 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1193 }
1194 else {
1195 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1196 }
1197 }
1198 else {
1199 if (orderByComparator.isAscending() ^ previous) {
1200 query.append(WHERE_GREATER_THAN);
1201 }
1202 else {
1203 query.append(WHERE_LESSER_THAN);
1204 }
1205 }
1206 }
1207
1208 query.append(ORDER_BY_CLAUSE);
1209
1210 String[] orderByFields = orderByComparator.getOrderByFields();
1211
1212 for (int i = 0; i < orderByFields.length; i++) {
1213 query.append(_ORDER_BY_ENTITY_ALIAS);
1214 query.append(orderByFields[i]);
1215
1216 if ((i + 1) < orderByFields.length) {
1217 if (orderByComparator.isAscending() ^ previous) {
1218 query.append(ORDER_BY_ASC_HAS_NEXT);
1219 }
1220 else {
1221 query.append(ORDER_BY_DESC_HAS_NEXT);
1222 }
1223 }
1224 else {
1225 if (orderByComparator.isAscending() ^ previous) {
1226 query.append(ORDER_BY_ASC);
1227 }
1228 else {
1229 query.append(ORDER_BY_DESC);
1230 }
1231 }
1232 }
1233 }
1234
1235 String sql = query.toString();
1236
1237 Query q = session.createQuery(sql);
1238
1239 q.setFirstResult(0);
1240 q.setMaxResults(2);
1241
1242 QueryPos qPos = QueryPos.getInstance(q);
1243
1244 if (uuid != null) {
1245 qPos.add(uuid);
1246 }
1247
1248 if (orderByComparator != null) {
1249 Object[] values = orderByComparator.getOrderByConditionValues(socialRelation);
1250
1251 for (Object value : values) {
1252 qPos.add(value);
1253 }
1254 }
1255
1256 List<SocialRelation> list = q.list();
1257
1258 if (list.size() == 2) {
1259 return list.get(1);
1260 }
1261 else {
1262 return null;
1263 }
1264 }
1265
1266
1273 public List<SocialRelation> findByCompanyId(long companyId)
1274 throws SystemException {
1275 return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1276 null);
1277 }
1278
1279
1292 public List<SocialRelation> findByCompanyId(long companyId, int start,
1293 int end) throws SystemException {
1294 return findByCompanyId(companyId, start, end, null);
1295 }
1296
1297
1311 public List<SocialRelation> findByCompanyId(long companyId, int start,
1312 int end, OrderByComparator orderByComparator) throws SystemException {
1313 FinderPath finderPath = null;
1314 Object[] finderArgs = null;
1315
1316 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1317 (orderByComparator == null)) {
1318 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
1319 finderArgs = new Object[] { companyId };
1320 }
1321 else {
1322 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
1323 finderArgs = new Object[] { companyId, start, end, orderByComparator };
1324 }
1325
1326 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(finderPath,
1327 finderArgs, this);
1328
1329 if ((list != null) && !list.isEmpty()) {
1330 for (SocialRelation socialRelation : list) {
1331 if ((companyId != socialRelation.getCompanyId())) {
1332 list = null;
1333
1334 break;
1335 }
1336 }
1337 }
1338
1339 if (list == null) {
1340 StringBundler query = null;
1341
1342 if (orderByComparator != null) {
1343 query = new StringBundler(3 +
1344 (orderByComparator.getOrderByFields().length * 3));
1345 }
1346 else {
1347 query = new StringBundler(2);
1348 }
1349
1350 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
1351
1352 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1353
1354 if (orderByComparator != null) {
1355 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1356 orderByComparator);
1357 }
1358
1359 String sql = query.toString();
1360
1361 Session session = null;
1362
1363 try {
1364 session = openSession();
1365
1366 Query q = session.createQuery(sql);
1367
1368 QueryPos qPos = QueryPos.getInstance(q);
1369
1370 qPos.add(companyId);
1371
1372 list = (List<SocialRelation>)QueryUtil.list(q, getDialect(),
1373 start, end);
1374 }
1375 catch (Exception e) {
1376 throw processException(e);
1377 }
1378 finally {
1379 if (list == null) {
1380 FinderCacheUtil.removeResult(finderPath, finderArgs);
1381 }
1382 else {
1383 cacheResult(list);
1384
1385 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1386 }
1387
1388 closeSession(session);
1389 }
1390 }
1391
1392 return list;
1393 }
1394
1395
1404 public SocialRelation findByCompanyId_First(long companyId,
1405 OrderByComparator orderByComparator)
1406 throws NoSuchRelationException, SystemException {
1407 SocialRelation socialRelation = fetchByCompanyId_First(companyId,
1408 orderByComparator);
1409
1410 if (socialRelation != null) {
1411 return socialRelation;
1412 }
1413
1414 StringBundler msg = new StringBundler(4);
1415
1416 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1417
1418 msg.append("companyId=");
1419 msg.append(companyId);
1420
1421 msg.append(StringPool.CLOSE_CURLY_BRACE);
1422
1423 throw new NoSuchRelationException(msg.toString());
1424 }
1425
1426
1434 public SocialRelation fetchByCompanyId_First(long companyId,
1435 OrderByComparator orderByComparator) throws SystemException {
1436 List<SocialRelation> list = findByCompanyId(companyId, 0, 1,
1437 orderByComparator);
1438
1439 if (!list.isEmpty()) {
1440 return list.get(0);
1441 }
1442
1443 return null;
1444 }
1445
1446
1455 public SocialRelation findByCompanyId_Last(long companyId,
1456 OrderByComparator orderByComparator)
1457 throws NoSuchRelationException, SystemException {
1458 SocialRelation socialRelation = fetchByCompanyId_Last(companyId,
1459 orderByComparator);
1460
1461 if (socialRelation != null) {
1462 return socialRelation;
1463 }
1464
1465 StringBundler msg = new StringBundler(4);
1466
1467 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1468
1469 msg.append("companyId=");
1470 msg.append(companyId);
1471
1472 msg.append(StringPool.CLOSE_CURLY_BRACE);
1473
1474 throw new NoSuchRelationException(msg.toString());
1475 }
1476
1477
1485 public SocialRelation fetchByCompanyId_Last(long companyId,
1486 OrderByComparator orderByComparator) throws SystemException {
1487 int count = countByCompanyId(companyId);
1488
1489 List<SocialRelation> list = findByCompanyId(companyId, count - 1,
1490 count, orderByComparator);
1491
1492 if (!list.isEmpty()) {
1493 return list.get(0);
1494 }
1495
1496 return null;
1497 }
1498
1499
1509 public SocialRelation[] findByCompanyId_PrevAndNext(long relationId,
1510 long companyId, OrderByComparator orderByComparator)
1511 throws NoSuchRelationException, SystemException {
1512 SocialRelation socialRelation = findByPrimaryKey(relationId);
1513
1514 Session session = null;
1515
1516 try {
1517 session = openSession();
1518
1519 SocialRelation[] array = new SocialRelationImpl[3];
1520
1521 array[0] = getByCompanyId_PrevAndNext(session, socialRelation,
1522 companyId, orderByComparator, true);
1523
1524 array[1] = socialRelation;
1525
1526 array[2] = getByCompanyId_PrevAndNext(session, socialRelation,
1527 companyId, orderByComparator, false);
1528
1529 return array;
1530 }
1531 catch (Exception e) {
1532 throw processException(e);
1533 }
1534 finally {
1535 closeSession(session);
1536 }
1537 }
1538
1539 protected SocialRelation getByCompanyId_PrevAndNext(Session session,
1540 SocialRelation socialRelation, long companyId,
1541 OrderByComparator orderByComparator, boolean previous) {
1542 StringBundler query = null;
1543
1544 if (orderByComparator != null) {
1545 query = new StringBundler(6 +
1546 (orderByComparator.getOrderByFields().length * 6));
1547 }
1548 else {
1549 query = new StringBundler(3);
1550 }
1551
1552 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
1553
1554 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1555
1556 if (orderByComparator != null) {
1557 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1558
1559 if (orderByConditionFields.length > 0) {
1560 query.append(WHERE_AND);
1561 }
1562
1563 for (int i = 0; i < orderByConditionFields.length; i++) {
1564 query.append(_ORDER_BY_ENTITY_ALIAS);
1565 query.append(orderByConditionFields[i]);
1566
1567 if ((i + 1) < orderByConditionFields.length) {
1568 if (orderByComparator.isAscending() ^ previous) {
1569 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1570 }
1571 else {
1572 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1573 }
1574 }
1575 else {
1576 if (orderByComparator.isAscending() ^ previous) {
1577 query.append(WHERE_GREATER_THAN);
1578 }
1579 else {
1580 query.append(WHERE_LESSER_THAN);
1581 }
1582 }
1583 }
1584
1585 query.append(ORDER_BY_CLAUSE);
1586
1587 String[] orderByFields = orderByComparator.getOrderByFields();
1588
1589 for (int i = 0; i < orderByFields.length; i++) {
1590 query.append(_ORDER_BY_ENTITY_ALIAS);
1591 query.append(orderByFields[i]);
1592
1593 if ((i + 1) < orderByFields.length) {
1594 if (orderByComparator.isAscending() ^ previous) {
1595 query.append(ORDER_BY_ASC_HAS_NEXT);
1596 }
1597 else {
1598 query.append(ORDER_BY_DESC_HAS_NEXT);
1599 }
1600 }
1601 else {
1602 if (orderByComparator.isAscending() ^ previous) {
1603 query.append(ORDER_BY_ASC);
1604 }
1605 else {
1606 query.append(ORDER_BY_DESC);
1607 }
1608 }
1609 }
1610 }
1611
1612 String sql = query.toString();
1613
1614 Query q = session.createQuery(sql);
1615
1616 q.setFirstResult(0);
1617 q.setMaxResults(2);
1618
1619 QueryPos qPos = QueryPos.getInstance(q);
1620
1621 qPos.add(companyId);
1622
1623 if (orderByComparator != null) {
1624 Object[] values = orderByComparator.getOrderByConditionValues(socialRelation);
1625
1626 for (Object value : values) {
1627 qPos.add(value);
1628 }
1629 }
1630
1631 List<SocialRelation> list = q.list();
1632
1633 if (list.size() == 2) {
1634 return list.get(1);
1635 }
1636 else {
1637 return null;
1638 }
1639 }
1640
1641
1648 public List<SocialRelation> findByUserId1(long userId1)
1649 throws SystemException {
1650 return findByUserId1(userId1, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1651 }
1652
1653
1666 public List<SocialRelation> findByUserId1(long userId1, int start, int end)
1667 throws SystemException {
1668 return findByUserId1(userId1, start, end, null);
1669 }
1670
1671
1685 public List<SocialRelation> findByUserId1(long userId1, int start, int end,
1686 OrderByComparator orderByComparator) throws SystemException {
1687 FinderPath finderPath = null;
1688 Object[] finderArgs = null;
1689
1690 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1691 (orderByComparator == null)) {
1692 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID1;
1693 finderArgs = new Object[] { userId1 };
1694 }
1695 else {
1696 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID1;
1697 finderArgs = new Object[] { userId1, start, end, orderByComparator };
1698 }
1699
1700 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(finderPath,
1701 finderArgs, this);
1702
1703 if ((list != null) && !list.isEmpty()) {
1704 for (SocialRelation socialRelation : list) {
1705 if ((userId1 != socialRelation.getUserId1())) {
1706 list = null;
1707
1708 break;
1709 }
1710 }
1711 }
1712
1713 if (list == null) {
1714 StringBundler query = null;
1715
1716 if (orderByComparator != null) {
1717 query = new StringBundler(3 +
1718 (orderByComparator.getOrderByFields().length * 3));
1719 }
1720 else {
1721 query = new StringBundler(2);
1722 }
1723
1724 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
1725
1726 query.append(_FINDER_COLUMN_USERID1_USERID1_2);
1727
1728 if (orderByComparator != null) {
1729 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1730 orderByComparator);
1731 }
1732
1733 String sql = query.toString();
1734
1735 Session session = null;
1736
1737 try {
1738 session = openSession();
1739
1740 Query q = session.createQuery(sql);
1741
1742 QueryPos qPos = QueryPos.getInstance(q);
1743
1744 qPos.add(userId1);
1745
1746 list = (List<SocialRelation>)QueryUtil.list(q, getDialect(),
1747 start, end);
1748 }
1749 catch (Exception e) {
1750 throw processException(e);
1751 }
1752 finally {
1753 if (list == null) {
1754 FinderCacheUtil.removeResult(finderPath, finderArgs);
1755 }
1756 else {
1757 cacheResult(list);
1758
1759 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1760 }
1761
1762 closeSession(session);
1763 }
1764 }
1765
1766 return list;
1767 }
1768
1769
1778 public SocialRelation findByUserId1_First(long userId1,
1779 OrderByComparator orderByComparator)
1780 throws NoSuchRelationException, SystemException {
1781 SocialRelation socialRelation = fetchByUserId1_First(userId1,
1782 orderByComparator);
1783
1784 if (socialRelation != null) {
1785 return socialRelation;
1786 }
1787
1788 StringBundler msg = new StringBundler(4);
1789
1790 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1791
1792 msg.append("userId1=");
1793 msg.append(userId1);
1794
1795 msg.append(StringPool.CLOSE_CURLY_BRACE);
1796
1797 throw new NoSuchRelationException(msg.toString());
1798 }
1799
1800
1808 public SocialRelation fetchByUserId1_First(long userId1,
1809 OrderByComparator orderByComparator) throws SystemException {
1810 List<SocialRelation> list = findByUserId1(userId1, 0, 1,
1811 orderByComparator);
1812
1813 if (!list.isEmpty()) {
1814 return list.get(0);
1815 }
1816
1817 return null;
1818 }
1819
1820
1829 public SocialRelation findByUserId1_Last(long userId1,
1830 OrderByComparator orderByComparator)
1831 throws NoSuchRelationException, SystemException {
1832 SocialRelation socialRelation = fetchByUserId1_Last(userId1,
1833 orderByComparator);
1834
1835 if (socialRelation != null) {
1836 return socialRelation;
1837 }
1838
1839 StringBundler msg = new StringBundler(4);
1840
1841 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1842
1843 msg.append("userId1=");
1844 msg.append(userId1);
1845
1846 msg.append(StringPool.CLOSE_CURLY_BRACE);
1847
1848 throw new NoSuchRelationException(msg.toString());
1849 }
1850
1851
1859 public SocialRelation fetchByUserId1_Last(long userId1,
1860 OrderByComparator orderByComparator) throws SystemException {
1861 int count = countByUserId1(userId1);
1862
1863 List<SocialRelation> list = findByUserId1(userId1, count - 1, count,
1864 orderByComparator);
1865
1866 if (!list.isEmpty()) {
1867 return list.get(0);
1868 }
1869
1870 return null;
1871 }
1872
1873
1883 public SocialRelation[] findByUserId1_PrevAndNext(long relationId,
1884 long userId1, OrderByComparator orderByComparator)
1885 throws NoSuchRelationException, SystemException {
1886 SocialRelation socialRelation = findByPrimaryKey(relationId);
1887
1888 Session session = null;
1889
1890 try {
1891 session = openSession();
1892
1893 SocialRelation[] array = new SocialRelationImpl[3];
1894
1895 array[0] = getByUserId1_PrevAndNext(session, socialRelation,
1896 userId1, orderByComparator, true);
1897
1898 array[1] = socialRelation;
1899
1900 array[2] = getByUserId1_PrevAndNext(session, socialRelation,
1901 userId1, orderByComparator, false);
1902
1903 return array;
1904 }
1905 catch (Exception e) {
1906 throw processException(e);
1907 }
1908 finally {
1909 closeSession(session);
1910 }
1911 }
1912
1913 protected SocialRelation getByUserId1_PrevAndNext(Session session,
1914 SocialRelation socialRelation, long userId1,
1915 OrderByComparator orderByComparator, boolean previous) {
1916 StringBundler query = null;
1917
1918 if (orderByComparator != null) {
1919 query = new StringBundler(6 +
1920 (orderByComparator.getOrderByFields().length * 6));
1921 }
1922 else {
1923 query = new StringBundler(3);
1924 }
1925
1926 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
1927
1928 query.append(_FINDER_COLUMN_USERID1_USERID1_2);
1929
1930 if (orderByComparator != null) {
1931 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1932
1933 if (orderByConditionFields.length > 0) {
1934 query.append(WHERE_AND);
1935 }
1936
1937 for (int i = 0; i < orderByConditionFields.length; i++) {
1938 query.append(_ORDER_BY_ENTITY_ALIAS);
1939 query.append(orderByConditionFields[i]);
1940
1941 if ((i + 1) < orderByConditionFields.length) {
1942 if (orderByComparator.isAscending() ^ previous) {
1943 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1944 }
1945 else {
1946 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1947 }
1948 }
1949 else {
1950 if (orderByComparator.isAscending() ^ previous) {
1951 query.append(WHERE_GREATER_THAN);
1952 }
1953 else {
1954 query.append(WHERE_LESSER_THAN);
1955 }
1956 }
1957 }
1958
1959 query.append(ORDER_BY_CLAUSE);
1960
1961 String[] orderByFields = orderByComparator.getOrderByFields();
1962
1963 for (int i = 0; i < orderByFields.length; i++) {
1964 query.append(_ORDER_BY_ENTITY_ALIAS);
1965 query.append(orderByFields[i]);
1966
1967 if ((i + 1) < orderByFields.length) {
1968 if (orderByComparator.isAscending() ^ previous) {
1969 query.append(ORDER_BY_ASC_HAS_NEXT);
1970 }
1971 else {
1972 query.append(ORDER_BY_DESC_HAS_NEXT);
1973 }
1974 }
1975 else {
1976 if (orderByComparator.isAscending() ^ previous) {
1977 query.append(ORDER_BY_ASC);
1978 }
1979 else {
1980 query.append(ORDER_BY_DESC);
1981 }
1982 }
1983 }
1984 }
1985
1986 String sql = query.toString();
1987
1988 Query q = session.createQuery(sql);
1989
1990 q.setFirstResult(0);
1991 q.setMaxResults(2);
1992
1993 QueryPos qPos = QueryPos.getInstance(q);
1994
1995 qPos.add(userId1);
1996
1997 if (orderByComparator != null) {
1998 Object[] values = orderByComparator.getOrderByConditionValues(socialRelation);
1999
2000 for (Object value : values) {
2001 qPos.add(value);
2002 }
2003 }
2004
2005 List<SocialRelation> list = q.list();
2006
2007 if (list.size() == 2) {
2008 return list.get(1);
2009 }
2010 else {
2011 return null;
2012 }
2013 }
2014
2015
2022 public List<SocialRelation> findByUserId2(long userId2)
2023 throws SystemException {
2024 return findByUserId2(userId2, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2025 }
2026
2027
2040 public List<SocialRelation> findByUserId2(long userId2, int start, int end)
2041 throws SystemException {
2042 return findByUserId2(userId2, start, end, null);
2043 }
2044
2045
2059 public List<SocialRelation> findByUserId2(long userId2, int start, int end,
2060 OrderByComparator orderByComparator) throws SystemException {
2061 FinderPath finderPath = null;
2062 Object[] finderArgs = null;
2063
2064 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2065 (orderByComparator == null)) {
2066 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID2;
2067 finderArgs = new Object[] { userId2 };
2068 }
2069 else {
2070 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID2;
2071 finderArgs = new Object[] { userId2, start, end, orderByComparator };
2072 }
2073
2074 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(finderPath,
2075 finderArgs, this);
2076
2077 if ((list != null) && !list.isEmpty()) {
2078 for (SocialRelation socialRelation : list) {
2079 if ((userId2 != socialRelation.getUserId2())) {
2080 list = null;
2081
2082 break;
2083 }
2084 }
2085 }
2086
2087 if (list == null) {
2088 StringBundler query = null;
2089
2090 if (orderByComparator != null) {
2091 query = new StringBundler(3 +
2092 (orderByComparator.getOrderByFields().length * 3));
2093 }
2094 else {
2095 query = new StringBundler(2);
2096 }
2097
2098 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
2099
2100 query.append(_FINDER_COLUMN_USERID2_USERID2_2);
2101
2102 if (orderByComparator != null) {
2103 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2104 orderByComparator);
2105 }
2106
2107 String sql = query.toString();
2108
2109 Session session = null;
2110
2111 try {
2112 session = openSession();
2113
2114 Query q = session.createQuery(sql);
2115
2116 QueryPos qPos = QueryPos.getInstance(q);
2117
2118 qPos.add(userId2);
2119
2120 list = (List<SocialRelation>)QueryUtil.list(q, getDialect(),
2121 start, end);
2122 }
2123 catch (Exception e) {
2124 throw processException(e);
2125 }
2126 finally {
2127 if (list == null) {
2128 FinderCacheUtil.removeResult(finderPath, finderArgs);
2129 }
2130 else {
2131 cacheResult(list);
2132
2133 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2134 }
2135
2136 closeSession(session);
2137 }
2138 }
2139
2140 return list;
2141 }
2142
2143
2152 public SocialRelation findByUserId2_First(long userId2,
2153 OrderByComparator orderByComparator)
2154 throws NoSuchRelationException, SystemException {
2155 SocialRelation socialRelation = fetchByUserId2_First(userId2,
2156 orderByComparator);
2157
2158 if (socialRelation != null) {
2159 return socialRelation;
2160 }
2161
2162 StringBundler msg = new StringBundler(4);
2163
2164 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2165
2166 msg.append("userId2=");
2167 msg.append(userId2);
2168
2169 msg.append(StringPool.CLOSE_CURLY_BRACE);
2170
2171 throw new NoSuchRelationException(msg.toString());
2172 }
2173
2174
2182 public SocialRelation fetchByUserId2_First(long userId2,
2183 OrderByComparator orderByComparator) throws SystemException {
2184 List<SocialRelation> list = findByUserId2(userId2, 0, 1,
2185 orderByComparator);
2186
2187 if (!list.isEmpty()) {
2188 return list.get(0);
2189 }
2190
2191 return null;
2192 }
2193
2194
2203 public SocialRelation findByUserId2_Last(long userId2,
2204 OrderByComparator orderByComparator)
2205 throws NoSuchRelationException, SystemException {
2206 SocialRelation socialRelation = fetchByUserId2_Last(userId2,
2207 orderByComparator);
2208
2209 if (socialRelation != null) {
2210 return socialRelation;
2211 }
2212
2213 StringBundler msg = new StringBundler(4);
2214
2215 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2216
2217 msg.append("userId2=");
2218 msg.append(userId2);
2219
2220 msg.append(StringPool.CLOSE_CURLY_BRACE);
2221
2222 throw new NoSuchRelationException(msg.toString());
2223 }
2224
2225
2233 public SocialRelation fetchByUserId2_Last(long userId2,
2234 OrderByComparator orderByComparator) throws SystemException {
2235 int count = countByUserId2(userId2);
2236
2237 List<SocialRelation> list = findByUserId2(userId2, count - 1, count,
2238 orderByComparator);
2239
2240 if (!list.isEmpty()) {
2241 return list.get(0);
2242 }
2243
2244 return null;
2245 }
2246
2247
2257 public SocialRelation[] findByUserId2_PrevAndNext(long relationId,
2258 long userId2, OrderByComparator orderByComparator)
2259 throws NoSuchRelationException, SystemException {
2260 SocialRelation socialRelation = findByPrimaryKey(relationId);
2261
2262 Session session = null;
2263
2264 try {
2265 session = openSession();
2266
2267 SocialRelation[] array = new SocialRelationImpl[3];
2268
2269 array[0] = getByUserId2_PrevAndNext(session, socialRelation,
2270 userId2, orderByComparator, true);
2271
2272 array[1] = socialRelation;
2273
2274 array[2] = getByUserId2_PrevAndNext(session, socialRelation,
2275 userId2, orderByComparator, false);
2276
2277 return array;
2278 }
2279 catch (Exception e) {
2280 throw processException(e);
2281 }
2282 finally {
2283 closeSession(session);
2284 }
2285 }
2286
2287 protected SocialRelation getByUserId2_PrevAndNext(Session session,
2288 SocialRelation socialRelation, long userId2,
2289 OrderByComparator orderByComparator, boolean previous) {
2290 StringBundler query = null;
2291
2292 if (orderByComparator != null) {
2293 query = new StringBundler(6 +
2294 (orderByComparator.getOrderByFields().length * 6));
2295 }
2296 else {
2297 query = new StringBundler(3);
2298 }
2299
2300 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
2301
2302 query.append(_FINDER_COLUMN_USERID2_USERID2_2);
2303
2304 if (orderByComparator != null) {
2305 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2306
2307 if (orderByConditionFields.length > 0) {
2308 query.append(WHERE_AND);
2309 }
2310
2311 for (int i = 0; i < orderByConditionFields.length; i++) {
2312 query.append(_ORDER_BY_ENTITY_ALIAS);
2313 query.append(orderByConditionFields[i]);
2314
2315 if ((i + 1) < orderByConditionFields.length) {
2316 if (orderByComparator.isAscending() ^ previous) {
2317 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2318 }
2319 else {
2320 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2321 }
2322 }
2323 else {
2324 if (orderByComparator.isAscending() ^ previous) {
2325 query.append(WHERE_GREATER_THAN);
2326 }
2327 else {
2328 query.append(WHERE_LESSER_THAN);
2329 }
2330 }
2331 }
2332
2333 query.append(ORDER_BY_CLAUSE);
2334
2335 String[] orderByFields = orderByComparator.getOrderByFields();
2336
2337 for (int i = 0; i < orderByFields.length; i++) {
2338 query.append(_ORDER_BY_ENTITY_ALIAS);
2339 query.append(orderByFields[i]);
2340
2341 if ((i + 1) < orderByFields.length) {
2342 if (orderByComparator.isAscending() ^ previous) {
2343 query.append(ORDER_BY_ASC_HAS_NEXT);
2344 }
2345 else {
2346 query.append(ORDER_BY_DESC_HAS_NEXT);
2347 }
2348 }
2349 else {
2350 if (orderByComparator.isAscending() ^ previous) {
2351 query.append(ORDER_BY_ASC);
2352 }
2353 else {
2354 query.append(ORDER_BY_DESC);
2355 }
2356 }
2357 }
2358 }
2359
2360 String sql = query.toString();
2361
2362 Query q = session.createQuery(sql);
2363
2364 q.setFirstResult(0);
2365 q.setMaxResults(2);
2366
2367 QueryPos qPos = QueryPos.getInstance(q);
2368
2369 qPos.add(userId2);
2370
2371 if (orderByComparator != null) {
2372 Object[] values = orderByComparator.getOrderByConditionValues(socialRelation);
2373
2374 for (Object value : values) {
2375 qPos.add(value);
2376 }
2377 }
2378
2379 List<SocialRelation> list = q.list();
2380
2381 if (list.size() == 2) {
2382 return list.get(1);
2383 }
2384 else {
2385 return null;
2386 }
2387 }
2388
2389
2396 public List<SocialRelation> findByType(int type) throws SystemException {
2397 return findByType(type, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2398 }
2399
2400
2413 public List<SocialRelation> findByType(int type, int start, int end)
2414 throws SystemException {
2415 return findByType(type, start, end, null);
2416 }
2417
2418
2432 public List<SocialRelation> findByType(int type, int start, int end,
2433 OrderByComparator orderByComparator) throws SystemException {
2434 FinderPath finderPath = null;
2435 Object[] finderArgs = null;
2436
2437 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2438 (orderByComparator == null)) {
2439 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE;
2440 finderArgs = new Object[] { type };
2441 }
2442 else {
2443 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_TYPE;
2444 finderArgs = new Object[] { type, start, end, orderByComparator };
2445 }
2446
2447 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(finderPath,
2448 finderArgs, this);
2449
2450 if ((list != null) && !list.isEmpty()) {
2451 for (SocialRelation socialRelation : list) {
2452 if ((type != socialRelation.getType())) {
2453 list = null;
2454
2455 break;
2456 }
2457 }
2458 }
2459
2460 if (list == null) {
2461 StringBundler query = null;
2462
2463 if (orderByComparator != null) {
2464 query = new StringBundler(3 +
2465 (orderByComparator.getOrderByFields().length * 3));
2466 }
2467 else {
2468 query = new StringBundler(2);
2469 }
2470
2471 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
2472
2473 query.append(_FINDER_COLUMN_TYPE_TYPE_2);
2474
2475 if (orderByComparator != null) {
2476 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2477 orderByComparator);
2478 }
2479
2480 String sql = query.toString();
2481
2482 Session session = null;
2483
2484 try {
2485 session = openSession();
2486
2487 Query q = session.createQuery(sql);
2488
2489 QueryPos qPos = QueryPos.getInstance(q);
2490
2491 qPos.add(type);
2492
2493 list = (List<SocialRelation>)QueryUtil.list(q, getDialect(),
2494 start, end);
2495 }
2496 catch (Exception e) {
2497 throw processException(e);
2498 }
2499 finally {
2500 if (list == null) {
2501 FinderCacheUtil.removeResult(finderPath, finderArgs);
2502 }
2503 else {
2504 cacheResult(list);
2505
2506 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2507 }
2508
2509 closeSession(session);
2510 }
2511 }
2512
2513 return list;
2514 }
2515
2516
2525 public SocialRelation findByType_First(int type,
2526 OrderByComparator orderByComparator)
2527 throws NoSuchRelationException, SystemException {
2528 SocialRelation socialRelation = fetchByType_First(type,
2529 orderByComparator);
2530
2531 if (socialRelation != null) {
2532 return socialRelation;
2533 }
2534
2535 StringBundler msg = new StringBundler(4);
2536
2537 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2538
2539 msg.append("type=");
2540 msg.append(type);
2541
2542 msg.append(StringPool.CLOSE_CURLY_BRACE);
2543
2544 throw new NoSuchRelationException(msg.toString());
2545 }
2546
2547
2555 public SocialRelation fetchByType_First(int type,
2556 OrderByComparator orderByComparator) throws SystemException {
2557 List<SocialRelation> list = findByType(type, 0, 1, orderByComparator);
2558
2559 if (!list.isEmpty()) {
2560 return list.get(0);
2561 }
2562
2563 return null;
2564 }
2565
2566
2575 public SocialRelation findByType_Last(int type,
2576 OrderByComparator orderByComparator)
2577 throws NoSuchRelationException, SystemException {
2578 SocialRelation socialRelation = fetchByType_Last(type, orderByComparator);
2579
2580 if (socialRelation != null) {
2581 return socialRelation;
2582 }
2583
2584 StringBundler msg = new StringBundler(4);
2585
2586 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2587
2588 msg.append("type=");
2589 msg.append(type);
2590
2591 msg.append(StringPool.CLOSE_CURLY_BRACE);
2592
2593 throw new NoSuchRelationException(msg.toString());
2594 }
2595
2596
2604 public SocialRelation fetchByType_Last(int type,
2605 OrderByComparator orderByComparator) throws SystemException {
2606 int count = countByType(type);
2607
2608 List<SocialRelation> list = findByType(type, count - 1, count,
2609 orderByComparator);
2610
2611 if (!list.isEmpty()) {
2612 return list.get(0);
2613 }
2614
2615 return null;
2616 }
2617
2618
2628 public SocialRelation[] findByType_PrevAndNext(long relationId, int type,
2629 OrderByComparator orderByComparator)
2630 throws NoSuchRelationException, SystemException {
2631 SocialRelation socialRelation = findByPrimaryKey(relationId);
2632
2633 Session session = null;
2634
2635 try {
2636 session = openSession();
2637
2638 SocialRelation[] array = new SocialRelationImpl[3];
2639
2640 array[0] = getByType_PrevAndNext(session, socialRelation, type,
2641 orderByComparator, true);
2642
2643 array[1] = socialRelation;
2644
2645 array[2] = getByType_PrevAndNext(session, socialRelation, type,
2646 orderByComparator, false);
2647
2648 return array;
2649 }
2650 catch (Exception e) {
2651 throw processException(e);
2652 }
2653 finally {
2654 closeSession(session);
2655 }
2656 }
2657
2658 protected SocialRelation getByType_PrevAndNext(Session session,
2659 SocialRelation socialRelation, int type,
2660 OrderByComparator orderByComparator, boolean previous) {
2661 StringBundler query = null;
2662
2663 if (orderByComparator != null) {
2664 query = new StringBundler(6 +
2665 (orderByComparator.getOrderByFields().length * 6));
2666 }
2667 else {
2668 query = new StringBundler(3);
2669 }
2670
2671 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
2672
2673 query.append(_FINDER_COLUMN_TYPE_TYPE_2);
2674
2675 if (orderByComparator != null) {
2676 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2677
2678 if (orderByConditionFields.length > 0) {
2679 query.append(WHERE_AND);
2680 }
2681
2682 for (int i = 0; i < orderByConditionFields.length; i++) {
2683 query.append(_ORDER_BY_ENTITY_ALIAS);
2684 query.append(orderByConditionFields[i]);
2685
2686 if ((i + 1) < orderByConditionFields.length) {
2687 if (orderByComparator.isAscending() ^ previous) {
2688 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2689 }
2690 else {
2691 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2692 }
2693 }
2694 else {
2695 if (orderByComparator.isAscending() ^ previous) {
2696 query.append(WHERE_GREATER_THAN);
2697 }
2698 else {
2699 query.append(WHERE_LESSER_THAN);
2700 }
2701 }
2702 }
2703
2704 query.append(ORDER_BY_CLAUSE);
2705
2706 String[] orderByFields = orderByComparator.getOrderByFields();
2707
2708 for (int i = 0; i < orderByFields.length; i++) {
2709 query.append(_ORDER_BY_ENTITY_ALIAS);
2710 query.append(orderByFields[i]);
2711
2712 if ((i + 1) < orderByFields.length) {
2713 if (orderByComparator.isAscending() ^ previous) {
2714 query.append(ORDER_BY_ASC_HAS_NEXT);
2715 }
2716 else {
2717 query.append(ORDER_BY_DESC_HAS_NEXT);
2718 }
2719 }
2720 else {
2721 if (orderByComparator.isAscending() ^ previous) {
2722 query.append(ORDER_BY_ASC);
2723 }
2724 else {
2725 query.append(ORDER_BY_DESC);
2726 }
2727 }
2728 }
2729 }
2730
2731 String sql = query.toString();
2732
2733 Query q = session.createQuery(sql);
2734
2735 q.setFirstResult(0);
2736 q.setMaxResults(2);
2737
2738 QueryPos qPos = QueryPos.getInstance(q);
2739
2740 qPos.add(type);
2741
2742 if (orderByComparator != null) {
2743 Object[] values = orderByComparator.getOrderByConditionValues(socialRelation);
2744
2745 for (Object value : values) {
2746 qPos.add(value);
2747 }
2748 }
2749
2750 List<SocialRelation> list = q.list();
2751
2752 if (list.size() == 2) {
2753 return list.get(1);
2754 }
2755 else {
2756 return null;
2757 }
2758 }
2759
2760
2768 public List<SocialRelation> findByC_T(long companyId, int type)
2769 throws SystemException {
2770 return findByC_T(companyId, type, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2771 null);
2772 }
2773
2774
2788 public List<SocialRelation> findByC_T(long companyId, int type, int start,
2789 int end) throws SystemException {
2790 return findByC_T(companyId, type, start, end, null);
2791 }
2792
2793
2808 public List<SocialRelation> findByC_T(long companyId, int type, int start,
2809 int end, OrderByComparator orderByComparator) throws SystemException {
2810 FinderPath finderPath = null;
2811 Object[] finderArgs = null;
2812
2813 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2814 (orderByComparator == null)) {
2815 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_T;
2816 finderArgs = new Object[] { companyId, type };
2817 }
2818 else {
2819 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_T;
2820 finderArgs = new Object[] {
2821 companyId, type,
2822
2823 start, end, orderByComparator
2824 };
2825 }
2826
2827 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(finderPath,
2828 finderArgs, this);
2829
2830 if ((list != null) && !list.isEmpty()) {
2831 for (SocialRelation socialRelation : list) {
2832 if ((companyId != socialRelation.getCompanyId()) ||
2833 (type != socialRelation.getType())) {
2834 list = null;
2835
2836 break;
2837 }
2838 }
2839 }
2840
2841 if (list == null) {
2842 StringBundler query = null;
2843
2844 if (orderByComparator != null) {
2845 query = new StringBundler(4 +
2846 (orderByComparator.getOrderByFields().length * 3));
2847 }
2848 else {
2849 query = new StringBundler(3);
2850 }
2851
2852 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
2853
2854 query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
2855
2856 query.append(_FINDER_COLUMN_C_T_TYPE_2);
2857
2858 if (orderByComparator != null) {
2859 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2860 orderByComparator);
2861 }
2862
2863 String sql = query.toString();
2864
2865 Session session = null;
2866
2867 try {
2868 session = openSession();
2869
2870 Query q = session.createQuery(sql);
2871
2872 QueryPos qPos = QueryPos.getInstance(q);
2873
2874 qPos.add(companyId);
2875
2876 qPos.add(type);
2877
2878 list = (List<SocialRelation>)QueryUtil.list(q, getDialect(),
2879 start, end);
2880 }
2881 catch (Exception e) {
2882 throw processException(e);
2883 }
2884 finally {
2885 if (list == null) {
2886 FinderCacheUtil.removeResult(finderPath, finderArgs);
2887 }
2888 else {
2889 cacheResult(list);
2890
2891 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2892 }
2893
2894 closeSession(session);
2895 }
2896 }
2897
2898 return list;
2899 }
2900
2901
2911 public SocialRelation findByC_T_First(long companyId, int type,
2912 OrderByComparator orderByComparator)
2913 throws NoSuchRelationException, SystemException {
2914 SocialRelation socialRelation = fetchByC_T_First(companyId, type,
2915 orderByComparator);
2916
2917 if (socialRelation != null) {
2918 return socialRelation;
2919 }
2920
2921 StringBundler msg = new StringBundler(6);
2922
2923 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2924
2925 msg.append("companyId=");
2926 msg.append(companyId);
2927
2928 msg.append(", type=");
2929 msg.append(type);
2930
2931 msg.append(StringPool.CLOSE_CURLY_BRACE);
2932
2933 throw new NoSuchRelationException(msg.toString());
2934 }
2935
2936
2945 public SocialRelation fetchByC_T_First(long companyId, int type,
2946 OrderByComparator orderByComparator) throws SystemException {
2947 List<SocialRelation> list = findByC_T(companyId, type, 0, 1,
2948 orderByComparator);
2949
2950 if (!list.isEmpty()) {
2951 return list.get(0);
2952 }
2953
2954 return null;
2955 }
2956
2957
2967 public SocialRelation findByC_T_Last(long companyId, int type,
2968 OrderByComparator orderByComparator)
2969 throws NoSuchRelationException, SystemException {
2970 SocialRelation socialRelation = fetchByC_T_Last(companyId, type,
2971 orderByComparator);
2972
2973 if (socialRelation != null) {
2974 return socialRelation;
2975 }
2976
2977 StringBundler msg = new StringBundler(6);
2978
2979 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2980
2981 msg.append("companyId=");
2982 msg.append(companyId);
2983
2984 msg.append(", type=");
2985 msg.append(type);
2986
2987 msg.append(StringPool.CLOSE_CURLY_BRACE);
2988
2989 throw new NoSuchRelationException(msg.toString());
2990 }
2991
2992
3001 public SocialRelation fetchByC_T_Last(long companyId, int type,
3002 OrderByComparator orderByComparator) throws SystemException {
3003 int count = countByC_T(companyId, type);
3004
3005 List<SocialRelation> list = findByC_T(companyId, type, count - 1,
3006 count, orderByComparator);
3007
3008 if (!list.isEmpty()) {
3009 return list.get(0);
3010 }
3011
3012 return null;
3013 }
3014
3015
3026 public SocialRelation[] findByC_T_PrevAndNext(long relationId,
3027 long companyId, int type, OrderByComparator orderByComparator)
3028 throws NoSuchRelationException, SystemException {
3029 SocialRelation socialRelation = findByPrimaryKey(relationId);
3030
3031 Session session = null;
3032
3033 try {
3034 session = openSession();
3035
3036 SocialRelation[] array = new SocialRelationImpl[3];
3037
3038 array[0] = getByC_T_PrevAndNext(session, socialRelation, companyId,
3039 type, orderByComparator, true);
3040
3041 array[1] = socialRelation;
3042
3043 array[2] = getByC_T_PrevAndNext(session, socialRelation, companyId,
3044 type, orderByComparator, false);
3045
3046 return array;
3047 }
3048 catch (Exception e) {
3049 throw processException(e);
3050 }
3051 finally {
3052 closeSession(session);
3053 }
3054 }
3055
3056 protected SocialRelation getByC_T_PrevAndNext(Session session,
3057 SocialRelation socialRelation, long companyId, int type,
3058 OrderByComparator orderByComparator, boolean previous) {
3059 StringBundler query = null;
3060
3061 if (orderByComparator != null) {
3062 query = new StringBundler(6 +
3063 (orderByComparator.getOrderByFields().length * 6));
3064 }
3065 else {
3066 query = new StringBundler(3);
3067 }
3068
3069 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
3070
3071 query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
3072
3073 query.append(_FINDER_COLUMN_C_T_TYPE_2);
3074
3075 if (orderByComparator != null) {
3076 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3077
3078 if (orderByConditionFields.length > 0) {
3079 query.append(WHERE_AND);
3080 }
3081
3082 for (int i = 0; i < orderByConditionFields.length; i++) {
3083 query.append(_ORDER_BY_ENTITY_ALIAS);
3084 query.append(orderByConditionFields[i]);
3085
3086 if ((i + 1) < orderByConditionFields.length) {
3087 if (orderByComparator.isAscending() ^ previous) {
3088 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3089 }
3090 else {
3091 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3092 }
3093 }
3094 else {
3095 if (orderByComparator.isAscending() ^ previous) {
3096 query.append(WHERE_GREATER_THAN);
3097 }
3098 else {
3099 query.append(WHERE_LESSER_THAN);
3100 }
3101 }
3102 }
3103
3104 query.append(ORDER_BY_CLAUSE);
3105
3106 String[] orderByFields = orderByComparator.getOrderByFields();
3107
3108 for (int i = 0; i < orderByFields.length; i++) {
3109 query.append(_ORDER_BY_ENTITY_ALIAS);
3110 query.append(orderByFields[i]);
3111
3112 if ((i + 1) < orderByFields.length) {
3113 if (orderByComparator.isAscending() ^ previous) {
3114 query.append(ORDER_BY_ASC_HAS_NEXT);
3115 }
3116 else {
3117 query.append(ORDER_BY_DESC_HAS_NEXT);
3118 }
3119 }
3120 else {
3121 if (orderByComparator.isAscending() ^ previous) {
3122 query.append(ORDER_BY_ASC);
3123 }
3124 else {
3125 query.append(ORDER_BY_DESC);
3126 }
3127 }
3128 }
3129 }
3130
3131 String sql = query.toString();
3132
3133 Query q = session.createQuery(sql);
3134
3135 q.setFirstResult(0);
3136 q.setMaxResults(2);
3137
3138 QueryPos qPos = QueryPos.getInstance(q);
3139
3140 qPos.add(companyId);
3141
3142 qPos.add(type);
3143
3144 if (orderByComparator != null) {
3145 Object[] values = orderByComparator.getOrderByConditionValues(socialRelation);
3146
3147 for (Object value : values) {
3148 qPos.add(value);
3149 }
3150 }
3151
3152 List<SocialRelation> list = q.list();
3153
3154 if (list.size() == 2) {
3155 return list.get(1);
3156 }
3157 else {
3158 return null;
3159 }
3160 }
3161
3162
3170 public List<SocialRelation> findByU1_U2(long userId1, long userId2)
3171 throws SystemException {
3172 return findByU1_U2(userId1, userId2, QueryUtil.ALL_POS,
3173 QueryUtil.ALL_POS, null);
3174 }
3175
3176
3190 public List<SocialRelation> findByU1_U2(long userId1, long userId2,
3191 int start, int end) throws SystemException {
3192 return findByU1_U2(userId1, userId2, start, end, null);
3193 }
3194
3195
3210 public List<SocialRelation> findByU1_U2(long userId1, long userId2,
3211 int start, int end, OrderByComparator orderByComparator)
3212 throws SystemException {
3213 FinderPath finderPath = null;
3214 Object[] finderArgs = null;
3215
3216 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3217 (orderByComparator == null)) {
3218 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U1_U2;
3219 finderArgs = new Object[] { userId1, userId2 };
3220 }
3221 else {
3222 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U1_U2;
3223 finderArgs = new Object[] {
3224 userId1, userId2,
3225
3226 start, end, orderByComparator
3227 };
3228 }
3229
3230 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(finderPath,
3231 finderArgs, this);
3232
3233 if ((list != null) && !list.isEmpty()) {
3234 for (SocialRelation socialRelation : list) {
3235 if ((userId1 != socialRelation.getUserId1()) ||
3236 (userId2 != socialRelation.getUserId2())) {
3237 list = null;
3238
3239 break;
3240 }
3241 }
3242 }
3243
3244 if (list == null) {
3245 StringBundler query = null;
3246
3247 if (orderByComparator != null) {
3248 query = new StringBundler(4 +
3249 (orderByComparator.getOrderByFields().length * 3));
3250 }
3251 else {
3252 query = new StringBundler(3);
3253 }
3254
3255 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
3256
3257 query.append(_FINDER_COLUMN_U1_U2_USERID1_2);
3258
3259 query.append(_FINDER_COLUMN_U1_U2_USERID2_2);
3260
3261 if (orderByComparator != null) {
3262 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3263 orderByComparator);
3264 }
3265
3266 String sql = query.toString();
3267
3268 Session session = null;
3269
3270 try {
3271 session = openSession();
3272
3273 Query q = session.createQuery(sql);
3274
3275 QueryPos qPos = QueryPos.getInstance(q);
3276
3277 qPos.add(userId1);
3278
3279 qPos.add(userId2);
3280
3281 list = (List<SocialRelation>)QueryUtil.list(q, getDialect(),
3282 start, end);
3283 }
3284 catch (Exception e) {
3285 throw processException(e);
3286 }
3287 finally {
3288 if (list == null) {
3289 FinderCacheUtil.removeResult(finderPath, finderArgs);
3290 }
3291 else {
3292 cacheResult(list);
3293
3294 FinderCacheUtil.putResult(finderPath, finderArgs, list);
3295 }
3296
3297 closeSession(session);
3298 }
3299 }
3300
3301 return list;
3302 }
3303
3304
3314 public SocialRelation findByU1_U2_First(long userId1, long userId2,
3315 OrderByComparator orderByComparator)
3316 throws NoSuchRelationException, SystemException {
3317 SocialRelation socialRelation = fetchByU1_U2_First(userId1, userId2,
3318 orderByComparator);
3319
3320 if (socialRelation != null) {
3321 return socialRelation;
3322 }
3323
3324 StringBundler msg = new StringBundler(6);
3325
3326 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3327
3328 msg.append("userId1=");
3329 msg.append(userId1);
3330
3331 msg.append(", userId2=");
3332 msg.append(userId2);
3333
3334 msg.append(StringPool.CLOSE_CURLY_BRACE);
3335
3336 throw new NoSuchRelationException(msg.toString());
3337 }
3338
3339
3348 public SocialRelation fetchByU1_U2_First(long userId1, long userId2,
3349 OrderByComparator orderByComparator) throws SystemException {
3350 List<SocialRelation> list = findByU1_U2(userId1, userId2, 0, 1,
3351 orderByComparator);
3352
3353 if (!list.isEmpty()) {
3354 return list.get(0);
3355 }
3356
3357 return null;
3358 }
3359
3360
3370 public SocialRelation findByU1_U2_Last(long userId1, long userId2,
3371 OrderByComparator orderByComparator)
3372 throws NoSuchRelationException, SystemException {
3373 SocialRelation socialRelation = fetchByU1_U2_Last(userId1, userId2,
3374 orderByComparator);
3375
3376 if (socialRelation != null) {
3377 return socialRelation;
3378 }
3379
3380 StringBundler msg = new StringBundler(6);
3381
3382 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3383
3384 msg.append("userId1=");
3385 msg.append(userId1);
3386
3387 msg.append(", userId2=");
3388 msg.append(userId2);
3389
3390 msg.append(StringPool.CLOSE_CURLY_BRACE);
3391
3392 throw new NoSuchRelationException(msg.toString());
3393 }
3394
3395
3404 public SocialRelation fetchByU1_U2_Last(long userId1, long userId2,
3405 OrderByComparator orderByComparator) throws SystemException {
3406 int count = countByU1_U2(userId1, userId2);
3407
3408 List<SocialRelation> list = findByU1_U2(userId1, userId2, count - 1,
3409 count, orderByComparator);
3410
3411 if (!list.isEmpty()) {
3412 return list.get(0);
3413 }
3414
3415 return null;
3416 }
3417
3418
3429 public SocialRelation[] findByU1_U2_PrevAndNext(long relationId,
3430 long userId1, long userId2, OrderByComparator orderByComparator)
3431 throws NoSuchRelationException, SystemException {
3432 SocialRelation socialRelation = findByPrimaryKey(relationId);
3433
3434 Session session = null;
3435
3436 try {
3437 session = openSession();
3438
3439 SocialRelation[] array = new SocialRelationImpl[3];
3440
3441 array[0] = getByU1_U2_PrevAndNext(session, socialRelation, userId1,
3442 userId2, orderByComparator, true);
3443
3444 array[1] = socialRelation;
3445
3446 array[2] = getByU1_U2_PrevAndNext(session, socialRelation, userId1,
3447 userId2, orderByComparator, false);
3448
3449 return array;
3450 }
3451 catch (Exception e) {
3452 throw processException(e);
3453 }
3454 finally {
3455 closeSession(session);
3456 }
3457 }
3458
3459 protected SocialRelation getByU1_U2_PrevAndNext(Session session,
3460 SocialRelation socialRelation, long userId1, long userId2,
3461 OrderByComparator orderByComparator, boolean previous) {
3462 StringBundler query = null;
3463
3464 if (orderByComparator != null) {
3465 query = new StringBundler(6 +
3466 (orderByComparator.getOrderByFields().length * 6));
3467 }
3468 else {
3469 query = new StringBundler(3);
3470 }
3471
3472 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
3473
3474 query.append(_FINDER_COLUMN_U1_U2_USERID1_2);
3475
3476 query.append(_FINDER_COLUMN_U1_U2_USERID2_2);
3477
3478 if (orderByComparator != null) {
3479 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3480
3481 if (orderByConditionFields.length > 0) {
3482 query.append(WHERE_AND);
3483 }
3484
3485 for (int i = 0; i < orderByConditionFields.length; i++) {
3486 query.append(_ORDER_BY_ENTITY_ALIAS);
3487 query.append(orderByConditionFields[i]);
3488
3489 if ((i + 1) < orderByConditionFields.length) {
3490 if (orderByComparator.isAscending() ^ previous) {
3491 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3492 }
3493 else {
3494 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3495 }
3496 }
3497 else {
3498 if (orderByComparator.isAscending() ^ previous) {
3499 query.append(WHERE_GREATER_THAN);
3500 }
3501 else {
3502 query.append(WHERE_LESSER_THAN);
3503 }
3504 }
3505 }
3506
3507 query.append(ORDER_BY_CLAUSE);
3508
3509 String[] orderByFields = orderByComparator.getOrderByFields();
3510
3511 for (int i = 0; i < orderByFields.length; i++) {
3512 query.append(_ORDER_BY_ENTITY_ALIAS);
3513 query.append(orderByFields[i]);
3514
3515 if ((i + 1) < orderByFields.length) {
3516 if (orderByComparator.isAscending() ^ previous) {
3517 query.append(ORDER_BY_ASC_HAS_NEXT);
3518 }
3519 else {
3520 query.append(ORDER_BY_DESC_HAS_NEXT);
3521 }
3522 }
3523 else {
3524 if (orderByComparator.isAscending() ^ previous) {
3525 query.append(ORDER_BY_ASC);
3526 }
3527 else {
3528 query.append(ORDER_BY_DESC);
3529 }
3530 }
3531 }
3532 }
3533
3534 String sql = query.toString();
3535
3536 Query q = session.createQuery(sql);
3537
3538 q.setFirstResult(0);
3539 q.setMaxResults(2);
3540
3541 QueryPos qPos = QueryPos.getInstance(q);
3542
3543 qPos.add(userId1);
3544
3545 qPos.add(userId2);
3546
3547 if (orderByComparator != null) {
3548 Object[] values = orderByComparator.getOrderByConditionValues(socialRelation);
3549
3550 for (Object value : values) {
3551 qPos.add(value);
3552 }
3553 }
3554
3555 List<SocialRelation> list = q.list();
3556
3557 if (list.size() == 2) {
3558 return list.get(1);
3559 }
3560 else {
3561 return null;
3562 }
3563 }
3564
3565
3573 public List<SocialRelation> findByU1_T(long userId1, int type)
3574 throws SystemException {
3575 return findByU1_T(userId1, type, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
3576 null);
3577 }
3578
3579
3593 public List<SocialRelation> findByU1_T(long userId1, int type, int start,
3594 int end) throws SystemException {
3595 return findByU1_T(userId1, type, start, end, null);
3596 }
3597
3598
3613 public List<SocialRelation> findByU1_T(long userId1, int type, int start,
3614 int end, OrderByComparator orderByComparator) throws SystemException {
3615 FinderPath finderPath = null;
3616 Object[] finderArgs = null;
3617
3618 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3619 (orderByComparator == null)) {
3620 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U1_T;
3621 finderArgs = new Object[] { userId1, type };
3622 }
3623 else {
3624 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U1_T;
3625 finderArgs = new Object[] {
3626 userId1, type,
3627
3628 start, end, orderByComparator
3629 };
3630 }
3631
3632 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(finderPath,
3633 finderArgs, this);
3634
3635 if ((list != null) && !list.isEmpty()) {
3636 for (SocialRelation socialRelation : list) {
3637 if ((userId1 != socialRelation.getUserId1()) ||
3638 (type != socialRelation.getType())) {
3639 list = null;
3640
3641 break;
3642 }
3643 }
3644 }
3645
3646 if (list == null) {
3647 StringBundler query = null;
3648
3649 if (orderByComparator != null) {
3650 query = new StringBundler(4 +
3651 (orderByComparator.getOrderByFields().length * 3));
3652 }
3653 else {
3654 query = new StringBundler(3);
3655 }
3656
3657 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
3658
3659 query.append(_FINDER_COLUMN_U1_T_USERID1_2);
3660
3661 query.append(_FINDER_COLUMN_U1_T_TYPE_2);
3662
3663 if (orderByComparator != null) {
3664 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3665 orderByComparator);
3666 }
3667
3668 String sql = query.toString();
3669
3670 Session session = null;
3671
3672 try {
3673 session = openSession();
3674
3675 Query q = session.createQuery(sql);
3676
3677 QueryPos qPos = QueryPos.getInstance(q);
3678
3679 qPos.add(userId1);
3680
3681 qPos.add(type);
3682
3683 list = (List<SocialRelation>)QueryUtil.list(q, getDialect(),
3684 start, end);
3685 }
3686 catch (Exception e) {
3687 throw processException(e);
3688 }
3689 finally {
3690 if (list == null) {
3691 FinderCacheUtil.removeResult(finderPath, finderArgs);
3692 }
3693 else {
3694 cacheResult(list);
3695
3696 FinderCacheUtil.putResult(finderPath, finderArgs, list);
3697 }
3698
3699 closeSession(session);
3700 }
3701 }
3702
3703 return list;
3704 }
3705
3706
3716 public SocialRelation findByU1_T_First(long userId1, int type,
3717 OrderByComparator orderByComparator)
3718 throws NoSuchRelationException, SystemException {
3719 SocialRelation socialRelation = fetchByU1_T_First(userId1, type,
3720 orderByComparator);
3721
3722 if (socialRelation != null) {
3723 return socialRelation;
3724 }
3725
3726 StringBundler msg = new StringBundler(6);
3727
3728 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3729
3730 msg.append("userId1=");
3731 msg.append(userId1);
3732
3733 msg.append(", type=");
3734 msg.append(type);
3735
3736 msg.append(StringPool.CLOSE_CURLY_BRACE);
3737
3738 throw new NoSuchRelationException(msg.toString());
3739 }
3740
3741
3750 public SocialRelation fetchByU1_T_First(long userId1, int type,
3751 OrderByComparator orderByComparator) throws SystemException {
3752 List<SocialRelation> list = findByU1_T(userId1, type, 0, 1,
3753 orderByComparator);
3754
3755 if (!list.isEmpty()) {
3756 return list.get(0);
3757 }
3758
3759 return null;
3760 }
3761
3762
3772 public SocialRelation findByU1_T_Last(long userId1, int type,
3773 OrderByComparator orderByComparator)
3774 throws NoSuchRelationException, SystemException {
3775 SocialRelation socialRelation = fetchByU1_T_Last(userId1, type,
3776 orderByComparator);
3777
3778 if (socialRelation != null) {
3779 return socialRelation;
3780 }
3781
3782 StringBundler msg = new StringBundler(6);
3783
3784 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3785
3786 msg.append("userId1=");
3787 msg.append(userId1);
3788
3789 msg.append(", type=");
3790 msg.append(type);
3791
3792 msg.append(StringPool.CLOSE_CURLY_BRACE);
3793
3794 throw new NoSuchRelationException(msg.toString());
3795 }
3796
3797
3806 public SocialRelation fetchByU1_T_Last(long userId1, int type,
3807 OrderByComparator orderByComparator) throws SystemException {
3808 int count = countByU1_T(userId1, type);
3809
3810 List<SocialRelation> list = findByU1_T(userId1, type, count - 1, count,
3811 orderByComparator);
3812
3813 if (!list.isEmpty()) {
3814 return list.get(0);
3815 }
3816
3817 return null;
3818 }
3819
3820
3831 public SocialRelation[] findByU1_T_PrevAndNext(long relationId,
3832 long userId1, int type, OrderByComparator orderByComparator)
3833 throws NoSuchRelationException, SystemException {
3834 SocialRelation socialRelation = findByPrimaryKey(relationId);
3835
3836 Session session = null;
3837
3838 try {
3839 session = openSession();
3840
3841 SocialRelation[] array = new SocialRelationImpl[3];
3842
3843 array[0] = getByU1_T_PrevAndNext(session, socialRelation, userId1,
3844 type, orderByComparator, true);
3845
3846 array[1] = socialRelation;
3847
3848 array[2] = getByU1_T_PrevAndNext(session, socialRelation, userId1,
3849 type, orderByComparator, false);
3850
3851 return array;
3852 }
3853 catch (Exception e) {
3854 throw processException(e);
3855 }
3856 finally {
3857 closeSession(session);
3858 }
3859 }
3860
3861 protected SocialRelation getByU1_T_PrevAndNext(Session session,
3862 SocialRelation socialRelation, long userId1, int type,
3863 OrderByComparator orderByComparator, boolean previous) {
3864 StringBundler query = null;
3865
3866 if (orderByComparator != null) {
3867 query = new StringBundler(6 +
3868 (orderByComparator.getOrderByFields().length * 6));
3869 }
3870 else {
3871 query = new StringBundler(3);
3872 }
3873
3874 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
3875
3876 query.append(_FINDER_COLUMN_U1_T_USERID1_2);
3877
3878 query.append(_FINDER_COLUMN_U1_T_TYPE_2);
3879
3880 if (orderByComparator != null) {
3881 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3882
3883 if (orderByConditionFields.length > 0) {
3884 query.append(WHERE_AND);
3885 }
3886
3887 for (int i = 0; i < orderByConditionFields.length; i++) {
3888 query.append(_ORDER_BY_ENTITY_ALIAS);
3889 query.append(orderByConditionFields[i]);
3890
3891 if ((i + 1) < orderByConditionFields.length) {
3892 if (orderByComparator.isAscending() ^ previous) {
3893 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3894 }
3895 else {
3896 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3897 }
3898 }
3899 else {
3900 if (orderByComparator.isAscending() ^ previous) {
3901 query.append(WHERE_GREATER_THAN);
3902 }
3903 else {
3904 query.append(WHERE_LESSER_THAN);
3905 }
3906 }
3907 }
3908
3909 query.append(ORDER_BY_CLAUSE);
3910
3911 String[] orderByFields = orderByComparator.getOrderByFields();
3912
3913 for (int i = 0; i < orderByFields.length; i++) {
3914 query.append(_ORDER_BY_ENTITY_ALIAS);
3915 query.append(orderByFields[i]);
3916
3917 if ((i + 1) < orderByFields.length) {
3918 if (orderByComparator.isAscending() ^ previous) {
3919 query.append(ORDER_BY_ASC_HAS_NEXT);
3920 }
3921 else {
3922 query.append(ORDER_BY_DESC_HAS_NEXT);
3923 }
3924 }
3925 else {
3926 if (orderByComparator.isAscending() ^ previous) {
3927 query.append(ORDER_BY_ASC);
3928 }
3929 else {
3930 query.append(ORDER_BY_DESC);
3931 }
3932 }
3933 }
3934 }
3935
3936 String sql = query.toString();
3937
3938 Query q = session.createQuery(sql);
3939
3940 q.setFirstResult(0);
3941 q.setMaxResults(2);
3942
3943 QueryPos qPos = QueryPos.getInstance(q);
3944
3945 qPos.add(userId1);
3946
3947 qPos.add(type);
3948
3949 if (orderByComparator != null) {
3950 Object[] values = orderByComparator.getOrderByConditionValues(socialRelation);
3951
3952 for (Object value : values) {
3953 qPos.add(value);
3954 }
3955 }
3956
3957 List<SocialRelation> list = q.list();
3958
3959 if (list.size() == 2) {
3960 return list.get(1);
3961 }
3962 else {
3963 return null;
3964 }
3965 }
3966
3967
3975 public List<SocialRelation> findByU2_T(long userId2, int type)
3976 throws SystemException {
3977 return findByU2_T(userId2, type, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
3978 null);
3979 }
3980
3981
3995 public List<SocialRelation> findByU2_T(long userId2, int type, int start,
3996 int end) throws SystemException {
3997 return findByU2_T(userId2, type, start, end, null);
3998 }
3999
4000
4015 public List<SocialRelation> findByU2_T(long userId2, int type, int start,
4016 int end, OrderByComparator orderByComparator) throws SystemException {
4017 FinderPath finderPath = null;
4018 Object[] finderArgs = null;
4019
4020 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4021 (orderByComparator == null)) {
4022 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U2_T;
4023 finderArgs = new Object[] { userId2, type };
4024 }
4025 else {
4026 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U2_T;
4027 finderArgs = new Object[] {
4028 userId2, type,
4029
4030 start, end, orderByComparator
4031 };
4032 }
4033
4034 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(finderPath,
4035 finderArgs, this);
4036
4037 if ((list != null) && !list.isEmpty()) {
4038 for (SocialRelation socialRelation : list) {
4039 if ((userId2 != socialRelation.getUserId2()) ||
4040 (type != socialRelation.getType())) {
4041 list = null;
4042
4043 break;
4044 }
4045 }
4046 }
4047
4048 if (list == null) {
4049 StringBundler query = null;
4050
4051 if (orderByComparator != null) {
4052 query = new StringBundler(4 +
4053 (orderByComparator.getOrderByFields().length * 3));
4054 }
4055 else {
4056 query = new StringBundler(3);
4057 }
4058
4059 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
4060
4061 query.append(_FINDER_COLUMN_U2_T_USERID2_2);
4062
4063 query.append(_FINDER_COLUMN_U2_T_TYPE_2);
4064
4065 if (orderByComparator != null) {
4066 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4067 orderByComparator);
4068 }
4069
4070 String sql = query.toString();
4071
4072 Session session = null;
4073
4074 try {
4075 session = openSession();
4076
4077 Query q = session.createQuery(sql);
4078
4079 QueryPos qPos = QueryPos.getInstance(q);
4080
4081 qPos.add(userId2);
4082
4083 qPos.add(type);
4084
4085 list = (List<SocialRelation>)QueryUtil.list(q, getDialect(),
4086 start, end);
4087 }
4088 catch (Exception e) {
4089 throw processException(e);
4090 }
4091 finally {
4092 if (list == null) {
4093 FinderCacheUtil.removeResult(finderPath, finderArgs);
4094 }
4095 else {
4096 cacheResult(list);
4097
4098 FinderCacheUtil.putResult(finderPath, finderArgs, list);
4099 }
4100
4101 closeSession(session);
4102 }
4103 }
4104
4105 return list;
4106 }
4107
4108
4118 public SocialRelation findByU2_T_First(long userId2, int type,
4119 OrderByComparator orderByComparator)
4120 throws NoSuchRelationException, SystemException {
4121 SocialRelation socialRelation = fetchByU2_T_First(userId2, type,
4122 orderByComparator);
4123
4124 if (socialRelation != null) {
4125 return socialRelation;
4126 }
4127
4128 StringBundler msg = new StringBundler(6);
4129
4130 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4131
4132 msg.append("userId2=");
4133 msg.append(userId2);
4134
4135 msg.append(", type=");
4136 msg.append(type);
4137
4138 msg.append(StringPool.CLOSE_CURLY_BRACE);
4139
4140 throw new NoSuchRelationException(msg.toString());
4141 }
4142
4143
4152 public SocialRelation fetchByU2_T_First(long userId2, int type,
4153 OrderByComparator orderByComparator) throws SystemException {
4154 List<SocialRelation> list = findByU2_T(userId2, type, 0, 1,
4155 orderByComparator);
4156
4157 if (!list.isEmpty()) {
4158 return list.get(0);
4159 }
4160
4161 return null;
4162 }
4163
4164
4174 public SocialRelation findByU2_T_Last(long userId2, int type,
4175 OrderByComparator orderByComparator)
4176 throws NoSuchRelationException, SystemException {
4177 SocialRelation socialRelation = fetchByU2_T_Last(userId2, type,
4178 orderByComparator);
4179
4180 if (socialRelation != null) {
4181 return socialRelation;
4182 }
4183
4184 StringBundler msg = new StringBundler(6);
4185
4186 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4187
4188 msg.append("userId2=");
4189 msg.append(userId2);
4190
4191 msg.append(", type=");
4192 msg.append(type);
4193
4194 msg.append(StringPool.CLOSE_CURLY_BRACE);
4195
4196 throw new NoSuchRelationException(msg.toString());
4197 }
4198
4199
4208 public SocialRelation fetchByU2_T_Last(long userId2, int type,
4209 OrderByComparator orderByComparator) throws SystemException {
4210 int count = countByU2_T(userId2, type);
4211
4212 List<SocialRelation> list = findByU2_T(userId2, type, count - 1, count,
4213 orderByComparator);
4214
4215 if (!list.isEmpty()) {
4216 return list.get(0);
4217 }
4218
4219 return null;
4220 }
4221
4222
4233 public SocialRelation[] findByU2_T_PrevAndNext(long relationId,
4234 long userId2, int type, OrderByComparator orderByComparator)
4235 throws NoSuchRelationException, SystemException {
4236 SocialRelation socialRelation = findByPrimaryKey(relationId);
4237
4238 Session session = null;
4239
4240 try {
4241 session = openSession();
4242
4243 SocialRelation[] array = new SocialRelationImpl[3];
4244
4245 array[0] = getByU2_T_PrevAndNext(session, socialRelation, userId2,
4246 type, orderByComparator, true);
4247
4248 array[1] = socialRelation;
4249
4250 array[2] = getByU2_T_PrevAndNext(session, socialRelation, userId2,
4251 type, orderByComparator, false);
4252
4253 return array;
4254 }
4255 catch (Exception e) {
4256 throw processException(e);
4257 }
4258 finally {
4259 closeSession(session);
4260 }
4261 }
4262
4263 protected SocialRelation getByU2_T_PrevAndNext(Session session,
4264 SocialRelation socialRelation, long userId2, int type,
4265 OrderByComparator orderByComparator, boolean previous) {
4266 StringBundler query = null;
4267
4268 if (orderByComparator != null) {
4269 query = new StringBundler(6 +
4270 (orderByComparator.getOrderByFields().length * 6));
4271 }
4272 else {
4273 query = new StringBundler(3);
4274 }
4275
4276 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
4277
4278 query.append(_FINDER_COLUMN_U2_T_USERID2_2);
4279
4280 query.append(_FINDER_COLUMN_U2_T_TYPE_2);
4281
4282 if (orderByComparator != null) {
4283 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4284
4285 if (orderByConditionFields.length > 0) {
4286 query.append(WHERE_AND);
4287 }
4288
4289 for (int i = 0; i < orderByConditionFields.length; i++) {
4290 query.append(_ORDER_BY_ENTITY_ALIAS);
4291 query.append(orderByConditionFields[i]);
4292
4293 if ((i + 1) < orderByConditionFields.length) {
4294 if (orderByComparator.isAscending() ^ previous) {
4295 query.append(WHERE_GREATER_THAN_HAS_NEXT);
4296 }
4297 else {
4298 query.append(WHERE_LESSER_THAN_HAS_NEXT);
4299 }
4300 }
4301 else {
4302 if (orderByComparator.isAscending() ^ previous) {
4303 query.append(WHERE_GREATER_THAN);
4304 }
4305 else {
4306 query.append(WHERE_LESSER_THAN);
4307 }
4308 }
4309 }
4310
4311 query.append(ORDER_BY_CLAUSE);
4312
4313 String[] orderByFields = orderByComparator.getOrderByFields();
4314
4315 for (int i = 0; i < orderByFields.length; i++) {
4316 query.append(_ORDER_BY_ENTITY_ALIAS);
4317 query.append(orderByFields[i]);
4318
4319 if ((i + 1) < orderByFields.length) {
4320 if (orderByComparator.isAscending() ^ previous) {
4321 query.append(ORDER_BY_ASC_HAS_NEXT);
4322 }
4323 else {
4324 query.append(ORDER_BY_DESC_HAS_NEXT);
4325 }
4326 }
4327 else {
4328 if (orderByComparator.isAscending() ^ previous) {
4329 query.append(ORDER_BY_ASC);
4330 }
4331 else {
4332 query.append(ORDER_BY_DESC);
4333 }
4334 }
4335 }
4336 }
4337
4338 String sql = query.toString();
4339
4340 Query q = session.createQuery(sql);
4341
4342 q.setFirstResult(0);
4343 q.setMaxResults(2);
4344
4345 QueryPos qPos = QueryPos.getInstance(q);
4346
4347 qPos.add(userId2);
4348
4349 qPos.add(type);
4350
4351 if (orderByComparator != null) {
4352 Object[] values = orderByComparator.getOrderByConditionValues(socialRelation);
4353
4354 for (Object value : values) {
4355 qPos.add(value);
4356 }
4357 }
4358
4359 List<SocialRelation> list = q.list();
4360
4361 if (list.size() == 2) {
4362 return list.get(1);
4363 }
4364 else {
4365 return null;
4366 }
4367 }
4368
4369
4379 public SocialRelation findByU1_U2_T(long userId1, long userId2, int type)
4380 throws NoSuchRelationException, SystemException {
4381 SocialRelation socialRelation = fetchByU1_U2_T(userId1, userId2, type);
4382
4383 if (socialRelation == null) {
4384 StringBundler msg = new StringBundler(8);
4385
4386 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4387
4388 msg.append("userId1=");
4389 msg.append(userId1);
4390
4391 msg.append(", userId2=");
4392 msg.append(userId2);
4393
4394 msg.append(", type=");
4395 msg.append(type);
4396
4397 msg.append(StringPool.CLOSE_CURLY_BRACE);
4398
4399 if (_log.isWarnEnabled()) {
4400 _log.warn(msg.toString());
4401 }
4402
4403 throw new NoSuchRelationException(msg.toString());
4404 }
4405
4406 return socialRelation;
4407 }
4408
4409
4418 public SocialRelation fetchByU1_U2_T(long userId1, long userId2, int type)
4419 throws SystemException {
4420 return fetchByU1_U2_T(userId1, userId2, type, true);
4421 }
4422
4423
4433 public SocialRelation fetchByU1_U2_T(long userId1, long userId2, int type,
4434 boolean retrieveFromCache) throws SystemException {
4435 Object[] finderArgs = new Object[] { userId1, userId2, type };
4436
4437 Object result = null;
4438
4439 if (retrieveFromCache) {
4440 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_U1_U2_T,
4441 finderArgs, this);
4442 }
4443
4444 if (result instanceof SocialRelation) {
4445 SocialRelation socialRelation = (SocialRelation)result;
4446
4447 if ((userId1 != socialRelation.getUserId1()) ||
4448 (userId2 != socialRelation.getUserId2()) ||
4449 (type != socialRelation.getType())) {
4450 result = null;
4451 }
4452 }
4453
4454 if (result == null) {
4455 StringBundler query = new StringBundler(4);
4456
4457 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
4458
4459 query.append(_FINDER_COLUMN_U1_U2_T_USERID1_2);
4460
4461 query.append(_FINDER_COLUMN_U1_U2_T_USERID2_2);
4462
4463 query.append(_FINDER_COLUMN_U1_U2_T_TYPE_2);
4464
4465 String sql = query.toString();
4466
4467 Session session = null;
4468
4469 try {
4470 session = openSession();
4471
4472 Query q = session.createQuery(sql);
4473
4474 QueryPos qPos = QueryPos.getInstance(q);
4475
4476 qPos.add(userId1);
4477
4478 qPos.add(userId2);
4479
4480 qPos.add(type);
4481
4482 List<SocialRelation> list = q.list();
4483
4484 result = list;
4485
4486 SocialRelation socialRelation = null;
4487
4488 if (list.isEmpty()) {
4489 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U1_U2_T,
4490 finderArgs, list);
4491 }
4492 else {
4493 socialRelation = list.get(0);
4494
4495 cacheResult(socialRelation);
4496
4497 if ((socialRelation.getUserId1() != userId1) ||
4498 (socialRelation.getUserId2() != userId2) ||
4499 (socialRelation.getType() != type)) {
4500 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U1_U2_T,
4501 finderArgs, socialRelation);
4502 }
4503 }
4504
4505 return socialRelation;
4506 }
4507 catch (Exception e) {
4508 throw processException(e);
4509 }
4510 finally {
4511 if (result == null) {
4512 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U1_U2_T,
4513 finderArgs);
4514 }
4515
4516 closeSession(session);
4517 }
4518 }
4519 else {
4520 if (result instanceof List<?>) {
4521 return null;
4522 }
4523 else {
4524 return (SocialRelation)result;
4525 }
4526 }
4527 }
4528
4529
4535 public List<SocialRelation> findAll() throws SystemException {
4536 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
4537 }
4538
4539
4551 public List<SocialRelation> findAll(int start, int end)
4552 throws SystemException {
4553 return findAll(start, end, null);
4554 }
4555
4556
4569 public List<SocialRelation> findAll(int start, int end,
4570 OrderByComparator orderByComparator) throws SystemException {
4571 FinderPath finderPath = null;
4572 Object[] finderArgs = new Object[] { start, end, orderByComparator };
4573
4574 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4575 (orderByComparator == null)) {
4576 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
4577 finderArgs = FINDER_ARGS_EMPTY;
4578 }
4579 else {
4580 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
4581 finderArgs = new Object[] { start, end, orderByComparator };
4582 }
4583
4584 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(finderPath,
4585 finderArgs, this);
4586
4587 if (list == null) {
4588 StringBundler query = null;
4589 String sql = null;
4590
4591 if (orderByComparator != null) {
4592 query = new StringBundler(2 +
4593 (orderByComparator.getOrderByFields().length * 3));
4594
4595 query.append(_SQL_SELECT_SOCIALRELATION);
4596
4597 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4598 orderByComparator);
4599
4600 sql = query.toString();
4601 }
4602 else {
4603 sql = _SQL_SELECT_SOCIALRELATION;
4604 }
4605
4606 Session session = null;
4607
4608 try {
4609 session = openSession();
4610
4611 Query q = session.createQuery(sql);
4612
4613 if (orderByComparator == null) {
4614 list = (List<SocialRelation>)QueryUtil.list(q,
4615 getDialect(), start, end, false);
4616
4617 Collections.sort(list);
4618 }
4619 else {
4620 list = (List<SocialRelation>)QueryUtil.list(q,
4621 getDialect(), start, end);
4622 }
4623 }
4624 catch (Exception e) {
4625 throw processException(e);
4626 }
4627 finally {
4628 if (list == null) {
4629 FinderCacheUtil.removeResult(finderPath, finderArgs);
4630 }
4631 else {
4632 cacheResult(list);
4633
4634 FinderCacheUtil.putResult(finderPath, finderArgs, list);
4635 }
4636
4637 closeSession(session);
4638 }
4639 }
4640
4641 return list;
4642 }
4643
4644
4650 public void removeByUuid(String uuid) throws SystemException {
4651 for (SocialRelation socialRelation : findByUuid(uuid)) {
4652 remove(socialRelation);
4653 }
4654 }
4655
4656
4662 public void removeByCompanyId(long companyId) throws SystemException {
4663 for (SocialRelation socialRelation : findByCompanyId(companyId)) {
4664 remove(socialRelation);
4665 }
4666 }
4667
4668
4674 public void removeByUserId1(long userId1) throws SystemException {
4675 for (SocialRelation socialRelation : findByUserId1(userId1)) {
4676 remove(socialRelation);
4677 }
4678 }
4679
4680
4686 public void removeByUserId2(long userId2) throws SystemException {
4687 for (SocialRelation socialRelation : findByUserId2(userId2)) {
4688 remove(socialRelation);
4689 }
4690 }
4691
4692
4698 public void removeByType(int type) throws SystemException {
4699 for (SocialRelation socialRelation : findByType(type)) {
4700 remove(socialRelation);
4701 }
4702 }
4703
4704
4711 public void removeByC_T(long companyId, int type) throws SystemException {
4712 for (SocialRelation socialRelation : findByC_T(companyId, type)) {
4713 remove(socialRelation);
4714 }
4715 }
4716
4717
4724 public void removeByU1_U2(long userId1, long userId2)
4725 throws SystemException {
4726 for (SocialRelation socialRelation : findByU1_U2(userId1, userId2)) {
4727 remove(socialRelation);
4728 }
4729 }
4730
4731
4738 public void removeByU1_T(long userId1, int type) throws SystemException {
4739 for (SocialRelation socialRelation : findByU1_T(userId1, type)) {
4740 remove(socialRelation);
4741 }
4742 }
4743
4744
4751 public void removeByU2_T(long userId2, int type) throws SystemException {
4752 for (SocialRelation socialRelation : findByU2_T(userId2, type)) {
4753 remove(socialRelation);
4754 }
4755 }
4756
4757
4766 public SocialRelation removeByU1_U2_T(long userId1, long userId2, int type)
4767 throws NoSuchRelationException, SystemException {
4768 SocialRelation socialRelation = findByU1_U2_T(userId1, userId2, type);
4769
4770 return remove(socialRelation);
4771 }
4772
4773
4778 public void removeAll() throws SystemException {
4779 for (SocialRelation socialRelation : findAll()) {
4780 remove(socialRelation);
4781 }
4782 }
4783
4784
4791 public int countByUuid(String uuid) throws SystemException {
4792 Object[] finderArgs = new Object[] { uuid };
4793
4794 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
4795 finderArgs, this);
4796
4797 if (count == null) {
4798 StringBundler query = new StringBundler(2);
4799
4800 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
4801
4802 if (uuid == null) {
4803 query.append(_FINDER_COLUMN_UUID_UUID_1);
4804 }
4805 else {
4806 if (uuid.equals(StringPool.BLANK)) {
4807 query.append(_FINDER_COLUMN_UUID_UUID_3);
4808 }
4809 else {
4810 query.append(_FINDER_COLUMN_UUID_UUID_2);
4811 }
4812 }
4813
4814 String sql = query.toString();
4815
4816 Session session = null;
4817
4818 try {
4819 session = openSession();
4820
4821 Query q = session.createQuery(sql);
4822
4823 QueryPos qPos = QueryPos.getInstance(q);
4824
4825 if (uuid != null) {
4826 qPos.add(uuid);
4827 }
4828
4829 count = (Long)q.uniqueResult();
4830 }
4831 catch (Exception e) {
4832 throw processException(e);
4833 }
4834 finally {
4835 if (count == null) {
4836 count = Long.valueOf(0);
4837 }
4838
4839 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
4840 finderArgs, count);
4841
4842 closeSession(session);
4843 }
4844 }
4845
4846 return count.intValue();
4847 }
4848
4849
4856 public int countByCompanyId(long companyId) throws SystemException {
4857 Object[] finderArgs = new Object[] { companyId };
4858
4859 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
4860 finderArgs, this);
4861
4862 if (count == null) {
4863 StringBundler query = new StringBundler(2);
4864
4865 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
4866
4867 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
4868
4869 String sql = query.toString();
4870
4871 Session session = null;
4872
4873 try {
4874 session = openSession();
4875
4876 Query q = session.createQuery(sql);
4877
4878 QueryPos qPos = QueryPos.getInstance(q);
4879
4880 qPos.add(companyId);
4881
4882 count = (Long)q.uniqueResult();
4883 }
4884 catch (Exception e) {
4885 throw processException(e);
4886 }
4887 finally {
4888 if (count == null) {
4889 count = Long.valueOf(0);
4890 }
4891
4892 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
4893 finderArgs, count);
4894
4895 closeSession(session);
4896 }
4897 }
4898
4899 return count.intValue();
4900 }
4901
4902
4909 public int countByUserId1(long userId1) throws SystemException {
4910 Object[] finderArgs = new Object[] { userId1 };
4911
4912 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID1,
4913 finderArgs, this);
4914
4915 if (count == null) {
4916 StringBundler query = new StringBundler(2);
4917
4918 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
4919
4920 query.append(_FINDER_COLUMN_USERID1_USERID1_2);
4921
4922 String sql = query.toString();
4923
4924 Session session = null;
4925
4926 try {
4927 session = openSession();
4928
4929 Query q = session.createQuery(sql);
4930
4931 QueryPos qPos = QueryPos.getInstance(q);
4932
4933 qPos.add(userId1);
4934
4935 count = (Long)q.uniqueResult();
4936 }
4937 catch (Exception e) {
4938 throw processException(e);
4939 }
4940 finally {
4941 if (count == null) {
4942 count = Long.valueOf(0);
4943 }
4944
4945 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID1,
4946 finderArgs, count);
4947
4948 closeSession(session);
4949 }
4950 }
4951
4952 return count.intValue();
4953 }
4954
4955
4962 public int countByUserId2(long userId2) throws SystemException {
4963 Object[] finderArgs = new Object[] { userId2 };
4964
4965 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID2,
4966 finderArgs, this);
4967
4968 if (count == null) {
4969 StringBundler query = new StringBundler(2);
4970
4971 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
4972
4973 query.append(_FINDER_COLUMN_USERID2_USERID2_2);
4974
4975 String sql = query.toString();
4976
4977 Session session = null;
4978
4979 try {
4980 session = openSession();
4981
4982 Query q = session.createQuery(sql);
4983
4984 QueryPos qPos = QueryPos.getInstance(q);
4985
4986 qPos.add(userId2);
4987
4988 count = (Long)q.uniqueResult();
4989 }
4990 catch (Exception e) {
4991 throw processException(e);
4992 }
4993 finally {
4994 if (count == null) {
4995 count = Long.valueOf(0);
4996 }
4997
4998 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID2,
4999 finderArgs, count);
5000
5001 closeSession(session);
5002 }
5003 }
5004
5005 return count.intValue();
5006 }
5007
5008
5015 public int countByType(int type) throws SystemException {
5016 Object[] finderArgs = new Object[] { type };
5017
5018 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_TYPE,
5019 finderArgs, this);
5020
5021 if (count == null) {
5022 StringBundler query = new StringBundler(2);
5023
5024 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
5025
5026 query.append(_FINDER_COLUMN_TYPE_TYPE_2);
5027
5028 String sql = query.toString();
5029
5030 Session session = null;
5031
5032 try {
5033 session = openSession();
5034
5035 Query q = session.createQuery(sql);
5036
5037 QueryPos qPos = QueryPos.getInstance(q);
5038
5039 qPos.add(type);
5040
5041 count = (Long)q.uniqueResult();
5042 }
5043 catch (Exception e) {
5044 throw processException(e);
5045 }
5046 finally {
5047 if (count == null) {
5048 count = Long.valueOf(0);
5049 }
5050
5051 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_TYPE,
5052 finderArgs, count);
5053
5054 closeSession(session);
5055 }
5056 }
5057
5058 return count.intValue();
5059 }
5060
5061
5069 public int countByC_T(long companyId, int type) throws SystemException {
5070 Object[] finderArgs = new Object[] { companyId, type };
5071
5072 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_T,
5073 finderArgs, this);
5074
5075 if (count == null) {
5076 StringBundler query = new StringBundler(3);
5077
5078 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
5079
5080 query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
5081
5082 query.append(_FINDER_COLUMN_C_T_TYPE_2);
5083
5084 String sql = query.toString();
5085
5086 Session session = null;
5087
5088 try {
5089 session = openSession();
5090
5091 Query q = session.createQuery(sql);
5092
5093 QueryPos qPos = QueryPos.getInstance(q);
5094
5095 qPos.add(companyId);
5096
5097 qPos.add(type);
5098
5099 count = (Long)q.uniqueResult();
5100 }
5101 catch (Exception e) {
5102 throw processException(e);
5103 }
5104 finally {
5105 if (count == null) {
5106 count = Long.valueOf(0);
5107 }
5108
5109 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_T, finderArgs,
5110 count);
5111
5112 closeSession(session);
5113 }
5114 }
5115
5116 return count.intValue();
5117 }
5118
5119
5127 public int countByU1_U2(long userId1, long userId2)
5128 throws SystemException {
5129 Object[] finderArgs = new Object[] { userId1, userId2 };
5130
5131 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U1_U2,
5132 finderArgs, this);
5133
5134 if (count == null) {
5135 StringBundler query = new StringBundler(3);
5136
5137 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
5138
5139 query.append(_FINDER_COLUMN_U1_U2_USERID1_2);
5140
5141 query.append(_FINDER_COLUMN_U1_U2_USERID2_2);
5142
5143 String sql = query.toString();
5144
5145 Session session = null;
5146
5147 try {
5148 session = openSession();
5149
5150 Query q = session.createQuery(sql);
5151
5152 QueryPos qPos = QueryPos.getInstance(q);
5153
5154 qPos.add(userId1);
5155
5156 qPos.add(userId2);
5157
5158 count = (Long)q.uniqueResult();
5159 }
5160 catch (Exception e) {
5161 throw processException(e);
5162 }
5163 finally {
5164 if (count == null) {
5165 count = Long.valueOf(0);
5166 }
5167
5168 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U1_U2,
5169 finderArgs, count);
5170
5171 closeSession(session);
5172 }
5173 }
5174
5175 return count.intValue();
5176 }
5177
5178
5186 public int countByU1_T(long userId1, int type) throws SystemException {
5187 Object[] finderArgs = new Object[] { userId1, type };
5188
5189 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U1_T,
5190 finderArgs, this);
5191
5192 if (count == null) {
5193 StringBundler query = new StringBundler(3);
5194
5195 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
5196
5197 query.append(_FINDER_COLUMN_U1_T_USERID1_2);
5198
5199 query.append(_FINDER_COLUMN_U1_T_TYPE_2);
5200
5201 String sql = query.toString();
5202
5203 Session session = null;
5204
5205 try {
5206 session = openSession();
5207
5208 Query q = session.createQuery(sql);
5209
5210 QueryPos qPos = QueryPos.getInstance(q);
5211
5212 qPos.add(userId1);
5213
5214 qPos.add(type);
5215
5216 count = (Long)q.uniqueResult();
5217 }
5218 catch (Exception e) {
5219 throw processException(e);
5220 }
5221 finally {
5222 if (count == null) {
5223 count = Long.valueOf(0);
5224 }
5225
5226 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U1_T,
5227 finderArgs, count);
5228
5229 closeSession(session);
5230 }
5231 }
5232
5233 return count.intValue();
5234 }
5235
5236
5244 public int countByU2_T(long userId2, int type) throws SystemException {
5245 Object[] finderArgs = new Object[] { userId2, type };
5246
5247 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U2_T,
5248 finderArgs, this);
5249
5250 if (count == null) {
5251 StringBundler query = new StringBundler(3);
5252
5253 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
5254
5255 query.append(_FINDER_COLUMN_U2_T_USERID2_2);
5256
5257 query.append(_FINDER_COLUMN_U2_T_TYPE_2);
5258
5259 String sql = query.toString();
5260
5261 Session session = null;
5262
5263 try {
5264 session = openSession();
5265
5266 Query q = session.createQuery(sql);
5267
5268 QueryPos qPos = QueryPos.getInstance(q);
5269
5270 qPos.add(userId2);
5271
5272 qPos.add(type);
5273
5274 count = (Long)q.uniqueResult();
5275 }
5276 catch (Exception e) {
5277 throw processException(e);
5278 }
5279 finally {
5280 if (count == null) {
5281 count = Long.valueOf(0);
5282 }
5283
5284 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U2_T,
5285 finderArgs, count);
5286
5287 closeSession(session);
5288 }
5289 }
5290
5291 return count.intValue();
5292 }
5293
5294
5303 public int countByU1_U2_T(long userId1, long userId2, int type)
5304 throws SystemException {
5305 Object[] finderArgs = new Object[] { userId1, userId2, type };
5306
5307 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U1_U2_T,
5308 finderArgs, this);
5309
5310 if (count == null) {
5311 StringBundler query = new StringBundler(4);
5312
5313 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
5314
5315 query.append(_FINDER_COLUMN_U1_U2_T_USERID1_2);
5316
5317 query.append(_FINDER_COLUMN_U1_U2_T_USERID2_2);
5318
5319 query.append(_FINDER_COLUMN_U1_U2_T_TYPE_2);
5320
5321 String sql = query.toString();
5322
5323 Session session = null;
5324
5325 try {
5326 session = openSession();
5327
5328 Query q = session.createQuery(sql);
5329
5330 QueryPos qPos = QueryPos.getInstance(q);
5331
5332 qPos.add(userId1);
5333
5334 qPos.add(userId2);
5335
5336 qPos.add(type);
5337
5338 count = (Long)q.uniqueResult();
5339 }
5340 catch (Exception e) {
5341 throw processException(e);
5342 }
5343 finally {
5344 if (count == null) {
5345 count = Long.valueOf(0);
5346 }
5347
5348 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U1_U2_T,
5349 finderArgs, count);
5350
5351 closeSession(session);
5352 }
5353 }
5354
5355 return count.intValue();
5356 }
5357
5358
5364 public int countAll() throws SystemException {
5365 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
5366 FINDER_ARGS_EMPTY, this);
5367
5368 if (count == null) {
5369 Session session = null;
5370
5371 try {
5372 session = openSession();
5373
5374 Query q = session.createQuery(_SQL_COUNT_SOCIALRELATION);
5375
5376 count = (Long)q.uniqueResult();
5377 }
5378 catch (Exception e) {
5379 throw processException(e);
5380 }
5381 finally {
5382 if (count == null) {
5383 count = Long.valueOf(0);
5384 }
5385
5386 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
5387 FINDER_ARGS_EMPTY, count);
5388
5389 closeSession(session);
5390 }
5391 }
5392
5393 return count.intValue();
5394 }
5395
5396
5399 public void afterPropertiesSet() {
5400 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
5401 com.liferay.portal.util.PropsUtil.get(
5402 "value.object.listener.com.liferay.portlet.social.model.SocialRelation")));
5403
5404 if (listenerClassNames.length > 0) {
5405 try {
5406 List<ModelListener<SocialRelation>> listenersList = new ArrayList<ModelListener<SocialRelation>>();
5407
5408 for (String listenerClassName : listenerClassNames) {
5409 listenersList.add((ModelListener<SocialRelation>)InstanceFactory.newInstance(
5410 listenerClassName));
5411 }
5412
5413 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
5414 }
5415 catch (Exception e) {
5416 _log.error(e);
5417 }
5418 }
5419 }
5420
5421 public void destroy() {
5422 EntityCacheUtil.removeCache(SocialRelationImpl.class.getName());
5423 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
5424 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
5425 }
5426
5427 @BeanReference(type = SocialActivityPersistence.class)
5428 protected SocialActivityPersistence socialActivityPersistence;
5429 @BeanReference(type = SocialActivityAchievementPersistence.class)
5430 protected SocialActivityAchievementPersistence socialActivityAchievementPersistence;
5431 @BeanReference(type = SocialActivityCounterPersistence.class)
5432 protected SocialActivityCounterPersistence socialActivityCounterPersistence;
5433 @BeanReference(type = SocialActivityLimitPersistence.class)
5434 protected SocialActivityLimitPersistence socialActivityLimitPersistence;
5435 @BeanReference(type = SocialActivitySettingPersistence.class)
5436 protected SocialActivitySettingPersistence socialActivitySettingPersistence;
5437 @BeanReference(type = SocialRelationPersistence.class)
5438 protected SocialRelationPersistence socialRelationPersistence;
5439 @BeanReference(type = SocialRequestPersistence.class)
5440 protected SocialRequestPersistence socialRequestPersistence;
5441 @BeanReference(type = ResourcePersistence.class)
5442 protected ResourcePersistence resourcePersistence;
5443 @BeanReference(type = UserPersistence.class)
5444 protected UserPersistence userPersistence;
5445 private static final String _SQL_SELECT_SOCIALRELATION = "SELECT socialRelation FROM SocialRelation socialRelation";
5446 private static final String _SQL_SELECT_SOCIALRELATION_WHERE = "SELECT socialRelation FROM SocialRelation socialRelation WHERE ";
5447 private static final String _SQL_COUNT_SOCIALRELATION = "SELECT COUNT(socialRelation) FROM SocialRelation socialRelation";
5448 private static final String _SQL_COUNT_SOCIALRELATION_WHERE = "SELECT COUNT(socialRelation) FROM SocialRelation socialRelation WHERE ";
5449 private static final String _FINDER_COLUMN_UUID_UUID_1 = "socialRelation.uuid IS NULL";
5450 private static final String _FINDER_COLUMN_UUID_UUID_2 = "socialRelation.uuid = ?";
5451 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(socialRelation.uuid IS NULL OR socialRelation.uuid = ?)";
5452 private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "socialRelation.companyId = ?";
5453 private static final String _FINDER_COLUMN_USERID1_USERID1_2 = "socialRelation.userId1 = ?";
5454 private static final String _FINDER_COLUMN_USERID2_USERID2_2 = "socialRelation.userId2 = ?";
5455 private static final String _FINDER_COLUMN_TYPE_TYPE_2 = "socialRelation.type = ?";
5456 private static final String _FINDER_COLUMN_C_T_COMPANYID_2 = "socialRelation.companyId = ? AND ";
5457 private static final String _FINDER_COLUMN_C_T_TYPE_2 = "socialRelation.type = ?";
5458 private static final String _FINDER_COLUMN_U1_U2_USERID1_2 = "socialRelation.userId1 = ? AND ";
5459 private static final String _FINDER_COLUMN_U1_U2_USERID2_2 = "socialRelation.userId2 = ?";
5460 private static final String _FINDER_COLUMN_U1_T_USERID1_2 = "socialRelation.userId1 = ? AND ";
5461 private static final String _FINDER_COLUMN_U1_T_TYPE_2 = "socialRelation.type = ?";
5462 private static final String _FINDER_COLUMN_U2_T_USERID2_2 = "socialRelation.userId2 = ? AND ";
5463 private static final String _FINDER_COLUMN_U2_T_TYPE_2 = "socialRelation.type = ?";
5464 private static final String _FINDER_COLUMN_U1_U2_T_USERID1_2 = "socialRelation.userId1 = ? AND ";
5465 private static final String _FINDER_COLUMN_U1_U2_T_USERID2_2 = "socialRelation.userId2 = ? AND ";
5466 private static final String _FINDER_COLUMN_U1_U2_T_TYPE_2 = "socialRelation.type = ?";
5467 private static final String _ORDER_BY_ENTITY_ALIAS = "socialRelation.";
5468 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No SocialRelation exists with the primary key ";
5469 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No SocialRelation exists with the key {";
5470 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
5471 private static Log _log = LogFactoryUtil.getLog(SocialRelationPersistenceImpl.class);
5472 private static SocialRelation _nullSocialRelation = new SocialRelationImpl() {
5473 @Override
5474 public Object clone() {
5475 return this;
5476 }
5477
5478 @Override
5479 public CacheModel<SocialRelation> toCacheModel() {
5480 return _nullSocialRelationCacheModel;
5481 }
5482 };
5483
5484 private static CacheModel<SocialRelation> _nullSocialRelationCacheModel = new CacheModel<SocialRelation>() {
5485 public SocialRelation toEntityModel() {
5486 return _nullSocialRelation;
5487 }
5488 };
5489 }