001
014
015 package com.liferay.portal.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
018 import com.liferay.portal.NoSuchOrgGroupRoleException;
019 import com.liferay.portal.kernel.annotation.BeanReference;
020 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
021 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
023 import com.liferay.portal.kernel.dao.orm.FinderPath;
024 import com.liferay.portal.kernel.dao.orm.Query;
025 import com.liferay.portal.kernel.dao.orm.QueryPos;
026 import com.liferay.portal.kernel.dao.orm.QueryUtil;
027 import com.liferay.portal.kernel.dao.orm.Session;
028 import com.liferay.portal.kernel.exception.SystemException;
029 import com.liferay.portal.kernel.log.Log;
030 import com.liferay.portal.kernel.log.LogFactoryUtil;
031 import com.liferay.portal.kernel.util.GetterUtil;
032 import com.liferay.portal.kernel.util.InstanceFactory;
033 import com.liferay.portal.kernel.util.OrderByComparator;
034 import com.liferay.portal.kernel.util.StringBundler;
035 import com.liferay.portal.kernel.util.StringPool;
036 import com.liferay.portal.kernel.util.StringUtil;
037 import com.liferay.portal.model.ModelListener;
038 import com.liferay.portal.model.OrgGroupRole;
039 import com.liferay.portal.model.impl.OrgGroupRoleImpl;
040 import com.liferay.portal.model.impl.OrgGroupRoleModelImpl;
041 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
042
043 import java.io.Serializable;
044
045 import java.util.ArrayList;
046 import java.util.Collections;
047 import java.util.List;
048
049
055 public class OrgGroupRolePersistenceImpl extends BasePersistenceImpl<OrgGroupRole>
056 implements OrgGroupRolePersistence {
057 public static final String FINDER_CLASS_NAME_ENTITY = OrgGroupRoleImpl.class.getName();
058 public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
059 ".List";
060 public static final FinderPath FINDER_PATH_FIND_BY_GROUPID = new FinderPath(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
061 OrgGroupRoleModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
062 "findByGroupId",
063 new String[] {
064 Long.class.getName(),
065
066 "java.lang.Integer", "java.lang.Integer",
067 "com.liferay.portal.kernel.util.OrderByComparator"
068 });
069 public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
070 OrgGroupRoleModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
071 "countByGroupId", new String[] { Long.class.getName() });
072 public static final FinderPath FINDER_PATH_FIND_BY_ROLEID = new FinderPath(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
073 OrgGroupRoleModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
074 "findByRoleId",
075 new String[] {
076 Long.class.getName(),
077
078 "java.lang.Integer", "java.lang.Integer",
079 "com.liferay.portal.kernel.util.OrderByComparator"
080 });
081 public static final FinderPath FINDER_PATH_COUNT_BY_ROLEID = new FinderPath(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
082 OrgGroupRoleModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
083 "countByRoleId", new String[] { Long.class.getName() });
084 public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
085 OrgGroupRoleModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
086 "findAll", new String[0]);
087 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
088 OrgGroupRoleModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
089 "countAll", new String[0]);
090
091 public void cacheResult(OrgGroupRole orgGroupRole) {
092 EntityCacheUtil.putResult(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
093 OrgGroupRoleImpl.class, orgGroupRole.getPrimaryKey(), orgGroupRole);
094 }
095
096 public void cacheResult(List<OrgGroupRole> orgGroupRoles) {
097 for (OrgGroupRole orgGroupRole : orgGroupRoles) {
098 if (EntityCacheUtil.getResult(
099 OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
100 OrgGroupRoleImpl.class, orgGroupRole.getPrimaryKey(),
101 this) == null) {
102 cacheResult(orgGroupRole);
103 }
104 }
105 }
106
107 public void clearCache() {
108 CacheRegistryUtil.clear(OrgGroupRoleImpl.class.getName());
109 EntityCacheUtil.clearCache(OrgGroupRoleImpl.class.getName());
110 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
111 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
112 }
113
114 public void clearCache(OrgGroupRole orgGroupRole) {
115 EntityCacheUtil.removeResult(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
116 OrgGroupRoleImpl.class, orgGroupRole.getPrimaryKey());
117 }
118
119 public OrgGroupRole create(OrgGroupRolePK orgGroupRolePK) {
120 OrgGroupRole orgGroupRole = new OrgGroupRoleImpl();
121
122 orgGroupRole.setNew(true);
123 orgGroupRole.setPrimaryKey(orgGroupRolePK);
124
125 return orgGroupRole;
126 }
127
128 public OrgGroupRole remove(Serializable primaryKey)
129 throws NoSuchModelException, SystemException {
130 return remove((OrgGroupRolePK)primaryKey);
131 }
132
133 public OrgGroupRole remove(OrgGroupRolePK orgGroupRolePK)
134 throws NoSuchOrgGroupRoleException, SystemException {
135 Session session = null;
136
137 try {
138 session = openSession();
139
140 OrgGroupRole orgGroupRole = (OrgGroupRole)session.get(OrgGroupRoleImpl.class,
141 orgGroupRolePK);
142
143 if (orgGroupRole == null) {
144 if (_log.isWarnEnabled()) {
145 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
146 orgGroupRolePK);
147 }
148
149 throw new NoSuchOrgGroupRoleException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
150 orgGroupRolePK);
151 }
152
153 return remove(orgGroupRole);
154 }
155 catch (NoSuchOrgGroupRoleException nsee) {
156 throw nsee;
157 }
158 catch (Exception e) {
159 throw processException(e);
160 }
161 finally {
162 closeSession(session);
163 }
164 }
165
166 protected OrgGroupRole removeImpl(OrgGroupRole orgGroupRole)
167 throws SystemException {
168 orgGroupRole = toUnwrappedModel(orgGroupRole);
169
170 Session session = null;
171
172 try {
173 session = openSession();
174
175 if (orgGroupRole.isCachedModel() || BatchSessionUtil.isEnabled()) {
176 Object staleObject = session.get(OrgGroupRoleImpl.class,
177 orgGroupRole.getPrimaryKeyObj());
178
179 if (staleObject != null) {
180 session.evict(staleObject);
181 }
182 }
183
184 session.delete(orgGroupRole);
185
186 session.flush();
187 }
188 catch (Exception e) {
189 throw processException(e);
190 }
191 finally {
192 closeSession(session);
193 }
194
195 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
196
197 EntityCacheUtil.removeResult(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
198 OrgGroupRoleImpl.class, orgGroupRole.getPrimaryKey());
199
200 return orgGroupRole;
201 }
202
203 public OrgGroupRole updateImpl(
204 com.liferay.portal.model.OrgGroupRole orgGroupRole, boolean merge)
205 throws SystemException {
206 orgGroupRole = toUnwrappedModel(orgGroupRole);
207
208 Session session = null;
209
210 try {
211 session = openSession();
212
213 BatchSessionUtil.update(session, orgGroupRole, merge);
214
215 orgGroupRole.setNew(false);
216 }
217 catch (Exception e) {
218 throw processException(e);
219 }
220 finally {
221 closeSession(session);
222 }
223
224 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
225
226 EntityCacheUtil.putResult(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
227 OrgGroupRoleImpl.class, orgGroupRole.getPrimaryKey(), orgGroupRole);
228
229 return orgGroupRole;
230 }
231
232 protected OrgGroupRole toUnwrappedModel(OrgGroupRole orgGroupRole) {
233 if (orgGroupRole instanceof OrgGroupRoleImpl) {
234 return orgGroupRole;
235 }
236
237 OrgGroupRoleImpl orgGroupRoleImpl = new OrgGroupRoleImpl();
238
239 orgGroupRoleImpl.setNew(orgGroupRole.isNew());
240 orgGroupRoleImpl.setPrimaryKey(orgGroupRole.getPrimaryKey());
241
242 orgGroupRoleImpl.setOrganizationId(orgGroupRole.getOrganizationId());
243 orgGroupRoleImpl.setGroupId(orgGroupRole.getGroupId());
244 orgGroupRoleImpl.setRoleId(orgGroupRole.getRoleId());
245
246 return orgGroupRoleImpl;
247 }
248
249 public OrgGroupRole findByPrimaryKey(Serializable primaryKey)
250 throws NoSuchModelException, SystemException {
251 return findByPrimaryKey((OrgGroupRolePK)primaryKey);
252 }
253
254 public OrgGroupRole findByPrimaryKey(OrgGroupRolePK orgGroupRolePK)
255 throws NoSuchOrgGroupRoleException, SystemException {
256 OrgGroupRole orgGroupRole = fetchByPrimaryKey(orgGroupRolePK);
257
258 if (orgGroupRole == null) {
259 if (_log.isWarnEnabled()) {
260 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + orgGroupRolePK);
261 }
262
263 throw new NoSuchOrgGroupRoleException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
264 orgGroupRolePK);
265 }
266
267 return orgGroupRole;
268 }
269
270 public OrgGroupRole fetchByPrimaryKey(Serializable primaryKey)
271 throws SystemException {
272 return fetchByPrimaryKey((OrgGroupRolePK)primaryKey);
273 }
274
275 public OrgGroupRole fetchByPrimaryKey(OrgGroupRolePK orgGroupRolePK)
276 throws SystemException {
277 OrgGroupRole orgGroupRole = (OrgGroupRole)EntityCacheUtil.getResult(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
278 OrgGroupRoleImpl.class, orgGroupRolePK, this);
279
280 if (orgGroupRole == null) {
281 Session session = null;
282
283 try {
284 session = openSession();
285
286 orgGroupRole = (OrgGroupRole)session.get(OrgGroupRoleImpl.class,
287 orgGroupRolePK);
288 }
289 catch (Exception e) {
290 throw processException(e);
291 }
292 finally {
293 if (orgGroupRole != null) {
294 cacheResult(orgGroupRole);
295 }
296
297 closeSession(session);
298 }
299 }
300
301 return orgGroupRole;
302 }
303
304 public List<OrgGroupRole> findByGroupId(long groupId)
305 throws SystemException {
306 return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
307 }
308
309 public List<OrgGroupRole> findByGroupId(long groupId, int start, int end)
310 throws SystemException {
311 return findByGroupId(groupId, start, end, null);
312 }
313
314 public List<OrgGroupRole> findByGroupId(long groupId, int start, int end,
315 OrderByComparator orderByComparator) throws SystemException {
316 Object[] finderArgs = new Object[] {
317 groupId,
318
319 String.valueOf(start), String.valueOf(end),
320 String.valueOf(orderByComparator)
321 };
322
323 List<OrgGroupRole> list = (List<OrgGroupRole>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_GROUPID,
324 finderArgs, this);
325
326 if (list == null) {
327 Session session = null;
328
329 try {
330 session = openSession();
331
332 StringBundler query = null;
333
334 if (orderByComparator != null) {
335 query = new StringBundler(3 +
336 (orderByComparator.getOrderByFields().length * 3));
337 }
338 else {
339 query = new StringBundler(2);
340 }
341
342 query.append(_SQL_SELECT_ORGGROUPROLE_WHERE);
343
344 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
345
346 if (orderByComparator != null) {
347 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
348 orderByComparator);
349 }
350
351 String sql = query.toString();
352
353 Query q = session.createQuery(sql);
354
355 QueryPos qPos = QueryPos.getInstance(q);
356
357 qPos.add(groupId);
358
359 list = (List<OrgGroupRole>)QueryUtil.list(q, getDialect(),
360 start, end);
361 }
362 catch (Exception e) {
363 throw processException(e);
364 }
365 finally {
366 if (list == null) {
367 list = new ArrayList<OrgGroupRole>();
368 }
369
370 cacheResult(list);
371
372 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID,
373 finderArgs, list);
374
375 closeSession(session);
376 }
377 }
378
379 return list;
380 }
381
382 public OrgGroupRole findByGroupId_First(long groupId,
383 OrderByComparator orderByComparator)
384 throws NoSuchOrgGroupRoleException, SystemException {
385 List<OrgGroupRole> list = findByGroupId(groupId, 0, 1, orderByComparator);
386
387 if (list.isEmpty()) {
388 StringBundler msg = new StringBundler(4);
389
390 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
391
392 msg.append("groupId=");
393 msg.append(groupId);
394
395 msg.append(StringPool.CLOSE_CURLY_BRACE);
396
397 throw new NoSuchOrgGroupRoleException(msg.toString());
398 }
399 else {
400 return list.get(0);
401 }
402 }
403
404 public OrgGroupRole findByGroupId_Last(long groupId,
405 OrderByComparator orderByComparator)
406 throws NoSuchOrgGroupRoleException, SystemException {
407 int count = countByGroupId(groupId);
408
409 List<OrgGroupRole> list = findByGroupId(groupId, count - 1, count,
410 orderByComparator);
411
412 if (list.isEmpty()) {
413 StringBundler msg = new StringBundler(4);
414
415 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
416
417 msg.append("groupId=");
418 msg.append(groupId);
419
420 msg.append(StringPool.CLOSE_CURLY_BRACE);
421
422 throw new NoSuchOrgGroupRoleException(msg.toString());
423 }
424 else {
425 return list.get(0);
426 }
427 }
428
429 public OrgGroupRole[] findByGroupId_PrevAndNext(
430 OrgGroupRolePK orgGroupRolePK, long groupId,
431 OrderByComparator orderByComparator)
432 throws NoSuchOrgGroupRoleException, SystemException {
433 OrgGroupRole orgGroupRole = findByPrimaryKey(orgGroupRolePK);
434
435 Session session = null;
436
437 try {
438 session = openSession();
439
440 OrgGroupRole[] array = new OrgGroupRoleImpl[3];
441
442 array[0] = getByGroupId_PrevAndNext(session, orgGroupRole, groupId,
443 orderByComparator, true);
444
445 array[1] = orgGroupRole;
446
447 array[2] = getByGroupId_PrevAndNext(session, orgGroupRole, groupId,
448 orderByComparator, false);
449
450 return array;
451 }
452 catch (Exception e) {
453 throw processException(e);
454 }
455 finally {
456 closeSession(session);
457 }
458 }
459
460 protected OrgGroupRole getByGroupId_PrevAndNext(Session session,
461 OrgGroupRole orgGroupRole, long groupId,
462 OrderByComparator orderByComparator, boolean previous) {
463 StringBundler query = null;
464
465 if (orderByComparator != null) {
466 query = new StringBundler(6 +
467 (orderByComparator.getOrderByFields().length * 6));
468 }
469 else {
470 query = new StringBundler(3);
471 }
472
473 query.append(_SQL_SELECT_ORGGROUPROLE_WHERE);
474
475 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
476
477 if (orderByComparator != null) {
478 String[] orderByFields = orderByComparator.getOrderByFields();
479
480 if (orderByFields.length > 0) {
481 query.append(WHERE_AND);
482 }
483
484 for (int i = 0; i < orderByFields.length; i++) {
485 query.append(_ORDER_BY_ENTITY_ALIAS);
486 query.append(orderByFields[i]);
487
488 if ((i + 1) < orderByFields.length) {
489 if (orderByComparator.isAscending() ^ previous) {
490 query.append(WHERE_GREATER_THAN_HAS_NEXT);
491 }
492 else {
493 query.append(WHERE_LESSER_THAN_HAS_NEXT);
494 }
495 }
496 else {
497 if (orderByComparator.isAscending() ^ previous) {
498 query.append(WHERE_GREATER_THAN);
499 }
500 else {
501 query.append(WHERE_LESSER_THAN);
502 }
503 }
504 }
505
506 query.append(ORDER_BY_CLAUSE);
507
508 for (int i = 0; i < orderByFields.length; i++) {
509 query.append(_ORDER_BY_ENTITY_ALIAS);
510 query.append(orderByFields[i]);
511
512 if ((i + 1) < orderByFields.length) {
513 if (orderByComparator.isAscending() ^ previous) {
514 query.append(ORDER_BY_ASC_HAS_NEXT);
515 }
516 else {
517 query.append(ORDER_BY_DESC_HAS_NEXT);
518 }
519 }
520 else {
521 if (orderByComparator.isAscending() ^ previous) {
522 query.append(ORDER_BY_ASC);
523 }
524 else {
525 query.append(ORDER_BY_DESC);
526 }
527 }
528 }
529 }
530
531 String sql = query.toString();
532
533 Query q = session.createQuery(sql);
534
535 q.setFirstResult(0);
536 q.setMaxResults(2);
537
538 QueryPos qPos = QueryPos.getInstance(q);
539
540 qPos.add(groupId);
541
542 if (orderByComparator != null) {
543 Object[] values = orderByComparator.getOrderByValues(orgGroupRole);
544
545 for (Object value : values) {
546 qPos.add(value);
547 }
548 }
549
550 List<OrgGroupRole> list = q.list();
551
552 if (list.size() == 2) {
553 return list.get(1);
554 }
555 else {
556 return null;
557 }
558 }
559
560 public List<OrgGroupRole> findByRoleId(long roleId)
561 throws SystemException {
562 return findByRoleId(roleId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
563 }
564
565 public List<OrgGroupRole> findByRoleId(long roleId, int start, int end)
566 throws SystemException {
567 return findByRoleId(roleId, start, end, null);
568 }
569
570 public List<OrgGroupRole> findByRoleId(long roleId, int start, int end,
571 OrderByComparator orderByComparator) throws SystemException {
572 Object[] finderArgs = new Object[] {
573 roleId,
574
575 String.valueOf(start), String.valueOf(end),
576 String.valueOf(orderByComparator)
577 };
578
579 List<OrgGroupRole> list = (List<OrgGroupRole>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_ROLEID,
580 finderArgs, this);
581
582 if (list == null) {
583 Session session = null;
584
585 try {
586 session = openSession();
587
588 StringBundler query = null;
589
590 if (orderByComparator != null) {
591 query = new StringBundler(3 +
592 (orderByComparator.getOrderByFields().length * 3));
593 }
594 else {
595 query = new StringBundler(2);
596 }
597
598 query.append(_SQL_SELECT_ORGGROUPROLE_WHERE);
599
600 query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
601
602 if (orderByComparator != null) {
603 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
604 orderByComparator);
605 }
606
607 String sql = query.toString();
608
609 Query q = session.createQuery(sql);
610
611 QueryPos qPos = QueryPos.getInstance(q);
612
613 qPos.add(roleId);
614
615 list = (List<OrgGroupRole>)QueryUtil.list(q, getDialect(),
616 start, end);
617 }
618 catch (Exception e) {
619 throw processException(e);
620 }
621 finally {
622 if (list == null) {
623 list = new ArrayList<OrgGroupRole>();
624 }
625
626 cacheResult(list);
627
628 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_ROLEID,
629 finderArgs, list);
630
631 closeSession(session);
632 }
633 }
634
635 return list;
636 }
637
638 public OrgGroupRole findByRoleId_First(long roleId,
639 OrderByComparator orderByComparator)
640 throws NoSuchOrgGroupRoleException, SystemException {
641 List<OrgGroupRole> list = findByRoleId(roleId, 0, 1, orderByComparator);
642
643 if (list.isEmpty()) {
644 StringBundler msg = new StringBundler(4);
645
646 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
647
648 msg.append("roleId=");
649 msg.append(roleId);
650
651 msg.append(StringPool.CLOSE_CURLY_BRACE);
652
653 throw new NoSuchOrgGroupRoleException(msg.toString());
654 }
655 else {
656 return list.get(0);
657 }
658 }
659
660 public OrgGroupRole findByRoleId_Last(long roleId,
661 OrderByComparator orderByComparator)
662 throws NoSuchOrgGroupRoleException, SystemException {
663 int count = countByRoleId(roleId);
664
665 List<OrgGroupRole> list = findByRoleId(roleId, count - 1, count,
666 orderByComparator);
667
668 if (list.isEmpty()) {
669 StringBundler msg = new StringBundler(4);
670
671 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
672
673 msg.append("roleId=");
674 msg.append(roleId);
675
676 msg.append(StringPool.CLOSE_CURLY_BRACE);
677
678 throw new NoSuchOrgGroupRoleException(msg.toString());
679 }
680 else {
681 return list.get(0);
682 }
683 }
684
685 public OrgGroupRole[] findByRoleId_PrevAndNext(
686 OrgGroupRolePK orgGroupRolePK, long roleId,
687 OrderByComparator orderByComparator)
688 throws NoSuchOrgGroupRoleException, SystemException {
689 OrgGroupRole orgGroupRole = findByPrimaryKey(orgGroupRolePK);
690
691 Session session = null;
692
693 try {
694 session = openSession();
695
696 OrgGroupRole[] array = new OrgGroupRoleImpl[3];
697
698 array[0] = getByRoleId_PrevAndNext(session, orgGroupRole, roleId,
699 orderByComparator, true);
700
701 array[1] = orgGroupRole;
702
703 array[2] = getByRoleId_PrevAndNext(session, orgGroupRole, roleId,
704 orderByComparator, false);
705
706 return array;
707 }
708 catch (Exception e) {
709 throw processException(e);
710 }
711 finally {
712 closeSession(session);
713 }
714 }
715
716 protected OrgGroupRole getByRoleId_PrevAndNext(Session session,
717 OrgGroupRole orgGroupRole, long roleId,
718 OrderByComparator orderByComparator, boolean previous) {
719 StringBundler query = null;
720
721 if (orderByComparator != null) {
722 query = new StringBundler(6 +
723 (orderByComparator.getOrderByFields().length * 6));
724 }
725 else {
726 query = new StringBundler(3);
727 }
728
729 query.append(_SQL_SELECT_ORGGROUPROLE_WHERE);
730
731 query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
732
733 if (orderByComparator != null) {
734 String[] orderByFields = orderByComparator.getOrderByFields();
735
736 if (orderByFields.length > 0) {
737 query.append(WHERE_AND);
738 }
739
740 for (int i = 0; i < orderByFields.length; i++) {
741 query.append(_ORDER_BY_ENTITY_ALIAS);
742 query.append(orderByFields[i]);
743
744 if ((i + 1) < orderByFields.length) {
745 if (orderByComparator.isAscending() ^ previous) {
746 query.append(WHERE_GREATER_THAN_HAS_NEXT);
747 }
748 else {
749 query.append(WHERE_LESSER_THAN_HAS_NEXT);
750 }
751 }
752 else {
753 if (orderByComparator.isAscending() ^ previous) {
754 query.append(WHERE_GREATER_THAN);
755 }
756 else {
757 query.append(WHERE_LESSER_THAN);
758 }
759 }
760 }
761
762 query.append(ORDER_BY_CLAUSE);
763
764 for (int i = 0; i < orderByFields.length; i++) {
765 query.append(_ORDER_BY_ENTITY_ALIAS);
766 query.append(orderByFields[i]);
767
768 if ((i + 1) < orderByFields.length) {
769 if (orderByComparator.isAscending() ^ previous) {
770 query.append(ORDER_BY_ASC_HAS_NEXT);
771 }
772 else {
773 query.append(ORDER_BY_DESC_HAS_NEXT);
774 }
775 }
776 else {
777 if (orderByComparator.isAscending() ^ previous) {
778 query.append(ORDER_BY_ASC);
779 }
780 else {
781 query.append(ORDER_BY_DESC);
782 }
783 }
784 }
785 }
786
787 String sql = query.toString();
788
789 Query q = session.createQuery(sql);
790
791 q.setFirstResult(0);
792 q.setMaxResults(2);
793
794 QueryPos qPos = QueryPos.getInstance(q);
795
796 qPos.add(roleId);
797
798 if (orderByComparator != null) {
799 Object[] values = orderByComparator.getOrderByValues(orgGroupRole);
800
801 for (Object value : values) {
802 qPos.add(value);
803 }
804 }
805
806 List<OrgGroupRole> list = q.list();
807
808 if (list.size() == 2) {
809 return list.get(1);
810 }
811 else {
812 return null;
813 }
814 }
815
816 public List<OrgGroupRole> findAll() throws SystemException {
817 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
818 }
819
820 public List<OrgGroupRole> findAll(int start, int end)
821 throws SystemException {
822 return findAll(start, end, null);
823 }
824
825 public List<OrgGroupRole> findAll(int start, int end,
826 OrderByComparator orderByComparator) throws SystemException {
827 Object[] finderArgs = new Object[] {
828 String.valueOf(start), String.valueOf(end),
829 String.valueOf(orderByComparator)
830 };
831
832 List<OrgGroupRole> list = (List<OrgGroupRole>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
833 finderArgs, this);
834
835 if (list == null) {
836 Session session = null;
837
838 try {
839 session = openSession();
840
841 StringBundler query = null;
842 String sql = null;
843
844 if (orderByComparator != null) {
845 query = new StringBundler(2 +
846 (orderByComparator.getOrderByFields().length * 3));
847
848 query.append(_SQL_SELECT_ORGGROUPROLE);
849
850 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
851 orderByComparator);
852
853 sql = query.toString();
854 }
855 else {
856 sql = _SQL_SELECT_ORGGROUPROLE;
857 }
858
859 Query q = session.createQuery(sql);
860
861 if (orderByComparator == null) {
862 list = (List<OrgGroupRole>)QueryUtil.list(q, getDialect(),
863 start, end, false);
864
865 Collections.sort(list);
866 }
867 else {
868 list = (List<OrgGroupRole>)QueryUtil.list(q, getDialect(),
869 start, end);
870 }
871 }
872 catch (Exception e) {
873 throw processException(e);
874 }
875 finally {
876 if (list == null) {
877 list = new ArrayList<OrgGroupRole>();
878 }
879
880 cacheResult(list);
881
882 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
883
884 closeSession(session);
885 }
886 }
887
888 return list;
889 }
890
891 public void removeByGroupId(long groupId) throws SystemException {
892 for (OrgGroupRole orgGroupRole : findByGroupId(groupId)) {
893 remove(orgGroupRole);
894 }
895 }
896
897 public void removeByRoleId(long roleId) throws SystemException {
898 for (OrgGroupRole orgGroupRole : findByRoleId(roleId)) {
899 remove(orgGroupRole);
900 }
901 }
902
903 public void removeAll() throws SystemException {
904 for (OrgGroupRole orgGroupRole : findAll()) {
905 remove(orgGroupRole);
906 }
907 }
908
909 public int countByGroupId(long groupId) throws SystemException {
910 Object[] finderArgs = new Object[] { groupId };
911
912 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
913 finderArgs, this);
914
915 if (count == null) {
916 Session session = null;
917
918 try {
919 session = openSession();
920
921 StringBundler query = new StringBundler(2);
922
923 query.append(_SQL_COUNT_ORGGROUPROLE_WHERE);
924
925 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
926
927 String sql = query.toString();
928
929 Query q = session.createQuery(sql);
930
931 QueryPos qPos = QueryPos.getInstance(q);
932
933 qPos.add(groupId);
934
935 count = (Long)q.uniqueResult();
936 }
937 catch (Exception e) {
938 throw processException(e);
939 }
940 finally {
941 if (count == null) {
942 count = Long.valueOf(0);
943 }
944
945 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
946 finderArgs, count);
947
948 closeSession(session);
949 }
950 }
951
952 return count.intValue();
953 }
954
955 public int countByRoleId(long roleId) throws SystemException {
956 Object[] finderArgs = new Object[] { roleId };
957
958 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_ROLEID,
959 finderArgs, this);
960
961 if (count == null) {
962 Session session = null;
963
964 try {
965 session = openSession();
966
967 StringBundler query = new StringBundler(2);
968
969 query.append(_SQL_COUNT_ORGGROUPROLE_WHERE);
970
971 query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
972
973 String sql = query.toString();
974
975 Query q = session.createQuery(sql);
976
977 QueryPos qPos = QueryPos.getInstance(q);
978
979 qPos.add(roleId);
980
981 count = (Long)q.uniqueResult();
982 }
983 catch (Exception e) {
984 throw processException(e);
985 }
986 finally {
987 if (count == null) {
988 count = Long.valueOf(0);
989 }
990
991 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_ROLEID,
992 finderArgs, count);
993
994 closeSession(session);
995 }
996 }
997
998 return count.intValue();
999 }
1000
1001 public int countAll() throws SystemException {
1002 Object[] finderArgs = new Object[0];
1003
1004 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1005 finderArgs, this);
1006
1007 if (count == null) {
1008 Session session = null;
1009
1010 try {
1011 session = openSession();
1012
1013 Query q = session.createQuery(_SQL_COUNT_ORGGROUPROLE);
1014
1015 count = (Long)q.uniqueResult();
1016 }
1017 catch (Exception e) {
1018 throw processException(e);
1019 }
1020 finally {
1021 if (count == null) {
1022 count = Long.valueOf(0);
1023 }
1024
1025 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1026 count);
1027
1028 closeSession(session);
1029 }
1030 }
1031
1032 return count.intValue();
1033 }
1034
1035 public void afterPropertiesSet() {
1036 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1037 com.liferay.portal.util.PropsUtil.get(
1038 "value.object.listener.com.liferay.portal.model.OrgGroupRole")));
1039
1040 if (listenerClassNames.length > 0) {
1041 try {
1042 List<ModelListener<OrgGroupRole>> listenersList = new ArrayList<ModelListener<OrgGroupRole>>();
1043
1044 for (String listenerClassName : listenerClassNames) {
1045 listenersList.add((ModelListener<OrgGroupRole>)InstanceFactory.newInstance(
1046 listenerClassName));
1047 }
1048
1049 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1050 }
1051 catch (Exception e) {
1052 _log.error(e);
1053 }
1054 }
1055 }
1056
1057 @BeanReference(type = AccountPersistence.class)
1058 protected AccountPersistence accountPersistence;
1059 @BeanReference(type = AddressPersistence.class)
1060 protected AddressPersistence addressPersistence;
1061 @BeanReference(type = BrowserTrackerPersistence.class)
1062 protected BrowserTrackerPersistence browserTrackerPersistence;
1063 @BeanReference(type = ClassNamePersistence.class)
1064 protected ClassNamePersistence classNamePersistence;
1065 @BeanReference(type = CompanyPersistence.class)
1066 protected CompanyPersistence companyPersistence;
1067 @BeanReference(type = ContactPersistence.class)
1068 protected ContactPersistence contactPersistence;
1069 @BeanReference(type = CountryPersistence.class)
1070 protected CountryPersistence countryPersistence;
1071 @BeanReference(type = EmailAddressPersistence.class)
1072 protected EmailAddressPersistence emailAddressPersistence;
1073 @BeanReference(type = GroupPersistence.class)
1074 protected GroupPersistence groupPersistence;
1075 @BeanReference(type = ImagePersistence.class)
1076 protected ImagePersistence imagePersistence;
1077 @BeanReference(type = LayoutPersistence.class)
1078 protected LayoutPersistence layoutPersistence;
1079 @BeanReference(type = LayoutPrototypePersistence.class)
1080 protected LayoutPrototypePersistence layoutPrototypePersistence;
1081 @BeanReference(type = LayoutSetPersistence.class)
1082 protected LayoutSetPersistence layoutSetPersistence;
1083 @BeanReference(type = LayoutSetPrototypePersistence.class)
1084 protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
1085 @BeanReference(type = ListTypePersistence.class)
1086 protected ListTypePersistence listTypePersistence;
1087 @BeanReference(type = LockPersistence.class)
1088 protected LockPersistence lockPersistence;
1089 @BeanReference(type = MembershipRequestPersistence.class)
1090 protected MembershipRequestPersistence membershipRequestPersistence;
1091 @BeanReference(type = OrganizationPersistence.class)
1092 protected OrganizationPersistence organizationPersistence;
1093 @BeanReference(type = OrgGroupPermissionPersistence.class)
1094 protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1095 @BeanReference(type = OrgGroupRolePersistence.class)
1096 protected OrgGroupRolePersistence orgGroupRolePersistence;
1097 @BeanReference(type = OrgLaborPersistence.class)
1098 protected OrgLaborPersistence orgLaborPersistence;
1099 @BeanReference(type = PasswordPolicyPersistence.class)
1100 protected PasswordPolicyPersistence passwordPolicyPersistence;
1101 @BeanReference(type = PasswordPolicyRelPersistence.class)
1102 protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1103 @BeanReference(type = PasswordTrackerPersistence.class)
1104 protected PasswordTrackerPersistence passwordTrackerPersistence;
1105 @BeanReference(type = PermissionPersistence.class)
1106 protected PermissionPersistence permissionPersistence;
1107 @BeanReference(type = PhonePersistence.class)
1108 protected PhonePersistence phonePersistence;
1109 @BeanReference(type = PluginSettingPersistence.class)
1110 protected PluginSettingPersistence pluginSettingPersistence;
1111 @BeanReference(type = PortletPersistence.class)
1112 protected PortletPersistence portletPersistence;
1113 @BeanReference(type = PortletItemPersistence.class)
1114 protected PortletItemPersistence portletItemPersistence;
1115 @BeanReference(type = PortletPreferencesPersistence.class)
1116 protected PortletPreferencesPersistence portletPreferencesPersistence;
1117 @BeanReference(type = RegionPersistence.class)
1118 protected RegionPersistence regionPersistence;
1119 @BeanReference(type = ReleasePersistence.class)
1120 protected ReleasePersistence releasePersistence;
1121 @BeanReference(type = ResourcePersistence.class)
1122 protected ResourcePersistence resourcePersistence;
1123 @BeanReference(type = ResourceActionPersistence.class)
1124 protected ResourceActionPersistence resourceActionPersistence;
1125 @BeanReference(type = ResourceCodePersistence.class)
1126 protected ResourceCodePersistence resourceCodePersistence;
1127 @BeanReference(type = ResourcePermissionPersistence.class)
1128 protected ResourcePermissionPersistence resourcePermissionPersistence;
1129 @BeanReference(type = RolePersistence.class)
1130 protected RolePersistence rolePersistence;
1131 @BeanReference(type = ServiceComponentPersistence.class)
1132 protected ServiceComponentPersistence serviceComponentPersistence;
1133 @BeanReference(type = ShardPersistence.class)
1134 protected ShardPersistence shardPersistence;
1135 @BeanReference(type = SubscriptionPersistence.class)
1136 protected SubscriptionPersistence subscriptionPersistence;
1137 @BeanReference(type = TicketPersistence.class)
1138 protected TicketPersistence ticketPersistence;
1139 @BeanReference(type = TeamPersistence.class)
1140 protected TeamPersistence teamPersistence;
1141 @BeanReference(type = UserPersistence.class)
1142 protected UserPersistence userPersistence;
1143 @BeanReference(type = UserGroupPersistence.class)
1144 protected UserGroupPersistence userGroupPersistence;
1145 @BeanReference(type = UserGroupGroupRolePersistence.class)
1146 protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
1147 @BeanReference(type = UserGroupRolePersistence.class)
1148 protected UserGroupRolePersistence userGroupRolePersistence;
1149 @BeanReference(type = UserIdMapperPersistence.class)
1150 protected UserIdMapperPersistence userIdMapperPersistence;
1151 @BeanReference(type = UserTrackerPersistence.class)
1152 protected UserTrackerPersistence userTrackerPersistence;
1153 @BeanReference(type = UserTrackerPathPersistence.class)
1154 protected UserTrackerPathPersistence userTrackerPathPersistence;
1155 @BeanReference(type = WebDAVPropsPersistence.class)
1156 protected WebDAVPropsPersistence webDAVPropsPersistence;
1157 @BeanReference(type = WebsitePersistence.class)
1158 protected WebsitePersistence websitePersistence;
1159 @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
1160 protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
1161 @BeanReference(type = WorkflowInstanceLinkPersistence.class)
1162 protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
1163 private static final String _SQL_SELECT_ORGGROUPROLE = "SELECT orgGroupRole FROM OrgGroupRole orgGroupRole";
1164 private static final String _SQL_SELECT_ORGGROUPROLE_WHERE = "SELECT orgGroupRole FROM OrgGroupRole orgGroupRole WHERE ";
1165 private static final String _SQL_COUNT_ORGGROUPROLE = "SELECT COUNT(orgGroupRole) FROM OrgGroupRole orgGroupRole";
1166 private static final String _SQL_COUNT_ORGGROUPROLE_WHERE = "SELECT COUNT(orgGroupRole) FROM OrgGroupRole orgGroupRole WHERE ";
1167 private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "orgGroupRole.id.groupId = ?";
1168 private static final String _FINDER_COLUMN_ROLEID_ROLEID_2 = "orgGroupRole.id.roleId = ?";
1169 private static final String _ORDER_BY_ENTITY_ALIAS = "orgGroupRole.";
1170 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No OrgGroupRole exists with the primary key ";
1171 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No OrgGroupRole exists with the key {";
1172 private static Log _log = LogFactoryUtil.getLog(OrgGroupRolePersistenceImpl.class);
1173 }