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 if (orgGroupRole.isCachedModel() || BatchSessionUtil.isEnabled()) {
232 Object staleObject = session.get(OrgGroupRoleImpl.class,
233 orgGroupRole.getPrimaryKeyObj());
234
235 if (staleObject != null) {
236 session.evict(staleObject);
237 }
238 }
239
240 session.delete(orgGroupRole);
241
242 session.flush();
243 }
244 catch (Exception e) {
245 throw processException(e);
246 }
247 finally {
248 closeSession(session);
249 }
250
251 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
252
253 EntityCacheUtil.removeResult(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
254 OrgGroupRoleImpl.class, orgGroupRole.getPrimaryKey());
255
256 return orgGroupRole;
257 }
258
259 public OrgGroupRole updateImpl(
260 com.liferay.portal.model.OrgGroupRole orgGroupRole, boolean merge)
261 throws SystemException {
262 orgGroupRole = toUnwrappedModel(orgGroupRole);
263
264 Session session = null;
265
266 try {
267 session = openSession();
268
269 BatchSessionUtil.update(session, orgGroupRole, merge);
270
271 orgGroupRole.setNew(false);
272 }
273 catch (Exception e) {
274 throw processException(e);
275 }
276 finally {
277 closeSession(session);
278 }
279
280 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
281
282 EntityCacheUtil.putResult(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
283 OrgGroupRoleImpl.class, orgGroupRole.getPrimaryKey(), orgGroupRole);
284
285 return orgGroupRole;
286 }
287
288 protected OrgGroupRole toUnwrappedModel(OrgGroupRole orgGroupRole) {
289 if (orgGroupRole instanceof OrgGroupRoleImpl) {
290 return orgGroupRole;
291 }
292
293 OrgGroupRoleImpl orgGroupRoleImpl = new OrgGroupRoleImpl();
294
295 orgGroupRoleImpl.setNew(orgGroupRole.isNew());
296 orgGroupRoleImpl.setPrimaryKey(orgGroupRole.getPrimaryKey());
297
298 orgGroupRoleImpl.setOrganizationId(orgGroupRole.getOrganizationId());
299 orgGroupRoleImpl.setGroupId(orgGroupRole.getGroupId());
300 orgGroupRoleImpl.setRoleId(orgGroupRole.getRoleId());
301
302 return orgGroupRoleImpl;
303 }
304
305
313 public OrgGroupRole findByPrimaryKey(Serializable primaryKey)
314 throws NoSuchModelException, SystemException {
315 return findByPrimaryKey((OrgGroupRolePK)primaryKey);
316 }
317
318
326 public OrgGroupRole findByPrimaryKey(OrgGroupRolePK orgGroupRolePK)
327 throws NoSuchOrgGroupRoleException, SystemException {
328 OrgGroupRole orgGroupRole = fetchByPrimaryKey(orgGroupRolePK);
329
330 if (orgGroupRole == null) {
331 if (_log.isWarnEnabled()) {
332 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + orgGroupRolePK);
333 }
334
335 throw new NoSuchOrgGroupRoleException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
336 orgGroupRolePK);
337 }
338
339 return orgGroupRole;
340 }
341
342
349 public OrgGroupRole fetchByPrimaryKey(Serializable primaryKey)
350 throws SystemException {
351 return fetchByPrimaryKey((OrgGroupRolePK)primaryKey);
352 }
353
354
361 public OrgGroupRole fetchByPrimaryKey(OrgGroupRolePK orgGroupRolePK)
362 throws SystemException {
363 OrgGroupRole orgGroupRole = (OrgGroupRole)EntityCacheUtil.getResult(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
364 OrgGroupRoleImpl.class, orgGroupRolePK, this);
365
366 if (orgGroupRole == null) {
367 Session session = null;
368
369 try {
370 session = openSession();
371
372 orgGroupRole = (OrgGroupRole)session.get(OrgGroupRoleImpl.class,
373 orgGroupRolePK);
374 }
375 catch (Exception e) {
376 throw processException(e);
377 }
378 finally {
379 if (orgGroupRole != null) {
380 cacheResult(orgGroupRole);
381 }
382
383 closeSession(session);
384 }
385 }
386
387 return orgGroupRole;
388 }
389
390
397 public List<OrgGroupRole> findByGroupId(long groupId)
398 throws SystemException {
399 return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
400 }
401
402
415 public List<OrgGroupRole> findByGroupId(long groupId, int start, int end)
416 throws SystemException {
417 return findByGroupId(groupId, start, end, null);
418 }
419
420
434 public List<OrgGroupRole> findByGroupId(long groupId, int start, int end,
435 OrderByComparator orderByComparator) throws SystemException {
436 Object[] finderArgs = new Object[] {
437 groupId,
438
439 String.valueOf(start), String.valueOf(end),
440 String.valueOf(orderByComparator)
441 };
442
443 List<OrgGroupRole> list = (List<OrgGroupRole>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_GROUPID,
444 finderArgs, this);
445
446 if (list == null) {
447 Session session = null;
448
449 try {
450 session = openSession();
451
452 StringBundler query = null;
453
454 if (orderByComparator != null) {
455 query = new StringBundler(3 +
456 (orderByComparator.getOrderByFields().length * 3));
457 }
458 else {
459 query = new StringBundler(2);
460 }
461
462 query.append(_SQL_SELECT_ORGGROUPROLE_WHERE);
463
464 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
465
466 if (orderByComparator != null) {
467 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
468 orderByComparator);
469 }
470
471 String sql = query.toString();
472
473 Query q = session.createQuery(sql);
474
475 QueryPos qPos = QueryPos.getInstance(q);
476
477 qPos.add(groupId);
478
479 list = (List<OrgGroupRole>)QueryUtil.list(q, getDialect(),
480 start, end);
481 }
482 catch (Exception e) {
483 throw processException(e);
484 }
485 finally {
486 if (list == null) {
487 list = new ArrayList<OrgGroupRole>();
488 }
489
490 cacheResult(list);
491
492 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID,
493 finderArgs, list);
494
495 closeSession(session);
496 }
497 }
498
499 return list;
500 }
501
502
515 public OrgGroupRole findByGroupId_First(long groupId,
516 OrderByComparator orderByComparator)
517 throws NoSuchOrgGroupRoleException, SystemException {
518 List<OrgGroupRole> list = findByGroupId(groupId, 0, 1, orderByComparator);
519
520 if (list.isEmpty()) {
521 StringBundler msg = new StringBundler(4);
522
523 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
524
525 msg.append("groupId=");
526 msg.append(groupId);
527
528 msg.append(StringPool.CLOSE_CURLY_BRACE);
529
530 throw new NoSuchOrgGroupRoleException(msg.toString());
531 }
532 else {
533 return list.get(0);
534 }
535 }
536
537
550 public OrgGroupRole findByGroupId_Last(long groupId,
551 OrderByComparator orderByComparator)
552 throws NoSuchOrgGroupRoleException, SystemException {
553 int count = countByGroupId(groupId);
554
555 List<OrgGroupRole> list = findByGroupId(groupId, count - 1, count,
556 orderByComparator);
557
558 if (list.isEmpty()) {
559 StringBundler msg = new StringBundler(4);
560
561 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
562
563 msg.append("groupId=");
564 msg.append(groupId);
565
566 msg.append(StringPool.CLOSE_CURLY_BRACE);
567
568 throw new NoSuchOrgGroupRoleException(msg.toString());
569 }
570 else {
571 return list.get(0);
572 }
573 }
574
575
589 public OrgGroupRole[] findByGroupId_PrevAndNext(
590 OrgGroupRolePK orgGroupRolePK, long groupId,
591 OrderByComparator orderByComparator)
592 throws NoSuchOrgGroupRoleException, SystemException {
593 OrgGroupRole orgGroupRole = findByPrimaryKey(orgGroupRolePK);
594
595 Session session = null;
596
597 try {
598 session = openSession();
599
600 OrgGroupRole[] array = new OrgGroupRoleImpl[3];
601
602 array[0] = getByGroupId_PrevAndNext(session, orgGroupRole, groupId,
603 orderByComparator, true);
604
605 array[1] = orgGroupRole;
606
607 array[2] = getByGroupId_PrevAndNext(session, orgGroupRole, groupId,
608 orderByComparator, false);
609
610 return array;
611 }
612 catch (Exception e) {
613 throw processException(e);
614 }
615 finally {
616 closeSession(session);
617 }
618 }
619
620 protected OrgGroupRole getByGroupId_PrevAndNext(Session session,
621 OrgGroupRole orgGroupRole, long groupId,
622 OrderByComparator orderByComparator, boolean previous) {
623 StringBundler query = null;
624
625 if (orderByComparator != null) {
626 query = new StringBundler(6 +
627 (orderByComparator.getOrderByFields().length * 6));
628 }
629 else {
630 query = new StringBundler(3);
631 }
632
633 query.append(_SQL_SELECT_ORGGROUPROLE_WHERE);
634
635 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
636
637 if (orderByComparator != null) {
638 String[] orderByFields = orderByComparator.getOrderByFields();
639
640 if (orderByFields.length > 0) {
641 query.append(WHERE_AND);
642 }
643
644 for (int i = 0; i < orderByFields.length; i++) {
645 query.append(_ORDER_BY_ENTITY_ALIAS);
646 query.append(orderByFields[i]);
647
648 if ((i + 1) < orderByFields.length) {
649 if (orderByComparator.isAscending() ^ previous) {
650 query.append(WHERE_GREATER_THAN_HAS_NEXT);
651 }
652 else {
653 query.append(WHERE_LESSER_THAN_HAS_NEXT);
654 }
655 }
656 else {
657 if (orderByComparator.isAscending() ^ previous) {
658 query.append(WHERE_GREATER_THAN);
659 }
660 else {
661 query.append(WHERE_LESSER_THAN);
662 }
663 }
664 }
665
666 query.append(ORDER_BY_CLAUSE);
667
668 for (int i = 0; i < orderByFields.length; i++) {
669 query.append(_ORDER_BY_ENTITY_ALIAS);
670 query.append(orderByFields[i]);
671
672 if ((i + 1) < orderByFields.length) {
673 if (orderByComparator.isAscending() ^ previous) {
674 query.append(ORDER_BY_ASC_HAS_NEXT);
675 }
676 else {
677 query.append(ORDER_BY_DESC_HAS_NEXT);
678 }
679 }
680 else {
681 if (orderByComparator.isAscending() ^ previous) {
682 query.append(ORDER_BY_ASC);
683 }
684 else {
685 query.append(ORDER_BY_DESC);
686 }
687 }
688 }
689 }
690
691 String sql = query.toString();
692
693 Query q = session.createQuery(sql);
694
695 q.setFirstResult(0);
696 q.setMaxResults(2);
697
698 QueryPos qPos = QueryPos.getInstance(q);
699
700 qPos.add(groupId);
701
702 if (orderByComparator != null) {
703 Object[] values = orderByComparator.getOrderByValues(orgGroupRole);
704
705 for (Object value : values) {
706 qPos.add(value);
707 }
708 }
709
710 List<OrgGroupRole> list = q.list();
711
712 if (list.size() == 2) {
713 return list.get(1);
714 }
715 else {
716 return null;
717 }
718 }
719
720
727 public List<OrgGroupRole> findByRoleId(long roleId)
728 throws SystemException {
729 return findByRoleId(roleId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
730 }
731
732
745 public List<OrgGroupRole> findByRoleId(long roleId, int start, int end)
746 throws SystemException {
747 return findByRoleId(roleId, start, end, null);
748 }
749
750
764 public List<OrgGroupRole> findByRoleId(long roleId, int start, int end,
765 OrderByComparator orderByComparator) throws SystemException {
766 Object[] finderArgs = new Object[] {
767 roleId,
768
769 String.valueOf(start), String.valueOf(end),
770 String.valueOf(orderByComparator)
771 };
772
773 List<OrgGroupRole> list = (List<OrgGroupRole>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_ROLEID,
774 finderArgs, this);
775
776 if (list == null) {
777 Session session = null;
778
779 try {
780 session = openSession();
781
782 StringBundler query = null;
783
784 if (orderByComparator != null) {
785 query = new StringBundler(3 +
786 (orderByComparator.getOrderByFields().length * 3));
787 }
788 else {
789 query = new StringBundler(2);
790 }
791
792 query.append(_SQL_SELECT_ORGGROUPROLE_WHERE);
793
794 query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
795
796 if (orderByComparator != null) {
797 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
798 orderByComparator);
799 }
800
801 String sql = query.toString();
802
803 Query q = session.createQuery(sql);
804
805 QueryPos qPos = QueryPos.getInstance(q);
806
807 qPos.add(roleId);
808
809 list = (List<OrgGroupRole>)QueryUtil.list(q, getDialect(),
810 start, end);
811 }
812 catch (Exception e) {
813 throw processException(e);
814 }
815 finally {
816 if (list == null) {
817 list = new ArrayList<OrgGroupRole>();
818 }
819
820 cacheResult(list);
821
822 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_ROLEID,
823 finderArgs, list);
824
825 closeSession(session);
826 }
827 }
828
829 return list;
830 }
831
832
845 public OrgGroupRole findByRoleId_First(long roleId,
846 OrderByComparator orderByComparator)
847 throws NoSuchOrgGroupRoleException, SystemException {
848 List<OrgGroupRole> list = findByRoleId(roleId, 0, 1, orderByComparator);
849
850 if (list.isEmpty()) {
851 StringBundler msg = new StringBundler(4);
852
853 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
854
855 msg.append("roleId=");
856 msg.append(roleId);
857
858 msg.append(StringPool.CLOSE_CURLY_BRACE);
859
860 throw new NoSuchOrgGroupRoleException(msg.toString());
861 }
862 else {
863 return list.get(0);
864 }
865 }
866
867
880 public OrgGroupRole findByRoleId_Last(long roleId,
881 OrderByComparator orderByComparator)
882 throws NoSuchOrgGroupRoleException, SystemException {
883 int count = countByRoleId(roleId);
884
885 List<OrgGroupRole> list = findByRoleId(roleId, count - 1, count,
886 orderByComparator);
887
888 if (list.isEmpty()) {
889 StringBundler msg = new StringBundler(4);
890
891 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
892
893 msg.append("roleId=");
894 msg.append(roleId);
895
896 msg.append(StringPool.CLOSE_CURLY_BRACE);
897
898 throw new NoSuchOrgGroupRoleException(msg.toString());
899 }
900 else {
901 return list.get(0);
902 }
903 }
904
905
919 public OrgGroupRole[] findByRoleId_PrevAndNext(
920 OrgGroupRolePK orgGroupRolePK, long roleId,
921 OrderByComparator orderByComparator)
922 throws NoSuchOrgGroupRoleException, SystemException {
923 OrgGroupRole orgGroupRole = findByPrimaryKey(orgGroupRolePK);
924
925 Session session = null;
926
927 try {
928 session = openSession();
929
930 OrgGroupRole[] array = new OrgGroupRoleImpl[3];
931
932 array[0] = getByRoleId_PrevAndNext(session, orgGroupRole, roleId,
933 orderByComparator, true);
934
935 array[1] = orgGroupRole;
936
937 array[2] = getByRoleId_PrevAndNext(session, orgGroupRole, roleId,
938 orderByComparator, false);
939
940 return array;
941 }
942 catch (Exception e) {
943 throw processException(e);
944 }
945 finally {
946 closeSession(session);
947 }
948 }
949
950 protected OrgGroupRole getByRoleId_PrevAndNext(Session session,
951 OrgGroupRole orgGroupRole, long roleId,
952 OrderByComparator orderByComparator, boolean previous) {
953 StringBundler query = null;
954
955 if (orderByComparator != null) {
956 query = new StringBundler(6 +
957 (orderByComparator.getOrderByFields().length * 6));
958 }
959 else {
960 query = new StringBundler(3);
961 }
962
963 query.append(_SQL_SELECT_ORGGROUPROLE_WHERE);
964
965 query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
966
967 if (orderByComparator != null) {
968 String[] orderByFields = orderByComparator.getOrderByFields();
969
970 if (orderByFields.length > 0) {
971 query.append(WHERE_AND);
972 }
973
974 for (int i = 0; i < orderByFields.length; i++) {
975 query.append(_ORDER_BY_ENTITY_ALIAS);
976 query.append(orderByFields[i]);
977
978 if ((i + 1) < orderByFields.length) {
979 if (orderByComparator.isAscending() ^ previous) {
980 query.append(WHERE_GREATER_THAN_HAS_NEXT);
981 }
982 else {
983 query.append(WHERE_LESSER_THAN_HAS_NEXT);
984 }
985 }
986 else {
987 if (orderByComparator.isAscending() ^ previous) {
988 query.append(WHERE_GREATER_THAN);
989 }
990 else {
991 query.append(WHERE_LESSER_THAN);
992 }
993 }
994 }
995
996 query.append(ORDER_BY_CLAUSE);
997
998 for (int i = 0; i < orderByFields.length; i++) {
999 query.append(_ORDER_BY_ENTITY_ALIAS);
1000 query.append(orderByFields[i]);
1001
1002 if ((i + 1) < orderByFields.length) {
1003 if (orderByComparator.isAscending() ^ previous) {
1004 query.append(ORDER_BY_ASC_HAS_NEXT);
1005 }
1006 else {
1007 query.append(ORDER_BY_DESC_HAS_NEXT);
1008 }
1009 }
1010 else {
1011 if (orderByComparator.isAscending() ^ previous) {
1012 query.append(ORDER_BY_ASC);
1013 }
1014 else {
1015 query.append(ORDER_BY_DESC);
1016 }
1017 }
1018 }
1019 }
1020
1021 String sql = query.toString();
1022
1023 Query q = session.createQuery(sql);
1024
1025 q.setFirstResult(0);
1026 q.setMaxResults(2);
1027
1028 QueryPos qPos = QueryPos.getInstance(q);
1029
1030 qPos.add(roleId);
1031
1032 if (orderByComparator != null) {
1033 Object[] values = orderByComparator.getOrderByValues(orgGroupRole);
1034
1035 for (Object value : values) {
1036 qPos.add(value);
1037 }
1038 }
1039
1040 List<OrgGroupRole> list = q.list();
1041
1042 if (list.size() == 2) {
1043 return list.get(1);
1044 }
1045 else {
1046 return null;
1047 }
1048 }
1049
1050
1056 public List<OrgGroupRole> findAll() throws SystemException {
1057 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1058 }
1059
1060
1072 public List<OrgGroupRole> findAll(int start, int end)
1073 throws SystemException {
1074 return findAll(start, end, null);
1075 }
1076
1077
1090 public List<OrgGroupRole> findAll(int start, int end,
1091 OrderByComparator orderByComparator) throws SystemException {
1092 Object[] finderArgs = new Object[] {
1093 String.valueOf(start), String.valueOf(end),
1094 String.valueOf(orderByComparator)
1095 };
1096
1097 List<OrgGroupRole> list = (List<OrgGroupRole>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1098 finderArgs, this);
1099
1100 if (list == null) {
1101 Session session = null;
1102
1103 try {
1104 session = openSession();
1105
1106 StringBundler query = null;
1107 String sql = null;
1108
1109 if (orderByComparator != null) {
1110 query = new StringBundler(2 +
1111 (orderByComparator.getOrderByFields().length * 3));
1112
1113 query.append(_SQL_SELECT_ORGGROUPROLE);
1114
1115 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1116 orderByComparator);
1117
1118 sql = query.toString();
1119 }
1120 else {
1121 sql = _SQL_SELECT_ORGGROUPROLE;
1122 }
1123
1124 Query q = session.createQuery(sql);
1125
1126 if (orderByComparator == null) {
1127 list = (List<OrgGroupRole>)QueryUtil.list(q, getDialect(),
1128 start, end, false);
1129
1130 Collections.sort(list);
1131 }
1132 else {
1133 list = (List<OrgGroupRole>)QueryUtil.list(q, getDialect(),
1134 start, end);
1135 }
1136 }
1137 catch (Exception e) {
1138 throw processException(e);
1139 }
1140 finally {
1141 if (list == null) {
1142 list = new ArrayList<OrgGroupRole>();
1143 }
1144
1145 cacheResult(list);
1146
1147 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1148
1149 closeSession(session);
1150 }
1151 }
1152
1153 return list;
1154 }
1155
1156
1162 public void removeByGroupId(long groupId) throws SystemException {
1163 for (OrgGroupRole orgGroupRole : findByGroupId(groupId)) {
1164 remove(orgGroupRole);
1165 }
1166 }
1167
1168
1174 public void removeByRoleId(long roleId) throws SystemException {
1175 for (OrgGroupRole orgGroupRole : findByRoleId(roleId)) {
1176 remove(orgGroupRole);
1177 }
1178 }
1179
1180
1185 public void removeAll() throws SystemException {
1186 for (OrgGroupRole orgGroupRole : findAll()) {
1187 remove(orgGroupRole);
1188 }
1189 }
1190
1191
1198 public int countByGroupId(long groupId) throws SystemException {
1199 Object[] finderArgs = new Object[] { groupId };
1200
1201 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
1202 finderArgs, this);
1203
1204 if (count == null) {
1205 Session session = null;
1206
1207 try {
1208 session = openSession();
1209
1210 StringBundler query = new StringBundler(2);
1211
1212 query.append(_SQL_COUNT_ORGGROUPROLE_WHERE);
1213
1214 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1215
1216 String sql = query.toString();
1217
1218 Query q = session.createQuery(sql);
1219
1220 QueryPos qPos = QueryPos.getInstance(q);
1221
1222 qPos.add(groupId);
1223
1224 count = (Long)q.uniqueResult();
1225 }
1226 catch (Exception e) {
1227 throw processException(e);
1228 }
1229 finally {
1230 if (count == null) {
1231 count = Long.valueOf(0);
1232 }
1233
1234 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
1235 finderArgs, count);
1236
1237 closeSession(session);
1238 }
1239 }
1240
1241 return count.intValue();
1242 }
1243
1244
1251 public int countByRoleId(long roleId) throws SystemException {
1252 Object[] finderArgs = new Object[] { roleId };
1253
1254 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_ROLEID,
1255 finderArgs, this);
1256
1257 if (count == null) {
1258 Session session = null;
1259
1260 try {
1261 session = openSession();
1262
1263 StringBundler query = new StringBundler(2);
1264
1265 query.append(_SQL_COUNT_ORGGROUPROLE_WHERE);
1266
1267 query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
1268
1269 String sql = query.toString();
1270
1271 Query q = session.createQuery(sql);
1272
1273 QueryPos qPos = QueryPos.getInstance(q);
1274
1275 qPos.add(roleId);
1276
1277 count = (Long)q.uniqueResult();
1278 }
1279 catch (Exception e) {
1280 throw processException(e);
1281 }
1282 finally {
1283 if (count == null) {
1284 count = Long.valueOf(0);
1285 }
1286
1287 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_ROLEID,
1288 finderArgs, count);
1289
1290 closeSession(session);
1291 }
1292 }
1293
1294 return count.intValue();
1295 }
1296
1297
1303 public int countAll() throws SystemException {
1304 Object[] finderArgs = new Object[0];
1305
1306 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1307 finderArgs, this);
1308
1309 if (count == null) {
1310 Session session = null;
1311
1312 try {
1313 session = openSession();
1314
1315 Query q = session.createQuery(_SQL_COUNT_ORGGROUPROLE);
1316
1317 count = (Long)q.uniqueResult();
1318 }
1319 catch (Exception e) {
1320 throw processException(e);
1321 }
1322 finally {
1323 if (count == null) {
1324 count = Long.valueOf(0);
1325 }
1326
1327 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1328 count);
1329
1330 closeSession(session);
1331 }
1332 }
1333
1334 return count.intValue();
1335 }
1336
1337
1340 public void afterPropertiesSet() {
1341 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1342 com.liferay.portal.util.PropsUtil.get(
1343 "value.object.listener.com.liferay.portal.model.OrgGroupRole")));
1344
1345 if (listenerClassNames.length > 0) {
1346 try {
1347 List<ModelListener<OrgGroupRole>> listenersList = new ArrayList<ModelListener<OrgGroupRole>>();
1348
1349 for (String listenerClassName : listenerClassNames) {
1350 listenersList.add((ModelListener<OrgGroupRole>)InstanceFactory.newInstance(
1351 listenerClassName));
1352 }
1353
1354 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1355 }
1356 catch (Exception e) {
1357 _log.error(e);
1358 }
1359 }
1360 }
1361
1362 @BeanReference(type = AccountPersistence.class)
1363 protected AccountPersistence accountPersistence;
1364 @BeanReference(type = AddressPersistence.class)
1365 protected AddressPersistence addressPersistence;
1366 @BeanReference(type = BrowserTrackerPersistence.class)
1367 protected BrowserTrackerPersistence browserTrackerPersistence;
1368 @BeanReference(type = ClassNamePersistence.class)
1369 protected ClassNamePersistence classNamePersistence;
1370 @BeanReference(type = ClusterGroupPersistence.class)
1371 protected ClusterGroupPersistence clusterGroupPersistence;
1372 @BeanReference(type = CompanyPersistence.class)
1373 protected CompanyPersistence companyPersistence;
1374 @BeanReference(type = ContactPersistence.class)
1375 protected ContactPersistence contactPersistence;
1376 @BeanReference(type = CountryPersistence.class)
1377 protected CountryPersistence countryPersistence;
1378 @BeanReference(type = EmailAddressPersistence.class)
1379 protected EmailAddressPersistence emailAddressPersistence;
1380 @BeanReference(type = GroupPersistence.class)
1381 protected GroupPersistence groupPersistence;
1382 @BeanReference(type = ImagePersistence.class)
1383 protected ImagePersistence imagePersistence;
1384 @BeanReference(type = LayoutPersistence.class)
1385 protected LayoutPersistence layoutPersistence;
1386 @BeanReference(type = LayoutPrototypePersistence.class)
1387 protected LayoutPrototypePersistence layoutPrototypePersistence;
1388 @BeanReference(type = LayoutSetPersistence.class)
1389 protected LayoutSetPersistence layoutSetPersistence;
1390 @BeanReference(type = LayoutSetPrototypePersistence.class)
1391 protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
1392 @BeanReference(type = ListTypePersistence.class)
1393 protected ListTypePersistence listTypePersistence;
1394 @BeanReference(type = LockPersistence.class)
1395 protected LockPersistence lockPersistence;
1396 @BeanReference(type = MembershipRequestPersistence.class)
1397 protected MembershipRequestPersistence membershipRequestPersistence;
1398 @BeanReference(type = OrganizationPersistence.class)
1399 protected OrganizationPersistence organizationPersistence;
1400 @BeanReference(type = OrgGroupPermissionPersistence.class)
1401 protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1402 @BeanReference(type = OrgGroupRolePersistence.class)
1403 protected OrgGroupRolePersistence orgGroupRolePersistence;
1404 @BeanReference(type = OrgLaborPersistence.class)
1405 protected OrgLaborPersistence orgLaborPersistence;
1406 @BeanReference(type = PasswordPolicyPersistence.class)
1407 protected PasswordPolicyPersistence passwordPolicyPersistence;
1408 @BeanReference(type = PasswordPolicyRelPersistence.class)
1409 protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1410 @BeanReference(type = PasswordTrackerPersistence.class)
1411 protected PasswordTrackerPersistence passwordTrackerPersistence;
1412 @BeanReference(type = PermissionPersistence.class)
1413 protected PermissionPersistence permissionPersistence;
1414 @BeanReference(type = PhonePersistence.class)
1415 protected PhonePersistence phonePersistence;
1416 @BeanReference(type = PluginSettingPersistence.class)
1417 protected PluginSettingPersistence pluginSettingPersistence;
1418 @BeanReference(type = PortletPersistence.class)
1419 protected PortletPersistence portletPersistence;
1420 @BeanReference(type = PortletItemPersistence.class)
1421 protected PortletItemPersistence portletItemPersistence;
1422 @BeanReference(type = PortletPreferencesPersistence.class)
1423 protected PortletPreferencesPersistence portletPreferencesPersistence;
1424 @BeanReference(type = RegionPersistence.class)
1425 protected RegionPersistence regionPersistence;
1426 @BeanReference(type = ReleasePersistence.class)
1427 protected ReleasePersistence releasePersistence;
1428 @BeanReference(type = ResourcePersistence.class)
1429 protected ResourcePersistence resourcePersistence;
1430 @BeanReference(type = ResourceActionPersistence.class)
1431 protected ResourceActionPersistence resourceActionPersistence;
1432 @BeanReference(type = ResourceCodePersistence.class)
1433 protected ResourceCodePersistence resourceCodePersistence;
1434 @BeanReference(type = ResourcePermissionPersistence.class)
1435 protected ResourcePermissionPersistence resourcePermissionPersistence;
1436 @BeanReference(type = RolePersistence.class)
1437 protected RolePersistence rolePersistence;
1438 @BeanReference(type = ServiceComponentPersistence.class)
1439 protected ServiceComponentPersistence serviceComponentPersistence;
1440 @BeanReference(type = ShardPersistence.class)
1441 protected ShardPersistence shardPersistence;
1442 @BeanReference(type = SubscriptionPersistence.class)
1443 protected SubscriptionPersistence subscriptionPersistence;
1444 @BeanReference(type = TicketPersistence.class)
1445 protected TicketPersistence ticketPersistence;
1446 @BeanReference(type = TeamPersistence.class)
1447 protected TeamPersistence teamPersistence;
1448 @BeanReference(type = UserPersistence.class)
1449 protected UserPersistence userPersistence;
1450 @BeanReference(type = UserGroupPersistence.class)
1451 protected UserGroupPersistence userGroupPersistence;
1452 @BeanReference(type = UserGroupGroupRolePersistence.class)
1453 protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
1454 @BeanReference(type = UserGroupRolePersistence.class)
1455 protected UserGroupRolePersistence userGroupRolePersistence;
1456 @BeanReference(type = UserIdMapperPersistence.class)
1457 protected UserIdMapperPersistence userIdMapperPersistence;
1458 @BeanReference(type = UserTrackerPersistence.class)
1459 protected UserTrackerPersistence userTrackerPersistence;
1460 @BeanReference(type = UserTrackerPathPersistence.class)
1461 protected UserTrackerPathPersistence userTrackerPathPersistence;
1462 @BeanReference(type = WebDAVPropsPersistence.class)
1463 protected WebDAVPropsPersistence webDAVPropsPersistence;
1464 @BeanReference(type = WebsitePersistence.class)
1465 protected WebsitePersistence websitePersistence;
1466 @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
1467 protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
1468 @BeanReference(type = WorkflowInstanceLinkPersistence.class)
1469 protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
1470 private static final String _SQL_SELECT_ORGGROUPROLE = "SELECT orgGroupRole FROM OrgGroupRole orgGroupRole";
1471 private static final String _SQL_SELECT_ORGGROUPROLE_WHERE = "SELECT orgGroupRole FROM OrgGroupRole orgGroupRole WHERE ";
1472 private static final String _SQL_COUNT_ORGGROUPROLE = "SELECT COUNT(orgGroupRole) FROM OrgGroupRole orgGroupRole";
1473 private static final String _SQL_COUNT_ORGGROUPROLE_WHERE = "SELECT COUNT(orgGroupRole) FROM OrgGroupRole orgGroupRole WHERE ";
1474 private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "orgGroupRole.id.groupId = ?";
1475 private static final String _FINDER_COLUMN_ROLEID_ROLEID_2 = "orgGroupRole.id.roleId = ?";
1476 private static final String _ORDER_BY_ENTITY_ALIAS = "orgGroupRole.";
1477 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No OrgGroupRole exists with the primary key ";
1478 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No OrgGroupRole exists with the key {";
1479 private static Log _log = LogFactoryUtil.getLog(OrgGroupRolePersistenceImpl.class);
1480 }