001
014
015 package com.liferay.portal.service.persistence;
016
017 import com.liferay.portal.NoSuchOrgGroupRoleException;
018 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
019 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
020 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderPath;
022 import com.liferay.portal.kernel.dao.orm.Query;
023 import com.liferay.portal.kernel.dao.orm.QueryPos;
024 import com.liferay.portal.kernel.dao.orm.QueryUtil;
025 import com.liferay.portal.kernel.dao.orm.Session;
026 import com.liferay.portal.kernel.exception.SystemException;
027 import com.liferay.portal.kernel.log.Log;
028 import com.liferay.portal.kernel.log.LogFactoryUtil;
029 import com.liferay.portal.kernel.util.GetterUtil;
030 import com.liferay.portal.kernel.util.InstanceFactory;
031 import com.liferay.portal.kernel.util.OrderByComparator;
032 import com.liferay.portal.kernel.util.StringBundler;
033 import com.liferay.portal.kernel.util.StringPool;
034 import com.liferay.portal.kernel.util.StringUtil;
035 import com.liferay.portal.kernel.util.UnmodifiableList;
036 import com.liferay.portal.model.CacheModel;
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
061 public class OrgGroupRolePersistenceImpl extends BasePersistenceImpl<OrgGroupRole>
062 implements OrgGroupRolePersistence {
063
068 public static final String FINDER_CLASS_NAME_ENTITY = OrgGroupRoleImpl.class.getName();
069 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
070 ".List1";
071 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
072 ".List2";
073 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
074 OrgGroupRoleModelImpl.FINDER_CACHE_ENABLED, OrgGroupRoleImpl.class,
075 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
076 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
077 OrgGroupRoleModelImpl.FINDER_CACHE_ENABLED, OrgGroupRoleImpl.class,
078 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
079 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
080 OrgGroupRoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
081 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
082 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
083 OrgGroupRoleModelImpl.FINDER_CACHE_ENABLED, OrgGroupRoleImpl.class,
084 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
085 new String[] {
086 Long.class.getName(),
087
088 Integer.class.getName(), Integer.class.getName(),
089 OrderByComparator.class.getName()
090 });
091 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
092 new FinderPath(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
093 OrgGroupRoleModelImpl.FINDER_CACHE_ENABLED, OrgGroupRoleImpl.class,
094 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
095 new String[] { Long.class.getName() },
096 OrgGroupRoleModelImpl.GROUPID_COLUMN_BITMASK);
097 public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
098 OrgGroupRoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
099 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
100 new String[] { Long.class.getName() });
101
102
109 @Override
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 @Override
129 public List<OrgGroupRole> findByGroupId(long groupId, int start, int end)
130 throws SystemException {
131 return findByGroupId(groupId, start, end, null);
132 }
133
134
148 @Override
149 public List<OrgGroupRole> findByGroupId(long groupId, int start, int end,
150 OrderByComparator orderByComparator) throws SystemException {
151 boolean pagination = true;
152 FinderPath finderPath = null;
153 Object[] finderArgs = null;
154
155 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
156 (orderByComparator == null)) {
157 pagination = false;
158 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
159 finderArgs = new Object[] { groupId };
160 }
161 else {
162 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
163 finderArgs = new Object[] { groupId, start, end, orderByComparator };
164 }
165
166 List<OrgGroupRole> list = (List<OrgGroupRole>)FinderCacheUtil.getResult(finderPath,
167 finderArgs, this);
168
169 if ((list != null) && !list.isEmpty()) {
170 for (OrgGroupRole orgGroupRole : list) {
171 if ((groupId != orgGroupRole.getGroupId())) {
172 list = null;
173
174 break;
175 }
176 }
177 }
178
179 if (list == null) {
180 StringBundler query = null;
181
182 if (orderByComparator != null) {
183 query = new StringBundler(3 +
184 (orderByComparator.getOrderByFields().length * 3));
185 }
186 else {
187 query = new StringBundler(3);
188 }
189
190 query.append(_SQL_SELECT_ORGGROUPROLE_WHERE);
191
192 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
193
194 if (orderByComparator != null) {
195 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
196 orderByComparator);
197 }
198 else
199 if (pagination) {
200 query.append(OrgGroupRoleModelImpl.ORDER_BY_JPQL);
201 }
202
203 String sql = query.toString();
204
205 Session session = null;
206
207 try {
208 session = openSession();
209
210 Query q = session.createQuery(sql);
211
212 QueryPos qPos = QueryPos.getInstance(q);
213
214 qPos.add(groupId);
215
216 if (!pagination) {
217 list = (List<OrgGroupRole>)QueryUtil.list(q, getDialect(),
218 start, end, false);
219
220 Collections.sort(list);
221
222 list = new UnmodifiableList<OrgGroupRole>(list);
223 }
224 else {
225 list = (List<OrgGroupRole>)QueryUtil.list(q, getDialect(),
226 start, end);
227 }
228
229 cacheResult(list);
230
231 FinderCacheUtil.putResult(finderPath, finderArgs, list);
232 }
233 catch (Exception e) {
234 FinderCacheUtil.removeResult(finderPath, finderArgs);
235
236 throw processException(e);
237 }
238 finally {
239 closeSession(session);
240 }
241 }
242
243 return list;
244 }
245
246
255 @Override
256 public OrgGroupRole findByGroupId_First(long groupId,
257 OrderByComparator orderByComparator)
258 throws NoSuchOrgGroupRoleException, SystemException {
259 OrgGroupRole orgGroupRole = fetchByGroupId_First(groupId,
260 orderByComparator);
261
262 if (orgGroupRole != null) {
263 return orgGroupRole;
264 }
265
266 StringBundler msg = new StringBundler(4);
267
268 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
269
270 msg.append("groupId=");
271 msg.append(groupId);
272
273 msg.append(StringPool.CLOSE_CURLY_BRACE);
274
275 throw new NoSuchOrgGroupRoleException(msg.toString());
276 }
277
278
286 @Override
287 public OrgGroupRole fetchByGroupId_First(long groupId,
288 OrderByComparator orderByComparator) throws SystemException {
289 List<OrgGroupRole> list = findByGroupId(groupId, 0, 1, orderByComparator);
290
291 if (!list.isEmpty()) {
292 return list.get(0);
293 }
294
295 return null;
296 }
297
298
307 @Override
308 public OrgGroupRole findByGroupId_Last(long groupId,
309 OrderByComparator orderByComparator)
310 throws NoSuchOrgGroupRoleException, SystemException {
311 OrgGroupRole orgGroupRole = fetchByGroupId_Last(groupId,
312 orderByComparator);
313
314 if (orgGroupRole != null) {
315 return orgGroupRole;
316 }
317
318 StringBundler msg = new StringBundler(4);
319
320 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
321
322 msg.append("groupId=");
323 msg.append(groupId);
324
325 msg.append(StringPool.CLOSE_CURLY_BRACE);
326
327 throw new NoSuchOrgGroupRoleException(msg.toString());
328 }
329
330
338 @Override
339 public OrgGroupRole fetchByGroupId_Last(long groupId,
340 OrderByComparator orderByComparator) throws SystemException {
341 int count = countByGroupId(groupId);
342
343 if (count == 0) {
344 return null;
345 }
346
347 List<OrgGroupRole> list = findByGroupId(groupId, count - 1, count,
348 orderByComparator);
349
350 if (!list.isEmpty()) {
351 return list.get(0);
352 }
353
354 return null;
355 }
356
357
367 @Override
368 public OrgGroupRole[] findByGroupId_PrevAndNext(
369 OrgGroupRolePK orgGroupRolePK, long groupId,
370 OrderByComparator orderByComparator)
371 throws NoSuchOrgGroupRoleException, SystemException {
372 OrgGroupRole orgGroupRole = findByPrimaryKey(orgGroupRolePK);
373
374 Session session = null;
375
376 try {
377 session = openSession();
378
379 OrgGroupRole[] array = new OrgGroupRoleImpl[3];
380
381 array[0] = getByGroupId_PrevAndNext(session, orgGroupRole, groupId,
382 orderByComparator, true);
383
384 array[1] = orgGroupRole;
385
386 array[2] = getByGroupId_PrevAndNext(session, orgGroupRole, groupId,
387 orderByComparator, false);
388
389 return array;
390 }
391 catch (Exception e) {
392 throw processException(e);
393 }
394 finally {
395 closeSession(session);
396 }
397 }
398
399 protected OrgGroupRole getByGroupId_PrevAndNext(Session session,
400 OrgGroupRole orgGroupRole, long groupId,
401 OrderByComparator orderByComparator, boolean previous) {
402 StringBundler query = null;
403
404 if (orderByComparator != null) {
405 query = new StringBundler(6 +
406 (orderByComparator.getOrderByFields().length * 6));
407 }
408 else {
409 query = new StringBundler(3);
410 }
411
412 query.append(_SQL_SELECT_ORGGROUPROLE_WHERE);
413
414 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
415
416 if (orderByComparator != null) {
417 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
418
419 if (orderByConditionFields.length > 0) {
420 query.append(WHERE_AND);
421 }
422
423 for (int i = 0; i < orderByConditionFields.length; i++) {
424 query.append(_ORDER_BY_ENTITY_ALIAS);
425 query.append(orderByConditionFields[i]);
426
427 if ((i + 1) < orderByConditionFields.length) {
428 if (orderByComparator.isAscending() ^ previous) {
429 query.append(WHERE_GREATER_THAN_HAS_NEXT);
430 }
431 else {
432 query.append(WHERE_LESSER_THAN_HAS_NEXT);
433 }
434 }
435 else {
436 if (orderByComparator.isAscending() ^ previous) {
437 query.append(WHERE_GREATER_THAN);
438 }
439 else {
440 query.append(WHERE_LESSER_THAN);
441 }
442 }
443 }
444
445 query.append(ORDER_BY_CLAUSE);
446
447 String[] orderByFields = orderByComparator.getOrderByFields();
448
449 for (int i = 0; i < orderByFields.length; i++) {
450 query.append(_ORDER_BY_ENTITY_ALIAS);
451 query.append(orderByFields[i]);
452
453 if ((i + 1) < orderByFields.length) {
454 if (orderByComparator.isAscending() ^ previous) {
455 query.append(ORDER_BY_ASC_HAS_NEXT);
456 }
457 else {
458 query.append(ORDER_BY_DESC_HAS_NEXT);
459 }
460 }
461 else {
462 if (orderByComparator.isAscending() ^ previous) {
463 query.append(ORDER_BY_ASC);
464 }
465 else {
466 query.append(ORDER_BY_DESC);
467 }
468 }
469 }
470 }
471 else {
472 query.append(OrgGroupRoleModelImpl.ORDER_BY_JPQL);
473 }
474
475 String sql = query.toString();
476
477 Query q = session.createQuery(sql);
478
479 q.setFirstResult(0);
480 q.setMaxResults(2);
481
482 QueryPos qPos = QueryPos.getInstance(q);
483
484 qPos.add(groupId);
485
486 if (orderByComparator != null) {
487 Object[] values = orderByComparator.getOrderByConditionValues(orgGroupRole);
488
489 for (Object value : values) {
490 qPos.add(value);
491 }
492 }
493
494 List<OrgGroupRole> list = q.list();
495
496 if (list.size() == 2) {
497 return list.get(1);
498 }
499 else {
500 return null;
501 }
502 }
503
504
510 @Override
511 public void removeByGroupId(long groupId) throws SystemException {
512 for (OrgGroupRole orgGroupRole : findByGroupId(groupId,
513 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
514 remove(orgGroupRole);
515 }
516 }
517
518
525 @Override
526 public int countByGroupId(long groupId) throws SystemException {
527 FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
528
529 Object[] finderArgs = new Object[] { groupId };
530
531 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
532 this);
533
534 if (count == null) {
535 StringBundler query = new StringBundler(2);
536
537 query.append(_SQL_COUNT_ORGGROUPROLE_WHERE);
538
539 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
540
541 String sql = query.toString();
542
543 Session session = null;
544
545 try {
546 session = openSession();
547
548 Query q = session.createQuery(sql);
549
550 QueryPos qPos = QueryPos.getInstance(q);
551
552 qPos.add(groupId);
553
554 count = (Long)q.uniqueResult();
555
556 FinderCacheUtil.putResult(finderPath, finderArgs, count);
557 }
558 catch (Exception e) {
559 FinderCacheUtil.removeResult(finderPath, finderArgs);
560
561 throw processException(e);
562 }
563 finally {
564 closeSession(session);
565 }
566 }
567
568 return count.intValue();
569 }
570
571 private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "orgGroupRole.id.groupId = ?";
572 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_ROLEID = new FinderPath(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
573 OrgGroupRoleModelImpl.FINDER_CACHE_ENABLED, OrgGroupRoleImpl.class,
574 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByRoleId",
575 new String[] {
576 Long.class.getName(),
577
578 Integer.class.getName(), Integer.class.getName(),
579 OrderByComparator.class.getName()
580 });
581 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID =
582 new FinderPath(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
583 OrgGroupRoleModelImpl.FINDER_CACHE_ENABLED, OrgGroupRoleImpl.class,
584 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByRoleId",
585 new String[] { Long.class.getName() },
586 OrgGroupRoleModelImpl.ROLEID_COLUMN_BITMASK);
587 public static final FinderPath FINDER_PATH_COUNT_BY_ROLEID = new FinderPath(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
588 OrgGroupRoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
589 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByRoleId",
590 new String[] { Long.class.getName() });
591
592
599 @Override
600 public List<OrgGroupRole> findByRoleId(long roleId)
601 throws SystemException {
602 return findByRoleId(roleId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
603 }
604
605
618 @Override
619 public List<OrgGroupRole> findByRoleId(long roleId, int start, int end)
620 throws SystemException {
621 return findByRoleId(roleId, start, end, null);
622 }
623
624
638 @Override
639 public List<OrgGroupRole> findByRoleId(long roleId, int start, int end,
640 OrderByComparator orderByComparator) throws SystemException {
641 boolean pagination = true;
642 FinderPath finderPath = null;
643 Object[] finderArgs = null;
644
645 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
646 (orderByComparator == null)) {
647 pagination = false;
648 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID;
649 finderArgs = new Object[] { roleId };
650 }
651 else {
652 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_ROLEID;
653 finderArgs = new Object[] { roleId, start, end, orderByComparator };
654 }
655
656 List<OrgGroupRole> list = (List<OrgGroupRole>)FinderCacheUtil.getResult(finderPath,
657 finderArgs, this);
658
659 if ((list != null) && !list.isEmpty()) {
660 for (OrgGroupRole orgGroupRole : list) {
661 if ((roleId != orgGroupRole.getRoleId())) {
662 list = null;
663
664 break;
665 }
666 }
667 }
668
669 if (list == null) {
670 StringBundler query = null;
671
672 if (orderByComparator != null) {
673 query = new StringBundler(3 +
674 (orderByComparator.getOrderByFields().length * 3));
675 }
676 else {
677 query = new StringBundler(3);
678 }
679
680 query.append(_SQL_SELECT_ORGGROUPROLE_WHERE);
681
682 query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
683
684 if (orderByComparator != null) {
685 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
686 orderByComparator);
687 }
688 else
689 if (pagination) {
690 query.append(OrgGroupRoleModelImpl.ORDER_BY_JPQL);
691 }
692
693 String sql = query.toString();
694
695 Session session = null;
696
697 try {
698 session = openSession();
699
700 Query q = session.createQuery(sql);
701
702 QueryPos qPos = QueryPos.getInstance(q);
703
704 qPos.add(roleId);
705
706 if (!pagination) {
707 list = (List<OrgGroupRole>)QueryUtil.list(q, getDialect(),
708 start, end, false);
709
710 Collections.sort(list);
711
712 list = new UnmodifiableList<OrgGroupRole>(list);
713 }
714 else {
715 list = (List<OrgGroupRole>)QueryUtil.list(q, getDialect(),
716 start, end);
717 }
718
719 cacheResult(list);
720
721 FinderCacheUtil.putResult(finderPath, finderArgs, list);
722 }
723 catch (Exception e) {
724 FinderCacheUtil.removeResult(finderPath, finderArgs);
725
726 throw processException(e);
727 }
728 finally {
729 closeSession(session);
730 }
731 }
732
733 return list;
734 }
735
736
745 @Override
746 public OrgGroupRole findByRoleId_First(long roleId,
747 OrderByComparator orderByComparator)
748 throws NoSuchOrgGroupRoleException, SystemException {
749 OrgGroupRole orgGroupRole = fetchByRoleId_First(roleId,
750 orderByComparator);
751
752 if (orgGroupRole != null) {
753 return orgGroupRole;
754 }
755
756 StringBundler msg = new StringBundler(4);
757
758 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
759
760 msg.append("roleId=");
761 msg.append(roleId);
762
763 msg.append(StringPool.CLOSE_CURLY_BRACE);
764
765 throw new NoSuchOrgGroupRoleException(msg.toString());
766 }
767
768
776 @Override
777 public OrgGroupRole fetchByRoleId_First(long roleId,
778 OrderByComparator orderByComparator) throws SystemException {
779 List<OrgGroupRole> list = findByRoleId(roleId, 0, 1, orderByComparator);
780
781 if (!list.isEmpty()) {
782 return list.get(0);
783 }
784
785 return null;
786 }
787
788
797 @Override
798 public OrgGroupRole findByRoleId_Last(long roleId,
799 OrderByComparator orderByComparator)
800 throws NoSuchOrgGroupRoleException, SystemException {
801 OrgGroupRole orgGroupRole = fetchByRoleId_Last(roleId, orderByComparator);
802
803 if (orgGroupRole != null) {
804 return orgGroupRole;
805 }
806
807 StringBundler msg = new StringBundler(4);
808
809 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
810
811 msg.append("roleId=");
812 msg.append(roleId);
813
814 msg.append(StringPool.CLOSE_CURLY_BRACE);
815
816 throw new NoSuchOrgGroupRoleException(msg.toString());
817 }
818
819
827 @Override
828 public OrgGroupRole fetchByRoleId_Last(long roleId,
829 OrderByComparator orderByComparator) throws SystemException {
830 int count = countByRoleId(roleId);
831
832 if (count == 0) {
833 return null;
834 }
835
836 List<OrgGroupRole> list = findByRoleId(roleId, count - 1, count,
837 orderByComparator);
838
839 if (!list.isEmpty()) {
840 return list.get(0);
841 }
842
843 return null;
844 }
845
846
856 @Override
857 public OrgGroupRole[] findByRoleId_PrevAndNext(
858 OrgGroupRolePK orgGroupRolePK, long roleId,
859 OrderByComparator orderByComparator)
860 throws NoSuchOrgGroupRoleException, SystemException {
861 OrgGroupRole orgGroupRole = findByPrimaryKey(orgGroupRolePK);
862
863 Session session = null;
864
865 try {
866 session = openSession();
867
868 OrgGroupRole[] array = new OrgGroupRoleImpl[3];
869
870 array[0] = getByRoleId_PrevAndNext(session, orgGroupRole, roleId,
871 orderByComparator, true);
872
873 array[1] = orgGroupRole;
874
875 array[2] = getByRoleId_PrevAndNext(session, orgGroupRole, roleId,
876 orderByComparator, false);
877
878 return array;
879 }
880 catch (Exception e) {
881 throw processException(e);
882 }
883 finally {
884 closeSession(session);
885 }
886 }
887
888 protected OrgGroupRole getByRoleId_PrevAndNext(Session session,
889 OrgGroupRole orgGroupRole, long roleId,
890 OrderByComparator orderByComparator, boolean previous) {
891 StringBundler query = null;
892
893 if (orderByComparator != null) {
894 query = new StringBundler(6 +
895 (orderByComparator.getOrderByFields().length * 6));
896 }
897 else {
898 query = new StringBundler(3);
899 }
900
901 query.append(_SQL_SELECT_ORGGROUPROLE_WHERE);
902
903 query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
904
905 if (orderByComparator != null) {
906 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
907
908 if (orderByConditionFields.length > 0) {
909 query.append(WHERE_AND);
910 }
911
912 for (int i = 0; i < orderByConditionFields.length; i++) {
913 query.append(_ORDER_BY_ENTITY_ALIAS);
914 query.append(orderByConditionFields[i]);
915
916 if ((i + 1) < orderByConditionFields.length) {
917 if (orderByComparator.isAscending() ^ previous) {
918 query.append(WHERE_GREATER_THAN_HAS_NEXT);
919 }
920 else {
921 query.append(WHERE_LESSER_THAN_HAS_NEXT);
922 }
923 }
924 else {
925 if (orderByComparator.isAscending() ^ previous) {
926 query.append(WHERE_GREATER_THAN);
927 }
928 else {
929 query.append(WHERE_LESSER_THAN);
930 }
931 }
932 }
933
934 query.append(ORDER_BY_CLAUSE);
935
936 String[] orderByFields = orderByComparator.getOrderByFields();
937
938 for (int i = 0; i < orderByFields.length; i++) {
939 query.append(_ORDER_BY_ENTITY_ALIAS);
940 query.append(orderByFields[i]);
941
942 if ((i + 1) < orderByFields.length) {
943 if (orderByComparator.isAscending() ^ previous) {
944 query.append(ORDER_BY_ASC_HAS_NEXT);
945 }
946 else {
947 query.append(ORDER_BY_DESC_HAS_NEXT);
948 }
949 }
950 else {
951 if (orderByComparator.isAscending() ^ previous) {
952 query.append(ORDER_BY_ASC);
953 }
954 else {
955 query.append(ORDER_BY_DESC);
956 }
957 }
958 }
959 }
960 else {
961 query.append(OrgGroupRoleModelImpl.ORDER_BY_JPQL);
962 }
963
964 String sql = query.toString();
965
966 Query q = session.createQuery(sql);
967
968 q.setFirstResult(0);
969 q.setMaxResults(2);
970
971 QueryPos qPos = QueryPos.getInstance(q);
972
973 qPos.add(roleId);
974
975 if (orderByComparator != null) {
976 Object[] values = orderByComparator.getOrderByConditionValues(orgGroupRole);
977
978 for (Object value : values) {
979 qPos.add(value);
980 }
981 }
982
983 List<OrgGroupRole> list = q.list();
984
985 if (list.size() == 2) {
986 return list.get(1);
987 }
988 else {
989 return null;
990 }
991 }
992
993
999 @Override
1000 public void removeByRoleId(long roleId) throws SystemException {
1001 for (OrgGroupRole orgGroupRole : findByRoleId(roleId,
1002 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1003 remove(orgGroupRole);
1004 }
1005 }
1006
1007
1014 @Override
1015 public int countByRoleId(long roleId) throws SystemException {
1016 FinderPath finderPath = FINDER_PATH_COUNT_BY_ROLEID;
1017
1018 Object[] finderArgs = new Object[] { roleId };
1019
1020 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1021 this);
1022
1023 if (count == null) {
1024 StringBundler query = new StringBundler(2);
1025
1026 query.append(_SQL_COUNT_ORGGROUPROLE_WHERE);
1027
1028 query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
1029
1030 String sql = query.toString();
1031
1032 Session session = null;
1033
1034 try {
1035 session = openSession();
1036
1037 Query q = session.createQuery(sql);
1038
1039 QueryPos qPos = QueryPos.getInstance(q);
1040
1041 qPos.add(roleId);
1042
1043 count = (Long)q.uniqueResult();
1044
1045 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1046 }
1047 catch (Exception e) {
1048 FinderCacheUtil.removeResult(finderPath, finderArgs);
1049
1050 throw processException(e);
1051 }
1052 finally {
1053 closeSession(session);
1054 }
1055 }
1056
1057 return count.intValue();
1058 }
1059
1060 private static final String _FINDER_COLUMN_ROLEID_ROLEID_2 = "orgGroupRole.id.roleId = ?";
1061
1062
1067 @Override
1068 public void cacheResult(OrgGroupRole orgGroupRole) {
1069 EntityCacheUtil.putResult(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
1070 OrgGroupRoleImpl.class, orgGroupRole.getPrimaryKey(), orgGroupRole);
1071
1072 orgGroupRole.resetOriginalValues();
1073 }
1074
1075
1080 @Override
1081 public void cacheResult(List<OrgGroupRole> orgGroupRoles) {
1082 for (OrgGroupRole orgGroupRole : orgGroupRoles) {
1083 if (EntityCacheUtil.getResult(
1084 OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
1085 OrgGroupRoleImpl.class, orgGroupRole.getPrimaryKey()) == null) {
1086 cacheResult(orgGroupRole);
1087 }
1088 else {
1089 orgGroupRole.resetOriginalValues();
1090 }
1091 }
1092 }
1093
1094
1101 @Override
1102 public void clearCache() {
1103 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
1104 CacheRegistryUtil.clear(OrgGroupRoleImpl.class.getName());
1105 }
1106
1107 EntityCacheUtil.clearCache(OrgGroupRoleImpl.class.getName());
1108
1109 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
1110 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1111 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1112 }
1113
1114
1121 @Override
1122 public void clearCache(OrgGroupRole orgGroupRole) {
1123 EntityCacheUtil.removeResult(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
1124 OrgGroupRoleImpl.class, orgGroupRole.getPrimaryKey());
1125
1126 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1127 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1128 }
1129
1130 @Override
1131 public void clearCache(List<OrgGroupRole> orgGroupRoles) {
1132 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1133 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1134
1135 for (OrgGroupRole orgGroupRole : orgGroupRoles) {
1136 EntityCacheUtil.removeResult(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
1137 OrgGroupRoleImpl.class, orgGroupRole.getPrimaryKey());
1138 }
1139 }
1140
1141
1147 @Override
1148 public OrgGroupRole create(OrgGroupRolePK orgGroupRolePK) {
1149 OrgGroupRole orgGroupRole = new OrgGroupRoleImpl();
1150
1151 orgGroupRole.setNew(true);
1152 orgGroupRole.setPrimaryKey(orgGroupRolePK);
1153
1154 return orgGroupRole;
1155 }
1156
1157
1165 @Override
1166 public OrgGroupRole remove(OrgGroupRolePK orgGroupRolePK)
1167 throws NoSuchOrgGroupRoleException, SystemException {
1168 return remove((Serializable)orgGroupRolePK);
1169 }
1170
1171
1179 @Override
1180 public OrgGroupRole remove(Serializable primaryKey)
1181 throws NoSuchOrgGroupRoleException, SystemException {
1182 Session session = null;
1183
1184 try {
1185 session = openSession();
1186
1187 OrgGroupRole orgGroupRole = (OrgGroupRole)session.get(OrgGroupRoleImpl.class,
1188 primaryKey);
1189
1190 if (orgGroupRole == null) {
1191 if (_log.isWarnEnabled()) {
1192 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1193 }
1194
1195 throw new NoSuchOrgGroupRoleException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1196 primaryKey);
1197 }
1198
1199 return remove(orgGroupRole);
1200 }
1201 catch (NoSuchOrgGroupRoleException nsee) {
1202 throw nsee;
1203 }
1204 catch (Exception e) {
1205 throw processException(e);
1206 }
1207 finally {
1208 closeSession(session);
1209 }
1210 }
1211
1212 @Override
1213 protected OrgGroupRole removeImpl(OrgGroupRole orgGroupRole)
1214 throws SystemException {
1215 orgGroupRole = toUnwrappedModel(orgGroupRole);
1216
1217 Session session = null;
1218
1219 try {
1220 session = openSession();
1221
1222 if (!session.contains(orgGroupRole)) {
1223 orgGroupRole = (OrgGroupRole)session.get(OrgGroupRoleImpl.class,
1224 orgGroupRole.getPrimaryKeyObj());
1225 }
1226
1227 if (orgGroupRole != null) {
1228 session.delete(orgGroupRole);
1229 }
1230 }
1231 catch (Exception e) {
1232 throw processException(e);
1233 }
1234 finally {
1235 closeSession(session);
1236 }
1237
1238 if (orgGroupRole != null) {
1239 clearCache(orgGroupRole);
1240 }
1241
1242 return orgGroupRole;
1243 }
1244
1245 @Override
1246 public OrgGroupRole updateImpl(
1247 com.liferay.portal.model.OrgGroupRole orgGroupRole)
1248 throws SystemException {
1249 orgGroupRole = toUnwrappedModel(orgGroupRole);
1250
1251 boolean isNew = orgGroupRole.isNew();
1252
1253 OrgGroupRoleModelImpl orgGroupRoleModelImpl = (OrgGroupRoleModelImpl)orgGroupRole;
1254
1255 Session session = null;
1256
1257 try {
1258 session = openSession();
1259
1260 if (orgGroupRole.isNew()) {
1261 session.save(orgGroupRole);
1262
1263 orgGroupRole.setNew(false);
1264 }
1265 else {
1266 session.merge(orgGroupRole);
1267 }
1268 }
1269 catch (Exception e) {
1270 throw processException(e);
1271 }
1272 finally {
1273 closeSession(session);
1274 }
1275
1276 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1277
1278 if (isNew || !OrgGroupRoleModelImpl.COLUMN_BITMASK_ENABLED) {
1279 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1280 }
1281
1282 else {
1283 if ((orgGroupRoleModelImpl.getColumnBitmask() &
1284 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
1285 Object[] args = new Object[] {
1286 orgGroupRoleModelImpl.getOriginalGroupId()
1287 };
1288
1289 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
1290 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
1291 args);
1292
1293 args = new Object[] { orgGroupRoleModelImpl.getGroupId() };
1294
1295 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
1296 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
1297 args);
1298 }
1299
1300 if ((orgGroupRoleModelImpl.getColumnBitmask() &
1301 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID.getColumnBitmask()) != 0) {
1302 Object[] args = new Object[] {
1303 orgGroupRoleModelImpl.getOriginalRoleId()
1304 };
1305
1306 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ROLEID, args);
1307 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID,
1308 args);
1309
1310 args = new Object[] { orgGroupRoleModelImpl.getRoleId() };
1311
1312 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ROLEID, args);
1313 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID,
1314 args);
1315 }
1316 }
1317
1318 EntityCacheUtil.putResult(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
1319 OrgGroupRoleImpl.class, orgGroupRole.getPrimaryKey(), orgGroupRole);
1320
1321 return orgGroupRole;
1322 }
1323
1324 protected OrgGroupRole toUnwrappedModel(OrgGroupRole orgGroupRole) {
1325 if (orgGroupRole instanceof OrgGroupRoleImpl) {
1326 return orgGroupRole;
1327 }
1328
1329 OrgGroupRoleImpl orgGroupRoleImpl = new OrgGroupRoleImpl();
1330
1331 orgGroupRoleImpl.setNew(orgGroupRole.isNew());
1332 orgGroupRoleImpl.setPrimaryKey(orgGroupRole.getPrimaryKey());
1333
1334 orgGroupRoleImpl.setOrganizationId(orgGroupRole.getOrganizationId());
1335 orgGroupRoleImpl.setGroupId(orgGroupRole.getGroupId());
1336 orgGroupRoleImpl.setRoleId(orgGroupRole.getRoleId());
1337
1338 return orgGroupRoleImpl;
1339 }
1340
1341
1349 @Override
1350 public OrgGroupRole findByPrimaryKey(Serializable primaryKey)
1351 throws NoSuchOrgGroupRoleException, SystemException {
1352 OrgGroupRole orgGroupRole = fetchByPrimaryKey(primaryKey);
1353
1354 if (orgGroupRole == null) {
1355 if (_log.isWarnEnabled()) {
1356 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1357 }
1358
1359 throw new NoSuchOrgGroupRoleException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1360 primaryKey);
1361 }
1362
1363 return orgGroupRole;
1364 }
1365
1366
1374 @Override
1375 public OrgGroupRole findByPrimaryKey(OrgGroupRolePK orgGroupRolePK)
1376 throws NoSuchOrgGroupRoleException, SystemException {
1377 return findByPrimaryKey((Serializable)orgGroupRolePK);
1378 }
1379
1380
1387 @Override
1388 public OrgGroupRole fetchByPrimaryKey(Serializable primaryKey)
1389 throws SystemException {
1390 OrgGroupRole orgGroupRole = (OrgGroupRole)EntityCacheUtil.getResult(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
1391 OrgGroupRoleImpl.class, primaryKey);
1392
1393 if (orgGroupRole == _nullOrgGroupRole) {
1394 return null;
1395 }
1396
1397 if (orgGroupRole == null) {
1398 Session session = null;
1399
1400 try {
1401 session = openSession();
1402
1403 orgGroupRole = (OrgGroupRole)session.get(OrgGroupRoleImpl.class,
1404 primaryKey);
1405
1406 if (orgGroupRole != null) {
1407 cacheResult(orgGroupRole);
1408 }
1409 else {
1410 EntityCacheUtil.putResult(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
1411 OrgGroupRoleImpl.class, primaryKey, _nullOrgGroupRole);
1412 }
1413 }
1414 catch (Exception e) {
1415 EntityCacheUtil.removeResult(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
1416 OrgGroupRoleImpl.class, primaryKey);
1417
1418 throw processException(e);
1419 }
1420 finally {
1421 closeSession(session);
1422 }
1423 }
1424
1425 return orgGroupRole;
1426 }
1427
1428
1435 @Override
1436 public OrgGroupRole fetchByPrimaryKey(OrgGroupRolePK orgGroupRolePK)
1437 throws SystemException {
1438 return fetchByPrimaryKey((Serializable)orgGroupRolePK);
1439 }
1440
1441
1447 @Override
1448 public List<OrgGroupRole> findAll() throws SystemException {
1449 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1450 }
1451
1452
1464 @Override
1465 public List<OrgGroupRole> findAll(int start, int end)
1466 throws SystemException {
1467 return findAll(start, end, null);
1468 }
1469
1470
1483 @Override
1484 public List<OrgGroupRole> findAll(int start, int end,
1485 OrderByComparator orderByComparator) throws SystemException {
1486 boolean pagination = true;
1487 FinderPath finderPath = null;
1488 Object[] finderArgs = null;
1489
1490 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1491 (orderByComparator == null)) {
1492 pagination = false;
1493 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1494 finderArgs = FINDER_ARGS_EMPTY;
1495 }
1496 else {
1497 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1498 finderArgs = new Object[] { start, end, orderByComparator };
1499 }
1500
1501 List<OrgGroupRole> list = (List<OrgGroupRole>)FinderCacheUtil.getResult(finderPath,
1502 finderArgs, this);
1503
1504 if (list == null) {
1505 StringBundler query = null;
1506 String sql = null;
1507
1508 if (orderByComparator != null) {
1509 query = new StringBundler(2 +
1510 (orderByComparator.getOrderByFields().length * 3));
1511
1512 query.append(_SQL_SELECT_ORGGROUPROLE);
1513
1514 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1515 orderByComparator);
1516
1517 sql = query.toString();
1518 }
1519 else {
1520 sql = _SQL_SELECT_ORGGROUPROLE;
1521
1522 if (pagination) {
1523 sql = sql.concat(OrgGroupRoleModelImpl.ORDER_BY_JPQL);
1524 }
1525 }
1526
1527 Session session = null;
1528
1529 try {
1530 session = openSession();
1531
1532 Query q = session.createQuery(sql);
1533
1534 if (!pagination) {
1535 list = (List<OrgGroupRole>)QueryUtil.list(q, getDialect(),
1536 start, end, false);
1537
1538 Collections.sort(list);
1539
1540 list = new UnmodifiableList<OrgGroupRole>(list);
1541 }
1542 else {
1543 list = (List<OrgGroupRole>)QueryUtil.list(q, getDialect(),
1544 start, end);
1545 }
1546
1547 cacheResult(list);
1548
1549 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1550 }
1551 catch (Exception e) {
1552 FinderCacheUtil.removeResult(finderPath, finderArgs);
1553
1554 throw processException(e);
1555 }
1556 finally {
1557 closeSession(session);
1558 }
1559 }
1560
1561 return list;
1562 }
1563
1564
1569 @Override
1570 public void removeAll() throws SystemException {
1571 for (OrgGroupRole orgGroupRole : findAll()) {
1572 remove(orgGroupRole);
1573 }
1574 }
1575
1576
1582 @Override
1583 public int countAll() throws SystemException {
1584 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1585 FINDER_ARGS_EMPTY, this);
1586
1587 if (count == null) {
1588 Session session = null;
1589
1590 try {
1591 session = openSession();
1592
1593 Query q = session.createQuery(_SQL_COUNT_ORGGROUPROLE);
1594
1595 count = (Long)q.uniqueResult();
1596
1597 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1598 FINDER_ARGS_EMPTY, count);
1599 }
1600 catch (Exception e) {
1601 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
1602 FINDER_ARGS_EMPTY);
1603
1604 throw processException(e);
1605 }
1606 finally {
1607 closeSession(session);
1608 }
1609 }
1610
1611 return count.intValue();
1612 }
1613
1614
1617 public void afterPropertiesSet() {
1618 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1619 com.liferay.portal.util.PropsUtil.get(
1620 "value.object.listener.com.liferay.portal.model.OrgGroupRole")));
1621
1622 if (listenerClassNames.length > 0) {
1623 try {
1624 List<ModelListener<OrgGroupRole>> listenersList = new ArrayList<ModelListener<OrgGroupRole>>();
1625
1626 for (String listenerClassName : listenerClassNames) {
1627 listenersList.add((ModelListener<OrgGroupRole>)InstanceFactory.newInstance(
1628 getClassLoader(), listenerClassName));
1629 }
1630
1631 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1632 }
1633 catch (Exception e) {
1634 _log.error(e);
1635 }
1636 }
1637 }
1638
1639 public void destroy() {
1640 EntityCacheUtil.removeCache(OrgGroupRoleImpl.class.getName());
1641 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1642 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1643 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1644 }
1645
1646 private static final String _SQL_SELECT_ORGGROUPROLE = "SELECT orgGroupRole FROM OrgGroupRole orgGroupRole";
1647 private static final String _SQL_SELECT_ORGGROUPROLE_WHERE = "SELECT orgGroupRole FROM OrgGroupRole orgGroupRole WHERE ";
1648 private static final String _SQL_COUNT_ORGGROUPROLE = "SELECT COUNT(orgGroupRole) FROM OrgGroupRole orgGroupRole";
1649 private static final String _SQL_COUNT_ORGGROUPROLE_WHERE = "SELECT COUNT(orgGroupRole) FROM OrgGroupRole orgGroupRole WHERE ";
1650 private static final String _ORDER_BY_ENTITY_ALIAS = "orgGroupRole.";
1651 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No OrgGroupRole exists with the primary key ";
1652 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No OrgGroupRole exists with the key {";
1653 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1654 private static Log _log = LogFactoryUtil.getLog(OrgGroupRolePersistenceImpl.class);
1655 private static OrgGroupRole _nullOrgGroupRole = new OrgGroupRoleImpl() {
1656 @Override
1657 public Object clone() {
1658 return this;
1659 }
1660
1661 @Override
1662 public CacheModel<OrgGroupRole> toCacheModel() {
1663 return _nullOrgGroupRoleCacheModel;
1664 }
1665 };
1666
1667 private static CacheModel<OrgGroupRole> _nullOrgGroupRoleCacheModel = new CacheModel<OrgGroupRole>() {
1668 @Override
1669 public OrgGroupRole toEntityModel() {
1670 return _nullOrgGroupRole;
1671 }
1672 };
1673 }