001
014
015 package com.liferay.portlet.social.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
018 import com.liferay.portal.kernel.bean.BeanReference;
019 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderPath;
023 import com.liferay.portal.kernel.dao.orm.Query;
024 import com.liferay.portal.kernel.dao.orm.QueryPos;
025 import com.liferay.portal.kernel.dao.orm.QueryUtil;
026 import com.liferay.portal.kernel.dao.orm.Session;
027 import com.liferay.portal.kernel.exception.SystemException;
028 import com.liferay.portal.kernel.log.Log;
029 import com.liferay.portal.kernel.log.LogFactoryUtil;
030 import com.liferay.portal.kernel.util.GetterUtil;
031 import com.liferay.portal.kernel.util.InstanceFactory;
032 import com.liferay.portal.kernel.util.OrderByComparator;
033 import com.liferay.portal.kernel.util.StringBundler;
034 import com.liferay.portal.kernel.util.StringPool;
035 import com.liferay.portal.kernel.util.StringUtil;
036 import com.liferay.portal.kernel.util.Validator;
037 import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
038 import com.liferay.portal.model.CacheModel;
039 import com.liferay.portal.model.ModelListener;
040 import com.liferay.portal.service.persistence.BatchSessionUtil;
041 import com.liferay.portal.service.persistence.ResourcePersistence;
042 import com.liferay.portal.service.persistence.UserPersistence;
043 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
044
045 import com.liferay.portlet.social.NoSuchRelationException;
046 import com.liferay.portlet.social.model.SocialRelation;
047 import com.liferay.portlet.social.model.impl.SocialRelationImpl;
048 import com.liferay.portlet.social.model.impl.SocialRelationModelImpl;
049
050 import java.io.Serializable;
051
052 import java.util.ArrayList;
053 import java.util.Collections;
054 import java.util.List;
055
056
068 public class SocialRelationPersistenceImpl extends BasePersistenceImpl<SocialRelation>
069 implements SocialRelationPersistence {
070
075 public static final String FINDER_CLASS_NAME_ENTITY = SocialRelationImpl.class.getName();
076 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
077 ".List1";
078 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
079 ".List2";
080 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
081 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
082 SocialRelationImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
083 "findByUuid",
084 new String[] {
085 String.class.getName(),
086
087 "java.lang.Integer", "java.lang.Integer",
088 "com.liferay.portal.kernel.util.OrderByComparator"
089 });
090 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
091 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
092 SocialRelationImpl.class,
093 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
094 new String[] { String.class.getName() },
095 SocialRelationModelImpl.UUID_COLUMN_BITMASK);
096 public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
097 SocialRelationModelImpl.FINDER_CACHE_ENABLED, Long.class,
098 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
099 new String[] { String.class.getName() });
100 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
101 new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
102 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
103 SocialRelationImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
104 "findByCompanyId",
105 new String[] {
106 Long.class.getName(),
107
108 "java.lang.Integer", "java.lang.Integer",
109 "com.liferay.portal.kernel.util.OrderByComparator"
110 });
111 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
112 new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
113 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
114 SocialRelationImpl.class,
115 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
116 new String[] { Long.class.getName() },
117 SocialRelationModelImpl.COMPANYID_COLUMN_BITMASK);
118 public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
119 SocialRelationModelImpl.FINDER_CACHE_ENABLED, Long.class,
120 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
121 new String[] { Long.class.getName() });
122 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID1 = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
123 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
124 SocialRelationImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
125 "findByUserId1",
126 new String[] {
127 Long.class.getName(),
128
129 "java.lang.Integer", "java.lang.Integer",
130 "com.liferay.portal.kernel.util.OrderByComparator"
131 });
132 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID1 =
133 new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
134 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
135 SocialRelationImpl.class,
136 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserId1",
137 new String[] { Long.class.getName() },
138 SocialRelationModelImpl.USERID1_COLUMN_BITMASK);
139 public static final FinderPath FINDER_PATH_COUNT_BY_USERID1 = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
140 SocialRelationModelImpl.FINDER_CACHE_ENABLED, Long.class,
141 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId1",
142 new String[] { Long.class.getName() });
143 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID2 = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
144 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
145 SocialRelationImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
146 "findByUserId2",
147 new String[] {
148 Long.class.getName(),
149
150 "java.lang.Integer", "java.lang.Integer",
151 "com.liferay.portal.kernel.util.OrderByComparator"
152 });
153 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID2 =
154 new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
155 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
156 SocialRelationImpl.class,
157 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserId2",
158 new String[] { Long.class.getName() },
159 SocialRelationModelImpl.USERID2_COLUMN_BITMASK);
160 public static final FinderPath FINDER_PATH_COUNT_BY_USERID2 = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
161 SocialRelationModelImpl.FINDER_CACHE_ENABLED, Long.class,
162 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId2",
163 new String[] { Long.class.getName() });
164 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_TYPE = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
165 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
166 SocialRelationImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
167 "findByType",
168 new String[] {
169 Integer.class.getName(),
170
171 "java.lang.Integer", "java.lang.Integer",
172 "com.liferay.portal.kernel.util.OrderByComparator"
173 });
174 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
175 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
176 SocialRelationImpl.class,
177 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByType",
178 new String[] { Integer.class.getName() },
179 SocialRelationModelImpl.TYPE_COLUMN_BITMASK);
180 public static final FinderPath FINDER_PATH_COUNT_BY_TYPE = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
181 SocialRelationModelImpl.FINDER_CACHE_ENABLED, Long.class,
182 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByType",
183 new String[] { Integer.class.getName() });
184 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
185 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
186 SocialRelationImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
187 "findByC_T",
188 new String[] {
189 Long.class.getName(), Integer.class.getName(),
190
191 "java.lang.Integer", "java.lang.Integer",
192 "com.liferay.portal.kernel.util.OrderByComparator"
193 });
194 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
195 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
196 SocialRelationImpl.class,
197 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_T",
198 new String[] { Long.class.getName(), Integer.class.getName() },
199 SocialRelationModelImpl.COMPANYID_COLUMN_BITMASK |
200 SocialRelationModelImpl.TYPE_COLUMN_BITMASK);
201 public static final FinderPath FINDER_PATH_COUNT_BY_C_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
202 SocialRelationModelImpl.FINDER_CACHE_ENABLED, Long.class,
203 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_T",
204 new String[] { Long.class.getName(), Integer.class.getName() });
205 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U1_U2 = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
206 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
207 SocialRelationImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
208 "findByU1_U2",
209 new String[] {
210 Long.class.getName(), Long.class.getName(),
211
212 "java.lang.Integer", "java.lang.Integer",
213 "com.liferay.portal.kernel.util.OrderByComparator"
214 });
215 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U1_U2 = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
216 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
217 SocialRelationImpl.class,
218 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU1_U2",
219 new String[] { Long.class.getName(), Long.class.getName() },
220 SocialRelationModelImpl.USERID1_COLUMN_BITMASK |
221 SocialRelationModelImpl.USERID2_COLUMN_BITMASK);
222 public static final FinderPath FINDER_PATH_COUNT_BY_U1_U2 = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
223 SocialRelationModelImpl.FINDER_CACHE_ENABLED, Long.class,
224 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU1_U2",
225 new String[] { Long.class.getName(), Long.class.getName() });
226 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U1_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
227 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
228 SocialRelationImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
229 "findByU1_T",
230 new String[] {
231 Long.class.getName(), Integer.class.getName(),
232
233 "java.lang.Integer", "java.lang.Integer",
234 "com.liferay.portal.kernel.util.OrderByComparator"
235 });
236 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U1_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
237 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
238 SocialRelationImpl.class,
239 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU1_T",
240 new String[] { Long.class.getName(), Integer.class.getName() },
241 SocialRelationModelImpl.USERID1_COLUMN_BITMASK |
242 SocialRelationModelImpl.TYPE_COLUMN_BITMASK);
243 public static final FinderPath FINDER_PATH_COUNT_BY_U1_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
244 SocialRelationModelImpl.FINDER_CACHE_ENABLED, Long.class,
245 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU1_T",
246 new String[] { Long.class.getName(), Integer.class.getName() });
247 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U2_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
248 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
249 SocialRelationImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
250 "findByU2_T",
251 new String[] {
252 Long.class.getName(), Integer.class.getName(),
253
254 "java.lang.Integer", "java.lang.Integer",
255 "com.liferay.portal.kernel.util.OrderByComparator"
256 });
257 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U2_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
258 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
259 SocialRelationImpl.class,
260 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU2_T",
261 new String[] { Long.class.getName(), Integer.class.getName() },
262 SocialRelationModelImpl.USERID2_COLUMN_BITMASK |
263 SocialRelationModelImpl.TYPE_COLUMN_BITMASK);
264 public static final FinderPath FINDER_PATH_COUNT_BY_U2_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
265 SocialRelationModelImpl.FINDER_CACHE_ENABLED, Long.class,
266 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU2_T",
267 new String[] { Long.class.getName(), Integer.class.getName() });
268 public static final FinderPath FINDER_PATH_FETCH_BY_U1_U2_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
269 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
270 SocialRelationImpl.class, FINDER_CLASS_NAME_ENTITY,
271 "fetchByU1_U2_T",
272 new String[] {
273 Long.class.getName(), Long.class.getName(),
274 Integer.class.getName()
275 },
276 SocialRelationModelImpl.USERID1_COLUMN_BITMASK |
277 SocialRelationModelImpl.USERID2_COLUMN_BITMASK |
278 SocialRelationModelImpl.TYPE_COLUMN_BITMASK);
279 public static final FinderPath FINDER_PATH_COUNT_BY_U1_U2_T = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
280 SocialRelationModelImpl.FINDER_CACHE_ENABLED, Long.class,
281 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU1_U2_T",
282 new String[] {
283 Long.class.getName(), Long.class.getName(),
284 Integer.class.getName()
285 });
286 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
287 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
288 SocialRelationImpl.class,
289 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
290 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
291 SocialRelationModelImpl.FINDER_CACHE_ENABLED,
292 SocialRelationImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
293 "findAll", new String[0]);
294 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
295 SocialRelationModelImpl.FINDER_CACHE_ENABLED, Long.class,
296 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
297
298
303 public void cacheResult(SocialRelation socialRelation) {
304 EntityCacheUtil.putResult(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
305 SocialRelationImpl.class, socialRelation.getPrimaryKey(),
306 socialRelation);
307
308 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U1_U2_T,
309 new Object[] {
310 Long.valueOf(socialRelation.getUserId1()),
311 Long.valueOf(socialRelation.getUserId2()),
312 Integer.valueOf(socialRelation.getType())
313 }, socialRelation);
314
315 socialRelation.resetOriginalValues();
316 }
317
318
323 public void cacheResult(List<SocialRelation> socialRelations) {
324 for (SocialRelation socialRelation : socialRelations) {
325 if (EntityCacheUtil.getResult(
326 SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
327 SocialRelationImpl.class, socialRelation.getPrimaryKey()) == null) {
328 cacheResult(socialRelation);
329 }
330 else {
331 socialRelation.resetOriginalValues();
332 }
333 }
334 }
335
336
343 @Override
344 public void clearCache() {
345 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
346 CacheRegistryUtil.clear(SocialRelationImpl.class.getName());
347 }
348
349 EntityCacheUtil.clearCache(SocialRelationImpl.class.getName());
350
351 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
352 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
353 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
354 }
355
356
363 @Override
364 public void clearCache(SocialRelation socialRelation) {
365 EntityCacheUtil.removeResult(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
366 SocialRelationImpl.class, socialRelation.getPrimaryKey());
367
368 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
369 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
370
371 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 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U1_U2_T, args);
735
736 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U1_U2_T,
737 new Object[] {
738 Long.valueOf(socialRelation.getUserId1()),
739 Long.valueOf(socialRelation.getUserId2()),
740 Integer.valueOf(socialRelation.getType())
741 }, socialRelation);
742 }
743 }
744
745 return socialRelation;
746 }
747
748 protected SocialRelation toUnwrappedModel(SocialRelation socialRelation) {
749 if (socialRelation instanceof SocialRelationImpl) {
750 return socialRelation;
751 }
752
753 SocialRelationImpl socialRelationImpl = new SocialRelationImpl();
754
755 socialRelationImpl.setNew(socialRelation.isNew());
756 socialRelationImpl.setPrimaryKey(socialRelation.getPrimaryKey());
757
758 socialRelationImpl.setUuid(socialRelation.getUuid());
759 socialRelationImpl.setRelationId(socialRelation.getRelationId());
760 socialRelationImpl.setCompanyId(socialRelation.getCompanyId());
761 socialRelationImpl.setCreateDate(socialRelation.getCreateDate());
762 socialRelationImpl.setUserId1(socialRelation.getUserId1());
763 socialRelationImpl.setUserId2(socialRelation.getUserId2());
764 socialRelationImpl.setType(socialRelation.getType());
765
766 return socialRelationImpl;
767 }
768
769
777 @Override
778 public SocialRelation findByPrimaryKey(Serializable primaryKey)
779 throws NoSuchModelException, SystemException {
780 return findByPrimaryKey(((Long)primaryKey).longValue());
781 }
782
783
791 public SocialRelation findByPrimaryKey(long relationId)
792 throws NoSuchRelationException, SystemException {
793 SocialRelation socialRelation = fetchByPrimaryKey(relationId);
794
795 if (socialRelation == null) {
796 if (_log.isWarnEnabled()) {
797 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + relationId);
798 }
799
800 throw new NoSuchRelationException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
801 relationId);
802 }
803
804 return socialRelation;
805 }
806
807
814 @Override
815 public SocialRelation fetchByPrimaryKey(Serializable primaryKey)
816 throws SystemException {
817 return fetchByPrimaryKey(((Long)primaryKey).longValue());
818 }
819
820
827 public SocialRelation fetchByPrimaryKey(long relationId)
828 throws SystemException {
829 SocialRelation socialRelation = (SocialRelation)EntityCacheUtil.getResult(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
830 SocialRelationImpl.class, relationId);
831
832 if (socialRelation == _nullSocialRelation) {
833 return null;
834 }
835
836 if (socialRelation == null) {
837 Session session = null;
838
839 boolean hasException = false;
840
841 try {
842 session = openSession();
843
844 socialRelation = (SocialRelation)session.get(SocialRelationImpl.class,
845 Long.valueOf(relationId));
846 }
847 catch (Exception e) {
848 hasException = true;
849
850 throw processException(e);
851 }
852 finally {
853 if (socialRelation != null) {
854 cacheResult(socialRelation);
855 }
856 else if (!hasException) {
857 EntityCacheUtil.putResult(SocialRelationModelImpl.ENTITY_CACHE_ENABLED,
858 SocialRelationImpl.class, relationId,
859 _nullSocialRelation);
860 }
861
862 closeSession(session);
863 }
864 }
865
866 return socialRelation;
867 }
868
869
876 public List<SocialRelation> findByUuid(String uuid)
877 throws SystemException {
878 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
879 }
880
881
894 public List<SocialRelation> findByUuid(String uuid, int start, int end)
895 throws SystemException {
896 return findByUuid(uuid, start, end, null);
897 }
898
899
913 public List<SocialRelation> findByUuid(String uuid, int start, int end,
914 OrderByComparator orderByComparator) throws SystemException {
915 FinderPath finderPath = null;
916 Object[] finderArgs = null;
917
918 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
919 (orderByComparator == null)) {
920 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
921 finderArgs = new Object[] { uuid };
922 }
923 else {
924 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
925 finderArgs = new Object[] { uuid, start, end, orderByComparator };
926 }
927
928 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(finderPath,
929 finderArgs, this);
930
931 if (list == null) {
932 StringBundler query = null;
933
934 if (orderByComparator != null) {
935 query = new StringBundler(3 +
936 (orderByComparator.getOrderByFields().length * 3));
937 }
938 else {
939 query = new StringBundler(2);
940 }
941
942 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
943
944 if (uuid == null) {
945 query.append(_FINDER_COLUMN_UUID_UUID_1);
946 }
947 else {
948 if (uuid.equals(StringPool.BLANK)) {
949 query.append(_FINDER_COLUMN_UUID_UUID_3);
950 }
951 else {
952 query.append(_FINDER_COLUMN_UUID_UUID_2);
953 }
954 }
955
956 if (orderByComparator != null) {
957 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
958 orderByComparator);
959 }
960
961 String sql = query.toString();
962
963 Session session = null;
964
965 try {
966 session = openSession();
967
968 Query q = session.createQuery(sql);
969
970 QueryPos qPos = QueryPos.getInstance(q);
971
972 if (uuid != null) {
973 qPos.add(uuid);
974 }
975
976 list = (List<SocialRelation>)QueryUtil.list(q, getDialect(),
977 start, end);
978 }
979 catch (Exception e) {
980 throw processException(e);
981 }
982 finally {
983 if (list == null) {
984 FinderCacheUtil.removeResult(finderPath, finderArgs);
985 }
986 else {
987 cacheResult(list);
988
989 FinderCacheUtil.putResult(finderPath, finderArgs, list);
990 }
991
992 closeSession(session);
993 }
994 }
995
996 return list;
997 }
998
999
1012 public SocialRelation findByUuid_First(String uuid,
1013 OrderByComparator orderByComparator)
1014 throws NoSuchRelationException, SystemException {
1015 List<SocialRelation> list = findByUuid(uuid, 0, 1, orderByComparator);
1016
1017 if (list.isEmpty()) {
1018 StringBundler msg = new StringBundler(4);
1019
1020 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1021
1022 msg.append("uuid=");
1023 msg.append(uuid);
1024
1025 msg.append(StringPool.CLOSE_CURLY_BRACE);
1026
1027 throw new NoSuchRelationException(msg.toString());
1028 }
1029 else {
1030 return list.get(0);
1031 }
1032 }
1033
1034
1047 public SocialRelation findByUuid_Last(String uuid,
1048 OrderByComparator orderByComparator)
1049 throws NoSuchRelationException, SystemException {
1050 int count = countByUuid(uuid);
1051
1052 List<SocialRelation> list = findByUuid(uuid, count - 1, count,
1053 orderByComparator);
1054
1055 if (list.isEmpty()) {
1056 StringBundler msg = new StringBundler(4);
1057
1058 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1059
1060 msg.append("uuid=");
1061 msg.append(uuid);
1062
1063 msg.append(StringPool.CLOSE_CURLY_BRACE);
1064
1065 throw new NoSuchRelationException(msg.toString());
1066 }
1067 else {
1068 return list.get(0);
1069 }
1070 }
1071
1072
1086 public SocialRelation[] findByUuid_PrevAndNext(long relationId,
1087 String uuid, OrderByComparator orderByComparator)
1088 throws NoSuchRelationException, SystemException {
1089 SocialRelation socialRelation = findByPrimaryKey(relationId);
1090
1091 Session session = null;
1092
1093 try {
1094 session = openSession();
1095
1096 SocialRelation[] array = new SocialRelationImpl[3];
1097
1098 array[0] = getByUuid_PrevAndNext(session, socialRelation, uuid,
1099 orderByComparator, true);
1100
1101 array[1] = socialRelation;
1102
1103 array[2] = getByUuid_PrevAndNext(session, socialRelation, uuid,
1104 orderByComparator, false);
1105
1106 return array;
1107 }
1108 catch (Exception e) {
1109 throw processException(e);
1110 }
1111 finally {
1112 closeSession(session);
1113 }
1114 }
1115
1116 protected SocialRelation getByUuid_PrevAndNext(Session session,
1117 SocialRelation socialRelation, String uuid,
1118 OrderByComparator orderByComparator, boolean previous) {
1119 StringBundler query = null;
1120
1121 if (orderByComparator != null) {
1122 query = new StringBundler(6 +
1123 (orderByComparator.getOrderByFields().length * 6));
1124 }
1125 else {
1126 query = new StringBundler(3);
1127 }
1128
1129 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
1130
1131 if (uuid == null) {
1132 query.append(_FINDER_COLUMN_UUID_UUID_1);
1133 }
1134 else {
1135 if (uuid.equals(StringPool.BLANK)) {
1136 query.append(_FINDER_COLUMN_UUID_UUID_3);
1137 }
1138 else {
1139 query.append(_FINDER_COLUMN_UUID_UUID_2);
1140 }
1141 }
1142
1143 if (orderByComparator != null) {
1144 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1145
1146 if (orderByConditionFields.length > 0) {
1147 query.append(WHERE_AND);
1148 }
1149
1150 for (int i = 0; i < orderByConditionFields.length; i++) {
1151 query.append(_ORDER_BY_ENTITY_ALIAS);
1152 query.append(orderByConditionFields[i]);
1153
1154 if ((i + 1) < orderByConditionFields.length) {
1155 if (orderByComparator.isAscending() ^ previous) {
1156 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1157 }
1158 else {
1159 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1160 }
1161 }
1162 else {
1163 if (orderByComparator.isAscending() ^ previous) {
1164 query.append(WHERE_GREATER_THAN);
1165 }
1166 else {
1167 query.append(WHERE_LESSER_THAN);
1168 }
1169 }
1170 }
1171
1172 query.append(ORDER_BY_CLAUSE);
1173
1174 String[] orderByFields = orderByComparator.getOrderByFields();
1175
1176 for (int i = 0; i < orderByFields.length; i++) {
1177 query.append(_ORDER_BY_ENTITY_ALIAS);
1178 query.append(orderByFields[i]);
1179
1180 if ((i + 1) < orderByFields.length) {
1181 if (orderByComparator.isAscending() ^ previous) {
1182 query.append(ORDER_BY_ASC_HAS_NEXT);
1183 }
1184 else {
1185 query.append(ORDER_BY_DESC_HAS_NEXT);
1186 }
1187 }
1188 else {
1189 if (orderByComparator.isAscending() ^ previous) {
1190 query.append(ORDER_BY_ASC);
1191 }
1192 else {
1193 query.append(ORDER_BY_DESC);
1194 }
1195 }
1196 }
1197 }
1198
1199 String sql = query.toString();
1200
1201 Query q = session.createQuery(sql);
1202
1203 q.setFirstResult(0);
1204 q.setMaxResults(2);
1205
1206 QueryPos qPos = QueryPos.getInstance(q);
1207
1208 if (uuid != null) {
1209 qPos.add(uuid);
1210 }
1211
1212 if (orderByComparator != null) {
1213 Object[] values = orderByComparator.getOrderByConditionValues(socialRelation);
1214
1215 for (Object value : values) {
1216 qPos.add(value);
1217 }
1218 }
1219
1220 List<SocialRelation> list = q.list();
1221
1222 if (list.size() == 2) {
1223 return list.get(1);
1224 }
1225 else {
1226 return null;
1227 }
1228 }
1229
1230
1237 public List<SocialRelation> findByCompanyId(long companyId)
1238 throws SystemException {
1239 return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1240 null);
1241 }
1242
1243
1256 public List<SocialRelation> findByCompanyId(long companyId, int start,
1257 int end) throws SystemException {
1258 return findByCompanyId(companyId, start, end, null);
1259 }
1260
1261
1275 public List<SocialRelation> findByCompanyId(long companyId, int start,
1276 int end, OrderByComparator orderByComparator) throws SystemException {
1277 FinderPath finderPath = null;
1278 Object[] finderArgs = null;
1279
1280 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1281 (orderByComparator == null)) {
1282 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
1283 finderArgs = new Object[] { companyId };
1284 }
1285 else {
1286 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
1287 finderArgs = new Object[] { companyId, start, end, orderByComparator };
1288 }
1289
1290 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(finderPath,
1291 finderArgs, this);
1292
1293 if (list == null) {
1294 StringBundler query = null;
1295
1296 if (orderByComparator != null) {
1297 query = new StringBundler(3 +
1298 (orderByComparator.getOrderByFields().length * 3));
1299 }
1300 else {
1301 query = new StringBundler(2);
1302 }
1303
1304 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
1305
1306 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1307
1308 if (orderByComparator != null) {
1309 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1310 orderByComparator);
1311 }
1312
1313 String sql = query.toString();
1314
1315 Session session = null;
1316
1317 try {
1318 session = openSession();
1319
1320 Query q = session.createQuery(sql);
1321
1322 QueryPos qPos = QueryPos.getInstance(q);
1323
1324 qPos.add(companyId);
1325
1326 list = (List<SocialRelation>)QueryUtil.list(q, getDialect(),
1327 start, end);
1328 }
1329 catch (Exception e) {
1330 throw processException(e);
1331 }
1332 finally {
1333 if (list == null) {
1334 FinderCacheUtil.removeResult(finderPath, finderArgs);
1335 }
1336 else {
1337 cacheResult(list);
1338
1339 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1340 }
1341
1342 closeSession(session);
1343 }
1344 }
1345
1346 return list;
1347 }
1348
1349
1362 public SocialRelation findByCompanyId_First(long companyId,
1363 OrderByComparator orderByComparator)
1364 throws NoSuchRelationException, SystemException {
1365 List<SocialRelation> list = findByCompanyId(companyId, 0, 1,
1366 orderByComparator);
1367
1368 if (list.isEmpty()) {
1369 StringBundler msg = new StringBundler(4);
1370
1371 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1372
1373 msg.append("companyId=");
1374 msg.append(companyId);
1375
1376 msg.append(StringPool.CLOSE_CURLY_BRACE);
1377
1378 throw new NoSuchRelationException(msg.toString());
1379 }
1380 else {
1381 return list.get(0);
1382 }
1383 }
1384
1385
1398 public SocialRelation findByCompanyId_Last(long companyId,
1399 OrderByComparator orderByComparator)
1400 throws NoSuchRelationException, SystemException {
1401 int count = countByCompanyId(companyId);
1402
1403 List<SocialRelation> list = findByCompanyId(companyId, count - 1,
1404 count, orderByComparator);
1405
1406 if (list.isEmpty()) {
1407 StringBundler msg = new StringBundler(4);
1408
1409 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1410
1411 msg.append("companyId=");
1412 msg.append(companyId);
1413
1414 msg.append(StringPool.CLOSE_CURLY_BRACE);
1415
1416 throw new NoSuchRelationException(msg.toString());
1417 }
1418 else {
1419 return list.get(0);
1420 }
1421 }
1422
1423
1437 public SocialRelation[] findByCompanyId_PrevAndNext(long relationId,
1438 long companyId, OrderByComparator orderByComparator)
1439 throws NoSuchRelationException, SystemException {
1440 SocialRelation socialRelation = findByPrimaryKey(relationId);
1441
1442 Session session = null;
1443
1444 try {
1445 session = openSession();
1446
1447 SocialRelation[] array = new SocialRelationImpl[3];
1448
1449 array[0] = getByCompanyId_PrevAndNext(session, socialRelation,
1450 companyId, orderByComparator, true);
1451
1452 array[1] = socialRelation;
1453
1454 array[2] = getByCompanyId_PrevAndNext(session, socialRelation,
1455 companyId, orderByComparator, false);
1456
1457 return array;
1458 }
1459 catch (Exception e) {
1460 throw processException(e);
1461 }
1462 finally {
1463 closeSession(session);
1464 }
1465 }
1466
1467 protected SocialRelation getByCompanyId_PrevAndNext(Session session,
1468 SocialRelation socialRelation, long companyId,
1469 OrderByComparator orderByComparator, boolean previous) {
1470 StringBundler query = null;
1471
1472 if (orderByComparator != null) {
1473 query = new StringBundler(6 +
1474 (orderByComparator.getOrderByFields().length * 6));
1475 }
1476 else {
1477 query = new StringBundler(3);
1478 }
1479
1480 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
1481
1482 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1483
1484 if (orderByComparator != null) {
1485 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1486
1487 if (orderByConditionFields.length > 0) {
1488 query.append(WHERE_AND);
1489 }
1490
1491 for (int i = 0; i < orderByConditionFields.length; i++) {
1492 query.append(_ORDER_BY_ENTITY_ALIAS);
1493 query.append(orderByConditionFields[i]);
1494
1495 if ((i + 1) < orderByConditionFields.length) {
1496 if (orderByComparator.isAscending() ^ previous) {
1497 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1498 }
1499 else {
1500 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1501 }
1502 }
1503 else {
1504 if (orderByComparator.isAscending() ^ previous) {
1505 query.append(WHERE_GREATER_THAN);
1506 }
1507 else {
1508 query.append(WHERE_LESSER_THAN);
1509 }
1510 }
1511 }
1512
1513 query.append(ORDER_BY_CLAUSE);
1514
1515 String[] orderByFields = orderByComparator.getOrderByFields();
1516
1517 for (int i = 0; i < orderByFields.length; i++) {
1518 query.append(_ORDER_BY_ENTITY_ALIAS);
1519 query.append(orderByFields[i]);
1520
1521 if ((i + 1) < orderByFields.length) {
1522 if (orderByComparator.isAscending() ^ previous) {
1523 query.append(ORDER_BY_ASC_HAS_NEXT);
1524 }
1525 else {
1526 query.append(ORDER_BY_DESC_HAS_NEXT);
1527 }
1528 }
1529 else {
1530 if (orderByComparator.isAscending() ^ previous) {
1531 query.append(ORDER_BY_ASC);
1532 }
1533 else {
1534 query.append(ORDER_BY_DESC);
1535 }
1536 }
1537 }
1538 }
1539
1540 String sql = query.toString();
1541
1542 Query q = session.createQuery(sql);
1543
1544 q.setFirstResult(0);
1545 q.setMaxResults(2);
1546
1547 QueryPos qPos = QueryPos.getInstance(q);
1548
1549 qPos.add(companyId);
1550
1551 if (orderByComparator != null) {
1552 Object[] values = orderByComparator.getOrderByConditionValues(socialRelation);
1553
1554 for (Object value : values) {
1555 qPos.add(value);
1556 }
1557 }
1558
1559 List<SocialRelation> list = q.list();
1560
1561 if (list.size() == 2) {
1562 return list.get(1);
1563 }
1564 else {
1565 return null;
1566 }
1567 }
1568
1569
1576 public List<SocialRelation> findByUserId1(long userId1)
1577 throws SystemException {
1578 return findByUserId1(userId1, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1579 }
1580
1581
1594 public List<SocialRelation> findByUserId1(long userId1, int start, int end)
1595 throws SystemException {
1596 return findByUserId1(userId1, start, end, null);
1597 }
1598
1599
1613 public List<SocialRelation> findByUserId1(long userId1, int start, int end,
1614 OrderByComparator orderByComparator) throws SystemException {
1615 FinderPath finderPath = null;
1616 Object[] finderArgs = null;
1617
1618 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1619 (orderByComparator == null)) {
1620 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID1;
1621 finderArgs = new Object[] { userId1 };
1622 }
1623 else {
1624 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID1;
1625 finderArgs = new Object[] { userId1, start, end, orderByComparator };
1626 }
1627
1628 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(finderPath,
1629 finderArgs, this);
1630
1631 if (list == null) {
1632 StringBundler query = null;
1633
1634 if (orderByComparator != null) {
1635 query = new StringBundler(3 +
1636 (orderByComparator.getOrderByFields().length * 3));
1637 }
1638 else {
1639 query = new StringBundler(2);
1640 }
1641
1642 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
1643
1644 query.append(_FINDER_COLUMN_USERID1_USERID1_2);
1645
1646 if (orderByComparator != null) {
1647 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1648 orderByComparator);
1649 }
1650
1651 String sql = query.toString();
1652
1653 Session session = null;
1654
1655 try {
1656 session = openSession();
1657
1658 Query q = session.createQuery(sql);
1659
1660 QueryPos qPos = QueryPos.getInstance(q);
1661
1662 qPos.add(userId1);
1663
1664 list = (List<SocialRelation>)QueryUtil.list(q, getDialect(),
1665 start, end);
1666 }
1667 catch (Exception e) {
1668 throw processException(e);
1669 }
1670 finally {
1671 if (list == null) {
1672 FinderCacheUtil.removeResult(finderPath, finderArgs);
1673 }
1674 else {
1675 cacheResult(list);
1676
1677 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1678 }
1679
1680 closeSession(session);
1681 }
1682 }
1683
1684 return list;
1685 }
1686
1687
1700 public SocialRelation findByUserId1_First(long userId1,
1701 OrderByComparator orderByComparator)
1702 throws NoSuchRelationException, SystemException {
1703 List<SocialRelation> list = findByUserId1(userId1, 0, 1,
1704 orderByComparator);
1705
1706 if (list.isEmpty()) {
1707 StringBundler msg = new StringBundler(4);
1708
1709 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1710
1711 msg.append("userId1=");
1712 msg.append(userId1);
1713
1714 msg.append(StringPool.CLOSE_CURLY_BRACE);
1715
1716 throw new NoSuchRelationException(msg.toString());
1717 }
1718 else {
1719 return list.get(0);
1720 }
1721 }
1722
1723
1736 public SocialRelation findByUserId1_Last(long userId1,
1737 OrderByComparator orderByComparator)
1738 throws NoSuchRelationException, SystemException {
1739 int count = countByUserId1(userId1);
1740
1741 List<SocialRelation> list = findByUserId1(userId1, count - 1, count,
1742 orderByComparator);
1743
1744 if (list.isEmpty()) {
1745 StringBundler msg = new StringBundler(4);
1746
1747 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1748
1749 msg.append("userId1=");
1750 msg.append(userId1);
1751
1752 msg.append(StringPool.CLOSE_CURLY_BRACE);
1753
1754 throw new NoSuchRelationException(msg.toString());
1755 }
1756 else {
1757 return list.get(0);
1758 }
1759 }
1760
1761
1775 public SocialRelation[] findByUserId1_PrevAndNext(long relationId,
1776 long userId1, OrderByComparator orderByComparator)
1777 throws NoSuchRelationException, SystemException {
1778 SocialRelation socialRelation = findByPrimaryKey(relationId);
1779
1780 Session session = null;
1781
1782 try {
1783 session = openSession();
1784
1785 SocialRelation[] array = new SocialRelationImpl[3];
1786
1787 array[0] = getByUserId1_PrevAndNext(session, socialRelation,
1788 userId1, orderByComparator, true);
1789
1790 array[1] = socialRelation;
1791
1792 array[2] = getByUserId1_PrevAndNext(session, socialRelation,
1793 userId1, orderByComparator, false);
1794
1795 return array;
1796 }
1797 catch (Exception e) {
1798 throw processException(e);
1799 }
1800 finally {
1801 closeSession(session);
1802 }
1803 }
1804
1805 protected SocialRelation getByUserId1_PrevAndNext(Session session,
1806 SocialRelation socialRelation, long userId1,
1807 OrderByComparator orderByComparator, boolean previous) {
1808 StringBundler query = null;
1809
1810 if (orderByComparator != null) {
1811 query = new StringBundler(6 +
1812 (orderByComparator.getOrderByFields().length * 6));
1813 }
1814 else {
1815 query = new StringBundler(3);
1816 }
1817
1818 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
1819
1820 query.append(_FINDER_COLUMN_USERID1_USERID1_2);
1821
1822 if (orderByComparator != null) {
1823 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1824
1825 if (orderByConditionFields.length > 0) {
1826 query.append(WHERE_AND);
1827 }
1828
1829 for (int i = 0; i < orderByConditionFields.length; i++) {
1830 query.append(_ORDER_BY_ENTITY_ALIAS);
1831 query.append(orderByConditionFields[i]);
1832
1833 if ((i + 1) < orderByConditionFields.length) {
1834 if (orderByComparator.isAscending() ^ previous) {
1835 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1836 }
1837 else {
1838 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1839 }
1840 }
1841 else {
1842 if (orderByComparator.isAscending() ^ previous) {
1843 query.append(WHERE_GREATER_THAN);
1844 }
1845 else {
1846 query.append(WHERE_LESSER_THAN);
1847 }
1848 }
1849 }
1850
1851 query.append(ORDER_BY_CLAUSE);
1852
1853 String[] orderByFields = orderByComparator.getOrderByFields();
1854
1855 for (int i = 0; i < orderByFields.length; i++) {
1856 query.append(_ORDER_BY_ENTITY_ALIAS);
1857 query.append(orderByFields[i]);
1858
1859 if ((i + 1) < orderByFields.length) {
1860 if (orderByComparator.isAscending() ^ previous) {
1861 query.append(ORDER_BY_ASC_HAS_NEXT);
1862 }
1863 else {
1864 query.append(ORDER_BY_DESC_HAS_NEXT);
1865 }
1866 }
1867 else {
1868 if (orderByComparator.isAscending() ^ previous) {
1869 query.append(ORDER_BY_ASC);
1870 }
1871 else {
1872 query.append(ORDER_BY_DESC);
1873 }
1874 }
1875 }
1876 }
1877
1878 String sql = query.toString();
1879
1880 Query q = session.createQuery(sql);
1881
1882 q.setFirstResult(0);
1883 q.setMaxResults(2);
1884
1885 QueryPos qPos = QueryPos.getInstance(q);
1886
1887 qPos.add(userId1);
1888
1889 if (orderByComparator != null) {
1890 Object[] values = orderByComparator.getOrderByConditionValues(socialRelation);
1891
1892 for (Object value : values) {
1893 qPos.add(value);
1894 }
1895 }
1896
1897 List<SocialRelation> list = q.list();
1898
1899 if (list.size() == 2) {
1900 return list.get(1);
1901 }
1902 else {
1903 return null;
1904 }
1905 }
1906
1907
1914 public List<SocialRelation> findByUserId2(long userId2)
1915 throws SystemException {
1916 return findByUserId2(userId2, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1917 }
1918
1919
1932 public List<SocialRelation> findByUserId2(long userId2, int start, int end)
1933 throws SystemException {
1934 return findByUserId2(userId2, start, end, null);
1935 }
1936
1937
1951 public List<SocialRelation> findByUserId2(long userId2, int start, int end,
1952 OrderByComparator orderByComparator) throws SystemException {
1953 FinderPath finderPath = null;
1954 Object[] finderArgs = null;
1955
1956 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1957 (orderByComparator == null)) {
1958 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID2;
1959 finderArgs = new Object[] { userId2 };
1960 }
1961 else {
1962 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID2;
1963 finderArgs = new Object[] { userId2, start, end, orderByComparator };
1964 }
1965
1966 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(finderPath,
1967 finderArgs, this);
1968
1969 if (list == null) {
1970 StringBundler query = null;
1971
1972 if (orderByComparator != null) {
1973 query = new StringBundler(3 +
1974 (orderByComparator.getOrderByFields().length * 3));
1975 }
1976 else {
1977 query = new StringBundler(2);
1978 }
1979
1980 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
1981
1982 query.append(_FINDER_COLUMN_USERID2_USERID2_2);
1983
1984 if (orderByComparator != null) {
1985 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1986 orderByComparator);
1987 }
1988
1989 String sql = query.toString();
1990
1991 Session session = null;
1992
1993 try {
1994 session = openSession();
1995
1996 Query q = session.createQuery(sql);
1997
1998 QueryPos qPos = QueryPos.getInstance(q);
1999
2000 qPos.add(userId2);
2001
2002 list = (List<SocialRelation>)QueryUtil.list(q, getDialect(),
2003 start, end);
2004 }
2005 catch (Exception e) {
2006 throw processException(e);
2007 }
2008 finally {
2009 if (list == null) {
2010 FinderCacheUtil.removeResult(finderPath, finderArgs);
2011 }
2012 else {
2013 cacheResult(list);
2014
2015 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2016 }
2017
2018 closeSession(session);
2019 }
2020 }
2021
2022 return list;
2023 }
2024
2025
2038 public SocialRelation findByUserId2_First(long userId2,
2039 OrderByComparator orderByComparator)
2040 throws NoSuchRelationException, SystemException {
2041 List<SocialRelation> list = findByUserId2(userId2, 0, 1,
2042 orderByComparator);
2043
2044 if (list.isEmpty()) {
2045 StringBundler msg = new StringBundler(4);
2046
2047 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2048
2049 msg.append("userId2=");
2050 msg.append(userId2);
2051
2052 msg.append(StringPool.CLOSE_CURLY_BRACE);
2053
2054 throw new NoSuchRelationException(msg.toString());
2055 }
2056 else {
2057 return list.get(0);
2058 }
2059 }
2060
2061
2074 public SocialRelation findByUserId2_Last(long userId2,
2075 OrderByComparator orderByComparator)
2076 throws NoSuchRelationException, SystemException {
2077 int count = countByUserId2(userId2);
2078
2079 List<SocialRelation> list = findByUserId2(userId2, count - 1, count,
2080 orderByComparator);
2081
2082 if (list.isEmpty()) {
2083 StringBundler msg = new StringBundler(4);
2084
2085 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2086
2087 msg.append("userId2=");
2088 msg.append(userId2);
2089
2090 msg.append(StringPool.CLOSE_CURLY_BRACE);
2091
2092 throw new NoSuchRelationException(msg.toString());
2093 }
2094 else {
2095 return list.get(0);
2096 }
2097 }
2098
2099
2113 public SocialRelation[] findByUserId2_PrevAndNext(long relationId,
2114 long userId2, OrderByComparator orderByComparator)
2115 throws NoSuchRelationException, SystemException {
2116 SocialRelation socialRelation = findByPrimaryKey(relationId);
2117
2118 Session session = null;
2119
2120 try {
2121 session = openSession();
2122
2123 SocialRelation[] array = new SocialRelationImpl[3];
2124
2125 array[0] = getByUserId2_PrevAndNext(session, socialRelation,
2126 userId2, orderByComparator, true);
2127
2128 array[1] = socialRelation;
2129
2130 array[2] = getByUserId2_PrevAndNext(session, socialRelation,
2131 userId2, orderByComparator, false);
2132
2133 return array;
2134 }
2135 catch (Exception e) {
2136 throw processException(e);
2137 }
2138 finally {
2139 closeSession(session);
2140 }
2141 }
2142
2143 protected SocialRelation getByUserId2_PrevAndNext(Session session,
2144 SocialRelation socialRelation, long userId2,
2145 OrderByComparator orderByComparator, boolean previous) {
2146 StringBundler query = null;
2147
2148 if (orderByComparator != null) {
2149 query = new StringBundler(6 +
2150 (orderByComparator.getOrderByFields().length * 6));
2151 }
2152 else {
2153 query = new StringBundler(3);
2154 }
2155
2156 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
2157
2158 query.append(_FINDER_COLUMN_USERID2_USERID2_2);
2159
2160 if (orderByComparator != null) {
2161 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2162
2163 if (orderByConditionFields.length > 0) {
2164 query.append(WHERE_AND);
2165 }
2166
2167 for (int i = 0; i < orderByConditionFields.length; i++) {
2168 query.append(_ORDER_BY_ENTITY_ALIAS);
2169 query.append(orderByConditionFields[i]);
2170
2171 if ((i + 1) < orderByConditionFields.length) {
2172 if (orderByComparator.isAscending() ^ previous) {
2173 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2174 }
2175 else {
2176 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2177 }
2178 }
2179 else {
2180 if (orderByComparator.isAscending() ^ previous) {
2181 query.append(WHERE_GREATER_THAN);
2182 }
2183 else {
2184 query.append(WHERE_LESSER_THAN);
2185 }
2186 }
2187 }
2188
2189 query.append(ORDER_BY_CLAUSE);
2190
2191 String[] orderByFields = orderByComparator.getOrderByFields();
2192
2193 for (int i = 0; i < orderByFields.length; i++) {
2194 query.append(_ORDER_BY_ENTITY_ALIAS);
2195 query.append(orderByFields[i]);
2196
2197 if ((i + 1) < orderByFields.length) {
2198 if (orderByComparator.isAscending() ^ previous) {
2199 query.append(ORDER_BY_ASC_HAS_NEXT);
2200 }
2201 else {
2202 query.append(ORDER_BY_DESC_HAS_NEXT);
2203 }
2204 }
2205 else {
2206 if (orderByComparator.isAscending() ^ previous) {
2207 query.append(ORDER_BY_ASC);
2208 }
2209 else {
2210 query.append(ORDER_BY_DESC);
2211 }
2212 }
2213 }
2214 }
2215
2216 String sql = query.toString();
2217
2218 Query q = session.createQuery(sql);
2219
2220 q.setFirstResult(0);
2221 q.setMaxResults(2);
2222
2223 QueryPos qPos = QueryPos.getInstance(q);
2224
2225 qPos.add(userId2);
2226
2227 if (orderByComparator != null) {
2228 Object[] values = orderByComparator.getOrderByConditionValues(socialRelation);
2229
2230 for (Object value : values) {
2231 qPos.add(value);
2232 }
2233 }
2234
2235 List<SocialRelation> list = q.list();
2236
2237 if (list.size() == 2) {
2238 return list.get(1);
2239 }
2240 else {
2241 return null;
2242 }
2243 }
2244
2245
2252 public List<SocialRelation> findByType(int type) throws SystemException {
2253 return findByType(type, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2254 }
2255
2256
2269 public List<SocialRelation> findByType(int type, int start, int end)
2270 throws SystemException {
2271 return findByType(type, start, end, null);
2272 }
2273
2274
2288 public List<SocialRelation> findByType(int type, int start, int end,
2289 OrderByComparator orderByComparator) throws SystemException {
2290 FinderPath finderPath = null;
2291 Object[] finderArgs = null;
2292
2293 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2294 (orderByComparator == null)) {
2295 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE;
2296 finderArgs = new Object[] { type };
2297 }
2298 else {
2299 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_TYPE;
2300 finderArgs = new Object[] { type, start, end, orderByComparator };
2301 }
2302
2303 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(finderPath,
2304 finderArgs, this);
2305
2306 if (list == null) {
2307 StringBundler query = null;
2308
2309 if (orderByComparator != null) {
2310 query = new StringBundler(3 +
2311 (orderByComparator.getOrderByFields().length * 3));
2312 }
2313 else {
2314 query = new StringBundler(2);
2315 }
2316
2317 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
2318
2319 query.append(_FINDER_COLUMN_TYPE_TYPE_2);
2320
2321 if (orderByComparator != null) {
2322 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2323 orderByComparator);
2324 }
2325
2326 String sql = query.toString();
2327
2328 Session session = null;
2329
2330 try {
2331 session = openSession();
2332
2333 Query q = session.createQuery(sql);
2334
2335 QueryPos qPos = QueryPos.getInstance(q);
2336
2337 qPos.add(type);
2338
2339 list = (List<SocialRelation>)QueryUtil.list(q, getDialect(),
2340 start, end);
2341 }
2342 catch (Exception e) {
2343 throw processException(e);
2344 }
2345 finally {
2346 if (list == null) {
2347 FinderCacheUtil.removeResult(finderPath, finderArgs);
2348 }
2349 else {
2350 cacheResult(list);
2351
2352 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2353 }
2354
2355 closeSession(session);
2356 }
2357 }
2358
2359 return list;
2360 }
2361
2362
2375 public SocialRelation findByType_First(int type,
2376 OrderByComparator orderByComparator)
2377 throws NoSuchRelationException, SystemException {
2378 List<SocialRelation> list = findByType(type, 0, 1, orderByComparator);
2379
2380 if (list.isEmpty()) {
2381 StringBundler msg = new StringBundler(4);
2382
2383 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2384
2385 msg.append("type=");
2386 msg.append(type);
2387
2388 msg.append(StringPool.CLOSE_CURLY_BRACE);
2389
2390 throw new NoSuchRelationException(msg.toString());
2391 }
2392 else {
2393 return list.get(0);
2394 }
2395 }
2396
2397
2410 public SocialRelation findByType_Last(int type,
2411 OrderByComparator orderByComparator)
2412 throws NoSuchRelationException, SystemException {
2413 int count = countByType(type);
2414
2415 List<SocialRelation> list = findByType(type, count - 1, count,
2416 orderByComparator);
2417
2418 if (list.isEmpty()) {
2419 StringBundler msg = new StringBundler(4);
2420
2421 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2422
2423 msg.append("type=");
2424 msg.append(type);
2425
2426 msg.append(StringPool.CLOSE_CURLY_BRACE);
2427
2428 throw new NoSuchRelationException(msg.toString());
2429 }
2430 else {
2431 return list.get(0);
2432 }
2433 }
2434
2435
2449 public SocialRelation[] findByType_PrevAndNext(long relationId, int type,
2450 OrderByComparator orderByComparator)
2451 throws NoSuchRelationException, SystemException {
2452 SocialRelation socialRelation = findByPrimaryKey(relationId);
2453
2454 Session session = null;
2455
2456 try {
2457 session = openSession();
2458
2459 SocialRelation[] array = new SocialRelationImpl[3];
2460
2461 array[0] = getByType_PrevAndNext(session, socialRelation, type,
2462 orderByComparator, true);
2463
2464 array[1] = socialRelation;
2465
2466 array[2] = getByType_PrevAndNext(session, socialRelation, type,
2467 orderByComparator, false);
2468
2469 return array;
2470 }
2471 catch (Exception e) {
2472 throw processException(e);
2473 }
2474 finally {
2475 closeSession(session);
2476 }
2477 }
2478
2479 protected SocialRelation getByType_PrevAndNext(Session session,
2480 SocialRelation socialRelation, int type,
2481 OrderByComparator orderByComparator, boolean previous) {
2482 StringBundler query = null;
2483
2484 if (orderByComparator != null) {
2485 query = new StringBundler(6 +
2486 (orderByComparator.getOrderByFields().length * 6));
2487 }
2488 else {
2489 query = new StringBundler(3);
2490 }
2491
2492 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
2493
2494 query.append(_FINDER_COLUMN_TYPE_TYPE_2);
2495
2496 if (orderByComparator != null) {
2497 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2498
2499 if (orderByConditionFields.length > 0) {
2500 query.append(WHERE_AND);
2501 }
2502
2503 for (int i = 0; i < orderByConditionFields.length; i++) {
2504 query.append(_ORDER_BY_ENTITY_ALIAS);
2505 query.append(orderByConditionFields[i]);
2506
2507 if ((i + 1) < orderByConditionFields.length) {
2508 if (orderByComparator.isAscending() ^ previous) {
2509 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2510 }
2511 else {
2512 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2513 }
2514 }
2515 else {
2516 if (orderByComparator.isAscending() ^ previous) {
2517 query.append(WHERE_GREATER_THAN);
2518 }
2519 else {
2520 query.append(WHERE_LESSER_THAN);
2521 }
2522 }
2523 }
2524
2525 query.append(ORDER_BY_CLAUSE);
2526
2527 String[] orderByFields = orderByComparator.getOrderByFields();
2528
2529 for (int i = 0; i < orderByFields.length; i++) {
2530 query.append(_ORDER_BY_ENTITY_ALIAS);
2531 query.append(orderByFields[i]);
2532
2533 if ((i + 1) < orderByFields.length) {
2534 if (orderByComparator.isAscending() ^ previous) {
2535 query.append(ORDER_BY_ASC_HAS_NEXT);
2536 }
2537 else {
2538 query.append(ORDER_BY_DESC_HAS_NEXT);
2539 }
2540 }
2541 else {
2542 if (orderByComparator.isAscending() ^ previous) {
2543 query.append(ORDER_BY_ASC);
2544 }
2545 else {
2546 query.append(ORDER_BY_DESC);
2547 }
2548 }
2549 }
2550 }
2551
2552 String sql = query.toString();
2553
2554 Query q = session.createQuery(sql);
2555
2556 q.setFirstResult(0);
2557 q.setMaxResults(2);
2558
2559 QueryPos qPos = QueryPos.getInstance(q);
2560
2561 qPos.add(type);
2562
2563 if (orderByComparator != null) {
2564 Object[] values = orderByComparator.getOrderByConditionValues(socialRelation);
2565
2566 for (Object value : values) {
2567 qPos.add(value);
2568 }
2569 }
2570
2571 List<SocialRelation> list = q.list();
2572
2573 if (list.size() == 2) {
2574 return list.get(1);
2575 }
2576 else {
2577 return null;
2578 }
2579 }
2580
2581
2589 public List<SocialRelation> findByC_T(long companyId, int type)
2590 throws SystemException {
2591 return findByC_T(companyId, type, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2592 null);
2593 }
2594
2595
2609 public List<SocialRelation> findByC_T(long companyId, int type, int start,
2610 int end) throws SystemException {
2611 return findByC_T(companyId, type, start, end, null);
2612 }
2613
2614
2629 public List<SocialRelation> findByC_T(long companyId, int type, int start,
2630 int end, OrderByComparator orderByComparator) throws SystemException {
2631 FinderPath finderPath = null;
2632 Object[] finderArgs = null;
2633
2634 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2635 (orderByComparator == null)) {
2636 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_T;
2637 finderArgs = new Object[] { companyId, type };
2638 }
2639 else {
2640 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_T;
2641 finderArgs = new Object[] {
2642 companyId, type,
2643
2644 start, end, orderByComparator
2645 };
2646 }
2647
2648 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(finderPath,
2649 finderArgs, this);
2650
2651 if (list == null) {
2652 StringBundler query = null;
2653
2654 if (orderByComparator != null) {
2655 query = new StringBundler(4 +
2656 (orderByComparator.getOrderByFields().length * 3));
2657 }
2658 else {
2659 query = new StringBundler(3);
2660 }
2661
2662 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
2663
2664 query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
2665
2666 query.append(_FINDER_COLUMN_C_T_TYPE_2);
2667
2668 if (orderByComparator != null) {
2669 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2670 orderByComparator);
2671 }
2672
2673 String sql = query.toString();
2674
2675 Session session = null;
2676
2677 try {
2678 session = openSession();
2679
2680 Query q = session.createQuery(sql);
2681
2682 QueryPos qPos = QueryPos.getInstance(q);
2683
2684 qPos.add(companyId);
2685
2686 qPos.add(type);
2687
2688 list = (List<SocialRelation>)QueryUtil.list(q, getDialect(),
2689 start, end);
2690 }
2691 catch (Exception e) {
2692 throw processException(e);
2693 }
2694 finally {
2695 if (list == null) {
2696 FinderCacheUtil.removeResult(finderPath, finderArgs);
2697 }
2698 else {
2699 cacheResult(list);
2700
2701 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2702 }
2703
2704 closeSession(session);
2705 }
2706 }
2707
2708 return list;
2709 }
2710
2711
2725 public SocialRelation findByC_T_First(long companyId, int type,
2726 OrderByComparator orderByComparator)
2727 throws NoSuchRelationException, SystemException {
2728 List<SocialRelation> list = findByC_T(companyId, type, 0, 1,
2729 orderByComparator);
2730
2731 if (list.isEmpty()) {
2732 StringBundler msg = new StringBundler(6);
2733
2734 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2735
2736 msg.append("companyId=");
2737 msg.append(companyId);
2738
2739 msg.append(", type=");
2740 msg.append(type);
2741
2742 msg.append(StringPool.CLOSE_CURLY_BRACE);
2743
2744 throw new NoSuchRelationException(msg.toString());
2745 }
2746 else {
2747 return list.get(0);
2748 }
2749 }
2750
2751
2765 public SocialRelation findByC_T_Last(long companyId, int type,
2766 OrderByComparator orderByComparator)
2767 throws NoSuchRelationException, SystemException {
2768 int count = countByC_T(companyId, type);
2769
2770 List<SocialRelation> list = findByC_T(companyId, type, count - 1,
2771 count, orderByComparator);
2772
2773 if (list.isEmpty()) {
2774 StringBundler msg = new StringBundler(6);
2775
2776 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2777
2778 msg.append("companyId=");
2779 msg.append(companyId);
2780
2781 msg.append(", type=");
2782 msg.append(type);
2783
2784 msg.append(StringPool.CLOSE_CURLY_BRACE);
2785
2786 throw new NoSuchRelationException(msg.toString());
2787 }
2788 else {
2789 return list.get(0);
2790 }
2791 }
2792
2793
2808 public SocialRelation[] findByC_T_PrevAndNext(long relationId,
2809 long companyId, int type, OrderByComparator orderByComparator)
2810 throws NoSuchRelationException, SystemException {
2811 SocialRelation socialRelation = findByPrimaryKey(relationId);
2812
2813 Session session = null;
2814
2815 try {
2816 session = openSession();
2817
2818 SocialRelation[] array = new SocialRelationImpl[3];
2819
2820 array[0] = getByC_T_PrevAndNext(session, socialRelation, companyId,
2821 type, orderByComparator, true);
2822
2823 array[1] = socialRelation;
2824
2825 array[2] = getByC_T_PrevAndNext(session, socialRelation, companyId,
2826 type, orderByComparator, false);
2827
2828 return array;
2829 }
2830 catch (Exception e) {
2831 throw processException(e);
2832 }
2833 finally {
2834 closeSession(session);
2835 }
2836 }
2837
2838 protected SocialRelation getByC_T_PrevAndNext(Session session,
2839 SocialRelation socialRelation, long companyId, int type,
2840 OrderByComparator orderByComparator, boolean previous) {
2841 StringBundler query = null;
2842
2843 if (orderByComparator != null) {
2844 query = new StringBundler(6 +
2845 (orderByComparator.getOrderByFields().length * 6));
2846 }
2847 else {
2848 query = new StringBundler(3);
2849 }
2850
2851 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
2852
2853 query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
2854
2855 query.append(_FINDER_COLUMN_C_T_TYPE_2);
2856
2857 if (orderByComparator != null) {
2858 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2859
2860 if (orderByConditionFields.length > 0) {
2861 query.append(WHERE_AND);
2862 }
2863
2864 for (int i = 0; i < orderByConditionFields.length; i++) {
2865 query.append(_ORDER_BY_ENTITY_ALIAS);
2866 query.append(orderByConditionFields[i]);
2867
2868 if ((i + 1) < orderByConditionFields.length) {
2869 if (orderByComparator.isAscending() ^ previous) {
2870 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2871 }
2872 else {
2873 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2874 }
2875 }
2876 else {
2877 if (orderByComparator.isAscending() ^ previous) {
2878 query.append(WHERE_GREATER_THAN);
2879 }
2880 else {
2881 query.append(WHERE_LESSER_THAN);
2882 }
2883 }
2884 }
2885
2886 query.append(ORDER_BY_CLAUSE);
2887
2888 String[] orderByFields = orderByComparator.getOrderByFields();
2889
2890 for (int i = 0; i < orderByFields.length; i++) {
2891 query.append(_ORDER_BY_ENTITY_ALIAS);
2892 query.append(orderByFields[i]);
2893
2894 if ((i + 1) < orderByFields.length) {
2895 if (orderByComparator.isAscending() ^ previous) {
2896 query.append(ORDER_BY_ASC_HAS_NEXT);
2897 }
2898 else {
2899 query.append(ORDER_BY_DESC_HAS_NEXT);
2900 }
2901 }
2902 else {
2903 if (orderByComparator.isAscending() ^ previous) {
2904 query.append(ORDER_BY_ASC);
2905 }
2906 else {
2907 query.append(ORDER_BY_DESC);
2908 }
2909 }
2910 }
2911 }
2912
2913 String sql = query.toString();
2914
2915 Query q = session.createQuery(sql);
2916
2917 q.setFirstResult(0);
2918 q.setMaxResults(2);
2919
2920 QueryPos qPos = QueryPos.getInstance(q);
2921
2922 qPos.add(companyId);
2923
2924 qPos.add(type);
2925
2926 if (orderByComparator != null) {
2927 Object[] values = orderByComparator.getOrderByConditionValues(socialRelation);
2928
2929 for (Object value : values) {
2930 qPos.add(value);
2931 }
2932 }
2933
2934 List<SocialRelation> list = q.list();
2935
2936 if (list.size() == 2) {
2937 return list.get(1);
2938 }
2939 else {
2940 return null;
2941 }
2942 }
2943
2944
2952 public List<SocialRelation> findByU1_U2(long userId1, long userId2)
2953 throws SystemException {
2954 return findByU1_U2(userId1, userId2, QueryUtil.ALL_POS,
2955 QueryUtil.ALL_POS, null);
2956 }
2957
2958
2972 public List<SocialRelation> findByU1_U2(long userId1, long userId2,
2973 int start, int end) throws SystemException {
2974 return findByU1_U2(userId1, userId2, start, end, null);
2975 }
2976
2977
2992 public List<SocialRelation> findByU1_U2(long userId1, long userId2,
2993 int start, int end, OrderByComparator orderByComparator)
2994 throws SystemException {
2995 FinderPath finderPath = null;
2996 Object[] finderArgs = null;
2997
2998 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2999 (orderByComparator == null)) {
3000 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U1_U2;
3001 finderArgs = new Object[] { userId1, userId2 };
3002 }
3003 else {
3004 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U1_U2;
3005 finderArgs = new Object[] {
3006 userId1, userId2,
3007
3008 start, end, orderByComparator
3009 };
3010 }
3011
3012 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(finderPath,
3013 finderArgs, this);
3014
3015 if (list == null) {
3016 StringBundler query = null;
3017
3018 if (orderByComparator != null) {
3019 query = new StringBundler(4 +
3020 (orderByComparator.getOrderByFields().length * 3));
3021 }
3022 else {
3023 query = new StringBundler(3);
3024 }
3025
3026 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
3027
3028 query.append(_FINDER_COLUMN_U1_U2_USERID1_2);
3029
3030 query.append(_FINDER_COLUMN_U1_U2_USERID2_2);
3031
3032 if (orderByComparator != null) {
3033 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3034 orderByComparator);
3035 }
3036
3037 String sql = query.toString();
3038
3039 Session session = null;
3040
3041 try {
3042 session = openSession();
3043
3044 Query q = session.createQuery(sql);
3045
3046 QueryPos qPos = QueryPos.getInstance(q);
3047
3048 qPos.add(userId1);
3049
3050 qPos.add(userId2);
3051
3052 list = (List<SocialRelation>)QueryUtil.list(q, getDialect(),
3053 start, end);
3054 }
3055 catch (Exception e) {
3056 throw processException(e);
3057 }
3058 finally {
3059 if (list == null) {
3060 FinderCacheUtil.removeResult(finderPath, finderArgs);
3061 }
3062 else {
3063 cacheResult(list);
3064
3065 FinderCacheUtil.putResult(finderPath, finderArgs, list);
3066 }
3067
3068 closeSession(session);
3069 }
3070 }
3071
3072 return list;
3073 }
3074
3075
3089 public SocialRelation findByU1_U2_First(long userId1, long userId2,
3090 OrderByComparator orderByComparator)
3091 throws NoSuchRelationException, SystemException {
3092 List<SocialRelation> list = findByU1_U2(userId1, userId2, 0, 1,
3093 orderByComparator);
3094
3095 if (list.isEmpty()) {
3096 StringBundler msg = new StringBundler(6);
3097
3098 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3099
3100 msg.append("userId1=");
3101 msg.append(userId1);
3102
3103 msg.append(", userId2=");
3104 msg.append(userId2);
3105
3106 msg.append(StringPool.CLOSE_CURLY_BRACE);
3107
3108 throw new NoSuchRelationException(msg.toString());
3109 }
3110 else {
3111 return list.get(0);
3112 }
3113 }
3114
3115
3129 public SocialRelation findByU1_U2_Last(long userId1, long userId2,
3130 OrderByComparator orderByComparator)
3131 throws NoSuchRelationException, SystemException {
3132 int count = countByU1_U2(userId1, userId2);
3133
3134 List<SocialRelation> list = findByU1_U2(userId1, userId2, count - 1,
3135 count, orderByComparator);
3136
3137 if (list.isEmpty()) {
3138 StringBundler msg = new StringBundler(6);
3139
3140 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3141
3142 msg.append("userId1=");
3143 msg.append(userId1);
3144
3145 msg.append(", userId2=");
3146 msg.append(userId2);
3147
3148 msg.append(StringPool.CLOSE_CURLY_BRACE);
3149
3150 throw new NoSuchRelationException(msg.toString());
3151 }
3152 else {
3153 return list.get(0);
3154 }
3155 }
3156
3157
3172 public SocialRelation[] findByU1_U2_PrevAndNext(long relationId,
3173 long userId1, long userId2, OrderByComparator orderByComparator)
3174 throws NoSuchRelationException, SystemException {
3175 SocialRelation socialRelation = findByPrimaryKey(relationId);
3176
3177 Session session = null;
3178
3179 try {
3180 session = openSession();
3181
3182 SocialRelation[] array = new SocialRelationImpl[3];
3183
3184 array[0] = getByU1_U2_PrevAndNext(session, socialRelation, userId1,
3185 userId2, orderByComparator, true);
3186
3187 array[1] = socialRelation;
3188
3189 array[2] = getByU1_U2_PrevAndNext(session, socialRelation, userId1,
3190 userId2, orderByComparator, false);
3191
3192 return array;
3193 }
3194 catch (Exception e) {
3195 throw processException(e);
3196 }
3197 finally {
3198 closeSession(session);
3199 }
3200 }
3201
3202 protected SocialRelation getByU1_U2_PrevAndNext(Session session,
3203 SocialRelation socialRelation, long userId1, long userId2,
3204 OrderByComparator orderByComparator, boolean previous) {
3205 StringBundler query = null;
3206
3207 if (orderByComparator != null) {
3208 query = new StringBundler(6 +
3209 (orderByComparator.getOrderByFields().length * 6));
3210 }
3211 else {
3212 query = new StringBundler(3);
3213 }
3214
3215 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
3216
3217 query.append(_FINDER_COLUMN_U1_U2_USERID1_2);
3218
3219 query.append(_FINDER_COLUMN_U1_U2_USERID2_2);
3220
3221 if (orderByComparator != null) {
3222 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3223
3224 if (orderByConditionFields.length > 0) {
3225 query.append(WHERE_AND);
3226 }
3227
3228 for (int i = 0; i < orderByConditionFields.length; i++) {
3229 query.append(_ORDER_BY_ENTITY_ALIAS);
3230 query.append(orderByConditionFields[i]);
3231
3232 if ((i + 1) < orderByConditionFields.length) {
3233 if (orderByComparator.isAscending() ^ previous) {
3234 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3235 }
3236 else {
3237 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3238 }
3239 }
3240 else {
3241 if (orderByComparator.isAscending() ^ previous) {
3242 query.append(WHERE_GREATER_THAN);
3243 }
3244 else {
3245 query.append(WHERE_LESSER_THAN);
3246 }
3247 }
3248 }
3249
3250 query.append(ORDER_BY_CLAUSE);
3251
3252 String[] orderByFields = orderByComparator.getOrderByFields();
3253
3254 for (int i = 0; i < orderByFields.length; i++) {
3255 query.append(_ORDER_BY_ENTITY_ALIAS);
3256 query.append(orderByFields[i]);
3257
3258 if ((i + 1) < orderByFields.length) {
3259 if (orderByComparator.isAscending() ^ previous) {
3260 query.append(ORDER_BY_ASC_HAS_NEXT);
3261 }
3262 else {
3263 query.append(ORDER_BY_DESC_HAS_NEXT);
3264 }
3265 }
3266 else {
3267 if (orderByComparator.isAscending() ^ previous) {
3268 query.append(ORDER_BY_ASC);
3269 }
3270 else {
3271 query.append(ORDER_BY_DESC);
3272 }
3273 }
3274 }
3275 }
3276
3277 String sql = query.toString();
3278
3279 Query q = session.createQuery(sql);
3280
3281 q.setFirstResult(0);
3282 q.setMaxResults(2);
3283
3284 QueryPos qPos = QueryPos.getInstance(q);
3285
3286 qPos.add(userId1);
3287
3288 qPos.add(userId2);
3289
3290 if (orderByComparator != null) {
3291 Object[] values = orderByComparator.getOrderByConditionValues(socialRelation);
3292
3293 for (Object value : values) {
3294 qPos.add(value);
3295 }
3296 }
3297
3298 List<SocialRelation> list = q.list();
3299
3300 if (list.size() == 2) {
3301 return list.get(1);
3302 }
3303 else {
3304 return null;
3305 }
3306 }
3307
3308
3316 public List<SocialRelation> findByU1_T(long userId1, int type)
3317 throws SystemException {
3318 return findByU1_T(userId1, type, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
3319 null);
3320 }
3321
3322
3336 public List<SocialRelation> findByU1_T(long userId1, int type, int start,
3337 int end) throws SystemException {
3338 return findByU1_T(userId1, type, start, end, null);
3339 }
3340
3341
3356 public List<SocialRelation> findByU1_T(long userId1, int type, int start,
3357 int end, OrderByComparator orderByComparator) throws SystemException {
3358 FinderPath finderPath = null;
3359 Object[] finderArgs = null;
3360
3361 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3362 (orderByComparator == null)) {
3363 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U1_T;
3364 finderArgs = new Object[] { userId1, type };
3365 }
3366 else {
3367 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U1_T;
3368 finderArgs = new Object[] {
3369 userId1, type,
3370
3371 start, end, orderByComparator
3372 };
3373 }
3374
3375 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(finderPath,
3376 finderArgs, this);
3377
3378 if (list == null) {
3379 StringBundler query = null;
3380
3381 if (orderByComparator != null) {
3382 query = new StringBundler(4 +
3383 (orderByComparator.getOrderByFields().length * 3));
3384 }
3385 else {
3386 query = new StringBundler(3);
3387 }
3388
3389 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
3390
3391 query.append(_FINDER_COLUMN_U1_T_USERID1_2);
3392
3393 query.append(_FINDER_COLUMN_U1_T_TYPE_2);
3394
3395 if (orderByComparator != null) {
3396 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3397 orderByComparator);
3398 }
3399
3400 String sql = query.toString();
3401
3402 Session session = null;
3403
3404 try {
3405 session = openSession();
3406
3407 Query q = session.createQuery(sql);
3408
3409 QueryPos qPos = QueryPos.getInstance(q);
3410
3411 qPos.add(userId1);
3412
3413 qPos.add(type);
3414
3415 list = (List<SocialRelation>)QueryUtil.list(q, getDialect(),
3416 start, end);
3417 }
3418 catch (Exception e) {
3419 throw processException(e);
3420 }
3421 finally {
3422 if (list == null) {
3423 FinderCacheUtil.removeResult(finderPath, finderArgs);
3424 }
3425 else {
3426 cacheResult(list);
3427
3428 FinderCacheUtil.putResult(finderPath, finderArgs, list);
3429 }
3430
3431 closeSession(session);
3432 }
3433 }
3434
3435 return list;
3436 }
3437
3438
3452 public SocialRelation findByU1_T_First(long userId1, int type,
3453 OrderByComparator orderByComparator)
3454 throws NoSuchRelationException, SystemException {
3455 List<SocialRelation> list = findByU1_T(userId1, type, 0, 1,
3456 orderByComparator);
3457
3458 if (list.isEmpty()) {
3459 StringBundler msg = new StringBundler(6);
3460
3461 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3462
3463 msg.append("userId1=");
3464 msg.append(userId1);
3465
3466 msg.append(", type=");
3467 msg.append(type);
3468
3469 msg.append(StringPool.CLOSE_CURLY_BRACE);
3470
3471 throw new NoSuchRelationException(msg.toString());
3472 }
3473 else {
3474 return list.get(0);
3475 }
3476 }
3477
3478
3492 public SocialRelation findByU1_T_Last(long userId1, int type,
3493 OrderByComparator orderByComparator)
3494 throws NoSuchRelationException, SystemException {
3495 int count = countByU1_T(userId1, type);
3496
3497 List<SocialRelation> list = findByU1_T(userId1, type, count - 1, count,
3498 orderByComparator);
3499
3500 if (list.isEmpty()) {
3501 StringBundler msg = new StringBundler(6);
3502
3503 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3504
3505 msg.append("userId1=");
3506 msg.append(userId1);
3507
3508 msg.append(", type=");
3509 msg.append(type);
3510
3511 msg.append(StringPool.CLOSE_CURLY_BRACE);
3512
3513 throw new NoSuchRelationException(msg.toString());
3514 }
3515 else {
3516 return list.get(0);
3517 }
3518 }
3519
3520
3535 public SocialRelation[] findByU1_T_PrevAndNext(long relationId,
3536 long userId1, int type, OrderByComparator orderByComparator)
3537 throws NoSuchRelationException, SystemException {
3538 SocialRelation socialRelation = findByPrimaryKey(relationId);
3539
3540 Session session = null;
3541
3542 try {
3543 session = openSession();
3544
3545 SocialRelation[] array = new SocialRelationImpl[3];
3546
3547 array[0] = getByU1_T_PrevAndNext(session, socialRelation, userId1,
3548 type, orderByComparator, true);
3549
3550 array[1] = socialRelation;
3551
3552 array[2] = getByU1_T_PrevAndNext(session, socialRelation, userId1,
3553 type, orderByComparator, false);
3554
3555 return array;
3556 }
3557 catch (Exception e) {
3558 throw processException(e);
3559 }
3560 finally {
3561 closeSession(session);
3562 }
3563 }
3564
3565 protected SocialRelation getByU1_T_PrevAndNext(Session session,
3566 SocialRelation socialRelation, long userId1, int type,
3567 OrderByComparator orderByComparator, boolean previous) {
3568 StringBundler query = null;
3569
3570 if (orderByComparator != null) {
3571 query = new StringBundler(6 +
3572 (orderByComparator.getOrderByFields().length * 6));
3573 }
3574 else {
3575 query = new StringBundler(3);
3576 }
3577
3578 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
3579
3580 query.append(_FINDER_COLUMN_U1_T_USERID1_2);
3581
3582 query.append(_FINDER_COLUMN_U1_T_TYPE_2);
3583
3584 if (orderByComparator != null) {
3585 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3586
3587 if (orderByConditionFields.length > 0) {
3588 query.append(WHERE_AND);
3589 }
3590
3591 for (int i = 0; i < orderByConditionFields.length; i++) {
3592 query.append(_ORDER_BY_ENTITY_ALIAS);
3593 query.append(orderByConditionFields[i]);
3594
3595 if ((i + 1) < orderByConditionFields.length) {
3596 if (orderByComparator.isAscending() ^ previous) {
3597 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3598 }
3599 else {
3600 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3601 }
3602 }
3603 else {
3604 if (orderByComparator.isAscending() ^ previous) {
3605 query.append(WHERE_GREATER_THAN);
3606 }
3607 else {
3608 query.append(WHERE_LESSER_THAN);
3609 }
3610 }
3611 }
3612
3613 query.append(ORDER_BY_CLAUSE);
3614
3615 String[] orderByFields = orderByComparator.getOrderByFields();
3616
3617 for (int i = 0; i < orderByFields.length; i++) {
3618 query.append(_ORDER_BY_ENTITY_ALIAS);
3619 query.append(orderByFields[i]);
3620
3621 if ((i + 1) < orderByFields.length) {
3622 if (orderByComparator.isAscending() ^ previous) {
3623 query.append(ORDER_BY_ASC_HAS_NEXT);
3624 }
3625 else {
3626 query.append(ORDER_BY_DESC_HAS_NEXT);
3627 }
3628 }
3629 else {
3630 if (orderByComparator.isAscending() ^ previous) {
3631 query.append(ORDER_BY_ASC);
3632 }
3633 else {
3634 query.append(ORDER_BY_DESC);
3635 }
3636 }
3637 }
3638 }
3639
3640 String sql = query.toString();
3641
3642 Query q = session.createQuery(sql);
3643
3644 q.setFirstResult(0);
3645 q.setMaxResults(2);
3646
3647 QueryPos qPos = QueryPos.getInstance(q);
3648
3649 qPos.add(userId1);
3650
3651 qPos.add(type);
3652
3653 if (orderByComparator != null) {
3654 Object[] values = orderByComparator.getOrderByConditionValues(socialRelation);
3655
3656 for (Object value : values) {
3657 qPos.add(value);
3658 }
3659 }
3660
3661 List<SocialRelation> list = q.list();
3662
3663 if (list.size() == 2) {
3664 return list.get(1);
3665 }
3666 else {
3667 return null;
3668 }
3669 }
3670
3671
3679 public List<SocialRelation> findByU2_T(long userId2, int type)
3680 throws SystemException {
3681 return findByU2_T(userId2, type, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
3682 null);
3683 }
3684
3685
3699 public List<SocialRelation> findByU2_T(long userId2, int type, int start,
3700 int end) throws SystemException {
3701 return findByU2_T(userId2, type, start, end, null);
3702 }
3703
3704
3719 public List<SocialRelation> findByU2_T(long userId2, int type, int start,
3720 int end, OrderByComparator orderByComparator) throws SystemException {
3721 FinderPath finderPath = null;
3722 Object[] finderArgs = null;
3723
3724 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3725 (orderByComparator == null)) {
3726 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U2_T;
3727 finderArgs = new Object[] { userId2, type };
3728 }
3729 else {
3730 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U2_T;
3731 finderArgs = new Object[] {
3732 userId2, type,
3733
3734 start, end, orderByComparator
3735 };
3736 }
3737
3738 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(finderPath,
3739 finderArgs, this);
3740
3741 if (list == null) {
3742 StringBundler query = null;
3743
3744 if (orderByComparator != null) {
3745 query = new StringBundler(4 +
3746 (orderByComparator.getOrderByFields().length * 3));
3747 }
3748 else {
3749 query = new StringBundler(3);
3750 }
3751
3752 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
3753
3754 query.append(_FINDER_COLUMN_U2_T_USERID2_2);
3755
3756 query.append(_FINDER_COLUMN_U2_T_TYPE_2);
3757
3758 if (orderByComparator != null) {
3759 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3760 orderByComparator);
3761 }
3762
3763 String sql = query.toString();
3764
3765 Session session = null;
3766
3767 try {
3768 session = openSession();
3769
3770 Query q = session.createQuery(sql);
3771
3772 QueryPos qPos = QueryPos.getInstance(q);
3773
3774 qPos.add(userId2);
3775
3776 qPos.add(type);
3777
3778 list = (List<SocialRelation>)QueryUtil.list(q, getDialect(),
3779 start, end);
3780 }
3781 catch (Exception e) {
3782 throw processException(e);
3783 }
3784 finally {
3785 if (list == null) {
3786 FinderCacheUtil.removeResult(finderPath, finderArgs);
3787 }
3788 else {
3789 cacheResult(list);
3790
3791 FinderCacheUtil.putResult(finderPath, finderArgs, list);
3792 }
3793
3794 closeSession(session);
3795 }
3796 }
3797
3798 return list;
3799 }
3800
3801
3815 public SocialRelation findByU2_T_First(long userId2, int type,
3816 OrderByComparator orderByComparator)
3817 throws NoSuchRelationException, SystemException {
3818 List<SocialRelation> list = findByU2_T(userId2, type, 0, 1,
3819 orderByComparator);
3820
3821 if (list.isEmpty()) {
3822 StringBundler msg = new StringBundler(6);
3823
3824 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3825
3826 msg.append("userId2=");
3827 msg.append(userId2);
3828
3829 msg.append(", type=");
3830 msg.append(type);
3831
3832 msg.append(StringPool.CLOSE_CURLY_BRACE);
3833
3834 throw new NoSuchRelationException(msg.toString());
3835 }
3836 else {
3837 return list.get(0);
3838 }
3839 }
3840
3841
3855 public SocialRelation findByU2_T_Last(long userId2, int type,
3856 OrderByComparator orderByComparator)
3857 throws NoSuchRelationException, SystemException {
3858 int count = countByU2_T(userId2, type);
3859
3860 List<SocialRelation> list = findByU2_T(userId2, type, count - 1, count,
3861 orderByComparator);
3862
3863 if (list.isEmpty()) {
3864 StringBundler msg = new StringBundler(6);
3865
3866 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3867
3868 msg.append("userId2=");
3869 msg.append(userId2);
3870
3871 msg.append(", type=");
3872 msg.append(type);
3873
3874 msg.append(StringPool.CLOSE_CURLY_BRACE);
3875
3876 throw new NoSuchRelationException(msg.toString());
3877 }
3878 else {
3879 return list.get(0);
3880 }
3881 }
3882
3883
3898 public SocialRelation[] findByU2_T_PrevAndNext(long relationId,
3899 long userId2, int type, OrderByComparator orderByComparator)
3900 throws NoSuchRelationException, SystemException {
3901 SocialRelation socialRelation = findByPrimaryKey(relationId);
3902
3903 Session session = null;
3904
3905 try {
3906 session = openSession();
3907
3908 SocialRelation[] array = new SocialRelationImpl[3];
3909
3910 array[0] = getByU2_T_PrevAndNext(session, socialRelation, userId2,
3911 type, orderByComparator, true);
3912
3913 array[1] = socialRelation;
3914
3915 array[2] = getByU2_T_PrevAndNext(session, socialRelation, userId2,
3916 type, orderByComparator, false);
3917
3918 return array;
3919 }
3920 catch (Exception e) {
3921 throw processException(e);
3922 }
3923 finally {
3924 closeSession(session);
3925 }
3926 }
3927
3928 protected SocialRelation getByU2_T_PrevAndNext(Session session,
3929 SocialRelation socialRelation, long userId2, int type,
3930 OrderByComparator orderByComparator, boolean previous) {
3931 StringBundler query = null;
3932
3933 if (orderByComparator != null) {
3934 query = new StringBundler(6 +
3935 (orderByComparator.getOrderByFields().length * 6));
3936 }
3937 else {
3938 query = new StringBundler(3);
3939 }
3940
3941 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
3942
3943 query.append(_FINDER_COLUMN_U2_T_USERID2_2);
3944
3945 query.append(_FINDER_COLUMN_U2_T_TYPE_2);
3946
3947 if (orderByComparator != null) {
3948 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3949
3950 if (orderByConditionFields.length > 0) {
3951 query.append(WHERE_AND);
3952 }
3953
3954 for (int i = 0; i < orderByConditionFields.length; i++) {
3955 query.append(_ORDER_BY_ENTITY_ALIAS);
3956 query.append(orderByConditionFields[i]);
3957
3958 if ((i + 1) < orderByConditionFields.length) {
3959 if (orderByComparator.isAscending() ^ previous) {
3960 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3961 }
3962 else {
3963 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3964 }
3965 }
3966 else {
3967 if (orderByComparator.isAscending() ^ previous) {
3968 query.append(WHERE_GREATER_THAN);
3969 }
3970 else {
3971 query.append(WHERE_LESSER_THAN);
3972 }
3973 }
3974 }
3975
3976 query.append(ORDER_BY_CLAUSE);
3977
3978 String[] orderByFields = orderByComparator.getOrderByFields();
3979
3980 for (int i = 0; i < orderByFields.length; i++) {
3981 query.append(_ORDER_BY_ENTITY_ALIAS);
3982 query.append(orderByFields[i]);
3983
3984 if ((i + 1) < orderByFields.length) {
3985 if (orderByComparator.isAscending() ^ previous) {
3986 query.append(ORDER_BY_ASC_HAS_NEXT);
3987 }
3988 else {
3989 query.append(ORDER_BY_DESC_HAS_NEXT);
3990 }
3991 }
3992 else {
3993 if (orderByComparator.isAscending() ^ previous) {
3994 query.append(ORDER_BY_ASC);
3995 }
3996 else {
3997 query.append(ORDER_BY_DESC);
3998 }
3999 }
4000 }
4001 }
4002
4003 String sql = query.toString();
4004
4005 Query q = session.createQuery(sql);
4006
4007 q.setFirstResult(0);
4008 q.setMaxResults(2);
4009
4010 QueryPos qPos = QueryPos.getInstance(q);
4011
4012 qPos.add(userId2);
4013
4014 qPos.add(type);
4015
4016 if (orderByComparator != null) {
4017 Object[] values = orderByComparator.getOrderByConditionValues(socialRelation);
4018
4019 for (Object value : values) {
4020 qPos.add(value);
4021 }
4022 }
4023
4024 List<SocialRelation> list = q.list();
4025
4026 if (list.size() == 2) {
4027 return list.get(1);
4028 }
4029 else {
4030 return null;
4031 }
4032 }
4033
4034
4044 public SocialRelation findByU1_U2_T(long userId1, long userId2, int type)
4045 throws NoSuchRelationException, SystemException {
4046 SocialRelation socialRelation = fetchByU1_U2_T(userId1, userId2, type);
4047
4048 if (socialRelation == null) {
4049 StringBundler msg = new StringBundler(8);
4050
4051 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4052
4053 msg.append("userId1=");
4054 msg.append(userId1);
4055
4056 msg.append(", userId2=");
4057 msg.append(userId2);
4058
4059 msg.append(", type=");
4060 msg.append(type);
4061
4062 msg.append(StringPool.CLOSE_CURLY_BRACE);
4063
4064 if (_log.isWarnEnabled()) {
4065 _log.warn(msg.toString());
4066 }
4067
4068 throw new NoSuchRelationException(msg.toString());
4069 }
4070
4071 return socialRelation;
4072 }
4073
4074
4083 public SocialRelation fetchByU1_U2_T(long userId1, long userId2, int type)
4084 throws SystemException {
4085 return fetchByU1_U2_T(userId1, userId2, type, true);
4086 }
4087
4088
4098 public SocialRelation fetchByU1_U2_T(long userId1, long userId2, int type,
4099 boolean retrieveFromCache) throws SystemException {
4100 Object[] finderArgs = new Object[] { userId1, userId2, type };
4101
4102 Object result = null;
4103
4104 if (retrieveFromCache) {
4105 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_U1_U2_T,
4106 finderArgs, this);
4107 }
4108
4109 if (result == null) {
4110 StringBundler query = new StringBundler(4);
4111
4112 query.append(_SQL_SELECT_SOCIALRELATION_WHERE);
4113
4114 query.append(_FINDER_COLUMN_U1_U2_T_USERID1_2);
4115
4116 query.append(_FINDER_COLUMN_U1_U2_T_USERID2_2);
4117
4118 query.append(_FINDER_COLUMN_U1_U2_T_TYPE_2);
4119
4120 String sql = query.toString();
4121
4122 Session session = null;
4123
4124 try {
4125 session = openSession();
4126
4127 Query q = session.createQuery(sql);
4128
4129 QueryPos qPos = QueryPos.getInstance(q);
4130
4131 qPos.add(userId1);
4132
4133 qPos.add(userId2);
4134
4135 qPos.add(type);
4136
4137 List<SocialRelation> list = q.list();
4138
4139 result = list;
4140
4141 SocialRelation socialRelation = null;
4142
4143 if (list.isEmpty()) {
4144 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U1_U2_T,
4145 finderArgs, list);
4146 }
4147 else {
4148 socialRelation = list.get(0);
4149
4150 cacheResult(socialRelation);
4151
4152 if ((socialRelation.getUserId1() != userId1) ||
4153 (socialRelation.getUserId2() != userId2) ||
4154 (socialRelation.getType() != type)) {
4155 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U1_U2_T,
4156 finderArgs, socialRelation);
4157 }
4158 }
4159
4160 return socialRelation;
4161 }
4162 catch (Exception e) {
4163 throw processException(e);
4164 }
4165 finally {
4166 if (result == null) {
4167 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U1_U2_T,
4168 finderArgs);
4169 }
4170
4171 closeSession(session);
4172 }
4173 }
4174 else {
4175 if (result instanceof List<?>) {
4176 return null;
4177 }
4178 else {
4179 return (SocialRelation)result;
4180 }
4181 }
4182 }
4183
4184
4190 public List<SocialRelation> findAll() throws SystemException {
4191 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
4192 }
4193
4194
4206 public List<SocialRelation> findAll(int start, int end)
4207 throws SystemException {
4208 return findAll(start, end, null);
4209 }
4210
4211
4224 public List<SocialRelation> findAll(int start, int end,
4225 OrderByComparator orderByComparator) throws SystemException {
4226 FinderPath finderPath = null;
4227 Object[] finderArgs = new Object[] { start, end, orderByComparator };
4228
4229 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4230 (orderByComparator == null)) {
4231 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
4232 finderArgs = FINDER_ARGS_EMPTY;
4233 }
4234 else {
4235 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
4236 finderArgs = new Object[] { start, end, orderByComparator };
4237 }
4238
4239 List<SocialRelation> list = (List<SocialRelation>)FinderCacheUtil.getResult(finderPath,
4240 finderArgs, this);
4241
4242 if (list == null) {
4243 StringBundler query = null;
4244 String sql = null;
4245
4246 if (orderByComparator != null) {
4247 query = new StringBundler(2 +
4248 (orderByComparator.getOrderByFields().length * 3));
4249
4250 query.append(_SQL_SELECT_SOCIALRELATION);
4251
4252 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4253 orderByComparator);
4254
4255 sql = query.toString();
4256 }
4257 else {
4258 sql = _SQL_SELECT_SOCIALRELATION;
4259 }
4260
4261 Session session = null;
4262
4263 try {
4264 session = openSession();
4265
4266 Query q = session.createQuery(sql);
4267
4268 if (orderByComparator == null) {
4269 list = (List<SocialRelation>)QueryUtil.list(q,
4270 getDialect(), start, end, false);
4271
4272 Collections.sort(list);
4273 }
4274 else {
4275 list = (List<SocialRelation>)QueryUtil.list(q,
4276 getDialect(), start, end);
4277 }
4278 }
4279 catch (Exception e) {
4280 throw processException(e);
4281 }
4282 finally {
4283 if (list == null) {
4284 FinderCacheUtil.removeResult(finderPath, finderArgs);
4285 }
4286 else {
4287 cacheResult(list);
4288
4289 FinderCacheUtil.putResult(finderPath, finderArgs, list);
4290 }
4291
4292 closeSession(session);
4293 }
4294 }
4295
4296 return list;
4297 }
4298
4299
4305 public void removeByUuid(String uuid) throws SystemException {
4306 for (SocialRelation socialRelation : findByUuid(uuid)) {
4307 remove(socialRelation);
4308 }
4309 }
4310
4311
4317 public void removeByCompanyId(long companyId) throws SystemException {
4318 for (SocialRelation socialRelation : findByCompanyId(companyId)) {
4319 remove(socialRelation);
4320 }
4321 }
4322
4323
4329 public void removeByUserId1(long userId1) throws SystemException {
4330 for (SocialRelation socialRelation : findByUserId1(userId1)) {
4331 remove(socialRelation);
4332 }
4333 }
4334
4335
4341 public void removeByUserId2(long userId2) throws SystemException {
4342 for (SocialRelation socialRelation : findByUserId2(userId2)) {
4343 remove(socialRelation);
4344 }
4345 }
4346
4347
4353 public void removeByType(int type) throws SystemException {
4354 for (SocialRelation socialRelation : findByType(type)) {
4355 remove(socialRelation);
4356 }
4357 }
4358
4359
4366 public void removeByC_T(long companyId, int type) throws SystemException {
4367 for (SocialRelation socialRelation : findByC_T(companyId, type)) {
4368 remove(socialRelation);
4369 }
4370 }
4371
4372
4379 public void removeByU1_U2(long userId1, long userId2)
4380 throws SystemException {
4381 for (SocialRelation socialRelation : findByU1_U2(userId1, userId2)) {
4382 remove(socialRelation);
4383 }
4384 }
4385
4386
4393 public void removeByU1_T(long userId1, int type) throws SystemException {
4394 for (SocialRelation socialRelation : findByU1_T(userId1, type)) {
4395 remove(socialRelation);
4396 }
4397 }
4398
4399
4406 public void removeByU2_T(long userId2, int type) throws SystemException {
4407 for (SocialRelation socialRelation : findByU2_T(userId2, type)) {
4408 remove(socialRelation);
4409 }
4410 }
4411
4412
4420 public void removeByU1_U2_T(long userId1, long userId2, int type)
4421 throws NoSuchRelationException, SystemException {
4422 SocialRelation socialRelation = findByU1_U2_T(userId1, userId2, type);
4423
4424 remove(socialRelation);
4425 }
4426
4427
4432 public void removeAll() throws SystemException {
4433 for (SocialRelation socialRelation : findAll()) {
4434 remove(socialRelation);
4435 }
4436 }
4437
4438
4445 public int countByUuid(String uuid) throws SystemException {
4446 Object[] finderArgs = new Object[] { uuid };
4447
4448 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
4449 finderArgs, this);
4450
4451 if (count == null) {
4452 StringBundler query = new StringBundler(2);
4453
4454 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
4455
4456 if (uuid == null) {
4457 query.append(_FINDER_COLUMN_UUID_UUID_1);
4458 }
4459 else {
4460 if (uuid.equals(StringPool.BLANK)) {
4461 query.append(_FINDER_COLUMN_UUID_UUID_3);
4462 }
4463 else {
4464 query.append(_FINDER_COLUMN_UUID_UUID_2);
4465 }
4466 }
4467
4468 String sql = query.toString();
4469
4470 Session session = null;
4471
4472 try {
4473 session = openSession();
4474
4475 Query q = session.createQuery(sql);
4476
4477 QueryPos qPos = QueryPos.getInstance(q);
4478
4479 if (uuid != null) {
4480 qPos.add(uuid);
4481 }
4482
4483 count = (Long)q.uniqueResult();
4484 }
4485 catch (Exception e) {
4486 throw processException(e);
4487 }
4488 finally {
4489 if (count == null) {
4490 count = Long.valueOf(0);
4491 }
4492
4493 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
4494 finderArgs, count);
4495
4496 closeSession(session);
4497 }
4498 }
4499
4500 return count.intValue();
4501 }
4502
4503
4510 public int countByCompanyId(long companyId) throws SystemException {
4511 Object[] finderArgs = new Object[] { companyId };
4512
4513 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
4514 finderArgs, this);
4515
4516 if (count == null) {
4517 StringBundler query = new StringBundler(2);
4518
4519 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
4520
4521 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
4522
4523 String sql = query.toString();
4524
4525 Session session = null;
4526
4527 try {
4528 session = openSession();
4529
4530 Query q = session.createQuery(sql);
4531
4532 QueryPos qPos = QueryPos.getInstance(q);
4533
4534 qPos.add(companyId);
4535
4536 count = (Long)q.uniqueResult();
4537 }
4538 catch (Exception e) {
4539 throw processException(e);
4540 }
4541 finally {
4542 if (count == null) {
4543 count = Long.valueOf(0);
4544 }
4545
4546 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
4547 finderArgs, count);
4548
4549 closeSession(session);
4550 }
4551 }
4552
4553 return count.intValue();
4554 }
4555
4556
4563 public int countByUserId1(long userId1) throws SystemException {
4564 Object[] finderArgs = new Object[] { userId1 };
4565
4566 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID1,
4567 finderArgs, this);
4568
4569 if (count == null) {
4570 StringBundler query = new StringBundler(2);
4571
4572 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
4573
4574 query.append(_FINDER_COLUMN_USERID1_USERID1_2);
4575
4576 String sql = query.toString();
4577
4578 Session session = null;
4579
4580 try {
4581 session = openSession();
4582
4583 Query q = session.createQuery(sql);
4584
4585 QueryPos qPos = QueryPos.getInstance(q);
4586
4587 qPos.add(userId1);
4588
4589 count = (Long)q.uniqueResult();
4590 }
4591 catch (Exception e) {
4592 throw processException(e);
4593 }
4594 finally {
4595 if (count == null) {
4596 count = Long.valueOf(0);
4597 }
4598
4599 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID1,
4600 finderArgs, count);
4601
4602 closeSession(session);
4603 }
4604 }
4605
4606 return count.intValue();
4607 }
4608
4609
4616 public int countByUserId2(long userId2) throws SystemException {
4617 Object[] finderArgs = new Object[] { userId2 };
4618
4619 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID2,
4620 finderArgs, this);
4621
4622 if (count == null) {
4623 StringBundler query = new StringBundler(2);
4624
4625 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
4626
4627 query.append(_FINDER_COLUMN_USERID2_USERID2_2);
4628
4629 String sql = query.toString();
4630
4631 Session session = null;
4632
4633 try {
4634 session = openSession();
4635
4636 Query q = session.createQuery(sql);
4637
4638 QueryPos qPos = QueryPos.getInstance(q);
4639
4640 qPos.add(userId2);
4641
4642 count = (Long)q.uniqueResult();
4643 }
4644 catch (Exception e) {
4645 throw processException(e);
4646 }
4647 finally {
4648 if (count == null) {
4649 count = Long.valueOf(0);
4650 }
4651
4652 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID2,
4653 finderArgs, count);
4654
4655 closeSession(session);
4656 }
4657 }
4658
4659 return count.intValue();
4660 }
4661
4662
4669 public int countByType(int type) throws SystemException {
4670 Object[] finderArgs = new Object[] { type };
4671
4672 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_TYPE,
4673 finderArgs, this);
4674
4675 if (count == null) {
4676 StringBundler query = new StringBundler(2);
4677
4678 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
4679
4680 query.append(_FINDER_COLUMN_TYPE_TYPE_2);
4681
4682 String sql = query.toString();
4683
4684 Session session = null;
4685
4686 try {
4687 session = openSession();
4688
4689 Query q = session.createQuery(sql);
4690
4691 QueryPos qPos = QueryPos.getInstance(q);
4692
4693 qPos.add(type);
4694
4695 count = (Long)q.uniqueResult();
4696 }
4697 catch (Exception e) {
4698 throw processException(e);
4699 }
4700 finally {
4701 if (count == null) {
4702 count = Long.valueOf(0);
4703 }
4704
4705 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_TYPE,
4706 finderArgs, count);
4707
4708 closeSession(session);
4709 }
4710 }
4711
4712 return count.intValue();
4713 }
4714
4715
4723 public int countByC_T(long companyId, int type) throws SystemException {
4724 Object[] finderArgs = new Object[] { companyId, type };
4725
4726 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_T,
4727 finderArgs, this);
4728
4729 if (count == null) {
4730 StringBundler query = new StringBundler(3);
4731
4732 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
4733
4734 query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
4735
4736 query.append(_FINDER_COLUMN_C_T_TYPE_2);
4737
4738 String sql = query.toString();
4739
4740 Session session = null;
4741
4742 try {
4743 session = openSession();
4744
4745 Query q = session.createQuery(sql);
4746
4747 QueryPos qPos = QueryPos.getInstance(q);
4748
4749 qPos.add(companyId);
4750
4751 qPos.add(type);
4752
4753 count = (Long)q.uniqueResult();
4754 }
4755 catch (Exception e) {
4756 throw processException(e);
4757 }
4758 finally {
4759 if (count == null) {
4760 count = Long.valueOf(0);
4761 }
4762
4763 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_T, finderArgs,
4764 count);
4765
4766 closeSession(session);
4767 }
4768 }
4769
4770 return count.intValue();
4771 }
4772
4773
4781 public int countByU1_U2(long userId1, long userId2)
4782 throws SystemException {
4783 Object[] finderArgs = new Object[] { userId1, userId2 };
4784
4785 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U1_U2,
4786 finderArgs, this);
4787
4788 if (count == null) {
4789 StringBundler query = new StringBundler(3);
4790
4791 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
4792
4793 query.append(_FINDER_COLUMN_U1_U2_USERID1_2);
4794
4795 query.append(_FINDER_COLUMN_U1_U2_USERID2_2);
4796
4797 String sql = query.toString();
4798
4799 Session session = null;
4800
4801 try {
4802 session = openSession();
4803
4804 Query q = session.createQuery(sql);
4805
4806 QueryPos qPos = QueryPos.getInstance(q);
4807
4808 qPos.add(userId1);
4809
4810 qPos.add(userId2);
4811
4812 count = (Long)q.uniqueResult();
4813 }
4814 catch (Exception e) {
4815 throw processException(e);
4816 }
4817 finally {
4818 if (count == null) {
4819 count = Long.valueOf(0);
4820 }
4821
4822 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U1_U2,
4823 finderArgs, count);
4824
4825 closeSession(session);
4826 }
4827 }
4828
4829 return count.intValue();
4830 }
4831
4832
4840 public int countByU1_T(long userId1, int type) throws SystemException {
4841 Object[] finderArgs = new Object[] { userId1, type };
4842
4843 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U1_T,
4844 finderArgs, this);
4845
4846 if (count == null) {
4847 StringBundler query = new StringBundler(3);
4848
4849 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
4850
4851 query.append(_FINDER_COLUMN_U1_T_USERID1_2);
4852
4853 query.append(_FINDER_COLUMN_U1_T_TYPE_2);
4854
4855 String sql = query.toString();
4856
4857 Session session = null;
4858
4859 try {
4860 session = openSession();
4861
4862 Query q = session.createQuery(sql);
4863
4864 QueryPos qPos = QueryPos.getInstance(q);
4865
4866 qPos.add(userId1);
4867
4868 qPos.add(type);
4869
4870 count = (Long)q.uniqueResult();
4871 }
4872 catch (Exception e) {
4873 throw processException(e);
4874 }
4875 finally {
4876 if (count == null) {
4877 count = Long.valueOf(0);
4878 }
4879
4880 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U1_T,
4881 finderArgs, count);
4882
4883 closeSession(session);
4884 }
4885 }
4886
4887 return count.intValue();
4888 }
4889
4890
4898 public int countByU2_T(long userId2, int type) throws SystemException {
4899 Object[] finderArgs = new Object[] { userId2, type };
4900
4901 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U2_T,
4902 finderArgs, this);
4903
4904 if (count == null) {
4905 StringBundler query = new StringBundler(3);
4906
4907 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
4908
4909 query.append(_FINDER_COLUMN_U2_T_USERID2_2);
4910
4911 query.append(_FINDER_COLUMN_U2_T_TYPE_2);
4912
4913 String sql = query.toString();
4914
4915 Session session = null;
4916
4917 try {
4918 session = openSession();
4919
4920 Query q = session.createQuery(sql);
4921
4922 QueryPos qPos = QueryPos.getInstance(q);
4923
4924 qPos.add(userId2);
4925
4926 qPos.add(type);
4927
4928 count = (Long)q.uniqueResult();
4929 }
4930 catch (Exception e) {
4931 throw processException(e);
4932 }
4933 finally {
4934 if (count == null) {
4935 count = Long.valueOf(0);
4936 }
4937
4938 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U2_T,
4939 finderArgs, count);
4940
4941 closeSession(session);
4942 }
4943 }
4944
4945 return count.intValue();
4946 }
4947
4948
4957 public int countByU1_U2_T(long userId1, long userId2, int type)
4958 throws SystemException {
4959 Object[] finderArgs = new Object[] { userId1, userId2, type };
4960
4961 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U1_U2_T,
4962 finderArgs, this);
4963
4964 if (count == null) {
4965 StringBundler query = new StringBundler(4);
4966
4967 query.append(_SQL_COUNT_SOCIALRELATION_WHERE);
4968
4969 query.append(_FINDER_COLUMN_U1_U2_T_USERID1_2);
4970
4971 query.append(_FINDER_COLUMN_U1_U2_T_USERID2_2);
4972
4973 query.append(_FINDER_COLUMN_U1_U2_T_TYPE_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(userId1);
4987
4988 qPos.add(userId2);
4989
4990 qPos.add(type);
4991
4992 count = (Long)q.uniqueResult();
4993 }
4994 catch (Exception e) {
4995 throw processException(e);
4996 }
4997 finally {
4998 if (count == null) {
4999 count = Long.valueOf(0);
5000 }
5001
5002 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U1_U2_T,
5003 finderArgs, count);
5004
5005 closeSession(session);
5006 }
5007 }
5008
5009 return count.intValue();
5010 }
5011
5012
5018 public int countAll() throws SystemException {
5019 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
5020 FINDER_ARGS_EMPTY, this);
5021
5022 if (count == null) {
5023 Session session = null;
5024
5025 try {
5026 session = openSession();
5027
5028 Query q = session.createQuery(_SQL_COUNT_SOCIALRELATION);
5029
5030 count = (Long)q.uniqueResult();
5031 }
5032 catch (Exception e) {
5033 throw processException(e);
5034 }
5035 finally {
5036 if (count == null) {
5037 count = Long.valueOf(0);
5038 }
5039
5040 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
5041 FINDER_ARGS_EMPTY, count);
5042
5043 closeSession(session);
5044 }
5045 }
5046
5047 return count.intValue();
5048 }
5049
5050
5053 public void afterPropertiesSet() {
5054 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
5055 com.liferay.portal.util.PropsUtil.get(
5056 "value.object.listener.com.liferay.portlet.social.model.SocialRelation")));
5057
5058 if (listenerClassNames.length > 0) {
5059 try {
5060 List<ModelListener<SocialRelation>> listenersList = new ArrayList<ModelListener<SocialRelation>>();
5061
5062 for (String listenerClassName : listenerClassNames) {
5063 listenersList.add((ModelListener<SocialRelation>)InstanceFactory.newInstance(
5064 listenerClassName));
5065 }
5066
5067 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
5068 }
5069 catch (Exception e) {
5070 _log.error(e);
5071 }
5072 }
5073 }
5074
5075 public void destroy() {
5076 EntityCacheUtil.removeCache(SocialRelationImpl.class.getName());
5077 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
5078 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
5079 }
5080
5081 @BeanReference(type = SocialActivityPersistence.class)
5082 protected SocialActivityPersistence socialActivityPersistence;
5083 @BeanReference(type = SocialActivityAchievementPersistence.class)
5084 protected SocialActivityAchievementPersistence socialActivityAchievementPersistence;
5085 @BeanReference(type = SocialActivityCounterPersistence.class)
5086 protected SocialActivityCounterPersistence socialActivityCounterPersistence;
5087 @BeanReference(type = SocialActivityLimitPersistence.class)
5088 protected SocialActivityLimitPersistence socialActivityLimitPersistence;
5089 @BeanReference(type = SocialActivitySettingPersistence.class)
5090 protected SocialActivitySettingPersistence socialActivitySettingPersistence;
5091 @BeanReference(type = SocialRelationPersistence.class)
5092 protected SocialRelationPersistence socialRelationPersistence;
5093 @BeanReference(type = SocialRequestPersistence.class)
5094 protected SocialRequestPersistence socialRequestPersistence;
5095 @BeanReference(type = ResourcePersistence.class)
5096 protected ResourcePersistence resourcePersistence;
5097 @BeanReference(type = UserPersistence.class)
5098 protected UserPersistence userPersistence;
5099 private static final String _SQL_SELECT_SOCIALRELATION = "SELECT socialRelation FROM SocialRelation socialRelation";
5100 private static final String _SQL_SELECT_SOCIALRELATION_WHERE = "SELECT socialRelation FROM SocialRelation socialRelation WHERE ";
5101 private static final String _SQL_COUNT_SOCIALRELATION = "SELECT COUNT(socialRelation) FROM SocialRelation socialRelation";
5102 private static final String _SQL_COUNT_SOCIALRELATION_WHERE = "SELECT COUNT(socialRelation) FROM SocialRelation socialRelation WHERE ";
5103 private static final String _FINDER_COLUMN_UUID_UUID_1 = "socialRelation.uuid IS NULL";
5104 private static final String _FINDER_COLUMN_UUID_UUID_2 = "socialRelation.uuid = ?";
5105 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(socialRelation.uuid IS NULL OR socialRelation.uuid = ?)";
5106 private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "socialRelation.companyId = ?";
5107 private static final String _FINDER_COLUMN_USERID1_USERID1_2 = "socialRelation.userId1 = ?";
5108 private static final String _FINDER_COLUMN_USERID2_USERID2_2 = "socialRelation.userId2 = ?";
5109 private static final String _FINDER_COLUMN_TYPE_TYPE_2 = "socialRelation.type = ?";
5110 private static final String _FINDER_COLUMN_C_T_COMPANYID_2 = "socialRelation.companyId = ? AND ";
5111 private static final String _FINDER_COLUMN_C_T_TYPE_2 = "socialRelation.type = ?";
5112 private static final String _FINDER_COLUMN_U1_U2_USERID1_2 = "socialRelation.userId1 = ? AND ";
5113 private static final String _FINDER_COLUMN_U1_U2_USERID2_2 = "socialRelation.userId2 = ?";
5114 private static final String _FINDER_COLUMN_U1_T_USERID1_2 = "socialRelation.userId1 = ? AND ";
5115 private static final String _FINDER_COLUMN_U1_T_TYPE_2 = "socialRelation.type = ?";
5116 private static final String _FINDER_COLUMN_U2_T_USERID2_2 = "socialRelation.userId2 = ? AND ";
5117 private static final String _FINDER_COLUMN_U2_T_TYPE_2 = "socialRelation.type = ?";
5118 private static final String _FINDER_COLUMN_U1_U2_T_USERID1_2 = "socialRelation.userId1 = ? AND ";
5119 private static final String _FINDER_COLUMN_U1_U2_T_USERID2_2 = "socialRelation.userId2 = ? AND ";
5120 private static final String _FINDER_COLUMN_U1_U2_T_TYPE_2 = "socialRelation.type = ?";
5121 private static final String _ORDER_BY_ENTITY_ALIAS = "socialRelation.";
5122 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No SocialRelation exists with the primary key ";
5123 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No SocialRelation exists with the key {";
5124 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
5125 private static Log _log = LogFactoryUtil.getLog(SocialRelationPersistenceImpl.class);
5126 private static SocialRelation _nullSocialRelation = new SocialRelationImpl() {
5127 @Override
5128 public Object clone() {
5129 return this;
5130 }
5131
5132 @Override
5133 public CacheModel<SocialRelation> toCacheModel() {
5134 return _nullSocialRelationCacheModel;
5135 }
5136 };
5137
5138 private static CacheModel<SocialRelation> _nullSocialRelationCacheModel = new CacheModel<SocialRelation>() {
5139 public SocialRelation toEntityModel() {
5140 return _nullSocialRelation;
5141 }
5142 };
5143 }