001
014
015 package com.liferay.portal.service.persistence.impl;
016
017 import aQute.bnd.annotation.ProviderType;
018
019 import com.liferay.portal.NoSuchOrgGroupRoleException;
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.log.Log;
029 import com.liferay.portal.kernel.log.LogFactoryUtil;
030 import com.liferay.portal.kernel.util.OrderByComparator;
031 import com.liferay.portal.kernel.util.StringBundler;
032 import com.liferay.portal.kernel.util.StringPool;
033 import com.liferay.portal.model.CacheModel;
034 import com.liferay.portal.model.MVCCModel;
035 import com.liferay.portal.model.OrgGroupRole;
036 import com.liferay.portal.model.impl.OrgGroupRoleImpl;
037 import com.liferay.portal.model.impl.OrgGroupRoleModelImpl;
038 import com.liferay.portal.service.persistence.OrgGroupRolePK;
039 import com.liferay.portal.service.persistence.OrgGroupRolePersistence;
040
041 import java.io.Serializable;
042
043 import java.util.Collections;
044 import java.util.HashMap;
045 import java.util.List;
046 import java.util.Map;
047 import java.util.Set;
048
049
061 @ProviderType
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
109 @Override
110 public List<OrgGroupRole> findByGroupId(long groupId) {
111 return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
112 }
113
114
126 @Override
127 public List<OrgGroupRole> findByGroupId(long groupId, int start, int end) {
128 return findByGroupId(groupId, start, end, null);
129 }
130
131
144 @Override
145 public List<OrgGroupRole> findByGroupId(long groupId, int start, int end,
146 OrderByComparator<OrgGroupRole> orderByComparator) {
147 boolean pagination = true;
148 FinderPath finderPath = null;
149 Object[] finderArgs = null;
150
151 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
152 (orderByComparator == null)) {
153 pagination = false;
154 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
155 finderArgs = new Object[] { groupId };
156 }
157 else {
158 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
159 finderArgs = new Object[] { groupId, start, end, orderByComparator };
160 }
161
162 List<OrgGroupRole> list = (List<OrgGroupRole>)FinderCacheUtil.getResult(finderPath,
163 finderArgs, this);
164
165 if ((list != null) && !list.isEmpty()) {
166 for (OrgGroupRole orgGroupRole : list) {
167 if ((groupId != orgGroupRole.getGroupId())) {
168 list = null;
169
170 break;
171 }
172 }
173 }
174
175 if (list == null) {
176 StringBundler query = null;
177
178 if (orderByComparator != null) {
179 query = new StringBundler(3 +
180 (orderByComparator.getOrderByFields().length * 3));
181 }
182 else {
183 query = new StringBundler(3);
184 }
185
186 query.append(_SQL_SELECT_ORGGROUPROLE_WHERE);
187
188 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
189
190 if (orderByComparator != null) {
191 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
192 orderByComparator);
193 }
194 else
195 if (pagination) {
196 query.append(OrgGroupRoleModelImpl.ORDER_BY_JPQL);
197 }
198
199 String sql = query.toString();
200
201 Session session = null;
202
203 try {
204 session = openSession();
205
206 Query q = session.createQuery(sql);
207
208 QueryPos qPos = QueryPos.getInstance(q);
209
210 qPos.add(groupId);
211
212 if (!pagination) {
213 list = (List<OrgGroupRole>)QueryUtil.list(q, getDialect(),
214 start, end, false);
215
216 Collections.sort(list);
217
218 list = Collections.unmodifiableList(list);
219 }
220 else {
221 list = (List<OrgGroupRole>)QueryUtil.list(q, getDialect(),
222 start, end);
223 }
224
225 cacheResult(list);
226
227 FinderCacheUtil.putResult(finderPath, finderArgs, list);
228 }
229 catch (Exception e) {
230 FinderCacheUtil.removeResult(finderPath, finderArgs);
231
232 throw processException(e);
233 }
234 finally {
235 closeSession(session);
236 }
237 }
238
239 return list;
240 }
241
242
250 @Override
251 public OrgGroupRole findByGroupId_First(long groupId,
252 OrderByComparator<OrgGroupRole> orderByComparator)
253 throws NoSuchOrgGroupRoleException {
254 OrgGroupRole orgGroupRole = fetchByGroupId_First(groupId,
255 orderByComparator);
256
257 if (orgGroupRole != null) {
258 return orgGroupRole;
259 }
260
261 StringBundler msg = new StringBundler(4);
262
263 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
264
265 msg.append("groupId=");
266 msg.append(groupId);
267
268 msg.append(StringPool.CLOSE_CURLY_BRACE);
269
270 throw new NoSuchOrgGroupRoleException(msg.toString());
271 }
272
273
280 @Override
281 public OrgGroupRole fetchByGroupId_First(long groupId,
282 OrderByComparator<OrgGroupRole> orderByComparator) {
283 List<OrgGroupRole> list = findByGroupId(groupId, 0, 1, orderByComparator);
284
285 if (!list.isEmpty()) {
286 return list.get(0);
287 }
288
289 return null;
290 }
291
292
300 @Override
301 public OrgGroupRole findByGroupId_Last(long groupId,
302 OrderByComparator<OrgGroupRole> orderByComparator)
303 throws NoSuchOrgGroupRoleException {
304 OrgGroupRole orgGroupRole = fetchByGroupId_Last(groupId,
305 orderByComparator);
306
307 if (orgGroupRole != null) {
308 return orgGroupRole;
309 }
310
311 StringBundler msg = new StringBundler(4);
312
313 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
314
315 msg.append("groupId=");
316 msg.append(groupId);
317
318 msg.append(StringPool.CLOSE_CURLY_BRACE);
319
320 throw new NoSuchOrgGroupRoleException(msg.toString());
321 }
322
323
330 @Override
331 public OrgGroupRole fetchByGroupId_Last(long groupId,
332 OrderByComparator<OrgGroupRole> orderByComparator) {
333 int count = countByGroupId(groupId);
334
335 if (count == 0) {
336 return null;
337 }
338
339 List<OrgGroupRole> list = findByGroupId(groupId, count - 1, count,
340 orderByComparator);
341
342 if (!list.isEmpty()) {
343 return list.get(0);
344 }
345
346 return null;
347 }
348
349
358 @Override
359 public OrgGroupRole[] findByGroupId_PrevAndNext(
360 OrgGroupRolePK orgGroupRolePK, long groupId,
361 OrderByComparator<OrgGroupRole> orderByComparator)
362 throws NoSuchOrgGroupRoleException {
363 OrgGroupRole orgGroupRole = findByPrimaryKey(orgGroupRolePK);
364
365 Session session = null;
366
367 try {
368 session = openSession();
369
370 OrgGroupRole[] array = new OrgGroupRoleImpl[3];
371
372 array[0] = getByGroupId_PrevAndNext(session, orgGroupRole, groupId,
373 orderByComparator, true);
374
375 array[1] = orgGroupRole;
376
377 array[2] = getByGroupId_PrevAndNext(session, orgGroupRole, groupId,
378 orderByComparator, false);
379
380 return array;
381 }
382 catch (Exception e) {
383 throw processException(e);
384 }
385 finally {
386 closeSession(session);
387 }
388 }
389
390 protected OrgGroupRole getByGroupId_PrevAndNext(Session session,
391 OrgGroupRole orgGroupRole, long groupId,
392 OrderByComparator<OrgGroupRole> orderByComparator, boolean previous) {
393 StringBundler query = null;
394
395 if (orderByComparator != null) {
396 query = new StringBundler(6 +
397 (orderByComparator.getOrderByFields().length * 6));
398 }
399 else {
400 query = new StringBundler(3);
401 }
402
403 query.append(_SQL_SELECT_ORGGROUPROLE_WHERE);
404
405 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
406
407 if (orderByComparator != null) {
408 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
409
410 if (orderByConditionFields.length > 0) {
411 query.append(WHERE_AND);
412 }
413
414 for (int i = 0; i < orderByConditionFields.length; i++) {
415 query.append(_ORDER_BY_ENTITY_ALIAS);
416 query.append(orderByConditionFields[i]);
417
418 if ((i + 1) < orderByConditionFields.length) {
419 if (orderByComparator.isAscending() ^ previous) {
420 query.append(WHERE_GREATER_THAN_HAS_NEXT);
421 }
422 else {
423 query.append(WHERE_LESSER_THAN_HAS_NEXT);
424 }
425 }
426 else {
427 if (orderByComparator.isAscending() ^ previous) {
428 query.append(WHERE_GREATER_THAN);
429 }
430 else {
431 query.append(WHERE_LESSER_THAN);
432 }
433 }
434 }
435
436 query.append(ORDER_BY_CLAUSE);
437
438 String[] orderByFields = orderByComparator.getOrderByFields();
439
440 for (int i = 0; i < orderByFields.length; i++) {
441 query.append(_ORDER_BY_ENTITY_ALIAS);
442 query.append(orderByFields[i]);
443
444 if ((i + 1) < orderByFields.length) {
445 if (orderByComparator.isAscending() ^ previous) {
446 query.append(ORDER_BY_ASC_HAS_NEXT);
447 }
448 else {
449 query.append(ORDER_BY_DESC_HAS_NEXT);
450 }
451 }
452 else {
453 if (orderByComparator.isAscending() ^ previous) {
454 query.append(ORDER_BY_ASC);
455 }
456 else {
457 query.append(ORDER_BY_DESC);
458 }
459 }
460 }
461 }
462 else {
463 query.append(OrgGroupRoleModelImpl.ORDER_BY_JPQL);
464 }
465
466 String sql = query.toString();
467
468 Query q = session.createQuery(sql);
469
470 q.setFirstResult(0);
471 q.setMaxResults(2);
472
473 QueryPos qPos = QueryPos.getInstance(q);
474
475 qPos.add(groupId);
476
477 if (orderByComparator != null) {
478 Object[] values = orderByComparator.getOrderByConditionValues(orgGroupRole);
479
480 for (Object value : values) {
481 qPos.add(value);
482 }
483 }
484
485 List<OrgGroupRole> list = q.list();
486
487 if (list.size() == 2) {
488 return list.get(1);
489 }
490 else {
491 return null;
492 }
493 }
494
495
500 @Override
501 public void removeByGroupId(long groupId) {
502 for (OrgGroupRole orgGroupRole : findByGroupId(groupId,
503 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
504 remove(orgGroupRole);
505 }
506 }
507
508
514 @Override
515 public int countByGroupId(long groupId) {
516 FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
517
518 Object[] finderArgs = new Object[] { groupId };
519
520 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
521 this);
522
523 if (count == null) {
524 StringBundler query = new StringBundler(2);
525
526 query.append(_SQL_COUNT_ORGGROUPROLE_WHERE);
527
528 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
529
530 String sql = query.toString();
531
532 Session session = null;
533
534 try {
535 session = openSession();
536
537 Query q = session.createQuery(sql);
538
539 QueryPos qPos = QueryPos.getInstance(q);
540
541 qPos.add(groupId);
542
543 count = (Long)q.uniqueResult();
544
545 FinderCacheUtil.putResult(finderPath, finderArgs, count);
546 }
547 catch (Exception e) {
548 FinderCacheUtil.removeResult(finderPath, finderArgs);
549
550 throw processException(e);
551 }
552 finally {
553 closeSession(session);
554 }
555 }
556
557 return count.intValue();
558 }
559
560 private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "orgGroupRole.id.groupId = ?";
561 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_ROLEID = new FinderPath(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
562 OrgGroupRoleModelImpl.FINDER_CACHE_ENABLED, OrgGroupRoleImpl.class,
563 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByRoleId",
564 new String[] {
565 Long.class.getName(),
566
567 Integer.class.getName(), Integer.class.getName(),
568 OrderByComparator.class.getName()
569 });
570 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID =
571 new FinderPath(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
572 OrgGroupRoleModelImpl.FINDER_CACHE_ENABLED, OrgGroupRoleImpl.class,
573 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByRoleId",
574 new String[] { Long.class.getName() },
575 OrgGroupRoleModelImpl.ROLEID_COLUMN_BITMASK);
576 public static final FinderPath FINDER_PATH_COUNT_BY_ROLEID = new FinderPath(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
577 OrgGroupRoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
578 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByRoleId",
579 new String[] { Long.class.getName() });
580
581
587 @Override
588 public List<OrgGroupRole> findByRoleId(long roleId) {
589 return findByRoleId(roleId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
590 }
591
592
604 @Override
605 public List<OrgGroupRole> findByRoleId(long roleId, int start, int end) {
606 return findByRoleId(roleId, start, end, null);
607 }
608
609
622 @Override
623 public List<OrgGroupRole> findByRoleId(long roleId, int start, int end,
624 OrderByComparator<OrgGroupRole> orderByComparator) {
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 = Collections.unmodifiableList(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
728 @Override
729 public OrgGroupRole findByRoleId_First(long roleId,
730 OrderByComparator<OrgGroupRole> orderByComparator)
731 throws NoSuchOrgGroupRoleException {
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
758 @Override
759 public OrgGroupRole fetchByRoleId_First(long roleId,
760 OrderByComparator<OrgGroupRole> orderByComparator) {
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
778 @Override
779 public OrgGroupRole findByRoleId_Last(long roleId,
780 OrderByComparator<OrgGroupRole> orderByComparator)
781 throws NoSuchOrgGroupRoleException {
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
807 @Override
808 public OrgGroupRole fetchByRoleId_Last(long roleId,
809 OrderByComparator<OrgGroupRole> orderByComparator) {
810 int count = countByRoleId(roleId);
811
812 if (count == 0) {
813 return null;
814 }
815
816 List<OrgGroupRole> list = findByRoleId(roleId, count - 1, count,
817 orderByComparator);
818
819 if (!list.isEmpty()) {
820 return list.get(0);
821 }
822
823 return null;
824 }
825
826
835 @Override
836 public OrgGroupRole[] findByRoleId_PrevAndNext(
837 OrgGroupRolePK orgGroupRolePK, long roleId,
838 OrderByComparator<OrgGroupRole> orderByComparator)
839 throws NoSuchOrgGroupRoleException {
840 OrgGroupRole orgGroupRole = findByPrimaryKey(orgGroupRolePK);
841
842 Session session = null;
843
844 try {
845 session = openSession();
846
847 OrgGroupRole[] array = new OrgGroupRoleImpl[3];
848
849 array[0] = getByRoleId_PrevAndNext(session, orgGroupRole, roleId,
850 orderByComparator, true);
851
852 array[1] = orgGroupRole;
853
854 array[2] = getByRoleId_PrevAndNext(session, orgGroupRole, roleId,
855 orderByComparator, false);
856
857 return array;
858 }
859 catch (Exception e) {
860 throw processException(e);
861 }
862 finally {
863 closeSession(session);
864 }
865 }
866
867 protected OrgGroupRole getByRoleId_PrevAndNext(Session session,
868 OrgGroupRole orgGroupRole, long roleId,
869 OrderByComparator<OrgGroupRole> orderByComparator, boolean previous) {
870 StringBundler query = null;
871
872 if (orderByComparator != null) {
873 query = new StringBundler(6 +
874 (orderByComparator.getOrderByFields().length * 6));
875 }
876 else {
877 query = new StringBundler(3);
878 }
879
880 query.append(_SQL_SELECT_ORGGROUPROLE_WHERE);
881
882 query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
883
884 if (orderByComparator != null) {
885 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
886
887 if (orderByConditionFields.length > 0) {
888 query.append(WHERE_AND);
889 }
890
891 for (int i = 0; i < orderByConditionFields.length; i++) {
892 query.append(_ORDER_BY_ENTITY_ALIAS);
893 query.append(orderByConditionFields[i]);
894
895 if ((i + 1) < orderByConditionFields.length) {
896 if (orderByComparator.isAscending() ^ previous) {
897 query.append(WHERE_GREATER_THAN_HAS_NEXT);
898 }
899 else {
900 query.append(WHERE_LESSER_THAN_HAS_NEXT);
901 }
902 }
903 else {
904 if (orderByComparator.isAscending() ^ previous) {
905 query.append(WHERE_GREATER_THAN);
906 }
907 else {
908 query.append(WHERE_LESSER_THAN);
909 }
910 }
911 }
912
913 query.append(ORDER_BY_CLAUSE);
914
915 String[] orderByFields = orderByComparator.getOrderByFields();
916
917 for (int i = 0; i < orderByFields.length; i++) {
918 query.append(_ORDER_BY_ENTITY_ALIAS);
919 query.append(orderByFields[i]);
920
921 if ((i + 1) < orderByFields.length) {
922 if (orderByComparator.isAscending() ^ previous) {
923 query.append(ORDER_BY_ASC_HAS_NEXT);
924 }
925 else {
926 query.append(ORDER_BY_DESC_HAS_NEXT);
927 }
928 }
929 else {
930 if (orderByComparator.isAscending() ^ previous) {
931 query.append(ORDER_BY_ASC);
932 }
933 else {
934 query.append(ORDER_BY_DESC);
935 }
936 }
937 }
938 }
939 else {
940 query.append(OrgGroupRoleModelImpl.ORDER_BY_JPQL);
941 }
942
943 String sql = query.toString();
944
945 Query q = session.createQuery(sql);
946
947 q.setFirstResult(0);
948 q.setMaxResults(2);
949
950 QueryPos qPos = QueryPos.getInstance(q);
951
952 qPos.add(roleId);
953
954 if (orderByComparator != null) {
955 Object[] values = orderByComparator.getOrderByConditionValues(orgGroupRole);
956
957 for (Object value : values) {
958 qPos.add(value);
959 }
960 }
961
962 List<OrgGroupRole> list = q.list();
963
964 if (list.size() == 2) {
965 return list.get(1);
966 }
967 else {
968 return null;
969 }
970 }
971
972
977 @Override
978 public void removeByRoleId(long roleId) {
979 for (OrgGroupRole orgGroupRole : findByRoleId(roleId,
980 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
981 remove(orgGroupRole);
982 }
983 }
984
985
991 @Override
992 public int countByRoleId(long roleId) {
993 FinderPath finderPath = FINDER_PATH_COUNT_BY_ROLEID;
994
995 Object[] finderArgs = new Object[] { roleId };
996
997 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
998 this);
999
1000 if (count == null) {
1001 StringBundler query = new StringBundler(2);
1002
1003 query.append(_SQL_COUNT_ORGGROUPROLE_WHERE);
1004
1005 query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
1006
1007 String sql = query.toString();
1008
1009 Session session = null;
1010
1011 try {
1012 session = openSession();
1013
1014 Query q = session.createQuery(sql);
1015
1016 QueryPos qPos = QueryPos.getInstance(q);
1017
1018 qPos.add(roleId);
1019
1020 count = (Long)q.uniqueResult();
1021
1022 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1023 }
1024 catch (Exception e) {
1025 FinderCacheUtil.removeResult(finderPath, finderArgs);
1026
1027 throw processException(e);
1028 }
1029 finally {
1030 closeSession(session);
1031 }
1032 }
1033
1034 return count.intValue();
1035 }
1036
1037 private static final String _FINDER_COLUMN_ROLEID_ROLEID_2 = "orgGroupRole.id.roleId = ?";
1038
1039 public OrgGroupRolePersistenceImpl() {
1040 setModelClass(OrgGroupRole.class);
1041 }
1042
1043
1048 @Override
1049 public void cacheResult(OrgGroupRole orgGroupRole) {
1050 EntityCacheUtil.putResult(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
1051 OrgGroupRoleImpl.class, orgGroupRole.getPrimaryKey(), orgGroupRole);
1052
1053 orgGroupRole.resetOriginalValues();
1054 }
1055
1056
1061 @Override
1062 public void cacheResult(List<OrgGroupRole> orgGroupRoles) {
1063 for (OrgGroupRole orgGroupRole : orgGroupRoles) {
1064 if (EntityCacheUtil.getResult(
1065 OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
1066 OrgGroupRoleImpl.class, orgGroupRole.getPrimaryKey()) == null) {
1067 cacheResult(orgGroupRole);
1068 }
1069 else {
1070 orgGroupRole.resetOriginalValues();
1071 }
1072 }
1073 }
1074
1075
1082 @Override
1083 public void clearCache() {
1084 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
1085 CacheRegistryUtil.clear(OrgGroupRoleImpl.class.getName());
1086 }
1087
1088 EntityCacheUtil.clearCache(OrgGroupRoleImpl.class);
1089
1090 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
1091 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1092 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1093 }
1094
1095
1102 @Override
1103 public void clearCache(OrgGroupRole orgGroupRole) {
1104 EntityCacheUtil.removeResult(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
1105 OrgGroupRoleImpl.class, orgGroupRole.getPrimaryKey());
1106
1107 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1108 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1109 }
1110
1111 @Override
1112 public void clearCache(List<OrgGroupRole> orgGroupRoles) {
1113 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1114 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1115
1116 for (OrgGroupRole orgGroupRole : orgGroupRoles) {
1117 EntityCacheUtil.removeResult(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
1118 OrgGroupRoleImpl.class, orgGroupRole.getPrimaryKey());
1119 }
1120 }
1121
1122
1128 @Override
1129 public OrgGroupRole create(OrgGroupRolePK orgGroupRolePK) {
1130 OrgGroupRole orgGroupRole = new OrgGroupRoleImpl();
1131
1132 orgGroupRole.setNew(true);
1133 orgGroupRole.setPrimaryKey(orgGroupRolePK);
1134
1135 return orgGroupRole;
1136 }
1137
1138
1145 @Override
1146 public OrgGroupRole remove(OrgGroupRolePK orgGroupRolePK)
1147 throws NoSuchOrgGroupRoleException {
1148 return remove((Serializable)orgGroupRolePK);
1149 }
1150
1151
1158 @Override
1159 public OrgGroupRole remove(Serializable primaryKey)
1160 throws NoSuchOrgGroupRoleException {
1161 Session session = null;
1162
1163 try {
1164 session = openSession();
1165
1166 OrgGroupRole orgGroupRole = (OrgGroupRole)session.get(OrgGroupRoleImpl.class,
1167 primaryKey);
1168
1169 if (orgGroupRole == null) {
1170 if (_log.isWarnEnabled()) {
1171 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1172 }
1173
1174 throw new NoSuchOrgGroupRoleException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1175 primaryKey);
1176 }
1177
1178 return remove(orgGroupRole);
1179 }
1180 catch (NoSuchOrgGroupRoleException nsee) {
1181 throw nsee;
1182 }
1183 catch (Exception e) {
1184 throw processException(e);
1185 }
1186 finally {
1187 closeSession(session);
1188 }
1189 }
1190
1191 @Override
1192 protected OrgGroupRole removeImpl(OrgGroupRole orgGroupRole) {
1193 orgGroupRole = toUnwrappedModel(orgGroupRole);
1194
1195 Session session = null;
1196
1197 try {
1198 session = openSession();
1199
1200 if (!session.contains(orgGroupRole)) {
1201 orgGroupRole = (OrgGroupRole)session.get(OrgGroupRoleImpl.class,
1202 orgGroupRole.getPrimaryKeyObj());
1203 }
1204
1205 if (orgGroupRole != null) {
1206 session.delete(orgGroupRole);
1207 }
1208 }
1209 catch (Exception e) {
1210 throw processException(e);
1211 }
1212 finally {
1213 closeSession(session);
1214 }
1215
1216 if (orgGroupRole != null) {
1217 clearCache(orgGroupRole);
1218 }
1219
1220 return orgGroupRole;
1221 }
1222
1223 @Override
1224 public OrgGroupRole updateImpl(
1225 com.liferay.portal.model.OrgGroupRole orgGroupRole) {
1226 orgGroupRole = toUnwrappedModel(orgGroupRole);
1227
1228 boolean isNew = orgGroupRole.isNew();
1229
1230 OrgGroupRoleModelImpl orgGroupRoleModelImpl = (OrgGroupRoleModelImpl)orgGroupRole;
1231
1232 Session session = null;
1233
1234 try {
1235 session = openSession();
1236
1237 if (orgGroupRole.isNew()) {
1238 session.save(orgGroupRole);
1239
1240 orgGroupRole.setNew(false);
1241 }
1242 else {
1243 session.merge(orgGroupRole);
1244 }
1245 }
1246 catch (Exception e) {
1247 throw processException(e);
1248 }
1249 finally {
1250 closeSession(session);
1251 }
1252
1253 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1254
1255 if (isNew || !OrgGroupRoleModelImpl.COLUMN_BITMASK_ENABLED) {
1256 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1257 }
1258
1259 else {
1260 if ((orgGroupRoleModelImpl.getColumnBitmask() &
1261 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
1262 Object[] args = new Object[] {
1263 orgGroupRoleModelImpl.getOriginalGroupId()
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 args = new Object[] { orgGroupRoleModelImpl.getGroupId() };
1271
1272 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
1273 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
1274 args);
1275 }
1276
1277 if ((orgGroupRoleModelImpl.getColumnBitmask() &
1278 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID.getColumnBitmask()) != 0) {
1279 Object[] args = new Object[] {
1280 orgGroupRoleModelImpl.getOriginalRoleId()
1281 };
1282
1283 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ROLEID, args);
1284 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID,
1285 args);
1286
1287 args = new Object[] { orgGroupRoleModelImpl.getRoleId() };
1288
1289 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ROLEID, args);
1290 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID,
1291 args);
1292 }
1293 }
1294
1295 EntityCacheUtil.putResult(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
1296 OrgGroupRoleImpl.class, orgGroupRole.getPrimaryKey(), orgGroupRole,
1297 false);
1298
1299 orgGroupRole.resetOriginalValues();
1300
1301 return orgGroupRole;
1302 }
1303
1304 protected OrgGroupRole toUnwrappedModel(OrgGroupRole orgGroupRole) {
1305 if (orgGroupRole instanceof OrgGroupRoleImpl) {
1306 return orgGroupRole;
1307 }
1308
1309 OrgGroupRoleImpl orgGroupRoleImpl = new OrgGroupRoleImpl();
1310
1311 orgGroupRoleImpl.setNew(orgGroupRole.isNew());
1312 orgGroupRoleImpl.setPrimaryKey(orgGroupRole.getPrimaryKey());
1313
1314 orgGroupRoleImpl.setMvccVersion(orgGroupRole.getMvccVersion());
1315 orgGroupRoleImpl.setOrganizationId(orgGroupRole.getOrganizationId());
1316 orgGroupRoleImpl.setGroupId(orgGroupRole.getGroupId());
1317 orgGroupRoleImpl.setRoleId(orgGroupRole.getRoleId());
1318
1319 return orgGroupRoleImpl;
1320 }
1321
1322
1329 @Override
1330 public OrgGroupRole findByPrimaryKey(Serializable primaryKey)
1331 throws NoSuchOrgGroupRoleException {
1332 OrgGroupRole orgGroupRole = fetchByPrimaryKey(primaryKey);
1333
1334 if (orgGroupRole == null) {
1335 if (_log.isWarnEnabled()) {
1336 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1337 }
1338
1339 throw new NoSuchOrgGroupRoleException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1340 primaryKey);
1341 }
1342
1343 return orgGroupRole;
1344 }
1345
1346
1353 @Override
1354 public OrgGroupRole findByPrimaryKey(OrgGroupRolePK orgGroupRolePK)
1355 throws NoSuchOrgGroupRoleException {
1356 return findByPrimaryKey((Serializable)orgGroupRolePK);
1357 }
1358
1359
1365 @Override
1366 public OrgGroupRole fetchByPrimaryKey(Serializable primaryKey) {
1367 OrgGroupRole orgGroupRole = (OrgGroupRole)EntityCacheUtil.getResult(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
1368 OrgGroupRoleImpl.class, primaryKey);
1369
1370 if (orgGroupRole == _nullOrgGroupRole) {
1371 return null;
1372 }
1373
1374 if (orgGroupRole == null) {
1375 Session session = null;
1376
1377 try {
1378 session = openSession();
1379
1380 orgGroupRole = (OrgGroupRole)session.get(OrgGroupRoleImpl.class,
1381 primaryKey);
1382
1383 if (orgGroupRole != null) {
1384 cacheResult(orgGroupRole);
1385 }
1386 else {
1387 EntityCacheUtil.putResult(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
1388 OrgGroupRoleImpl.class, primaryKey, _nullOrgGroupRole);
1389 }
1390 }
1391 catch (Exception e) {
1392 EntityCacheUtil.removeResult(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
1393 OrgGroupRoleImpl.class, primaryKey);
1394
1395 throw processException(e);
1396 }
1397 finally {
1398 closeSession(session);
1399 }
1400 }
1401
1402 return orgGroupRole;
1403 }
1404
1405
1411 @Override
1412 public OrgGroupRole fetchByPrimaryKey(OrgGroupRolePK orgGroupRolePK) {
1413 return fetchByPrimaryKey((Serializable)orgGroupRolePK);
1414 }
1415
1416 @Override
1417 public Map<Serializable, OrgGroupRole> fetchByPrimaryKeys(
1418 Set<Serializable> primaryKeys) {
1419 if (primaryKeys.isEmpty()) {
1420 return Collections.emptyMap();
1421 }
1422
1423 Map<Serializable, OrgGroupRole> map = new HashMap<Serializable, OrgGroupRole>();
1424
1425 for (Serializable primaryKey : primaryKeys) {
1426 OrgGroupRole orgGroupRole = fetchByPrimaryKey(primaryKey);
1427
1428 if (orgGroupRole != null) {
1429 map.put(primaryKey, orgGroupRole);
1430 }
1431 }
1432
1433 return map;
1434 }
1435
1436
1441 @Override
1442 public List<OrgGroupRole> findAll() {
1443 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1444 }
1445
1446
1457 @Override
1458 public List<OrgGroupRole> findAll(int start, int end) {
1459 return findAll(start, end, null);
1460 }
1461
1462
1474 @Override
1475 public List<OrgGroupRole> findAll(int start, int end,
1476 OrderByComparator<OrgGroupRole> orderByComparator) {
1477 boolean pagination = true;
1478 FinderPath finderPath = null;
1479 Object[] finderArgs = null;
1480
1481 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1482 (orderByComparator == null)) {
1483 pagination = false;
1484 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1485 finderArgs = FINDER_ARGS_EMPTY;
1486 }
1487 else {
1488 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1489 finderArgs = new Object[] { start, end, orderByComparator };
1490 }
1491
1492 List<OrgGroupRole> list = (List<OrgGroupRole>)FinderCacheUtil.getResult(finderPath,
1493 finderArgs, this);
1494
1495 if (list == null) {
1496 StringBundler query = null;
1497 String sql = null;
1498
1499 if (orderByComparator != null) {
1500 query = new StringBundler(2 +
1501 (orderByComparator.getOrderByFields().length * 3));
1502
1503 query.append(_SQL_SELECT_ORGGROUPROLE);
1504
1505 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1506 orderByComparator);
1507
1508 sql = query.toString();
1509 }
1510 else {
1511 sql = _SQL_SELECT_ORGGROUPROLE;
1512
1513 if (pagination) {
1514 sql = sql.concat(OrgGroupRoleModelImpl.ORDER_BY_JPQL);
1515 }
1516 }
1517
1518 Session session = null;
1519
1520 try {
1521 session = openSession();
1522
1523 Query q = session.createQuery(sql);
1524
1525 if (!pagination) {
1526 list = (List<OrgGroupRole>)QueryUtil.list(q, getDialect(),
1527 start, end, false);
1528
1529 Collections.sort(list);
1530
1531 list = Collections.unmodifiableList(list);
1532 }
1533 else {
1534 list = (List<OrgGroupRole>)QueryUtil.list(q, getDialect(),
1535 start, end);
1536 }
1537
1538 cacheResult(list);
1539
1540 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1541 }
1542 catch (Exception e) {
1543 FinderCacheUtil.removeResult(finderPath, finderArgs);
1544
1545 throw processException(e);
1546 }
1547 finally {
1548 closeSession(session);
1549 }
1550 }
1551
1552 return list;
1553 }
1554
1555
1559 @Override
1560 public void removeAll() {
1561 for (OrgGroupRole orgGroupRole : findAll()) {
1562 remove(orgGroupRole);
1563 }
1564 }
1565
1566
1571 @Override
1572 public int countAll() {
1573 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1574 FINDER_ARGS_EMPTY, this);
1575
1576 if (count == null) {
1577 Session session = null;
1578
1579 try {
1580 session = openSession();
1581
1582 Query q = session.createQuery(_SQL_COUNT_ORGGROUPROLE);
1583
1584 count = (Long)q.uniqueResult();
1585
1586 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1587 FINDER_ARGS_EMPTY, count);
1588 }
1589 catch (Exception e) {
1590 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
1591 FINDER_ARGS_EMPTY);
1592
1593 throw processException(e);
1594 }
1595 finally {
1596 closeSession(session);
1597 }
1598 }
1599
1600 return count.intValue();
1601 }
1602
1603
1606 public void afterPropertiesSet() {
1607 }
1608
1609 public void destroy() {
1610 EntityCacheUtil.removeCache(OrgGroupRoleImpl.class.getName());
1611 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1612 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1613 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1614 }
1615
1616 private static final String _SQL_SELECT_ORGGROUPROLE = "SELECT orgGroupRole FROM OrgGroupRole orgGroupRole";
1617 private static final String _SQL_SELECT_ORGGROUPROLE_WHERE = "SELECT orgGroupRole FROM OrgGroupRole orgGroupRole WHERE ";
1618 private static final String _SQL_COUNT_ORGGROUPROLE = "SELECT COUNT(orgGroupRole) FROM OrgGroupRole orgGroupRole";
1619 private static final String _SQL_COUNT_ORGGROUPROLE_WHERE = "SELECT COUNT(orgGroupRole) FROM OrgGroupRole orgGroupRole WHERE ";
1620 private static final String _ORDER_BY_ENTITY_ALIAS = "orgGroupRole.";
1621 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No OrgGroupRole exists with the primary key ";
1622 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No OrgGroupRole exists with the key {";
1623 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1624 private static final Log _log = LogFactoryUtil.getLog(OrgGroupRolePersistenceImpl.class);
1625 private static final OrgGroupRole _nullOrgGroupRole = new OrgGroupRoleImpl() {
1626 @Override
1627 public Object clone() {
1628 return this;
1629 }
1630
1631 @Override
1632 public CacheModel<OrgGroupRole> toCacheModel() {
1633 return _nullOrgGroupRoleCacheModel;
1634 }
1635 };
1636
1637 private static final CacheModel<OrgGroupRole> _nullOrgGroupRoleCacheModel = new NullCacheModel();
1638
1639 private static class NullCacheModel implements CacheModel<OrgGroupRole>,
1640 MVCCModel {
1641 @Override
1642 public long getMvccVersion() {
1643 return -1;
1644 }
1645
1646 @Override
1647 public void setMvccVersion(long mvccVersion) {
1648 }
1649
1650 @Override
1651 public OrgGroupRole toEntityModel() {
1652 return _nullOrgGroupRole;
1653 }
1654 }
1655 }