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