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