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