001
014
015 package com.liferay.portal.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
018 import com.liferay.portal.NoSuchOrgGroupPermissionException;
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.OrgGroupPermission;
039 import com.liferay.portal.model.impl.OrgGroupPermissionImpl;
040 import com.liferay.portal.model.impl.OrgGroupPermissionModelImpl;
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 OrgGroupPermissionPersistenceImpl extends BasePersistenceImpl<OrgGroupPermission>
066 implements OrgGroupPermissionPersistence {
067 public static final String FINDER_CLASS_NAME_ENTITY = OrgGroupPermissionImpl.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(OrgGroupPermissionModelImpl.ENTITY_CACHE_ENABLED,
071 OrgGroupPermissionModelImpl.FINDER_CACHE_ENABLED,
072 FINDER_CLASS_NAME_LIST, "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(OrgGroupPermissionModelImpl.ENTITY_CACHE_ENABLED,
080 OrgGroupPermissionModelImpl.FINDER_CACHE_ENABLED,
081 FINDER_CLASS_NAME_LIST, "countByGroupId",
082 new String[] { Long.class.getName() });
083 public static final FinderPath FINDER_PATH_FIND_BY_PERMISSIONID = new FinderPath(OrgGroupPermissionModelImpl.ENTITY_CACHE_ENABLED,
084 OrgGroupPermissionModelImpl.FINDER_CACHE_ENABLED,
085 FINDER_CLASS_NAME_LIST, "findByPermissionId",
086 new String[] {
087 Long.class.getName(),
088
089 "java.lang.Integer", "java.lang.Integer",
090 "com.liferay.portal.kernel.util.OrderByComparator"
091 });
092 public static final FinderPath FINDER_PATH_COUNT_BY_PERMISSIONID = new FinderPath(OrgGroupPermissionModelImpl.ENTITY_CACHE_ENABLED,
093 OrgGroupPermissionModelImpl.FINDER_CACHE_ENABLED,
094 FINDER_CLASS_NAME_LIST, "countByPermissionId",
095 new String[] { Long.class.getName() });
096 public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(OrgGroupPermissionModelImpl.ENTITY_CACHE_ENABLED,
097 OrgGroupPermissionModelImpl.FINDER_CACHE_ENABLED,
098 FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
099 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(OrgGroupPermissionModelImpl.ENTITY_CACHE_ENABLED,
100 OrgGroupPermissionModelImpl.FINDER_CACHE_ENABLED,
101 FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
102
103
108 public void cacheResult(OrgGroupPermission orgGroupPermission) {
109 EntityCacheUtil.putResult(OrgGroupPermissionModelImpl.ENTITY_CACHE_ENABLED,
110 OrgGroupPermissionImpl.class, orgGroupPermission.getPrimaryKey(),
111 orgGroupPermission);
112 }
113
114
119 public void cacheResult(List<OrgGroupPermission> orgGroupPermissions) {
120 for (OrgGroupPermission orgGroupPermission : orgGroupPermissions) {
121 if (EntityCacheUtil.getResult(
122 OrgGroupPermissionModelImpl.ENTITY_CACHE_ENABLED,
123 OrgGroupPermissionImpl.class,
124 orgGroupPermission.getPrimaryKey(), this) == null) {
125 cacheResult(orgGroupPermission);
126 }
127 }
128 }
129
130
137 public void clearCache() {
138 CacheRegistryUtil.clear(OrgGroupPermissionImpl.class.getName());
139 EntityCacheUtil.clearCache(OrgGroupPermissionImpl.class.getName());
140 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
141 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
142 }
143
144
151 public void clearCache(OrgGroupPermission orgGroupPermission) {
152 EntityCacheUtil.removeResult(OrgGroupPermissionModelImpl.ENTITY_CACHE_ENABLED,
153 OrgGroupPermissionImpl.class, orgGroupPermission.getPrimaryKey());
154 }
155
156
162 public OrgGroupPermission create(OrgGroupPermissionPK orgGroupPermissionPK) {
163 OrgGroupPermission orgGroupPermission = new OrgGroupPermissionImpl();
164
165 orgGroupPermission.setNew(true);
166 orgGroupPermission.setPrimaryKey(orgGroupPermissionPK);
167
168 return orgGroupPermission;
169 }
170
171
179 public OrgGroupPermission remove(Serializable primaryKey)
180 throws NoSuchModelException, SystemException {
181 return remove((OrgGroupPermissionPK)primaryKey);
182 }
183
184
192 public OrgGroupPermission remove(OrgGroupPermissionPK orgGroupPermissionPK)
193 throws NoSuchOrgGroupPermissionException, SystemException {
194 Session session = null;
195
196 try {
197 session = openSession();
198
199 OrgGroupPermission orgGroupPermission = (OrgGroupPermission)session.get(OrgGroupPermissionImpl.class,
200 orgGroupPermissionPK);
201
202 if (orgGroupPermission == null) {
203 if (_log.isWarnEnabled()) {
204 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
205 orgGroupPermissionPK);
206 }
207
208 throw new NoSuchOrgGroupPermissionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
209 orgGroupPermissionPK);
210 }
211
212 return remove(orgGroupPermission);
213 }
214 catch (NoSuchOrgGroupPermissionException nsee) {
215 throw nsee;
216 }
217 catch (Exception e) {
218 throw processException(e);
219 }
220 finally {
221 closeSession(session);
222 }
223 }
224
225 protected OrgGroupPermission removeImpl(
226 OrgGroupPermission orgGroupPermission) throws SystemException {
227 orgGroupPermission = toUnwrappedModel(orgGroupPermission);
228
229 Session session = null;
230
231 try {
232 session = openSession();
233
234 BatchSessionUtil.delete(session, orgGroupPermission);
235 }
236 catch (Exception e) {
237 throw processException(e);
238 }
239 finally {
240 closeSession(session);
241 }
242
243 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
244
245 EntityCacheUtil.removeResult(OrgGroupPermissionModelImpl.ENTITY_CACHE_ENABLED,
246 OrgGroupPermissionImpl.class, orgGroupPermission.getPrimaryKey());
247
248 return orgGroupPermission;
249 }
250
251 public OrgGroupPermission updateImpl(
252 com.liferay.portal.model.OrgGroupPermission orgGroupPermission,
253 boolean merge) throws SystemException {
254 orgGroupPermission = toUnwrappedModel(orgGroupPermission);
255
256 Session session = null;
257
258 try {
259 session = openSession();
260
261 BatchSessionUtil.update(session, orgGroupPermission, merge);
262
263 orgGroupPermission.setNew(false);
264 }
265 catch (Exception e) {
266 throw processException(e);
267 }
268 finally {
269 closeSession(session);
270 }
271
272 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
273
274 EntityCacheUtil.putResult(OrgGroupPermissionModelImpl.ENTITY_CACHE_ENABLED,
275 OrgGroupPermissionImpl.class, orgGroupPermission.getPrimaryKey(),
276 orgGroupPermission);
277
278 return orgGroupPermission;
279 }
280
281 protected OrgGroupPermission toUnwrappedModel(
282 OrgGroupPermission orgGroupPermission) {
283 if (orgGroupPermission instanceof OrgGroupPermissionImpl) {
284 return orgGroupPermission;
285 }
286
287 OrgGroupPermissionImpl orgGroupPermissionImpl = new OrgGroupPermissionImpl();
288
289 orgGroupPermissionImpl.setNew(orgGroupPermission.isNew());
290 orgGroupPermissionImpl.setPrimaryKey(orgGroupPermission.getPrimaryKey());
291
292 orgGroupPermissionImpl.setOrganizationId(orgGroupPermission.getOrganizationId());
293 orgGroupPermissionImpl.setGroupId(orgGroupPermission.getGroupId());
294 orgGroupPermissionImpl.setPermissionId(orgGroupPermission.getPermissionId());
295
296 return orgGroupPermissionImpl;
297 }
298
299
307 public OrgGroupPermission findByPrimaryKey(Serializable primaryKey)
308 throws NoSuchModelException, SystemException {
309 return findByPrimaryKey((OrgGroupPermissionPK)primaryKey);
310 }
311
312
320 public OrgGroupPermission findByPrimaryKey(
321 OrgGroupPermissionPK orgGroupPermissionPK)
322 throws NoSuchOrgGroupPermissionException, SystemException {
323 OrgGroupPermission orgGroupPermission = fetchByPrimaryKey(orgGroupPermissionPK);
324
325 if (orgGroupPermission == null) {
326 if (_log.isWarnEnabled()) {
327 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
328 orgGroupPermissionPK);
329 }
330
331 throw new NoSuchOrgGroupPermissionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
332 orgGroupPermissionPK);
333 }
334
335 return orgGroupPermission;
336 }
337
338
345 public OrgGroupPermission fetchByPrimaryKey(Serializable primaryKey)
346 throws SystemException {
347 return fetchByPrimaryKey((OrgGroupPermissionPK)primaryKey);
348 }
349
350
357 public OrgGroupPermission fetchByPrimaryKey(
358 OrgGroupPermissionPK orgGroupPermissionPK) throws SystemException {
359 OrgGroupPermission orgGroupPermission = (OrgGroupPermission)EntityCacheUtil.getResult(OrgGroupPermissionModelImpl.ENTITY_CACHE_ENABLED,
360 OrgGroupPermissionImpl.class, orgGroupPermissionPK, this);
361
362 if (orgGroupPermission == null) {
363 Session session = null;
364
365 try {
366 session = openSession();
367
368 orgGroupPermission = (OrgGroupPermission)session.get(OrgGroupPermissionImpl.class,
369 orgGroupPermissionPK);
370 }
371 catch (Exception e) {
372 throw processException(e);
373 }
374 finally {
375 if (orgGroupPermission != null) {
376 cacheResult(orgGroupPermission);
377 }
378
379 closeSession(session);
380 }
381 }
382
383 return orgGroupPermission;
384 }
385
386
393 public List<OrgGroupPermission> findByGroupId(long groupId)
394 throws SystemException {
395 return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
396 }
397
398
411 public List<OrgGroupPermission> findByGroupId(long groupId, int start,
412 int end) throws SystemException {
413 return findByGroupId(groupId, start, end, null);
414 }
415
416
430 public List<OrgGroupPermission> findByGroupId(long groupId, int start,
431 int end, OrderByComparator orderByComparator) throws SystemException {
432 Object[] finderArgs = new Object[] {
433 groupId,
434
435 String.valueOf(start), String.valueOf(end),
436 String.valueOf(orderByComparator)
437 };
438
439 List<OrgGroupPermission> list = (List<OrgGroupPermission>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_GROUPID,
440 finderArgs, this);
441
442 if (list == null) {
443 StringBundler query = null;
444
445 if (orderByComparator != null) {
446 query = new StringBundler(3 +
447 (orderByComparator.getOrderByFields().length * 3));
448 }
449 else {
450 query = new StringBundler(2);
451 }
452
453 query.append(_SQL_SELECT_ORGGROUPPERMISSION_WHERE);
454
455 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
456
457 if (orderByComparator != null) {
458 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
459 orderByComparator);
460 }
461
462 String sql = query.toString();
463
464 Session session = null;
465
466 try {
467 session = openSession();
468
469 Query q = session.createQuery(sql);
470
471 QueryPos qPos = QueryPos.getInstance(q);
472
473 qPos.add(groupId);
474
475 list = (List<OrgGroupPermission>)QueryUtil.list(q,
476 getDialect(), start, end);
477 }
478 catch (Exception e) {
479 throw processException(e);
480 }
481 finally {
482 if (list == null) {
483 FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_GROUPID,
484 finderArgs);
485 }
486 else {
487 cacheResult(list);
488
489 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID,
490 finderArgs, list);
491 }
492
493 closeSession(session);
494 }
495 }
496
497 return list;
498 }
499
500
513 public OrgGroupPermission findByGroupId_First(long groupId,
514 OrderByComparator orderByComparator)
515 throws NoSuchOrgGroupPermissionException, SystemException {
516 List<OrgGroupPermission> list = findByGroupId(groupId, 0, 1,
517 orderByComparator);
518
519 if (list.isEmpty()) {
520 StringBundler msg = new StringBundler(4);
521
522 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
523
524 msg.append("groupId=");
525 msg.append(groupId);
526
527 msg.append(StringPool.CLOSE_CURLY_BRACE);
528
529 throw new NoSuchOrgGroupPermissionException(msg.toString());
530 }
531 else {
532 return list.get(0);
533 }
534 }
535
536
549 public OrgGroupPermission findByGroupId_Last(long groupId,
550 OrderByComparator orderByComparator)
551 throws NoSuchOrgGroupPermissionException, SystemException {
552 int count = countByGroupId(groupId);
553
554 List<OrgGroupPermission> list = findByGroupId(groupId, count - 1,
555 count, orderByComparator);
556
557 if (list.isEmpty()) {
558 StringBundler msg = new StringBundler(4);
559
560 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
561
562 msg.append("groupId=");
563 msg.append(groupId);
564
565 msg.append(StringPool.CLOSE_CURLY_BRACE);
566
567 throw new NoSuchOrgGroupPermissionException(msg.toString());
568 }
569 else {
570 return list.get(0);
571 }
572 }
573
574
588 public OrgGroupPermission[] findByGroupId_PrevAndNext(
589 OrgGroupPermissionPK orgGroupPermissionPK, long groupId,
590 OrderByComparator orderByComparator)
591 throws NoSuchOrgGroupPermissionException, SystemException {
592 OrgGroupPermission orgGroupPermission = findByPrimaryKey(orgGroupPermissionPK);
593
594 Session session = null;
595
596 try {
597 session = openSession();
598
599 OrgGroupPermission[] array = new OrgGroupPermissionImpl[3];
600
601 array[0] = getByGroupId_PrevAndNext(session, orgGroupPermission,
602 groupId, orderByComparator, true);
603
604 array[1] = orgGroupPermission;
605
606 array[2] = getByGroupId_PrevAndNext(session, orgGroupPermission,
607 groupId, orderByComparator, false);
608
609 return array;
610 }
611 catch (Exception e) {
612 throw processException(e);
613 }
614 finally {
615 closeSession(session);
616 }
617 }
618
619 protected OrgGroupPermission getByGroupId_PrevAndNext(Session session,
620 OrgGroupPermission orgGroupPermission, long groupId,
621 OrderByComparator orderByComparator, boolean previous) {
622 StringBundler query = null;
623
624 if (orderByComparator != null) {
625 query = new StringBundler(6 +
626 (orderByComparator.getOrderByFields().length * 6));
627 }
628 else {
629 query = new StringBundler(3);
630 }
631
632 query.append(_SQL_SELECT_ORGGROUPPERMISSION_WHERE);
633
634 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
635
636 if (orderByComparator != null) {
637 String[] orderByFields = orderByComparator.getOrderByFields();
638
639 if (orderByFields.length > 0) {
640 query.append(WHERE_AND);
641 }
642
643 for (int i = 0; i < orderByFields.length; i++) {
644 query.append(_ORDER_BY_ENTITY_ALIAS);
645 query.append(orderByFields[i]);
646
647 if ((i + 1) < orderByFields.length) {
648 if (orderByComparator.isAscending() ^ previous) {
649 query.append(WHERE_GREATER_THAN_HAS_NEXT);
650 }
651 else {
652 query.append(WHERE_LESSER_THAN_HAS_NEXT);
653 }
654 }
655 else {
656 if (orderByComparator.isAscending() ^ previous) {
657 query.append(WHERE_GREATER_THAN);
658 }
659 else {
660 query.append(WHERE_LESSER_THAN);
661 }
662 }
663 }
664
665 query.append(ORDER_BY_CLAUSE);
666
667 for (int i = 0; i < orderByFields.length; i++) {
668 query.append(_ORDER_BY_ENTITY_ALIAS);
669 query.append(orderByFields[i]);
670
671 if ((i + 1) < orderByFields.length) {
672 if (orderByComparator.isAscending() ^ previous) {
673 query.append(ORDER_BY_ASC_HAS_NEXT);
674 }
675 else {
676 query.append(ORDER_BY_DESC_HAS_NEXT);
677 }
678 }
679 else {
680 if (orderByComparator.isAscending() ^ previous) {
681 query.append(ORDER_BY_ASC);
682 }
683 else {
684 query.append(ORDER_BY_DESC);
685 }
686 }
687 }
688 }
689
690 String sql = query.toString();
691
692 Query q = session.createQuery(sql);
693
694 q.setFirstResult(0);
695 q.setMaxResults(2);
696
697 QueryPos qPos = QueryPos.getInstance(q);
698
699 qPos.add(groupId);
700
701 if (orderByComparator != null) {
702 Object[] values = orderByComparator.getOrderByValues(orgGroupPermission);
703
704 for (Object value : values) {
705 qPos.add(value);
706 }
707 }
708
709 List<OrgGroupPermission> list = q.list();
710
711 if (list.size() == 2) {
712 return list.get(1);
713 }
714 else {
715 return null;
716 }
717 }
718
719
726 public List<OrgGroupPermission> findByPermissionId(long permissionId)
727 throws SystemException {
728 return findByPermissionId(permissionId, QueryUtil.ALL_POS,
729 QueryUtil.ALL_POS, null);
730 }
731
732
745 public List<OrgGroupPermission> findByPermissionId(long permissionId,
746 int start, int end) throws SystemException {
747 return findByPermissionId(permissionId, start, end, null);
748 }
749
750
764 public List<OrgGroupPermission> findByPermissionId(long permissionId,
765 int start, int end, OrderByComparator orderByComparator)
766 throws SystemException {
767 Object[] finderArgs = new Object[] {
768 permissionId,
769
770 String.valueOf(start), String.valueOf(end),
771 String.valueOf(orderByComparator)
772 };
773
774 List<OrgGroupPermission> list = (List<OrgGroupPermission>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_PERMISSIONID,
775 finderArgs, this);
776
777 if (list == null) {
778 StringBundler query = null;
779
780 if (orderByComparator != null) {
781 query = new StringBundler(3 +
782 (orderByComparator.getOrderByFields().length * 3));
783 }
784 else {
785 query = new StringBundler(2);
786 }
787
788 query.append(_SQL_SELECT_ORGGROUPPERMISSION_WHERE);
789
790 query.append(_FINDER_COLUMN_PERMISSIONID_PERMISSIONID_2);
791
792 if (orderByComparator != null) {
793 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
794 orderByComparator);
795 }
796
797 String sql = query.toString();
798
799 Session session = null;
800
801 try {
802 session = openSession();
803
804 Query q = session.createQuery(sql);
805
806 QueryPos qPos = QueryPos.getInstance(q);
807
808 qPos.add(permissionId);
809
810 list = (List<OrgGroupPermission>)QueryUtil.list(q,
811 getDialect(), start, end);
812 }
813 catch (Exception e) {
814 throw processException(e);
815 }
816 finally {
817 if (list == null) {
818 FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_PERMISSIONID,
819 finderArgs);
820 }
821 else {
822 cacheResult(list);
823
824 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_PERMISSIONID,
825 finderArgs, list);
826 }
827
828 closeSession(session);
829 }
830 }
831
832 return list;
833 }
834
835
848 public OrgGroupPermission findByPermissionId_First(long permissionId,
849 OrderByComparator orderByComparator)
850 throws NoSuchOrgGroupPermissionException, SystemException {
851 List<OrgGroupPermission> list = findByPermissionId(permissionId, 0, 1,
852 orderByComparator);
853
854 if (list.isEmpty()) {
855 StringBundler msg = new StringBundler(4);
856
857 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
858
859 msg.append("permissionId=");
860 msg.append(permissionId);
861
862 msg.append(StringPool.CLOSE_CURLY_BRACE);
863
864 throw new NoSuchOrgGroupPermissionException(msg.toString());
865 }
866 else {
867 return list.get(0);
868 }
869 }
870
871
884 public OrgGroupPermission findByPermissionId_Last(long permissionId,
885 OrderByComparator orderByComparator)
886 throws NoSuchOrgGroupPermissionException, SystemException {
887 int count = countByPermissionId(permissionId);
888
889 List<OrgGroupPermission> list = findByPermissionId(permissionId,
890 count - 1, count, orderByComparator);
891
892 if (list.isEmpty()) {
893 StringBundler msg = new StringBundler(4);
894
895 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
896
897 msg.append("permissionId=");
898 msg.append(permissionId);
899
900 msg.append(StringPool.CLOSE_CURLY_BRACE);
901
902 throw new NoSuchOrgGroupPermissionException(msg.toString());
903 }
904 else {
905 return list.get(0);
906 }
907 }
908
909
923 public OrgGroupPermission[] findByPermissionId_PrevAndNext(
924 OrgGroupPermissionPK orgGroupPermissionPK, long permissionId,
925 OrderByComparator orderByComparator)
926 throws NoSuchOrgGroupPermissionException, SystemException {
927 OrgGroupPermission orgGroupPermission = findByPrimaryKey(orgGroupPermissionPK);
928
929 Session session = null;
930
931 try {
932 session = openSession();
933
934 OrgGroupPermission[] array = new OrgGroupPermissionImpl[3];
935
936 array[0] = getByPermissionId_PrevAndNext(session,
937 orgGroupPermission, permissionId, orderByComparator, true);
938
939 array[1] = orgGroupPermission;
940
941 array[2] = getByPermissionId_PrevAndNext(session,
942 orgGroupPermission, permissionId, orderByComparator, false);
943
944 return array;
945 }
946 catch (Exception e) {
947 throw processException(e);
948 }
949 finally {
950 closeSession(session);
951 }
952 }
953
954 protected OrgGroupPermission getByPermissionId_PrevAndNext(
955 Session session, OrgGroupPermission orgGroupPermission,
956 long permissionId, OrderByComparator orderByComparator, boolean previous) {
957 StringBundler query = null;
958
959 if (orderByComparator != null) {
960 query = new StringBundler(6 +
961 (orderByComparator.getOrderByFields().length * 6));
962 }
963 else {
964 query = new StringBundler(3);
965 }
966
967 query.append(_SQL_SELECT_ORGGROUPPERMISSION_WHERE);
968
969 query.append(_FINDER_COLUMN_PERMISSIONID_PERMISSIONID_2);
970
971 if (orderByComparator != null) {
972 String[] orderByFields = orderByComparator.getOrderByFields();
973
974 if (orderByFields.length > 0) {
975 query.append(WHERE_AND);
976 }
977
978 for (int i = 0; i < orderByFields.length; i++) {
979 query.append(_ORDER_BY_ENTITY_ALIAS);
980 query.append(orderByFields[i]);
981
982 if ((i + 1) < orderByFields.length) {
983 if (orderByComparator.isAscending() ^ previous) {
984 query.append(WHERE_GREATER_THAN_HAS_NEXT);
985 }
986 else {
987 query.append(WHERE_LESSER_THAN_HAS_NEXT);
988 }
989 }
990 else {
991 if (orderByComparator.isAscending() ^ previous) {
992 query.append(WHERE_GREATER_THAN);
993 }
994 else {
995 query.append(WHERE_LESSER_THAN);
996 }
997 }
998 }
999
1000 query.append(ORDER_BY_CLAUSE);
1001
1002 for (int i = 0; i < orderByFields.length; i++) {
1003 query.append(_ORDER_BY_ENTITY_ALIAS);
1004 query.append(orderByFields[i]);
1005
1006 if ((i + 1) < orderByFields.length) {
1007 if (orderByComparator.isAscending() ^ previous) {
1008 query.append(ORDER_BY_ASC_HAS_NEXT);
1009 }
1010 else {
1011 query.append(ORDER_BY_DESC_HAS_NEXT);
1012 }
1013 }
1014 else {
1015 if (orderByComparator.isAscending() ^ previous) {
1016 query.append(ORDER_BY_ASC);
1017 }
1018 else {
1019 query.append(ORDER_BY_DESC);
1020 }
1021 }
1022 }
1023 }
1024
1025 String sql = query.toString();
1026
1027 Query q = session.createQuery(sql);
1028
1029 q.setFirstResult(0);
1030 q.setMaxResults(2);
1031
1032 QueryPos qPos = QueryPos.getInstance(q);
1033
1034 qPos.add(permissionId);
1035
1036 if (orderByComparator != null) {
1037 Object[] values = orderByComparator.getOrderByValues(orgGroupPermission);
1038
1039 for (Object value : values) {
1040 qPos.add(value);
1041 }
1042 }
1043
1044 List<OrgGroupPermission> list = q.list();
1045
1046 if (list.size() == 2) {
1047 return list.get(1);
1048 }
1049 else {
1050 return null;
1051 }
1052 }
1053
1054
1060 public List<OrgGroupPermission> findAll() throws SystemException {
1061 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1062 }
1063
1064
1076 public List<OrgGroupPermission> findAll(int start, int end)
1077 throws SystemException {
1078 return findAll(start, end, null);
1079 }
1080
1081
1094 public List<OrgGroupPermission> findAll(int start, int end,
1095 OrderByComparator orderByComparator) throws SystemException {
1096 Object[] finderArgs = new Object[] {
1097 String.valueOf(start), String.valueOf(end),
1098 String.valueOf(orderByComparator)
1099 };
1100
1101 List<OrgGroupPermission> list = (List<OrgGroupPermission>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1102 finderArgs, this);
1103
1104 if (list == null) {
1105 StringBundler query = null;
1106 String sql = null;
1107
1108 if (orderByComparator != null) {
1109 query = new StringBundler(2 +
1110 (orderByComparator.getOrderByFields().length * 3));
1111
1112 query.append(_SQL_SELECT_ORGGROUPPERMISSION);
1113
1114 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1115 orderByComparator);
1116
1117 sql = query.toString();
1118 }
1119 else {
1120 sql = _SQL_SELECT_ORGGROUPPERMISSION;
1121 }
1122
1123 Session session = null;
1124
1125 try {
1126 session = openSession();
1127
1128 Query q = session.createQuery(sql);
1129
1130 if (orderByComparator == null) {
1131 list = (List<OrgGroupPermission>)QueryUtil.list(q,
1132 getDialect(), start, end, false);
1133
1134 Collections.sort(list);
1135 }
1136 else {
1137 list = (List<OrgGroupPermission>)QueryUtil.list(q,
1138 getDialect(), start, end);
1139 }
1140 }
1141 catch (Exception e) {
1142 throw processException(e);
1143 }
1144 finally {
1145 if (list == null) {
1146 FinderCacheUtil.removeResult(FINDER_PATH_FIND_ALL,
1147 finderArgs);
1148 }
1149 else {
1150 cacheResult(list);
1151
1152 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs,
1153 list);
1154 }
1155
1156 closeSession(session);
1157 }
1158 }
1159
1160 return list;
1161 }
1162
1163
1169 public void removeByGroupId(long groupId) throws SystemException {
1170 for (OrgGroupPermission orgGroupPermission : findByGroupId(groupId)) {
1171 remove(orgGroupPermission);
1172 }
1173 }
1174
1175
1181 public void removeByPermissionId(long permissionId)
1182 throws SystemException {
1183 for (OrgGroupPermission orgGroupPermission : findByPermissionId(
1184 permissionId)) {
1185 remove(orgGroupPermission);
1186 }
1187 }
1188
1189
1194 public void removeAll() throws SystemException {
1195 for (OrgGroupPermission orgGroupPermission : findAll()) {
1196 remove(orgGroupPermission);
1197 }
1198 }
1199
1200
1207 public int countByGroupId(long groupId) throws SystemException {
1208 Object[] finderArgs = new Object[] { groupId };
1209
1210 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
1211 finderArgs, this);
1212
1213 if (count == null) {
1214 StringBundler query = new StringBundler(2);
1215
1216 query.append(_SQL_COUNT_ORGGROUPPERMISSION_WHERE);
1217
1218 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1219
1220 String sql = query.toString();
1221
1222 Session session = null;
1223
1224 try {
1225 session = openSession();
1226
1227 Query q = session.createQuery(sql);
1228
1229 QueryPos qPos = QueryPos.getInstance(q);
1230
1231 qPos.add(groupId);
1232
1233 count = (Long)q.uniqueResult();
1234 }
1235 catch (Exception e) {
1236 throw processException(e);
1237 }
1238 finally {
1239 if (count == null) {
1240 count = Long.valueOf(0);
1241 }
1242
1243 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
1244 finderArgs, count);
1245
1246 closeSession(session);
1247 }
1248 }
1249
1250 return count.intValue();
1251 }
1252
1253
1260 public int countByPermissionId(long permissionId) throws SystemException {
1261 Object[] finderArgs = new Object[] { permissionId };
1262
1263 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_PERMISSIONID,
1264 finderArgs, this);
1265
1266 if (count == null) {
1267 StringBundler query = new StringBundler(2);
1268
1269 query.append(_SQL_COUNT_ORGGROUPPERMISSION_WHERE);
1270
1271 query.append(_FINDER_COLUMN_PERMISSIONID_PERMISSIONID_2);
1272
1273 String sql = query.toString();
1274
1275 Session session = null;
1276
1277 try {
1278 session = openSession();
1279
1280 Query q = session.createQuery(sql);
1281
1282 QueryPos qPos = QueryPos.getInstance(q);
1283
1284 qPos.add(permissionId);
1285
1286 count = (Long)q.uniqueResult();
1287 }
1288 catch (Exception e) {
1289 throw processException(e);
1290 }
1291 finally {
1292 if (count == null) {
1293 count = Long.valueOf(0);
1294 }
1295
1296 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_PERMISSIONID,
1297 finderArgs, count);
1298
1299 closeSession(session);
1300 }
1301 }
1302
1303 return count.intValue();
1304 }
1305
1306
1312 public int countAll() throws SystemException {
1313 Object[] finderArgs = new Object[0];
1314
1315 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1316 finderArgs, this);
1317
1318 if (count == null) {
1319 Session session = null;
1320
1321 try {
1322 session = openSession();
1323
1324 Query q = session.createQuery(_SQL_COUNT_ORGGROUPPERMISSION);
1325
1326 count = (Long)q.uniqueResult();
1327 }
1328 catch (Exception e) {
1329 throw processException(e);
1330 }
1331 finally {
1332 if (count == null) {
1333 count = Long.valueOf(0);
1334 }
1335
1336 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1337 count);
1338
1339 closeSession(session);
1340 }
1341 }
1342
1343 return count.intValue();
1344 }
1345
1346
1349 public void afterPropertiesSet() {
1350 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1351 com.liferay.portal.util.PropsUtil.get(
1352 "value.object.listener.com.liferay.portal.model.OrgGroupPermission")));
1353
1354 if (listenerClassNames.length > 0) {
1355 try {
1356 List<ModelListener<OrgGroupPermission>> listenersList = new ArrayList<ModelListener<OrgGroupPermission>>();
1357
1358 for (String listenerClassName : listenerClassNames) {
1359 listenersList.add((ModelListener<OrgGroupPermission>)InstanceFactory.newInstance(
1360 listenerClassName));
1361 }
1362
1363 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1364 }
1365 catch (Exception e) {
1366 _log.error(e);
1367 }
1368 }
1369 }
1370
1371 public void destroy() {
1372 EntityCacheUtil.removeCache(OrgGroupPermissionImpl.class.getName());
1373 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1374 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
1375 }
1376
1377 @BeanReference(type = AccountPersistence.class)
1378 protected AccountPersistence accountPersistence;
1379 @BeanReference(type = AddressPersistence.class)
1380 protected AddressPersistence addressPersistence;
1381 @BeanReference(type = BrowserTrackerPersistence.class)
1382 protected BrowserTrackerPersistence browserTrackerPersistence;
1383 @BeanReference(type = ClassNamePersistence.class)
1384 protected ClassNamePersistence classNamePersistence;
1385 @BeanReference(type = ClusterGroupPersistence.class)
1386 protected ClusterGroupPersistence clusterGroupPersistence;
1387 @BeanReference(type = CompanyPersistence.class)
1388 protected CompanyPersistence companyPersistence;
1389 @BeanReference(type = ContactPersistence.class)
1390 protected ContactPersistence contactPersistence;
1391 @BeanReference(type = CountryPersistence.class)
1392 protected CountryPersistence countryPersistence;
1393 @BeanReference(type = EmailAddressPersistence.class)
1394 protected EmailAddressPersistence emailAddressPersistence;
1395 @BeanReference(type = GroupPersistence.class)
1396 protected GroupPersistence groupPersistence;
1397 @BeanReference(type = ImagePersistence.class)
1398 protected ImagePersistence imagePersistence;
1399 @BeanReference(type = LayoutPersistence.class)
1400 protected LayoutPersistence layoutPersistence;
1401 @BeanReference(type = LayoutPrototypePersistence.class)
1402 protected LayoutPrototypePersistence layoutPrototypePersistence;
1403 @BeanReference(type = LayoutSetPersistence.class)
1404 protected LayoutSetPersistence layoutSetPersistence;
1405 @BeanReference(type = LayoutSetPrototypePersistence.class)
1406 protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
1407 @BeanReference(type = ListTypePersistence.class)
1408 protected ListTypePersistence listTypePersistence;
1409 @BeanReference(type = LockPersistence.class)
1410 protected LockPersistence lockPersistence;
1411 @BeanReference(type = MembershipRequestPersistence.class)
1412 protected MembershipRequestPersistence membershipRequestPersistence;
1413 @BeanReference(type = OrganizationPersistence.class)
1414 protected OrganizationPersistence organizationPersistence;
1415 @BeanReference(type = OrgGroupPermissionPersistence.class)
1416 protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1417 @BeanReference(type = OrgGroupRolePersistence.class)
1418 protected OrgGroupRolePersistence orgGroupRolePersistence;
1419 @BeanReference(type = OrgLaborPersistence.class)
1420 protected OrgLaborPersistence orgLaborPersistence;
1421 @BeanReference(type = PasswordPolicyPersistence.class)
1422 protected PasswordPolicyPersistence passwordPolicyPersistence;
1423 @BeanReference(type = PasswordPolicyRelPersistence.class)
1424 protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1425 @BeanReference(type = PasswordTrackerPersistence.class)
1426 protected PasswordTrackerPersistence passwordTrackerPersistence;
1427 @BeanReference(type = PermissionPersistence.class)
1428 protected PermissionPersistence permissionPersistence;
1429 @BeanReference(type = PhonePersistence.class)
1430 protected PhonePersistence phonePersistence;
1431 @BeanReference(type = PluginSettingPersistence.class)
1432 protected PluginSettingPersistence pluginSettingPersistence;
1433 @BeanReference(type = PortletPersistence.class)
1434 protected PortletPersistence portletPersistence;
1435 @BeanReference(type = PortletItemPersistence.class)
1436 protected PortletItemPersistence portletItemPersistence;
1437 @BeanReference(type = PortletPreferencesPersistence.class)
1438 protected PortletPreferencesPersistence portletPreferencesPersistence;
1439 @BeanReference(type = RegionPersistence.class)
1440 protected RegionPersistence regionPersistence;
1441 @BeanReference(type = ReleasePersistence.class)
1442 protected ReleasePersistence releasePersistence;
1443 @BeanReference(type = ResourcePersistence.class)
1444 protected ResourcePersistence resourcePersistence;
1445 @BeanReference(type = ResourceActionPersistence.class)
1446 protected ResourceActionPersistence resourceActionPersistence;
1447 @BeanReference(type = ResourceCodePersistence.class)
1448 protected ResourceCodePersistence resourceCodePersistence;
1449 @BeanReference(type = ResourcePermissionPersistence.class)
1450 protected ResourcePermissionPersistence resourcePermissionPersistence;
1451 @BeanReference(type = RolePersistence.class)
1452 protected RolePersistence rolePersistence;
1453 @BeanReference(type = ServiceComponentPersistence.class)
1454 protected ServiceComponentPersistence serviceComponentPersistence;
1455 @BeanReference(type = ShardPersistence.class)
1456 protected ShardPersistence shardPersistence;
1457 @BeanReference(type = SubscriptionPersistence.class)
1458 protected SubscriptionPersistence subscriptionPersistence;
1459 @BeanReference(type = TicketPersistence.class)
1460 protected TicketPersistence ticketPersistence;
1461 @BeanReference(type = TeamPersistence.class)
1462 protected TeamPersistence teamPersistence;
1463 @BeanReference(type = UserPersistence.class)
1464 protected UserPersistence userPersistence;
1465 @BeanReference(type = UserGroupPersistence.class)
1466 protected UserGroupPersistence userGroupPersistence;
1467 @BeanReference(type = UserGroupGroupRolePersistence.class)
1468 protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
1469 @BeanReference(type = UserGroupRolePersistence.class)
1470 protected UserGroupRolePersistence userGroupRolePersistence;
1471 @BeanReference(type = UserIdMapperPersistence.class)
1472 protected UserIdMapperPersistence userIdMapperPersistence;
1473 @BeanReference(type = UserTrackerPersistence.class)
1474 protected UserTrackerPersistence userTrackerPersistence;
1475 @BeanReference(type = UserTrackerPathPersistence.class)
1476 protected UserTrackerPathPersistence userTrackerPathPersistence;
1477 @BeanReference(type = WebDAVPropsPersistence.class)
1478 protected WebDAVPropsPersistence webDAVPropsPersistence;
1479 @BeanReference(type = WebsitePersistence.class)
1480 protected WebsitePersistence websitePersistence;
1481 @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
1482 protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
1483 @BeanReference(type = WorkflowInstanceLinkPersistence.class)
1484 protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
1485 private static final String _SQL_SELECT_ORGGROUPPERMISSION = "SELECT orgGroupPermission FROM OrgGroupPermission orgGroupPermission";
1486 private static final String _SQL_SELECT_ORGGROUPPERMISSION_WHERE = "SELECT orgGroupPermission FROM OrgGroupPermission orgGroupPermission WHERE ";
1487 private static final String _SQL_COUNT_ORGGROUPPERMISSION = "SELECT COUNT(orgGroupPermission) FROM OrgGroupPermission orgGroupPermission";
1488 private static final String _SQL_COUNT_ORGGROUPPERMISSION_WHERE = "SELECT COUNT(orgGroupPermission) FROM OrgGroupPermission orgGroupPermission WHERE ";
1489 private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "orgGroupPermission.id.groupId = ?";
1490 private static final String _FINDER_COLUMN_PERMISSIONID_PERMISSIONID_2 = "orgGroupPermission.id.permissionId = ?";
1491 private static final String _ORDER_BY_ENTITY_ALIAS = "orgGroupPermission.";
1492 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No OrgGroupPermission exists with the primary key ";
1493 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No OrgGroupPermission exists with the key {";
1494 private static Log _log = LogFactoryUtil.getLog(OrgGroupPermissionPersistenceImpl.class);
1495 }