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
065 public class OrgGroupRolePersistenceImpl extends BasePersistenceImpl<OrgGroupRole>
066 implements OrgGroupRolePersistence {
067 public static final String FINDER_CLASS_NAME_ENTITY = OrgGroupRoleImpl.class.getName();
068 public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
069 ".List";
070 public static final FinderPath FINDER_PATH_FIND_BY_GROUPID = new FinderPath(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
071 OrgGroupRoleModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
072 "findByGroupId",
073 new String[] {
074 Long.class.getName(),
075
076 "java.lang.Integer", "java.lang.Integer",
077 "com.liferay.portal.kernel.util.OrderByComparator"
078 });
079 public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
080 OrgGroupRoleModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
081 "countByGroupId", new String[] { Long.class.getName() });
082 public static final FinderPath FINDER_PATH_FIND_BY_ROLEID = new FinderPath(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
083 OrgGroupRoleModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
084 "findByRoleId",
085 new String[] {
086 Long.class.getName(),
087
088 "java.lang.Integer", "java.lang.Integer",
089 "com.liferay.portal.kernel.util.OrderByComparator"
090 });
091 public static final FinderPath FINDER_PATH_COUNT_BY_ROLEID = new FinderPath(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
092 OrgGroupRoleModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
093 "countByRoleId", new String[] { Long.class.getName() });
094 public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
095 OrgGroupRoleModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
096 "findAll", new String[0]);
097 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
098 OrgGroupRoleModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
099 "countAll", new String[0]);
100
101
106 public void cacheResult(OrgGroupRole orgGroupRole) {
107 EntityCacheUtil.putResult(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
108 OrgGroupRoleImpl.class, orgGroupRole.getPrimaryKey(), orgGroupRole);
109 }
110
111
116 public void cacheResult(List<OrgGroupRole> orgGroupRoles) {
117 for (OrgGroupRole orgGroupRole : orgGroupRoles) {
118 if (EntityCacheUtil.getResult(
119 OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
120 OrgGroupRoleImpl.class, orgGroupRole.getPrimaryKey(),
121 this) == null) {
122 cacheResult(orgGroupRole);
123 }
124 }
125 }
126
127
134 public void clearCache() {
135 CacheRegistryUtil.clear(OrgGroupRoleImpl.class.getName());
136 EntityCacheUtil.clearCache(OrgGroupRoleImpl.class.getName());
137 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
138 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
139 }
140
141
148 public void clearCache(OrgGroupRole orgGroupRole) {
149 EntityCacheUtil.removeResult(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
150 OrgGroupRoleImpl.class, orgGroupRole.getPrimaryKey());
151 }
152
153
159 public OrgGroupRole create(OrgGroupRolePK orgGroupRolePK) {
160 OrgGroupRole orgGroupRole = new OrgGroupRoleImpl();
161
162 orgGroupRole.setNew(true);
163 orgGroupRole.setPrimaryKey(orgGroupRolePK);
164
165 return orgGroupRole;
166 }
167
168
176 public OrgGroupRole remove(Serializable primaryKey)
177 throws NoSuchModelException, SystemException {
178 return remove((OrgGroupRolePK)primaryKey);
179 }
180
181
189 public OrgGroupRole remove(OrgGroupRolePK orgGroupRolePK)
190 throws NoSuchOrgGroupRoleException, SystemException {
191 Session session = null;
192
193 try {
194 session = openSession();
195
196 OrgGroupRole orgGroupRole = (OrgGroupRole)session.get(OrgGroupRoleImpl.class,
197 orgGroupRolePK);
198
199 if (orgGroupRole == null) {
200 if (_log.isWarnEnabled()) {
201 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
202 orgGroupRolePK);
203 }
204
205 throw new NoSuchOrgGroupRoleException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
206 orgGroupRolePK);
207 }
208
209 return remove(orgGroupRole);
210 }
211 catch (NoSuchOrgGroupRoleException nsee) {
212 throw nsee;
213 }
214 catch (Exception e) {
215 throw processException(e);
216 }
217 finally {
218 closeSession(session);
219 }
220 }
221
222 protected OrgGroupRole removeImpl(OrgGroupRole orgGroupRole)
223 throws SystemException {
224 orgGroupRole = toUnwrappedModel(orgGroupRole);
225
226 Session session = null;
227
228 try {
229 session = openSession();
230
231 BatchSessionUtil.delete(session, orgGroupRole);
232 }
233 catch (Exception e) {
234 throw processException(e);
235 }
236 finally {
237 closeSession(session);
238 }
239
240 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
241
242 EntityCacheUtil.removeResult(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
243 OrgGroupRoleImpl.class, orgGroupRole.getPrimaryKey());
244
245 return orgGroupRole;
246 }
247
248 public OrgGroupRole updateImpl(
249 com.liferay.portal.model.OrgGroupRole orgGroupRole, boolean merge)
250 throws SystemException {
251 orgGroupRole = toUnwrappedModel(orgGroupRole);
252
253 Session session = null;
254
255 try {
256 session = openSession();
257
258 BatchSessionUtil.update(session, orgGroupRole, merge);
259
260 orgGroupRole.setNew(false);
261 }
262 catch (Exception e) {
263 throw processException(e);
264 }
265 finally {
266 closeSession(session);
267 }
268
269 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
270
271 EntityCacheUtil.putResult(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
272 OrgGroupRoleImpl.class, orgGroupRole.getPrimaryKey(), orgGroupRole);
273
274 return orgGroupRole;
275 }
276
277 protected OrgGroupRole toUnwrappedModel(OrgGroupRole orgGroupRole) {
278 if (orgGroupRole instanceof OrgGroupRoleImpl) {
279 return orgGroupRole;
280 }
281
282 OrgGroupRoleImpl orgGroupRoleImpl = new OrgGroupRoleImpl();
283
284 orgGroupRoleImpl.setNew(orgGroupRole.isNew());
285 orgGroupRoleImpl.setPrimaryKey(orgGroupRole.getPrimaryKey());
286
287 orgGroupRoleImpl.setOrganizationId(orgGroupRole.getOrganizationId());
288 orgGroupRoleImpl.setGroupId(orgGroupRole.getGroupId());
289 orgGroupRoleImpl.setRoleId(orgGroupRole.getRoleId());
290
291 return orgGroupRoleImpl;
292 }
293
294
302 public OrgGroupRole findByPrimaryKey(Serializable primaryKey)
303 throws NoSuchModelException, SystemException {
304 return findByPrimaryKey((OrgGroupRolePK)primaryKey);
305 }
306
307
315 public OrgGroupRole findByPrimaryKey(OrgGroupRolePK orgGroupRolePK)
316 throws NoSuchOrgGroupRoleException, SystemException {
317 OrgGroupRole orgGroupRole = fetchByPrimaryKey(orgGroupRolePK);
318
319 if (orgGroupRole == null) {
320 if (_log.isWarnEnabled()) {
321 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + orgGroupRolePK);
322 }
323
324 throw new NoSuchOrgGroupRoleException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
325 orgGroupRolePK);
326 }
327
328 return orgGroupRole;
329 }
330
331
338 public OrgGroupRole fetchByPrimaryKey(Serializable primaryKey)
339 throws SystemException {
340 return fetchByPrimaryKey((OrgGroupRolePK)primaryKey);
341 }
342
343
350 public OrgGroupRole fetchByPrimaryKey(OrgGroupRolePK orgGroupRolePK)
351 throws SystemException {
352 OrgGroupRole orgGroupRole = (OrgGroupRole)EntityCacheUtil.getResult(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
353 OrgGroupRoleImpl.class, orgGroupRolePK, this);
354
355 if (orgGroupRole == null) {
356 Session session = null;
357
358 try {
359 session = openSession();
360
361 orgGroupRole = (OrgGroupRole)session.get(OrgGroupRoleImpl.class,
362 orgGroupRolePK);
363 }
364 catch (Exception e) {
365 throw processException(e);
366 }
367 finally {
368 if (orgGroupRole != null) {
369 cacheResult(orgGroupRole);
370 }
371
372 closeSession(session);
373 }
374 }
375
376 return orgGroupRole;
377 }
378
379
386 public List<OrgGroupRole> findByGroupId(long groupId)
387 throws SystemException {
388 return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
389 }
390
391
404 public List<OrgGroupRole> findByGroupId(long groupId, int start, int end)
405 throws SystemException {
406 return findByGroupId(groupId, start, end, null);
407 }
408
409
423 public List<OrgGroupRole> findByGroupId(long groupId, int start, int end,
424 OrderByComparator orderByComparator) throws SystemException {
425 Object[] finderArgs = new Object[] {
426 groupId,
427
428 String.valueOf(start), String.valueOf(end),
429 String.valueOf(orderByComparator)
430 };
431
432 List<OrgGroupRole> list = (List<OrgGroupRole>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_GROUPID,
433 finderArgs, this);
434
435 if (list == null) {
436 Session session = null;
437
438 try {
439 session = openSession();
440
441 StringBundler query = null;
442
443 if (orderByComparator != null) {
444 query = new StringBundler(3 +
445 (orderByComparator.getOrderByFields().length * 3));
446 }
447 else {
448 query = new StringBundler(2);
449 }
450
451 query.append(_SQL_SELECT_ORGGROUPROLE_WHERE);
452
453 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
454
455 if (orderByComparator != null) {
456 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
457 orderByComparator);
458 }
459
460 String sql = query.toString();
461
462 Query q = session.createQuery(sql);
463
464 QueryPos qPos = QueryPos.getInstance(q);
465
466 qPos.add(groupId);
467
468 list = (List<OrgGroupRole>)QueryUtil.list(q, getDialect(),
469 start, end);
470 }
471 catch (Exception e) {
472 throw processException(e);
473 }
474 finally {
475 if (list == null) {
476 list = new ArrayList<OrgGroupRole>();
477 }
478
479 cacheResult(list);
480
481 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID,
482 finderArgs, list);
483
484 closeSession(session);
485 }
486 }
487
488 return list;
489 }
490
491
504 public OrgGroupRole findByGroupId_First(long groupId,
505 OrderByComparator orderByComparator)
506 throws NoSuchOrgGroupRoleException, SystemException {
507 List<OrgGroupRole> list = findByGroupId(groupId, 0, 1, orderByComparator);
508
509 if (list.isEmpty()) {
510 StringBundler msg = new StringBundler(4);
511
512 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
513
514 msg.append("groupId=");
515 msg.append(groupId);
516
517 msg.append(StringPool.CLOSE_CURLY_BRACE);
518
519 throw new NoSuchOrgGroupRoleException(msg.toString());
520 }
521 else {
522 return list.get(0);
523 }
524 }
525
526
539 public OrgGroupRole findByGroupId_Last(long groupId,
540 OrderByComparator orderByComparator)
541 throws NoSuchOrgGroupRoleException, SystemException {
542 int count = countByGroupId(groupId);
543
544 List<OrgGroupRole> list = findByGroupId(groupId, count - 1, count,
545 orderByComparator);
546
547 if (list.isEmpty()) {
548 StringBundler msg = new StringBundler(4);
549
550 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
551
552 msg.append("groupId=");
553 msg.append(groupId);
554
555 msg.append(StringPool.CLOSE_CURLY_BRACE);
556
557 throw new NoSuchOrgGroupRoleException(msg.toString());
558 }
559 else {
560 return list.get(0);
561 }
562 }
563
564
578 public OrgGroupRole[] findByGroupId_PrevAndNext(
579 OrgGroupRolePK orgGroupRolePK, long groupId,
580 OrderByComparator orderByComparator)
581 throws NoSuchOrgGroupRoleException, SystemException {
582 OrgGroupRole orgGroupRole = findByPrimaryKey(orgGroupRolePK);
583
584 Session session = null;
585
586 try {
587 session = openSession();
588
589 OrgGroupRole[] array = new OrgGroupRoleImpl[3];
590
591 array[0] = getByGroupId_PrevAndNext(session, orgGroupRole, groupId,
592 orderByComparator, true);
593
594 array[1] = orgGroupRole;
595
596 array[2] = getByGroupId_PrevAndNext(session, orgGroupRole, groupId,
597 orderByComparator, false);
598
599 return array;
600 }
601 catch (Exception e) {
602 throw processException(e);
603 }
604 finally {
605 closeSession(session);
606 }
607 }
608
609 protected OrgGroupRole getByGroupId_PrevAndNext(Session session,
610 OrgGroupRole orgGroupRole, long groupId,
611 OrderByComparator orderByComparator, boolean previous) {
612 StringBundler query = null;
613
614 if (orderByComparator != null) {
615 query = new StringBundler(6 +
616 (orderByComparator.getOrderByFields().length * 6));
617 }
618 else {
619 query = new StringBundler(3);
620 }
621
622 query.append(_SQL_SELECT_ORGGROUPROLE_WHERE);
623
624 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
625
626 if (orderByComparator != null) {
627 String[] orderByFields = orderByComparator.getOrderByFields();
628
629 if (orderByFields.length > 0) {
630 query.append(WHERE_AND);
631 }
632
633 for (int i = 0; i < orderByFields.length; i++) {
634 query.append(_ORDER_BY_ENTITY_ALIAS);
635 query.append(orderByFields[i]);
636
637 if ((i + 1) < orderByFields.length) {
638 if (orderByComparator.isAscending() ^ previous) {
639 query.append(WHERE_GREATER_THAN_HAS_NEXT);
640 }
641 else {
642 query.append(WHERE_LESSER_THAN_HAS_NEXT);
643 }
644 }
645 else {
646 if (orderByComparator.isAscending() ^ previous) {
647 query.append(WHERE_GREATER_THAN);
648 }
649 else {
650 query.append(WHERE_LESSER_THAN);
651 }
652 }
653 }
654
655 query.append(ORDER_BY_CLAUSE);
656
657 for (int i = 0; i < orderByFields.length; i++) {
658 query.append(_ORDER_BY_ENTITY_ALIAS);
659 query.append(orderByFields[i]);
660
661 if ((i + 1) < orderByFields.length) {
662 if (orderByComparator.isAscending() ^ previous) {
663 query.append(ORDER_BY_ASC_HAS_NEXT);
664 }
665 else {
666 query.append(ORDER_BY_DESC_HAS_NEXT);
667 }
668 }
669 else {
670 if (orderByComparator.isAscending() ^ previous) {
671 query.append(ORDER_BY_ASC);
672 }
673 else {
674 query.append(ORDER_BY_DESC);
675 }
676 }
677 }
678 }
679
680 String sql = query.toString();
681
682 Query q = session.createQuery(sql);
683
684 q.setFirstResult(0);
685 q.setMaxResults(2);
686
687 QueryPos qPos = QueryPos.getInstance(q);
688
689 qPos.add(groupId);
690
691 if (orderByComparator != null) {
692 Object[] values = orderByComparator.getOrderByValues(orgGroupRole);
693
694 for (Object value : values) {
695 qPos.add(value);
696 }
697 }
698
699 List<OrgGroupRole> list = q.list();
700
701 if (list.size() == 2) {
702 return list.get(1);
703 }
704 else {
705 return null;
706 }
707 }
708
709
716 public List<OrgGroupRole> findByRoleId(long roleId)
717 throws SystemException {
718 return findByRoleId(roleId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
719 }
720
721
734 public List<OrgGroupRole> findByRoleId(long roleId, int start, int end)
735 throws SystemException {
736 return findByRoleId(roleId, start, end, null);
737 }
738
739
753 public List<OrgGroupRole> findByRoleId(long roleId, int start, int end,
754 OrderByComparator orderByComparator) throws SystemException {
755 Object[] finderArgs = new Object[] {
756 roleId,
757
758 String.valueOf(start), String.valueOf(end),
759 String.valueOf(orderByComparator)
760 };
761
762 List<OrgGroupRole> list = (List<OrgGroupRole>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_ROLEID,
763 finderArgs, this);
764
765 if (list == null) {
766 Session session = null;
767
768 try {
769 session = openSession();
770
771 StringBundler query = null;
772
773 if (orderByComparator != null) {
774 query = new StringBundler(3 +
775 (orderByComparator.getOrderByFields().length * 3));
776 }
777 else {
778 query = new StringBundler(2);
779 }
780
781 query.append(_SQL_SELECT_ORGGROUPROLE_WHERE);
782
783 query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
784
785 if (orderByComparator != null) {
786 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
787 orderByComparator);
788 }
789
790 String sql = query.toString();
791
792 Query q = session.createQuery(sql);
793
794 QueryPos qPos = QueryPos.getInstance(q);
795
796 qPos.add(roleId);
797
798 list = (List<OrgGroupRole>)QueryUtil.list(q, getDialect(),
799 start, end);
800 }
801 catch (Exception e) {
802 throw processException(e);
803 }
804 finally {
805 if (list == null) {
806 list = new ArrayList<OrgGroupRole>();
807 }
808
809 cacheResult(list);
810
811 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_ROLEID,
812 finderArgs, list);
813
814 closeSession(session);
815 }
816 }
817
818 return list;
819 }
820
821
834 public OrgGroupRole findByRoleId_First(long roleId,
835 OrderByComparator orderByComparator)
836 throws NoSuchOrgGroupRoleException, SystemException {
837 List<OrgGroupRole> list = findByRoleId(roleId, 0, 1, orderByComparator);
838
839 if (list.isEmpty()) {
840 StringBundler msg = new StringBundler(4);
841
842 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
843
844 msg.append("roleId=");
845 msg.append(roleId);
846
847 msg.append(StringPool.CLOSE_CURLY_BRACE);
848
849 throw new NoSuchOrgGroupRoleException(msg.toString());
850 }
851 else {
852 return list.get(0);
853 }
854 }
855
856
869 public OrgGroupRole findByRoleId_Last(long roleId,
870 OrderByComparator orderByComparator)
871 throws NoSuchOrgGroupRoleException, SystemException {
872 int count = countByRoleId(roleId);
873
874 List<OrgGroupRole> list = findByRoleId(roleId, count - 1, count,
875 orderByComparator);
876
877 if (list.isEmpty()) {
878 StringBundler msg = new StringBundler(4);
879
880 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
881
882 msg.append("roleId=");
883 msg.append(roleId);
884
885 msg.append(StringPool.CLOSE_CURLY_BRACE);
886
887 throw new NoSuchOrgGroupRoleException(msg.toString());
888 }
889 else {
890 return list.get(0);
891 }
892 }
893
894
908 public OrgGroupRole[] findByRoleId_PrevAndNext(
909 OrgGroupRolePK orgGroupRolePK, long roleId,
910 OrderByComparator orderByComparator)
911 throws NoSuchOrgGroupRoleException, SystemException {
912 OrgGroupRole orgGroupRole = findByPrimaryKey(orgGroupRolePK);
913
914 Session session = null;
915
916 try {
917 session = openSession();
918
919 OrgGroupRole[] array = new OrgGroupRoleImpl[3];
920
921 array[0] = getByRoleId_PrevAndNext(session, orgGroupRole, roleId,
922 orderByComparator, true);
923
924 array[1] = orgGroupRole;
925
926 array[2] = getByRoleId_PrevAndNext(session, orgGroupRole, roleId,
927 orderByComparator, false);
928
929 return array;
930 }
931 catch (Exception e) {
932 throw processException(e);
933 }
934 finally {
935 closeSession(session);
936 }
937 }
938
939 protected OrgGroupRole getByRoleId_PrevAndNext(Session session,
940 OrgGroupRole orgGroupRole, long roleId,
941 OrderByComparator orderByComparator, boolean previous) {
942 StringBundler query = null;
943
944 if (orderByComparator != null) {
945 query = new StringBundler(6 +
946 (orderByComparator.getOrderByFields().length * 6));
947 }
948 else {
949 query = new StringBundler(3);
950 }
951
952 query.append(_SQL_SELECT_ORGGROUPROLE_WHERE);
953
954 query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
955
956 if (orderByComparator != null) {
957 String[] orderByFields = orderByComparator.getOrderByFields();
958
959 if (orderByFields.length > 0) {
960 query.append(WHERE_AND);
961 }
962
963 for (int i = 0; i < orderByFields.length; i++) {
964 query.append(_ORDER_BY_ENTITY_ALIAS);
965 query.append(orderByFields[i]);
966
967 if ((i + 1) < orderByFields.length) {
968 if (orderByComparator.isAscending() ^ previous) {
969 query.append(WHERE_GREATER_THAN_HAS_NEXT);
970 }
971 else {
972 query.append(WHERE_LESSER_THAN_HAS_NEXT);
973 }
974 }
975 else {
976 if (orderByComparator.isAscending() ^ previous) {
977 query.append(WHERE_GREATER_THAN);
978 }
979 else {
980 query.append(WHERE_LESSER_THAN);
981 }
982 }
983 }
984
985 query.append(ORDER_BY_CLAUSE);
986
987 for (int i = 0; i < orderByFields.length; i++) {
988 query.append(_ORDER_BY_ENTITY_ALIAS);
989 query.append(orderByFields[i]);
990
991 if ((i + 1) < orderByFields.length) {
992 if (orderByComparator.isAscending() ^ previous) {
993 query.append(ORDER_BY_ASC_HAS_NEXT);
994 }
995 else {
996 query.append(ORDER_BY_DESC_HAS_NEXT);
997 }
998 }
999 else {
1000 if (orderByComparator.isAscending() ^ previous) {
1001 query.append(ORDER_BY_ASC);
1002 }
1003 else {
1004 query.append(ORDER_BY_DESC);
1005 }
1006 }
1007 }
1008 }
1009
1010 String sql = query.toString();
1011
1012 Query q = session.createQuery(sql);
1013
1014 q.setFirstResult(0);
1015 q.setMaxResults(2);
1016
1017 QueryPos qPos = QueryPos.getInstance(q);
1018
1019 qPos.add(roleId);
1020
1021 if (orderByComparator != null) {
1022 Object[] values = orderByComparator.getOrderByValues(orgGroupRole);
1023
1024 for (Object value : values) {
1025 qPos.add(value);
1026 }
1027 }
1028
1029 List<OrgGroupRole> list = q.list();
1030
1031 if (list.size() == 2) {
1032 return list.get(1);
1033 }
1034 else {
1035 return null;
1036 }
1037 }
1038
1039
1045 public List<OrgGroupRole> findAll() throws SystemException {
1046 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1047 }
1048
1049
1061 public List<OrgGroupRole> findAll(int start, int end)
1062 throws SystemException {
1063 return findAll(start, end, null);
1064 }
1065
1066
1079 public List<OrgGroupRole> findAll(int start, int end,
1080 OrderByComparator orderByComparator) throws SystemException {
1081 Object[] finderArgs = new Object[] {
1082 String.valueOf(start), String.valueOf(end),
1083 String.valueOf(orderByComparator)
1084 };
1085
1086 List<OrgGroupRole> list = (List<OrgGroupRole>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1087 finderArgs, this);
1088
1089 if (list == null) {
1090 Session session = null;
1091
1092 try {
1093 session = openSession();
1094
1095 StringBundler query = null;
1096 String sql = null;
1097
1098 if (orderByComparator != null) {
1099 query = new StringBundler(2 +
1100 (orderByComparator.getOrderByFields().length * 3));
1101
1102 query.append(_SQL_SELECT_ORGGROUPROLE);
1103
1104 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1105 orderByComparator);
1106
1107 sql = query.toString();
1108 }
1109 else {
1110 sql = _SQL_SELECT_ORGGROUPROLE;
1111 }
1112
1113 Query q = session.createQuery(sql);
1114
1115 if (orderByComparator == null) {
1116 list = (List<OrgGroupRole>)QueryUtil.list(q, getDialect(),
1117 start, end, false);
1118
1119 Collections.sort(list);
1120 }
1121 else {
1122 list = (List<OrgGroupRole>)QueryUtil.list(q, getDialect(),
1123 start, end);
1124 }
1125 }
1126 catch (Exception e) {
1127 throw processException(e);
1128 }
1129 finally {
1130 if (list == null) {
1131 list = new ArrayList<OrgGroupRole>();
1132 }
1133
1134 cacheResult(list);
1135
1136 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1137
1138 closeSession(session);
1139 }
1140 }
1141
1142 return list;
1143 }
1144
1145
1151 public void removeByGroupId(long groupId) throws SystemException {
1152 for (OrgGroupRole orgGroupRole : findByGroupId(groupId)) {
1153 remove(orgGroupRole);
1154 }
1155 }
1156
1157
1163 public void removeByRoleId(long roleId) throws SystemException {
1164 for (OrgGroupRole orgGroupRole : findByRoleId(roleId)) {
1165 remove(orgGroupRole);
1166 }
1167 }
1168
1169
1174 public void removeAll() throws SystemException {
1175 for (OrgGroupRole orgGroupRole : findAll()) {
1176 remove(orgGroupRole);
1177 }
1178 }
1179
1180
1187 public int countByGroupId(long groupId) throws SystemException {
1188 Object[] finderArgs = new Object[] { groupId };
1189
1190 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
1191 finderArgs, this);
1192
1193 if (count == null) {
1194 Session session = null;
1195
1196 try {
1197 session = openSession();
1198
1199 StringBundler query = new StringBundler(2);
1200
1201 query.append(_SQL_COUNT_ORGGROUPROLE_WHERE);
1202
1203 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1204
1205 String sql = query.toString();
1206
1207 Query q = session.createQuery(sql);
1208
1209 QueryPos qPos = QueryPos.getInstance(q);
1210
1211 qPos.add(groupId);
1212
1213 count = (Long)q.uniqueResult();
1214 }
1215 catch (Exception e) {
1216 throw processException(e);
1217 }
1218 finally {
1219 if (count == null) {
1220 count = Long.valueOf(0);
1221 }
1222
1223 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
1224 finderArgs, count);
1225
1226 closeSession(session);
1227 }
1228 }
1229
1230 return count.intValue();
1231 }
1232
1233
1240 public int countByRoleId(long roleId) throws SystemException {
1241 Object[] finderArgs = new Object[] { roleId };
1242
1243 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_ROLEID,
1244 finderArgs, this);
1245
1246 if (count == null) {
1247 Session session = null;
1248
1249 try {
1250 session = openSession();
1251
1252 StringBundler query = new StringBundler(2);
1253
1254 query.append(_SQL_COUNT_ORGGROUPROLE_WHERE);
1255
1256 query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
1257
1258 String sql = query.toString();
1259
1260 Query q = session.createQuery(sql);
1261
1262 QueryPos qPos = QueryPos.getInstance(q);
1263
1264 qPos.add(roleId);
1265
1266 count = (Long)q.uniqueResult();
1267 }
1268 catch (Exception e) {
1269 throw processException(e);
1270 }
1271 finally {
1272 if (count == null) {
1273 count = Long.valueOf(0);
1274 }
1275
1276 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_ROLEID,
1277 finderArgs, count);
1278
1279 closeSession(session);
1280 }
1281 }
1282
1283 return count.intValue();
1284 }
1285
1286
1292 public int countAll() throws SystemException {
1293 Object[] finderArgs = new Object[0];
1294
1295 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1296 finderArgs, this);
1297
1298 if (count == null) {
1299 Session session = null;
1300
1301 try {
1302 session = openSession();
1303
1304 Query q = session.createQuery(_SQL_COUNT_ORGGROUPROLE);
1305
1306 count = (Long)q.uniqueResult();
1307 }
1308 catch (Exception e) {
1309 throw processException(e);
1310 }
1311 finally {
1312 if (count == null) {
1313 count = Long.valueOf(0);
1314 }
1315
1316 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1317 count);
1318
1319 closeSession(session);
1320 }
1321 }
1322
1323 return count.intValue();
1324 }
1325
1326
1329 public void afterPropertiesSet() {
1330 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1331 com.liferay.portal.util.PropsUtil.get(
1332 "value.object.listener.com.liferay.portal.model.OrgGroupRole")));
1333
1334 if (listenerClassNames.length > 0) {
1335 try {
1336 List<ModelListener<OrgGroupRole>> listenersList = new ArrayList<ModelListener<OrgGroupRole>>();
1337
1338 for (String listenerClassName : listenerClassNames) {
1339 listenersList.add((ModelListener<OrgGroupRole>)InstanceFactory.newInstance(
1340 listenerClassName));
1341 }
1342
1343 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1344 }
1345 catch (Exception e) {
1346 _log.error(e);
1347 }
1348 }
1349 }
1350
1351 public void destroy() {
1352 EntityCacheUtil.removeCache(OrgGroupRoleImpl.class.getName());
1353 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1354 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
1355 }
1356
1357 @BeanReference(type = AccountPersistence.class)
1358 protected AccountPersistence accountPersistence;
1359 @BeanReference(type = AddressPersistence.class)
1360 protected AddressPersistence addressPersistence;
1361 @BeanReference(type = BrowserTrackerPersistence.class)
1362 protected BrowserTrackerPersistence browserTrackerPersistence;
1363 @BeanReference(type = ClassNamePersistence.class)
1364 protected ClassNamePersistence classNamePersistence;
1365 @BeanReference(type = ClusterGroupPersistence.class)
1366 protected ClusterGroupPersistence clusterGroupPersistence;
1367 @BeanReference(type = CompanyPersistence.class)
1368 protected CompanyPersistence companyPersistence;
1369 @BeanReference(type = ContactPersistence.class)
1370 protected ContactPersistence contactPersistence;
1371 @BeanReference(type = CountryPersistence.class)
1372 protected CountryPersistence countryPersistence;
1373 @BeanReference(type = EmailAddressPersistence.class)
1374 protected EmailAddressPersistence emailAddressPersistence;
1375 @BeanReference(type = GroupPersistence.class)
1376 protected GroupPersistence groupPersistence;
1377 @BeanReference(type = ImagePersistence.class)
1378 protected ImagePersistence imagePersistence;
1379 @BeanReference(type = LayoutPersistence.class)
1380 protected LayoutPersistence layoutPersistence;
1381 @BeanReference(type = LayoutPrototypePersistence.class)
1382 protected LayoutPrototypePersistence layoutPrototypePersistence;
1383 @BeanReference(type = LayoutSetPersistence.class)
1384 protected LayoutSetPersistence layoutSetPersistence;
1385 @BeanReference(type = LayoutSetPrototypePersistence.class)
1386 protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
1387 @BeanReference(type = ListTypePersistence.class)
1388 protected ListTypePersistence listTypePersistence;
1389 @BeanReference(type = LockPersistence.class)
1390 protected LockPersistence lockPersistence;
1391 @BeanReference(type = MembershipRequestPersistence.class)
1392 protected MembershipRequestPersistence membershipRequestPersistence;
1393 @BeanReference(type = OrganizationPersistence.class)
1394 protected OrganizationPersistence organizationPersistence;
1395 @BeanReference(type = OrgGroupPermissionPersistence.class)
1396 protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1397 @BeanReference(type = OrgGroupRolePersistence.class)
1398 protected OrgGroupRolePersistence orgGroupRolePersistence;
1399 @BeanReference(type = OrgLaborPersistence.class)
1400 protected OrgLaborPersistence orgLaborPersistence;
1401 @BeanReference(type = PasswordPolicyPersistence.class)
1402 protected PasswordPolicyPersistence passwordPolicyPersistence;
1403 @BeanReference(type = PasswordPolicyRelPersistence.class)
1404 protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1405 @BeanReference(type = PasswordTrackerPersistence.class)
1406 protected PasswordTrackerPersistence passwordTrackerPersistence;
1407 @BeanReference(type = PermissionPersistence.class)
1408 protected PermissionPersistence permissionPersistence;
1409 @BeanReference(type = PhonePersistence.class)
1410 protected PhonePersistence phonePersistence;
1411 @BeanReference(type = PluginSettingPersistence.class)
1412 protected PluginSettingPersistence pluginSettingPersistence;
1413 @BeanReference(type = PortletPersistence.class)
1414 protected PortletPersistence portletPersistence;
1415 @BeanReference(type = PortletItemPersistence.class)
1416 protected PortletItemPersistence portletItemPersistence;
1417 @BeanReference(type = PortletPreferencesPersistence.class)
1418 protected PortletPreferencesPersistence portletPreferencesPersistence;
1419 @BeanReference(type = RegionPersistence.class)
1420 protected RegionPersistence regionPersistence;
1421 @BeanReference(type = ReleasePersistence.class)
1422 protected ReleasePersistence releasePersistence;
1423 @BeanReference(type = ResourcePersistence.class)
1424 protected ResourcePersistence resourcePersistence;
1425 @BeanReference(type = ResourceActionPersistence.class)
1426 protected ResourceActionPersistence resourceActionPersistence;
1427 @BeanReference(type = ResourceCodePersistence.class)
1428 protected ResourceCodePersistence resourceCodePersistence;
1429 @BeanReference(type = ResourcePermissionPersistence.class)
1430 protected ResourcePermissionPersistence resourcePermissionPersistence;
1431 @BeanReference(type = RolePersistence.class)
1432 protected RolePersistence rolePersistence;
1433 @BeanReference(type = ServiceComponentPersistence.class)
1434 protected ServiceComponentPersistence serviceComponentPersistence;
1435 @BeanReference(type = ShardPersistence.class)
1436 protected ShardPersistence shardPersistence;
1437 @BeanReference(type = SubscriptionPersistence.class)
1438 protected SubscriptionPersistence subscriptionPersistence;
1439 @BeanReference(type = TicketPersistence.class)
1440 protected TicketPersistence ticketPersistence;
1441 @BeanReference(type = TeamPersistence.class)
1442 protected TeamPersistence teamPersistence;
1443 @BeanReference(type = UserPersistence.class)
1444 protected UserPersistence userPersistence;
1445 @BeanReference(type = UserGroupPersistence.class)
1446 protected UserGroupPersistence userGroupPersistence;
1447 @BeanReference(type = UserGroupGroupRolePersistence.class)
1448 protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
1449 @BeanReference(type = UserGroupRolePersistence.class)
1450 protected UserGroupRolePersistence userGroupRolePersistence;
1451 @BeanReference(type = UserIdMapperPersistence.class)
1452 protected UserIdMapperPersistence userIdMapperPersistence;
1453 @BeanReference(type = UserTrackerPersistence.class)
1454 protected UserTrackerPersistence userTrackerPersistence;
1455 @BeanReference(type = UserTrackerPathPersistence.class)
1456 protected UserTrackerPathPersistence userTrackerPathPersistence;
1457 @BeanReference(type = WebDAVPropsPersistence.class)
1458 protected WebDAVPropsPersistence webDAVPropsPersistence;
1459 @BeanReference(type = WebsitePersistence.class)
1460 protected WebsitePersistence websitePersistence;
1461 @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
1462 protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
1463 @BeanReference(type = WorkflowInstanceLinkPersistence.class)
1464 protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
1465 private static final String _SQL_SELECT_ORGGROUPROLE = "SELECT orgGroupRole FROM OrgGroupRole orgGroupRole";
1466 private static final String _SQL_SELECT_ORGGROUPROLE_WHERE = "SELECT orgGroupRole FROM OrgGroupRole orgGroupRole WHERE ";
1467 private static final String _SQL_COUNT_ORGGROUPROLE = "SELECT COUNT(orgGroupRole) FROM OrgGroupRole orgGroupRole";
1468 private static final String _SQL_COUNT_ORGGROUPROLE_WHERE = "SELECT COUNT(orgGroupRole) FROM OrgGroupRole orgGroupRole WHERE ";
1469 private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "orgGroupRole.id.groupId = ?";
1470 private static final String _FINDER_COLUMN_ROLEID_ROLEID_2 = "orgGroupRole.id.roleId = ?";
1471 private static final String _ORDER_BY_ENTITY_ALIAS = "orgGroupRole.";
1472 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No OrgGroupRole exists with the primary key ";
1473 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No OrgGroupRole exists with the key {";
1474 private static Log _log = LogFactoryUtil.getLog(OrgGroupRolePersistenceImpl.class);
1475 }