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