001
014
015 package com.liferay.portal.service.persistence.impl;
016
017 import aQute.bnd.annotation.ProviderType;
018
019 import com.liferay.portal.NoSuchOrganizationException;
020 import com.liferay.portal.kernel.bean.BeanReference;
021 import com.liferay.portal.kernel.dao.orm.EntityCache;
022 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
023 import com.liferay.portal.kernel.dao.orm.FinderCache;
024 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
025 import com.liferay.portal.kernel.dao.orm.FinderPath;
026 import com.liferay.portal.kernel.dao.orm.Query;
027 import com.liferay.portal.kernel.dao.orm.QueryPos;
028 import com.liferay.portal.kernel.dao.orm.QueryUtil;
029 import com.liferay.portal.kernel.dao.orm.SQLQuery;
030 import com.liferay.portal.kernel.dao.orm.Session;
031 import com.liferay.portal.kernel.log.Log;
032 import com.liferay.portal.kernel.log.LogFactoryUtil;
033 import com.liferay.portal.kernel.util.CharPool;
034 import com.liferay.portal.kernel.util.OrderByComparator;
035 import com.liferay.portal.kernel.util.SetUtil;
036 import com.liferay.portal.kernel.util.StringBundler;
037 import com.liferay.portal.kernel.util.StringPool;
038 import com.liferay.portal.kernel.util.StringUtil;
039 import com.liferay.portal.kernel.util.Validator;
040 import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
041 import com.liferay.portal.model.CacheModel;
042 import com.liferay.portal.model.MVCCModel;
043 import com.liferay.portal.model.Organization;
044 import com.liferay.portal.model.impl.OrganizationImpl;
045 import com.liferay.portal.model.impl.OrganizationModelImpl;
046 import com.liferay.portal.security.permission.InlineSQLHelperUtil;
047 import com.liferay.portal.service.ServiceContext;
048 import com.liferay.portal.service.ServiceContextThreadLocal;
049 import com.liferay.portal.service.persistence.CompanyProvider;
050 import com.liferay.portal.service.persistence.GroupPersistence;
051 import com.liferay.portal.service.persistence.OrganizationPersistence;
052 import com.liferay.portal.service.persistence.UserPersistence;
053
054 import java.io.Serializable;
055
056 import java.util.Collections;
057 import java.util.Date;
058 import java.util.HashMap;
059 import java.util.HashSet;
060 import java.util.Iterator;
061 import java.util.List;
062 import java.util.Map;
063 import java.util.Set;
064
065
077 @ProviderType
078 public class OrganizationPersistenceImpl extends BasePersistenceImpl<Organization>
079 implements OrganizationPersistence {
080
085 public static final String FINDER_CLASS_NAME_ENTITY = OrganizationImpl.class.getName();
086 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
087 ".List1";
088 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
089 ".List2";
090 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
091 OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
092 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
093 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
094 OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
095 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
096 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
097 OrganizationModelImpl.FINDER_CACHE_ENABLED, Long.class,
098 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
099 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
100 OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
101 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
102 new String[] {
103 String.class.getName(),
104
105 Integer.class.getName(), Integer.class.getName(),
106 OrderByComparator.class.getName()
107 });
108 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
109 OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
110 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
111 new String[] { String.class.getName() },
112 OrganizationModelImpl.UUID_COLUMN_BITMASK |
113 OrganizationModelImpl.NAME_COLUMN_BITMASK);
114 public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
115 OrganizationModelImpl.FINDER_CACHE_ENABLED, Long.class,
116 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
117 new String[] { String.class.getName() });
118
119
125 @Override
126 public List<Organization> findByUuid(String uuid) {
127 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
128 }
129
130
142 @Override
143 public List<Organization> findByUuid(String uuid, int start, int end) {
144 return findByUuid(uuid, start, end, null);
145 }
146
147
160 @Override
161 public List<Organization> findByUuid(String uuid, int start, int end,
162 OrderByComparator<Organization> orderByComparator) {
163 return findByUuid(uuid, start, end, orderByComparator, true);
164 }
165
166
180 @Override
181 public List<Organization> findByUuid(String uuid, int start, int end,
182 OrderByComparator<Organization> orderByComparator,
183 boolean retrieveFromCache) {
184 boolean pagination = true;
185 FinderPath finderPath = null;
186 Object[] finderArgs = null;
187
188 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
189 (orderByComparator == null)) {
190 pagination = false;
191 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
192 finderArgs = new Object[] { uuid };
193 }
194 else {
195 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
196 finderArgs = new Object[] { uuid, start, end, orderByComparator };
197 }
198
199 List<Organization> list = null;
200
201 if (retrieveFromCache) {
202 list = (List<Organization>)finderCache.getResult(finderPath,
203 finderArgs, this);
204
205 if ((list != null) && !list.isEmpty()) {
206 for (Organization organization : list) {
207 if (!Validator.equals(uuid, organization.getUuid())) {
208 list = null;
209
210 break;
211 }
212 }
213 }
214 }
215
216 if (list == null) {
217 StringBundler query = null;
218
219 if (orderByComparator != null) {
220 query = new StringBundler(3 +
221 (orderByComparator.getOrderByFields().length * 3));
222 }
223 else {
224 query = new StringBundler(3);
225 }
226
227 query.append(_SQL_SELECT_ORGANIZATION_WHERE);
228
229 boolean bindUuid = false;
230
231 if (uuid == null) {
232 query.append(_FINDER_COLUMN_UUID_UUID_1);
233 }
234 else if (uuid.equals(StringPool.BLANK)) {
235 query.append(_FINDER_COLUMN_UUID_UUID_3);
236 }
237 else {
238 bindUuid = true;
239
240 query.append(_FINDER_COLUMN_UUID_UUID_2);
241 }
242
243 if (orderByComparator != null) {
244 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
245 orderByComparator);
246 }
247 else
248 if (pagination) {
249 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
250 }
251
252 String sql = query.toString();
253
254 Session session = null;
255
256 try {
257 session = openSession();
258
259 Query q = session.createQuery(sql);
260
261 QueryPos qPos = QueryPos.getInstance(q);
262
263 if (bindUuid) {
264 qPos.add(uuid);
265 }
266
267 if (!pagination) {
268 list = (List<Organization>)QueryUtil.list(q, getDialect(),
269 start, end, false);
270
271 Collections.sort(list);
272
273 list = Collections.unmodifiableList(list);
274 }
275 else {
276 list = (List<Organization>)QueryUtil.list(q, getDialect(),
277 start, end);
278 }
279
280 cacheResult(list);
281
282 finderCache.putResult(finderPath, finderArgs, list);
283 }
284 catch (Exception e) {
285 finderCache.removeResult(finderPath, finderArgs);
286
287 throw processException(e);
288 }
289 finally {
290 closeSession(session);
291 }
292 }
293
294 return list;
295 }
296
297
305 @Override
306 public Organization findByUuid_First(String uuid,
307 OrderByComparator<Organization> orderByComparator)
308 throws NoSuchOrganizationException {
309 Organization organization = fetchByUuid_First(uuid, orderByComparator);
310
311 if (organization != null) {
312 return organization;
313 }
314
315 StringBundler msg = new StringBundler(4);
316
317 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
318
319 msg.append("uuid=");
320 msg.append(uuid);
321
322 msg.append(StringPool.CLOSE_CURLY_BRACE);
323
324 throw new NoSuchOrganizationException(msg.toString());
325 }
326
327
334 @Override
335 public Organization fetchByUuid_First(String uuid,
336 OrderByComparator<Organization> orderByComparator) {
337 List<Organization> list = findByUuid(uuid, 0, 1, orderByComparator);
338
339 if (!list.isEmpty()) {
340 return list.get(0);
341 }
342
343 return null;
344 }
345
346
354 @Override
355 public Organization findByUuid_Last(String uuid,
356 OrderByComparator<Organization> orderByComparator)
357 throws NoSuchOrganizationException {
358 Organization organization = fetchByUuid_Last(uuid, orderByComparator);
359
360 if (organization != null) {
361 return organization;
362 }
363
364 StringBundler msg = new StringBundler(4);
365
366 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
367
368 msg.append("uuid=");
369 msg.append(uuid);
370
371 msg.append(StringPool.CLOSE_CURLY_BRACE);
372
373 throw new NoSuchOrganizationException(msg.toString());
374 }
375
376
383 @Override
384 public Organization fetchByUuid_Last(String uuid,
385 OrderByComparator<Organization> orderByComparator) {
386 int count = countByUuid(uuid);
387
388 if (count == 0) {
389 return null;
390 }
391
392 List<Organization> list = findByUuid(uuid, count - 1, count,
393 orderByComparator);
394
395 if (!list.isEmpty()) {
396 return list.get(0);
397 }
398
399 return null;
400 }
401
402
411 @Override
412 public Organization[] findByUuid_PrevAndNext(long organizationId,
413 String uuid, OrderByComparator<Organization> orderByComparator)
414 throws NoSuchOrganizationException {
415 Organization organization = findByPrimaryKey(organizationId);
416
417 Session session = null;
418
419 try {
420 session = openSession();
421
422 Organization[] array = new OrganizationImpl[3];
423
424 array[0] = getByUuid_PrevAndNext(session, organization, uuid,
425 orderByComparator, true);
426
427 array[1] = organization;
428
429 array[2] = getByUuid_PrevAndNext(session, organization, uuid,
430 orderByComparator, false);
431
432 return array;
433 }
434 catch (Exception e) {
435 throw processException(e);
436 }
437 finally {
438 closeSession(session);
439 }
440 }
441
442 protected Organization getByUuid_PrevAndNext(Session session,
443 Organization organization, String uuid,
444 OrderByComparator<Organization> orderByComparator, boolean previous) {
445 StringBundler query = null;
446
447 if (orderByComparator != null) {
448 query = new StringBundler(6 +
449 (orderByComparator.getOrderByFields().length * 6));
450 }
451 else {
452 query = new StringBundler(3);
453 }
454
455 query.append(_SQL_SELECT_ORGANIZATION_WHERE);
456
457 boolean bindUuid = false;
458
459 if (uuid == null) {
460 query.append(_FINDER_COLUMN_UUID_UUID_1);
461 }
462 else if (uuid.equals(StringPool.BLANK)) {
463 query.append(_FINDER_COLUMN_UUID_UUID_3);
464 }
465 else {
466 bindUuid = true;
467
468 query.append(_FINDER_COLUMN_UUID_UUID_2);
469 }
470
471 if (orderByComparator != null) {
472 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
473
474 if (orderByConditionFields.length > 0) {
475 query.append(WHERE_AND);
476 }
477
478 for (int i = 0; i < orderByConditionFields.length; i++) {
479 query.append(_ORDER_BY_ENTITY_ALIAS);
480 query.append(orderByConditionFields[i]);
481
482 if ((i + 1) < orderByConditionFields.length) {
483 if (orderByComparator.isAscending() ^ previous) {
484 query.append(WHERE_GREATER_THAN_HAS_NEXT);
485 }
486 else {
487 query.append(WHERE_LESSER_THAN_HAS_NEXT);
488 }
489 }
490 else {
491 if (orderByComparator.isAscending() ^ previous) {
492 query.append(WHERE_GREATER_THAN);
493 }
494 else {
495 query.append(WHERE_LESSER_THAN);
496 }
497 }
498 }
499
500 query.append(ORDER_BY_CLAUSE);
501
502 String[] orderByFields = orderByComparator.getOrderByFields();
503
504 for (int i = 0; i < orderByFields.length; i++) {
505 query.append(_ORDER_BY_ENTITY_ALIAS);
506 query.append(orderByFields[i]);
507
508 if ((i + 1) < orderByFields.length) {
509 if (orderByComparator.isAscending() ^ previous) {
510 query.append(ORDER_BY_ASC_HAS_NEXT);
511 }
512 else {
513 query.append(ORDER_BY_DESC_HAS_NEXT);
514 }
515 }
516 else {
517 if (orderByComparator.isAscending() ^ previous) {
518 query.append(ORDER_BY_ASC);
519 }
520 else {
521 query.append(ORDER_BY_DESC);
522 }
523 }
524 }
525 }
526 else {
527 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
528 }
529
530 String sql = query.toString();
531
532 Query q = session.createQuery(sql);
533
534 q.setFirstResult(0);
535 q.setMaxResults(2);
536
537 QueryPos qPos = QueryPos.getInstance(q);
538
539 if (bindUuid) {
540 qPos.add(uuid);
541 }
542
543 if (orderByComparator != null) {
544 Object[] values = orderByComparator.getOrderByConditionValues(organization);
545
546 for (Object value : values) {
547 qPos.add(value);
548 }
549 }
550
551 List<Organization> list = q.list();
552
553 if (list.size() == 2) {
554 return list.get(1);
555 }
556 else {
557 return null;
558 }
559 }
560
561
567 @Override
568 public List<Organization> filterFindByUuid(String uuid) {
569 return filterFindByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
570 }
571
572
584 @Override
585 public List<Organization> filterFindByUuid(String uuid, int start, int end) {
586 return filterFindByUuid(uuid, start, end, null);
587 }
588
589
602 @Override
603 public List<Organization> filterFindByUuid(String uuid, int start, int end,
604 OrderByComparator<Organization> orderByComparator) {
605 if (!InlineSQLHelperUtil.isEnabled()) {
606 return findByUuid(uuid, start, end, orderByComparator);
607 }
608
609 StringBundler query = null;
610
611 if (orderByComparator != null) {
612 query = new StringBundler(3 +
613 (orderByComparator.getOrderByFields().length * 3));
614 }
615 else {
616 query = new StringBundler(3);
617 }
618
619 if (getDB().isSupportsInlineDistinct()) {
620 query.append(_FILTER_SQL_SELECT_ORGANIZATION_WHERE);
621 }
622 else {
623 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1);
624 }
625
626 boolean bindUuid = false;
627
628 if (uuid == null) {
629 query.append(_FINDER_COLUMN_UUID_UUID_1_SQL);
630 }
631 else if (uuid.equals(StringPool.BLANK)) {
632 query.append(_FINDER_COLUMN_UUID_UUID_3_SQL);
633 }
634 else {
635 bindUuid = true;
636
637 query.append(_FINDER_COLUMN_UUID_UUID_2_SQL);
638 }
639
640 if (!getDB().isSupportsInlineDistinct()) {
641 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2);
642 }
643
644 if (orderByComparator != null) {
645 if (getDB().isSupportsInlineDistinct()) {
646 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
647 orderByComparator, true);
648 }
649 else {
650 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
651 orderByComparator, true);
652 }
653 }
654 else {
655 if (getDB().isSupportsInlineDistinct()) {
656 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
657 }
658 else {
659 query.append(OrganizationModelImpl.ORDER_BY_SQL);
660 }
661 }
662
663 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
664 Organization.class.getName(),
665 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
666
667 Session session = null;
668
669 try {
670 session = openSession();
671
672 SQLQuery q = session.createSynchronizedSQLQuery(sql);
673
674 if (getDB().isSupportsInlineDistinct()) {
675 q.addEntity(_FILTER_ENTITY_ALIAS, OrganizationImpl.class);
676 }
677 else {
678 q.addEntity(_FILTER_ENTITY_TABLE, OrganizationImpl.class);
679 }
680
681 QueryPos qPos = QueryPos.getInstance(q);
682
683 if (bindUuid) {
684 qPos.add(uuid);
685 }
686
687 return (List<Organization>)QueryUtil.list(q, getDialect(), start,
688 end);
689 }
690 catch (Exception e) {
691 throw processException(e);
692 }
693 finally {
694 closeSession(session);
695 }
696 }
697
698
707 @Override
708 public Organization[] filterFindByUuid_PrevAndNext(long organizationId,
709 String uuid, OrderByComparator<Organization> orderByComparator)
710 throws NoSuchOrganizationException {
711 if (!InlineSQLHelperUtil.isEnabled()) {
712 return findByUuid_PrevAndNext(organizationId, uuid,
713 orderByComparator);
714 }
715
716 Organization organization = findByPrimaryKey(organizationId);
717
718 Session session = null;
719
720 try {
721 session = openSession();
722
723 Organization[] array = new OrganizationImpl[3];
724
725 array[0] = filterGetByUuid_PrevAndNext(session, organization, uuid,
726 orderByComparator, true);
727
728 array[1] = organization;
729
730 array[2] = filterGetByUuid_PrevAndNext(session, organization, uuid,
731 orderByComparator, false);
732
733 return array;
734 }
735 catch (Exception e) {
736 throw processException(e);
737 }
738 finally {
739 closeSession(session);
740 }
741 }
742
743 protected Organization filterGetByUuid_PrevAndNext(Session session,
744 Organization organization, String uuid,
745 OrderByComparator<Organization> orderByComparator, boolean previous) {
746 StringBundler query = null;
747
748 if (orderByComparator != null) {
749 query = new StringBundler(6 +
750 (orderByComparator.getOrderByFields().length * 6));
751 }
752 else {
753 query = new StringBundler(3);
754 }
755
756 if (getDB().isSupportsInlineDistinct()) {
757 query.append(_FILTER_SQL_SELECT_ORGANIZATION_WHERE);
758 }
759 else {
760 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1);
761 }
762
763 boolean bindUuid = false;
764
765 if (uuid == null) {
766 query.append(_FINDER_COLUMN_UUID_UUID_1_SQL);
767 }
768 else if (uuid.equals(StringPool.BLANK)) {
769 query.append(_FINDER_COLUMN_UUID_UUID_3_SQL);
770 }
771 else {
772 bindUuid = true;
773
774 query.append(_FINDER_COLUMN_UUID_UUID_2_SQL);
775 }
776
777 if (!getDB().isSupportsInlineDistinct()) {
778 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2);
779 }
780
781 if (orderByComparator != null) {
782 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
783
784 if (orderByConditionFields.length > 0) {
785 query.append(WHERE_AND);
786 }
787
788 for (int i = 0; i < orderByConditionFields.length; i++) {
789 if (getDB().isSupportsInlineDistinct()) {
790 query.append(_ORDER_BY_ENTITY_ALIAS);
791 }
792 else {
793 query.append(_ORDER_BY_ENTITY_TABLE);
794 }
795
796 query.append(orderByConditionFields[i]);
797
798 if ((i + 1) < orderByConditionFields.length) {
799 if (orderByComparator.isAscending() ^ previous) {
800 query.append(WHERE_GREATER_THAN_HAS_NEXT);
801 }
802 else {
803 query.append(WHERE_LESSER_THAN_HAS_NEXT);
804 }
805 }
806 else {
807 if (orderByComparator.isAscending() ^ previous) {
808 query.append(WHERE_GREATER_THAN);
809 }
810 else {
811 query.append(WHERE_LESSER_THAN);
812 }
813 }
814 }
815
816 query.append(ORDER_BY_CLAUSE);
817
818 String[] orderByFields = orderByComparator.getOrderByFields();
819
820 for (int i = 0; i < orderByFields.length; i++) {
821 if (getDB().isSupportsInlineDistinct()) {
822 query.append(_ORDER_BY_ENTITY_ALIAS);
823 }
824 else {
825 query.append(_ORDER_BY_ENTITY_TABLE);
826 }
827
828 query.append(orderByFields[i]);
829
830 if ((i + 1) < orderByFields.length) {
831 if (orderByComparator.isAscending() ^ previous) {
832 query.append(ORDER_BY_ASC_HAS_NEXT);
833 }
834 else {
835 query.append(ORDER_BY_DESC_HAS_NEXT);
836 }
837 }
838 else {
839 if (orderByComparator.isAscending() ^ previous) {
840 query.append(ORDER_BY_ASC);
841 }
842 else {
843 query.append(ORDER_BY_DESC);
844 }
845 }
846 }
847 }
848 else {
849 if (getDB().isSupportsInlineDistinct()) {
850 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
851 }
852 else {
853 query.append(OrganizationModelImpl.ORDER_BY_SQL);
854 }
855 }
856
857 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
858 Organization.class.getName(),
859 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
860
861 SQLQuery q = session.createSynchronizedSQLQuery(sql);
862
863 q.setFirstResult(0);
864 q.setMaxResults(2);
865
866 if (getDB().isSupportsInlineDistinct()) {
867 q.addEntity(_FILTER_ENTITY_ALIAS, OrganizationImpl.class);
868 }
869 else {
870 q.addEntity(_FILTER_ENTITY_TABLE, OrganizationImpl.class);
871 }
872
873 QueryPos qPos = QueryPos.getInstance(q);
874
875 if (bindUuid) {
876 qPos.add(uuid);
877 }
878
879 if (orderByComparator != null) {
880 Object[] values = orderByComparator.getOrderByConditionValues(organization);
881
882 for (Object value : values) {
883 qPos.add(value);
884 }
885 }
886
887 List<Organization> list = q.list();
888
889 if (list.size() == 2) {
890 return list.get(1);
891 }
892 else {
893 return null;
894 }
895 }
896
897
902 @Override
903 public void removeByUuid(String uuid) {
904 for (Organization organization : findByUuid(uuid, QueryUtil.ALL_POS,
905 QueryUtil.ALL_POS, null)) {
906 remove(organization);
907 }
908 }
909
910
916 @Override
917 public int countByUuid(String uuid) {
918 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
919
920 Object[] finderArgs = new Object[] { uuid };
921
922 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
923
924 if (count == null) {
925 StringBundler query = new StringBundler(2);
926
927 query.append(_SQL_COUNT_ORGANIZATION_WHERE);
928
929 boolean bindUuid = false;
930
931 if (uuid == null) {
932 query.append(_FINDER_COLUMN_UUID_UUID_1);
933 }
934 else if (uuid.equals(StringPool.BLANK)) {
935 query.append(_FINDER_COLUMN_UUID_UUID_3);
936 }
937 else {
938 bindUuid = true;
939
940 query.append(_FINDER_COLUMN_UUID_UUID_2);
941 }
942
943 String sql = query.toString();
944
945 Session session = null;
946
947 try {
948 session = openSession();
949
950 Query q = session.createQuery(sql);
951
952 QueryPos qPos = QueryPos.getInstance(q);
953
954 if (bindUuid) {
955 qPos.add(uuid);
956 }
957
958 count = (Long)q.uniqueResult();
959
960 finderCache.putResult(finderPath, finderArgs, count);
961 }
962 catch (Exception e) {
963 finderCache.removeResult(finderPath, finderArgs);
964
965 throw processException(e);
966 }
967 finally {
968 closeSession(session);
969 }
970 }
971
972 return count.intValue();
973 }
974
975
981 @Override
982 public int filterCountByUuid(String uuid) {
983 if (!InlineSQLHelperUtil.isEnabled()) {
984 return countByUuid(uuid);
985 }
986
987 StringBundler query = new StringBundler(2);
988
989 query.append(_FILTER_SQL_COUNT_ORGANIZATION_WHERE);
990
991 boolean bindUuid = false;
992
993 if (uuid == null) {
994 query.append(_FINDER_COLUMN_UUID_UUID_1_SQL);
995 }
996 else if (uuid.equals(StringPool.BLANK)) {
997 query.append(_FINDER_COLUMN_UUID_UUID_3_SQL);
998 }
999 else {
1000 bindUuid = true;
1001
1002 query.append(_FINDER_COLUMN_UUID_UUID_2_SQL);
1003 }
1004
1005 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1006 Organization.class.getName(),
1007 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1008
1009 Session session = null;
1010
1011 try {
1012 session = openSession();
1013
1014 SQLQuery q = session.createSynchronizedSQLQuery(sql);
1015
1016 q.addScalar(COUNT_COLUMN_NAME,
1017 com.liferay.portal.kernel.dao.orm.Type.LONG);
1018
1019 QueryPos qPos = QueryPos.getInstance(q);
1020
1021 if (bindUuid) {
1022 qPos.add(uuid);
1023 }
1024
1025 Long count = (Long)q.uniqueResult();
1026
1027 return count.intValue();
1028 }
1029 catch (Exception e) {
1030 throw processException(e);
1031 }
1032 finally {
1033 closeSession(session);
1034 }
1035 }
1036
1037 private static final String _FINDER_COLUMN_UUID_UUID_1 = "organization.uuid IS NULL";
1038 private static final String _FINDER_COLUMN_UUID_UUID_2 = "organization.uuid = ?";
1039 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(organization.uuid IS NULL OR organization.uuid = '')";
1040 private static final String _FINDER_COLUMN_UUID_UUID_1_SQL = "organization.uuid_ IS NULL";
1041 private static final String _FINDER_COLUMN_UUID_UUID_2_SQL = "organization.uuid_ = ?";
1042 private static final String _FINDER_COLUMN_UUID_UUID_3_SQL = "(organization.uuid_ IS NULL OR organization.uuid_ = '')";
1043 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
1044 OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
1045 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
1046 new String[] {
1047 String.class.getName(), Long.class.getName(),
1048
1049 Integer.class.getName(), Integer.class.getName(),
1050 OrderByComparator.class.getName()
1051 });
1052 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
1053 new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
1054 OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
1055 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
1056 new String[] { String.class.getName(), Long.class.getName() },
1057 OrganizationModelImpl.UUID_COLUMN_BITMASK |
1058 OrganizationModelImpl.COMPANYID_COLUMN_BITMASK |
1059 OrganizationModelImpl.NAME_COLUMN_BITMASK);
1060 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
1061 OrganizationModelImpl.FINDER_CACHE_ENABLED, Long.class,
1062 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
1063 new String[] { String.class.getName(), Long.class.getName() });
1064
1065
1072 @Override
1073 public List<Organization> findByUuid_C(String uuid, long companyId) {
1074 return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
1075 QueryUtil.ALL_POS, null);
1076 }
1077
1078
1091 @Override
1092 public List<Organization> findByUuid_C(String uuid, long companyId,
1093 int start, int end) {
1094 return findByUuid_C(uuid, companyId, start, end, null);
1095 }
1096
1097
1111 @Override
1112 public List<Organization> findByUuid_C(String uuid, long companyId,
1113 int start, int end, OrderByComparator<Organization> orderByComparator) {
1114 return findByUuid_C(uuid, companyId, start, end, orderByComparator, true);
1115 }
1116
1117
1132 @Override
1133 public List<Organization> findByUuid_C(String uuid, long companyId,
1134 int start, int end, OrderByComparator<Organization> orderByComparator,
1135 boolean retrieveFromCache) {
1136 boolean pagination = true;
1137 FinderPath finderPath = null;
1138 Object[] finderArgs = null;
1139
1140 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1141 (orderByComparator == null)) {
1142 pagination = false;
1143 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
1144 finderArgs = new Object[] { uuid, companyId };
1145 }
1146 else {
1147 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
1148 finderArgs = new Object[] {
1149 uuid, companyId,
1150
1151 start, end, orderByComparator
1152 };
1153 }
1154
1155 List<Organization> list = null;
1156
1157 if (retrieveFromCache) {
1158 list = (List<Organization>)finderCache.getResult(finderPath,
1159 finderArgs, this);
1160
1161 if ((list != null) && !list.isEmpty()) {
1162 for (Organization organization : list) {
1163 if (!Validator.equals(uuid, organization.getUuid()) ||
1164 (companyId != organization.getCompanyId())) {
1165 list = null;
1166
1167 break;
1168 }
1169 }
1170 }
1171 }
1172
1173 if (list == null) {
1174 StringBundler query = null;
1175
1176 if (orderByComparator != null) {
1177 query = new StringBundler(4 +
1178 (orderByComparator.getOrderByFields().length * 3));
1179 }
1180 else {
1181 query = new StringBundler(4);
1182 }
1183
1184 query.append(_SQL_SELECT_ORGANIZATION_WHERE);
1185
1186 boolean bindUuid = false;
1187
1188 if (uuid == null) {
1189 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1190 }
1191 else if (uuid.equals(StringPool.BLANK)) {
1192 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1193 }
1194 else {
1195 bindUuid = true;
1196
1197 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1198 }
1199
1200 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1201
1202 if (orderByComparator != null) {
1203 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1204 orderByComparator);
1205 }
1206 else
1207 if (pagination) {
1208 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
1209 }
1210
1211 String sql = query.toString();
1212
1213 Session session = null;
1214
1215 try {
1216 session = openSession();
1217
1218 Query q = session.createQuery(sql);
1219
1220 QueryPos qPos = QueryPos.getInstance(q);
1221
1222 if (bindUuid) {
1223 qPos.add(uuid);
1224 }
1225
1226 qPos.add(companyId);
1227
1228 if (!pagination) {
1229 list = (List<Organization>)QueryUtil.list(q, getDialect(),
1230 start, end, false);
1231
1232 Collections.sort(list);
1233
1234 list = Collections.unmodifiableList(list);
1235 }
1236 else {
1237 list = (List<Organization>)QueryUtil.list(q, getDialect(),
1238 start, end);
1239 }
1240
1241 cacheResult(list);
1242
1243 finderCache.putResult(finderPath, finderArgs, list);
1244 }
1245 catch (Exception e) {
1246 finderCache.removeResult(finderPath, finderArgs);
1247
1248 throw processException(e);
1249 }
1250 finally {
1251 closeSession(session);
1252 }
1253 }
1254
1255 return list;
1256 }
1257
1258
1267 @Override
1268 public Organization findByUuid_C_First(String uuid, long companyId,
1269 OrderByComparator<Organization> orderByComparator)
1270 throws NoSuchOrganizationException {
1271 Organization organization = fetchByUuid_C_First(uuid, companyId,
1272 orderByComparator);
1273
1274 if (organization != null) {
1275 return organization;
1276 }
1277
1278 StringBundler msg = new StringBundler(6);
1279
1280 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1281
1282 msg.append("uuid=");
1283 msg.append(uuid);
1284
1285 msg.append(", companyId=");
1286 msg.append(companyId);
1287
1288 msg.append(StringPool.CLOSE_CURLY_BRACE);
1289
1290 throw new NoSuchOrganizationException(msg.toString());
1291 }
1292
1293
1301 @Override
1302 public Organization fetchByUuid_C_First(String uuid, long companyId,
1303 OrderByComparator<Organization> orderByComparator) {
1304 List<Organization> list = findByUuid_C(uuid, companyId, 0, 1,
1305 orderByComparator);
1306
1307 if (!list.isEmpty()) {
1308 return list.get(0);
1309 }
1310
1311 return null;
1312 }
1313
1314
1323 @Override
1324 public Organization findByUuid_C_Last(String uuid, long companyId,
1325 OrderByComparator<Organization> orderByComparator)
1326 throws NoSuchOrganizationException {
1327 Organization organization = fetchByUuid_C_Last(uuid, companyId,
1328 orderByComparator);
1329
1330 if (organization != null) {
1331 return organization;
1332 }
1333
1334 StringBundler msg = new StringBundler(6);
1335
1336 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1337
1338 msg.append("uuid=");
1339 msg.append(uuid);
1340
1341 msg.append(", companyId=");
1342 msg.append(companyId);
1343
1344 msg.append(StringPool.CLOSE_CURLY_BRACE);
1345
1346 throw new NoSuchOrganizationException(msg.toString());
1347 }
1348
1349
1357 @Override
1358 public Organization fetchByUuid_C_Last(String uuid, long companyId,
1359 OrderByComparator<Organization> orderByComparator) {
1360 int count = countByUuid_C(uuid, companyId);
1361
1362 if (count == 0) {
1363 return null;
1364 }
1365
1366 List<Organization> list = findByUuid_C(uuid, companyId, count - 1,
1367 count, orderByComparator);
1368
1369 if (!list.isEmpty()) {
1370 return list.get(0);
1371 }
1372
1373 return null;
1374 }
1375
1376
1386 @Override
1387 public Organization[] findByUuid_C_PrevAndNext(long organizationId,
1388 String uuid, long companyId,
1389 OrderByComparator<Organization> orderByComparator)
1390 throws NoSuchOrganizationException {
1391 Organization organization = findByPrimaryKey(organizationId);
1392
1393 Session session = null;
1394
1395 try {
1396 session = openSession();
1397
1398 Organization[] array = new OrganizationImpl[3];
1399
1400 array[0] = getByUuid_C_PrevAndNext(session, organization, uuid,
1401 companyId, orderByComparator, true);
1402
1403 array[1] = organization;
1404
1405 array[2] = getByUuid_C_PrevAndNext(session, organization, uuid,
1406 companyId, orderByComparator, false);
1407
1408 return array;
1409 }
1410 catch (Exception e) {
1411 throw processException(e);
1412 }
1413 finally {
1414 closeSession(session);
1415 }
1416 }
1417
1418 protected Organization getByUuid_C_PrevAndNext(Session session,
1419 Organization organization, String uuid, long companyId,
1420 OrderByComparator<Organization> orderByComparator, boolean previous) {
1421 StringBundler query = null;
1422
1423 if (orderByComparator != null) {
1424 query = new StringBundler(6 +
1425 (orderByComparator.getOrderByFields().length * 6));
1426 }
1427 else {
1428 query = new StringBundler(3);
1429 }
1430
1431 query.append(_SQL_SELECT_ORGANIZATION_WHERE);
1432
1433 boolean bindUuid = false;
1434
1435 if (uuid == null) {
1436 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1437 }
1438 else if (uuid.equals(StringPool.BLANK)) {
1439 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1440 }
1441 else {
1442 bindUuid = true;
1443
1444 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1445 }
1446
1447 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1448
1449 if (orderByComparator != null) {
1450 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1451
1452 if (orderByConditionFields.length > 0) {
1453 query.append(WHERE_AND);
1454 }
1455
1456 for (int i = 0; i < orderByConditionFields.length; i++) {
1457 query.append(_ORDER_BY_ENTITY_ALIAS);
1458 query.append(orderByConditionFields[i]);
1459
1460 if ((i + 1) < orderByConditionFields.length) {
1461 if (orderByComparator.isAscending() ^ previous) {
1462 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1463 }
1464 else {
1465 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1466 }
1467 }
1468 else {
1469 if (orderByComparator.isAscending() ^ previous) {
1470 query.append(WHERE_GREATER_THAN);
1471 }
1472 else {
1473 query.append(WHERE_LESSER_THAN);
1474 }
1475 }
1476 }
1477
1478 query.append(ORDER_BY_CLAUSE);
1479
1480 String[] orderByFields = orderByComparator.getOrderByFields();
1481
1482 for (int i = 0; i < orderByFields.length; i++) {
1483 query.append(_ORDER_BY_ENTITY_ALIAS);
1484 query.append(orderByFields[i]);
1485
1486 if ((i + 1) < orderByFields.length) {
1487 if (orderByComparator.isAscending() ^ previous) {
1488 query.append(ORDER_BY_ASC_HAS_NEXT);
1489 }
1490 else {
1491 query.append(ORDER_BY_DESC_HAS_NEXT);
1492 }
1493 }
1494 else {
1495 if (orderByComparator.isAscending() ^ previous) {
1496 query.append(ORDER_BY_ASC);
1497 }
1498 else {
1499 query.append(ORDER_BY_DESC);
1500 }
1501 }
1502 }
1503 }
1504 else {
1505 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
1506 }
1507
1508 String sql = query.toString();
1509
1510 Query q = session.createQuery(sql);
1511
1512 q.setFirstResult(0);
1513 q.setMaxResults(2);
1514
1515 QueryPos qPos = QueryPos.getInstance(q);
1516
1517 if (bindUuid) {
1518 qPos.add(uuid);
1519 }
1520
1521 qPos.add(companyId);
1522
1523 if (orderByComparator != null) {
1524 Object[] values = orderByComparator.getOrderByConditionValues(organization);
1525
1526 for (Object value : values) {
1527 qPos.add(value);
1528 }
1529 }
1530
1531 List<Organization> list = q.list();
1532
1533 if (list.size() == 2) {
1534 return list.get(1);
1535 }
1536 else {
1537 return null;
1538 }
1539 }
1540
1541
1548 @Override
1549 public List<Organization> filterFindByUuid_C(String uuid, long companyId) {
1550 return filterFindByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
1551 QueryUtil.ALL_POS, null);
1552 }
1553
1554
1567 @Override
1568 public List<Organization> filterFindByUuid_C(String uuid, long companyId,
1569 int start, int end) {
1570 return filterFindByUuid_C(uuid, companyId, start, end, null);
1571 }
1572
1573
1587 @Override
1588 public List<Organization> filterFindByUuid_C(String uuid, long companyId,
1589 int start, int end, OrderByComparator<Organization> orderByComparator) {
1590 if (!InlineSQLHelperUtil.isEnabled()) {
1591 return findByUuid_C(uuid, companyId, start, end, orderByComparator);
1592 }
1593
1594 StringBundler query = null;
1595
1596 if (orderByComparator != null) {
1597 query = new StringBundler(4 +
1598 (orderByComparator.getOrderByFields().length * 3));
1599 }
1600 else {
1601 query = new StringBundler(4);
1602 }
1603
1604 if (getDB().isSupportsInlineDistinct()) {
1605 query.append(_FILTER_SQL_SELECT_ORGANIZATION_WHERE);
1606 }
1607 else {
1608 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1);
1609 }
1610
1611 boolean bindUuid = false;
1612
1613 if (uuid == null) {
1614 query.append(_FINDER_COLUMN_UUID_C_UUID_1_SQL);
1615 }
1616 else if (uuid.equals(StringPool.BLANK)) {
1617 query.append(_FINDER_COLUMN_UUID_C_UUID_3_SQL);
1618 }
1619 else {
1620 bindUuid = true;
1621
1622 query.append(_FINDER_COLUMN_UUID_C_UUID_2_SQL);
1623 }
1624
1625 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1626
1627 if (!getDB().isSupportsInlineDistinct()) {
1628 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2);
1629 }
1630
1631 if (orderByComparator != null) {
1632 if (getDB().isSupportsInlineDistinct()) {
1633 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1634 orderByComparator, true);
1635 }
1636 else {
1637 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1638 orderByComparator, true);
1639 }
1640 }
1641 else {
1642 if (getDB().isSupportsInlineDistinct()) {
1643 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
1644 }
1645 else {
1646 query.append(OrganizationModelImpl.ORDER_BY_SQL);
1647 }
1648 }
1649
1650 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1651 Organization.class.getName(),
1652 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1653
1654 Session session = null;
1655
1656 try {
1657 session = openSession();
1658
1659 SQLQuery q = session.createSynchronizedSQLQuery(sql);
1660
1661 if (getDB().isSupportsInlineDistinct()) {
1662 q.addEntity(_FILTER_ENTITY_ALIAS, OrganizationImpl.class);
1663 }
1664 else {
1665 q.addEntity(_FILTER_ENTITY_TABLE, OrganizationImpl.class);
1666 }
1667
1668 QueryPos qPos = QueryPos.getInstance(q);
1669
1670 if (bindUuid) {
1671 qPos.add(uuid);
1672 }
1673
1674 qPos.add(companyId);
1675
1676 return (List<Organization>)QueryUtil.list(q, getDialect(), start,
1677 end);
1678 }
1679 catch (Exception e) {
1680 throw processException(e);
1681 }
1682 finally {
1683 closeSession(session);
1684 }
1685 }
1686
1687
1697 @Override
1698 public Organization[] filterFindByUuid_C_PrevAndNext(long organizationId,
1699 String uuid, long companyId,
1700 OrderByComparator<Organization> orderByComparator)
1701 throws NoSuchOrganizationException {
1702 if (!InlineSQLHelperUtil.isEnabled()) {
1703 return findByUuid_C_PrevAndNext(organizationId, uuid, companyId,
1704 orderByComparator);
1705 }
1706
1707 Organization organization = findByPrimaryKey(organizationId);
1708
1709 Session session = null;
1710
1711 try {
1712 session = openSession();
1713
1714 Organization[] array = new OrganizationImpl[3];
1715
1716 array[0] = filterGetByUuid_C_PrevAndNext(session, organization,
1717 uuid, companyId, orderByComparator, true);
1718
1719 array[1] = organization;
1720
1721 array[2] = filterGetByUuid_C_PrevAndNext(session, organization,
1722 uuid, companyId, orderByComparator, false);
1723
1724 return array;
1725 }
1726 catch (Exception e) {
1727 throw processException(e);
1728 }
1729 finally {
1730 closeSession(session);
1731 }
1732 }
1733
1734 protected Organization filterGetByUuid_C_PrevAndNext(Session session,
1735 Organization organization, String uuid, long companyId,
1736 OrderByComparator<Organization> orderByComparator, boolean previous) {
1737 StringBundler query = null;
1738
1739 if (orderByComparator != null) {
1740 query = new StringBundler(6 +
1741 (orderByComparator.getOrderByFields().length * 6));
1742 }
1743 else {
1744 query = new StringBundler(3);
1745 }
1746
1747 if (getDB().isSupportsInlineDistinct()) {
1748 query.append(_FILTER_SQL_SELECT_ORGANIZATION_WHERE);
1749 }
1750 else {
1751 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1);
1752 }
1753
1754 boolean bindUuid = false;
1755
1756 if (uuid == null) {
1757 query.append(_FINDER_COLUMN_UUID_C_UUID_1_SQL);
1758 }
1759 else if (uuid.equals(StringPool.BLANK)) {
1760 query.append(_FINDER_COLUMN_UUID_C_UUID_3_SQL);
1761 }
1762 else {
1763 bindUuid = true;
1764
1765 query.append(_FINDER_COLUMN_UUID_C_UUID_2_SQL);
1766 }
1767
1768 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1769
1770 if (!getDB().isSupportsInlineDistinct()) {
1771 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2);
1772 }
1773
1774 if (orderByComparator != null) {
1775 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1776
1777 if (orderByConditionFields.length > 0) {
1778 query.append(WHERE_AND);
1779 }
1780
1781 for (int i = 0; i < orderByConditionFields.length; i++) {
1782 if (getDB().isSupportsInlineDistinct()) {
1783 query.append(_ORDER_BY_ENTITY_ALIAS);
1784 }
1785 else {
1786 query.append(_ORDER_BY_ENTITY_TABLE);
1787 }
1788
1789 query.append(orderByConditionFields[i]);
1790
1791 if ((i + 1) < orderByConditionFields.length) {
1792 if (orderByComparator.isAscending() ^ previous) {
1793 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1794 }
1795 else {
1796 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1797 }
1798 }
1799 else {
1800 if (orderByComparator.isAscending() ^ previous) {
1801 query.append(WHERE_GREATER_THAN);
1802 }
1803 else {
1804 query.append(WHERE_LESSER_THAN);
1805 }
1806 }
1807 }
1808
1809 query.append(ORDER_BY_CLAUSE);
1810
1811 String[] orderByFields = orderByComparator.getOrderByFields();
1812
1813 for (int i = 0; i < orderByFields.length; i++) {
1814 if (getDB().isSupportsInlineDistinct()) {
1815 query.append(_ORDER_BY_ENTITY_ALIAS);
1816 }
1817 else {
1818 query.append(_ORDER_BY_ENTITY_TABLE);
1819 }
1820
1821 query.append(orderByFields[i]);
1822
1823 if ((i + 1) < orderByFields.length) {
1824 if (orderByComparator.isAscending() ^ previous) {
1825 query.append(ORDER_BY_ASC_HAS_NEXT);
1826 }
1827 else {
1828 query.append(ORDER_BY_DESC_HAS_NEXT);
1829 }
1830 }
1831 else {
1832 if (orderByComparator.isAscending() ^ previous) {
1833 query.append(ORDER_BY_ASC);
1834 }
1835 else {
1836 query.append(ORDER_BY_DESC);
1837 }
1838 }
1839 }
1840 }
1841 else {
1842 if (getDB().isSupportsInlineDistinct()) {
1843 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
1844 }
1845 else {
1846 query.append(OrganizationModelImpl.ORDER_BY_SQL);
1847 }
1848 }
1849
1850 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1851 Organization.class.getName(),
1852 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1853
1854 SQLQuery q = session.createSynchronizedSQLQuery(sql);
1855
1856 q.setFirstResult(0);
1857 q.setMaxResults(2);
1858
1859 if (getDB().isSupportsInlineDistinct()) {
1860 q.addEntity(_FILTER_ENTITY_ALIAS, OrganizationImpl.class);
1861 }
1862 else {
1863 q.addEntity(_FILTER_ENTITY_TABLE, OrganizationImpl.class);
1864 }
1865
1866 QueryPos qPos = QueryPos.getInstance(q);
1867
1868 if (bindUuid) {
1869 qPos.add(uuid);
1870 }
1871
1872 qPos.add(companyId);
1873
1874 if (orderByComparator != null) {
1875 Object[] values = orderByComparator.getOrderByConditionValues(organization);
1876
1877 for (Object value : values) {
1878 qPos.add(value);
1879 }
1880 }
1881
1882 List<Organization> list = q.list();
1883
1884 if (list.size() == 2) {
1885 return list.get(1);
1886 }
1887 else {
1888 return null;
1889 }
1890 }
1891
1892
1898 @Override
1899 public void removeByUuid_C(String uuid, long companyId) {
1900 for (Organization organization : findByUuid_C(uuid, companyId,
1901 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1902 remove(organization);
1903 }
1904 }
1905
1906
1913 @Override
1914 public int countByUuid_C(String uuid, long companyId) {
1915 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1916
1917 Object[] finderArgs = new Object[] { uuid, companyId };
1918
1919 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1920
1921 if (count == null) {
1922 StringBundler query = new StringBundler(3);
1923
1924 query.append(_SQL_COUNT_ORGANIZATION_WHERE);
1925
1926 boolean bindUuid = false;
1927
1928 if (uuid == null) {
1929 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1930 }
1931 else if (uuid.equals(StringPool.BLANK)) {
1932 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1933 }
1934 else {
1935 bindUuid = true;
1936
1937 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1938 }
1939
1940 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1941
1942 String sql = query.toString();
1943
1944 Session session = null;
1945
1946 try {
1947 session = openSession();
1948
1949 Query q = session.createQuery(sql);
1950
1951 QueryPos qPos = QueryPos.getInstance(q);
1952
1953 if (bindUuid) {
1954 qPos.add(uuid);
1955 }
1956
1957 qPos.add(companyId);
1958
1959 count = (Long)q.uniqueResult();
1960
1961 finderCache.putResult(finderPath, finderArgs, count);
1962 }
1963 catch (Exception e) {
1964 finderCache.removeResult(finderPath, finderArgs);
1965
1966 throw processException(e);
1967 }
1968 finally {
1969 closeSession(session);
1970 }
1971 }
1972
1973 return count.intValue();
1974 }
1975
1976
1983 @Override
1984 public int filterCountByUuid_C(String uuid, long companyId) {
1985 if (!InlineSQLHelperUtil.isEnabled()) {
1986 return countByUuid_C(uuid, companyId);
1987 }
1988
1989 StringBundler query = new StringBundler(3);
1990
1991 query.append(_FILTER_SQL_COUNT_ORGANIZATION_WHERE);
1992
1993 boolean bindUuid = false;
1994
1995 if (uuid == null) {
1996 query.append(_FINDER_COLUMN_UUID_C_UUID_1_SQL);
1997 }
1998 else if (uuid.equals(StringPool.BLANK)) {
1999 query.append(_FINDER_COLUMN_UUID_C_UUID_3_SQL);
2000 }
2001 else {
2002 bindUuid = true;
2003
2004 query.append(_FINDER_COLUMN_UUID_C_UUID_2_SQL);
2005 }
2006
2007 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
2008
2009 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2010 Organization.class.getName(),
2011 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2012
2013 Session session = null;
2014
2015 try {
2016 session = openSession();
2017
2018 SQLQuery q = session.createSynchronizedSQLQuery(sql);
2019
2020 q.addScalar(COUNT_COLUMN_NAME,
2021 com.liferay.portal.kernel.dao.orm.Type.LONG);
2022
2023 QueryPos qPos = QueryPos.getInstance(q);
2024
2025 if (bindUuid) {
2026 qPos.add(uuid);
2027 }
2028
2029 qPos.add(companyId);
2030
2031 Long count = (Long)q.uniqueResult();
2032
2033 return count.intValue();
2034 }
2035 catch (Exception e) {
2036 throw processException(e);
2037 }
2038 finally {
2039 closeSession(session);
2040 }
2041 }
2042
2043 private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "organization.uuid IS NULL AND ";
2044 private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "organization.uuid = ? AND ";
2045 private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(organization.uuid IS NULL OR organization.uuid = '') AND ";
2046 private static final String _FINDER_COLUMN_UUID_C_UUID_1_SQL = "organization.uuid_ IS NULL AND ";
2047 private static final String _FINDER_COLUMN_UUID_C_UUID_2_SQL = "organization.uuid_ = ? AND ";
2048 private static final String _FINDER_COLUMN_UUID_C_UUID_3_SQL = "(organization.uuid_ IS NULL OR organization.uuid_ = '') AND ";
2049 private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "organization.companyId = ?";
2050 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
2051 new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
2052 OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
2053 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
2054 new String[] {
2055 Long.class.getName(),
2056
2057 Integer.class.getName(), Integer.class.getName(),
2058 OrderByComparator.class.getName()
2059 });
2060 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
2061 new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
2062 OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
2063 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
2064 new String[] { Long.class.getName() },
2065 OrganizationModelImpl.COMPANYID_COLUMN_BITMASK |
2066 OrganizationModelImpl.NAME_COLUMN_BITMASK);
2067 public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
2068 OrganizationModelImpl.FINDER_CACHE_ENABLED, Long.class,
2069 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
2070 new String[] { Long.class.getName() });
2071
2072
2078 @Override
2079 public List<Organization> findByCompanyId(long companyId) {
2080 return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2081 null);
2082 }
2083
2084
2096 @Override
2097 public List<Organization> findByCompanyId(long companyId, int start, int end) {
2098 return findByCompanyId(companyId, start, end, null);
2099 }
2100
2101
2114 @Override
2115 public List<Organization> findByCompanyId(long companyId, int start,
2116 int end, OrderByComparator<Organization> orderByComparator) {
2117 return findByCompanyId(companyId, start, end, orderByComparator, true);
2118 }
2119
2120
2134 @Override
2135 public List<Organization> findByCompanyId(long companyId, int start,
2136 int end, OrderByComparator<Organization> orderByComparator,
2137 boolean retrieveFromCache) {
2138 boolean pagination = true;
2139 FinderPath finderPath = null;
2140 Object[] finderArgs = null;
2141
2142 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2143 (orderByComparator == null)) {
2144 pagination = false;
2145 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
2146 finderArgs = new Object[] { companyId };
2147 }
2148 else {
2149 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
2150 finderArgs = new Object[] { companyId, start, end, orderByComparator };
2151 }
2152
2153 List<Organization> list = null;
2154
2155 if (retrieveFromCache) {
2156 list = (List<Organization>)finderCache.getResult(finderPath,
2157 finderArgs, this);
2158
2159 if ((list != null) && !list.isEmpty()) {
2160 for (Organization organization : list) {
2161 if ((companyId != organization.getCompanyId())) {
2162 list = null;
2163
2164 break;
2165 }
2166 }
2167 }
2168 }
2169
2170 if (list == null) {
2171 StringBundler query = null;
2172
2173 if (orderByComparator != null) {
2174 query = new StringBundler(3 +
2175 (orderByComparator.getOrderByFields().length * 3));
2176 }
2177 else {
2178 query = new StringBundler(3);
2179 }
2180
2181 query.append(_SQL_SELECT_ORGANIZATION_WHERE);
2182
2183 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2184
2185 if (orderByComparator != null) {
2186 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2187 orderByComparator);
2188 }
2189 else
2190 if (pagination) {
2191 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
2192 }
2193
2194 String sql = query.toString();
2195
2196 Session session = null;
2197
2198 try {
2199 session = openSession();
2200
2201 Query q = session.createQuery(sql);
2202
2203 QueryPos qPos = QueryPos.getInstance(q);
2204
2205 qPos.add(companyId);
2206
2207 if (!pagination) {
2208 list = (List<Organization>)QueryUtil.list(q, getDialect(),
2209 start, end, false);
2210
2211 Collections.sort(list);
2212
2213 list = Collections.unmodifiableList(list);
2214 }
2215 else {
2216 list = (List<Organization>)QueryUtil.list(q, getDialect(),
2217 start, end);
2218 }
2219
2220 cacheResult(list);
2221
2222 finderCache.putResult(finderPath, finderArgs, list);
2223 }
2224 catch (Exception e) {
2225 finderCache.removeResult(finderPath, finderArgs);
2226
2227 throw processException(e);
2228 }
2229 finally {
2230 closeSession(session);
2231 }
2232 }
2233
2234 return list;
2235 }
2236
2237
2245 @Override
2246 public Organization findByCompanyId_First(long companyId,
2247 OrderByComparator<Organization> orderByComparator)
2248 throws NoSuchOrganizationException {
2249 Organization organization = fetchByCompanyId_First(companyId,
2250 orderByComparator);
2251
2252 if (organization != null) {
2253 return organization;
2254 }
2255
2256 StringBundler msg = new StringBundler(4);
2257
2258 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2259
2260 msg.append("companyId=");
2261 msg.append(companyId);
2262
2263 msg.append(StringPool.CLOSE_CURLY_BRACE);
2264
2265 throw new NoSuchOrganizationException(msg.toString());
2266 }
2267
2268
2275 @Override
2276 public Organization fetchByCompanyId_First(long companyId,
2277 OrderByComparator<Organization> orderByComparator) {
2278 List<Organization> list = findByCompanyId(companyId, 0, 1,
2279 orderByComparator);
2280
2281 if (!list.isEmpty()) {
2282 return list.get(0);
2283 }
2284
2285 return null;
2286 }
2287
2288
2296 @Override
2297 public Organization findByCompanyId_Last(long companyId,
2298 OrderByComparator<Organization> orderByComparator)
2299 throws NoSuchOrganizationException {
2300 Organization organization = fetchByCompanyId_Last(companyId,
2301 orderByComparator);
2302
2303 if (organization != null) {
2304 return organization;
2305 }
2306
2307 StringBundler msg = new StringBundler(4);
2308
2309 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2310
2311 msg.append("companyId=");
2312 msg.append(companyId);
2313
2314 msg.append(StringPool.CLOSE_CURLY_BRACE);
2315
2316 throw new NoSuchOrganizationException(msg.toString());
2317 }
2318
2319
2326 @Override
2327 public Organization fetchByCompanyId_Last(long companyId,
2328 OrderByComparator<Organization> orderByComparator) {
2329 int count = countByCompanyId(companyId);
2330
2331 if (count == 0) {
2332 return null;
2333 }
2334
2335 List<Organization> list = findByCompanyId(companyId, count - 1, count,
2336 orderByComparator);
2337
2338 if (!list.isEmpty()) {
2339 return list.get(0);
2340 }
2341
2342 return null;
2343 }
2344
2345
2354 @Override
2355 public Organization[] findByCompanyId_PrevAndNext(long organizationId,
2356 long companyId, OrderByComparator<Organization> orderByComparator)
2357 throws NoSuchOrganizationException {
2358 Organization organization = findByPrimaryKey(organizationId);
2359
2360 Session session = null;
2361
2362 try {
2363 session = openSession();
2364
2365 Organization[] array = new OrganizationImpl[3];
2366
2367 array[0] = getByCompanyId_PrevAndNext(session, organization,
2368 companyId, orderByComparator, true);
2369
2370 array[1] = organization;
2371
2372 array[2] = getByCompanyId_PrevAndNext(session, organization,
2373 companyId, orderByComparator, false);
2374
2375 return array;
2376 }
2377 catch (Exception e) {
2378 throw processException(e);
2379 }
2380 finally {
2381 closeSession(session);
2382 }
2383 }
2384
2385 protected Organization getByCompanyId_PrevAndNext(Session session,
2386 Organization organization, long companyId,
2387 OrderByComparator<Organization> orderByComparator, boolean previous) {
2388 StringBundler query = null;
2389
2390 if (orderByComparator != null) {
2391 query = new StringBundler(6 +
2392 (orderByComparator.getOrderByFields().length * 6));
2393 }
2394 else {
2395 query = new StringBundler(3);
2396 }
2397
2398 query.append(_SQL_SELECT_ORGANIZATION_WHERE);
2399
2400 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2401
2402 if (orderByComparator != null) {
2403 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2404
2405 if (orderByConditionFields.length > 0) {
2406 query.append(WHERE_AND);
2407 }
2408
2409 for (int i = 0; i < orderByConditionFields.length; i++) {
2410 query.append(_ORDER_BY_ENTITY_ALIAS);
2411 query.append(orderByConditionFields[i]);
2412
2413 if ((i + 1) < orderByConditionFields.length) {
2414 if (orderByComparator.isAscending() ^ previous) {
2415 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2416 }
2417 else {
2418 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2419 }
2420 }
2421 else {
2422 if (orderByComparator.isAscending() ^ previous) {
2423 query.append(WHERE_GREATER_THAN);
2424 }
2425 else {
2426 query.append(WHERE_LESSER_THAN);
2427 }
2428 }
2429 }
2430
2431 query.append(ORDER_BY_CLAUSE);
2432
2433 String[] orderByFields = orderByComparator.getOrderByFields();
2434
2435 for (int i = 0; i < orderByFields.length; i++) {
2436 query.append(_ORDER_BY_ENTITY_ALIAS);
2437 query.append(orderByFields[i]);
2438
2439 if ((i + 1) < orderByFields.length) {
2440 if (orderByComparator.isAscending() ^ previous) {
2441 query.append(ORDER_BY_ASC_HAS_NEXT);
2442 }
2443 else {
2444 query.append(ORDER_BY_DESC_HAS_NEXT);
2445 }
2446 }
2447 else {
2448 if (orderByComparator.isAscending() ^ previous) {
2449 query.append(ORDER_BY_ASC);
2450 }
2451 else {
2452 query.append(ORDER_BY_DESC);
2453 }
2454 }
2455 }
2456 }
2457 else {
2458 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
2459 }
2460
2461 String sql = query.toString();
2462
2463 Query q = session.createQuery(sql);
2464
2465 q.setFirstResult(0);
2466 q.setMaxResults(2);
2467
2468 QueryPos qPos = QueryPos.getInstance(q);
2469
2470 qPos.add(companyId);
2471
2472 if (orderByComparator != null) {
2473 Object[] values = orderByComparator.getOrderByConditionValues(organization);
2474
2475 for (Object value : values) {
2476 qPos.add(value);
2477 }
2478 }
2479
2480 List<Organization> list = q.list();
2481
2482 if (list.size() == 2) {
2483 return list.get(1);
2484 }
2485 else {
2486 return null;
2487 }
2488 }
2489
2490
2496 @Override
2497 public List<Organization> filterFindByCompanyId(long companyId) {
2498 return filterFindByCompanyId(companyId, QueryUtil.ALL_POS,
2499 QueryUtil.ALL_POS, null);
2500 }
2501
2502
2514 @Override
2515 public List<Organization> filterFindByCompanyId(long companyId, int start,
2516 int end) {
2517 return filterFindByCompanyId(companyId, start, end, null);
2518 }
2519
2520
2533 @Override
2534 public List<Organization> filterFindByCompanyId(long companyId, int start,
2535 int end, OrderByComparator<Organization> orderByComparator) {
2536 if (!InlineSQLHelperUtil.isEnabled()) {
2537 return findByCompanyId(companyId, start, end, orderByComparator);
2538 }
2539
2540 StringBundler query = null;
2541
2542 if (orderByComparator != null) {
2543 query = new StringBundler(3 +
2544 (orderByComparator.getOrderByFields().length * 3));
2545 }
2546 else {
2547 query = new StringBundler(3);
2548 }
2549
2550 if (getDB().isSupportsInlineDistinct()) {
2551 query.append(_FILTER_SQL_SELECT_ORGANIZATION_WHERE);
2552 }
2553 else {
2554 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1);
2555 }
2556
2557 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2558
2559 if (!getDB().isSupportsInlineDistinct()) {
2560 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2);
2561 }
2562
2563 if (orderByComparator != null) {
2564 if (getDB().isSupportsInlineDistinct()) {
2565 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2566 orderByComparator, true);
2567 }
2568 else {
2569 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
2570 orderByComparator, true);
2571 }
2572 }
2573 else {
2574 if (getDB().isSupportsInlineDistinct()) {
2575 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
2576 }
2577 else {
2578 query.append(OrganizationModelImpl.ORDER_BY_SQL);
2579 }
2580 }
2581
2582 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2583 Organization.class.getName(),
2584 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2585
2586 Session session = null;
2587
2588 try {
2589 session = openSession();
2590
2591 SQLQuery q = session.createSynchronizedSQLQuery(sql);
2592
2593 if (getDB().isSupportsInlineDistinct()) {
2594 q.addEntity(_FILTER_ENTITY_ALIAS, OrganizationImpl.class);
2595 }
2596 else {
2597 q.addEntity(_FILTER_ENTITY_TABLE, OrganizationImpl.class);
2598 }
2599
2600 QueryPos qPos = QueryPos.getInstance(q);
2601
2602 qPos.add(companyId);
2603
2604 return (List<Organization>)QueryUtil.list(q, getDialect(), start,
2605 end);
2606 }
2607 catch (Exception e) {
2608 throw processException(e);
2609 }
2610 finally {
2611 closeSession(session);
2612 }
2613 }
2614
2615
2624 @Override
2625 public Organization[] filterFindByCompanyId_PrevAndNext(
2626 long organizationId, long companyId,
2627 OrderByComparator<Organization> orderByComparator)
2628 throws NoSuchOrganizationException {
2629 if (!InlineSQLHelperUtil.isEnabled()) {
2630 return findByCompanyId_PrevAndNext(organizationId, companyId,
2631 orderByComparator);
2632 }
2633
2634 Organization organization = findByPrimaryKey(organizationId);
2635
2636 Session session = null;
2637
2638 try {
2639 session = openSession();
2640
2641 Organization[] array = new OrganizationImpl[3];
2642
2643 array[0] = filterGetByCompanyId_PrevAndNext(session, organization,
2644 companyId, orderByComparator, true);
2645
2646 array[1] = organization;
2647
2648 array[2] = filterGetByCompanyId_PrevAndNext(session, organization,
2649 companyId, orderByComparator, false);
2650
2651 return array;
2652 }
2653 catch (Exception e) {
2654 throw processException(e);
2655 }
2656 finally {
2657 closeSession(session);
2658 }
2659 }
2660
2661 protected Organization filterGetByCompanyId_PrevAndNext(Session session,
2662 Organization organization, long companyId,
2663 OrderByComparator<Organization> orderByComparator, boolean previous) {
2664 StringBundler query = null;
2665
2666 if (orderByComparator != null) {
2667 query = new StringBundler(6 +
2668 (orderByComparator.getOrderByFields().length * 6));
2669 }
2670 else {
2671 query = new StringBundler(3);
2672 }
2673
2674 if (getDB().isSupportsInlineDistinct()) {
2675 query.append(_FILTER_SQL_SELECT_ORGANIZATION_WHERE);
2676 }
2677 else {
2678 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1);
2679 }
2680
2681 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2682
2683 if (!getDB().isSupportsInlineDistinct()) {
2684 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2);
2685 }
2686
2687 if (orderByComparator != null) {
2688 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2689
2690 if (orderByConditionFields.length > 0) {
2691 query.append(WHERE_AND);
2692 }
2693
2694 for (int i = 0; i < orderByConditionFields.length; i++) {
2695 if (getDB().isSupportsInlineDistinct()) {
2696 query.append(_ORDER_BY_ENTITY_ALIAS);
2697 }
2698 else {
2699 query.append(_ORDER_BY_ENTITY_TABLE);
2700 }
2701
2702 query.append(orderByConditionFields[i]);
2703
2704 if ((i + 1) < orderByConditionFields.length) {
2705 if (orderByComparator.isAscending() ^ previous) {
2706 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2707 }
2708 else {
2709 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2710 }
2711 }
2712 else {
2713 if (orderByComparator.isAscending() ^ previous) {
2714 query.append(WHERE_GREATER_THAN);
2715 }
2716 else {
2717 query.append(WHERE_LESSER_THAN);
2718 }
2719 }
2720 }
2721
2722 query.append(ORDER_BY_CLAUSE);
2723
2724 String[] orderByFields = orderByComparator.getOrderByFields();
2725
2726 for (int i = 0; i < orderByFields.length; i++) {
2727 if (getDB().isSupportsInlineDistinct()) {
2728 query.append(_ORDER_BY_ENTITY_ALIAS);
2729 }
2730 else {
2731 query.append(_ORDER_BY_ENTITY_TABLE);
2732 }
2733
2734 query.append(orderByFields[i]);
2735
2736 if ((i + 1) < orderByFields.length) {
2737 if (orderByComparator.isAscending() ^ previous) {
2738 query.append(ORDER_BY_ASC_HAS_NEXT);
2739 }
2740 else {
2741 query.append(ORDER_BY_DESC_HAS_NEXT);
2742 }
2743 }
2744 else {
2745 if (orderByComparator.isAscending() ^ previous) {
2746 query.append(ORDER_BY_ASC);
2747 }
2748 else {
2749 query.append(ORDER_BY_DESC);
2750 }
2751 }
2752 }
2753 }
2754 else {
2755 if (getDB().isSupportsInlineDistinct()) {
2756 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
2757 }
2758 else {
2759 query.append(OrganizationModelImpl.ORDER_BY_SQL);
2760 }
2761 }
2762
2763 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2764 Organization.class.getName(),
2765 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2766
2767 SQLQuery q = session.createSynchronizedSQLQuery(sql);
2768
2769 q.setFirstResult(0);
2770 q.setMaxResults(2);
2771
2772 if (getDB().isSupportsInlineDistinct()) {
2773 q.addEntity(_FILTER_ENTITY_ALIAS, OrganizationImpl.class);
2774 }
2775 else {
2776 q.addEntity(_FILTER_ENTITY_TABLE, OrganizationImpl.class);
2777 }
2778
2779 QueryPos qPos = QueryPos.getInstance(q);
2780
2781 qPos.add(companyId);
2782
2783 if (orderByComparator != null) {
2784 Object[] values = orderByComparator.getOrderByConditionValues(organization);
2785
2786 for (Object value : values) {
2787 qPos.add(value);
2788 }
2789 }
2790
2791 List<Organization> list = q.list();
2792
2793 if (list.size() == 2) {
2794 return list.get(1);
2795 }
2796 else {
2797 return null;
2798 }
2799 }
2800
2801
2806 @Override
2807 public void removeByCompanyId(long companyId) {
2808 for (Organization organization : findByCompanyId(companyId,
2809 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2810 remove(organization);
2811 }
2812 }
2813
2814
2820 @Override
2821 public int countByCompanyId(long companyId) {
2822 FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
2823
2824 Object[] finderArgs = new Object[] { companyId };
2825
2826 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
2827
2828 if (count == null) {
2829 StringBundler query = new StringBundler(2);
2830
2831 query.append(_SQL_COUNT_ORGANIZATION_WHERE);
2832
2833 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2834
2835 String sql = query.toString();
2836
2837 Session session = null;
2838
2839 try {
2840 session = openSession();
2841
2842 Query q = session.createQuery(sql);
2843
2844 QueryPos qPos = QueryPos.getInstance(q);
2845
2846 qPos.add(companyId);
2847
2848 count = (Long)q.uniqueResult();
2849
2850 finderCache.putResult(finderPath, finderArgs, count);
2851 }
2852 catch (Exception e) {
2853 finderCache.removeResult(finderPath, finderArgs);
2854
2855 throw processException(e);
2856 }
2857 finally {
2858 closeSession(session);
2859 }
2860 }
2861
2862 return count.intValue();
2863 }
2864
2865
2871 @Override
2872 public int filterCountByCompanyId(long companyId) {
2873 if (!InlineSQLHelperUtil.isEnabled()) {
2874 return countByCompanyId(companyId);
2875 }
2876
2877 StringBundler query = new StringBundler(2);
2878
2879 query.append(_FILTER_SQL_COUNT_ORGANIZATION_WHERE);
2880
2881 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2882
2883 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2884 Organization.class.getName(),
2885 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2886
2887 Session session = null;
2888
2889 try {
2890 session = openSession();
2891
2892 SQLQuery q = session.createSynchronizedSQLQuery(sql);
2893
2894 q.addScalar(COUNT_COLUMN_NAME,
2895 com.liferay.portal.kernel.dao.orm.Type.LONG);
2896
2897 QueryPos qPos = QueryPos.getInstance(q);
2898
2899 qPos.add(companyId);
2900
2901 Long count = (Long)q.uniqueResult();
2902
2903 return count.intValue();
2904 }
2905 catch (Exception e) {
2906 throw processException(e);
2907 }
2908 finally {
2909 closeSession(session);
2910 }
2911 }
2912
2913 private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "organization.companyId = ?";
2914 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_LOCATIONS =
2915 new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
2916 OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
2917 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByLocations",
2918 new String[] {
2919 Long.class.getName(),
2920
2921 Integer.class.getName(), Integer.class.getName(),
2922 OrderByComparator.class.getName()
2923 });
2924 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LOCATIONS =
2925 new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
2926 OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
2927 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByLocations",
2928 new String[] { Long.class.getName() },
2929 OrganizationModelImpl.COMPANYID_COLUMN_BITMASK |
2930 OrganizationModelImpl.NAME_COLUMN_BITMASK);
2931 public static final FinderPath FINDER_PATH_COUNT_BY_LOCATIONS = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
2932 OrganizationModelImpl.FINDER_CACHE_ENABLED, Long.class,
2933 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByLocations",
2934 new String[] { Long.class.getName() });
2935
2936
2942 @Override
2943 public List<Organization> findByLocations(long companyId) {
2944 return findByLocations(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2945 null);
2946 }
2947
2948
2960 @Override
2961 public List<Organization> findByLocations(long companyId, int start, int end) {
2962 return findByLocations(companyId, start, end, null);
2963 }
2964
2965
2978 @Override
2979 public List<Organization> findByLocations(long companyId, int start,
2980 int end, OrderByComparator<Organization> orderByComparator) {
2981 return findByLocations(companyId, start, end, orderByComparator, true);
2982 }
2983
2984
2998 @Override
2999 public List<Organization> findByLocations(long companyId, int start,
3000 int end, OrderByComparator<Organization> orderByComparator,
3001 boolean retrieveFromCache) {
3002 boolean pagination = true;
3003 FinderPath finderPath = null;
3004 Object[] finderArgs = null;
3005
3006 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3007 (orderByComparator == null)) {
3008 pagination = false;
3009 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LOCATIONS;
3010 finderArgs = new Object[] { companyId };
3011 }
3012 else {
3013 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_LOCATIONS;
3014 finderArgs = new Object[] { companyId, start, end, orderByComparator };
3015 }
3016
3017 List<Organization> list = null;
3018
3019 if (retrieveFromCache) {
3020 list = (List<Organization>)finderCache.getResult(finderPath,
3021 finderArgs, this);
3022
3023 if ((list != null) && !list.isEmpty()) {
3024 for (Organization organization : list) {
3025 if ((companyId != organization.getCompanyId())) {
3026 list = null;
3027
3028 break;
3029 }
3030 }
3031 }
3032 }
3033
3034 if (list == null) {
3035 StringBundler query = null;
3036
3037 if (orderByComparator != null) {
3038 query = new StringBundler(3 +
3039 (orderByComparator.getOrderByFields().length * 3));
3040 }
3041 else {
3042 query = new StringBundler(3);
3043 }
3044
3045 query.append(_SQL_SELECT_ORGANIZATION_WHERE);
3046
3047 query.append(_FINDER_COLUMN_LOCATIONS_COMPANYID_2);
3048
3049 if (orderByComparator != null) {
3050 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3051 orderByComparator);
3052 }
3053 else
3054 if (pagination) {
3055 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
3056 }
3057
3058 String sql = query.toString();
3059
3060 Session session = null;
3061
3062 try {
3063 session = openSession();
3064
3065 Query q = session.createQuery(sql);
3066
3067 QueryPos qPos = QueryPos.getInstance(q);
3068
3069 qPos.add(companyId);
3070
3071 if (!pagination) {
3072 list = (List<Organization>)QueryUtil.list(q, getDialect(),
3073 start, end, false);
3074
3075 Collections.sort(list);
3076
3077 list = Collections.unmodifiableList(list);
3078 }
3079 else {
3080 list = (List<Organization>)QueryUtil.list(q, getDialect(),
3081 start, end);
3082 }
3083
3084 cacheResult(list);
3085
3086 finderCache.putResult(finderPath, finderArgs, list);
3087 }
3088 catch (Exception e) {
3089 finderCache.removeResult(finderPath, finderArgs);
3090
3091 throw processException(e);
3092 }
3093 finally {
3094 closeSession(session);
3095 }
3096 }
3097
3098 return list;
3099 }
3100
3101
3109 @Override
3110 public Organization findByLocations_First(long companyId,
3111 OrderByComparator<Organization> orderByComparator)
3112 throws NoSuchOrganizationException {
3113 Organization organization = fetchByLocations_First(companyId,
3114 orderByComparator);
3115
3116 if (organization != null) {
3117 return organization;
3118 }
3119
3120 StringBundler msg = new StringBundler(4);
3121
3122 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3123
3124 msg.append("companyId=");
3125 msg.append(companyId);
3126
3127 msg.append(StringPool.CLOSE_CURLY_BRACE);
3128
3129 throw new NoSuchOrganizationException(msg.toString());
3130 }
3131
3132
3139 @Override
3140 public Organization fetchByLocations_First(long companyId,
3141 OrderByComparator<Organization> orderByComparator) {
3142 List<Organization> list = findByLocations(companyId, 0, 1,
3143 orderByComparator);
3144
3145 if (!list.isEmpty()) {
3146 return list.get(0);
3147 }
3148
3149 return null;
3150 }
3151
3152
3160 @Override
3161 public Organization findByLocations_Last(long companyId,
3162 OrderByComparator<Organization> orderByComparator)
3163 throws NoSuchOrganizationException {
3164 Organization organization = fetchByLocations_Last(companyId,
3165 orderByComparator);
3166
3167 if (organization != null) {
3168 return organization;
3169 }
3170
3171 StringBundler msg = new StringBundler(4);
3172
3173 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3174
3175 msg.append("companyId=");
3176 msg.append(companyId);
3177
3178 msg.append(StringPool.CLOSE_CURLY_BRACE);
3179
3180 throw new NoSuchOrganizationException(msg.toString());
3181 }
3182
3183
3190 @Override
3191 public Organization fetchByLocations_Last(long companyId,
3192 OrderByComparator<Organization> orderByComparator) {
3193 int count = countByLocations(companyId);
3194
3195 if (count == 0) {
3196 return null;
3197 }
3198
3199 List<Organization> list = findByLocations(companyId, count - 1, count,
3200 orderByComparator);
3201
3202 if (!list.isEmpty()) {
3203 return list.get(0);
3204 }
3205
3206 return null;
3207 }
3208
3209
3218 @Override
3219 public Organization[] findByLocations_PrevAndNext(long organizationId,
3220 long companyId, OrderByComparator<Organization> orderByComparator)
3221 throws NoSuchOrganizationException {
3222 Organization organization = findByPrimaryKey(organizationId);
3223
3224 Session session = null;
3225
3226 try {
3227 session = openSession();
3228
3229 Organization[] array = new OrganizationImpl[3];
3230
3231 array[0] = getByLocations_PrevAndNext(session, organization,
3232 companyId, orderByComparator, true);
3233
3234 array[1] = organization;
3235
3236 array[2] = getByLocations_PrevAndNext(session, organization,
3237 companyId, orderByComparator, false);
3238
3239 return array;
3240 }
3241 catch (Exception e) {
3242 throw processException(e);
3243 }
3244 finally {
3245 closeSession(session);
3246 }
3247 }
3248
3249 protected Organization getByLocations_PrevAndNext(Session session,
3250 Organization organization, long companyId,
3251 OrderByComparator<Organization> orderByComparator, boolean previous) {
3252 StringBundler query = null;
3253
3254 if (orderByComparator != null) {
3255 query = new StringBundler(6 +
3256 (orderByComparator.getOrderByFields().length * 6));
3257 }
3258 else {
3259 query = new StringBundler(3);
3260 }
3261
3262 query.append(_SQL_SELECT_ORGANIZATION_WHERE);
3263
3264 query.append(_FINDER_COLUMN_LOCATIONS_COMPANYID_2);
3265
3266 if (orderByComparator != null) {
3267 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3268
3269 if (orderByConditionFields.length > 0) {
3270 query.append(WHERE_AND);
3271 }
3272
3273 for (int i = 0; i < orderByConditionFields.length; i++) {
3274 query.append(_ORDER_BY_ENTITY_ALIAS);
3275 query.append(orderByConditionFields[i]);
3276
3277 if ((i + 1) < orderByConditionFields.length) {
3278 if (orderByComparator.isAscending() ^ previous) {
3279 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3280 }
3281 else {
3282 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3283 }
3284 }
3285 else {
3286 if (orderByComparator.isAscending() ^ previous) {
3287 query.append(WHERE_GREATER_THAN);
3288 }
3289 else {
3290 query.append(WHERE_LESSER_THAN);
3291 }
3292 }
3293 }
3294
3295 query.append(ORDER_BY_CLAUSE);
3296
3297 String[] orderByFields = orderByComparator.getOrderByFields();
3298
3299 for (int i = 0; i < orderByFields.length; i++) {
3300 query.append(_ORDER_BY_ENTITY_ALIAS);
3301 query.append(orderByFields[i]);
3302
3303 if ((i + 1) < orderByFields.length) {
3304 if (orderByComparator.isAscending() ^ previous) {
3305 query.append(ORDER_BY_ASC_HAS_NEXT);
3306 }
3307 else {
3308 query.append(ORDER_BY_DESC_HAS_NEXT);
3309 }
3310 }
3311 else {
3312 if (orderByComparator.isAscending() ^ previous) {
3313 query.append(ORDER_BY_ASC);
3314 }
3315 else {
3316 query.append(ORDER_BY_DESC);
3317 }
3318 }
3319 }
3320 }
3321 else {
3322 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
3323 }
3324
3325 String sql = query.toString();
3326
3327 Query q = session.createQuery(sql);
3328
3329 q.setFirstResult(0);
3330 q.setMaxResults(2);
3331
3332 QueryPos qPos = QueryPos.getInstance(q);
3333
3334 qPos.add(companyId);
3335
3336 if (orderByComparator != null) {
3337 Object[] values = orderByComparator.getOrderByConditionValues(organization);
3338
3339 for (Object value : values) {
3340 qPos.add(value);
3341 }
3342 }
3343
3344 List<Organization> list = q.list();
3345
3346 if (list.size() == 2) {
3347 return list.get(1);
3348 }
3349 else {
3350 return null;
3351 }
3352 }
3353
3354
3360 @Override
3361 public List<Organization> filterFindByLocations(long companyId) {
3362 return filterFindByLocations(companyId, QueryUtil.ALL_POS,
3363 QueryUtil.ALL_POS, null);
3364 }
3365
3366
3378 @Override
3379 public List<Organization> filterFindByLocations(long companyId, int start,
3380 int end) {
3381 return filterFindByLocations(companyId, start, end, null);
3382 }
3383
3384
3397 @Override
3398 public List<Organization> filterFindByLocations(long companyId, int start,
3399 int end, OrderByComparator<Organization> orderByComparator) {
3400 if (!InlineSQLHelperUtil.isEnabled()) {
3401 return findByLocations(companyId, start, end, orderByComparator);
3402 }
3403
3404 StringBundler query = null;
3405
3406 if (orderByComparator != null) {
3407 query = new StringBundler(3 +
3408 (orderByComparator.getOrderByFields().length * 3));
3409 }
3410 else {
3411 query = new StringBundler(3);
3412 }
3413
3414 if (getDB().isSupportsInlineDistinct()) {
3415 query.append(_FILTER_SQL_SELECT_ORGANIZATION_WHERE);
3416 }
3417 else {
3418 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1);
3419 }
3420
3421 query.append(_FINDER_COLUMN_LOCATIONS_COMPANYID_2);
3422
3423 if (!getDB().isSupportsInlineDistinct()) {
3424 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2);
3425 }
3426
3427 if (orderByComparator != null) {
3428 if (getDB().isSupportsInlineDistinct()) {
3429 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3430 orderByComparator, true);
3431 }
3432 else {
3433 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
3434 orderByComparator, true);
3435 }
3436 }
3437 else {
3438 if (getDB().isSupportsInlineDistinct()) {
3439 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
3440 }
3441 else {
3442 query.append(OrganizationModelImpl.ORDER_BY_SQL);
3443 }
3444 }
3445
3446 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3447 Organization.class.getName(),
3448 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
3449
3450 Session session = null;
3451
3452 try {
3453 session = openSession();
3454
3455 SQLQuery q = session.createSynchronizedSQLQuery(sql);
3456
3457 if (getDB().isSupportsInlineDistinct()) {
3458 q.addEntity(_FILTER_ENTITY_ALIAS, OrganizationImpl.class);
3459 }
3460 else {
3461 q.addEntity(_FILTER_ENTITY_TABLE, OrganizationImpl.class);
3462 }
3463
3464 QueryPos qPos = QueryPos.getInstance(q);
3465
3466 qPos.add(companyId);
3467
3468 return (List<Organization>)QueryUtil.list(q, getDialect(), start,
3469 end);
3470 }
3471 catch (Exception e) {
3472 throw processException(e);
3473 }
3474 finally {
3475 closeSession(session);
3476 }
3477 }
3478
3479
3488 @Override
3489 public Organization[] filterFindByLocations_PrevAndNext(
3490 long organizationId, long companyId,
3491 OrderByComparator<Organization> orderByComparator)
3492 throws NoSuchOrganizationException {
3493 if (!InlineSQLHelperUtil.isEnabled()) {
3494 return findByLocations_PrevAndNext(organizationId, companyId,
3495 orderByComparator);
3496 }
3497
3498 Organization organization = findByPrimaryKey(organizationId);
3499
3500 Session session = null;
3501
3502 try {
3503 session = openSession();
3504
3505 Organization[] array = new OrganizationImpl[3];
3506
3507 array[0] = filterGetByLocations_PrevAndNext(session, organization,
3508 companyId, orderByComparator, true);
3509
3510 array[1] = organization;
3511
3512 array[2] = filterGetByLocations_PrevAndNext(session, organization,
3513 companyId, orderByComparator, false);
3514
3515 return array;
3516 }
3517 catch (Exception e) {
3518 throw processException(e);
3519 }
3520 finally {
3521 closeSession(session);
3522 }
3523 }
3524
3525 protected Organization filterGetByLocations_PrevAndNext(Session session,
3526 Organization organization, long companyId,
3527 OrderByComparator<Organization> orderByComparator, boolean previous) {
3528 StringBundler query = null;
3529
3530 if (orderByComparator != null) {
3531 query = new StringBundler(6 +
3532 (orderByComparator.getOrderByFields().length * 6));
3533 }
3534 else {
3535 query = new StringBundler(3);
3536 }
3537
3538 if (getDB().isSupportsInlineDistinct()) {
3539 query.append(_FILTER_SQL_SELECT_ORGANIZATION_WHERE);
3540 }
3541 else {
3542 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1);
3543 }
3544
3545 query.append(_FINDER_COLUMN_LOCATIONS_COMPANYID_2);
3546
3547 if (!getDB().isSupportsInlineDistinct()) {
3548 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2);
3549 }
3550
3551 if (orderByComparator != null) {
3552 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3553
3554 if (orderByConditionFields.length > 0) {
3555 query.append(WHERE_AND);
3556 }
3557
3558 for (int i = 0; i < orderByConditionFields.length; i++) {
3559 if (getDB().isSupportsInlineDistinct()) {
3560 query.append(_ORDER_BY_ENTITY_ALIAS);
3561 }
3562 else {
3563 query.append(_ORDER_BY_ENTITY_TABLE);
3564 }
3565
3566 query.append(orderByConditionFields[i]);
3567
3568 if ((i + 1) < orderByConditionFields.length) {
3569 if (orderByComparator.isAscending() ^ previous) {
3570 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3571 }
3572 else {
3573 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3574 }
3575 }
3576 else {
3577 if (orderByComparator.isAscending() ^ previous) {
3578 query.append(WHERE_GREATER_THAN);
3579 }
3580 else {
3581 query.append(WHERE_LESSER_THAN);
3582 }
3583 }
3584 }
3585
3586 query.append(ORDER_BY_CLAUSE);
3587
3588 String[] orderByFields = orderByComparator.getOrderByFields();
3589
3590 for (int i = 0; i < orderByFields.length; i++) {
3591 if (getDB().isSupportsInlineDistinct()) {
3592 query.append(_ORDER_BY_ENTITY_ALIAS);
3593 }
3594 else {
3595 query.append(_ORDER_BY_ENTITY_TABLE);
3596 }
3597
3598 query.append(orderByFields[i]);
3599
3600 if ((i + 1) < orderByFields.length) {
3601 if (orderByComparator.isAscending() ^ previous) {
3602 query.append(ORDER_BY_ASC_HAS_NEXT);
3603 }
3604 else {
3605 query.append(ORDER_BY_DESC_HAS_NEXT);
3606 }
3607 }
3608 else {
3609 if (orderByComparator.isAscending() ^ previous) {
3610 query.append(ORDER_BY_ASC);
3611 }
3612 else {
3613 query.append(ORDER_BY_DESC);
3614 }
3615 }
3616 }
3617 }
3618 else {
3619 if (getDB().isSupportsInlineDistinct()) {
3620 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
3621 }
3622 else {
3623 query.append(OrganizationModelImpl.ORDER_BY_SQL);
3624 }
3625 }
3626
3627 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3628 Organization.class.getName(),
3629 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
3630
3631 SQLQuery q = session.createSynchronizedSQLQuery(sql);
3632
3633 q.setFirstResult(0);
3634 q.setMaxResults(2);
3635
3636 if (getDB().isSupportsInlineDistinct()) {
3637 q.addEntity(_FILTER_ENTITY_ALIAS, OrganizationImpl.class);
3638 }
3639 else {
3640 q.addEntity(_FILTER_ENTITY_TABLE, OrganizationImpl.class);
3641 }
3642
3643 QueryPos qPos = QueryPos.getInstance(q);
3644
3645 qPos.add(companyId);
3646
3647 if (orderByComparator != null) {
3648 Object[] values = orderByComparator.getOrderByConditionValues(organization);
3649
3650 for (Object value : values) {
3651 qPos.add(value);
3652 }
3653 }
3654
3655 List<Organization> list = q.list();
3656
3657 if (list.size() == 2) {
3658 return list.get(1);
3659 }
3660 else {
3661 return null;
3662 }
3663 }
3664
3665
3670 @Override
3671 public void removeByLocations(long companyId) {
3672 for (Organization organization : findByLocations(companyId,
3673 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3674 remove(organization);
3675 }
3676 }
3677
3678
3684 @Override
3685 public int countByLocations(long companyId) {
3686 FinderPath finderPath = FINDER_PATH_COUNT_BY_LOCATIONS;
3687
3688 Object[] finderArgs = new Object[] { companyId };
3689
3690 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
3691
3692 if (count == null) {
3693 StringBundler query = new StringBundler(2);
3694
3695 query.append(_SQL_COUNT_ORGANIZATION_WHERE);
3696
3697 query.append(_FINDER_COLUMN_LOCATIONS_COMPANYID_2);
3698
3699 String sql = query.toString();
3700
3701 Session session = null;
3702
3703 try {
3704 session = openSession();
3705
3706 Query q = session.createQuery(sql);
3707
3708 QueryPos qPos = QueryPos.getInstance(q);
3709
3710 qPos.add(companyId);
3711
3712 count = (Long)q.uniqueResult();
3713
3714 finderCache.putResult(finderPath, finderArgs, count);
3715 }
3716 catch (Exception e) {
3717 finderCache.removeResult(finderPath, finderArgs);
3718
3719 throw processException(e);
3720 }
3721 finally {
3722 closeSession(session);
3723 }
3724 }
3725
3726 return count.intValue();
3727 }
3728
3729
3735 @Override
3736 public int filterCountByLocations(long companyId) {
3737 if (!InlineSQLHelperUtil.isEnabled()) {
3738 return countByLocations(companyId);
3739 }
3740
3741 StringBundler query = new StringBundler(2);
3742
3743 query.append(_FILTER_SQL_COUNT_ORGANIZATION_WHERE);
3744
3745 query.append(_FINDER_COLUMN_LOCATIONS_COMPANYID_2);
3746
3747 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3748 Organization.class.getName(),
3749 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
3750
3751 Session session = null;
3752
3753 try {
3754 session = openSession();
3755
3756 SQLQuery q = session.createSynchronizedSQLQuery(sql);
3757
3758 q.addScalar(COUNT_COLUMN_NAME,
3759 com.liferay.portal.kernel.dao.orm.Type.LONG);
3760
3761 QueryPos qPos = QueryPos.getInstance(q);
3762
3763 qPos.add(companyId);
3764
3765 Long count = (Long)q.uniqueResult();
3766
3767 return count.intValue();
3768 }
3769 catch (Exception e) {
3770 throw processException(e);
3771 }
3772 finally {
3773 closeSession(session);
3774 }
3775 }
3776
3777 private static final String _FINDER_COLUMN_LOCATIONS_COMPANYID_2 = "organization.companyId = ? AND organization.parentOrganizationId != 0";
3778 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_P = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
3779 OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
3780 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_P",
3781 new String[] {
3782 Long.class.getName(), Long.class.getName(),
3783
3784 Integer.class.getName(), Integer.class.getName(),
3785 OrderByComparator.class.getName()
3786 });
3787 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
3788 OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
3789 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_P",
3790 new String[] { Long.class.getName(), Long.class.getName() },
3791 OrganizationModelImpl.COMPANYID_COLUMN_BITMASK |
3792 OrganizationModelImpl.PARENTORGANIZATIONID_COLUMN_BITMASK |
3793 OrganizationModelImpl.NAME_COLUMN_BITMASK);
3794 public static final FinderPath FINDER_PATH_COUNT_BY_C_P = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
3795 OrganizationModelImpl.FINDER_CACHE_ENABLED, Long.class,
3796 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_P",
3797 new String[] { Long.class.getName(), Long.class.getName() });
3798
3799
3806 @Override
3807 public List<Organization> findByC_P(long companyId,
3808 long parentOrganizationId) {
3809 return findByC_P(companyId, parentOrganizationId, QueryUtil.ALL_POS,
3810 QueryUtil.ALL_POS, null);
3811 }
3812
3813
3826 @Override
3827 public List<Organization> findByC_P(long companyId,
3828 long parentOrganizationId, int start, int end) {
3829 return findByC_P(companyId, parentOrganizationId, start, end, null);
3830 }
3831
3832
3846 @Override
3847 public List<Organization> findByC_P(long companyId,
3848 long parentOrganizationId, int start, int end,
3849 OrderByComparator<Organization> orderByComparator) {
3850 return findByC_P(companyId, parentOrganizationId, start, end,
3851 orderByComparator, true);
3852 }
3853
3854
3869 @Override
3870 public List<Organization> findByC_P(long companyId,
3871 long parentOrganizationId, int start, int end,
3872 OrderByComparator<Organization> orderByComparator,
3873 boolean retrieveFromCache) {
3874 boolean pagination = true;
3875 FinderPath finderPath = null;
3876 Object[] finderArgs = null;
3877
3878 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3879 (orderByComparator == null)) {
3880 pagination = false;
3881 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P;
3882 finderArgs = new Object[] { companyId, parentOrganizationId };
3883 }
3884 else {
3885 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_P;
3886 finderArgs = new Object[] {
3887 companyId, parentOrganizationId,
3888
3889 start, end, orderByComparator
3890 };
3891 }
3892
3893 List<Organization> list = null;
3894
3895 if (retrieveFromCache) {
3896 list = (List<Organization>)finderCache.getResult(finderPath,
3897 finderArgs, this);
3898
3899 if ((list != null) && !list.isEmpty()) {
3900 for (Organization organization : list) {
3901 if ((companyId != organization.getCompanyId()) ||
3902 (parentOrganizationId != organization.getParentOrganizationId())) {
3903 list = null;
3904
3905 break;
3906 }
3907 }
3908 }
3909 }
3910
3911 if (list == null) {
3912 StringBundler query = null;
3913
3914 if (orderByComparator != null) {
3915 query = new StringBundler(4 +
3916 (orderByComparator.getOrderByFields().length * 3));
3917 }
3918 else {
3919 query = new StringBundler(4);
3920 }
3921
3922 query.append(_SQL_SELECT_ORGANIZATION_WHERE);
3923
3924 query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
3925
3926 query.append(_FINDER_COLUMN_C_P_PARENTORGANIZATIONID_2);
3927
3928 if (orderByComparator != null) {
3929 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3930 orderByComparator);
3931 }
3932 else
3933 if (pagination) {
3934 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
3935 }
3936
3937 String sql = query.toString();
3938
3939 Session session = null;
3940
3941 try {
3942 session = openSession();
3943
3944 Query q = session.createQuery(sql);
3945
3946 QueryPos qPos = QueryPos.getInstance(q);
3947
3948 qPos.add(companyId);
3949
3950 qPos.add(parentOrganizationId);
3951
3952 if (!pagination) {
3953 list = (List<Organization>)QueryUtil.list(q, getDialect(),
3954 start, end, false);
3955
3956 Collections.sort(list);
3957
3958 list = Collections.unmodifiableList(list);
3959 }
3960 else {
3961 list = (List<Organization>)QueryUtil.list(q, getDialect(),
3962 start, end);
3963 }
3964
3965 cacheResult(list);
3966
3967 finderCache.putResult(finderPath, finderArgs, list);
3968 }
3969 catch (Exception e) {
3970 finderCache.removeResult(finderPath, finderArgs);
3971
3972 throw processException(e);
3973 }
3974 finally {
3975 closeSession(session);
3976 }
3977 }
3978
3979 return list;
3980 }
3981
3982
3991 @Override
3992 public Organization findByC_P_First(long companyId,
3993 long parentOrganizationId,
3994 OrderByComparator<Organization> orderByComparator)
3995 throws NoSuchOrganizationException {
3996 Organization organization = fetchByC_P_First(companyId,
3997 parentOrganizationId, orderByComparator);
3998
3999 if (organization != null) {
4000 return organization;
4001 }
4002
4003 StringBundler msg = new StringBundler(6);
4004
4005 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4006
4007 msg.append("companyId=");
4008 msg.append(companyId);
4009
4010 msg.append(", parentOrganizationId=");
4011 msg.append(parentOrganizationId);
4012
4013 msg.append(StringPool.CLOSE_CURLY_BRACE);
4014
4015 throw new NoSuchOrganizationException(msg.toString());
4016 }
4017
4018
4026 @Override
4027 public Organization fetchByC_P_First(long companyId,
4028 long parentOrganizationId,
4029 OrderByComparator<Organization> orderByComparator) {
4030 List<Organization> list = findByC_P(companyId, parentOrganizationId, 0,
4031 1, orderByComparator);
4032
4033 if (!list.isEmpty()) {
4034 return list.get(0);
4035 }
4036
4037 return null;
4038 }
4039
4040
4049 @Override
4050 public Organization findByC_P_Last(long companyId,
4051 long parentOrganizationId,
4052 OrderByComparator<Organization> orderByComparator)
4053 throws NoSuchOrganizationException {
4054 Organization organization = fetchByC_P_Last(companyId,
4055 parentOrganizationId, orderByComparator);
4056
4057 if (organization != null) {
4058 return organization;
4059 }
4060
4061 StringBundler msg = new StringBundler(6);
4062
4063 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4064
4065 msg.append("companyId=");
4066 msg.append(companyId);
4067
4068 msg.append(", parentOrganizationId=");
4069 msg.append(parentOrganizationId);
4070
4071 msg.append(StringPool.CLOSE_CURLY_BRACE);
4072
4073 throw new NoSuchOrganizationException(msg.toString());
4074 }
4075
4076
4084 @Override
4085 public Organization fetchByC_P_Last(long companyId,
4086 long parentOrganizationId,
4087 OrderByComparator<Organization> orderByComparator) {
4088 int count = countByC_P(companyId, parentOrganizationId);
4089
4090 if (count == 0) {
4091 return null;
4092 }
4093
4094 List<Organization> list = findByC_P(companyId, parentOrganizationId,
4095 count - 1, count, orderByComparator);
4096
4097 if (!list.isEmpty()) {
4098 return list.get(0);
4099 }
4100
4101 return null;
4102 }
4103
4104
4114 @Override
4115 public Organization[] findByC_P_PrevAndNext(long organizationId,
4116 long companyId, long parentOrganizationId,
4117 OrderByComparator<Organization> orderByComparator)
4118 throws NoSuchOrganizationException {
4119 Organization organization = findByPrimaryKey(organizationId);
4120
4121 Session session = null;
4122
4123 try {
4124 session = openSession();
4125
4126 Organization[] array = new OrganizationImpl[3];
4127
4128 array[0] = getByC_P_PrevAndNext(session, organization, companyId,
4129 parentOrganizationId, orderByComparator, true);
4130
4131 array[1] = organization;
4132
4133 array[2] = getByC_P_PrevAndNext(session, organization, companyId,
4134 parentOrganizationId, orderByComparator, false);
4135
4136 return array;
4137 }
4138 catch (Exception e) {
4139 throw processException(e);
4140 }
4141 finally {
4142 closeSession(session);
4143 }
4144 }
4145
4146 protected Organization getByC_P_PrevAndNext(Session session,
4147 Organization organization, long companyId, long parentOrganizationId,
4148 OrderByComparator<Organization> orderByComparator, boolean previous) {
4149 StringBundler query = null;
4150
4151 if (orderByComparator != null) {
4152 query = new StringBundler(6 +
4153 (orderByComparator.getOrderByFields().length * 6));
4154 }
4155 else {
4156 query = new StringBundler(3);
4157 }
4158
4159 query.append(_SQL_SELECT_ORGANIZATION_WHERE);
4160
4161 query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
4162
4163 query.append(_FINDER_COLUMN_C_P_PARENTORGANIZATIONID_2);
4164
4165 if (orderByComparator != null) {
4166 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4167
4168 if (orderByConditionFields.length > 0) {
4169 query.append(WHERE_AND);
4170 }
4171
4172 for (int i = 0; i < orderByConditionFields.length; i++) {
4173 query.append(_ORDER_BY_ENTITY_ALIAS);
4174 query.append(orderByConditionFields[i]);
4175
4176 if ((i + 1) < orderByConditionFields.length) {
4177 if (orderByComparator.isAscending() ^ previous) {
4178 query.append(WHERE_GREATER_THAN_HAS_NEXT);
4179 }
4180 else {
4181 query.append(WHERE_LESSER_THAN_HAS_NEXT);
4182 }
4183 }
4184 else {
4185 if (orderByComparator.isAscending() ^ previous) {
4186 query.append(WHERE_GREATER_THAN);
4187 }
4188 else {
4189 query.append(WHERE_LESSER_THAN);
4190 }
4191 }
4192 }
4193
4194 query.append(ORDER_BY_CLAUSE);
4195
4196 String[] orderByFields = orderByComparator.getOrderByFields();
4197
4198 for (int i = 0; i < orderByFields.length; i++) {
4199 query.append(_ORDER_BY_ENTITY_ALIAS);
4200 query.append(orderByFields[i]);
4201
4202 if ((i + 1) < orderByFields.length) {
4203 if (orderByComparator.isAscending() ^ previous) {
4204 query.append(ORDER_BY_ASC_HAS_NEXT);
4205 }
4206 else {
4207 query.append(ORDER_BY_DESC_HAS_NEXT);
4208 }
4209 }
4210 else {
4211 if (orderByComparator.isAscending() ^ previous) {
4212 query.append(ORDER_BY_ASC);
4213 }
4214 else {
4215 query.append(ORDER_BY_DESC);
4216 }
4217 }
4218 }
4219 }
4220 else {
4221 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
4222 }
4223
4224 String sql = query.toString();
4225
4226 Query q = session.createQuery(sql);
4227
4228 q.setFirstResult(0);
4229 q.setMaxResults(2);
4230
4231 QueryPos qPos = QueryPos.getInstance(q);
4232
4233 qPos.add(companyId);
4234
4235 qPos.add(parentOrganizationId);
4236
4237 if (orderByComparator != null) {
4238 Object[] values = orderByComparator.getOrderByConditionValues(organization);
4239
4240 for (Object value : values) {
4241 qPos.add(value);
4242 }
4243 }
4244
4245 List<Organization> list = q.list();
4246
4247 if (list.size() == 2) {
4248 return list.get(1);
4249 }
4250 else {
4251 return null;
4252 }
4253 }
4254
4255
4262 @Override
4263 public List<Organization> filterFindByC_P(long companyId,
4264 long parentOrganizationId) {
4265 return filterFindByC_P(companyId, parentOrganizationId,
4266 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
4267 }
4268
4269
4282 @Override
4283 public List<Organization> filterFindByC_P(long companyId,
4284 long parentOrganizationId, int start, int end) {
4285 return filterFindByC_P(companyId, parentOrganizationId, start, end, null);
4286 }
4287
4288
4302 @Override
4303 public List<Organization> filterFindByC_P(long companyId,
4304 long parentOrganizationId, int start, int end,
4305 OrderByComparator<Organization> orderByComparator) {
4306 if (!InlineSQLHelperUtil.isEnabled()) {
4307 return findByC_P(companyId, parentOrganizationId, start, end,
4308 orderByComparator);
4309 }
4310
4311 StringBundler query = null;
4312
4313 if (orderByComparator != null) {
4314 query = new StringBundler(4 +
4315 (orderByComparator.getOrderByFields().length * 3));
4316 }
4317 else {
4318 query = new StringBundler(4);
4319 }
4320
4321 if (getDB().isSupportsInlineDistinct()) {
4322 query.append(_FILTER_SQL_SELECT_ORGANIZATION_WHERE);
4323 }
4324 else {
4325 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1);
4326 }
4327
4328 query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
4329
4330 query.append(_FINDER_COLUMN_C_P_PARENTORGANIZATIONID_2);
4331
4332 if (!getDB().isSupportsInlineDistinct()) {
4333 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2);
4334 }
4335
4336 if (orderByComparator != null) {
4337 if (getDB().isSupportsInlineDistinct()) {
4338 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4339 orderByComparator, true);
4340 }
4341 else {
4342 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
4343 orderByComparator, true);
4344 }
4345 }
4346 else {
4347 if (getDB().isSupportsInlineDistinct()) {
4348 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
4349 }
4350 else {
4351 query.append(OrganizationModelImpl.ORDER_BY_SQL);
4352 }
4353 }
4354
4355 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4356 Organization.class.getName(),
4357 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
4358
4359 Session session = null;
4360
4361 try {
4362 session = openSession();
4363
4364 SQLQuery q = session.createSynchronizedSQLQuery(sql);
4365
4366 if (getDB().isSupportsInlineDistinct()) {
4367 q.addEntity(_FILTER_ENTITY_ALIAS, OrganizationImpl.class);
4368 }
4369 else {
4370 q.addEntity(_FILTER_ENTITY_TABLE, OrganizationImpl.class);
4371 }
4372
4373 QueryPos qPos = QueryPos.getInstance(q);
4374
4375 qPos.add(companyId);
4376
4377 qPos.add(parentOrganizationId);
4378
4379 return (List<Organization>)QueryUtil.list(q, getDialect(), start,
4380 end);
4381 }
4382 catch (Exception e) {
4383 throw processException(e);
4384 }
4385 finally {
4386 closeSession(session);
4387 }
4388 }
4389
4390
4400 @Override
4401 public Organization[] filterFindByC_P_PrevAndNext(long organizationId,
4402 long companyId, long parentOrganizationId,
4403 OrderByComparator<Organization> orderByComparator)
4404 throws NoSuchOrganizationException {
4405 if (!InlineSQLHelperUtil.isEnabled()) {
4406 return findByC_P_PrevAndNext(organizationId, companyId,
4407 parentOrganizationId, orderByComparator);
4408 }
4409
4410 Organization organization = findByPrimaryKey(organizationId);
4411
4412 Session session = null;
4413
4414 try {
4415 session = openSession();
4416
4417 Organization[] array = new OrganizationImpl[3];
4418
4419 array[0] = filterGetByC_P_PrevAndNext(session, organization,
4420 companyId, parentOrganizationId, orderByComparator, true);
4421
4422 array[1] = organization;
4423
4424 array[2] = filterGetByC_P_PrevAndNext(session, organization,
4425 companyId, parentOrganizationId, orderByComparator, false);
4426
4427 return array;
4428 }
4429 catch (Exception e) {
4430 throw processException(e);
4431 }
4432 finally {
4433 closeSession(session);
4434 }
4435 }
4436
4437 protected Organization filterGetByC_P_PrevAndNext(Session session,
4438 Organization organization, long companyId, long parentOrganizationId,
4439 OrderByComparator<Organization> orderByComparator, boolean previous) {
4440 StringBundler query = null;
4441
4442 if (orderByComparator != null) {
4443 query = new StringBundler(6 +
4444 (orderByComparator.getOrderByFields().length * 6));
4445 }
4446 else {
4447 query = new StringBundler(3);
4448 }
4449
4450 if (getDB().isSupportsInlineDistinct()) {
4451 query.append(_FILTER_SQL_SELECT_ORGANIZATION_WHERE);
4452 }
4453 else {
4454 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1);
4455 }
4456
4457 query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
4458
4459 query.append(_FINDER_COLUMN_C_P_PARENTORGANIZATIONID_2);
4460
4461 if (!getDB().isSupportsInlineDistinct()) {
4462 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2);
4463 }
4464
4465 if (orderByComparator != null) {
4466 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4467
4468 if (orderByConditionFields.length > 0) {
4469 query.append(WHERE_AND);
4470 }
4471
4472 for (int i = 0; i < orderByConditionFields.length; i++) {
4473 if (getDB().isSupportsInlineDistinct()) {
4474 query.append(_ORDER_BY_ENTITY_ALIAS);
4475 }
4476 else {
4477 query.append(_ORDER_BY_ENTITY_TABLE);
4478 }
4479
4480 query.append(orderByConditionFields[i]);
4481
4482 if ((i + 1) < orderByConditionFields.length) {
4483 if (orderByComparator.isAscending() ^ previous) {
4484 query.append(WHERE_GREATER_THAN_HAS_NEXT);
4485 }
4486 else {
4487 query.append(WHERE_LESSER_THAN_HAS_NEXT);
4488 }
4489 }
4490 else {
4491 if (orderByComparator.isAscending() ^ previous) {
4492 query.append(WHERE_GREATER_THAN);
4493 }
4494 else {
4495 query.append(WHERE_LESSER_THAN);
4496 }
4497 }
4498 }
4499
4500 query.append(ORDER_BY_CLAUSE);
4501
4502 String[] orderByFields = orderByComparator.getOrderByFields();
4503
4504 for (int i = 0; i < orderByFields.length; i++) {
4505 if (getDB().isSupportsInlineDistinct()) {
4506 query.append(_ORDER_BY_ENTITY_ALIAS);
4507 }
4508 else {
4509 query.append(_ORDER_BY_ENTITY_TABLE);
4510 }
4511
4512 query.append(orderByFields[i]);
4513
4514 if ((i + 1) < orderByFields.length) {
4515 if (orderByComparator.isAscending() ^ previous) {
4516 query.append(ORDER_BY_ASC_HAS_NEXT);
4517 }
4518 else {
4519 query.append(ORDER_BY_DESC_HAS_NEXT);
4520 }
4521 }
4522 else {
4523 if (orderByComparator.isAscending() ^ previous) {
4524 query.append(ORDER_BY_ASC);
4525 }
4526 else {
4527 query.append(ORDER_BY_DESC);
4528 }
4529 }
4530 }
4531 }
4532 else {
4533 if (getDB().isSupportsInlineDistinct()) {
4534 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
4535 }
4536 else {
4537 query.append(OrganizationModelImpl.ORDER_BY_SQL);
4538 }
4539 }
4540
4541 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4542 Organization.class.getName(),
4543 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
4544
4545 SQLQuery q = session.createSynchronizedSQLQuery(sql);
4546
4547 q.setFirstResult(0);
4548 q.setMaxResults(2);
4549
4550 if (getDB().isSupportsInlineDistinct()) {
4551 q.addEntity(_FILTER_ENTITY_ALIAS, OrganizationImpl.class);
4552 }
4553 else {
4554 q.addEntity(_FILTER_ENTITY_TABLE, OrganizationImpl.class);
4555 }
4556
4557 QueryPos qPos = QueryPos.getInstance(q);
4558
4559 qPos.add(companyId);
4560
4561 qPos.add(parentOrganizationId);
4562
4563 if (orderByComparator != null) {
4564 Object[] values = orderByComparator.getOrderByConditionValues(organization);
4565
4566 for (Object value : values) {
4567 qPos.add(value);
4568 }
4569 }
4570
4571 List<Organization> list = q.list();
4572
4573 if (list.size() == 2) {
4574 return list.get(1);
4575 }
4576 else {
4577 return null;
4578 }
4579 }
4580
4581
4587 @Override
4588 public void removeByC_P(long companyId, long parentOrganizationId) {
4589 for (Organization organization : findByC_P(companyId,
4590 parentOrganizationId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
4591 remove(organization);
4592 }
4593 }
4594
4595
4602 @Override
4603 public int countByC_P(long companyId, long parentOrganizationId) {
4604 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_P;
4605
4606 Object[] finderArgs = new Object[] { companyId, parentOrganizationId };
4607
4608 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
4609
4610 if (count == null) {
4611 StringBundler query = new StringBundler(3);
4612
4613 query.append(_SQL_COUNT_ORGANIZATION_WHERE);
4614
4615 query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
4616
4617 query.append(_FINDER_COLUMN_C_P_PARENTORGANIZATIONID_2);
4618
4619 String sql = query.toString();
4620
4621 Session session = null;
4622
4623 try {
4624 session = openSession();
4625
4626 Query q = session.createQuery(sql);
4627
4628 QueryPos qPos = QueryPos.getInstance(q);
4629
4630 qPos.add(companyId);
4631
4632 qPos.add(parentOrganizationId);
4633
4634 count = (Long)q.uniqueResult();
4635
4636 finderCache.putResult(finderPath, finderArgs, count);
4637 }
4638 catch (Exception e) {
4639 finderCache.removeResult(finderPath, finderArgs);
4640
4641 throw processException(e);
4642 }
4643 finally {
4644 closeSession(session);
4645 }
4646 }
4647
4648 return count.intValue();
4649 }
4650
4651
4658 @Override
4659 public int filterCountByC_P(long companyId, long parentOrganizationId) {
4660 if (!InlineSQLHelperUtil.isEnabled()) {
4661 return countByC_P(companyId, parentOrganizationId);
4662 }
4663
4664 StringBundler query = new StringBundler(3);
4665
4666 query.append(_FILTER_SQL_COUNT_ORGANIZATION_WHERE);
4667
4668 query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
4669
4670 query.append(_FINDER_COLUMN_C_P_PARENTORGANIZATIONID_2);
4671
4672 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4673 Organization.class.getName(),
4674 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
4675
4676 Session session = null;
4677
4678 try {
4679 session = openSession();
4680
4681 SQLQuery q = session.createSynchronizedSQLQuery(sql);
4682
4683 q.addScalar(COUNT_COLUMN_NAME,
4684 com.liferay.portal.kernel.dao.orm.Type.LONG);
4685
4686 QueryPos qPos = QueryPos.getInstance(q);
4687
4688 qPos.add(companyId);
4689
4690 qPos.add(parentOrganizationId);
4691
4692 Long count = (Long)q.uniqueResult();
4693
4694 return count.intValue();
4695 }
4696 catch (Exception e) {
4697 throw processException(e);
4698 }
4699 finally {
4700 closeSession(session);
4701 }
4702 }
4703
4704 private static final String _FINDER_COLUMN_C_P_COMPANYID_2 = "organization.companyId = ? AND ";
4705 private static final String _FINDER_COLUMN_C_P_PARENTORGANIZATIONID_2 = "organization.parentOrganizationId = ?";
4706 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_T = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
4707 OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
4708 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_T",
4709 new String[] {
4710 Long.class.getName(), String.class.getName(),
4711
4712 Integer.class.getName(), Integer.class.getName(),
4713 OrderByComparator.class.getName()
4714 });
4715 public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_T = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
4716 OrganizationModelImpl.FINDER_CACHE_ENABLED, Long.class,
4717 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByC_T",
4718 new String[] { Long.class.getName(), String.class.getName() });
4719
4720
4727 @Override
4728 public List<Organization> findByC_T(long companyId, String treePath) {
4729 return findByC_T(companyId, treePath, QueryUtil.ALL_POS,
4730 QueryUtil.ALL_POS, null);
4731 }
4732
4733
4746 @Override
4747 public List<Organization> findByC_T(long companyId, String treePath,
4748 int start, int end) {
4749 return findByC_T(companyId, treePath, start, end, null);
4750 }
4751
4752
4766 @Override
4767 public List<Organization> findByC_T(long companyId, String treePath,
4768 int start, int end, OrderByComparator<Organization> orderByComparator) {
4769 return findByC_T(companyId, treePath, start, end, orderByComparator,
4770 true);
4771 }
4772
4773
4788 @Override
4789 public List<Organization> findByC_T(long companyId, String treePath,
4790 int start, int end, OrderByComparator<Organization> orderByComparator,
4791 boolean retrieveFromCache) {
4792 boolean pagination = true;
4793 FinderPath finderPath = null;
4794 Object[] finderArgs = null;
4795
4796 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_T;
4797 finderArgs = new Object[] {
4798 companyId, treePath,
4799
4800 start, end, orderByComparator
4801 };
4802
4803 List<Organization> list = null;
4804
4805 if (retrieveFromCache) {
4806 list = (List<Organization>)finderCache.getResult(finderPath,
4807 finderArgs, this);
4808
4809 if ((list != null) && !list.isEmpty()) {
4810 for (Organization organization : list) {
4811 if ((companyId != organization.getCompanyId()) ||
4812 !StringUtil.wildcardMatches(
4813 organization.getTreePath(), treePath,
4814 CharPool.UNDERLINE, CharPool.PERCENT,
4815 CharPool.BACK_SLASH, true)) {
4816 list = null;
4817
4818 break;
4819 }
4820 }
4821 }
4822 }
4823
4824 if (list == null) {
4825 StringBundler query = null;
4826
4827 if (orderByComparator != null) {
4828 query = new StringBundler(4 +
4829 (orderByComparator.getOrderByFields().length * 3));
4830 }
4831 else {
4832 query = new StringBundler(4);
4833 }
4834
4835 query.append(_SQL_SELECT_ORGANIZATION_WHERE);
4836
4837 query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
4838
4839 boolean bindTreePath = false;
4840
4841 if (treePath == null) {
4842 query.append(_FINDER_COLUMN_C_T_TREEPATH_1);
4843 }
4844 else if (treePath.equals(StringPool.BLANK)) {
4845 query.append(_FINDER_COLUMN_C_T_TREEPATH_3);
4846 }
4847 else {
4848 bindTreePath = true;
4849
4850 query.append(_FINDER_COLUMN_C_T_TREEPATH_2);
4851 }
4852
4853 if (orderByComparator != null) {
4854 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4855 orderByComparator);
4856 }
4857 else
4858 if (pagination) {
4859 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
4860 }
4861
4862 String sql = query.toString();
4863
4864 Session session = null;
4865
4866 try {
4867 session = openSession();
4868
4869 Query q = session.createQuery(sql);
4870
4871 QueryPos qPos = QueryPos.getInstance(q);
4872
4873 qPos.add(companyId);
4874
4875 if (bindTreePath) {
4876 qPos.add(treePath);
4877 }
4878
4879 if (!pagination) {
4880 list = (List<Organization>)QueryUtil.list(q, getDialect(),
4881 start, end, false);
4882
4883 Collections.sort(list);
4884
4885 list = Collections.unmodifiableList(list);
4886 }
4887 else {
4888 list = (List<Organization>)QueryUtil.list(q, getDialect(),
4889 start, end);
4890 }
4891
4892 cacheResult(list);
4893
4894 finderCache.putResult(finderPath, finderArgs, list);
4895 }
4896 catch (Exception e) {
4897 finderCache.removeResult(finderPath, finderArgs);
4898
4899 throw processException(e);
4900 }
4901 finally {
4902 closeSession(session);
4903 }
4904 }
4905
4906 return list;
4907 }
4908
4909
4918 @Override
4919 public Organization findByC_T_First(long companyId, String treePath,
4920 OrderByComparator<Organization> orderByComparator)
4921 throws NoSuchOrganizationException {
4922 Organization organization = fetchByC_T_First(companyId, treePath,
4923 orderByComparator);
4924
4925 if (organization != null) {
4926 return organization;
4927 }
4928
4929 StringBundler msg = new StringBundler(6);
4930
4931 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4932
4933 msg.append("companyId=");
4934 msg.append(companyId);
4935
4936 msg.append(", treePath=");
4937 msg.append(treePath);
4938
4939 msg.append(StringPool.CLOSE_CURLY_BRACE);
4940
4941 throw new NoSuchOrganizationException(msg.toString());
4942 }
4943
4944
4952 @Override
4953 public Organization fetchByC_T_First(long companyId, String treePath,
4954 OrderByComparator<Organization> orderByComparator) {
4955 List<Organization> list = findByC_T(companyId, treePath, 0, 1,
4956 orderByComparator);
4957
4958 if (!list.isEmpty()) {
4959 return list.get(0);
4960 }
4961
4962 return null;
4963 }
4964
4965
4974 @Override
4975 public Organization findByC_T_Last(long companyId, String treePath,
4976 OrderByComparator<Organization> orderByComparator)
4977 throws NoSuchOrganizationException {
4978 Organization organization = fetchByC_T_Last(companyId, treePath,
4979 orderByComparator);
4980
4981 if (organization != null) {
4982 return organization;
4983 }
4984
4985 StringBundler msg = new StringBundler(6);
4986
4987 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4988
4989 msg.append("companyId=");
4990 msg.append(companyId);
4991
4992 msg.append(", treePath=");
4993 msg.append(treePath);
4994
4995 msg.append(StringPool.CLOSE_CURLY_BRACE);
4996
4997 throw new NoSuchOrganizationException(msg.toString());
4998 }
4999
5000
5008 @Override
5009 public Organization fetchByC_T_Last(long companyId, String treePath,
5010 OrderByComparator<Organization> orderByComparator) {
5011 int count = countByC_T(companyId, treePath);
5012
5013 if (count == 0) {
5014 return null;
5015 }
5016
5017 List<Organization> list = findByC_T(companyId, treePath, count - 1,
5018 count, orderByComparator);
5019
5020 if (!list.isEmpty()) {
5021 return list.get(0);
5022 }
5023
5024 return null;
5025 }
5026
5027
5037 @Override
5038 public Organization[] findByC_T_PrevAndNext(long organizationId,
5039 long companyId, String treePath,
5040 OrderByComparator<Organization> orderByComparator)
5041 throws NoSuchOrganizationException {
5042 Organization organization = findByPrimaryKey(organizationId);
5043
5044 Session session = null;
5045
5046 try {
5047 session = openSession();
5048
5049 Organization[] array = new OrganizationImpl[3];
5050
5051 array[0] = getByC_T_PrevAndNext(session, organization, companyId,
5052 treePath, orderByComparator, true);
5053
5054 array[1] = organization;
5055
5056 array[2] = getByC_T_PrevAndNext(session, organization, companyId,
5057 treePath, orderByComparator, false);
5058
5059 return array;
5060 }
5061 catch (Exception e) {
5062 throw processException(e);
5063 }
5064 finally {
5065 closeSession(session);
5066 }
5067 }
5068
5069 protected Organization getByC_T_PrevAndNext(Session session,
5070 Organization organization, long companyId, String treePath,
5071 OrderByComparator<Organization> orderByComparator, boolean previous) {
5072 StringBundler query = null;
5073
5074 if (orderByComparator != null) {
5075 query = new StringBundler(6 +
5076 (orderByComparator.getOrderByFields().length * 6));
5077 }
5078 else {
5079 query = new StringBundler(3);
5080 }
5081
5082 query.append(_SQL_SELECT_ORGANIZATION_WHERE);
5083
5084 query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
5085
5086 boolean bindTreePath = false;
5087
5088 if (treePath == null) {
5089 query.append(_FINDER_COLUMN_C_T_TREEPATH_1);
5090 }
5091 else if (treePath.equals(StringPool.BLANK)) {
5092 query.append(_FINDER_COLUMN_C_T_TREEPATH_3);
5093 }
5094 else {
5095 bindTreePath = true;
5096
5097 query.append(_FINDER_COLUMN_C_T_TREEPATH_2);
5098 }
5099
5100 if (orderByComparator != null) {
5101 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5102
5103 if (orderByConditionFields.length > 0) {
5104 query.append(WHERE_AND);
5105 }
5106
5107 for (int i = 0; i < orderByConditionFields.length; i++) {
5108 query.append(_ORDER_BY_ENTITY_ALIAS);
5109 query.append(orderByConditionFields[i]);
5110
5111 if ((i + 1) < orderByConditionFields.length) {
5112 if (orderByComparator.isAscending() ^ previous) {
5113 query.append(WHERE_GREATER_THAN_HAS_NEXT);
5114 }
5115 else {
5116 query.append(WHERE_LESSER_THAN_HAS_NEXT);
5117 }
5118 }
5119 else {
5120 if (orderByComparator.isAscending() ^ previous) {
5121 query.append(WHERE_GREATER_THAN);
5122 }
5123 else {
5124 query.append(WHERE_LESSER_THAN);
5125 }
5126 }
5127 }
5128
5129 query.append(ORDER_BY_CLAUSE);
5130
5131 String[] orderByFields = orderByComparator.getOrderByFields();
5132
5133 for (int i = 0; i < orderByFields.length; i++) {
5134 query.append(_ORDER_BY_ENTITY_ALIAS);
5135 query.append(orderByFields[i]);
5136
5137 if ((i + 1) < orderByFields.length) {
5138 if (orderByComparator.isAscending() ^ previous) {
5139 query.append(ORDER_BY_ASC_HAS_NEXT);
5140 }
5141 else {
5142 query.append(ORDER_BY_DESC_HAS_NEXT);
5143 }
5144 }
5145 else {
5146 if (orderByComparator.isAscending() ^ previous) {
5147 query.append(ORDER_BY_ASC);
5148 }
5149 else {
5150 query.append(ORDER_BY_DESC);
5151 }
5152 }
5153 }
5154 }
5155 else {
5156 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
5157 }
5158
5159 String sql = query.toString();
5160
5161 Query q = session.createQuery(sql);
5162
5163 q.setFirstResult(0);
5164 q.setMaxResults(2);
5165
5166 QueryPos qPos = QueryPos.getInstance(q);
5167
5168 qPos.add(companyId);
5169
5170 if (bindTreePath) {
5171 qPos.add(treePath);
5172 }
5173
5174 if (orderByComparator != null) {
5175 Object[] values = orderByComparator.getOrderByConditionValues(organization);
5176
5177 for (Object value : values) {
5178 qPos.add(value);
5179 }
5180 }
5181
5182 List<Organization> list = q.list();
5183
5184 if (list.size() == 2) {
5185 return list.get(1);
5186 }
5187 else {
5188 return null;
5189 }
5190 }
5191
5192
5199 @Override
5200 public List<Organization> filterFindByC_T(long companyId, String treePath) {
5201 return filterFindByC_T(companyId, treePath, QueryUtil.ALL_POS,
5202 QueryUtil.ALL_POS, null);
5203 }
5204
5205
5218 @Override
5219 public List<Organization> filterFindByC_T(long companyId, String treePath,
5220 int start, int end) {
5221 return filterFindByC_T(companyId, treePath, start, end, null);
5222 }
5223
5224
5238 @Override
5239 public List<Organization> filterFindByC_T(long companyId, String treePath,
5240 int start, int end, OrderByComparator<Organization> orderByComparator) {
5241 if (!InlineSQLHelperUtil.isEnabled()) {
5242 return findByC_T(companyId, treePath, start, end, orderByComparator);
5243 }
5244
5245 StringBundler query = null;
5246
5247 if (orderByComparator != null) {
5248 query = new StringBundler(4 +
5249 (orderByComparator.getOrderByFields().length * 3));
5250 }
5251 else {
5252 query = new StringBundler(4);
5253 }
5254
5255 if (getDB().isSupportsInlineDistinct()) {
5256 query.append(_FILTER_SQL_SELECT_ORGANIZATION_WHERE);
5257 }
5258 else {
5259 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1);
5260 }
5261
5262 query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
5263
5264 boolean bindTreePath = false;
5265
5266 if (treePath == null) {
5267 query.append(_FINDER_COLUMN_C_T_TREEPATH_1);
5268 }
5269 else if (treePath.equals(StringPool.BLANK)) {
5270 query.append(_FINDER_COLUMN_C_T_TREEPATH_3);
5271 }
5272 else {
5273 bindTreePath = true;
5274
5275 query.append(_FINDER_COLUMN_C_T_TREEPATH_2);
5276 }
5277
5278 if (!getDB().isSupportsInlineDistinct()) {
5279 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2);
5280 }
5281
5282 if (orderByComparator != null) {
5283 if (getDB().isSupportsInlineDistinct()) {
5284 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5285 orderByComparator, true);
5286 }
5287 else {
5288 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
5289 orderByComparator, true);
5290 }
5291 }
5292 else {
5293 if (getDB().isSupportsInlineDistinct()) {
5294 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
5295 }
5296 else {
5297 query.append(OrganizationModelImpl.ORDER_BY_SQL);
5298 }
5299 }
5300
5301 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5302 Organization.class.getName(),
5303 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
5304
5305 Session session = null;
5306
5307 try {
5308 session = openSession();
5309
5310 SQLQuery q = session.createSynchronizedSQLQuery(sql);
5311
5312 if (getDB().isSupportsInlineDistinct()) {
5313 q.addEntity(_FILTER_ENTITY_ALIAS, OrganizationImpl.class);
5314 }
5315 else {
5316 q.addEntity(_FILTER_ENTITY_TABLE, OrganizationImpl.class);
5317 }
5318
5319 QueryPos qPos = QueryPos.getInstance(q);
5320
5321 qPos.add(companyId);
5322
5323 if (bindTreePath) {
5324 qPos.add(treePath);
5325 }
5326
5327 return (List<Organization>)QueryUtil.list(q, getDialect(), start,
5328 end);
5329 }
5330 catch (Exception e) {
5331 throw processException(e);
5332 }
5333 finally {
5334 closeSession(session);
5335 }
5336 }
5337
5338
5348 @Override
5349 public Organization[] filterFindByC_T_PrevAndNext(long organizationId,
5350 long companyId, String treePath,
5351 OrderByComparator<Organization> orderByComparator)
5352 throws NoSuchOrganizationException {
5353 if (!InlineSQLHelperUtil.isEnabled()) {
5354 return findByC_T_PrevAndNext(organizationId, companyId, treePath,
5355 orderByComparator);
5356 }
5357
5358 Organization organization = findByPrimaryKey(organizationId);
5359
5360 Session session = null;
5361
5362 try {
5363 session = openSession();
5364
5365 Organization[] array = new OrganizationImpl[3];
5366
5367 array[0] = filterGetByC_T_PrevAndNext(session, organization,
5368 companyId, treePath, orderByComparator, true);
5369
5370 array[1] = organization;
5371
5372 array[2] = filterGetByC_T_PrevAndNext(session, organization,
5373 companyId, treePath, orderByComparator, false);
5374
5375 return array;
5376 }
5377 catch (Exception e) {
5378 throw processException(e);
5379 }
5380 finally {
5381 closeSession(session);
5382 }
5383 }
5384
5385 protected Organization filterGetByC_T_PrevAndNext(Session session,
5386 Organization organization, long companyId, String treePath,
5387 OrderByComparator<Organization> orderByComparator, boolean previous) {
5388 StringBundler query = null;
5389
5390 if (orderByComparator != null) {
5391 query = new StringBundler(6 +
5392 (orderByComparator.getOrderByFields().length * 6));
5393 }
5394 else {
5395 query = new StringBundler(3);
5396 }
5397
5398 if (getDB().isSupportsInlineDistinct()) {
5399 query.append(_FILTER_SQL_SELECT_ORGANIZATION_WHERE);
5400 }
5401 else {
5402 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1);
5403 }
5404
5405 query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
5406
5407 boolean bindTreePath = false;
5408
5409 if (treePath == null) {
5410 query.append(_FINDER_COLUMN_C_T_TREEPATH_1);
5411 }
5412 else if (treePath.equals(StringPool.BLANK)) {
5413 query.append(_FINDER_COLUMN_C_T_TREEPATH_3);
5414 }
5415 else {
5416 bindTreePath = true;
5417
5418 query.append(_FINDER_COLUMN_C_T_TREEPATH_2);
5419 }
5420
5421 if (!getDB().isSupportsInlineDistinct()) {
5422 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2);
5423 }
5424
5425 if (orderByComparator != null) {
5426 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5427
5428 if (orderByConditionFields.length > 0) {
5429 query.append(WHERE_AND);
5430 }
5431
5432 for (int i = 0; i < orderByConditionFields.length; i++) {
5433 if (getDB().isSupportsInlineDistinct()) {
5434 query.append(_ORDER_BY_ENTITY_ALIAS);
5435 }
5436 else {
5437 query.append(_ORDER_BY_ENTITY_TABLE);
5438 }
5439
5440 query.append(orderByConditionFields[i]);
5441
5442 if ((i + 1) < orderByConditionFields.length) {
5443 if (orderByComparator.isAscending() ^ previous) {
5444 query.append(WHERE_GREATER_THAN_HAS_NEXT);
5445 }
5446 else {
5447 query.append(WHERE_LESSER_THAN_HAS_NEXT);
5448 }
5449 }
5450 else {
5451 if (orderByComparator.isAscending() ^ previous) {
5452 query.append(WHERE_GREATER_THAN);
5453 }
5454 else {
5455 query.append(WHERE_LESSER_THAN);
5456 }
5457 }
5458 }
5459
5460 query.append(ORDER_BY_CLAUSE);
5461
5462 String[] orderByFields = orderByComparator.getOrderByFields();
5463
5464 for (int i = 0; i < orderByFields.length; i++) {
5465 if (getDB().isSupportsInlineDistinct()) {
5466 query.append(_ORDER_BY_ENTITY_ALIAS);
5467 }
5468 else {
5469 query.append(_ORDER_BY_ENTITY_TABLE);
5470 }
5471
5472 query.append(orderByFields[i]);
5473
5474 if ((i + 1) < orderByFields.length) {
5475 if (orderByComparator.isAscending() ^ previous) {
5476 query.append(ORDER_BY_ASC_HAS_NEXT);
5477 }
5478 else {
5479 query.append(ORDER_BY_DESC_HAS_NEXT);
5480 }
5481 }
5482 else {
5483 if (orderByComparator.isAscending() ^ previous) {
5484 query.append(ORDER_BY_ASC);
5485 }
5486 else {
5487 query.append(ORDER_BY_DESC);
5488 }
5489 }
5490 }
5491 }
5492 else {
5493 if (getDB().isSupportsInlineDistinct()) {
5494 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
5495 }
5496 else {
5497 query.append(OrganizationModelImpl.ORDER_BY_SQL);
5498 }
5499 }
5500
5501 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5502 Organization.class.getName(),
5503 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
5504
5505 SQLQuery q = session.createSynchronizedSQLQuery(sql);
5506
5507 q.setFirstResult(0);
5508 q.setMaxResults(2);
5509
5510 if (getDB().isSupportsInlineDistinct()) {
5511 q.addEntity(_FILTER_ENTITY_ALIAS, OrganizationImpl.class);
5512 }
5513 else {
5514 q.addEntity(_FILTER_ENTITY_TABLE, OrganizationImpl.class);
5515 }
5516
5517 QueryPos qPos = QueryPos.getInstance(q);
5518
5519 qPos.add(companyId);
5520
5521 if (bindTreePath) {
5522 qPos.add(treePath);
5523 }
5524
5525 if (orderByComparator != null) {
5526 Object[] values = orderByComparator.getOrderByConditionValues(organization);
5527
5528 for (Object value : values) {
5529 qPos.add(value);
5530 }
5531 }
5532
5533 List<Organization> list = q.list();
5534
5535 if (list.size() == 2) {
5536 return list.get(1);
5537 }
5538 else {
5539 return null;
5540 }
5541 }
5542
5543
5549 @Override
5550 public void removeByC_T(long companyId, String treePath) {
5551 for (Organization organization : findByC_T(companyId, treePath,
5552 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
5553 remove(organization);
5554 }
5555 }
5556
5557
5564 @Override
5565 public int countByC_T(long companyId, String treePath) {
5566 FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_T;
5567
5568 Object[] finderArgs = new Object[] { companyId, treePath };
5569
5570 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
5571
5572 if (count == null) {
5573 StringBundler query = new StringBundler(3);
5574
5575 query.append(_SQL_COUNT_ORGANIZATION_WHERE);
5576
5577 query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
5578
5579 boolean bindTreePath = false;
5580
5581 if (treePath == null) {
5582 query.append(_FINDER_COLUMN_C_T_TREEPATH_1);
5583 }
5584 else if (treePath.equals(StringPool.BLANK)) {
5585 query.append(_FINDER_COLUMN_C_T_TREEPATH_3);
5586 }
5587 else {
5588 bindTreePath = true;
5589
5590 query.append(_FINDER_COLUMN_C_T_TREEPATH_2);
5591 }
5592
5593 String sql = query.toString();
5594
5595 Session session = null;
5596
5597 try {
5598 session = openSession();
5599
5600 Query q = session.createQuery(sql);
5601
5602 QueryPos qPos = QueryPos.getInstance(q);
5603
5604 qPos.add(companyId);
5605
5606 if (bindTreePath) {
5607 qPos.add(treePath);
5608 }
5609
5610 count = (Long)q.uniqueResult();
5611
5612 finderCache.putResult(finderPath, finderArgs, count);
5613 }
5614 catch (Exception e) {
5615 finderCache.removeResult(finderPath, finderArgs);
5616
5617 throw processException(e);
5618 }
5619 finally {
5620 closeSession(session);
5621 }
5622 }
5623
5624 return count.intValue();
5625 }
5626
5627
5634 @Override
5635 public int filterCountByC_T(long companyId, String treePath) {
5636 if (!InlineSQLHelperUtil.isEnabled()) {
5637 return countByC_T(companyId, treePath);
5638 }
5639
5640 StringBundler query = new StringBundler(3);
5641
5642 query.append(_FILTER_SQL_COUNT_ORGANIZATION_WHERE);
5643
5644 query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
5645
5646 boolean bindTreePath = false;
5647
5648 if (treePath == null) {
5649 query.append(_FINDER_COLUMN_C_T_TREEPATH_1);
5650 }
5651 else if (treePath.equals(StringPool.BLANK)) {
5652 query.append(_FINDER_COLUMN_C_T_TREEPATH_3);
5653 }
5654 else {
5655 bindTreePath = true;
5656
5657 query.append(_FINDER_COLUMN_C_T_TREEPATH_2);
5658 }
5659
5660 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5661 Organization.class.getName(),
5662 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
5663
5664 Session session = null;
5665
5666 try {
5667 session = openSession();
5668
5669 SQLQuery q = session.createSynchronizedSQLQuery(sql);
5670
5671 q.addScalar(COUNT_COLUMN_NAME,
5672 com.liferay.portal.kernel.dao.orm.Type.LONG);
5673
5674 QueryPos qPos = QueryPos.getInstance(q);
5675
5676 qPos.add(companyId);
5677
5678 if (bindTreePath) {
5679 qPos.add(treePath);
5680 }
5681
5682 Long count = (Long)q.uniqueResult();
5683
5684 return count.intValue();
5685 }
5686 catch (Exception e) {
5687 throw processException(e);
5688 }
5689 finally {
5690 closeSession(session);
5691 }
5692 }
5693
5694 private static final String _FINDER_COLUMN_C_T_COMPANYID_2 = "organization.companyId = ? AND ";
5695 private static final String _FINDER_COLUMN_C_T_TREEPATH_1 = "organization.treePath IS NULL";
5696 private static final String _FINDER_COLUMN_C_T_TREEPATH_2 = "organization.treePath LIKE ?";
5697 private static final String _FINDER_COLUMN_C_T_TREEPATH_3 = "(organization.treePath IS NULL OR organization.treePath LIKE '')";
5698 public static final FinderPath FINDER_PATH_FETCH_BY_C_N = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
5699 OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
5700 FINDER_CLASS_NAME_ENTITY, "fetchByC_N",
5701 new String[] { Long.class.getName(), String.class.getName() },
5702 OrganizationModelImpl.COMPANYID_COLUMN_BITMASK |
5703 OrganizationModelImpl.NAME_COLUMN_BITMASK);
5704 public static final FinderPath FINDER_PATH_COUNT_BY_C_N = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
5705 OrganizationModelImpl.FINDER_CACHE_ENABLED, Long.class,
5706 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_N",
5707 new String[] { Long.class.getName(), String.class.getName() });
5708
5709
5717 @Override
5718 public Organization findByC_N(long companyId, String name)
5719 throws NoSuchOrganizationException {
5720 Organization organization = fetchByC_N(companyId, name);
5721
5722 if (organization == null) {
5723 StringBundler msg = new StringBundler(6);
5724
5725 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5726
5727 msg.append("companyId=");
5728 msg.append(companyId);
5729
5730 msg.append(", name=");
5731 msg.append(name);
5732
5733 msg.append(StringPool.CLOSE_CURLY_BRACE);
5734
5735 if (_log.isWarnEnabled()) {
5736 _log.warn(msg.toString());
5737 }
5738
5739 throw new NoSuchOrganizationException(msg.toString());
5740 }
5741
5742 return organization;
5743 }
5744
5745
5752 @Override
5753 public Organization fetchByC_N(long companyId, String name) {
5754 return fetchByC_N(companyId, name, true);
5755 }
5756
5757
5765 @Override
5766 public Organization fetchByC_N(long companyId, String name,
5767 boolean retrieveFromCache) {
5768 Object[] finderArgs = new Object[] { companyId, name };
5769
5770 Object result = null;
5771
5772 if (retrieveFromCache) {
5773 result = finderCache.getResult(FINDER_PATH_FETCH_BY_C_N,
5774 finderArgs, this);
5775 }
5776
5777 if (result instanceof Organization) {
5778 Organization organization = (Organization)result;
5779
5780 if ((companyId != organization.getCompanyId()) ||
5781 !Validator.equals(name, organization.getName())) {
5782 result = null;
5783 }
5784 }
5785
5786 if (result == null) {
5787 StringBundler query = new StringBundler(4);
5788
5789 query.append(_SQL_SELECT_ORGANIZATION_WHERE);
5790
5791 query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
5792
5793 boolean bindName = false;
5794
5795 if (name == null) {
5796 query.append(_FINDER_COLUMN_C_N_NAME_1);
5797 }
5798 else if (name.equals(StringPool.BLANK)) {
5799 query.append(_FINDER_COLUMN_C_N_NAME_3);
5800 }
5801 else {
5802 bindName = true;
5803
5804 query.append(_FINDER_COLUMN_C_N_NAME_2);
5805 }
5806
5807 String sql = query.toString();
5808
5809 Session session = null;
5810
5811 try {
5812 session = openSession();
5813
5814 Query q = session.createQuery(sql);
5815
5816 QueryPos qPos = QueryPos.getInstance(q);
5817
5818 qPos.add(companyId);
5819
5820 if (bindName) {
5821 qPos.add(name);
5822 }
5823
5824 List<Organization> list = q.list();
5825
5826 if (list.isEmpty()) {
5827 finderCache.putResult(FINDER_PATH_FETCH_BY_C_N, finderArgs,
5828 list);
5829 }
5830 else {
5831 Organization organization = list.get(0);
5832
5833 result = organization;
5834
5835 cacheResult(organization);
5836
5837 if ((organization.getCompanyId() != companyId) ||
5838 (organization.getName() == null) ||
5839 !organization.getName().equals(name)) {
5840 finderCache.putResult(FINDER_PATH_FETCH_BY_C_N,
5841 finderArgs, organization);
5842 }
5843 }
5844 }
5845 catch (Exception e) {
5846 finderCache.removeResult(FINDER_PATH_FETCH_BY_C_N, finderArgs);
5847
5848 throw processException(e);
5849 }
5850 finally {
5851 closeSession(session);
5852 }
5853 }
5854
5855 if (result instanceof List<?>) {
5856 return null;
5857 }
5858 else {
5859 return (Organization)result;
5860 }
5861 }
5862
5863
5870 @Override
5871 public Organization removeByC_N(long companyId, String name)
5872 throws NoSuchOrganizationException {
5873 Organization organization = findByC_N(companyId, name);
5874
5875 return remove(organization);
5876 }
5877
5878
5885 @Override
5886 public int countByC_N(long companyId, String name) {
5887 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_N;
5888
5889 Object[] finderArgs = new Object[] { companyId, name };
5890
5891 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
5892
5893 if (count == null) {
5894 StringBundler query = new StringBundler(3);
5895
5896 query.append(_SQL_COUNT_ORGANIZATION_WHERE);
5897
5898 query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
5899
5900 boolean bindName = false;
5901
5902 if (name == null) {
5903 query.append(_FINDER_COLUMN_C_N_NAME_1);
5904 }
5905 else if (name.equals(StringPool.BLANK)) {
5906 query.append(_FINDER_COLUMN_C_N_NAME_3);
5907 }
5908 else {
5909 bindName = true;
5910
5911 query.append(_FINDER_COLUMN_C_N_NAME_2);
5912 }
5913
5914 String sql = query.toString();
5915
5916 Session session = null;
5917
5918 try {
5919 session = openSession();
5920
5921 Query q = session.createQuery(sql);
5922
5923 QueryPos qPos = QueryPos.getInstance(q);
5924
5925 qPos.add(companyId);
5926
5927 if (bindName) {
5928 qPos.add(name);
5929 }
5930
5931 count = (Long)q.uniqueResult();
5932
5933 finderCache.putResult(finderPath, finderArgs, count);
5934 }
5935 catch (Exception e) {
5936 finderCache.removeResult(finderPath, finderArgs);
5937
5938 throw processException(e);
5939 }
5940 finally {
5941 closeSession(session);
5942 }
5943 }
5944
5945 return count.intValue();
5946 }
5947
5948 private static final String _FINDER_COLUMN_C_N_COMPANYID_2 = "organization.companyId = ? AND ";
5949 private static final String _FINDER_COLUMN_C_N_NAME_1 = "organization.name IS NULL";
5950 private static final String _FINDER_COLUMN_C_N_NAME_2 = "organization.name = ?";
5951 private static final String _FINDER_COLUMN_C_N_NAME_3 = "(organization.name IS NULL OR organization.name = '')";
5952 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_O_C_P = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
5953 OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
5954 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByO_C_P",
5955 new String[] {
5956 Long.class.getName(), Long.class.getName(), Long.class.getName(),
5957
5958 Integer.class.getName(), Integer.class.getName(),
5959 OrderByComparator.class.getName()
5960 });
5961 public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_O_C_P = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
5962 OrganizationModelImpl.FINDER_CACHE_ENABLED, Long.class,
5963 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByO_C_P",
5964 new String[] {
5965 Long.class.getName(), Long.class.getName(), Long.class.getName()
5966 });
5967
5968
5976 @Override
5977 public List<Organization> findByO_C_P(long organizationId, long companyId,
5978 long parentOrganizationId) {
5979 return findByO_C_P(organizationId, companyId, parentOrganizationId,
5980 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
5981 }
5982
5983
5997 @Override
5998 public List<Organization> findByO_C_P(long organizationId, long companyId,
5999 long parentOrganizationId, int start, int end) {
6000 return findByO_C_P(organizationId, companyId, parentOrganizationId,
6001 start, end, null);
6002 }
6003
6004
6019 @Override
6020 public List<Organization> findByO_C_P(long organizationId, long companyId,
6021 long parentOrganizationId, int start, int end,
6022 OrderByComparator<Organization> orderByComparator) {
6023 return findByO_C_P(organizationId, companyId, parentOrganizationId,
6024 start, end, orderByComparator, true);
6025 }
6026
6027
6043 @Override
6044 public List<Organization> findByO_C_P(long organizationId, long companyId,
6045 long parentOrganizationId, int start, int end,
6046 OrderByComparator<Organization> orderByComparator,
6047 boolean retrieveFromCache) {
6048 boolean pagination = true;
6049 FinderPath finderPath = null;
6050 Object[] finderArgs = null;
6051
6052 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_O_C_P;
6053 finderArgs = new Object[] {
6054 organizationId, companyId, parentOrganizationId,
6055
6056 start, end, orderByComparator
6057 };
6058
6059 List<Organization> list = null;
6060
6061 if (retrieveFromCache) {
6062 list = (List<Organization>)finderCache.getResult(finderPath,
6063 finderArgs, this);
6064
6065 if ((list != null) && !list.isEmpty()) {
6066 for (Organization organization : list) {
6067 if ((organizationId >= organization.getOrganizationId()) ||
6068 (companyId != organization.getCompanyId()) ||
6069 (parentOrganizationId != organization.getParentOrganizationId())) {
6070 list = null;
6071
6072 break;
6073 }
6074 }
6075 }
6076 }
6077
6078 if (list == null) {
6079 StringBundler query = null;
6080
6081 if (orderByComparator != null) {
6082 query = new StringBundler(5 +
6083 (orderByComparator.getOrderByFields().length * 3));
6084 }
6085 else {
6086 query = new StringBundler(5);
6087 }
6088
6089 query.append(_SQL_SELECT_ORGANIZATION_WHERE);
6090
6091 query.append(_FINDER_COLUMN_O_C_P_ORGANIZATIONID_2);
6092
6093 query.append(_FINDER_COLUMN_O_C_P_COMPANYID_2);
6094
6095 query.append(_FINDER_COLUMN_O_C_P_PARENTORGANIZATIONID_2);
6096
6097 if (orderByComparator != null) {
6098 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6099 orderByComparator);
6100 }
6101 else
6102 if (pagination) {
6103 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
6104 }
6105
6106 String sql = query.toString();
6107
6108 Session session = null;
6109
6110 try {
6111 session = openSession();
6112
6113 Query q = session.createQuery(sql);
6114
6115 QueryPos qPos = QueryPos.getInstance(q);
6116
6117 qPos.add(organizationId);
6118
6119 qPos.add(companyId);
6120
6121 qPos.add(parentOrganizationId);
6122
6123 if (!pagination) {
6124 list = (List<Organization>)QueryUtil.list(q, getDialect(),
6125 start, end, false);
6126
6127 Collections.sort(list);
6128
6129 list = Collections.unmodifiableList(list);
6130 }
6131 else {
6132 list = (List<Organization>)QueryUtil.list(q, getDialect(),
6133 start, end);
6134 }
6135
6136 cacheResult(list);
6137
6138 finderCache.putResult(finderPath, finderArgs, list);
6139 }
6140 catch (Exception e) {
6141 finderCache.removeResult(finderPath, finderArgs);
6142
6143 throw processException(e);
6144 }
6145 finally {
6146 closeSession(session);
6147 }
6148 }
6149
6150 return list;
6151 }
6152
6153
6163 @Override
6164 public Organization findByO_C_P_First(long organizationId, long companyId,
6165 long parentOrganizationId,
6166 OrderByComparator<Organization> orderByComparator)
6167 throws NoSuchOrganizationException {
6168 Organization organization = fetchByO_C_P_First(organizationId,
6169 companyId, parentOrganizationId, orderByComparator);
6170
6171 if (organization != null) {
6172 return organization;
6173 }
6174
6175 StringBundler msg = new StringBundler(8);
6176
6177 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6178
6179 msg.append("organizationId=");
6180 msg.append(organizationId);
6181
6182 msg.append(", companyId=");
6183 msg.append(companyId);
6184
6185 msg.append(", parentOrganizationId=");
6186 msg.append(parentOrganizationId);
6187
6188 msg.append(StringPool.CLOSE_CURLY_BRACE);
6189
6190 throw new NoSuchOrganizationException(msg.toString());
6191 }
6192
6193
6202 @Override
6203 public Organization fetchByO_C_P_First(long organizationId, long companyId,
6204 long parentOrganizationId,
6205 OrderByComparator<Organization> orderByComparator) {
6206 List<Organization> list = findByO_C_P(organizationId, companyId,
6207 parentOrganizationId, 0, 1, orderByComparator);
6208
6209 if (!list.isEmpty()) {
6210 return list.get(0);
6211 }
6212
6213 return null;
6214 }
6215
6216
6226 @Override
6227 public Organization findByO_C_P_Last(long organizationId, long companyId,
6228 long parentOrganizationId,
6229 OrderByComparator<Organization> orderByComparator)
6230 throws NoSuchOrganizationException {
6231 Organization organization = fetchByO_C_P_Last(organizationId,
6232 companyId, parentOrganizationId, orderByComparator);
6233
6234 if (organization != null) {
6235 return organization;
6236 }
6237
6238 StringBundler msg = new StringBundler(8);
6239
6240 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6241
6242 msg.append("organizationId=");
6243 msg.append(organizationId);
6244
6245 msg.append(", companyId=");
6246 msg.append(companyId);
6247
6248 msg.append(", parentOrganizationId=");
6249 msg.append(parentOrganizationId);
6250
6251 msg.append(StringPool.CLOSE_CURLY_BRACE);
6252
6253 throw new NoSuchOrganizationException(msg.toString());
6254 }
6255
6256
6265 @Override
6266 public Organization fetchByO_C_P_Last(long organizationId, long companyId,
6267 long parentOrganizationId,
6268 OrderByComparator<Organization> orderByComparator) {
6269 int count = countByO_C_P(organizationId, companyId, parentOrganizationId);
6270
6271 if (count == 0) {
6272 return null;
6273 }
6274
6275 List<Organization> list = findByO_C_P(organizationId, companyId,
6276 parentOrganizationId, count - 1, count, orderByComparator);
6277
6278 if (!list.isEmpty()) {
6279 return list.get(0);
6280 }
6281
6282 return null;
6283 }
6284
6285
6293 @Override
6294 public List<Organization> filterFindByO_C_P(long organizationId,
6295 long companyId, long parentOrganizationId) {
6296 return filterFindByO_C_P(organizationId, companyId,
6297 parentOrganizationId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
6298 }
6299
6300
6314 @Override
6315 public List<Organization> filterFindByO_C_P(long organizationId,
6316 long companyId, long parentOrganizationId, int start, int end) {
6317 return filterFindByO_C_P(organizationId, companyId,
6318 parentOrganizationId, start, end, null);
6319 }
6320
6321
6336 @Override
6337 public List<Organization> filterFindByO_C_P(long organizationId,
6338 long companyId, long parentOrganizationId, int start, int end,
6339 OrderByComparator<Organization> orderByComparator) {
6340 if (!InlineSQLHelperUtil.isEnabled()) {
6341 return findByO_C_P(organizationId, companyId, parentOrganizationId,
6342 start, end, orderByComparator);
6343 }
6344
6345 StringBundler query = null;
6346
6347 if (orderByComparator != null) {
6348 query = new StringBundler(5 +
6349 (orderByComparator.getOrderByFields().length * 3));
6350 }
6351 else {
6352 query = new StringBundler(5);
6353 }
6354
6355 if (getDB().isSupportsInlineDistinct()) {
6356 query.append(_FILTER_SQL_SELECT_ORGANIZATION_WHERE);
6357 }
6358 else {
6359 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1);
6360 }
6361
6362 query.append(_FINDER_COLUMN_O_C_P_ORGANIZATIONID_2);
6363
6364 query.append(_FINDER_COLUMN_O_C_P_COMPANYID_2);
6365
6366 query.append(_FINDER_COLUMN_O_C_P_PARENTORGANIZATIONID_2);
6367
6368 if (!getDB().isSupportsInlineDistinct()) {
6369 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2);
6370 }
6371
6372 if (orderByComparator != null) {
6373 if (getDB().isSupportsInlineDistinct()) {
6374 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6375 orderByComparator, true);
6376 }
6377 else {
6378 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
6379 orderByComparator, true);
6380 }
6381 }
6382 else {
6383 if (getDB().isSupportsInlineDistinct()) {
6384 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
6385 }
6386 else {
6387 query.append(OrganizationModelImpl.ORDER_BY_SQL);
6388 }
6389 }
6390
6391 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6392 Organization.class.getName(),
6393 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
6394
6395 Session session = null;
6396
6397 try {
6398 session = openSession();
6399
6400 SQLQuery q = session.createSynchronizedSQLQuery(sql);
6401
6402 if (getDB().isSupportsInlineDistinct()) {
6403 q.addEntity(_FILTER_ENTITY_ALIAS, OrganizationImpl.class);
6404 }
6405 else {
6406 q.addEntity(_FILTER_ENTITY_TABLE, OrganizationImpl.class);
6407 }
6408
6409 QueryPos qPos = QueryPos.getInstance(q);
6410
6411 qPos.add(organizationId);
6412
6413 qPos.add(companyId);
6414
6415 qPos.add(parentOrganizationId);
6416
6417 return (List<Organization>)QueryUtil.list(q, getDialect(), start,
6418 end);
6419 }
6420 catch (Exception e) {
6421 throw processException(e);
6422 }
6423 finally {
6424 closeSession(session);
6425 }
6426 }
6427
6428
6435 @Override
6436 public void removeByO_C_P(long organizationId, long companyId,
6437 long parentOrganizationId) {
6438 for (Organization organization : findByO_C_P(organizationId, companyId,
6439 parentOrganizationId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
6440 remove(organization);
6441 }
6442 }
6443
6444
6452 @Override
6453 public int countByO_C_P(long organizationId, long companyId,
6454 long parentOrganizationId) {
6455 FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_O_C_P;
6456
6457 Object[] finderArgs = new Object[] {
6458 organizationId, companyId, parentOrganizationId
6459 };
6460
6461 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
6462
6463 if (count == null) {
6464 StringBundler query = new StringBundler(4);
6465
6466 query.append(_SQL_COUNT_ORGANIZATION_WHERE);
6467
6468 query.append(_FINDER_COLUMN_O_C_P_ORGANIZATIONID_2);
6469
6470 query.append(_FINDER_COLUMN_O_C_P_COMPANYID_2);
6471
6472 query.append(_FINDER_COLUMN_O_C_P_PARENTORGANIZATIONID_2);
6473
6474 String sql = query.toString();
6475
6476 Session session = null;
6477
6478 try {
6479 session = openSession();
6480
6481 Query q = session.createQuery(sql);
6482
6483 QueryPos qPos = QueryPos.getInstance(q);
6484
6485 qPos.add(organizationId);
6486
6487 qPos.add(companyId);
6488
6489 qPos.add(parentOrganizationId);
6490
6491 count = (Long)q.uniqueResult();
6492
6493 finderCache.putResult(finderPath, finderArgs, count);
6494 }
6495 catch (Exception e) {
6496 finderCache.removeResult(finderPath, finderArgs);
6497
6498 throw processException(e);
6499 }
6500 finally {
6501 closeSession(session);
6502 }
6503 }
6504
6505 return count.intValue();
6506 }
6507
6508
6516 @Override
6517 public int filterCountByO_C_P(long organizationId, long companyId,
6518 long parentOrganizationId) {
6519 if (!InlineSQLHelperUtil.isEnabled()) {
6520 return countByO_C_P(organizationId, companyId, parentOrganizationId);
6521 }
6522
6523 StringBundler query = new StringBundler(4);
6524
6525 query.append(_FILTER_SQL_COUNT_ORGANIZATION_WHERE);
6526
6527 query.append(_FINDER_COLUMN_O_C_P_ORGANIZATIONID_2);
6528
6529 query.append(_FINDER_COLUMN_O_C_P_COMPANYID_2);
6530
6531 query.append(_FINDER_COLUMN_O_C_P_PARENTORGANIZATIONID_2);
6532
6533 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6534 Organization.class.getName(),
6535 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
6536
6537 Session session = null;
6538
6539 try {
6540 session = openSession();
6541
6542 SQLQuery q = session.createSynchronizedSQLQuery(sql);
6543
6544 q.addScalar(COUNT_COLUMN_NAME,
6545 com.liferay.portal.kernel.dao.orm.Type.LONG);
6546
6547 QueryPos qPos = QueryPos.getInstance(q);
6548
6549 qPos.add(organizationId);
6550
6551 qPos.add(companyId);
6552
6553 qPos.add(parentOrganizationId);
6554
6555 Long count = (Long)q.uniqueResult();
6556
6557 return count.intValue();
6558 }
6559 catch (Exception e) {
6560 throw processException(e);
6561 }
6562 finally {
6563 closeSession(session);
6564 }
6565 }
6566
6567 private static final String _FINDER_COLUMN_O_C_P_ORGANIZATIONID_2 = "organization.organizationId > ? AND ";
6568 private static final String _FINDER_COLUMN_O_C_P_COMPANYID_2 = "organization.companyId = ? AND ";
6569 private static final String _FINDER_COLUMN_O_C_P_PARENTORGANIZATIONID_2 = "organization.parentOrganizationId = ?";
6570
6571 public OrganizationPersistenceImpl() {
6572 setModelClass(Organization.class);
6573 }
6574
6575
6580 @Override
6581 public void cacheResult(Organization organization) {
6582 entityCache.putResult(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
6583 OrganizationImpl.class, organization.getPrimaryKey(), organization);
6584
6585 finderCache.putResult(FINDER_PATH_FETCH_BY_C_N,
6586 new Object[] { organization.getCompanyId(), organization.getName() },
6587 organization);
6588
6589 organization.resetOriginalValues();
6590 }
6591
6592
6597 @Override
6598 public void cacheResult(List<Organization> organizations) {
6599 for (Organization organization : organizations) {
6600 if (entityCache.getResult(
6601 OrganizationModelImpl.ENTITY_CACHE_ENABLED,
6602 OrganizationImpl.class, organization.getPrimaryKey()) == null) {
6603 cacheResult(organization);
6604 }
6605 else {
6606 organization.resetOriginalValues();
6607 }
6608 }
6609 }
6610
6611
6618 @Override
6619 public void clearCache() {
6620 entityCache.clearCache(OrganizationImpl.class);
6621
6622 finderCache.clearCache(FINDER_CLASS_NAME_ENTITY);
6623 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
6624 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
6625 }
6626
6627
6634 @Override
6635 public void clearCache(Organization organization) {
6636 entityCache.removeResult(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
6637 OrganizationImpl.class, organization.getPrimaryKey());
6638
6639 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
6640 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
6641
6642 clearUniqueFindersCache((OrganizationModelImpl)organization);
6643 }
6644
6645 @Override
6646 public void clearCache(List<Organization> organizations) {
6647 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
6648 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
6649
6650 for (Organization organization : organizations) {
6651 entityCache.removeResult(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
6652 OrganizationImpl.class, organization.getPrimaryKey());
6653
6654 clearUniqueFindersCache((OrganizationModelImpl)organization);
6655 }
6656 }
6657
6658 protected void cacheUniqueFindersCache(
6659 OrganizationModelImpl organizationModelImpl, boolean isNew) {
6660 if (isNew) {
6661 Object[] args = new Object[] {
6662 organizationModelImpl.getCompanyId(),
6663 organizationModelImpl.getName()
6664 };
6665
6666 finderCache.putResult(FINDER_PATH_COUNT_BY_C_N, args,
6667 Long.valueOf(1));
6668 finderCache.putResult(FINDER_PATH_FETCH_BY_C_N, args,
6669 organizationModelImpl);
6670 }
6671 else {
6672 if ((organizationModelImpl.getColumnBitmask() &
6673 FINDER_PATH_FETCH_BY_C_N.getColumnBitmask()) != 0) {
6674 Object[] args = new Object[] {
6675 organizationModelImpl.getCompanyId(),
6676 organizationModelImpl.getName()
6677 };
6678
6679 finderCache.putResult(FINDER_PATH_COUNT_BY_C_N, args,
6680 Long.valueOf(1));
6681 finderCache.putResult(FINDER_PATH_FETCH_BY_C_N, args,
6682 organizationModelImpl);
6683 }
6684 }
6685 }
6686
6687 protected void clearUniqueFindersCache(
6688 OrganizationModelImpl organizationModelImpl) {
6689 Object[] args = new Object[] {
6690 organizationModelImpl.getCompanyId(),
6691 organizationModelImpl.getName()
6692 };
6693
6694 finderCache.removeResult(FINDER_PATH_COUNT_BY_C_N, args);
6695 finderCache.removeResult(FINDER_PATH_FETCH_BY_C_N, args);
6696
6697 if ((organizationModelImpl.getColumnBitmask() &
6698 FINDER_PATH_FETCH_BY_C_N.getColumnBitmask()) != 0) {
6699 args = new Object[] {
6700 organizationModelImpl.getOriginalCompanyId(),
6701 organizationModelImpl.getOriginalName()
6702 };
6703
6704 finderCache.removeResult(FINDER_PATH_COUNT_BY_C_N, args);
6705 finderCache.removeResult(FINDER_PATH_FETCH_BY_C_N, args);
6706 }
6707 }
6708
6709
6715 @Override
6716 public Organization create(long organizationId) {
6717 Organization organization = new OrganizationImpl();
6718
6719 organization.setNew(true);
6720 organization.setPrimaryKey(organizationId);
6721
6722 String uuid = PortalUUIDUtil.generate();
6723
6724 organization.setUuid(uuid);
6725
6726 return organization;
6727 }
6728
6729
6736 @Override
6737 public Organization remove(long organizationId)
6738 throws NoSuchOrganizationException {
6739 return remove((Serializable)organizationId);
6740 }
6741
6742
6749 @Override
6750 public Organization remove(Serializable primaryKey)
6751 throws NoSuchOrganizationException {
6752 Session session = null;
6753
6754 try {
6755 session = openSession();
6756
6757 Organization organization = (Organization)session.get(OrganizationImpl.class,
6758 primaryKey);
6759
6760 if (organization == null) {
6761 if (_log.isWarnEnabled()) {
6762 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
6763 }
6764
6765 throw new NoSuchOrganizationException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
6766 primaryKey);
6767 }
6768
6769 return remove(organization);
6770 }
6771 catch (NoSuchOrganizationException nsee) {
6772 throw nsee;
6773 }
6774 catch (Exception e) {
6775 throw processException(e);
6776 }
6777 finally {
6778 closeSession(session);
6779 }
6780 }
6781
6782 @Override
6783 protected Organization removeImpl(Organization organization) {
6784 organization = toUnwrappedModel(organization);
6785
6786 organizationToGroupTableMapper.deleteLeftPrimaryKeyTableMappings(0,
6787 organization.getPrimaryKey());
6788
6789 organizationToUserTableMapper.deleteLeftPrimaryKeyTableMappings(0,
6790 organization.getPrimaryKey());
6791
6792 Session session = null;
6793
6794 try {
6795 session = openSession();
6796
6797 if (!session.contains(organization)) {
6798 organization = (Organization)session.get(OrganizationImpl.class,
6799 organization.getPrimaryKeyObj());
6800 }
6801
6802 if (organization != null) {
6803 session.delete(organization);
6804 }
6805 }
6806 catch (Exception e) {
6807 throw processException(e);
6808 }
6809 finally {
6810 closeSession(session);
6811 }
6812
6813 if (organization != null) {
6814 clearCache(organization);
6815 }
6816
6817 return organization;
6818 }
6819
6820 @Override
6821 public Organization updateImpl(Organization organization) {
6822 organization = toUnwrappedModel(organization);
6823
6824 boolean isNew = organization.isNew();
6825
6826 OrganizationModelImpl organizationModelImpl = (OrganizationModelImpl)organization;
6827
6828 if (Validator.isNull(organization.getUuid())) {
6829 String uuid = PortalUUIDUtil.generate();
6830
6831 organization.setUuid(uuid);
6832 }
6833
6834 ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();
6835
6836 Date now = new Date();
6837
6838 if (isNew && (organization.getCreateDate() == null)) {
6839 if (serviceContext == null) {
6840 organization.setCreateDate(now);
6841 }
6842 else {
6843 organization.setCreateDate(serviceContext.getCreateDate(now));
6844 }
6845 }
6846
6847 if (!organizationModelImpl.hasSetModifiedDate()) {
6848 if (serviceContext == null) {
6849 organization.setModifiedDate(now);
6850 }
6851 else {
6852 organization.setModifiedDate(serviceContext.getModifiedDate(now));
6853 }
6854 }
6855
6856 Session session = null;
6857
6858 try {
6859 session = openSession();
6860
6861 if (organization.isNew()) {
6862 session.save(organization);
6863
6864 organization.setNew(false);
6865 }
6866 else {
6867 organization = (Organization)session.merge(organization);
6868 }
6869 }
6870 catch (Exception e) {
6871 throw processException(e);
6872 }
6873 finally {
6874 closeSession(session);
6875 }
6876
6877 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
6878
6879 if (isNew || !OrganizationModelImpl.COLUMN_BITMASK_ENABLED) {
6880 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
6881 }
6882
6883 else {
6884 if ((organizationModelImpl.getColumnBitmask() &
6885 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
6886 Object[] args = new Object[] {
6887 organizationModelImpl.getOriginalUuid()
6888 };
6889
6890 finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
6891 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
6892 args);
6893
6894 args = new Object[] { organizationModelImpl.getUuid() };
6895
6896 finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
6897 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
6898 args);
6899 }
6900
6901 if ((organizationModelImpl.getColumnBitmask() &
6902 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
6903 Object[] args = new Object[] {
6904 organizationModelImpl.getOriginalUuid(),
6905 organizationModelImpl.getOriginalCompanyId()
6906 };
6907
6908 finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
6909 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
6910 args);
6911
6912 args = new Object[] {
6913 organizationModelImpl.getUuid(),
6914 organizationModelImpl.getCompanyId()
6915 };
6916
6917 finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
6918 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
6919 args);
6920 }
6921
6922 if ((organizationModelImpl.getColumnBitmask() &
6923 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
6924 Object[] args = new Object[] {
6925 organizationModelImpl.getOriginalCompanyId()
6926 };
6927
6928 finderCache.removeResult(FINDER_PATH_COUNT_BY_COMPANYID, args);
6929 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
6930 args);
6931
6932 args = new Object[] { organizationModelImpl.getCompanyId() };
6933
6934 finderCache.removeResult(FINDER_PATH_COUNT_BY_COMPANYID, args);
6935 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
6936 args);
6937 }
6938
6939 if ((organizationModelImpl.getColumnBitmask() &
6940 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LOCATIONS.getColumnBitmask()) != 0) {
6941 Object[] args = new Object[] {
6942 organizationModelImpl.getOriginalCompanyId()
6943 };
6944
6945 finderCache.removeResult(FINDER_PATH_COUNT_BY_LOCATIONS, args);
6946 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LOCATIONS,
6947 args);
6948
6949 args = new Object[] { organizationModelImpl.getCompanyId() };
6950
6951 finderCache.removeResult(FINDER_PATH_COUNT_BY_LOCATIONS, args);
6952 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LOCATIONS,
6953 args);
6954 }
6955
6956 if ((organizationModelImpl.getColumnBitmask() &
6957 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P.getColumnBitmask()) != 0) {
6958 Object[] args = new Object[] {
6959 organizationModelImpl.getOriginalCompanyId(),
6960 organizationModelImpl.getOriginalParentOrganizationId()
6961 };
6962
6963 finderCache.removeResult(FINDER_PATH_COUNT_BY_C_P, args);
6964 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P,
6965 args);
6966
6967 args = new Object[] {
6968 organizationModelImpl.getCompanyId(),
6969 organizationModelImpl.getParentOrganizationId()
6970 };
6971
6972 finderCache.removeResult(FINDER_PATH_COUNT_BY_C_P, args);
6973 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P,
6974 args);
6975 }
6976 }
6977
6978 entityCache.putResult(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
6979 OrganizationImpl.class, organization.getPrimaryKey(), organization,
6980 false);
6981
6982 clearUniqueFindersCache(organizationModelImpl);
6983 cacheUniqueFindersCache(organizationModelImpl, isNew);
6984
6985 organization.resetOriginalValues();
6986
6987 return organization;
6988 }
6989
6990 protected Organization toUnwrappedModel(Organization organization) {
6991 if (organization instanceof OrganizationImpl) {
6992 return organization;
6993 }
6994
6995 OrganizationImpl organizationImpl = new OrganizationImpl();
6996
6997 organizationImpl.setNew(organization.isNew());
6998 organizationImpl.setPrimaryKey(organization.getPrimaryKey());
6999
7000 organizationImpl.setMvccVersion(organization.getMvccVersion());
7001 organizationImpl.setUuid(organization.getUuid());
7002 organizationImpl.setOrganizationId(organization.getOrganizationId());
7003 organizationImpl.setCompanyId(organization.getCompanyId());
7004 organizationImpl.setUserId(organization.getUserId());
7005 organizationImpl.setUserName(organization.getUserName());
7006 organizationImpl.setCreateDate(organization.getCreateDate());
7007 organizationImpl.setModifiedDate(organization.getModifiedDate());
7008 organizationImpl.setParentOrganizationId(organization.getParentOrganizationId());
7009 organizationImpl.setTreePath(organization.getTreePath());
7010 organizationImpl.setName(organization.getName());
7011 organizationImpl.setType(organization.getType());
7012 organizationImpl.setRecursable(organization.isRecursable());
7013 organizationImpl.setRegionId(organization.getRegionId());
7014 organizationImpl.setCountryId(organization.getCountryId());
7015 organizationImpl.setStatusId(organization.getStatusId());
7016 organizationImpl.setComments(organization.getComments());
7017 organizationImpl.setLogoId(organization.getLogoId());
7018
7019 return organizationImpl;
7020 }
7021
7022
7029 @Override
7030 public Organization findByPrimaryKey(Serializable primaryKey)
7031 throws NoSuchOrganizationException {
7032 Organization organization = fetchByPrimaryKey(primaryKey);
7033
7034 if (organization == null) {
7035 if (_log.isWarnEnabled()) {
7036 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
7037 }
7038
7039 throw new NoSuchOrganizationException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
7040 primaryKey);
7041 }
7042
7043 return organization;
7044 }
7045
7046
7053 @Override
7054 public Organization findByPrimaryKey(long organizationId)
7055 throws NoSuchOrganizationException {
7056 return findByPrimaryKey((Serializable)organizationId);
7057 }
7058
7059
7065 @Override
7066 public Organization fetchByPrimaryKey(Serializable primaryKey) {
7067 Organization organization = (Organization)entityCache.getResult(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
7068 OrganizationImpl.class, primaryKey);
7069
7070 if (organization == _nullOrganization) {
7071 return null;
7072 }
7073
7074 if (organization == null) {
7075 Session session = null;
7076
7077 try {
7078 session = openSession();
7079
7080 organization = (Organization)session.get(OrganizationImpl.class,
7081 primaryKey);
7082
7083 if (organization != null) {
7084 cacheResult(organization);
7085 }
7086 else {
7087 entityCache.putResult(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
7088 OrganizationImpl.class, primaryKey, _nullOrganization);
7089 }
7090 }
7091 catch (Exception e) {
7092 entityCache.removeResult(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
7093 OrganizationImpl.class, primaryKey);
7094
7095 throw processException(e);
7096 }
7097 finally {
7098 closeSession(session);
7099 }
7100 }
7101
7102 return organization;
7103 }
7104
7105
7111 @Override
7112 public Organization fetchByPrimaryKey(long organizationId) {
7113 return fetchByPrimaryKey((Serializable)organizationId);
7114 }
7115
7116 @Override
7117 public Map<Serializable, Organization> fetchByPrimaryKeys(
7118 Set<Serializable> primaryKeys) {
7119 if (primaryKeys.isEmpty()) {
7120 return Collections.emptyMap();
7121 }
7122
7123 Map<Serializable, Organization> map = new HashMap<Serializable, Organization>();
7124
7125 if (primaryKeys.size() == 1) {
7126 Iterator<Serializable> iterator = primaryKeys.iterator();
7127
7128 Serializable primaryKey = iterator.next();
7129
7130 Organization organization = fetchByPrimaryKey(primaryKey);
7131
7132 if (organization != null) {
7133 map.put(primaryKey, organization);
7134 }
7135
7136 return map;
7137 }
7138
7139 Set<Serializable> uncachedPrimaryKeys = null;
7140
7141 for (Serializable primaryKey : primaryKeys) {
7142 Organization organization = (Organization)entityCache.getResult(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
7143 OrganizationImpl.class, primaryKey);
7144
7145 if (organization == null) {
7146 if (uncachedPrimaryKeys == null) {
7147 uncachedPrimaryKeys = new HashSet<Serializable>();
7148 }
7149
7150 uncachedPrimaryKeys.add(primaryKey);
7151 }
7152 else {
7153 map.put(primaryKey, organization);
7154 }
7155 }
7156
7157 if (uncachedPrimaryKeys == null) {
7158 return map;
7159 }
7160
7161 StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
7162 1);
7163
7164 query.append(_SQL_SELECT_ORGANIZATION_WHERE_PKS_IN);
7165
7166 for (Serializable primaryKey : uncachedPrimaryKeys) {
7167 query.append(String.valueOf(primaryKey));
7168
7169 query.append(StringPool.COMMA);
7170 }
7171
7172 query.setIndex(query.index() - 1);
7173
7174 query.append(StringPool.CLOSE_PARENTHESIS);
7175
7176 String sql = query.toString();
7177
7178 Session session = null;
7179
7180 try {
7181 session = openSession();
7182
7183 Query q = session.createQuery(sql);
7184
7185 for (Organization organization : (List<Organization>)q.list()) {
7186 map.put(organization.getPrimaryKeyObj(), organization);
7187
7188 cacheResult(organization);
7189
7190 uncachedPrimaryKeys.remove(organization.getPrimaryKeyObj());
7191 }
7192
7193 for (Serializable primaryKey : uncachedPrimaryKeys) {
7194 entityCache.putResult(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
7195 OrganizationImpl.class, primaryKey, _nullOrganization);
7196 }
7197 }
7198 catch (Exception e) {
7199 throw processException(e);
7200 }
7201 finally {
7202 closeSession(session);
7203 }
7204
7205 return map;
7206 }
7207
7208
7213 @Override
7214 public List<Organization> findAll() {
7215 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
7216 }
7217
7218
7229 @Override
7230 public List<Organization> findAll(int start, int end) {
7231 return findAll(start, end, null);
7232 }
7233
7234
7246 @Override
7247 public List<Organization> findAll(int start, int end,
7248 OrderByComparator<Organization> orderByComparator) {
7249 return findAll(start, end, orderByComparator, true);
7250 }
7251
7252
7265 @Override
7266 public List<Organization> findAll(int start, int end,
7267 OrderByComparator<Organization> orderByComparator,
7268 boolean retrieveFromCache) {
7269 boolean pagination = true;
7270 FinderPath finderPath = null;
7271 Object[] finderArgs = null;
7272
7273 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7274 (orderByComparator == null)) {
7275 pagination = false;
7276 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
7277 finderArgs = FINDER_ARGS_EMPTY;
7278 }
7279 else {
7280 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
7281 finderArgs = new Object[] { start, end, orderByComparator };
7282 }
7283
7284 List<Organization> list = null;
7285
7286 if (retrieveFromCache) {
7287 list = (List<Organization>)finderCache.getResult(finderPath,
7288 finderArgs, this);
7289 }
7290
7291 if (list == null) {
7292 StringBundler query = null;
7293 String sql = null;
7294
7295 if (orderByComparator != null) {
7296 query = new StringBundler(2 +
7297 (orderByComparator.getOrderByFields().length * 3));
7298
7299 query.append(_SQL_SELECT_ORGANIZATION);
7300
7301 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7302 orderByComparator);
7303
7304 sql = query.toString();
7305 }
7306 else {
7307 sql = _SQL_SELECT_ORGANIZATION;
7308
7309 if (pagination) {
7310 sql = sql.concat(OrganizationModelImpl.ORDER_BY_JPQL);
7311 }
7312 }
7313
7314 Session session = null;
7315
7316 try {
7317 session = openSession();
7318
7319 Query q = session.createQuery(sql);
7320
7321 if (!pagination) {
7322 list = (List<Organization>)QueryUtil.list(q, getDialect(),
7323 start, end, false);
7324
7325 Collections.sort(list);
7326
7327 list = Collections.unmodifiableList(list);
7328 }
7329 else {
7330 list = (List<Organization>)QueryUtil.list(q, getDialect(),
7331 start, end);
7332 }
7333
7334 cacheResult(list);
7335
7336 finderCache.putResult(finderPath, finderArgs, list);
7337 }
7338 catch (Exception e) {
7339 finderCache.removeResult(finderPath, finderArgs);
7340
7341 throw processException(e);
7342 }
7343 finally {
7344 closeSession(session);
7345 }
7346 }
7347
7348 return list;
7349 }
7350
7351
7355 @Override
7356 public void removeAll() {
7357 for (Organization organization : findAll()) {
7358 remove(organization);
7359 }
7360 }
7361
7362
7367 @Override
7368 public int countAll() {
7369 Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL,
7370 FINDER_ARGS_EMPTY, this);
7371
7372 if (count == null) {
7373 Session session = null;
7374
7375 try {
7376 session = openSession();
7377
7378 Query q = session.createQuery(_SQL_COUNT_ORGANIZATION);
7379
7380 count = (Long)q.uniqueResult();
7381
7382 finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY,
7383 count);
7384 }
7385 catch (Exception e) {
7386 finderCache.removeResult(FINDER_PATH_COUNT_ALL,
7387 FINDER_ARGS_EMPTY);
7388
7389 throw processException(e);
7390 }
7391 finally {
7392 closeSession(session);
7393 }
7394 }
7395
7396 return count.intValue();
7397 }
7398
7399
7405 @Override
7406 public long[] getGroupPrimaryKeys(long pk) {
7407 long[] pks = organizationToGroupTableMapper.getRightPrimaryKeys(0, pk);
7408
7409 return pks.clone();
7410 }
7411
7412
7418 @Override
7419 public List<com.liferay.portal.model.Group> getGroups(long pk) {
7420 return getGroups(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
7421 }
7422
7423
7435 @Override
7436 public List<com.liferay.portal.model.Group> getGroups(long pk, int start,
7437 int end) {
7438 return getGroups(pk, start, end, null);
7439 }
7440
7441
7454 @Override
7455 public List<com.liferay.portal.model.Group> getGroups(long pk, int start,
7456 int end,
7457 OrderByComparator<com.liferay.portal.model.Group> orderByComparator) {
7458 return organizationToGroupTableMapper.getRightBaseModels(0, pk, start,
7459 end, orderByComparator);
7460 }
7461
7462
7468 @Override
7469 public int getGroupsSize(long pk) {
7470 long[] pks = organizationToGroupTableMapper.getRightPrimaryKeys(0, pk);
7471
7472 return pks.length;
7473 }
7474
7475
7482 @Override
7483 public boolean containsGroup(long pk, long groupPK) {
7484 return organizationToGroupTableMapper.containsTableMapping(0, pk,
7485 groupPK);
7486 }
7487
7488
7494 @Override
7495 public boolean containsGroups(long pk) {
7496 if (getGroupsSize(pk) > 0) {
7497 return true;
7498 }
7499 else {
7500 return false;
7501 }
7502 }
7503
7504
7510 @Override
7511 public void addGroup(long pk, long groupPK) {
7512 organizationToGroupTableMapper.addTableMapping(0, pk, groupPK);
7513 }
7514
7515
7521 @Override
7522 public void addGroup(long pk, com.liferay.portal.model.Group group) {
7523 organizationToGroupTableMapper.addTableMapping(0, pk,
7524 group.getPrimaryKey());
7525 }
7526
7527
7533 @Override
7534 public void addGroups(long pk, long[] groupPKs) {
7535 for (long groupPK : groupPKs) {
7536 organizationToGroupTableMapper.addTableMapping(0, pk, groupPK);
7537 }
7538 }
7539
7540
7546 @Override
7547 public void addGroups(long pk, List<com.liferay.portal.model.Group> groups) {
7548 for (com.liferay.portal.model.Group group : groups) {
7549 organizationToGroupTableMapper.addTableMapping(0, pk,
7550 group.getPrimaryKey());
7551 }
7552 }
7553
7554
7559 @Override
7560 public void clearGroups(long pk) {
7561 organizationToGroupTableMapper.deleteLeftPrimaryKeyTableMappings(0, pk);
7562 }
7563
7564
7570 @Override
7571 public void removeGroup(long pk, long groupPK) {
7572 organizationToGroupTableMapper.deleteTableMapping(0, pk, groupPK);
7573 }
7574
7575
7581 @Override
7582 public void removeGroup(long pk, com.liferay.portal.model.Group group) {
7583 organizationToGroupTableMapper.deleteTableMapping(0, pk,
7584 group.getPrimaryKey());
7585 }
7586
7587
7593 @Override
7594 public void removeGroups(long pk, long[] groupPKs) {
7595 for (long groupPK : groupPKs) {
7596 organizationToGroupTableMapper.deleteTableMapping(0, pk, groupPK);
7597 }
7598 }
7599
7600
7606 @Override
7607 public void removeGroups(long pk,
7608 List<com.liferay.portal.model.Group> groups) {
7609 for (com.liferay.portal.model.Group group : groups) {
7610 organizationToGroupTableMapper.deleteTableMapping(0, pk,
7611 group.getPrimaryKey());
7612 }
7613 }
7614
7615
7621 @Override
7622 public void setGroups(long pk, long[] groupPKs) {
7623 Set<Long> newGroupPKsSet = SetUtil.fromArray(groupPKs);
7624 Set<Long> oldGroupPKsSet = SetUtil.fromArray(organizationToGroupTableMapper.getRightPrimaryKeys(
7625 0, pk));
7626
7627 Set<Long> removeGroupPKsSet = new HashSet<Long>(oldGroupPKsSet);
7628
7629 removeGroupPKsSet.removeAll(newGroupPKsSet);
7630
7631 for (long removeGroupPK : removeGroupPKsSet) {
7632 organizationToGroupTableMapper.deleteTableMapping(0, pk,
7633 removeGroupPK);
7634 }
7635
7636 newGroupPKsSet.removeAll(oldGroupPKsSet);
7637
7638 for (long newGroupPK : newGroupPKsSet) {
7639 organizationToGroupTableMapper.addTableMapping(0, pk, newGroupPK);
7640 }
7641 }
7642
7643
7649 @Override
7650 public void setGroups(long pk, List<com.liferay.portal.model.Group> groups) {
7651 try {
7652 long[] groupPKs = new long[groups.size()];
7653
7654 for (int i = 0; i < groups.size(); i++) {
7655 com.liferay.portal.model.Group group = groups.get(i);
7656
7657 groupPKs[i] = group.getPrimaryKey();
7658 }
7659
7660 setGroups(pk, groupPKs);
7661 }
7662 catch (Exception e) {
7663 throw processException(e);
7664 }
7665 }
7666
7667
7673 @Override
7674 public long[] getUserPrimaryKeys(long pk) {
7675 long[] pks = organizationToUserTableMapper.getRightPrimaryKeys(0, pk);
7676
7677 return pks.clone();
7678 }
7679
7680
7686 @Override
7687 public List<com.liferay.portal.model.User> getUsers(long pk) {
7688 return getUsers(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
7689 }
7690
7691
7703 @Override
7704 public List<com.liferay.portal.model.User> getUsers(long pk, int start,
7705 int end) {
7706 return getUsers(pk, start, end, null);
7707 }
7708
7709
7722 @Override
7723 public List<com.liferay.portal.model.User> getUsers(long pk, int start,
7724 int end,
7725 OrderByComparator<com.liferay.portal.model.User> orderByComparator) {
7726 return organizationToUserTableMapper.getRightBaseModels(0, pk, start,
7727 end, orderByComparator);
7728 }
7729
7730
7736 @Override
7737 public int getUsersSize(long pk) {
7738 long[] pks = organizationToUserTableMapper.getRightPrimaryKeys(0, pk);
7739
7740 return pks.length;
7741 }
7742
7743
7750 @Override
7751 public boolean containsUser(long pk, long userPK) {
7752 return organizationToUserTableMapper.containsTableMapping(0, pk, userPK);
7753 }
7754
7755
7761 @Override
7762 public boolean containsUsers(long pk) {
7763 if (getUsersSize(pk) > 0) {
7764 return true;
7765 }
7766 else {
7767 return false;
7768 }
7769 }
7770
7771
7777 @Override
7778 public void addUser(long pk, long userPK) {
7779 organizationToUserTableMapper.addTableMapping(0, pk, userPK);
7780 }
7781
7782
7788 @Override
7789 public void addUser(long pk, com.liferay.portal.model.User user) {
7790 organizationToUserTableMapper.addTableMapping(0, pk,
7791 user.getPrimaryKey());
7792 }
7793
7794
7800 @Override
7801 public void addUsers(long pk, long[] userPKs) {
7802 for (long userPK : userPKs) {
7803 organizationToUserTableMapper.addTableMapping(0, pk, userPK);
7804 }
7805 }
7806
7807
7813 @Override
7814 public void addUsers(long pk, List<com.liferay.portal.model.User> users) {
7815 for (com.liferay.portal.model.User user : users) {
7816 organizationToUserTableMapper.addTableMapping(0, pk,
7817 user.getPrimaryKey());
7818 }
7819 }
7820
7821
7826 @Override
7827 public void clearUsers(long pk) {
7828 organizationToUserTableMapper.deleteLeftPrimaryKeyTableMappings(0, pk);
7829 }
7830
7831
7837 @Override
7838 public void removeUser(long pk, long userPK) {
7839 organizationToUserTableMapper.deleteTableMapping(0, pk, userPK);
7840 }
7841
7842
7848 @Override
7849 public void removeUser(long pk, com.liferay.portal.model.User user) {
7850 organizationToUserTableMapper.deleteTableMapping(0, pk,
7851 user.getPrimaryKey());
7852 }
7853
7854
7860 @Override
7861 public void removeUsers(long pk, long[] userPKs) {
7862 for (long userPK : userPKs) {
7863 organizationToUserTableMapper.deleteTableMapping(0, pk, userPK);
7864 }
7865 }
7866
7867
7873 @Override
7874 public void removeUsers(long pk, List<com.liferay.portal.model.User> users) {
7875 for (com.liferay.portal.model.User user : users) {
7876 organizationToUserTableMapper.deleteTableMapping(0, pk,
7877 user.getPrimaryKey());
7878 }
7879 }
7880
7881
7887 @Override
7888 public void setUsers(long pk, long[] userPKs) {
7889 Set<Long> newUserPKsSet = SetUtil.fromArray(userPKs);
7890 Set<Long> oldUserPKsSet = SetUtil.fromArray(organizationToUserTableMapper.getRightPrimaryKeys(
7891 0, pk));
7892
7893 Set<Long> removeUserPKsSet = new HashSet<Long>(oldUserPKsSet);
7894
7895 removeUserPKsSet.removeAll(newUserPKsSet);
7896
7897 for (long removeUserPK : removeUserPKsSet) {
7898 organizationToUserTableMapper.deleteTableMapping(0, pk, removeUserPK);
7899 }
7900
7901 newUserPKsSet.removeAll(oldUserPKsSet);
7902
7903 for (long newUserPK : newUserPKsSet) {
7904 organizationToUserTableMapper.addTableMapping(0, pk, newUserPK);
7905 }
7906 }
7907
7908
7914 @Override
7915 public void setUsers(long pk, List<com.liferay.portal.model.User> users) {
7916 try {
7917 long[] userPKs = new long[users.size()];
7918
7919 for (int i = 0; i < users.size(); i++) {
7920 com.liferay.portal.model.User user = users.get(i);
7921
7922 userPKs[i] = user.getPrimaryKey();
7923 }
7924
7925 setUsers(pk, userPKs);
7926 }
7927 catch (Exception e) {
7928 throw processException(e);
7929 }
7930 }
7931
7932 @Override
7933 public Set<String> getBadColumnNames() {
7934 return _badColumnNames;
7935 }
7936
7937 @Override
7938 protected Map<String, Integer> getTableColumnsMap() {
7939 return OrganizationModelImpl.TABLE_COLUMNS_MAP;
7940 }
7941
7942
7945 public void afterPropertiesSet() {
7946 organizationToGroupTableMapper = TableMapperFactory.getTableMapper("Groups_Orgs",
7947 "companyId", "organizationId", "groupId", this, groupPersistence);
7948
7949 organizationToUserTableMapper = TableMapperFactory.getTableMapper("Users_Orgs",
7950 "companyId", "organizationId", "userId", this, userPersistence);
7951 }
7952
7953 public void destroy() {
7954 entityCache.removeCache(OrganizationImpl.class.getName());
7955 finderCache.removeCache(FINDER_CLASS_NAME_ENTITY);
7956 finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
7957 finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
7958
7959 TableMapperFactory.removeTableMapper("Groups_Orgs");
7960 TableMapperFactory.removeTableMapper("Users_Orgs");
7961 }
7962
7963 @BeanReference(type = CompanyProvider.class)
7964 protected CompanyProvider companyProvider;
7965 protected EntityCache entityCache = EntityCacheUtil.getEntityCache();
7966 protected FinderCache finderCache = FinderCacheUtil.getFinderCache();
7967 @BeanReference(type = GroupPersistence.class)
7968 protected GroupPersistence groupPersistence;
7969 protected TableMapper<Organization, com.liferay.portal.model.Group> organizationToGroupTableMapper;
7970 @BeanReference(type = UserPersistence.class)
7971 protected UserPersistence userPersistence;
7972 protected TableMapper<Organization, com.liferay.portal.model.User> organizationToUserTableMapper;
7973 private static final String _SQL_SELECT_ORGANIZATION = "SELECT organization FROM Organization organization";
7974 private static final String _SQL_SELECT_ORGANIZATION_WHERE_PKS_IN = "SELECT organization FROM Organization organization WHERE organizationId IN (";
7975 private static final String _SQL_SELECT_ORGANIZATION_WHERE = "SELECT organization FROM Organization organization WHERE ";
7976 private static final String _SQL_COUNT_ORGANIZATION = "SELECT COUNT(organization) FROM Organization organization";
7977 private static final String _SQL_COUNT_ORGANIZATION_WHERE = "SELECT COUNT(organization) FROM Organization organization WHERE ";
7978 private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "organization.organizationId";
7979 private static final String _FILTER_SQL_SELECT_ORGANIZATION_WHERE = "SELECT DISTINCT {organization.*} FROM Organization_ organization WHERE ";
7980 private static final String _FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1 =
7981 "SELECT {Organization_.*} FROM (SELECT DISTINCT organization.organizationId FROM Organization_ organization WHERE ";
7982 private static final String _FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2 =
7983 ") TEMP_TABLE INNER JOIN Organization_ ON TEMP_TABLE.organizationId = Organization_.organizationId";
7984 private static final String _FILTER_SQL_COUNT_ORGANIZATION_WHERE = "SELECT COUNT(DISTINCT organization.organizationId) AS COUNT_VALUE FROM Organization_ organization WHERE ";
7985 private static final String _FILTER_ENTITY_ALIAS = "organization";
7986 private static final String _FILTER_ENTITY_TABLE = "Organization_";
7987 private static final String _ORDER_BY_ENTITY_ALIAS = "organization.";
7988 private static final String _ORDER_BY_ENTITY_TABLE = "Organization_.";
7989 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Organization exists with the primary key ";
7990 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Organization exists with the key {";
7991 private static final Log _log = LogFactoryUtil.getLog(OrganizationPersistenceImpl.class);
7992 private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
7993 "uuid", "type"
7994 });
7995 private static final Organization _nullOrganization = new OrganizationImpl() {
7996 @Override
7997 public Object clone() {
7998 return this;
7999 }
8000
8001 @Override
8002 public CacheModel<Organization> toCacheModel() {
8003 return _nullOrganizationCacheModel;
8004 }
8005 };
8006
8007 private static final CacheModel<Organization> _nullOrganizationCacheModel = new NullCacheModel();
8008
8009 private static class NullCacheModel implements CacheModel<Organization>,
8010 MVCCModel {
8011 @Override
8012 public long getMvccVersion() {
8013 return -1;
8014 }
8015
8016 @Override
8017 public void setMvccVersion(long mvccVersion) {
8018 }
8019
8020 @Override
8021 public Organization toEntityModel() {
8022 return _nullOrganization;
8023 }
8024 }
8025 }