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.cache.CacheRegistryUtil;
020 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderPath;
023 import com.liferay.portal.kernel.dao.orm.Query;
024 import com.liferay.portal.kernel.dao.orm.QueryPos;
025 import com.liferay.portal.kernel.dao.orm.QueryUtil;
026 import com.liferay.portal.kernel.dao.orm.Session;
027 import com.liferay.portal.kernel.exception.SystemException;
028 import com.liferay.portal.kernel.log.Log;
029 import com.liferay.portal.kernel.log.LogFactoryUtil;
030 import com.liferay.portal.kernel.util.GetterUtil;
031 import com.liferay.portal.kernel.util.InstanceFactory;
032 import com.liferay.portal.kernel.util.OrderByComparator;
033 import com.liferay.portal.kernel.util.StringBundler;
034 import com.liferay.portal.kernel.util.StringPool;
035 import com.liferay.portal.kernel.util.StringUtil;
036 import com.liferay.portal.kernel.util.UnmodifiableList;
037 import com.liferay.portal.model.CacheModel;
038 import com.liferay.portal.model.ModelListener;
039 import com.liferay.portal.model.OrgGroupRole;
040 import com.liferay.portal.model.impl.OrgGroupRoleImpl;
041 import com.liferay.portal.model.impl.OrgGroupRoleModelImpl;
042 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
043
044 import java.io.Serializable;
045
046 import java.util.ArrayList;
047 import java.util.Collections;
048 import java.util.List;
049
050
062 public class OrgGroupRolePersistenceImpl extends BasePersistenceImpl<OrgGroupRole>
063 implements OrgGroupRolePersistence {
064
069 public static final String FINDER_CLASS_NAME_ENTITY = OrgGroupRoleImpl.class.getName();
070 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
071 ".List1";
072 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
073 ".List2";
074 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
075 OrgGroupRoleModelImpl.FINDER_CACHE_ENABLED, OrgGroupRoleImpl.class,
076 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
077 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
078 OrgGroupRoleModelImpl.FINDER_CACHE_ENABLED, OrgGroupRoleImpl.class,
079 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
080 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
081 OrgGroupRoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
082 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
083 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
084 OrgGroupRoleModelImpl.FINDER_CACHE_ENABLED, OrgGroupRoleImpl.class,
085 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
086 new String[] {
087 Long.class.getName(),
088
089 Integer.class.getName(), Integer.class.getName(),
090 OrderByComparator.class.getName()
091 });
092 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
093 new FinderPath(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
094 OrgGroupRoleModelImpl.FINDER_CACHE_ENABLED, OrgGroupRoleImpl.class,
095 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
096 new String[] { Long.class.getName() },
097 OrgGroupRoleModelImpl.GROUPID_COLUMN_BITMASK);
098 public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
099 OrgGroupRoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
100 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
101 new String[] { Long.class.getName() });
102
103
110 public List<OrgGroupRole> findByGroupId(long groupId)
111 throws SystemException {
112 return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
113 }
114
115
128 public List<OrgGroupRole> findByGroupId(long groupId, int start, int end)
129 throws SystemException {
130 return findByGroupId(groupId, start, end, null);
131 }
132
133
147 public List<OrgGroupRole> findByGroupId(long groupId, int start, int end,
148 OrderByComparator orderByComparator) throws SystemException {
149 boolean pagination = true;
150 FinderPath finderPath = null;
151 Object[] finderArgs = null;
152
153 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
154 (orderByComparator == null)) {
155 pagination = false;
156 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
157 finderArgs = new Object[] { groupId };
158 }
159 else {
160 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
161 finderArgs = new Object[] { groupId, start, end, orderByComparator };
162 }
163
164 List<OrgGroupRole> list = (List<OrgGroupRole>)FinderCacheUtil.getResult(finderPath,
165 finderArgs, this);
166
167 if ((list != null) && !list.isEmpty()) {
168 for (OrgGroupRole orgGroupRole : list) {
169 if ((groupId != orgGroupRole.getGroupId())) {
170 list = null;
171
172 break;
173 }
174 }
175 }
176
177 if (list == null) {
178 StringBundler query = null;
179
180 if (orderByComparator != null) {
181 query = new StringBundler(3 +
182 (orderByComparator.getOrderByFields().length * 3));
183 }
184 else {
185 query = new StringBundler(3);
186 }
187
188 query.append(_SQL_SELECT_ORGGROUPROLE_WHERE);
189
190 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
191
192 if (orderByComparator != null) {
193 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
194 orderByComparator);
195 }
196 else
197 if (pagination) {
198 query.append(OrgGroupRoleModelImpl.ORDER_BY_JPQL);
199 }
200
201 String sql = query.toString();
202
203 Session session = null;
204
205 try {
206 session = openSession();
207
208 Query q = session.createQuery(sql);
209
210 QueryPos qPos = QueryPos.getInstance(q);
211
212 qPos.add(groupId);
213
214 if (!pagination) {
215 list = (List<OrgGroupRole>)QueryUtil.list(q, getDialect(),
216 start, end, false);
217
218 Collections.sort(list);
219
220 list = new UnmodifiableList<OrgGroupRole>(list);
221 }
222 else {
223 list = (List<OrgGroupRole>)QueryUtil.list(q, getDialect(),
224 start, end);
225 }
226
227 cacheResult(list);
228
229 FinderCacheUtil.putResult(finderPath, finderArgs, list);
230 }
231 catch (Exception e) {
232 FinderCacheUtil.removeResult(finderPath, finderArgs);
233
234 throw processException(e);
235 }
236 finally {
237 closeSession(session);
238 }
239 }
240
241 return list;
242 }
243
244
253 public OrgGroupRole findByGroupId_First(long groupId,
254 OrderByComparator orderByComparator)
255 throws NoSuchOrgGroupRoleException, SystemException {
256 OrgGroupRole orgGroupRole = fetchByGroupId_First(groupId,
257 orderByComparator);
258
259 if (orgGroupRole != null) {
260 return orgGroupRole;
261 }
262
263 StringBundler msg = new StringBundler(4);
264
265 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
266
267 msg.append("groupId=");
268 msg.append(groupId);
269
270 msg.append(StringPool.CLOSE_CURLY_BRACE);
271
272 throw new NoSuchOrgGroupRoleException(msg.toString());
273 }
274
275
283 public OrgGroupRole fetchByGroupId_First(long groupId,
284 OrderByComparator orderByComparator) throws SystemException {
285 List<OrgGroupRole> list = findByGroupId(groupId, 0, 1, orderByComparator);
286
287 if (!list.isEmpty()) {
288 return list.get(0);
289 }
290
291 return null;
292 }
293
294
303 public OrgGroupRole findByGroupId_Last(long groupId,
304 OrderByComparator orderByComparator)
305 throws NoSuchOrgGroupRoleException, SystemException {
306 OrgGroupRole orgGroupRole = fetchByGroupId_Last(groupId,
307 orderByComparator);
308
309 if (orgGroupRole != null) {
310 return orgGroupRole;
311 }
312
313 StringBundler msg = new StringBundler(4);
314
315 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
316
317 msg.append("groupId=");
318 msg.append(groupId);
319
320 msg.append(StringPool.CLOSE_CURLY_BRACE);
321
322 throw new NoSuchOrgGroupRoleException(msg.toString());
323 }
324
325
333 public OrgGroupRole fetchByGroupId_Last(long groupId,
334 OrderByComparator orderByComparator) throws SystemException {
335 int count = countByGroupId(groupId);
336
337 List<OrgGroupRole> list = findByGroupId(groupId, count - 1, count,
338 orderByComparator);
339
340 if (!list.isEmpty()) {
341 return list.get(0);
342 }
343
344 return null;
345 }
346
347
357 public OrgGroupRole[] findByGroupId_PrevAndNext(
358 OrgGroupRolePK orgGroupRolePK, long groupId,
359 OrderByComparator orderByComparator)
360 throws NoSuchOrgGroupRoleException, SystemException {
361 OrgGroupRole orgGroupRole = findByPrimaryKey(orgGroupRolePK);
362
363 Session session = null;
364
365 try {
366 session = openSession();
367
368 OrgGroupRole[] array = new OrgGroupRoleImpl[3];
369
370 array[0] = getByGroupId_PrevAndNext(session, orgGroupRole, groupId,
371 orderByComparator, true);
372
373 array[1] = orgGroupRole;
374
375 array[2] = getByGroupId_PrevAndNext(session, orgGroupRole, groupId,
376 orderByComparator, false);
377
378 return array;
379 }
380 catch (Exception e) {
381 throw processException(e);
382 }
383 finally {
384 closeSession(session);
385 }
386 }
387
388 protected OrgGroupRole getByGroupId_PrevAndNext(Session session,
389 OrgGroupRole orgGroupRole, long groupId,
390 OrderByComparator orderByComparator, boolean previous) {
391 StringBundler query = null;
392
393 if (orderByComparator != null) {
394 query = new StringBundler(6 +
395 (orderByComparator.getOrderByFields().length * 6));
396 }
397 else {
398 query = new StringBundler(3);
399 }
400
401 query.append(_SQL_SELECT_ORGGROUPROLE_WHERE);
402
403 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
404
405 if (orderByComparator != null) {
406 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
407
408 if (orderByConditionFields.length > 0) {
409 query.append(WHERE_AND);
410 }
411
412 for (int i = 0; i < orderByConditionFields.length; i++) {
413 query.append(_ORDER_BY_ENTITY_ALIAS);
414 query.append(orderByConditionFields[i]);
415
416 if ((i + 1) < orderByConditionFields.length) {
417 if (orderByComparator.isAscending() ^ previous) {
418 query.append(WHERE_GREATER_THAN_HAS_NEXT);
419 }
420 else {
421 query.append(WHERE_LESSER_THAN_HAS_NEXT);
422 }
423 }
424 else {
425 if (orderByComparator.isAscending() ^ previous) {
426 query.append(WHERE_GREATER_THAN);
427 }
428 else {
429 query.append(WHERE_LESSER_THAN);
430 }
431 }
432 }
433
434 query.append(ORDER_BY_CLAUSE);
435
436 String[] orderByFields = orderByComparator.getOrderByFields();
437
438 for (int i = 0; i < orderByFields.length; i++) {
439 query.append(_ORDER_BY_ENTITY_ALIAS);
440 query.append(orderByFields[i]);
441
442 if ((i + 1) < orderByFields.length) {
443 if (orderByComparator.isAscending() ^ previous) {
444 query.append(ORDER_BY_ASC_HAS_NEXT);
445 }
446 else {
447 query.append(ORDER_BY_DESC_HAS_NEXT);
448 }
449 }
450 else {
451 if (orderByComparator.isAscending() ^ previous) {
452 query.append(ORDER_BY_ASC);
453 }
454 else {
455 query.append(ORDER_BY_DESC);
456 }
457 }
458 }
459 }
460 else {
461 query.append(OrgGroupRoleModelImpl.ORDER_BY_JPQL);
462 }
463
464 String sql = query.toString();
465
466 Query q = session.createQuery(sql);
467
468 q.setFirstResult(0);
469 q.setMaxResults(2);
470
471 QueryPos qPos = QueryPos.getInstance(q);
472
473 qPos.add(groupId);
474
475 if (orderByComparator != null) {
476 Object[] values = orderByComparator.getOrderByConditionValues(orgGroupRole);
477
478 for (Object value : values) {
479 qPos.add(value);
480 }
481 }
482
483 List<OrgGroupRole> list = q.list();
484
485 if (list.size() == 2) {
486 return list.get(1);
487 }
488 else {
489 return null;
490 }
491 }
492
493
499 public void removeByGroupId(long groupId) throws SystemException {
500 for (OrgGroupRole orgGroupRole : findByGroupId(groupId,
501 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
502 remove(orgGroupRole);
503 }
504 }
505
506
513 public int countByGroupId(long groupId) throws SystemException {
514 FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
515
516 Object[] finderArgs = new Object[] { groupId };
517
518 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
519 this);
520
521 if (count == null) {
522 StringBundler query = new StringBundler(2);
523
524 query.append(_SQL_COUNT_ORGGROUPROLE_WHERE);
525
526 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
527
528 String sql = query.toString();
529
530 Session session = null;
531
532 try {
533 session = openSession();
534
535 Query q = session.createQuery(sql);
536
537 QueryPos qPos = QueryPos.getInstance(q);
538
539 qPos.add(groupId);
540
541 count = (Long)q.uniqueResult();
542
543 FinderCacheUtil.putResult(finderPath, finderArgs, count);
544 }
545 catch (Exception e) {
546 FinderCacheUtil.removeResult(finderPath, finderArgs);
547
548 throw processException(e);
549 }
550 finally {
551 closeSession(session);
552 }
553 }
554
555 return count.intValue();
556 }
557
558 private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "orgGroupRole.id.groupId = ?";
559 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_ROLEID = new FinderPath(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
560 OrgGroupRoleModelImpl.FINDER_CACHE_ENABLED, OrgGroupRoleImpl.class,
561 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByRoleId",
562 new String[] {
563 Long.class.getName(),
564
565 Integer.class.getName(), Integer.class.getName(),
566 OrderByComparator.class.getName()
567 });
568 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID =
569 new FinderPath(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
570 OrgGroupRoleModelImpl.FINDER_CACHE_ENABLED, OrgGroupRoleImpl.class,
571 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByRoleId",
572 new String[] { Long.class.getName() },
573 OrgGroupRoleModelImpl.ROLEID_COLUMN_BITMASK);
574 public static final FinderPath FINDER_PATH_COUNT_BY_ROLEID = new FinderPath(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
575 OrgGroupRoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
576 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByRoleId",
577 new String[] { Long.class.getName() });
578
579
586 public List<OrgGroupRole> findByRoleId(long roleId)
587 throws SystemException {
588 return findByRoleId(roleId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
589 }
590
591
604 public List<OrgGroupRole> findByRoleId(long roleId, int start, int end)
605 throws SystemException {
606 return findByRoleId(roleId, start, end, null);
607 }
608
609
623 public List<OrgGroupRole> findByRoleId(long roleId, int start, int end,
624 OrderByComparator orderByComparator) throws SystemException {
625 boolean pagination = true;
626 FinderPath finderPath = null;
627 Object[] finderArgs = null;
628
629 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
630 (orderByComparator == null)) {
631 pagination = false;
632 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID;
633 finderArgs = new Object[] { roleId };
634 }
635 else {
636 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_ROLEID;
637 finderArgs = new Object[] { roleId, start, end, orderByComparator };
638 }
639
640 List<OrgGroupRole> list = (List<OrgGroupRole>)FinderCacheUtil.getResult(finderPath,
641 finderArgs, this);
642
643 if ((list != null) && !list.isEmpty()) {
644 for (OrgGroupRole orgGroupRole : list) {
645 if ((roleId != orgGroupRole.getRoleId())) {
646 list = null;
647
648 break;
649 }
650 }
651 }
652
653 if (list == null) {
654 StringBundler query = null;
655
656 if (orderByComparator != null) {
657 query = new StringBundler(3 +
658 (orderByComparator.getOrderByFields().length * 3));
659 }
660 else {
661 query = new StringBundler(3);
662 }
663
664 query.append(_SQL_SELECT_ORGGROUPROLE_WHERE);
665
666 query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
667
668 if (orderByComparator != null) {
669 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
670 orderByComparator);
671 }
672 else
673 if (pagination) {
674 query.append(OrgGroupRoleModelImpl.ORDER_BY_JPQL);
675 }
676
677 String sql = query.toString();
678
679 Session session = null;
680
681 try {
682 session = openSession();
683
684 Query q = session.createQuery(sql);
685
686 QueryPos qPos = QueryPos.getInstance(q);
687
688 qPos.add(roleId);
689
690 if (!pagination) {
691 list = (List<OrgGroupRole>)QueryUtil.list(q, getDialect(),
692 start, end, false);
693
694 Collections.sort(list);
695
696 list = new UnmodifiableList<OrgGroupRole>(list);
697 }
698 else {
699 list = (List<OrgGroupRole>)QueryUtil.list(q, getDialect(),
700 start, end);
701 }
702
703 cacheResult(list);
704
705 FinderCacheUtil.putResult(finderPath, finderArgs, list);
706 }
707 catch (Exception e) {
708 FinderCacheUtil.removeResult(finderPath, finderArgs);
709
710 throw processException(e);
711 }
712 finally {
713 closeSession(session);
714 }
715 }
716
717 return list;
718 }
719
720
729 public OrgGroupRole findByRoleId_First(long roleId,
730 OrderByComparator orderByComparator)
731 throws NoSuchOrgGroupRoleException, SystemException {
732 OrgGroupRole orgGroupRole = fetchByRoleId_First(roleId,
733 orderByComparator);
734
735 if (orgGroupRole != null) {
736 return orgGroupRole;
737 }
738
739 StringBundler msg = new StringBundler(4);
740
741 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
742
743 msg.append("roleId=");
744 msg.append(roleId);
745
746 msg.append(StringPool.CLOSE_CURLY_BRACE);
747
748 throw new NoSuchOrgGroupRoleException(msg.toString());
749 }
750
751
759 public OrgGroupRole fetchByRoleId_First(long roleId,
760 OrderByComparator orderByComparator) throws SystemException {
761 List<OrgGroupRole> list = findByRoleId(roleId, 0, 1, orderByComparator);
762
763 if (!list.isEmpty()) {
764 return list.get(0);
765 }
766
767 return null;
768 }
769
770
779 public OrgGroupRole findByRoleId_Last(long roleId,
780 OrderByComparator orderByComparator)
781 throws NoSuchOrgGroupRoleException, SystemException {
782 OrgGroupRole orgGroupRole = fetchByRoleId_Last(roleId, orderByComparator);
783
784 if (orgGroupRole != null) {
785 return orgGroupRole;
786 }
787
788 StringBundler msg = new StringBundler(4);
789
790 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
791
792 msg.append("roleId=");
793 msg.append(roleId);
794
795 msg.append(StringPool.CLOSE_CURLY_BRACE);
796
797 throw new NoSuchOrgGroupRoleException(msg.toString());
798 }
799
800
808 public OrgGroupRole fetchByRoleId_Last(long roleId,
809 OrderByComparator orderByComparator) throws SystemException {
810 int count = countByRoleId(roleId);
811
812 List<OrgGroupRole> list = findByRoleId(roleId, count - 1, count,
813 orderByComparator);
814
815 if (!list.isEmpty()) {
816 return list.get(0);
817 }
818
819 return null;
820 }
821
822
832 public OrgGroupRole[] findByRoleId_PrevAndNext(
833 OrgGroupRolePK orgGroupRolePK, long roleId,
834 OrderByComparator orderByComparator)
835 throws NoSuchOrgGroupRoleException, SystemException {
836 OrgGroupRole orgGroupRole = findByPrimaryKey(orgGroupRolePK);
837
838 Session session = null;
839
840 try {
841 session = openSession();
842
843 OrgGroupRole[] array = new OrgGroupRoleImpl[3];
844
845 array[0] = getByRoleId_PrevAndNext(session, orgGroupRole, roleId,
846 orderByComparator, true);
847
848 array[1] = orgGroupRole;
849
850 array[2] = getByRoleId_PrevAndNext(session, orgGroupRole, roleId,
851 orderByComparator, false);
852
853 return array;
854 }
855 catch (Exception e) {
856 throw processException(e);
857 }
858 finally {
859 closeSession(session);
860 }
861 }
862
863 protected OrgGroupRole getByRoleId_PrevAndNext(Session session,
864 OrgGroupRole orgGroupRole, long roleId,
865 OrderByComparator orderByComparator, boolean previous) {
866 StringBundler query = null;
867
868 if (orderByComparator != null) {
869 query = new StringBundler(6 +
870 (orderByComparator.getOrderByFields().length * 6));
871 }
872 else {
873 query = new StringBundler(3);
874 }
875
876 query.append(_SQL_SELECT_ORGGROUPROLE_WHERE);
877
878 query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
879
880 if (orderByComparator != null) {
881 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
882
883 if (orderByConditionFields.length > 0) {
884 query.append(WHERE_AND);
885 }
886
887 for (int i = 0; i < orderByConditionFields.length; i++) {
888 query.append(_ORDER_BY_ENTITY_ALIAS);
889 query.append(orderByConditionFields[i]);
890
891 if ((i + 1) < orderByConditionFields.length) {
892 if (orderByComparator.isAscending() ^ previous) {
893 query.append(WHERE_GREATER_THAN_HAS_NEXT);
894 }
895 else {
896 query.append(WHERE_LESSER_THAN_HAS_NEXT);
897 }
898 }
899 else {
900 if (orderByComparator.isAscending() ^ previous) {
901 query.append(WHERE_GREATER_THAN);
902 }
903 else {
904 query.append(WHERE_LESSER_THAN);
905 }
906 }
907 }
908
909 query.append(ORDER_BY_CLAUSE);
910
911 String[] orderByFields = orderByComparator.getOrderByFields();
912
913 for (int i = 0; i < orderByFields.length; i++) {
914 query.append(_ORDER_BY_ENTITY_ALIAS);
915 query.append(orderByFields[i]);
916
917 if ((i + 1) < orderByFields.length) {
918 if (orderByComparator.isAscending() ^ previous) {
919 query.append(ORDER_BY_ASC_HAS_NEXT);
920 }
921 else {
922 query.append(ORDER_BY_DESC_HAS_NEXT);
923 }
924 }
925 else {
926 if (orderByComparator.isAscending() ^ previous) {
927 query.append(ORDER_BY_ASC);
928 }
929 else {
930 query.append(ORDER_BY_DESC);
931 }
932 }
933 }
934 }
935 else {
936 query.append(OrgGroupRoleModelImpl.ORDER_BY_JPQL);
937 }
938
939 String sql = query.toString();
940
941 Query q = session.createQuery(sql);
942
943 q.setFirstResult(0);
944 q.setMaxResults(2);
945
946 QueryPos qPos = QueryPos.getInstance(q);
947
948 qPos.add(roleId);
949
950 if (orderByComparator != null) {
951 Object[] values = orderByComparator.getOrderByConditionValues(orgGroupRole);
952
953 for (Object value : values) {
954 qPos.add(value);
955 }
956 }
957
958 List<OrgGroupRole> list = q.list();
959
960 if (list.size() == 2) {
961 return list.get(1);
962 }
963 else {
964 return null;
965 }
966 }
967
968
974 public void removeByRoleId(long roleId) throws SystemException {
975 for (OrgGroupRole orgGroupRole : findByRoleId(roleId,
976 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
977 remove(orgGroupRole);
978 }
979 }
980
981
988 public int countByRoleId(long roleId) throws SystemException {
989 FinderPath finderPath = FINDER_PATH_COUNT_BY_ROLEID;
990
991 Object[] finderArgs = new Object[] { roleId };
992
993 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
994 this);
995
996 if (count == null) {
997 StringBundler query = new StringBundler(2);
998
999 query.append(_SQL_COUNT_ORGGROUPROLE_WHERE);
1000
1001 query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
1002
1003 String sql = query.toString();
1004
1005 Session session = null;
1006
1007 try {
1008 session = openSession();
1009
1010 Query q = session.createQuery(sql);
1011
1012 QueryPos qPos = QueryPos.getInstance(q);
1013
1014 qPos.add(roleId);
1015
1016 count = (Long)q.uniqueResult();
1017
1018 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1019 }
1020 catch (Exception e) {
1021 FinderCacheUtil.removeResult(finderPath, finderArgs);
1022
1023 throw processException(e);
1024 }
1025 finally {
1026 closeSession(session);
1027 }
1028 }
1029
1030 return count.intValue();
1031 }
1032
1033 private static final String _FINDER_COLUMN_ROLEID_ROLEID_2 = "orgGroupRole.id.roleId = ?";
1034
1035
1040 public void cacheResult(OrgGroupRole orgGroupRole) {
1041 EntityCacheUtil.putResult(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
1042 OrgGroupRoleImpl.class, orgGroupRole.getPrimaryKey(), orgGroupRole);
1043
1044 orgGroupRole.resetOriginalValues();
1045 }
1046
1047
1052 public void cacheResult(List<OrgGroupRole> orgGroupRoles) {
1053 for (OrgGroupRole orgGroupRole : orgGroupRoles) {
1054 if (EntityCacheUtil.getResult(
1055 OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
1056 OrgGroupRoleImpl.class, orgGroupRole.getPrimaryKey()) == null) {
1057 cacheResult(orgGroupRole);
1058 }
1059 else {
1060 orgGroupRole.resetOriginalValues();
1061 }
1062 }
1063 }
1064
1065
1072 @Override
1073 public void clearCache() {
1074 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
1075 CacheRegistryUtil.clear(OrgGroupRoleImpl.class.getName());
1076 }
1077
1078 EntityCacheUtil.clearCache(OrgGroupRoleImpl.class.getName());
1079
1080 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
1081 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1082 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1083 }
1084
1085
1092 @Override
1093 public void clearCache(OrgGroupRole orgGroupRole) {
1094 EntityCacheUtil.removeResult(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
1095 OrgGroupRoleImpl.class, orgGroupRole.getPrimaryKey());
1096
1097 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1098 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1099 }
1100
1101 @Override
1102 public void clearCache(List<OrgGroupRole> orgGroupRoles) {
1103 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1104 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1105
1106 for (OrgGroupRole orgGroupRole : orgGroupRoles) {
1107 EntityCacheUtil.removeResult(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
1108 OrgGroupRoleImpl.class, orgGroupRole.getPrimaryKey());
1109 }
1110 }
1111
1112
1118 public OrgGroupRole create(OrgGroupRolePK orgGroupRolePK) {
1119 OrgGroupRole orgGroupRole = new OrgGroupRoleImpl();
1120
1121 orgGroupRole.setNew(true);
1122 orgGroupRole.setPrimaryKey(orgGroupRolePK);
1123
1124 return orgGroupRole;
1125 }
1126
1127
1135 public OrgGroupRole remove(OrgGroupRolePK orgGroupRolePK)
1136 throws NoSuchOrgGroupRoleException, SystemException {
1137 return remove((Serializable)orgGroupRolePK);
1138 }
1139
1140
1148 @Override
1149 public OrgGroupRole remove(Serializable primaryKey)
1150 throws NoSuchOrgGroupRoleException, SystemException {
1151 Session session = null;
1152
1153 try {
1154 session = openSession();
1155
1156 OrgGroupRole orgGroupRole = (OrgGroupRole)session.get(OrgGroupRoleImpl.class,
1157 primaryKey);
1158
1159 if (orgGroupRole == null) {
1160 if (_log.isWarnEnabled()) {
1161 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1162 }
1163
1164 throw new NoSuchOrgGroupRoleException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1165 primaryKey);
1166 }
1167
1168 return remove(orgGroupRole);
1169 }
1170 catch (NoSuchOrgGroupRoleException nsee) {
1171 throw nsee;
1172 }
1173 catch (Exception e) {
1174 throw processException(e);
1175 }
1176 finally {
1177 closeSession(session);
1178 }
1179 }
1180
1181 @Override
1182 protected OrgGroupRole removeImpl(OrgGroupRole orgGroupRole)
1183 throws SystemException {
1184 orgGroupRole = toUnwrappedModel(orgGroupRole);
1185
1186 Session session = null;
1187
1188 try {
1189 session = openSession();
1190
1191 if (!session.contains(orgGroupRole)) {
1192 orgGroupRole = (OrgGroupRole)session.get(OrgGroupRoleImpl.class,
1193 orgGroupRole.getPrimaryKeyObj());
1194 }
1195
1196 if (orgGroupRole != null) {
1197 session.delete(orgGroupRole);
1198 }
1199 }
1200 catch (Exception e) {
1201 throw processException(e);
1202 }
1203 finally {
1204 closeSession(session);
1205 }
1206
1207 if (orgGroupRole != null) {
1208 clearCache(orgGroupRole);
1209 }
1210
1211 return orgGroupRole;
1212 }
1213
1214 @Override
1215 public OrgGroupRole updateImpl(
1216 com.liferay.portal.model.OrgGroupRole orgGroupRole)
1217 throws SystemException {
1218 orgGroupRole = toUnwrappedModel(orgGroupRole);
1219
1220 boolean isNew = orgGroupRole.isNew();
1221
1222 OrgGroupRoleModelImpl orgGroupRoleModelImpl = (OrgGroupRoleModelImpl)orgGroupRole;
1223
1224 Session session = null;
1225
1226 try {
1227 session = openSession();
1228
1229 if (orgGroupRole.isNew()) {
1230 session.save(orgGroupRole);
1231
1232 orgGroupRole.setNew(false);
1233 }
1234 else {
1235 session.merge(orgGroupRole);
1236 }
1237 }
1238 catch (Exception e) {
1239 throw processException(e);
1240 }
1241 finally {
1242 closeSession(session);
1243 }
1244
1245 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1246
1247 if (isNew || !OrgGroupRoleModelImpl.COLUMN_BITMASK_ENABLED) {
1248 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1249 }
1250
1251 else {
1252 if ((orgGroupRoleModelImpl.getColumnBitmask() &
1253 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
1254 Object[] args = new Object[] {
1255 Long.valueOf(orgGroupRoleModelImpl.getOriginalGroupId())
1256 };
1257
1258 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
1259 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
1260 args);
1261
1262 args = new Object[] {
1263 Long.valueOf(orgGroupRoleModelImpl.getGroupId())
1264 };
1265
1266 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
1267 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
1268 args);
1269 }
1270
1271 if ((orgGroupRoleModelImpl.getColumnBitmask() &
1272 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID.getColumnBitmask()) != 0) {
1273 Object[] args = new Object[] {
1274 Long.valueOf(orgGroupRoleModelImpl.getOriginalRoleId())
1275 };
1276
1277 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ROLEID, args);
1278 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID,
1279 args);
1280
1281 args = new Object[] {
1282 Long.valueOf(orgGroupRoleModelImpl.getRoleId())
1283 };
1284
1285 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ROLEID, args);
1286 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID,
1287 args);
1288 }
1289 }
1290
1291 EntityCacheUtil.putResult(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
1292 OrgGroupRoleImpl.class, orgGroupRole.getPrimaryKey(), orgGroupRole);
1293
1294 return orgGroupRole;
1295 }
1296
1297 protected OrgGroupRole toUnwrappedModel(OrgGroupRole orgGroupRole) {
1298 if (orgGroupRole instanceof OrgGroupRoleImpl) {
1299 return orgGroupRole;
1300 }
1301
1302 OrgGroupRoleImpl orgGroupRoleImpl = new OrgGroupRoleImpl();
1303
1304 orgGroupRoleImpl.setNew(orgGroupRole.isNew());
1305 orgGroupRoleImpl.setPrimaryKey(orgGroupRole.getPrimaryKey());
1306
1307 orgGroupRoleImpl.setOrganizationId(orgGroupRole.getOrganizationId());
1308 orgGroupRoleImpl.setGroupId(orgGroupRole.getGroupId());
1309 orgGroupRoleImpl.setRoleId(orgGroupRole.getRoleId());
1310
1311 return orgGroupRoleImpl;
1312 }
1313
1314
1322 @Override
1323 public OrgGroupRole findByPrimaryKey(Serializable primaryKey)
1324 throws NoSuchModelException, SystemException {
1325 return findByPrimaryKey((OrgGroupRolePK)primaryKey);
1326 }
1327
1328
1336 public OrgGroupRole findByPrimaryKey(OrgGroupRolePK orgGroupRolePK)
1337 throws NoSuchOrgGroupRoleException, SystemException {
1338 OrgGroupRole orgGroupRole = fetchByPrimaryKey(orgGroupRolePK);
1339
1340 if (orgGroupRole == null) {
1341 if (_log.isWarnEnabled()) {
1342 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + orgGroupRolePK);
1343 }
1344
1345 throw new NoSuchOrgGroupRoleException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1346 orgGroupRolePK);
1347 }
1348
1349 return orgGroupRole;
1350 }
1351
1352
1359 @Override
1360 public OrgGroupRole fetchByPrimaryKey(Serializable primaryKey)
1361 throws SystemException {
1362 return fetchByPrimaryKey((OrgGroupRolePK)primaryKey);
1363 }
1364
1365
1372 public OrgGroupRole fetchByPrimaryKey(OrgGroupRolePK orgGroupRolePK)
1373 throws SystemException {
1374 OrgGroupRole orgGroupRole = (OrgGroupRole)EntityCacheUtil.getResult(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
1375 OrgGroupRoleImpl.class, orgGroupRolePK);
1376
1377 if (orgGroupRole == _nullOrgGroupRole) {
1378 return null;
1379 }
1380
1381 if (orgGroupRole == null) {
1382 Session session = null;
1383
1384 try {
1385 session = openSession();
1386
1387 orgGroupRole = (OrgGroupRole)session.get(OrgGroupRoleImpl.class,
1388 orgGroupRolePK);
1389
1390 if (orgGroupRole != null) {
1391 cacheResult(orgGroupRole);
1392 }
1393 else {
1394 EntityCacheUtil.putResult(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
1395 OrgGroupRoleImpl.class, orgGroupRolePK,
1396 _nullOrgGroupRole);
1397 }
1398 }
1399 catch (Exception e) {
1400 EntityCacheUtil.removeResult(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
1401 OrgGroupRoleImpl.class, orgGroupRolePK);
1402
1403 throw processException(e);
1404 }
1405 finally {
1406 closeSession(session);
1407 }
1408 }
1409
1410 return orgGroupRole;
1411 }
1412
1413
1419 public List<OrgGroupRole> findAll() throws SystemException {
1420 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1421 }
1422
1423
1435 public List<OrgGroupRole> findAll(int start, int end)
1436 throws SystemException {
1437 return findAll(start, end, null);
1438 }
1439
1440
1453 public List<OrgGroupRole> findAll(int start, int end,
1454 OrderByComparator orderByComparator) throws SystemException {
1455 boolean pagination = true;
1456 FinderPath finderPath = null;
1457 Object[] finderArgs = null;
1458
1459 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1460 (orderByComparator == null)) {
1461 pagination = false;
1462 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1463 finderArgs = FINDER_ARGS_EMPTY;
1464 }
1465 else {
1466 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1467 finderArgs = new Object[] { start, end, orderByComparator };
1468 }
1469
1470 List<OrgGroupRole> list = (List<OrgGroupRole>)FinderCacheUtil.getResult(finderPath,
1471 finderArgs, this);
1472
1473 if (list == null) {
1474 StringBundler query = null;
1475 String sql = null;
1476
1477 if (orderByComparator != null) {
1478 query = new StringBundler(2 +
1479 (orderByComparator.getOrderByFields().length * 3));
1480
1481 query.append(_SQL_SELECT_ORGGROUPROLE);
1482
1483 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1484 orderByComparator);
1485
1486 sql = query.toString();
1487 }
1488 else {
1489 sql = _SQL_SELECT_ORGGROUPROLE;
1490
1491 if (pagination) {
1492 sql = sql.concat(OrgGroupRoleModelImpl.ORDER_BY_JPQL);
1493 }
1494 }
1495
1496 Session session = null;
1497
1498 try {
1499 session = openSession();
1500
1501 Query q = session.createQuery(sql);
1502
1503 if (!pagination) {
1504 list = (List<OrgGroupRole>)QueryUtil.list(q, getDialect(),
1505 start, end, false);
1506
1507 Collections.sort(list);
1508
1509 list = new UnmodifiableList<OrgGroupRole>(list);
1510 }
1511 else {
1512 list = (List<OrgGroupRole>)QueryUtil.list(q, getDialect(),
1513 start, end);
1514 }
1515
1516 cacheResult(list);
1517
1518 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1519 }
1520 catch (Exception e) {
1521 FinderCacheUtil.removeResult(finderPath, finderArgs);
1522
1523 throw processException(e);
1524 }
1525 finally {
1526 closeSession(session);
1527 }
1528 }
1529
1530 return list;
1531 }
1532
1533
1538 public void removeAll() throws SystemException {
1539 for (OrgGroupRole orgGroupRole : findAll()) {
1540 remove(orgGroupRole);
1541 }
1542 }
1543
1544
1550 public int countAll() throws SystemException {
1551 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1552 FINDER_ARGS_EMPTY, this);
1553
1554 if (count == null) {
1555 Session session = null;
1556
1557 try {
1558 session = openSession();
1559
1560 Query q = session.createQuery(_SQL_COUNT_ORGGROUPROLE);
1561
1562 count = (Long)q.uniqueResult();
1563
1564 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1565 FINDER_ARGS_EMPTY, count);
1566 }
1567 catch (Exception e) {
1568 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
1569 FINDER_ARGS_EMPTY);
1570
1571 throw processException(e);
1572 }
1573 finally {
1574 closeSession(session);
1575 }
1576 }
1577
1578 return count.intValue();
1579 }
1580
1581
1584 public void afterPropertiesSet() {
1585 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1586 com.liferay.portal.util.PropsUtil.get(
1587 "value.object.listener.com.liferay.portal.model.OrgGroupRole")));
1588
1589 if (listenerClassNames.length > 0) {
1590 try {
1591 List<ModelListener<OrgGroupRole>> listenersList = new ArrayList<ModelListener<OrgGroupRole>>();
1592
1593 for (String listenerClassName : listenerClassNames) {
1594 listenersList.add((ModelListener<OrgGroupRole>)InstanceFactory.newInstance(
1595 listenerClassName));
1596 }
1597
1598 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1599 }
1600 catch (Exception e) {
1601 _log.error(e);
1602 }
1603 }
1604 }
1605
1606 public void destroy() {
1607 EntityCacheUtil.removeCache(OrgGroupRoleImpl.class.getName());
1608 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1609 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1610 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1611 }
1612
1613 private static final String _SQL_SELECT_ORGGROUPROLE = "SELECT orgGroupRole FROM OrgGroupRole orgGroupRole";
1614 private static final String _SQL_SELECT_ORGGROUPROLE_WHERE = "SELECT orgGroupRole FROM OrgGroupRole orgGroupRole WHERE ";
1615 private static final String _SQL_COUNT_ORGGROUPROLE = "SELECT COUNT(orgGroupRole) FROM OrgGroupRole orgGroupRole";
1616 private static final String _SQL_COUNT_ORGGROUPROLE_WHERE = "SELECT COUNT(orgGroupRole) FROM OrgGroupRole orgGroupRole WHERE ";
1617 private static final String _ORDER_BY_ENTITY_ALIAS = "orgGroupRole.";
1618 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No OrgGroupRole exists with the primary key ";
1619 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No OrgGroupRole exists with the key {";
1620 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1621 private static Log _log = LogFactoryUtil.getLog(OrgGroupRolePersistenceImpl.class);
1622 private static OrgGroupRole _nullOrgGroupRole = new OrgGroupRoleImpl() {
1623 @Override
1624 public Object clone() {
1625 return this;
1626 }
1627
1628 @Override
1629 public CacheModel<OrgGroupRole> toCacheModel() {
1630 return _nullOrgGroupRoleCacheModel;
1631 }
1632 };
1633
1634 private static CacheModel<OrgGroupRole> _nullOrgGroupRoleCacheModel = new CacheModel<OrgGroupRole>() {
1635 public OrgGroupRole toEntityModel() {
1636 return _nullOrgGroupRole;
1637 }
1638 };
1639 }