001
014
015 package com.liferay.portal.service.persistence.impl;
016
017 import aQute.bnd.annotation.ProviderType;
018
019 import com.liferay.portal.kernel.bean.BeanReference;
020 import com.liferay.portal.kernel.dao.orm.EntityCache;
021 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderCache;
023 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
024 import com.liferay.portal.kernel.dao.orm.FinderPath;
025 import com.liferay.portal.kernel.dao.orm.Query;
026 import com.liferay.portal.kernel.dao.orm.QueryPos;
027 import com.liferay.portal.kernel.dao.orm.QueryUtil;
028 import com.liferay.portal.kernel.dao.orm.SQLQuery;
029 import com.liferay.portal.kernel.dao.orm.Session;
030 import com.liferay.portal.kernel.exception.NoSuchOrganizationException;
031 import com.liferay.portal.kernel.log.Log;
032 import com.liferay.portal.kernel.log.LogFactoryUtil;
033 import com.liferay.portal.kernel.model.CacheModel;
034 import com.liferay.portal.kernel.model.MVCCModel;
035 import com.liferay.portal.kernel.model.Organization;
036 import com.liferay.portal.kernel.security.permission.InlineSQLHelperUtil;
037 import com.liferay.portal.kernel.service.ServiceContext;
038 import com.liferay.portal.kernel.service.ServiceContextThreadLocal;
039 import com.liferay.portal.kernel.service.persistence.CompanyProvider;
040 import com.liferay.portal.kernel.service.persistence.CompanyProviderWrapper;
041 import com.liferay.portal.kernel.service.persistence.GroupPersistence;
042 import com.liferay.portal.kernel.service.persistence.OrganizationPersistence;
043 import com.liferay.portal.kernel.service.persistence.UserPersistence;
044 import com.liferay.portal.kernel.service.persistence.impl.BasePersistenceImpl;
045 import com.liferay.portal.kernel.service.persistence.impl.TableMapper;
046 import com.liferay.portal.kernel.service.persistence.impl.TableMapperFactory;
047 import com.liferay.portal.kernel.util.CharPool;
048 import com.liferay.portal.kernel.util.OrderByComparator;
049 import com.liferay.portal.kernel.util.SetUtil;
050 import com.liferay.portal.kernel.util.StringBundler;
051 import com.liferay.portal.kernel.util.StringPool;
052 import com.liferay.portal.kernel.util.StringUtil;
053 import com.liferay.portal.kernel.util.Validator;
054 import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
055 import com.liferay.portal.model.impl.OrganizationImpl;
056 import com.liferay.portal.model.impl.OrganizationModelImpl;
057
058 import java.io.Serializable;
059
060 import java.util.Collections;
061 import java.util.Date;
062 import java.util.HashMap;
063 import java.util.HashSet;
064 import java.util.Iterator;
065 import java.util.List;
066 import java.util.Map;
067 import java.util.Objects;
068 import java.util.Set;
069
070
082 @ProviderType
083 public class OrganizationPersistenceImpl extends BasePersistenceImpl<Organization>
084 implements OrganizationPersistence {
085
090 public static final String FINDER_CLASS_NAME_ENTITY = OrganizationImpl.class.getName();
091 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
092 ".List1";
093 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
094 ".List2";
095 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
096 OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
097 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
098 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
099 OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
100 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
101 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
102 OrganizationModelImpl.FINDER_CACHE_ENABLED, Long.class,
103 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
104 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
105 OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
106 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
107 new String[] {
108 String.class.getName(),
109
110 Integer.class.getName(), Integer.class.getName(),
111 OrderByComparator.class.getName()
112 });
113 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
114 OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
115 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
116 new String[] { String.class.getName() },
117 OrganizationModelImpl.UUID_COLUMN_BITMASK |
118 OrganizationModelImpl.NAME_COLUMN_BITMASK);
119 public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
120 OrganizationModelImpl.FINDER_CACHE_ENABLED, Long.class,
121 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
122 new String[] { String.class.getName() });
123
124
130 @Override
131 public List<Organization> findByUuid(String uuid) {
132 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
133 }
134
135
147 @Override
148 public List<Organization> findByUuid(String uuid, int start, int end) {
149 return findByUuid(uuid, start, end, null);
150 }
151
152
165 @Override
166 public List<Organization> findByUuid(String uuid, int start, int end,
167 OrderByComparator<Organization> orderByComparator) {
168 return findByUuid(uuid, start, end, orderByComparator, true);
169 }
170
171
185 @Override
186 public List<Organization> findByUuid(String uuid, int start, int end,
187 OrderByComparator<Organization> orderByComparator,
188 boolean retrieveFromCache) {
189 boolean pagination = true;
190 FinderPath finderPath = null;
191 Object[] finderArgs = null;
192
193 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
194 (orderByComparator == null)) {
195 pagination = false;
196 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
197 finderArgs = new Object[] { uuid };
198 }
199 else {
200 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
201 finderArgs = new Object[] { uuid, start, end, orderByComparator };
202 }
203
204 List<Organization> list = null;
205
206 if (retrieveFromCache) {
207 list = (List<Organization>)finderCache.getResult(finderPath,
208 finderArgs, this);
209
210 if ((list != null) && !list.isEmpty()) {
211 for (Organization organization : list) {
212 if (!Objects.equals(uuid, organization.getUuid())) {
213 list = null;
214
215 break;
216 }
217 }
218 }
219 }
220
221 if (list == null) {
222 StringBundler query = null;
223
224 if (orderByComparator != null) {
225 query = new StringBundler(3 +
226 (orderByComparator.getOrderByFields().length * 2));
227 }
228 else {
229 query = new StringBundler(3);
230 }
231
232 query.append(_SQL_SELECT_ORGANIZATION_WHERE);
233
234 boolean bindUuid = false;
235
236 if (uuid == null) {
237 query.append(_FINDER_COLUMN_UUID_UUID_1);
238 }
239 else if (uuid.equals(StringPool.BLANK)) {
240 query.append(_FINDER_COLUMN_UUID_UUID_3);
241 }
242 else {
243 bindUuid = true;
244
245 query.append(_FINDER_COLUMN_UUID_UUID_2);
246 }
247
248 if (orderByComparator != null) {
249 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
250 orderByComparator);
251 }
252 else
253 if (pagination) {
254 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
255 }
256
257 String sql = query.toString();
258
259 Session session = null;
260
261 try {
262 session = openSession();
263
264 Query q = session.createQuery(sql);
265
266 QueryPos qPos = QueryPos.getInstance(q);
267
268 if (bindUuid) {
269 qPos.add(uuid);
270 }
271
272 if (!pagination) {
273 list = (List<Organization>)QueryUtil.list(q, getDialect(),
274 start, end, false);
275
276 Collections.sort(list);
277
278 list = Collections.unmodifiableList(list);
279 }
280 else {
281 list = (List<Organization>)QueryUtil.list(q, getDialect(),
282 start, end);
283 }
284
285 cacheResult(list);
286
287 finderCache.putResult(finderPath, finderArgs, list);
288 }
289 catch (Exception e) {
290 finderCache.removeResult(finderPath, finderArgs);
291
292 throw processException(e);
293 }
294 finally {
295 closeSession(session);
296 }
297 }
298
299 return list;
300 }
301
302
310 @Override
311 public Organization findByUuid_First(String uuid,
312 OrderByComparator<Organization> orderByComparator)
313 throws NoSuchOrganizationException {
314 Organization organization = fetchByUuid_First(uuid, orderByComparator);
315
316 if (organization != null) {
317 return organization;
318 }
319
320 StringBundler msg = new StringBundler(4);
321
322 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
323
324 msg.append("uuid=");
325 msg.append(uuid);
326
327 msg.append(StringPool.CLOSE_CURLY_BRACE);
328
329 throw new NoSuchOrganizationException(msg.toString());
330 }
331
332
339 @Override
340 public Organization fetchByUuid_First(String uuid,
341 OrderByComparator<Organization> orderByComparator) {
342 List<Organization> list = findByUuid(uuid, 0, 1, orderByComparator);
343
344 if (!list.isEmpty()) {
345 return list.get(0);
346 }
347
348 return null;
349 }
350
351
359 @Override
360 public Organization findByUuid_Last(String uuid,
361 OrderByComparator<Organization> orderByComparator)
362 throws NoSuchOrganizationException {
363 Organization organization = fetchByUuid_Last(uuid, orderByComparator);
364
365 if (organization != null) {
366 return organization;
367 }
368
369 StringBundler msg = new StringBundler(4);
370
371 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
372
373 msg.append("uuid=");
374 msg.append(uuid);
375
376 msg.append(StringPool.CLOSE_CURLY_BRACE);
377
378 throw new NoSuchOrganizationException(msg.toString());
379 }
380
381
388 @Override
389 public Organization fetchByUuid_Last(String uuid,
390 OrderByComparator<Organization> orderByComparator) {
391 int count = countByUuid(uuid);
392
393 if (count == 0) {
394 return null;
395 }
396
397 List<Organization> list = findByUuid(uuid, count - 1, count,
398 orderByComparator);
399
400 if (!list.isEmpty()) {
401 return list.get(0);
402 }
403
404 return null;
405 }
406
407
416 @Override
417 public Organization[] findByUuid_PrevAndNext(long organizationId,
418 String uuid, OrderByComparator<Organization> orderByComparator)
419 throws NoSuchOrganizationException {
420 Organization organization = findByPrimaryKey(organizationId);
421
422 Session session = null;
423
424 try {
425 session = openSession();
426
427 Organization[] array = new OrganizationImpl[3];
428
429 array[0] = getByUuid_PrevAndNext(session, organization, uuid,
430 orderByComparator, true);
431
432 array[1] = organization;
433
434 array[2] = getByUuid_PrevAndNext(session, organization, uuid,
435 orderByComparator, false);
436
437 return array;
438 }
439 catch (Exception e) {
440 throw processException(e);
441 }
442 finally {
443 closeSession(session);
444 }
445 }
446
447 protected Organization getByUuid_PrevAndNext(Session session,
448 Organization organization, String uuid,
449 OrderByComparator<Organization> orderByComparator, boolean previous) {
450 StringBundler query = null;
451
452 if (orderByComparator != null) {
453 query = new StringBundler(4 +
454 (orderByComparator.getOrderByConditionFields().length * 3) +
455 (orderByComparator.getOrderByFields().length * 3));
456 }
457 else {
458 query = new StringBundler(3);
459 }
460
461 query.append(_SQL_SELECT_ORGANIZATION_WHERE);
462
463 boolean bindUuid = false;
464
465 if (uuid == null) {
466 query.append(_FINDER_COLUMN_UUID_UUID_1);
467 }
468 else if (uuid.equals(StringPool.BLANK)) {
469 query.append(_FINDER_COLUMN_UUID_UUID_3);
470 }
471 else {
472 bindUuid = true;
473
474 query.append(_FINDER_COLUMN_UUID_UUID_2);
475 }
476
477 if (orderByComparator != null) {
478 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
479
480 if (orderByConditionFields.length > 0) {
481 query.append(WHERE_AND);
482 }
483
484 for (int i = 0; i < orderByConditionFields.length; i++) {
485 query.append(_ORDER_BY_ENTITY_ALIAS);
486 query.append(orderByConditionFields[i]);
487
488 if ((i + 1) < orderByConditionFields.length) {
489 if (orderByComparator.isAscending() ^ previous) {
490 query.append(WHERE_GREATER_THAN_HAS_NEXT);
491 }
492 else {
493 query.append(WHERE_LESSER_THAN_HAS_NEXT);
494 }
495 }
496 else {
497 if (orderByComparator.isAscending() ^ previous) {
498 query.append(WHERE_GREATER_THAN);
499 }
500 else {
501 query.append(WHERE_LESSER_THAN);
502 }
503 }
504 }
505
506 query.append(ORDER_BY_CLAUSE);
507
508 String[] orderByFields = orderByComparator.getOrderByFields();
509
510 for (int i = 0; i < orderByFields.length; i++) {
511 query.append(_ORDER_BY_ENTITY_ALIAS);
512 query.append(orderByFields[i]);
513
514 if ((i + 1) < orderByFields.length) {
515 if (orderByComparator.isAscending() ^ previous) {
516 query.append(ORDER_BY_ASC_HAS_NEXT);
517 }
518 else {
519 query.append(ORDER_BY_DESC_HAS_NEXT);
520 }
521 }
522 else {
523 if (orderByComparator.isAscending() ^ previous) {
524 query.append(ORDER_BY_ASC);
525 }
526 else {
527 query.append(ORDER_BY_DESC);
528 }
529 }
530 }
531 }
532 else {
533 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
534 }
535
536 String sql = query.toString();
537
538 Query q = session.createQuery(sql);
539
540 q.setFirstResult(0);
541 q.setMaxResults(2);
542
543 QueryPos qPos = QueryPos.getInstance(q);
544
545 if (bindUuid) {
546 qPos.add(uuid);
547 }
548
549 if (orderByComparator != null) {
550 Object[] values = orderByComparator.getOrderByConditionValues(organization);
551
552 for (Object value : values) {
553 qPos.add(value);
554 }
555 }
556
557 List<Organization> list = q.list();
558
559 if (list.size() == 2) {
560 return list.get(1);
561 }
562 else {
563 return null;
564 }
565 }
566
567
573 @Override
574 public List<Organization> filterFindByUuid(String uuid) {
575 return filterFindByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
576 }
577
578
590 @Override
591 public List<Organization> filterFindByUuid(String uuid, int start, int end) {
592 return filterFindByUuid(uuid, start, end, null);
593 }
594
595
608 @Override
609 public List<Organization> filterFindByUuid(String uuid, int start, int end,
610 OrderByComparator<Organization> orderByComparator) {
611 if (!InlineSQLHelperUtil.isEnabled()) {
612 return findByUuid(uuid, start, end, orderByComparator);
613 }
614
615 StringBundler query = null;
616
617 if (orderByComparator != null) {
618 query = new StringBundler(3 +
619 (orderByComparator.getOrderByFields().length * 2));
620 }
621 else {
622 query = new StringBundler(4);
623 }
624
625 if (getDB().isSupportsInlineDistinct()) {
626 query.append(_FILTER_SQL_SELECT_ORGANIZATION_WHERE);
627 }
628 else {
629 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1);
630 }
631
632 boolean bindUuid = false;
633
634 if (uuid == null) {
635 query.append(_FINDER_COLUMN_UUID_UUID_1_SQL);
636 }
637 else if (uuid.equals(StringPool.BLANK)) {
638 query.append(_FINDER_COLUMN_UUID_UUID_3_SQL);
639 }
640 else {
641 bindUuid = true;
642
643 query.append(_FINDER_COLUMN_UUID_UUID_2_SQL);
644 }
645
646 if (!getDB().isSupportsInlineDistinct()) {
647 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2);
648 }
649
650 if (orderByComparator != null) {
651 if (getDB().isSupportsInlineDistinct()) {
652 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
653 orderByComparator, true);
654 }
655 else {
656 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
657 orderByComparator, true);
658 }
659 }
660 else {
661 if (getDB().isSupportsInlineDistinct()) {
662 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
663 }
664 else {
665 query.append(OrganizationModelImpl.ORDER_BY_SQL);
666 }
667 }
668
669 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
670 Organization.class.getName(),
671 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
672
673 Session session = null;
674
675 try {
676 session = openSession();
677
678 SQLQuery q = session.createSynchronizedSQLQuery(sql);
679
680 if (getDB().isSupportsInlineDistinct()) {
681 q.addEntity(_FILTER_ENTITY_ALIAS, OrganizationImpl.class);
682 }
683 else {
684 q.addEntity(_FILTER_ENTITY_TABLE, OrganizationImpl.class);
685 }
686
687 QueryPos qPos = QueryPos.getInstance(q);
688
689 if (bindUuid) {
690 qPos.add(uuid);
691 }
692
693 return (List<Organization>)QueryUtil.list(q, getDialect(), start,
694 end);
695 }
696 catch (Exception e) {
697 throw processException(e);
698 }
699 finally {
700 closeSession(session);
701 }
702 }
703
704
713 @Override
714 public Organization[] filterFindByUuid_PrevAndNext(long organizationId,
715 String uuid, OrderByComparator<Organization> orderByComparator)
716 throws NoSuchOrganizationException {
717 if (!InlineSQLHelperUtil.isEnabled()) {
718 return findByUuid_PrevAndNext(organizationId, uuid,
719 orderByComparator);
720 }
721
722 Organization organization = findByPrimaryKey(organizationId);
723
724 Session session = null;
725
726 try {
727 session = openSession();
728
729 Organization[] array = new OrganizationImpl[3];
730
731 array[0] = filterGetByUuid_PrevAndNext(session, organization, uuid,
732 orderByComparator, true);
733
734 array[1] = organization;
735
736 array[2] = filterGetByUuid_PrevAndNext(session, organization, uuid,
737 orderByComparator, false);
738
739 return array;
740 }
741 catch (Exception e) {
742 throw processException(e);
743 }
744 finally {
745 closeSession(session);
746 }
747 }
748
749 protected Organization filterGetByUuid_PrevAndNext(Session session,
750 Organization organization, String uuid,
751 OrderByComparator<Organization> orderByComparator, boolean previous) {
752 StringBundler query = null;
753
754 if (orderByComparator != null) {
755 query = new StringBundler(5 +
756 (orderByComparator.getOrderByConditionFields().length * 3) +
757 (orderByComparator.getOrderByFields().length * 3));
758 }
759 else {
760 query = new StringBundler(4);
761 }
762
763 if (getDB().isSupportsInlineDistinct()) {
764 query.append(_FILTER_SQL_SELECT_ORGANIZATION_WHERE);
765 }
766 else {
767 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1);
768 }
769
770 boolean bindUuid = false;
771
772 if (uuid == null) {
773 query.append(_FINDER_COLUMN_UUID_UUID_1_SQL);
774 }
775 else if (uuid.equals(StringPool.BLANK)) {
776 query.append(_FINDER_COLUMN_UUID_UUID_3_SQL);
777 }
778 else {
779 bindUuid = true;
780
781 query.append(_FINDER_COLUMN_UUID_UUID_2_SQL);
782 }
783
784 if (!getDB().isSupportsInlineDistinct()) {
785 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2);
786 }
787
788 if (orderByComparator != null) {
789 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
790
791 if (orderByConditionFields.length > 0) {
792 query.append(WHERE_AND);
793 }
794
795 for (int i = 0; i < orderByConditionFields.length; i++) {
796 if (getDB().isSupportsInlineDistinct()) {
797 query.append(_ORDER_BY_ENTITY_ALIAS);
798 }
799 else {
800 query.append(_ORDER_BY_ENTITY_TABLE);
801 }
802
803 query.append(orderByConditionFields[i]);
804
805 if ((i + 1) < orderByConditionFields.length) {
806 if (orderByComparator.isAscending() ^ previous) {
807 query.append(WHERE_GREATER_THAN_HAS_NEXT);
808 }
809 else {
810 query.append(WHERE_LESSER_THAN_HAS_NEXT);
811 }
812 }
813 else {
814 if (orderByComparator.isAscending() ^ previous) {
815 query.append(WHERE_GREATER_THAN);
816 }
817 else {
818 query.append(WHERE_LESSER_THAN);
819 }
820 }
821 }
822
823 query.append(ORDER_BY_CLAUSE);
824
825 String[] orderByFields = orderByComparator.getOrderByFields();
826
827 for (int i = 0; i < orderByFields.length; i++) {
828 if (getDB().isSupportsInlineDistinct()) {
829 query.append(_ORDER_BY_ENTITY_ALIAS);
830 }
831 else {
832 query.append(_ORDER_BY_ENTITY_TABLE);
833 }
834
835 query.append(orderByFields[i]);
836
837 if ((i + 1) < orderByFields.length) {
838 if (orderByComparator.isAscending() ^ previous) {
839 query.append(ORDER_BY_ASC_HAS_NEXT);
840 }
841 else {
842 query.append(ORDER_BY_DESC_HAS_NEXT);
843 }
844 }
845 else {
846 if (orderByComparator.isAscending() ^ previous) {
847 query.append(ORDER_BY_ASC);
848 }
849 else {
850 query.append(ORDER_BY_DESC);
851 }
852 }
853 }
854 }
855 else {
856 if (getDB().isSupportsInlineDistinct()) {
857 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
858 }
859 else {
860 query.append(OrganizationModelImpl.ORDER_BY_SQL);
861 }
862 }
863
864 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
865 Organization.class.getName(),
866 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
867
868 SQLQuery q = session.createSynchronizedSQLQuery(sql);
869
870 q.setFirstResult(0);
871 q.setMaxResults(2);
872
873 if (getDB().isSupportsInlineDistinct()) {
874 q.addEntity(_FILTER_ENTITY_ALIAS, OrganizationImpl.class);
875 }
876 else {
877 q.addEntity(_FILTER_ENTITY_TABLE, OrganizationImpl.class);
878 }
879
880 QueryPos qPos = QueryPos.getInstance(q);
881
882 if (bindUuid) {
883 qPos.add(uuid);
884 }
885
886 if (orderByComparator != null) {
887 Object[] values = orderByComparator.getOrderByConditionValues(organization);
888
889 for (Object value : values) {
890 qPos.add(value);
891 }
892 }
893
894 List<Organization> list = q.list();
895
896 if (list.size() == 2) {
897 return list.get(1);
898 }
899 else {
900 return null;
901 }
902 }
903
904
909 @Override
910 public void removeByUuid(String uuid) {
911 for (Organization organization : findByUuid(uuid, QueryUtil.ALL_POS,
912 QueryUtil.ALL_POS, null)) {
913 remove(organization);
914 }
915 }
916
917
923 @Override
924 public int countByUuid(String uuid) {
925 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
926
927 Object[] finderArgs = new Object[] { uuid };
928
929 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
930
931 if (count == null) {
932 StringBundler query = new StringBundler(2);
933
934 query.append(_SQL_COUNT_ORGANIZATION_WHERE);
935
936 boolean bindUuid = false;
937
938 if (uuid == null) {
939 query.append(_FINDER_COLUMN_UUID_UUID_1);
940 }
941 else if (uuid.equals(StringPool.BLANK)) {
942 query.append(_FINDER_COLUMN_UUID_UUID_3);
943 }
944 else {
945 bindUuid = true;
946
947 query.append(_FINDER_COLUMN_UUID_UUID_2);
948 }
949
950 String sql = query.toString();
951
952 Session session = null;
953
954 try {
955 session = openSession();
956
957 Query q = session.createQuery(sql);
958
959 QueryPos qPos = QueryPos.getInstance(q);
960
961 if (bindUuid) {
962 qPos.add(uuid);
963 }
964
965 count = (Long)q.uniqueResult();
966
967 finderCache.putResult(finderPath, finderArgs, count);
968 }
969 catch (Exception e) {
970 finderCache.removeResult(finderPath, finderArgs);
971
972 throw processException(e);
973 }
974 finally {
975 closeSession(session);
976 }
977 }
978
979 return count.intValue();
980 }
981
982
988 @Override
989 public int filterCountByUuid(String uuid) {
990 if (!InlineSQLHelperUtil.isEnabled()) {
991 return countByUuid(uuid);
992 }
993
994 StringBundler query = new StringBundler(2);
995
996 query.append(_FILTER_SQL_COUNT_ORGANIZATION_WHERE);
997
998 boolean bindUuid = false;
999
1000 if (uuid == null) {
1001 query.append(_FINDER_COLUMN_UUID_UUID_1_SQL);
1002 }
1003 else if (uuid.equals(StringPool.BLANK)) {
1004 query.append(_FINDER_COLUMN_UUID_UUID_3_SQL);
1005 }
1006 else {
1007 bindUuid = true;
1008
1009 query.append(_FINDER_COLUMN_UUID_UUID_2_SQL);
1010 }
1011
1012 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1013 Organization.class.getName(),
1014 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1015
1016 Session session = null;
1017
1018 try {
1019 session = openSession();
1020
1021 SQLQuery q = session.createSynchronizedSQLQuery(sql);
1022
1023 q.addScalar(COUNT_COLUMN_NAME,
1024 com.liferay.portal.kernel.dao.orm.Type.LONG);
1025
1026 QueryPos qPos = QueryPos.getInstance(q);
1027
1028 if (bindUuid) {
1029 qPos.add(uuid);
1030 }
1031
1032 Long count = (Long)q.uniqueResult();
1033
1034 return count.intValue();
1035 }
1036 catch (Exception e) {
1037 throw processException(e);
1038 }
1039 finally {
1040 closeSession(session);
1041 }
1042 }
1043
1044 private static final String _FINDER_COLUMN_UUID_UUID_1 = "organization.uuid IS NULL";
1045 private static final String _FINDER_COLUMN_UUID_UUID_2 = "organization.uuid = ?";
1046 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(organization.uuid IS NULL OR organization.uuid = '')";
1047 private static final String _FINDER_COLUMN_UUID_UUID_1_SQL = "organization.uuid_ IS NULL";
1048 private static final String _FINDER_COLUMN_UUID_UUID_2_SQL = "organization.uuid_ = ?";
1049 private static final String _FINDER_COLUMN_UUID_UUID_3_SQL = "(organization.uuid_ IS NULL OR organization.uuid_ = '')";
1050 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
1051 OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
1052 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
1053 new String[] {
1054 String.class.getName(), Long.class.getName(),
1055
1056 Integer.class.getName(), Integer.class.getName(),
1057 OrderByComparator.class.getName()
1058 });
1059 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
1060 new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
1061 OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
1062 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
1063 new String[] { String.class.getName(), Long.class.getName() },
1064 OrganizationModelImpl.UUID_COLUMN_BITMASK |
1065 OrganizationModelImpl.COMPANYID_COLUMN_BITMASK |
1066 OrganizationModelImpl.NAME_COLUMN_BITMASK);
1067 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
1068 OrganizationModelImpl.FINDER_CACHE_ENABLED, Long.class,
1069 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
1070 new String[] { String.class.getName(), Long.class.getName() });
1071
1072
1079 @Override
1080 public List<Organization> findByUuid_C(String uuid, long companyId) {
1081 return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
1082 QueryUtil.ALL_POS, null);
1083 }
1084
1085
1098 @Override
1099 public List<Organization> findByUuid_C(String uuid, long companyId,
1100 int start, int end) {
1101 return findByUuid_C(uuid, companyId, start, end, null);
1102 }
1103
1104
1118 @Override
1119 public List<Organization> findByUuid_C(String uuid, long companyId,
1120 int start, int end, OrderByComparator<Organization> orderByComparator) {
1121 return findByUuid_C(uuid, companyId, start, end, orderByComparator, true);
1122 }
1123
1124
1139 @Override
1140 public List<Organization> findByUuid_C(String uuid, long companyId,
1141 int start, int end, OrderByComparator<Organization> orderByComparator,
1142 boolean retrieveFromCache) {
1143 boolean pagination = true;
1144 FinderPath finderPath = null;
1145 Object[] finderArgs = null;
1146
1147 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1148 (orderByComparator == null)) {
1149 pagination = false;
1150 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
1151 finderArgs = new Object[] { uuid, companyId };
1152 }
1153 else {
1154 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
1155 finderArgs = new Object[] {
1156 uuid, companyId,
1157
1158 start, end, orderByComparator
1159 };
1160 }
1161
1162 List<Organization> list = null;
1163
1164 if (retrieveFromCache) {
1165 list = (List<Organization>)finderCache.getResult(finderPath,
1166 finderArgs, this);
1167
1168 if ((list != null) && !list.isEmpty()) {
1169 for (Organization organization : list) {
1170 if (!Objects.equals(uuid, organization.getUuid()) ||
1171 (companyId != organization.getCompanyId())) {
1172 list = null;
1173
1174 break;
1175 }
1176 }
1177 }
1178 }
1179
1180 if (list == null) {
1181 StringBundler query = null;
1182
1183 if (orderByComparator != null) {
1184 query = new StringBundler(4 +
1185 (orderByComparator.getOrderByFields().length * 2));
1186 }
1187 else {
1188 query = new StringBundler(4);
1189 }
1190
1191 query.append(_SQL_SELECT_ORGANIZATION_WHERE);
1192
1193 boolean bindUuid = false;
1194
1195 if (uuid == null) {
1196 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1197 }
1198 else if (uuid.equals(StringPool.BLANK)) {
1199 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1200 }
1201 else {
1202 bindUuid = true;
1203
1204 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1205 }
1206
1207 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1208
1209 if (orderByComparator != null) {
1210 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1211 orderByComparator);
1212 }
1213 else
1214 if (pagination) {
1215 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
1216 }
1217
1218 String sql = query.toString();
1219
1220 Session session = null;
1221
1222 try {
1223 session = openSession();
1224
1225 Query q = session.createQuery(sql);
1226
1227 QueryPos qPos = QueryPos.getInstance(q);
1228
1229 if (bindUuid) {
1230 qPos.add(uuid);
1231 }
1232
1233 qPos.add(companyId);
1234
1235 if (!pagination) {
1236 list = (List<Organization>)QueryUtil.list(q, getDialect(),
1237 start, end, false);
1238
1239 Collections.sort(list);
1240
1241 list = Collections.unmodifiableList(list);
1242 }
1243 else {
1244 list = (List<Organization>)QueryUtil.list(q, getDialect(),
1245 start, end);
1246 }
1247
1248 cacheResult(list);
1249
1250 finderCache.putResult(finderPath, finderArgs, list);
1251 }
1252 catch (Exception e) {
1253 finderCache.removeResult(finderPath, finderArgs);
1254
1255 throw processException(e);
1256 }
1257 finally {
1258 closeSession(session);
1259 }
1260 }
1261
1262 return list;
1263 }
1264
1265
1274 @Override
1275 public Organization findByUuid_C_First(String uuid, long companyId,
1276 OrderByComparator<Organization> orderByComparator)
1277 throws NoSuchOrganizationException {
1278 Organization organization = fetchByUuid_C_First(uuid, companyId,
1279 orderByComparator);
1280
1281 if (organization != null) {
1282 return organization;
1283 }
1284
1285 StringBundler msg = new StringBundler(6);
1286
1287 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1288
1289 msg.append("uuid=");
1290 msg.append(uuid);
1291
1292 msg.append(", companyId=");
1293 msg.append(companyId);
1294
1295 msg.append(StringPool.CLOSE_CURLY_BRACE);
1296
1297 throw new NoSuchOrganizationException(msg.toString());
1298 }
1299
1300
1308 @Override
1309 public Organization fetchByUuid_C_First(String uuid, long companyId,
1310 OrderByComparator<Organization> orderByComparator) {
1311 List<Organization> list = findByUuid_C(uuid, companyId, 0, 1,
1312 orderByComparator);
1313
1314 if (!list.isEmpty()) {
1315 return list.get(0);
1316 }
1317
1318 return null;
1319 }
1320
1321
1330 @Override
1331 public Organization findByUuid_C_Last(String uuid, long companyId,
1332 OrderByComparator<Organization> orderByComparator)
1333 throws NoSuchOrganizationException {
1334 Organization organization = fetchByUuid_C_Last(uuid, companyId,
1335 orderByComparator);
1336
1337 if (organization != null) {
1338 return organization;
1339 }
1340
1341 StringBundler msg = new StringBundler(6);
1342
1343 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1344
1345 msg.append("uuid=");
1346 msg.append(uuid);
1347
1348 msg.append(", companyId=");
1349 msg.append(companyId);
1350
1351 msg.append(StringPool.CLOSE_CURLY_BRACE);
1352
1353 throw new NoSuchOrganizationException(msg.toString());
1354 }
1355
1356
1364 @Override
1365 public Organization fetchByUuid_C_Last(String uuid, long companyId,
1366 OrderByComparator<Organization> orderByComparator) {
1367 int count = countByUuid_C(uuid, companyId);
1368
1369 if (count == 0) {
1370 return null;
1371 }
1372
1373 List<Organization> list = findByUuid_C(uuid, companyId, count - 1,
1374 count, orderByComparator);
1375
1376 if (!list.isEmpty()) {
1377 return list.get(0);
1378 }
1379
1380 return null;
1381 }
1382
1383
1393 @Override
1394 public Organization[] findByUuid_C_PrevAndNext(long organizationId,
1395 String uuid, long companyId,
1396 OrderByComparator<Organization> orderByComparator)
1397 throws NoSuchOrganizationException {
1398 Organization organization = findByPrimaryKey(organizationId);
1399
1400 Session session = null;
1401
1402 try {
1403 session = openSession();
1404
1405 Organization[] array = new OrganizationImpl[3];
1406
1407 array[0] = getByUuid_C_PrevAndNext(session, organization, uuid,
1408 companyId, orderByComparator, true);
1409
1410 array[1] = organization;
1411
1412 array[2] = getByUuid_C_PrevAndNext(session, organization, uuid,
1413 companyId, orderByComparator, false);
1414
1415 return array;
1416 }
1417 catch (Exception e) {
1418 throw processException(e);
1419 }
1420 finally {
1421 closeSession(session);
1422 }
1423 }
1424
1425 protected Organization getByUuid_C_PrevAndNext(Session session,
1426 Organization organization, String uuid, long companyId,
1427 OrderByComparator<Organization> orderByComparator, boolean previous) {
1428 StringBundler query = null;
1429
1430 if (orderByComparator != null) {
1431 query = new StringBundler(5 +
1432 (orderByComparator.getOrderByConditionFields().length * 3) +
1433 (orderByComparator.getOrderByFields().length * 3));
1434 }
1435 else {
1436 query = new StringBundler(4);
1437 }
1438
1439 query.append(_SQL_SELECT_ORGANIZATION_WHERE);
1440
1441 boolean bindUuid = false;
1442
1443 if (uuid == null) {
1444 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1445 }
1446 else if (uuid.equals(StringPool.BLANK)) {
1447 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1448 }
1449 else {
1450 bindUuid = true;
1451
1452 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1453 }
1454
1455 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1456
1457 if (orderByComparator != null) {
1458 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1459
1460 if (orderByConditionFields.length > 0) {
1461 query.append(WHERE_AND);
1462 }
1463
1464 for (int i = 0; i < orderByConditionFields.length; i++) {
1465 query.append(_ORDER_BY_ENTITY_ALIAS);
1466 query.append(orderByConditionFields[i]);
1467
1468 if ((i + 1) < orderByConditionFields.length) {
1469 if (orderByComparator.isAscending() ^ previous) {
1470 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1471 }
1472 else {
1473 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1474 }
1475 }
1476 else {
1477 if (orderByComparator.isAscending() ^ previous) {
1478 query.append(WHERE_GREATER_THAN);
1479 }
1480 else {
1481 query.append(WHERE_LESSER_THAN);
1482 }
1483 }
1484 }
1485
1486 query.append(ORDER_BY_CLAUSE);
1487
1488 String[] orderByFields = orderByComparator.getOrderByFields();
1489
1490 for (int i = 0; i < orderByFields.length; i++) {
1491 query.append(_ORDER_BY_ENTITY_ALIAS);
1492 query.append(orderByFields[i]);
1493
1494 if ((i + 1) < orderByFields.length) {
1495 if (orderByComparator.isAscending() ^ previous) {
1496 query.append(ORDER_BY_ASC_HAS_NEXT);
1497 }
1498 else {
1499 query.append(ORDER_BY_DESC_HAS_NEXT);
1500 }
1501 }
1502 else {
1503 if (orderByComparator.isAscending() ^ previous) {
1504 query.append(ORDER_BY_ASC);
1505 }
1506 else {
1507 query.append(ORDER_BY_DESC);
1508 }
1509 }
1510 }
1511 }
1512 else {
1513 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
1514 }
1515
1516 String sql = query.toString();
1517
1518 Query q = session.createQuery(sql);
1519
1520 q.setFirstResult(0);
1521 q.setMaxResults(2);
1522
1523 QueryPos qPos = QueryPos.getInstance(q);
1524
1525 if (bindUuid) {
1526 qPos.add(uuid);
1527 }
1528
1529 qPos.add(companyId);
1530
1531 if (orderByComparator != null) {
1532 Object[] values = orderByComparator.getOrderByConditionValues(organization);
1533
1534 for (Object value : values) {
1535 qPos.add(value);
1536 }
1537 }
1538
1539 List<Organization> list = q.list();
1540
1541 if (list.size() == 2) {
1542 return list.get(1);
1543 }
1544 else {
1545 return null;
1546 }
1547 }
1548
1549
1556 @Override
1557 public List<Organization> filterFindByUuid_C(String uuid, long companyId) {
1558 return filterFindByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
1559 QueryUtil.ALL_POS, null);
1560 }
1561
1562
1575 @Override
1576 public List<Organization> filterFindByUuid_C(String uuid, long companyId,
1577 int start, int end) {
1578 return filterFindByUuid_C(uuid, companyId, start, end, null);
1579 }
1580
1581
1595 @Override
1596 public List<Organization> filterFindByUuid_C(String uuid, long companyId,
1597 int start, int end, OrderByComparator<Organization> orderByComparator) {
1598 if (!InlineSQLHelperUtil.isEnabled(companyId, 0)) {
1599 return findByUuid_C(uuid, companyId, start, end, orderByComparator);
1600 }
1601
1602 StringBundler query = null;
1603
1604 if (orderByComparator != null) {
1605 query = new StringBundler(4 +
1606 (orderByComparator.getOrderByFields().length * 2));
1607 }
1608 else {
1609 query = new StringBundler(5);
1610 }
1611
1612 if (getDB().isSupportsInlineDistinct()) {
1613 query.append(_FILTER_SQL_SELECT_ORGANIZATION_WHERE);
1614 }
1615 else {
1616 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1);
1617 }
1618
1619 boolean bindUuid = false;
1620
1621 if (uuid == null) {
1622 query.append(_FINDER_COLUMN_UUID_C_UUID_1_SQL);
1623 }
1624 else if (uuid.equals(StringPool.BLANK)) {
1625 query.append(_FINDER_COLUMN_UUID_C_UUID_3_SQL);
1626 }
1627 else {
1628 bindUuid = true;
1629
1630 query.append(_FINDER_COLUMN_UUID_C_UUID_2_SQL);
1631 }
1632
1633 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1634
1635 if (!getDB().isSupportsInlineDistinct()) {
1636 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2);
1637 }
1638
1639 if (orderByComparator != null) {
1640 if (getDB().isSupportsInlineDistinct()) {
1641 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1642 orderByComparator, true);
1643 }
1644 else {
1645 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1646 orderByComparator, true);
1647 }
1648 }
1649 else {
1650 if (getDB().isSupportsInlineDistinct()) {
1651 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
1652 }
1653 else {
1654 query.append(OrganizationModelImpl.ORDER_BY_SQL);
1655 }
1656 }
1657
1658 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1659 Organization.class.getName(),
1660 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1661
1662 Session session = null;
1663
1664 try {
1665 session = openSession();
1666
1667 SQLQuery q = session.createSynchronizedSQLQuery(sql);
1668
1669 if (getDB().isSupportsInlineDistinct()) {
1670 q.addEntity(_FILTER_ENTITY_ALIAS, OrganizationImpl.class);
1671 }
1672 else {
1673 q.addEntity(_FILTER_ENTITY_TABLE, OrganizationImpl.class);
1674 }
1675
1676 QueryPos qPos = QueryPos.getInstance(q);
1677
1678 if (bindUuid) {
1679 qPos.add(uuid);
1680 }
1681
1682 qPos.add(companyId);
1683
1684 return (List<Organization>)QueryUtil.list(q, getDialect(), start,
1685 end);
1686 }
1687 catch (Exception e) {
1688 throw processException(e);
1689 }
1690 finally {
1691 closeSession(session);
1692 }
1693 }
1694
1695
1705 @Override
1706 public Organization[] filterFindByUuid_C_PrevAndNext(long organizationId,
1707 String uuid, long companyId,
1708 OrderByComparator<Organization> orderByComparator)
1709 throws NoSuchOrganizationException {
1710 if (!InlineSQLHelperUtil.isEnabled(companyId, 0)) {
1711 return findByUuid_C_PrevAndNext(organizationId, uuid, companyId,
1712 orderByComparator);
1713 }
1714
1715 Organization organization = findByPrimaryKey(organizationId);
1716
1717 Session session = null;
1718
1719 try {
1720 session = openSession();
1721
1722 Organization[] array = new OrganizationImpl[3];
1723
1724 array[0] = filterGetByUuid_C_PrevAndNext(session, organization,
1725 uuid, companyId, orderByComparator, true);
1726
1727 array[1] = organization;
1728
1729 array[2] = filterGetByUuid_C_PrevAndNext(session, organization,
1730 uuid, companyId, orderByComparator, false);
1731
1732 return array;
1733 }
1734 catch (Exception e) {
1735 throw processException(e);
1736 }
1737 finally {
1738 closeSession(session);
1739 }
1740 }
1741
1742 protected Organization filterGetByUuid_C_PrevAndNext(Session session,
1743 Organization organization, String uuid, long companyId,
1744 OrderByComparator<Organization> orderByComparator, boolean previous) {
1745 StringBundler query = null;
1746
1747 if (orderByComparator != null) {
1748 query = new StringBundler(6 +
1749 (orderByComparator.getOrderByConditionFields().length * 3) +
1750 (orderByComparator.getOrderByFields().length * 3));
1751 }
1752 else {
1753 query = new StringBundler(5);
1754 }
1755
1756 if (getDB().isSupportsInlineDistinct()) {
1757 query.append(_FILTER_SQL_SELECT_ORGANIZATION_WHERE);
1758 }
1759 else {
1760 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1);
1761 }
1762
1763 boolean bindUuid = false;
1764
1765 if (uuid == null) {
1766 query.append(_FINDER_COLUMN_UUID_C_UUID_1_SQL);
1767 }
1768 else if (uuid.equals(StringPool.BLANK)) {
1769 query.append(_FINDER_COLUMN_UUID_C_UUID_3_SQL);
1770 }
1771 else {
1772 bindUuid = true;
1773
1774 query.append(_FINDER_COLUMN_UUID_C_UUID_2_SQL);
1775 }
1776
1777 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1778
1779 if (!getDB().isSupportsInlineDistinct()) {
1780 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2);
1781 }
1782
1783 if (orderByComparator != null) {
1784 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1785
1786 if (orderByConditionFields.length > 0) {
1787 query.append(WHERE_AND);
1788 }
1789
1790 for (int i = 0; i < orderByConditionFields.length; i++) {
1791 if (getDB().isSupportsInlineDistinct()) {
1792 query.append(_ORDER_BY_ENTITY_ALIAS);
1793 }
1794 else {
1795 query.append(_ORDER_BY_ENTITY_TABLE);
1796 }
1797
1798 query.append(orderByConditionFields[i]);
1799
1800 if ((i + 1) < orderByConditionFields.length) {
1801 if (orderByComparator.isAscending() ^ previous) {
1802 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1803 }
1804 else {
1805 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1806 }
1807 }
1808 else {
1809 if (orderByComparator.isAscending() ^ previous) {
1810 query.append(WHERE_GREATER_THAN);
1811 }
1812 else {
1813 query.append(WHERE_LESSER_THAN);
1814 }
1815 }
1816 }
1817
1818 query.append(ORDER_BY_CLAUSE);
1819
1820 String[] orderByFields = orderByComparator.getOrderByFields();
1821
1822 for (int i = 0; i < orderByFields.length; i++) {
1823 if (getDB().isSupportsInlineDistinct()) {
1824 query.append(_ORDER_BY_ENTITY_ALIAS);
1825 }
1826 else {
1827 query.append(_ORDER_BY_ENTITY_TABLE);
1828 }
1829
1830 query.append(orderByFields[i]);
1831
1832 if ((i + 1) < orderByFields.length) {
1833 if (orderByComparator.isAscending() ^ previous) {
1834 query.append(ORDER_BY_ASC_HAS_NEXT);
1835 }
1836 else {
1837 query.append(ORDER_BY_DESC_HAS_NEXT);
1838 }
1839 }
1840 else {
1841 if (orderByComparator.isAscending() ^ previous) {
1842 query.append(ORDER_BY_ASC);
1843 }
1844 else {
1845 query.append(ORDER_BY_DESC);
1846 }
1847 }
1848 }
1849 }
1850 else {
1851 if (getDB().isSupportsInlineDistinct()) {
1852 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
1853 }
1854 else {
1855 query.append(OrganizationModelImpl.ORDER_BY_SQL);
1856 }
1857 }
1858
1859 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1860 Organization.class.getName(),
1861 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1862
1863 SQLQuery q = session.createSynchronizedSQLQuery(sql);
1864
1865 q.setFirstResult(0);
1866 q.setMaxResults(2);
1867
1868 if (getDB().isSupportsInlineDistinct()) {
1869 q.addEntity(_FILTER_ENTITY_ALIAS, OrganizationImpl.class);
1870 }
1871 else {
1872 q.addEntity(_FILTER_ENTITY_TABLE, OrganizationImpl.class);
1873 }
1874
1875 QueryPos qPos = QueryPos.getInstance(q);
1876
1877 if (bindUuid) {
1878 qPos.add(uuid);
1879 }
1880
1881 qPos.add(companyId);
1882
1883 if (orderByComparator != null) {
1884 Object[] values = orderByComparator.getOrderByConditionValues(organization);
1885
1886 for (Object value : values) {
1887 qPos.add(value);
1888 }
1889 }
1890
1891 List<Organization> list = q.list();
1892
1893 if (list.size() == 2) {
1894 return list.get(1);
1895 }
1896 else {
1897 return null;
1898 }
1899 }
1900
1901
1907 @Override
1908 public void removeByUuid_C(String uuid, long companyId) {
1909 for (Organization organization : findByUuid_C(uuid, companyId,
1910 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1911 remove(organization);
1912 }
1913 }
1914
1915
1922 @Override
1923 public int countByUuid_C(String uuid, long companyId) {
1924 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1925
1926 Object[] finderArgs = new Object[] { uuid, companyId };
1927
1928 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1929
1930 if (count == null) {
1931 StringBundler query = new StringBundler(3);
1932
1933 query.append(_SQL_COUNT_ORGANIZATION_WHERE);
1934
1935 boolean bindUuid = false;
1936
1937 if (uuid == null) {
1938 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1939 }
1940 else if (uuid.equals(StringPool.BLANK)) {
1941 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1942 }
1943 else {
1944 bindUuid = true;
1945
1946 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1947 }
1948
1949 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1950
1951 String sql = query.toString();
1952
1953 Session session = null;
1954
1955 try {
1956 session = openSession();
1957
1958 Query q = session.createQuery(sql);
1959
1960 QueryPos qPos = QueryPos.getInstance(q);
1961
1962 if (bindUuid) {
1963 qPos.add(uuid);
1964 }
1965
1966 qPos.add(companyId);
1967
1968 count = (Long)q.uniqueResult();
1969
1970 finderCache.putResult(finderPath, finderArgs, count);
1971 }
1972 catch (Exception e) {
1973 finderCache.removeResult(finderPath, finderArgs);
1974
1975 throw processException(e);
1976 }
1977 finally {
1978 closeSession(session);
1979 }
1980 }
1981
1982 return count.intValue();
1983 }
1984
1985
1992 @Override
1993 public int filterCountByUuid_C(String uuid, long companyId) {
1994 if (!InlineSQLHelperUtil.isEnabled(companyId, 0)) {
1995 return countByUuid_C(uuid, companyId);
1996 }
1997
1998 StringBundler query = new StringBundler(3);
1999
2000 query.append(_FILTER_SQL_COUNT_ORGANIZATION_WHERE);
2001
2002 boolean bindUuid = false;
2003
2004 if (uuid == null) {
2005 query.append(_FINDER_COLUMN_UUID_C_UUID_1_SQL);
2006 }
2007 else if (uuid.equals(StringPool.BLANK)) {
2008 query.append(_FINDER_COLUMN_UUID_C_UUID_3_SQL);
2009 }
2010 else {
2011 bindUuid = true;
2012
2013 query.append(_FINDER_COLUMN_UUID_C_UUID_2_SQL);
2014 }
2015
2016 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
2017
2018 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2019 Organization.class.getName(),
2020 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2021
2022 Session session = null;
2023
2024 try {
2025 session = openSession();
2026
2027 SQLQuery q = session.createSynchronizedSQLQuery(sql);
2028
2029 q.addScalar(COUNT_COLUMN_NAME,
2030 com.liferay.portal.kernel.dao.orm.Type.LONG);
2031
2032 QueryPos qPos = QueryPos.getInstance(q);
2033
2034 if (bindUuid) {
2035 qPos.add(uuid);
2036 }
2037
2038 qPos.add(companyId);
2039
2040 Long count = (Long)q.uniqueResult();
2041
2042 return count.intValue();
2043 }
2044 catch (Exception e) {
2045 throw processException(e);
2046 }
2047 finally {
2048 closeSession(session);
2049 }
2050 }
2051
2052 private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "organization.uuid IS NULL AND ";
2053 private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "organization.uuid = ? AND ";
2054 private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(organization.uuid IS NULL OR organization.uuid = '') AND ";
2055 private static final String _FINDER_COLUMN_UUID_C_UUID_1_SQL = "organization.uuid_ IS NULL AND ";
2056 private static final String _FINDER_COLUMN_UUID_C_UUID_2_SQL = "organization.uuid_ = ? AND ";
2057 private static final String _FINDER_COLUMN_UUID_C_UUID_3_SQL = "(organization.uuid_ IS NULL OR organization.uuid_ = '') AND ";
2058 private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "organization.companyId = ?";
2059 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
2060 new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
2061 OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
2062 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
2063 new String[] {
2064 Long.class.getName(),
2065
2066 Integer.class.getName(), Integer.class.getName(),
2067 OrderByComparator.class.getName()
2068 });
2069 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
2070 new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
2071 OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
2072 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
2073 new String[] { Long.class.getName() },
2074 OrganizationModelImpl.COMPANYID_COLUMN_BITMASK |
2075 OrganizationModelImpl.NAME_COLUMN_BITMASK);
2076 public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
2077 OrganizationModelImpl.FINDER_CACHE_ENABLED, Long.class,
2078 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
2079 new String[] { Long.class.getName() });
2080
2081
2087 @Override
2088 public List<Organization> findByCompanyId(long companyId) {
2089 return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2090 null);
2091 }
2092
2093
2105 @Override
2106 public List<Organization> findByCompanyId(long companyId, int start, int end) {
2107 return findByCompanyId(companyId, start, end, null);
2108 }
2109
2110
2123 @Override
2124 public List<Organization> findByCompanyId(long companyId, int start,
2125 int end, OrderByComparator<Organization> orderByComparator) {
2126 return findByCompanyId(companyId, start, end, orderByComparator, true);
2127 }
2128
2129
2143 @Override
2144 public List<Organization> findByCompanyId(long companyId, int start,
2145 int end, OrderByComparator<Organization> orderByComparator,
2146 boolean retrieveFromCache) {
2147 boolean pagination = true;
2148 FinderPath finderPath = null;
2149 Object[] finderArgs = null;
2150
2151 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2152 (orderByComparator == null)) {
2153 pagination = false;
2154 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
2155 finderArgs = new Object[] { companyId };
2156 }
2157 else {
2158 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
2159 finderArgs = new Object[] { companyId, start, end, orderByComparator };
2160 }
2161
2162 List<Organization> list = null;
2163
2164 if (retrieveFromCache) {
2165 list = (List<Organization>)finderCache.getResult(finderPath,
2166 finderArgs, this);
2167
2168 if ((list != null) && !list.isEmpty()) {
2169 for (Organization organization : list) {
2170 if ((companyId != organization.getCompanyId())) {
2171 list = null;
2172
2173 break;
2174 }
2175 }
2176 }
2177 }
2178
2179 if (list == null) {
2180 StringBundler query = null;
2181
2182 if (orderByComparator != null) {
2183 query = new StringBundler(3 +
2184 (orderByComparator.getOrderByFields().length * 2));
2185 }
2186 else {
2187 query = new StringBundler(3);
2188 }
2189
2190 query.append(_SQL_SELECT_ORGANIZATION_WHERE);
2191
2192 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2193
2194 if (orderByComparator != null) {
2195 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2196 orderByComparator);
2197 }
2198 else
2199 if (pagination) {
2200 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
2201 }
2202
2203 String sql = query.toString();
2204
2205 Session session = null;
2206
2207 try {
2208 session = openSession();
2209
2210 Query q = session.createQuery(sql);
2211
2212 QueryPos qPos = QueryPos.getInstance(q);
2213
2214 qPos.add(companyId);
2215
2216 if (!pagination) {
2217 list = (List<Organization>)QueryUtil.list(q, getDialect(),
2218 start, end, false);
2219
2220 Collections.sort(list);
2221
2222 list = Collections.unmodifiableList(list);
2223 }
2224 else {
2225 list = (List<Organization>)QueryUtil.list(q, getDialect(),
2226 start, end);
2227 }
2228
2229 cacheResult(list);
2230
2231 finderCache.putResult(finderPath, finderArgs, list);
2232 }
2233 catch (Exception e) {
2234 finderCache.removeResult(finderPath, finderArgs);
2235
2236 throw processException(e);
2237 }
2238 finally {
2239 closeSession(session);
2240 }
2241 }
2242
2243 return list;
2244 }
2245
2246
2254 @Override
2255 public Organization findByCompanyId_First(long companyId,
2256 OrderByComparator<Organization> orderByComparator)
2257 throws NoSuchOrganizationException {
2258 Organization organization = fetchByCompanyId_First(companyId,
2259 orderByComparator);
2260
2261 if (organization != null) {
2262 return organization;
2263 }
2264
2265 StringBundler msg = new StringBundler(4);
2266
2267 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2268
2269 msg.append("companyId=");
2270 msg.append(companyId);
2271
2272 msg.append(StringPool.CLOSE_CURLY_BRACE);
2273
2274 throw new NoSuchOrganizationException(msg.toString());
2275 }
2276
2277
2284 @Override
2285 public Organization fetchByCompanyId_First(long companyId,
2286 OrderByComparator<Organization> orderByComparator) {
2287 List<Organization> list = findByCompanyId(companyId, 0, 1,
2288 orderByComparator);
2289
2290 if (!list.isEmpty()) {
2291 return list.get(0);
2292 }
2293
2294 return null;
2295 }
2296
2297
2305 @Override
2306 public Organization findByCompanyId_Last(long companyId,
2307 OrderByComparator<Organization> orderByComparator)
2308 throws NoSuchOrganizationException {
2309 Organization organization = fetchByCompanyId_Last(companyId,
2310 orderByComparator);
2311
2312 if (organization != null) {
2313 return organization;
2314 }
2315
2316 StringBundler msg = new StringBundler(4);
2317
2318 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2319
2320 msg.append("companyId=");
2321 msg.append(companyId);
2322
2323 msg.append(StringPool.CLOSE_CURLY_BRACE);
2324
2325 throw new NoSuchOrganizationException(msg.toString());
2326 }
2327
2328
2335 @Override
2336 public Organization fetchByCompanyId_Last(long companyId,
2337 OrderByComparator<Organization> orderByComparator) {
2338 int count = countByCompanyId(companyId);
2339
2340 if (count == 0) {
2341 return null;
2342 }
2343
2344 List<Organization> list = findByCompanyId(companyId, count - 1, count,
2345 orderByComparator);
2346
2347 if (!list.isEmpty()) {
2348 return list.get(0);
2349 }
2350
2351 return null;
2352 }
2353
2354
2363 @Override
2364 public Organization[] findByCompanyId_PrevAndNext(long organizationId,
2365 long companyId, OrderByComparator<Organization> orderByComparator)
2366 throws NoSuchOrganizationException {
2367 Organization organization = findByPrimaryKey(organizationId);
2368
2369 Session session = null;
2370
2371 try {
2372 session = openSession();
2373
2374 Organization[] array = new OrganizationImpl[3];
2375
2376 array[0] = getByCompanyId_PrevAndNext(session, organization,
2377 companyId, orderByComparator, true);
2378
2379 array[1] = organization;
2380
2381 array[2] = getByCompanyId_PrevAndNext(session, organization,
2382 companyId, orderByComparator, false);
2383
2384 return array;
2385 }
2386 catch (Exception e) {
2387 throw processException(e);
2388 }
2389 finally {
2390 closeSession(session);
2391 }
2392 }
2393
2394 protected Organization getByCompanyId_PrevAndNext(Session session,
2395 Organization organization, long companyId,
2396 OrderByComparator<Organization> orderByComparator, boolean previous) {
2397 StringBundler query = null;
2398
2399 if (orderByComparator != null) {
2400 query = new StringBundler(4 +
2401 (orderByComparator.getOrderByConditionFields().length * 3) +
2402 (orderByComparator.getOrderByFields().length * 3));
2403 }
2404 else {
2405 query = new StringBundler(3);
2406 }
2407
2408 query.append(_SQL_SELECT_ORGANIZATION_WHERE);
2409
2410 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2411
2412 if (orderByComparator != null) {
2413 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2414
2415 if (orderByConditionFields.length > 0) {
2416 query.append(WHERE_AND);
2417 }
2418
2419 for (int i = 0; i < orderByConditionFields.length; i++) {
2420 query.append(_ORDER_BY_ENTITY_ALIAS);
2421 query.append(orderByConditionFields[i]);
2422
2423 if ((i + 1) < orderByConditionFields.length) {
2424 if (orderByComparator.isAscending() ^ previous) {
2425 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2426 }
2427 else {
2428 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2429 }
2430 }
2431 else {
2432 if (orderByComparator.isAscending() ^ previous) {
2433 query.append(WHERE_GREATER_THAN);
2434 }
2435 else {
2436 query.append(WHERE_LESSER_THAN);
2437 }
2438 }
2439 }
2440
2441 query.append(ORDER_BY_CLAUSE);
2442
2443 String[] orderByFields = orderByComparator.getOrderByFields();
2444
2445 for (int i = 0; i < orderByFields.length; i++) {
2446 query.append(_ORDER_BY_ENTITY_ALIAS);
2447 query.append(orderByFields[i]);
2448
2449 if ((i + 1) < orderByFields.length) {
2450 if (orderByComparator.isAscending() ^ previous) {
2451 query.append(ORDER_BY_ASC_HAS_NEXT);
2452 }
2453 else {
2454 query.append(ORDER_BY_DESC_HAS_NEXT);
2455 }
2456 }
2457 else {
2458 if (orderByComparator.isAscending() ^ previous) {
2459 query.append(ORDER_BY_ASC);
2460 }
2461 else {
2462 query.append(ORDER_BY_DESC);
2463 }
2464 }
2465 }
2466 }
2467 else {
2468 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
2469 }
2470
2471 String sql = query.toString();
2472
2473 Query q = session.createQuery(sql);
2474
2475 q.setFirstResult(0);
2476 q.setMaxResults(2);
2477
2478 QueryPos qPos = QueryPos.getInstance(q);
2479
2480 qPos.add(companyId);
2481
2482 if (orderByComparator != null) {
2483 Object[] values = orderByComparator.getOrderByConditionValues(organization);
2484
2485 for (Object value : values) {
2486 qPos.add(value);
2487 }
2488 }
2489
2490 List<Organization> list = q.list();
2491
2492 if (list.size() == 2) {
2493 return list.get(1);
2494 }
2495 else {
2496 return null;
2497 }
2498 }
2499
2500
2506 @Override
2507 public List<Organization> filterFindByCompanyId(long companyId) {
2508 return filterFindByCompanyId(companyId, QueryUtil.ALL_POS,
2509 QueryUtil.ALL_POS, null);
2510 }
2511
2512
2524 @Override
2525 public List<Organization> filterFindByCompanyId(long companyId, int start,
2526 int end) {
2527 return filterFindByCompanyId(companyId, start, end, null);
2528 }
2529
2530
2543 @Override
2544 public List<Organization> filterFindByCompanyId(long companyId, int start,
2545 int end, OrderByComparator<Organization> orderByComparator) {
2546 if (!InlineSQLHelperUtil.isEnabled(companyId, 0)) {
2547 return findByCompanyId(companyId, start, end, orderByComparator);
2548 }
2549
2550 StringBundler query = null;
2551
2552 if (orderByComparator != null) {
2553 query = new StringBundler(3 +
2554 (orderByComparator.getOrderByFields().length * 2));
2555 }
2556 else {
2557 query = new StringBundler(4);
2558 }
2559
2560 if (getDB().isSupportsInlineDistinct()) {
2561 query.append(_FILTER_SQL_SELECT_ORGANIZATION_WHERE);
2562 }
2563 else {
2564 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1);
2565 }
2566
2567 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2568
2569 if (!getDB().isSupportsInlineDistinct()) {
2570 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2);
2571 }
2572
2573 if (orderByComparator != null) {
2574 if (getDB().isSupportsInlineDistinct()) {
2575 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2576 orderByComparator, true);
2577 }
2578 else {
2579 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
2580 orderByComparator, true);
2581 }
2582 }
2583 else {
2584 if (getDB().isSupportsInlineDistinct()) {
2585 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
2586 }
2587 else {
2588 query.append(OrganizationModelImpl.ORDER_BY_SQL);
2589 }
2590 }
2591
2592 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2593 Organization.class.getName(),
2594 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2595
2596 Session session = null;
2597
2598 try {
2599 session = openSession();
2600
2601 SQLQuery q = session.createSynchronizedSQLQuery(sql);
2602
2603 if (getDB().isSupportsInlineDistinct()) {
2604 q.addEntity(_FILTER_ENTITY_ALIAS, OrganizationImpl.class);
2605 }
2606 else {
2607 q.addEntity(_FILTER_ENTITY_TABLE, OrganizationImpl.class);
2608 }
2609
2610 QueryPos qPos = QueryPos.getInstance(q);
2611
2612 qPos.add(companyId);
2613
2614 return (List<Organization>)QueryUtil.list(q, getDialect(), start,
2615 end);
2616 }
2617 catch (Exception e) {
2618 throw processException(e);
2619 }
2620 finally {
2621 closeSession(session);
2622 }
2623 }
2624
2625
2634 @Override
2635 public Organization[] filterFindByCompanyId_PrevAndNext(
2636 long organizationId, long companyId,
2637 OrderByComparator<Organization> orderByComparator)
2638 throws NoSuchOrganizationException {
2639 if (!InlineSQLHelperUtil.isEnabled(companyId, 0)) {
2640 return findByCompanyId_PrevAndNext(organizationId, companyId,
2641 orderByComparator);
2642 }
2643
2644 Organization organization = findByPrimaryKey(organizationId);
2645
2646 Session session = null;
2647
2648 try {
2649 session = openSession();
2650
2651 Organization[] array = new OrganizationImpl[3];
2652
2653 array[0] = filterGetByCompanyId_PrevAndNext(session, organization,
2654 companyId, orderByComparator, true);
2655
2656 array[1] = organization;
2657
2658 array[2] = filterGetByCompanyId_PrevAndNext(session, organization,
2659 companyId, orderByComparator, false);
2660
2661 return array;
2662 }
2663 catch (Exception e) {
2664 throw processException(e);
2665 }
2666 finally {
2667 closeSession(session);
2668 }
2669 }
2670
2671 protected Organization filterGetByCompanyId_PrevAndNext(Session session,
2672 Organization organization, long companyId,
2673 OrderByComparator<Organization> orderByComparator, boolean previous) {
2674 StringBundler query = null;
2675
2676 if (orderByComparator != null) {
2677 query = new StringBundler(5 +
2678 (orderByComparator.getOrderByConditionFields().length * 3) +
2679 (orderByComparator.getOrderByFields().length * 3));
2680 }
2681 else {
2682 query = new StringBundler(4);
2683 }
2684
2685 if (getDB().isSupportsInlineDistinct()) {
2686 query.append(_FILTER_SQL_SELECT_ORGANIZATION_WHERE);
2687 }
2688 else {
2689 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1);
2690 }
2691
2692 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2693
2694 if (!getDB().isSupportsInlineDistinct()) {
2695 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2);
2696 }
2697
2698 if (orderByComparator != null) {
2699 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2700
2701 if (orderByConditionFields.length > 0) {
2702 query.append(WHERE_AND);
2703 }
2704
2705 for (int i = 0; i < orderByConditionFields.length; i++) {
2706 if (getDB().isSupportsInlineDistinct()) {
2707 query.append(_ORDER_BY_ENTITY_ALIAS);
2708 }
2709 else {
2710 query.append(_ORDER_BY_ENTITY_TABLE);
2711 }
2712
2713 query.append(orderByConditionFields[i]);
2714
2715 if ((i + 1) < orderByConditionFields.length) {
2716 if (orderByComparator.isAscending() ^ previous) {
2717 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2718 }
2719 else {
2720 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2721 }
2722 }
2723 else {
2724 if (orderByComparator.isAscending() ^ previous) {
2725 query.append(WHERE_GREATER_THAN);
2726 }
2727 else {
2728 query.append(WHERE_LESSER_THAN);
2729 }
2730 }
2731 }
2732
2733 query.append(ORDER_BY_CLAUSE);
2734
2735 String[] orderByFields = orderByComparator.getOrderByFields();
2736
2737 for (int i = 0; i < orderByFields.length; i++) {
2738 if (getDB().isSupportsInlineDistinct()) {
2739 query.append(_ORDER_BY_ENTITY_ALIAS);
2740 }
2741 else {
2742 query.append(_ORDER_BY_ENTITY_TABLE);
2743 }
2744
2745 query.append(orderByFields[i]);
2746
2747 if ((i + 1) < orderByFields.length) {
2748 if (orderByComparator.isAscending() ^ previous) {
2749 query.append(ORDER_BY_ASC_HAS_NEXT);
2750 }
2751 else {
2752 query.append(ORDER_BY_DESC_HAS_NEXT);
2753 }
2754 }
2755 else {
2756 if (orderByComparator.isAscending() ^ previous) {
2757 query.append(ORDER_BY_ASC);
2758 }
2759 else {
2760 query.append(ORDER_BY_DESC);
2761 }
2762 }
2763 }
2764 }
2765 else {
2766 if (getDB().isSupportsInlineDistinct()) {
2767 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
2768 }
2769 else {
2770 query.append(OrganizationModelImpl.ORDER_BY_SQL);
2771 }
2772 }
2773
2774 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2775 Organization.class.getName(),
2776 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2777
2778 SQLQuery q = session.createSynchronizedSQLQuery(sql);
2779
2780 q.setFirstResult(0);
2781 q.setMaxResults(2);
2782
2783 if (getDB().isSupportsInlineDistinct()) {
2784 q.addEntity(_FILTER_ENTITY_ALIAS, OrganizationImpl.class);
2785 }
2786 else {
2787 q.addEntity(_FILTER_ENTITY_TABLE, OrganizationImpl.class);
2788 }
2789
2790 QueryPos qPos = QueryPos.getInstance(q);
2791
2792 qPos.add(companyId);
2793
2794 if (orderByComparator != null) {
2795 Object[] values = orderByComparator.getOrderByConditionValues(organization);
2796
2797 for (Object value : values) {
2798 qPos.add(value);
2799 }
2800 }
2801
2802 List<Organization> list = q.list();
2803
2804 if (list.size() == 2) {
2805 return list.get(1);
2806 }
2807 else {
2808 return null;
2809 }
2810 }
2811
2812
2817 @Override
2818 public void removeByCompanyId(long companyId) {
2819 for (Organization organization : findByCompanyId(companyId,
2820 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2821 remove(organization);
2822 }
2823 }
2824
2825
2831 @Override
2832 public int countByCompanyId(long companyId) {
2833 FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
2834
2835 Object[] finderArgs = new Object[] { companyId };
2836
2837 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
2838
2839 if (count == null) {
2840 StringBundler query = new StringBundler(2);
2841
2842 query.append(_SQL_COUNT_ORGANIZATION_WHERE);
2843
2844 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2845
2846 String sql = query.toString();
2847
2848 Session session = null;
2849
2850 try {
2851 session = openSession();
2852
2853 Query q = session.createQuery(sql);
2854
2855 QueryPos qPos = QueryPos.getInstance(q);
2856
2857 qPos.add(companyId);
2858
2859 count = (Long)q.uniqueResult();
2860
2861 finderCache.putResult(finderPath, finderArgs, count);
2862 }
2863 catch (Exception e) {
2864 finderCache.removeResult(finderPath, finderArgs);
2865
2866 throw processException(e);
2867 }
2868 finally {
2869 closeSession(session);
2870 }
2871 }
2872
2873 return count.intValue();
2874 }
2875
2876
2882 @Override
2883 public int filterCountByCompanyId(long companyId) {
2884 if (!InlineSQLHelperUtil.isEnabled(companyId, 0)) {
2885 return countByCompanyId(companyId);
2886 }
2887
2888 StringBundler query = new StringBundler(2);
2889
2890 query.append(_FILTER_SQL_COUNT_ORGANIZATION_WHERE);
2891
2892 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2893
2894 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2895 Organization.class.getName(),
2896 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2897
2898 Session session = null;
2899
2900 try {
2901 session = openSession();
2902
2903 SQLQuery q = session.createSynchronizedSQLQuery(sql);
2904
2905 q.addScalar(COUNT_COLUMN_NAME,
2906 com.liferay.portal.kernel.dao.orm.Type.LONG);
2907
2908 QueryPos qPos = QueryPos.getInstance(q);
2909
2910 qPos.add(companyId);
2911
2912 Long count = (Long)q.uniqueResult();
2913
2914 return count.intValue();
2915 }
2916 catch (Exception e) {
2917 throw processException(e);
2918 }
2919 finally {
2920 closeSession(session);
2921 }
2922 }
2923
2924 private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "organization.companyId = ?";
2925 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_LOCATIONS =
2926 new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
2927 OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
2928 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByLocations",
2929 new String[] {
2930 Long.class.getName(),
2931
2932 Integer.class.getName(), Integer.class.getName(),
2933 OrderByComparator.class.getName()
2934 });
2935 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LOCATIONS =
2936 new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
2937 OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
2938 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByLocations",
2939 new String[] { Long.class.getName() },
2940 OrganizationModelImpl.COMPANYID_COLUMN_BITMASK |
2941 OrganizationModelImpl.NAME_COLUMN_BITMASK);
2942 public static final FinderPath FINDER_PATH_COUNT_BY_LOCATIONS = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
2943 OrganizationModelImpl.FINDER_CACHE_ENABLED, Long.class,
2944 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByLocations",
2945 new String[] { Long.class.getName() });
2946
2947
2953 @Override
2954 public List<Organization> findByLocations(long companyId) {
2955 return findByLocations(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2956 null);
2957 }
2958
2959
2971 @Override
2972 public List<Organization> findByLocations(long companyId, int start, int end) {
2973 return findByLocations(companyId, start, end, null);
2974 }
2975
2976
2989 @Override
2990 public List<Organization> findByLocations(long companyId, int start,
2991 int end, OrderByComparator<Organization> orderByComparator) {
2992 return findByLocations(companyId, start, end, orderByComparator, true);
2993 }
2994
2995
3009 @Override
3010 public List<Organization> findByLocations(long companyId, int start,
3011 int end, OrderByComparator<Organization> orderByComparator,
3012 boolean retrieveFromCache) {
3013 boolean pagination = true;
3014 FinderPath finderPath = null;
3015 Object[] finderArgs = null;
3016
3017 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3018 (orderByComparator == null)) {
3019 pagination = false;
3020 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LOCATIONS;
3021 finderArgs = new Object[] { companyId };
3022 }
3023 else {
3024 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_LOCATIONS;
3025 finderArgs = new Object[] { companyId, start, end, orderByComparator };
3026 }
3027
3028 List<Organization> list = null;
3029
3030 if (retrieveFromCache) {
3031 list = (List<Organization>)finderCache.getResult(finderPath,
3032 finderArgs, this);
3033
3034 if ((list != null) && !list.isEmpty()) {
3035 for (Organization organization : list) {
3036 if ((companyId != organization.getCompanyId())) {
3037 list = null;
3038
3039 break;
3040 }
3041 }
3042 }
3043 }
3044
3045 if (list == null) {
3046 StringBundler query = null;
3047
3048 if (orderByComparator != null) {
3049 query = new StringBundler(3 +
3050 (orderByComparator.getOrderByFields().length * 2));
3051 }
3052 else {
3053 query = new StringBundler(3);
3054 }
3055
3056 query.append(_SQL_SELECT_ORGANIZATION_WHERE);
3057
3058 query.append(_FINDER_COLUMN_LOCATIONS_COMPANYID_2);
3059
3060 if (orderByComparator != null) {
3061 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3062 orderByComparator);
3063 }
3064 else
3065 if (pagination) {
3066 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
3067 }
3068
3069 String sql = query.toString();
3070
3071 Session session = null;
3072
3073 try {
3074 session = openSession();
3075
3076 Query q = session.createQuery(sql);
3077
3078 QueryPos qPos = QueryPos.getInstance(q);
3079
3080 qPos.add(companyId);
3081
3082 if (!pagination) {
3083 list = (List<Organization>)QueryUtil.list(q, getDialect(),
3084 start, end, false);
3085
3086 Collections.sort(list);
3087
3088 list = Collections.unmodifiableList(list);
3089 }
3090 else {
3091 list = (List<Organization>)QueryUtil.list(q, getDialect(),
3092 start, end);
3093 }
3094
3095 cacheResult(list);
3096
3097 finderCache.putResult(finderPath, finderArgs, list);
3098 }
3099 catch (Exception e) {
3100 finderCache.removeResult(finderPath, finderArgs);
3101
3102 throw processException(e);
3103 }
3104 finally {
3105 closeSession(session);
3106 }
3107 }
3108
3109 return list;
3110 }
3111
3112
3120 @Override
3121 public Organization findByLocations_First(long companyId,
3122 OrderByComparator<Organization> orderByComparator)
3123 throws NoSuchOrganizationException {
3124 Organization organization = fetchByLocations_First(companyId,
3125 orderByComparator);
3126
3127 if (organization != null) {
3128 return organization;
3129 }
3130
3131 StringBundler msg = new StringBundler(4);
3132
3133 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3134
3135 msg.append("companyId=");
3136 msg.append(companyId);
3137
3138 msg.append(StringPool.CLOSE_CURLY_BRACE);
3139
3140 throw new NoSuchOrganizationException(msg.toString());
3141 }
3142
3143
3150 @Override
3151 public Organization fetchByLocations_First(long companyId,
3152 OrderByComparator<Organization> orderByComparator) {
3153 List<Organization> list = findByLocations(companyId, 0, 1,
3154 orderByComparator);
3155
3156 if (!list.isEmpty()) {
3157 return list.get(0);
3158 }
3159
3160 return null;
3161 }
3162
3163
3171 @Override
3172 public Organization findByLocations_Last(long companyId,
3173 OrderByComparator<Organization> orderByComparator)
3174 throws NoSuchOrganizationException {
3175 Organization organization = fetchByLocations_Last(companyId,
3176 orderByComparator);
3177
3178 if (organization != null) {
3179 return organization;
3180 }
3181
3182 StringBundler msg = new StringBundler(4);
3183
3184 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3185
3186 msg.append("companyId=");
3187 msg.append(companyId);
3188
3189 msg.append(StringPool.CLOSE_CURLY_BRACE);
3190
3191 throw new NoSuchOrganizationException(msg.toString());
3192 }
3193
3194
3201 @Override
3202 public Organization fetchByLocations_Last(long companyId,
3203 OrderByComparator<Organization> orderByComparator) {
3204 int count = countByLocations(companyId);
3205
3206 if (count == 0) {
3207 return null;
3208 }
3209
3210 List<Organization> list = findByLocations(companyId, count - 1, count,
3211 orderByComparator);
3212
3213 if (!list.isEmpty()) {
3214 return list.get(0);
3215 }
3216
3217 return null;
3218 }
3219
3220
3229 @Override
3230 public Organization[] findByLocations_PrevAndNext(long organizationId,
3231 long companyId, OrderByComparator<Organization> orderByComparator)
3232 throws NoSuchOrganizationException {
3233 Organization organization = findByPrimaryKey(organizationId);
3234
3235 Session session = null;
3236
3237 try {
3238 session = openSession();
3239
3240 Organization[] array = new OrganizationImpl[3];
3241
3242 array[0] = getByLocations_PrevAndNext(session, organization,
3243 companyId, orderByComparator, true);
3244
3245 array[1] = organization;
3246
3247 array[2] = getByLocations_PrevAndNext(session, organization,
3248 companyId, orderByComparator, false);
3249
3250 return array;
3251 }
3252 catch (Exception e) {
3253 throw processException(e);
3254 }
3255 finally {
3256 closeSession(session);
3257 }
3258 }
3259
3260 protected Organization getByLocations_PrevAndNext(Session session,
3261 Organization organization, long companyId,
3262 OrderByComparator<Organization> orderByComparator, boolean previous) {
3263 StringBundler query = null;
3264
3265 if (orderByComparator != null) {
3266 query = new StringBundler(4 +
3267 (orderByComparator.getOrderByConditionFields().length * 3) +
3268 (orderByComparator.getOrderByFields().length * 3));
3269 }
3270 else {
3271 query = new StringBundler(3);
3272 }
3273
3274 query.append(_SQL_SELECT_ORGANIZATION_WHERE);
3275
3276 query.append(_FINDER_COLUMN_LOCATIONS_COMPANYID_2);
3277
3278 if (orderByComparator != null) {
3279 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3280
3281 if (orderByConditionFields.length > 0) {
3282 query.append(WHERE_AND);
3283 }
3284
3285 for (int i = 0; i < orderByConditionFields.length; i++) {
3286 query.append(_ORDER_BY_ENTITY_ALIAS);
3287 query.append(orderByConditionFields[i]);
3288
3289 if ((i + 1) < orderByConditionFields.length) {
3290 if (orderByComparator.isAscending() ^ previous) {
3291 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3292 }
3293 else {
3294 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3295 }
3296 }
3297 else {
3298 if (orderByComparator.isAscending() ^ previous) {
3299 query.append(WHERE_GREATER_THAN);
3300 }
3301 else {
3302 query.append(WHERE_LESSER_THAN);
3303 }
3304 }
3305 }
3306
3307 query.append(ORDER_BY_CLAUSE);
3308
3309 String[] orderByFields = orderByComparator.getOrderByFields();
3310
3311 for (int i = 0; i < orderByFields.length; i++) {
3312 query.append(_ORDER_BY_ENTITY_ALIAS);
3313 query.append(orderByFields[i]);
3314
3315 if ((i + 1) < orderByFields.length) {
3316 if (orderByComparator.isAscending() ^ previous) {
3317 query.append(ORDER_BY_ASC_HAS_NEXT);
3318 }
3319 else {
3320 query.append(ORDER_BY_DESC_HAS_NEXT);
3321 }
3322 }
3323 else {
3324 if (orderByComparator.isAscending() ^ previous) {
3325 query.append(ORDER_BY_ASC);
3326 }
3327 else {
3328 query.append(ORDER_BY_DESC);
3329 }
3330 }
3331 }
3332 }
3333 else {
3334 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
3335 }
3336
3337 String sql = query.toString();
3338
3339 Query q = session.createQuery(sql);
3340
3341 q.setFirstResult(0);
3342 q.setMaxResults(2);
3343
3344 QueryPos qPos = QueryPos.getInstance(q);
3345
3346 qPos.add(companyId);
3347
3348 if (orderByComparator != null) {
3349 Object[] values = orderByComparator.getOrderByConditionValues(organization);
3350
3351 for (Object value : values) {
3352 qPos.add(value);
3353 }
3354 }
3355
3356 List<Organization> list = q.list();
3357
3358 if (list.size() == 2) {
3359 return list.get(1);
3360 }
3361 else {
3362 return null;
3363 }
3364 }
3365
3366
3372 @Override
3373 public List<Organization> filterFindByLocations(long companyId) {
3374 return filterFindByLocations(companyId, QueryUtil.ALL_POS,
3375 QueryUtil.ALL_POS, null);
3376 }
3377
3378
3390 @Override
3391 public List<Organization> filterFindByLocations(long companyId, int start,
3392 int end) {
3393 return filterFindByLocations(companyId, start, end, null);
3394 }
3395
3396
3409 @Override
3410 public List<Organization> filterFindByLocations(long companyId, int start,
3411 int end, OrderByComparator<Organization> orderByComparator) {
3412 if (!InlineSQLHelperUtil.isEnabled(companyId, 0)) {
3413 return findByLocations(companyId, start, end, orderByComparator);
3414 }
3415
3416 StringBundler query = null;
3417
3418 if (orderByComparator != null) {
3419 query = new StringBundler(3 +
3420 (orderByComparator.getOrderByFields().length * 2));
3421 }
3422 else {
3423 query = new StringBundler(4);
3424 }
3425
3426 if (getDB().isSupportsInlineDistinct()) {
3427 query.append(_FILTER_SQL_SELECT_ORGANIZATION_WHERE);
3428 }
3429 else {
3430 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1);
3431 }
3432
3433 query.append(_FINDER_COLUMN_LOCATIONS_COMPANYID_2);
3434
3435 if (!getDB().isSupportsInlineDistinct()) {
3436 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2);
3437 }
3438
3439 if (orderByComparator != null) {
3440 if (getDB().isSupportsInlineDistinct()) {
3441 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3442 orderByComparator, true);
3443 }
3444 else {
3445 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
3446 orderByComparator, true);
3447 }
3448 }
3449 else {
3450 if (getDB().isSupportsInlineDistinct()) {
3451 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
3452 }
3453 else {
3454 query.append(OrganizationModelImpl.ORDER_BY_SQL);
3455 }
3456 }
3457
3458 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3459 Organization.class.getName(),
3460 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
3461
3462 Session session = null;
3463
3464 try {
3465 session = openSession();
3466
3467 SQLQuery q = session.createSynchronizedSQLQuery(sql);
3468
3469 if (getDB().isSupportsInlineDistinct()) {
3470 q.addEntity(_FILTER_ENTITY_ALIAS, OrganizationImpl.class);
3471 }
3472 else {
3473 q.addEntity(_FILTER_ENTITY_TABLE, OrganizationImpl.class);
3474 }
3475
3476 QueryPos qPos = QueryPos.getInstance(q);
3477
3478 qPos.add(companyId);
3479
3480 return (List<Organization>)QueryUtil.list(q, getDialect(), start,
3481 end);
3482 }
3483 catch (Exception e) {
3484 throw processException(e);
3485 }
3486 finally {
3487 closeSession(session);
3488 }
3489 }
3490
3491
3500 @Override
3501 public Organization[] filterFindByLocations_PrevAndNext(
3502 long organizationId, long companyId,
3503 OrderByComparator<Organization> orderByComparator)
3504 throws NoSuchOrganizationException {
3505 if (!InlineSQLHelperUtil.isEnabled(companyId, 0)) {
3506 return findByLocations_PrevAndNext(organizationId, companyId,
3507 orderByComparator);
3508 }
3509
3510 Organization organization = findByPrimaryKey(organizationId);
3511
3512 Session session = null;
3513
3514 try {
3515 session = openSession();
3516
3517 Organization[] array = new OrganizationImpl[3];
3518
3519 array[0] = filterGetByLocations_PrevAndNext(session, organization,
3520 companyId, orderByComparator, true);
3521
3522 array[1] = organization;
3523
3524 array[2] = filterGetByLocations_PrevAndNext(session, organization,
3525 companyId, orderByComparator, false);
3526
3527 return array;
3528 }
3529 catch (Exception e) {
3530 throw processException(e);
3531 }
3532 finally {
3533 closeSession(session);
3534 }
3535 }
3536
3537 protected Organization filterGetByLocations_PrevAndNext(Session session,
3538 Organization organization, long companyId,
3539 OrderByComparator<Organization> orderByComparator, boolean previous) {
3540 StringBundler query = null;
3541
3542 if (orderByComparator != null) {
3543 query = new StringBundler(5 +
3544 (orderByComparator.getOrderByConditionFields().length * 3) +
3545 (orderByComparator.getOrderByFields().length * 3));
3546 }
3547 else {
3548 query = new StringBundler(4);
3549 }
3550
3551 if (getDB().isSupportsInlineDistinct()) {
3552 query.append(_FILTER_SQL_SELECT_ORGANIZATION_WHERE);
3553 }
3554 else {
3555 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1);
3556 }
3557
3558 query.append(_FINDER_COLUMN_LOCATIONS_COMPANYID_2);
3559
3560 if (!getDB().isSupportsInlineDistinct()) {
3561 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2);
3562 }
3563
3564 if (orderByComparator != null) {
3565 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3566
3567 if (orderByConditionFields.length > 0) {
3568 query.append(WHERE_AND);
3569 }
3570
3571 for (int i = 0; i < orderByConditionFields.length; i++) {
3572 if (getDB().isSupportsInlineDistinct()) {
3573 query.append(_ORDER_BY_ENTITY_ALIAS);
3574 }
3575 else {
3576 query.append(_ORDER_BY_ENTITY_TABLE);
3577 }
3578
3579 query.append(orderByConditionFields[i]);
3580
3581 if ((i + 1) < orderByConditionFields.length) {
3582 if (orderByComparator.isAscending() ^ previous) {
3583 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3584 }
3585 else {
3586 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3587 }
3588 }
3589 else {
3590 if (orderByComparator.isAscending() ^ previous) {
3591 query.append(WHERE_GREATER_THAN);
3592 }
3593 else {
3594 query.append(WHERE_LESSER_THAN);
3595 }
3596 }
3597 }
3598
3599 query.append(ORDER_BY_CLAUSE);
3600
3601 String[] orderByFields = orderByComparator.getOrderByFields();
3602
3603 for (int i = 0; i < orderByFields.length; i++) {
3604 if (getDB().isSupportsInlineDistinct()) {
3605 query.append(_ORDER_BY_ENTITY_ALIAS);
3606 }
3607 else {
3608 query.append(_ORDER_BY_ENTITY_TABLE);
3609 }
3610
3611 query.append(orderByFields[i]);
3612
3613 if ((i + 1) < orderByFields.length) {
3614 if (orderByComparator.isAscending() ^ previous) {
3615 query.append(ORDER_BY_ASC_HAS_NEXT);
3616 }
3617 else {
3618 query.append(ORDER_BY_DESC_HAS_NEXT);
3619 }
3620 }
3621 else {
3622 if (orderByComparator.isAscending() ^ previous) {
3623 query.append(ORDER_BY_ASC);
3624 }
3625 else {
3626 query.append(ORDER_BY_DESC);
3627 }
3628 }
3629 }
3630 }
3631 else {
3632 if (getDB().isSupportsInlineDistinct()) {
3633 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
3634 }
3635 else {
3636 query.append(OrganizationModelImpl.ORDER_BY_SQL);
3637 }
3638 }
3639
3640 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3641 Organization.class.getName(),
3642 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
3643
3644 SQLQuery q = session.createSynchronizedSQLQuery(sql);
3645
3646 q.setFirstResult(0);
3647 q.setMaxResults(2);
3648
3649 if (getDB().isSupportsInlineDistinct()) {
3650 q.addEntity(_FILTER_ENTITY_ALIAS, OrganizationImpl.class);
3651 }
3652 else {
3653 q.addEntity(_FILTER_ENTITY_TABLE, OrganizationImpl.class);
3654 }
3655
3656 QueryPos qPos = QueryPos.getInstance(q);
3657
3658 qPos.add(companyId);
3659
3660 if (orderByComparator != null) {
3661 Object[] values = orderByComparator.getOrderByConditionValues(organization);
3662
3663 for (Object value : values) {
3664 qPos.add(value);
3665 }
3666 }
3667
3668 List<Organization> list = q.list();
3669
3670 if (list.size() == 2) {
3671 return list.get(1);
3672 }
3673 else {
3674 return null;
3675 }
3676 }
3677
3678
3683 @Override
3684 public void removeByLocations(long companyId) {
3685 for (Organization organization : findByLocations(companyId,
3686 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3687 remove(organization);
3688 }
3689 }
3690
3691
3697 @Override
3698 public int countByLocations(long companyId) {
3699 FinderPath finderPath = FINDER_PATH_COUNT_BY_LOCATIONS;
3700
3701 Object[] finderArgs = new Object[] { companyId };
3702
3703 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
3704
3705 if (count == null) {
3706 StringBundler query = new StringBundler(2);
3707
3708 query.append(_SQL_COUNT_ORGANIZATION_WHERE);
3709
3710 query.append(_FINDER_COLUMN_LOCATIONS_COMPANYID_2);
3711
3712 String sql = query.toString();
3713
3714 Session session = null;
3715
3716 try {
3717 session = openSession();
3718
3719 Query q = session.createQuery(sql);
3720
3721 QueryPos qPos = QueryPos.getInstance(q);
3722
3723 qPos.add(companyId);
3724
3725 count = (Long)q.uniqueResult();
3726
3727 finderCache.putResult(finderPath, finderArgs, count);
3728 }
3729 catch (Exception e) {
3730 finderCache.removeResult(finderPath, finderArgs);
3731
3732 throw processException(e);
3733 }
3734 finally {
3735 closeSession(session);
3736 }
3737 }
3738
3739 return count.intValue();
3740 }
3741
3742
3748 @Override
3749 public int filterCountByLocations(long companyId) {
3750 if (!InlineSQLHelperUtil.isEnabled(companyId, 0)) {
3751 return countByLocations(companyId);
3752 }
3753
3754 StringBundler query = new StringBundler(2);
3755
3756 query.append(_FILTER_SQL_COUNT_ORGANIZATION_WHERE);
3757
3758 query.append(_FINDER_COLUMN_LOCATIONS_COMPANYID_2);
3759
3760 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3761 Organization.class.getName(),
3762 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
3763
3764 Session session = null;
3765
3766 try {
3767 session = openSession();
3768
3769 SQLQuery q = session.createSynchronizedSQLQuery(sql);
3770
3771 q.addScalar(COUNT_COLUMN_NAME,
3772 com.liferay.portal.kernel.dao.orm.Type.LONG);
3773
3774 QueryPos qPos = QueryPos.getInstance(q);
3775
3776 qPos.add(companyId);
3777
3778 Long count = (Long)q.uniqueResult();
3779
3780 return count.intValue();
3781 }
3782 catch (Exception e) {
3783 throw processException(e);
3784 }
3785 finally {
3786 closeSession(session);
3787 }
3788 }
3789
3790 private static final String _FINDER_COLUMN_LOCATIONS_COMPANYID_2 = "organization.companyId = ? AND organization.parentOrganizationId != 0";
3791 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_P = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
3792 OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
3793 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_P",
3794 new String[] {
3795 Long.class.getName(), Long.class.getName(),
3796
3797 Integer.class.getName(), Integer.class.getName(),
3798 OrderByComparator.class.getName()
3799 });
3800 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
3801 OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
3802 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_P",
3803 new String[] { Long.class.getName(), Long.class.getName() },
3804 OrganizationModelImpl.COMPANYID_COLUMN_BITMASK |
3805 OrganizationModelImpl.PARENTORGANIZATIONID_COLUMN_BITMASK |
3806 OrganizationModelImpl.NAME_COLUMN_BITMASK);
3807 public static final FinderPath FINDER_PATH_COUNT_BY_C_P = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
3808 OrganizationModelImpl.FINDER_CACHE_ENABLED, Long.class,
3809 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_P",
3810 new String[] { Long.class.getName(), Long.class.getName() });
3811
3812
3819 @Override
3820 public List<Organization> findByC_P(long companyId,
3821 long parentOrganizationId) {
3822 return findByC_P(companyId, parentOrganizationId, QueryUtil.ALL_POS,
3823 QueryUtil.ALL_POS, null);
3824 }
3825
3826
3839 @Override
3840 public List<Organization> findByC_P(long companyId,
3841 long parentOrganizationId, int start, int end) {
3842 return findByC_P(companyId, parentOrganizationId, start, end, null);
3843 }
3844
3845
3859 @Override
3860 public List<Organization> findByC_P(long companyId,
3861 long parentOrganizationId, int start, int end,
3862 OrderByComparator<Organization> orderByComparator) {
3863 return findByC_P(companyId, parentOrganizationId, start, end,
3864 orderByComparator, true);
3865 }
3866
3867
3882 @Override
3883 public List<Organization> findByC_P(long companyId,
3884 long parentOrganizationId, int start, int end,
3885 OrderByComparator<Organization> orderByComparator,
3886 boolean retrieveFromCache) {
3887 boolean pagination = true;
3888 FinderPath finderPath = null;
3889 Object[] finderArgs = null;
3890
3891 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3892 (orderByComparator == null)) {
3893 pagination = false;
3894 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P;
3895 finderArgs = new Object[] { companyId, parentOrganizationId };
3896 }
3897 else {
3898 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_P;
3899 finderArgs = new Object[] {
3900 companyId, parentOrganizationId,
3901
3902 start, end, orderByComparator
3903 };
3904 }
3905
3906 List<Organization> list = null;
3907
3908 if (retrieveFromCache) {
3909 list = (List<Organization>)finderCache.getResult(finderPath,
3910 finderArgs, this);
3911
3912 if ((list != null) && !list.isEmpty()) {
3913 for (Organization organization : list) {
3914 if ((companyId != organization.getCompanyId()) ||
3915 (parentOrganizationId != organization.getParentOrganizationId())) {
3916 list = null;
3917
3918 break;
3919 }
3920 }
3921 }
3922 }
3923
3924 if (list == null) {
3925 StringBundler query = null;
3926
3927 if (orderByComparator != null) {
3928 query = new StringBundler(4 +
3929 (orderByComparator.getOrderByFields().length * 2));
3930 }
3931 else {
3932 query = new StringBundler(4);
3933 }
3934
3935 query.append(_SQL_SELECT_ORGANIZATION_WHERE);
3936
3937 query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
3938
3939 query.append(_FINDER_COLUMN_C_P_PARENTORGANIZATIONID_2);
3940
3941 if (orderByComparator != null) {
3942 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3943 orderByComparator);
3944 }
3945 else
3946 if (pagination) {
3947 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
3948 }
3949
3950 String sql = query.toString();
3951
3952 Session session = null;
3953
3954 try {
3955 session = openSession();
3956
3957 Query q = session.createQuery(sql);
3958
3959 QueryPos qPos = QueryPos.getInstance(q);
3960
3961 qPos.add(companyId);
3962
3963 qPos.add(parentOrganizationId);
3964
3965 if (!pagination) {
3966 list = (List<Organization>)QueryUtil.list(q, getDialect(),
3967 start, end, false);
3968
3969 Collections.sort(list);
3970
3971 list = Collections.unmodifiableList(list);
3972 }
3973 else {
3974 list = (List<Organization>)QueryUtil.list(q, getDialect(),
3975 start, end);
3976 }
3977
3978 cacheResult(list);
3979
3980 finderCache.putResult(finderPath, finderArgs, list);
3981 }
3982 catch (Exception e) {
3983 finderCache.removeResult(finderPath, finderArgs);
3984
3985 throw processException(e);
3986 }
3987 finally {
3988 closeSession(session);
3989 }
3990 }
3991
3992 return list;
3993 }
3994
3995
4004 @Override
4005 public Organization findByC_P_First(long companyId,
4006 long parentOrganizationId,
4007 OrderByComparator<Organization> orderByComparator)
4008 throws NoSuchOrganizationException {
4009 Organization organization = fetchByC_P_First(companyId,
4010 parentOrganizationId, orderByComparator);
4011
4012 if (organization != null) {
4013 return organization;
4014 }
4015
4016 StringBundler msg = new StringBundler(6);
4017
4018 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4019
4020 msg.append("companyId=");
4021 msg.append(companyId);
4022
4023 msg.append(", parentOrganizationId=");
4024 msg.append(parentOrganizationId);
4025
4026 msg.append(StringPool.CLOSE_CURLY_BRACE);
4027
4028 throw new NoSuchOrganizationException(msg.toString());
4029 }
4030
4031
4039 @Override
4040 public Organization fetchByC_P_First(long companyId,
4041 long parentOrganizationId,
4042 OrderByComparator<Organization> orderByComparator) {
4043 List<Organization> list = findByC_P(companyId, parentOrganizationId, 0,
4044 1, orderByComparator);
4045
4046 if (!list.isEmpty()) {
4047 return list.get(0);
4048 }
4049
4050 return null;
4051 }
4052
4053
4062 @Override
4063 public Organization findByC_P_Last(long companyId,
4064 long parentOrganizationId,
4065 OrderByComparator<Organization> orderByComparator)
4066 throws NoSuchOrganizationException {
4067 Organization organization = fetchByC_P_Last(companyId,
4068 parentOrganizationId, orderByComparator);
4069
4070 if (organization != null) {
4071 return organization;
4072 }
4073
4074 StringBundler msg = new StringBundler(6);
4075
4076 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4077
4078 msg.append("companyId=");
4079 msg.append(companyId);
4080
4081 msg.append(", parentOrganizationId=");
4082 msg.append(parentOrganizationId);
4083
4084 msg.append(StringPool.CLOSE_CURLY_BRACE);
4085
4086 throw new NoSuchOrganizationException(msg.toString());
4087 }
4088
4089
4097 @Override
4098 public Organization fetchByC_P_Last(long companyId,
4099 long parentOrganizationId,
4100 OrderByComparator<Organization> orderByComparator) {
4101 int count = countByC_P(companyId, parentOrganizationId);
4102
4103 if (count == 0) {
4104 return null;
4105 }
4106
4107 List<Organization> list = findByC_P(companyId, parentOrganizationId,
4108 count - 1, count, orderByComparator);
4109
4110 if (!list.isEmpty()) {
4111 return list.get(0);
4112 }
4113
4114 return null;
4115 }
4116
4117
4127 @Override
4128 public Organization[] findByC_P_PrevAndNext(long organizationId,
4129 long companyId, long parentOrganizationId,
4130 OrderByComparator<Organization> orderByComparator)
4131 throws NoSuchOrganizationException {
4132 Organization organization = findByPrimaryKey(organizationId);
4133
4134 Session session = null;
4135
4136 try {
4137 session = openSession();
4138
4139 Organization[] array = new OrganizationImpl[3];
4140
4141 array[0] = getByC_P_PrevAndNext(session, organization, companyId,
4142 parentOrganizationId, orderByComparator, true);
4143
4144 array[1] = organization;
4145
4146 array[2] = getByC_P_PrevAndNext(session, organization, companyId,
4147 parentOrganizationId, orderByComparator, false);
4148
4149 return array;
4150 }
4151 catch (Exception e) {
4152 throw processException(e);
4153 }
4154 finally {
4155 closeSession(session);
4156 }
4157 }
4158
4159 protected Organization getByC_P_PrevAndNext(Session session,
4160 Organization organization, long companyId, long parentOrganizationId,
4161 OrderByComparator<Organization> orderByComparator, boolean previous) {
4162 StringBundler query = null;
4163
4164 if (orderByComparator != null) {
4165 query = new StringBundler(5 +
4166 (orderByComparator.getOrderByConditionFields().length * 3) +
4167 (orderByComparator.getOrderByFields().length * 3));
4168 }
4169 else {
4170 query = new StringBundler(4);
4171 }
4172
4173 query.append(_SQL_SELECT_ORGANIZATION_WHERE);
4174
4175 query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
4176
4177 query.append(_FINDER_COLUMN_C_P_PARENTORGANIZATIONID_2);
4178
4179 if (orderByComparator != null) {
4180 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4181
4182 if (orderByConditionFields.length > 0) {
4183 query.append(WHERE_AND);
4184 }
4185
4186 for (int i = 0; i < orderByConditionFields.length; i++) {
4187 query.append(_ORDER_BY_ENTITY_ALIAS);
4188 query.append(orderByConditionFields[i]);
4189
4190 if ((i + 1) < orderByConditionFields.length) {
4191 if (orderByComparator.isAscending() ^ previous) {
4192 query.append(WHERE_GREATER_THAN_HAS_NEXT);
4193 }
4194 else {
4195 query.append(WHERE_LESSER_THAN_HAS_NEXT);
4196 }
4197 }
4198 else {
4199 if (orderByComparator.isAscending() ^ previous) {
4200 query.append(WHERE_GREATER_THAN);
4201 }
4202 else {
4203 query.append(WHERE_LESSER_THAN);
4204 }
4205 }
4206 }
4207
4208 query.append(ORDER_BY_CLAUSE);
4209
4210 String[] orderByFields = orderByComparator.getOrderByFields();
4211
4212 for (int i = 0; i < orderByFields.length; i++) {
4213 query.append(_ORDER_BY_ENTITY_ALIAS);
4214 query.append(orderByFields[i]);
4215
4216 if ((i + 1) < orderByFields.length) {
4217 if (orderByComparator.isAscending() ^ previous) {
4218 query.append(ORDER_BY_ASC_HAS_NEXT);
4219 }
4220 else {
4221 query.append(ORDER_BY_DESC_HAS_NEXT);
4222 }
4223 }
4224 else {
4225 if (orderByComparator.isAscending() ^ previous) {
4226 query.append(ORDER_BY_ASC);
4227 }
4228 else {
4229 query.append(ORDER_BY_DESC);
4230 }
4231 }
4232 }
4233 }
4234 else {
4235 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
4236 }
4237
4238 String sql = query.toString();
4239
4240 Query q = session.createQuery(sql);
4241
4242 q.setFirstResult(0);
4243 q.setMaxResults(2);
4244
4245 QueryPos qPos = QueryPos.getInstance(q);
4246
4247 qPos.add(companyId);
4248
4249 qPos.add(parentOrganizationId);
4250
4251 if (orderByComparator != null) {
4252 Object[] values = orderByComparator.getOrderByConditionValues(organization);
4253
4254 for (Object value : values) {
4255 qPos.add(value);
4256 }
4257 }
4258
4259 List<Organization> list = q.list();
4260
4261 if (list.size() == 2) {
4262 return list.get(1);
4263 }
4264 else {
4265 return null;
4266 }
4267 }
4268
4269
4276 @Override
4277 public List<Organization> filterFindByC_P(long companyId,
4278 long parentOrganizationId) {
4279 return filterFindByC_P(companyId, parentOrganizationId,
4280 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
4281 }
4282
4283
4296 @Override
4297 public List<Organization> filterFindByC_P(long companyId,
4298 long parentOrganizationId, int start, int end) {
4299 return filterFindByC_P(companyId, parentOrganizationId, start, end, null);
4300 }
4301
4302
4316 @Override
4317 public List<Organization> filterFindByC_P(long companyId,
4318 long parentOrganizationId, int start, int end,
4319 OrderByComparator<Organization> orderByComparator) {
4320 if (!InlineSQLHelperUtil.isEnabled(companyId, 0)) {
4321 return findByC_P(companyId, parentOrganizationId, start, end,
4322 orderByComparator);
4323 }
4324
4325 StringBundler query = null;
4326
4327 if (orderByComparator != null) {
4328 query = new StringBundler(4 +
4329 (orderByComparator.getOrderByFields().length * 2));
4330 }
4331 else {
4332 query = new StringBundler(5);
4333 }
4334
4335 if (getDB().isSupportsInlineDistinct()) {
4336 query.append(_FILTER_SQL_SELECT_ORGANIZATION_WHERE);
4337 }
4338 else {
4339 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1);
4340 }
4341
4342 query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
4343
4344 query.append(_FINDER_COLUMN_C_P_PARENTORGANIZATIONID_2);
4345
4346 if (!getDB().isSupportsInlineDistinct()) {
4347 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2);
4348 }
4349
4350 if (orderByComparator != null) {
4351 if (getDB().isSupportsInlineDistinct()) {
4352 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4353 orderByComparator, true);
4354 }
4355 else {
4356 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
4357 orderByComparator, true);
4358 }
4359 }
4360 else {
4361 if (getDB().isSupportsInlineDistinct()) {
4362 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
4363 }
4364 else {
4365 query.append(OrganizationModelImpl.ORDER_BY_SQL);
4366 }
4367 }
4368
4369 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4370 Organization.class.getName(),
4371 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
4372
4373 Session session = null;
4374
4375 try {
4376 session = openSession();
4377
4378 SQLQuery q = session.createSynchronizedSQLQuery(sql);
4379
4380 if (getDB().isSupportsInlineDistinct()) {
4381 q.addEntity(_FILTER_ENTITY_ALIAS, OrganizationImpl.class);
4382 }
4383 else {
4384 q.addEntity(_FILTER_ENTITY_TABLE, OrganizationImpl.class);
4385 }
4386
4387 QueryPos qPos = QueryPos.getInstance(q);
4388
4389 qPos.add(companyId);
4390
4391 qPos.add(parentOrganizationId);
4392
4393 return (List<Organization>)QueryUtil.list(q, getDialect(), start,
4394 end);
4395 }
4396 catch (Exception e) {
4397 throw processException(e);
4398 }
4399 finally {
4400 closeSession(session);
4401 }
4402 }
4403
4404
4414 @Override
4415 public Organization[] filterFindByC_P_PrevAndNext(long organizationId,
4416 long companyId, long parentOrganizationId,
4417 OrderByComparator<Organization> orderByComparator)
4418 throws NoSuchOrganizationException {
4419 if (!InlineSQLHelperUtil.isEnabled(companyId, 0)) {
4420 return findByC_P_PrevAndNext(organizationId, companyId,
4421 parentOrganizationId, orderByComparator);
4422 }
4423
4424 Organization organization = findByPrimaryKey(organizationId);
4425
4426 Session session = null;
4427
4428 try {
4429 session = openSession();
4430
4431 Organization[] array = new OrganizationImpl[3];
4432
4433 array[0] = filterGetByC_P_PrevAndNext(session, organization,
4434 companyId, parentOrganizationId, orderByComparator, true);
4435
4436 array[1] = organization;
4437
4438 array[2] = filterGetByC_P_PrevAndNext(session, organization,
4439 companyId, parentOrganizationId, orderByComparator, false);
4440
4441 return array;
4442 }
4443 catch (Exception e) {
4444 throw processException(e);
4445 }
4446 finally {
4447 closeSession(session);
4448 }
4449 }
4450
4451 protected Organization filterGetByC_P_PrevAndNext(Session session,
4452 Organization organization, long companyId, long parentOrganizationId,
4453 OrderByComparator<Organization> orderByComparator, boolean previous) {
4454 StringBundler query = null;
4455
4456 if (orderByComparator != null) {
4457 query = new StringBundler(6 +
4458 (orderByComparator.getOrderByConditionFields().length * 3) +
4459 (orderByComparator.getOrderByFields().length * 3));
4460 }
4461 else {
4462 query = new StringBundler(5);
4463 }
4464
4465 if (getDB().isSupportsInlineDistinct()) {
4466 query.append(_FILTER_SQL_SELECT_ORGANIZATION_WHERE);
4467 }
4468 else {
4469 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1);
4470 }
4471
4472 query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
4473
4474 query.append(_FINDER_COLUMN_C_P_PARENTORGANIZATIONID_2);
4475
4476 if (!getDB().isSupportsInlineDistinct()) {
4477 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2);
4478 }
4479
4480 if (orderByComparator != null) {
4481 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4482
4483 if (orderByConditionFields.length > 0) {
4484 query.append(WHERE_AND);
4485 }
4486
4487 for (int i = 0; i < orderByConditionFields.length; i++) {
4488 if (getDB().isSupportsInlineDistinct()) {
4489 query.append(_ORDER_BY_ENTITY_ALIAS);
4490 }
4491 else {
4492 query.append(_ORDER_BY_ENTITY_TABLE);
4493 }
4494
4495 query.append(orderByConditionFields[i]);
4496
4497 if ((i + 1) < orderByConditionFields.length) {
4498 if (orderByComparator.isAscending() ^ previous) {
4499 query.append(WHERE_GREATER_THAN_HAS_NEXT);
4500 }
4501 else {
4502 query.append(WHERE_LESSER_THAN_HAS_NEXT);
4503 }
4504 }
4505 else {
4506 if (orderByComparator.isAscending() ^ previous) {
4507 query.append(WHERE_GREATER_THAN);
4508 }
4509 else {
4510 query.append(WHERE_LESSER_THAN);
4511 }
4512 }
4513 }
4514
4515 query.append(ORDER_BY_CLAUSE);
4516
4517 String[] orderByFields = orderByComparator.getOrderByFields();
4518
4519 for (int i = 0; i < orderByFields.length; i++) {
4520 if (getDB().isSupportsInlineDistinct()) {
4521 query.append(_ORDER_BY_ENTITY_ALIAS);
4522 }
4523 else {
4524 query.append(_ORDER_BY_ENTITY_TABLE);
4525 }
4526
4527 query.append(orderByFields[i]);
4528
4529 if ((i + 1) < orderByFields.length) {
4530 if (orderByComparator.isAscending() ^ previous) {
4531 query.append(ORDER_BY_ASC_HAS_NEXT);
4532 }
4533 else {
4534 query.append(ORDER_BY_DESC_HAS_NEXT);
4535 }
4536 }
4537 else {
4538 if (orderByComparator.isAscending() ^ previous) {
4539 query.append(ORDER_BY_ASC);
4540 }
4541 else {
4542 query.append(ORDER_BY_DESC);
4543 }
4544 }
4545 }
4546 }
4547 else {
4548 if (getDB().isSupportsInlineDistinct()) {
4549 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
4550 }
4551 else {
4552 query.append(OrganizationModelImpl.ORDER_BY_SQL);
4553 }
4554 }
4555
4556 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4557 Organization.class.getName(),
4558 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
4559
4560 SQLQuery q = session.createSynchronizedSQLQuery(sql);
4561
4562 q.setFirstResult(0);
4563 q.setMaxResults(2);
4564
4565 if (getDB().isSupportsInlineDistinct()) {
4566 q.addEntity(_FILTER_ENTITY_ALIAS, OrganizationImpl.class);
4567 }
4568 else {
4569 q.addEntity(_FILTER_ENTITY_TABLE, OrganizationImpl.class);
4570 }
4571
4572 QueryPos qPos = QueryPos.getInstance(q);
4573
4574 qPos.add(companyId);
4575
4576 qPos.add(parentOrganizationId);
4577
4578 if (orderByComparator != null) {
4579 Object[] values = orderByComparator.getOrderByConditionValues(organization);
4580
4581 for (Object value : values) {
4582 qPos.add(value);
4583 }
4584 }
4585
4586 List<Organization> list = q.list();
4587
4588 if (list.size() == 2) {
4589 return list.get(1);
4590 }
4591 else {
4592 return null;
4593 }
4594 }
4595
4596
4602 @Override
4603 public void removeByC_P(long companyId, long parentOrganizationId) {
4604 for (Organization organization : findByC_P(companyId,
4605 parentOrganizationId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
4606 remove(organization);
4607 }
4608 }
4609
4610
4617 @Override
4618 public int countByC_P(long companyId, long parentOrganizationId) {
4619 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_P;
4620
4621 Object[] finderArgs = new Object[] { companyId, parentOrganizationId };
4622
4623 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
4624
4625 if (count == null) {
4626 StringBundler query = new StringBundler(3);
4627
4628 query.append(_SQL_COUNT_ORGANIZATION_WHERE);
4629
4630 query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
4631
4632 query.append(_FINDER_COLUMN_C_P_PARENTORGANIZATIONID_2);
4633
4634 String sql = query.toString();
4635
4636 Session session = null;
4637
4638 try {
4639 session = openSession();
4640
4641 Query q = session.createQuery(sql);
4642
4643 QueryPos qPos = QueryPos.getInstance(q);
4644
4645 qPos.add(companyId);
4646
4647 qPos.add(parentOrganizationId);
4648
4649 count = (Long)q.uniqueResult();
4650
4651 finderCache.putResult(finderPath, finderArgs, count);
4652 }
4653 catch (Exception e) {
4654 finderCache.removeResult(finderPath, finderArgs);
4655
4656 throw processException(e);
4657 }
4658 finally {
4659 closeSession(session);
4660 }
4661 }
4662
4663 return count.intValue();
4664 }
4665
4666
4673 @Override
4674 public int filterCountByC_P(long companyId, long parentOrganizationId) {
4675 if (!InlineSQLHelperUtil.isEnabled(companyId, 0)) {
4676 return countByC_P(companyId, parentOrganizationId);
4677 }
4678
4679 StringBundler query = new StringBundler(3);
4680
4681 query.append(_FILTER_SQL_COUNT_ORGANIZATION_WHERE);
4682
4683 query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
4684
4685 query.append(_FINDER_COLUMN_C_P_PARENTORGANIZATIONID_2);
4686
4687 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4688 Organization.class.getName(),
4689 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
4690
4691 Session session = null;
4692
4693 try {
4694 session = openSession();
4695
4696 SQLQuery q = session.createSynchronizedSQLQuery(sql);
4697
4698 q.addScalar(COUNT_COLUMN_NAME,
4699 com.liferay.portal.kernel.dao.orm.Type.LONG);
4700
4701 QueryPos qPos = QueryPos.getInstance(q);
4702
4703 qPos.add(companyId);
4704
4705 qPos.add(parentOrganizationId);
4706
4707 Long count = (Long)q.uniqueResult();
4708
4709 return count.intValue();
4710 }
4711 catch (Exception e) {
4712 throw processException(e);
4713 }
4714 finally {
4715 closeSession(session);
4716 }
4717 }
4718
4719 private static final String _FINDER_COLUMN_C_P_COMPANYID_2 = "organization.companyId = ? AND ";
4720 private static final String _FINDER_COLUMN_C_P_PARENTORGANIZATIONID_2 = "organization.parentOrganizationId = ?";
4721 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_T = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
4722 OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
4723 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_T",
4724 new String[] {
4725 Long.class.getName(), String.class.getName(),
4726
4727 Integer.class.getName(), Integer.class.getName(),
4728 OrderByComparator.class.getName()
4729 });
4730 public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_T = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
4731 OrganizationModelImpl.FINDER_CACHE_ENABLED, Long.class,
4732 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByC_T",
4733 new String[] { Long.class.getName(), String.class.getName() });
4734
4735
4742 @Override
4743 public List<Organization> findByC_T(long companyId, String treePath) {
4744 return findByC_T(companyId, treePath, QueryUtil.ALL_POS,
4745 QueryUtil.ALL_POS, null);
4746 }
4747
4748
4761 @Override
4762 public List<Organization> findByC_T(long companyId, String treePath,
4763 int start, int end) {
4764 return findByC_T(companyId, treePath, start, end, null);
4765 }
4766
4767
4781 @Override
4782 public List<Organization> findByC_T(long companyId, String treePath,
4783 int start, int end, OrderByComparator<Organization> orderByComparator) {
4784 return findByC_T(companyId, treePath, start, end, orderByComparator,
4785 true);
4786 }
4787
4788
4803 @Override
4804 public List<Organization> findByC_T(long companyId, String treePath,
4805 int start, int end, OrderByComparator<Organization> orderByComparator,
4806 boolean retrieveFromCache) {
4807 boolean pagination = true;
4808 FinderPath finderPath = null;
4809 Object[] finderArgs = null;
4810
4811 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_T;
4812 finderArgs = new Object[] {
4813 companyId, treePath,
4814
4815 start, end, orderByComparator
4816 };
4817
4818 List<Organization> list = null;
4819
4820 if (retrieveFromCache) {
4821 list = (List<Organization>)finderCache.getResult(finderPath,
4822 finderArgs, this);
4823
4824 if ((list != null) && !list.isEmpty()) {
4825 for (Organization organization : list) {
4826 if ((companyId != organization.getCompanyId()) ||
4827 !StringUtil.wildcardMatches(
4828 organization.getTreePath(), treePath,
4829 CharPool.UNDERLINE, CharPool.PERCENT,
4830 CharPool.BACK_SLASH, true)) {
4831 list = null;
4832
4833 break;
4834 }
4835 }
4836 }
4837 }
4838
4839 if (list == null) {
4840 StringBundler query = null;
4841
4842 if (orderByComparator != null) {
4843 query = new StringBundler(4 +
4844 (orderByComparator.getOrderByFields().length * 2));
4845 }
4846 else {
4847 query = new StringBundler(4);
4848 }
4849
4850 query.append(_SQL_SELECT_ORGANIZATION_WHERE);
4851
4852 query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
4853
4854 boolean bindTreePath = false;
4855
4856 if (treePath == null) {
4857 query.append(_FINDER_COLUMN_C_T_TREEPATH_1);
4858 }
4859 else if (treePath.equals(StringPool.BLANK)) {
4860 query.append(_FINDER_COLUMN_C_T_TREEPATH_3);
4861 }
4862 else {
4863 bindTreePath = true;
4864
4865 query.append(_FINDER_COLUMN_C_T_TREEPATH_2);
4866 }
4867
4868 if (orderByComparator != null) {
4869 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4870 orderByComparator);
4871 }
4872 else
4873 if (pagination) {
4874 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
4875 }
4876
4877 String sql = query.toString();
4878
4879 Session session = null;
4880
4881 try {
4882 session = openSession();
4883
4884 Query q = session.createQuery(sql);
4885
4886 QueryPos qPos = QueryPos.getInstance(q);
4887
4888 qPos.add(companyId);
4889
4890 if (bindTreePath) {
4891 qPos.add(treePath);
4892 }
4893
4894 if (!pagination) {
4895 list = (List<Organization>)QueryUtil.list(q, getDialect(),
4896 start, end, false);
4897
4898 Collections.sort(list);
4899
4900 list = Collections.unmodifiableList(list);
4901 }
4902 else {
4903 list = (List<Organization>)QueryUtil.list(q, getDialect(),
4904 start, end);
4905 }
4906
4907 cacheResult(list);
4908
4909 finderCache.putResult(finderPath, finderArgs, list);
4910 }
4911 catch (Exception e) {
4912 finderCache.removeResult(finderPath, finderArgs);
4913
4914 throw processException(e);
4915 }
4916 finally {
4917 closeSession(session);
4918 }
4919 }
4920
4921 return list;
4922 }
4923
4924
4933 @Override
4934 public Organization findByC_T_First(long companyId, String treePath,
4935 OrderByComparator<Organization> orderByComparator)
4936 throws NoSuchOrganizationException {
4937 Organization organization = fetchByC_T_First(companyId, treePath,
4938 orderByComparator);
4939
4940 if (organization != null) {
4941 return organization;
4942 }
4943
4944 StringBundler msg = new StringBundler(6);
4945
4946 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4947
4948 msg.append("companyId=");
4949 msg.append(companyId);
4950
4951 msg.append(", treePath=");
4952 msg.append(treePath);
4953
4954 msg.append(StringPool.CLOSE_CURLY_BRACE);
4955
4956 throw new NoSuchOrganizationException(msg.toString());
4957 }
4958
4959
4967 @Override
4968 public Organization fetchByC_T_First(long companyId, String treePath,
4969 OrderByComparator<Organization> orderByComparator) {
4970 List<Organization> list = findByC_T(companyId, treePath, 0, 1,
4971 orderByComparator);
4972
4973 if (!list.isEmpty()) {
4974 return list.get(0);
4975 }
4976
4977 return null;
4978 }
4979
4980
4989 @Override
4990 public Organization findByC_T_Last(long companyId, String treePath,
4991 OrderByComparator<Organization> orderByComparator)
4992 throws NoSuchOrganizationException {
4993 Organization organization = fetchByC_T_Last(companyId, treePath,
4994 orderByComparator);
4995
4996 if (organization != null) {
4997 return organization;
4998 }
4999
5000 StringBundler msg = new StringBundler(6);
5001
5002 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5003
5004 msg.append("companyId=");
5005 msg.append(companyId);
5006
5007 msg.append(", treePath=");
5008 msg.append(treePath);
5009
5010 msg.append(StringPool.CLOSE_CURLY_BRACE);
5011
5012 throw new NoSuchOrganizationException(msg.toString());
5013 }
5014
5015
5023 @Override
5024 public Organization fetchByC_T_Last(long companyId, String treePath,
5025 OrderByComparator<Organization> orderByComparator) {
5026 int count = countByC_T(companyId, treePath);
5027
5028 if (count == 0) {
5029 return null;
5030 }
5031
5032 List<Organization> list = findByC_T(companyId, treePath, count - 1,
5033 count, orderByComparator);
5034
5035 if (!list.isEmpty()) {
5036 return list.get(0);
5037 }
5038
5039 return null;
5040 }
5041
5042
5052 @Override
5053 public Organization[] findByC_T_PrevAndNext(long organizationId,
5054 long companyId, String treePath,
5055 OrderByComparator<Organization> orderByComparator)
5056 throws NoSuchOrganizationException {
5057 Organization organization = findByPrimaryKey(organizationId);
5058
5059 Session session = null;
5060
5061 try {
5062 session = openSession();
5063
5064 Organization[] array = new OrganizationImpl[3];
5065
5066 array[0] = getByC_T_PrevAndNext(session, organization, companyId,
5067 treePath, orderByComparator, true);
5068
5069 array[1] = organization;
5070
5071 array[2] = getByC_T_PrevAndNext(session, organization, companyId,
5072 treePath, orderByComparator, false);
5073
5074 return array;
5075 }
5076 catch (Exception e) {
5077 throw processException(e);
5078 }
5079 finally {
5080 closeSession(session);
5081 }
5082 }
5083
5084 protected Organization getByC_T_PrevAndNext(Session session,
5085 Organization organization, long companyId, String treePath,
5086 OrderByComparator<Organization> orderByComparator, boolean previous) {
5087 StringBundler query = null;
5088
5089 if (orderByComparator != null) {
5090 query = new StringBundler(5 +
5091 (orderByComparator.getOrderByConditionFields().length * 3) +
5092 (orderByComparator.getOrderByFields().length * 3));
5093 }
5094 else {
5095 query = new StringBundler(4);
5096 }
5097
5098 query.append(_SQL_SELECT_ORGANIZATION_WHERE);
5099
5100 query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
5101
5102 boolean bindTreePath = false;
5103
5104 if (treePath == null) {
5105 query.append(_FINDER_COLUMN_C_T_TREEPATH_1);
5106 }
5107 else if (treePath.equals(StringPool.BLANK)) {
5108 query.append(_FINDER_COLUMN_C_T_TREEPATH_3);
5109 }
5110 else {
5111 bindTreePath = true;
5112
5113 query.append(_FINDER_COLUMN_C_T_TREEPATH_2);
5114 }
5115
5116 if (orderByComparator != null) {
5117 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5118
5119 if (orderByConditionFields.length > 0) {
5120 query.append(WHERE_AND);
5121 }
5122
5123 for (int i = 0; i < orderByConditionFields.length; i++) {
5124 query.append(_ORDER_BY_ENTITY_ALIAS);
5125 query.append(orderByConditionFields[i]);
5126
5127 if ((i + 1) < orderByConditionFields.length) {
5128 if (orderByComparator.isAscending() ^ previous) {
5129 query.append(WHERE_GREATER_THAN_HAS_NEXT);
5130 }
5131 else {
5132 query.append(WHERE_LESSER_THAN_HAS_NEXT);
5133 }
5134 }
5135 else {
5136 if (orderByComparator.isAscending() ^ previous) {
5137 query.append(WHERE_GREATER_THAN);
5138 }
5139 else {
5140 query.append(WHERE_LESSER_THAN);
5141 }
5142 }
5143 }
5144
5145 query.append(ORDER_BY_CLAUSE);
5146
5147 String[] orderByFields = orderByComparator.getOrderByFields();
5148
5149 for (int i = 0; i < orderByFields.length; i++) {
5150 query.append(_ORDER_BY_ENTITY_ALIAS);
5151 query.append(orderByFields[i]);
5152
5153 if ((i + 1) < orderByFields.length) {
5154 if (orderByComparator.isAscending() ^ previous) {
5155 query.append(ORDER_BY_ASC_HAS_NEXT);
5156 }
5157 else {
5158 query.append(ORDER_BY_DESC_HAS_NEXT);
5159 }
5160 }
5161 else {
5162 if (orderByComparator.isAscending() ^ previous) {
5163 query.append(ORDER_BY_ASC);
5164 }
5165 else {
5166 query.append(ORDER_BY_DESC);
5167 }
5168 }
5169 }
5170 }
5171 else {
5172 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
5173 }
5174
5175 String sql = query.toString();
5176
5177 Query q = session.createQuery(sql);
5178
5179 q.setFirstResult(0);
5180 q.setMaxResults(2);
5181
5182 QueryPos qPos = QueryPos.getInstance(q);
5183
5184 qPos.add(companyId);
5185
5186 if (bindTreePath) {
5187 qPos.add(treePath);
5188 }
5189
5190 if (orderByComparator != null) {
5191 Object[] values = orderByComparator.getOrderByConditionValues(organization);
5192
5193 for (Object value : values) {
5194 qPos.add(value);
5195 }
5196 }
5197
5198 List<Organization> list = q.list();
5199
5200 if (list.size() == 2) {
5201 return list.get(1);
5202 }
5203 else {
5204 return null;
5205 }
5206 }
5207
5208
5215 @Override
5216 public List<Organization> filterFindByC_T(long companyId, String treePath) {
5217 return filterFindByC_T(companyId, treePath, QueryUtil.ALL_POS,
5218 QueryUtil.ALL_POS, null);
5219 }
5220
5221
5234 @Override
5235 public List<Organization> filterFindByC_T(long companyId, String treePath,
5236 int start, int end) {
5237 return filterFindByC_T(companyId, treePath, start, end, null);
5238 }
5239
5240
5254 @Override
5255 public List<Organization> filterFindByC_T(long companyId, String treePath,
5256 int start, int end, OrderByComparator<Organization> orderByComparator) {
5257 if (!InlineSQLHelperUtil.isEnabled(companyId, 0)) {
5258 return findByC_T(companyId, treePath, start, end, orderByComparator);
5259 }
5260
5261 StringBundler query = null;
5262
5263 if (orderByComparator != null) {
5264 query = new StringBundler(4 +
5265 (orderByComparator.getOrderByFields().length * 2));
5266 }
5267 else {
5268 query = new StringBundler(5);
5269 }
5270
5271 if (getDB().isSupportsInlineDistinct()) {
5272 query.append(_FILTER_SQL_SELECT_ORGANIZATION_WHERE);
5273 }
5274 else {
5275 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1);
5276 }
5277
5278 query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
5279
5280 boolean bindTreePath = false;
5281
5282 if (treePath == null) {
5283 query.append(_FINDER_COLUMN_C_T_TREEPATH_1);
5284 }
5285 else if (treePath.equals(StringPool.BLANK)) {
5286 query.append(_FINDER_COLUMN_C_T_TREEPATH_3);
5287 }
5288 else {
5289 bindTreePath = true;
5290
5291 query.append(_FINDER_COLUMN_C_T_TREEPATH_2);
5292 }
5293
5294 if (!getDB().isSupportsInlineDistinct()) {
5295 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2);
5296 }
5297
5298 if (orderByComparator != null) {
5299 if (getDB().isSupportsInlineDistinct()) {
5300 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5301 orderByComparator, true);
5302 }
5303 else {
5304 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
5305 orderByComparator, true);
5306 }
5307 }
5308 else {
5309 if (getDB().isSupportsInlineDistinct()) {
5310 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
5311 }
5312 else {
5313 query.append(OrganizationModelImpl.ORDER_BY_SQL);
5314 }
5315 }
5316
5317 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5318 Organization.class.getName(),
5319 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
5320
5321 Session session = null;
5322
5323 try {
5324 session = openSession();
5325
5326 SQLQuery q = session.createSynchronizedSQLQuery(sql);
5327
5328 if (getDB().isSupportsInlineDistinct()) {
5329 q.addEntity(_FILTER_ENTITY_ALIAS, OrganizationImpl.class);
5330 }
5331 else {
5332 q.addEntity(_FILTER_ENTITY_TABLE, OrganizationImpl.class);
5333 }
5334
5335 QueryPos qPos = QueryPos.getInstance(q);
5336
5337 qPos.add(companyId);
5338
5339 if (bindTreePath) {
5340 qPos.add(treePath);
5341 }
5342
5343 return (List<Organization>)QueryUtil.list(q, getDialect(), start,
5344 end);
5345 }
5346 catch (Exception e) {
5347 throw processException(e);
5348 }
5349 finally {
5350 closeSession(session);
5351 }
5352 }
5353
5354
5364 @Override
5365 public Organization[] filterFindByC_T_PrevAndNext(long organizationId,
5366 long companyId, String treePath,
5367 OrderByComparator<Organization> orderByComparator)
5368 throws NoSuchOrganizationException {
5369 if (!InlineSQLHelperUtil.isEnabled(companyId, 0)) {
5370 return findByC_T_PrevAndNext(organizationId, companyId, treePath,
5371 orderByComparator);
5372 }
5373
5374 Organization organization = findByPrimaryKey(organizationId);
5375
5376 Session session = null;
5377
5378 try {
5379 session = openSession();
5380
5381 Organization[] array = new OrganizationImpl[3];
5382
5383 array[0] = filterGetByC_T_PrevAndNext(session, organization,
5384 companyId, treePath, orderByComparator, true);
5385
5386 array[1] = organization;
5387
5388 array[2] = filterGetByC_T_PrevAndNext(session, organization,
5389 companyId, treePath, orderByComparator, false);
5390
5391 return array;
5392 }
5393 catch (Exception e) {
5394 throw processException(e);
5395 }
5396 finally {
5397 closeSession(session);
5398 }
5399 }
5400
5401 protected Organization filterGetByC_T_PrevAndNext(Session session,
5402 Organization organization, long companyId, String treePath,
5403 OrderByComparator<Organization> orderByComparator, boolean previous) {
5404 StringBundler query = null;
5405
5406 if (orderByComparator != null) {
5407 query = new StringBundler(6 +
5408 (orderByComparator.getOrderByConditionFields().length * 3) +
5409 (orderByComparator.getOrderByFields().length * 3));
5410 }
5411 else {
5412 query = new StringBundler(5);
5413 }
5414
5415 if (getDB().isSupportsInlineDistinct()) {
5416 query.append(_FILTER_SQL_SELECT_ORGANIZATION_WHERE);
5417 }
5418 else {
5419 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1);
5420 }
5421
5422 query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
5423
5424 boolean bindTreePath = false;
5425
5426 if (treePath == null) {
5427 query.append(_FINDER_COLUMN_C_T_TREEPATH_1);
5428 }
5429 else if (treePath.equals(StringPool.BLANK)) {
5430 query.append(_FINDER_COLUMN_C_T_TREEPATH_3);
5431 }
5432 else {
5433 bindTreePath = true;
5434
5435 query.append(_FINDER_COLUMN_C_T_TREEPATH_2);
5436 }
5437
5438 if (!getDB().isSupportsInlineDistinct()) {
5439 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2);
5440 }
5441
5442 if (orderByComparator != null) {
5443 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5444
5445 if (orderByConditionFields.length > 0) {
5446 query.append(WHERE_AND);
5447 }
5448
5449 for (int i = 0; i < orderByConditionFields.length; i++) {
5450 if (getDB().isSupportsInlineDistinct()) {
5451 query.append(_ORDER_BY_ENTITY_ALIAS);
5452 }
5453 else {
5454 query.append(_ORDER_BY_ENTITY_TABLE);
5455 }
5456
5457 query.append(orderByConditionFields[i]);
5458
5459 if ((i + 1) < orderByConditionFields.length) {
5460 if (orderByComparator.isAscending() ^ previous) {
5461 query.append(WHERE_GREATER_THAN_HAS_NEXT);
5462 }
5463 else {
5464 query.append(WHERE_LESSER_THAN_HAS_NEXT);
5465 }
5466 }
5467 else {
5468 if (orderByComparator.isAscending() ^ previous) {
5469 query.append(WHERE_GREATER_THAN);
5470 }
5471 else {
5472 query.append(WHERE_LESSER_THAN);
5473 }
5474 }
5475 }
5476
5477 query.append(ORDER_BY_CLAUSE);
5478
5479 String[] orderByFields = orderByComparator.getOrderByFields();
5480
5481 for (int i = 0; i < orderByFields.length; i++) {
5482 if (getDB().isSupportsInlineDistinct()) {
5483 query.append(_ORDER_BY_ENTITY_ALIAS);
5484 }
5485 else {
5486 query.append(_ORDER_BY_ENTITY_TABLE);
5487 }
5488
5489 query.append(orderByFields[i]);
5490
5491 if ((i + 1) < orderByFields.length) {
5492 if (orderByComparator.isAscending() ^ previous) {
5493 query.append(ORDER_BY_ASC_HAS_NEXT);
5494 }
5495 else {
5496 query.append(ORDER_BY_DESC_HAS_NEXT);
5497 }
5498 }
5499 else {
5500 if (orderByComparator.isAscending() ^ previous) {
5501 query.append(ORDER_BY_ASC);
5502 }
5503 else {
5504 query.append(ORDER_BY_DESC);
5505 }
5506 }
5507 }
5508 }
5509 else {
5510 if (getDB().isSupportsInlineDistinct()) {
5511 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
5512 }
5513 else {
5514 query.append(OrganizationModelImpl.ORDER_BY_SQL);
5515 }
5516 }
5517
5518 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5519 Organization.class.getName(),
5520 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
5521
5522 SQLQuery q = session.createSynchronizedSQLQuery(sql);
5523
5524 q.setFirstResult(0);
5525 q.setMaxResults(2);
5526
5527 if (getDB().isSupportsInlineDistinct()) {
5528 q.addEntity(_FILTER_ENTITY_ALIAS, OrganizationImpl.class);
5529 }
5530 else {
5531 q.addEntity(_FILTER_ENTITY_TABLE, OrganizationImpl.class);
5532 }
5533
5534 QueryPos qPos = QueryPos.getInstance(q);
5535
5536 qPos.add(companyId);
5537
5538 if (bindTreePath) {
5539 qPos.add(treePath);
5540 }
5541
5542 if (orderByComparator != null) {
5543 Object[] values = orderByComparator.getOrderByConditionValues(organization);
5544
5545 for (Object value : values) {
5546 qPos.add(value);
5547 }
5548 }
5549
5550 List<Organization> list = q.list();
5551
5552 if (list.size() == 2) {
5553 return list.get(1);
5554 }
5555 else {
5556 return null;
5557 }
5558 }
5559
5560
5566 @Override
5567 public void removeByC_T(long companyId, String treePath) {
5568 for (Organization organization : findByC_T(companyId, treePath,
5569 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
5570 remove(organization);
5571 }
5572 }
5573
5574
5581 @Override
5582 public int countByC_T(long companyId, String treePath) {
5583 FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_T;
5584
5585 Object[] finderArgs = new Object[] { companyId, treePath };
5586
5587 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
5588
5589 if (count == null) {
5590 StringBundler query = new StringBundler(3);
5591
5592 query.append(_SQL_COUNT_ORGANIZATION_WHERE);
5593
5594 query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
5595
5596 boolean bindTreePath = false;
5597
5598 if (treePath == null) {
5599 query.append(_FINDER_COLUMN_C_T_TREEPATH_1);
5600 }
5601 else if (treePath.equals(StringPool.BLANK)) {
5602 query.append(_FINDER_COLUMN_C_T_TREEPATH_3);
5603 }
5604 else {
5605 bindTreePath = true;
5606
5607 query.append(_FINDER_COLUMN_C_T_TREEPATH_2);
5608 }
5609
5610 String sql = query.toString();
5611
5612 Session session = null;
5613
5614 try {
5615 session = openSession();
5616
5617 Query q = session.createQuery(sql);
5618
5619 QueryPos qPos = QueryPos.getInstance(q);
5620
5621 qPos.add(companyId);
5622
5623 if (bindTreePath) {
5624 qPos.add(treePath);
5625 }
5626
5627 count = (Long)q.uniqueResult();
5628
5629 finderCache.putResult(finderPath, finderArgs, count);
5630 }
5631 catch (Exception e) {
5632 finderCache.removeResult(finderPath, finderArgs);
5633
5634 throw processException(e);
5635 }
5636 finally {
5637 closeSession(session);
5638 }
5639 }
5640
5641 return count.intValue();
5642 }
5643
5644
5651 @Override
5652 public int filterCountByC_T(long companyId, String treePath) {
5653 if (!InlineSQLHelperUtil.isEnabled(companyId, 0)) {
5654 return countByC_T(companyId, treePath);
5655 }
5656
5657 StringBundler query = new StringBundler(3);
5658
5659 query.append(_FILTER_SQL_COUNT_ORGANIZATION_WHERE);
5660
5661 query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
5662
5663 boolean bindTreePath = false;
5664
5665 if (treePath == null) {
5666 query.append(_FINDER_COLUMN_C_T_TREEPATH_1);
5667 }
5668 else if (treePath.equals(StringPool.BLANK)) {
5669 query.append(_FINDER_COLUMN_C_T_TREEPATH_3);
5670 }
5671 else {
5672 bindTreePath = true;
5673
5674 query.append(_FINDER_COLUMN_C_T_TREEPATH_2);
5675 }
5676
5677 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5678 Organization.class.getName(),
5679 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
5680
5681 Session session = null;
5682
5683 try {
5684 session = openSession();
5685
5686 SQLQuery q = session.createSynchronizedSQLQuery(sql);
5687
5688 q.addScalar(COUNT_COLUMN_NAME,
5689 com.liferay.portal.kernel.dao.orm.Type.LONG);
5690
5691 QueryPos qPos = QueryPos.getInstance(q);
5692
5693 qPos.add(companyId);
5694
5695 if (bindTreePath) {
5696 qPos.add(treePath);
5697 }
5698
5699 Long count = (Long)q.uniqueResult();
5700
5701 return count.intValue();
5702 }
5703 catch (Exception e) {
5704 throw processException(e);
5705 }
5706 finally {
5707 closeSession(session);
5708 }
5709 }
5710
5711 private static final String _FINDER_COLUMN_C_T_COMPANYID_2 = "organization.companyId = ? AND ";
5712 private static final String _FINDER_COLUMN_C_T_TREEPATH_1 = "organization.treePath IS NULL";
5713 private static final String _FINDER_COLUMN_C_T_TREEPATH_2 = "organization.treePath LIKE ?";
5714 private static final String _FINDER_COLUMN_C_T_TREEPATH_3 = "(organization.treePath IS NULL OR organization.treePath LIKE '')";
5715 public static final FinderPath FINDER_PATH_FETCH_BY_C_N = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
5716 OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
5717 FINDER_CLASS_NAME_ENTITY, "fetchByC_N",
5718 new String[] { Long.class.getName(), String.class.getName() },
5719 OrganizationModelImpl.COMPANYID_COLUMN_BITMASK |
5720 OrganizationModelImpl.NAME_COLUMN_BITMASK);
5721 public static final FinderPath FINDER_PATH_COUNT_BY_C_N = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
5722 OrganizationModelImpl.FINDER_CACHE_ENABLED, Long.class,
5723 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_N",
5724 new String[] { Long.class.getName(), String.class.getName() });
5725
5726
5734 @Override
5735 public Organization findByC_N(long companyId, String name)
5736 throws NoSuchOrganizationException {
5737 Organization organization = fetchByC_N(companyId, name);
5738
5739 if (organization == null) {
5740 StringBundler msg = new StringBundler(6);
5741
5742 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5743
5744 msg.append("companyId=");
5745 msg.append(companyId);
5746
5747 msg.append(", name=");
5748 msg.append(name);
5749
5750 msg.append(StringPool.CLOSE_CURLY_BRACE);
5751
5752 if (_log.isDebugEnabled()) {
5753 _log.debug(msg.toString());
5754 }
5755
5756 throw new NoSuchOrganizationException(msg.toString());
5757 }
5758
5759 return organization;
5760 }
5761
5762
5769 @Override
5770 public Organization fetchByC_N(long companyId, String name) {
5771 return fetchByC_N(companyId, name, true);
5772 }
5773
5774
5782 @Override
5783 public Organization fetchByC_N(long companyId, String name,
5784 boolean retrieveFromCache) {
5785 Object[] finderArgs = new Object[] { companyId, name };
5786
5787 Object result = null;
5788
5789 if (retrieveFromCache) {
5790 result = finderCache.getResult(FINDER_PATH_FETCH_BY_C_N,
5791 finderArgs, this);
5792 }
5793
5794 if (result instanceof Organization) {
5795 Organization organization = (Organization)result;
5796
5797 if ((companyId != organization.getCompanyId()) ||
5798 !Objects.equals(name, organization.getName())) {
5799 result = null;
5800 }
5801 }
5802
5803 if (result == null) {
5804 StringBundler query = new StringBundler(4);
5805
5806 query.append(_SQL_SELECT_ORGANIZATION_WHERE);
5807
5808 query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
5809
5810 boolean bindName = false;
5811
5812 if (name == null) {
5813 query.append(_FINDER_COLUMN_C_N_NAME_1);
5814 }
5815 else if (name.equals(StringPool.BLANK)) {
5816 query.append(_FINDER_COLUMN_C_N_NAME_3);
5817 }
5818 else {
5819 bindName = true;
5820
5821 query.append(_FINDER_COLUMN_C_N_NAME_2);
5822 }
5823
5824 String sql = query.toString();
5825
5826 Session session = null;
5827
5828 try {
5829 session = openSession();
5830
5831 Query q = session.createQuery(sql);
5832
5833 QueryPos qPos = QueryPos.getInstance(q);
5834
5835 qPos.add(companyId);
5836
5837 if (bindName) {
5838 qPos.add(name);
5839 }
5840
5841 List<Organization> list = q.list();
5842
5843 if (list.isEmpty()) {
5844 finderCache.putResult(FINDER_PATH_FETCH_BY_C_N, finderArgs,
5845 list);
5846 }
5847 else {
5848 Organization organization = list.get(0);
5849
5850 result = organization;
5851
5852 cacheResult(organization);
5853
5854 if ((organization.getCompanyId() != companyId) ||
5855 (organization.getName() == null) ||
5856 !organization.getName().equals(name)) {
5857 finderCache.putResult(FINDER_PATH_FETCH_BY_C_N,
5858 finderArgs, organization);
5859 }
5860 }
5861 }
5862 catch (Exception e) {
5863 finderCache.removeResult(FINDER_PATH_FETCH_BY_C_N, finderArgs);
5864
5865 throw processException(e);
5866 }
5867 finally {
5868 closeSession(session);
5869 }
5870 }
5871
5872 if (result instanceof List<?>) {
5873 return null;
5874 }
5875 else {
5876 return (Organization)result;
5877 }
5878 }
5879
5880
5887 @Override
5888 public Organization removeByC_N(long companyId, String name)
5889 throws NoSuchOrganizationException {
5890 Organization organization = findByC_N(companyId, name);
5891
5892 return remove(organization);
5893 }
5894
5895
5902 @Override
5903 public int countByC_N(long companyId, String name) {
5904 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_N;
5905
5906 Object[] finderArgs = new Object[] { companyId, name };
5907
5908 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
5909
5910 if (count == null) {
5911 StringBundler query = new StringBundler(3);
5912
5913 query.append(_SQL_COUNT_ORGANIZATION_WHERE);
5914
5915 query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
5916
5917 boolean bindName = false;
5918
5919 if (name == null) {
5920 query.append(_FINDER_COLUMN_C_N_NAME_1);
5921 }
5922 else if (name.equals(StringPool.BLANK)) {
5923 query.append(_FINDER_COLUMN_C_N_NAME_3);
5924 }
5925 else {
5926 bindName = true;
5927
5928 query.append(_FINDER_COLUMN_C_N_NAME_2);
5929 }
5930
5931 String sql = query.toString();
5932
5933 Session session = null;
5934
5935 try {
5936 session = openSession();
5937
5938 Query q = session.createQuery(sql);
5939
5940 QueryPos qPos = QueryPos.getInstance(q);
5941
5942 qPos.add(companyId);
5943
5944 if (bindName) {
5945 qPos.add(name);
5946 }
5947
5948 count = (Long)q.uniqueResult();
5949
5950 finderCache.putResult(finderPath, finderArgs, count);
5951 }
5952 catch (Exception e) {
5953 finderCache.removeResult(finderPath, finderArgs);
5954
5955 throw processException(e);
5956 }
5957 finally {
5958 closeSession(session);
5959 }
5960 }
5961
5962 return count.intValue();
5963 }
5964
5965 private static final String _FINDER_COLUMN_C_N_COMPANYID_2 = "organization.companyId = ? AND ";
5966 private static final String _FINDER_COLUMN_C_N_NAME_1 = "organization.name IS NULL";
5967 private static final String _FINDER_COLUMN_C_N_NAME_2 = "organization.name = ?";
5968 private static final String _FINDER_COLUMN_C_N_NAME_3 = "(organization.name IS NULL OR organization.name = '')";
5969 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_O_C_P = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
5970 OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
5971 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByO_C_P",
5972 new String[] {
5973 Long.class.getName(), Long.class.getName(), Long.class.getName(),
5974
5975 Integer.class.getName(), Integer.class.getName(),
5976 OrderByComparator.class.getName()
5977 });
5978 public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_O_C_P = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
5979 OrganizationModelImpl.FINDER_CACHE_ENABLED, Long.class,
5980 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByO_C_P",
5981 new String[] {
5982 Long.class.getName(), Long.class.getName(), Long.class.getName()
5983 });
5984
5985
5993 @Override
5994 public List<Organization> findByO_C_P(long organizationId, long companyId,
5995 long parentOrganizationId) {
5996 return findByO_C_P(organizationId, companyId, parentOrganizationId,
5997 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
5998 }
5999
6000
6014 @Override
6015 public List<Organization> findByO_C_P(long organizationId, long companyId,
6016 long parentOrganizationId, int start, int end) {
6017 return findByO_C_P(organizationId, companyId, parentOrganizationId,
6018 start, end, null);
6019 }
6020
6021
6036 @Override
6037 public List<Organization> findByO_C_P(long organizationId, long companyId,
6038 long parentOrganizationId, int start, int end,
6039 OrderByComparator<Organization> orderByComparator) {
6040 return findByO_C_P(organizationId, companyId, parentOrganizationId,
6041 start, end, orderByComparator, true);
6042 }
6043
6044
6060 @Override
6061 public List<Organization> findByO_C_P(long organizationId, long companyId,
6062 long parentOrganizationId, int start, int end,
6063 OrderByComparator<Organization> orderByComparator,
6064 boolean retrieveFromCache) {
6065 boolean pagination = true;
6066 FinderPath finderPath = null;
6067 Object[] finderArgs = null;
6068
6069 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_O_C_P;
6070 finderArgs = new Object[] {
6071 organizationId, companyId, parentOrganizationId,
6072
6073 start, end, orderByComparator
6074 };
6075
6076 List<Organization> list = null;
6077
6078 if (retrieveFromCache) {
6079 list = (List<Organization>)finderCache.getResult(finderPath,
6080 finderArgs, this);
6081
6082 if ((list != null) && !list.isEmpty()) {
6083 for (Organization organization : list) {
6084 if ((organizationId >= organization.getOrganizationId()) ||
6085 (companyId != organization.getCompanyId()) ||
6086 (parentOrganizationId != organization.getParentOrganizationId())) {
6087 list = null;
6088
6089 break;
6090 }
6091 }
6092 }
6093 }
6094
6095 if (list == null) {
6096 StringBundler query = null;
6097
6098 if (orderByComparator != null) {
6099 query = new StringBundler(5 +
6100 (orderByComparator.getOrderByFields().length * 2));
6101 }
6102 else {
6103 query = new StringBundler(5);
6104 }
6105
6106 query.append(_SQL_SELECT_ORGANIZATION_WHERE);
6107
6108 query.append(_FINDER_COLUMN_O_C_P_ORGANIZATIONID_2);
6109
6110 query.append(_FINDER_COLUMN_O_C_P_COMPANYID_2);
6111
6112 query.append(_FINDER_COLUMN_O_C_P_PARENTORGANIZATIONID_2);
6113
6114 if (orderByComparator != null) {
6115 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6116 orderByComparator);
6117 }
6118 else
6119 if (pagination) {
6120 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
6121 }
6122
6123 String sql = query.toString();
6124
6125 Session session = null;
6126
6127 try {
6128 session = openSession();
6129
6130 Query q = session.createQuery(sql);
6131
6132 QueryPos qPos = QueryPos.getInstance(q);
6133
6134 qPos.add(organizationId);
6135
6136 qPos.add(companyId);
6137
6138 qPos.add(parentOrganizationId);
6139
6140 if (!pagination) {
6141 list = (List<Organization>)QueryUtil.list(q, getDialect(),
6142 start, end, false);
6143
6144 Collections.sort(list);
6145
6146 list = Collections.unmodifiableList(list);
6147 }
6148 else {
6149 list = (List<Organization>)QueryUtil.list(q, getDialect(),
6150 start, end);
6151 }
6152
6153 cacheResult(list);
6154
6155 finderCache.putResult(finderPath, finderArgs, list);
6156 }
6157 catch (Exception e) {
6158 finderCache.removeResult(finderPath, finderArgs);
6159
6160 throw processException(e);
6161 }
6162 finally {
6163 closeSession(session);
6164 }
6165 }
6166
6167 return list;
6168 }
6169
6170
6180 @Override
6181 public Organization findByO_C_P_First(long organizationId, long companyId,
6182 long parentOrganizationId,
6183 OrderByComparator<Organization> orderByComparator)
6184 throws NoSuchOrganizationException {
6185 Organization organization = fetchByO_C_P_First(organizationId,
6186 companyId, parentOrganizationId, orderByComparator);
6187
6188 if (organization != null) {
6189 return organization;
6190 }
6191
6192 StringBundler msg = new StringBundler(8);
6193
6194 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6195
6196 msg.append("organizationId=");
6197 msg.append(organizationId);
6198
6199 msg.append(", companyId=");
6200 msg.append(companyId);
6201
6202 msg.append(", parentOrganizationId=");
6203 msg.append(parentOrganizationId);
6204
6205 msg.append(StringPool.CLOSE_CURLY_BRACE);
6206
6207 throw new NoSuchOrganizationException(msg.toString());
6208 }
6209
6210
6219 @Override
6220 public Organization fetchByO_C_P_First(long organizationId, long companyId,
6221 long parentOrganizationId,
6222 OrderByComparator<Organization> orderByComparator) {
6223 List<Organization> list = findByO_C_P(organizationId, companyId,
6224 parentOrganizationId, 0, 1, orderByComparator);
6225
6226 if (!list.isEmpty()) {
6227 return list.get(0);
6228 }
6229
6230 return null;
6231 }
6232
6233
6243 @Override
6244 public Organization findByO_C_P_Last(long organizationId, long companyId,
6245 long parentOrganizationId,
6246 OrderByComparator<Organization> orderByComparator)
6247 throws NoSuchOrganizationException {
6248 Organization organization = fetchByO_C_P_Last(organizationId,
6249 companyId, parentOrganizationId, orderByComparator);
6250
6251 if (organization != null) {
6252 return organization;
6253 }
6254
6255 StringBundler msg = new StringBundler(8);
6256
6257 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6258
6259 msg.append("organizationId=");
6260 msg.append(organizationId);
6261
6262 msg.append(", companyId=");
6263 msg.append(companyId);
6264
6265 msg.append(", parentOrganizationId=");
6266 msg.append(parentOrganizationId);
6267
6268 msg.append(StringPool.CLOSE_CURLY_BRACE);
6269
6270 throw new NoSuchOrganizationException(msg.toString());
6271 }
6272
6273
6282 @Override
6283 public Organization fetchByO_C_P_Last(long organizationId, long companyId,
6284 long parentOrganizationId,
6285 OrderByComparator<Organization> orderByComparator) {
6286 int count = countByO_C_P(organizationId, companyId, parentOrganizationId);
6287
6288 if (count == 0) {
6289 return null;
6290 }
6291
6292 List<Organization> list = findByO_C_P(organizationId, companyId,
6293 parentOrganizationId, count - 1, count, orderByComparator);
6294
6295 if (!list.isEmpty()) {
6296 return list.get(0);
6297 }
6298
6299 return null;
6300 }
6301
6302
6310 @Override
6311 public List<Organization> filterFindByO_C_P(long organizationId,
6312 long companyId, long parentOrganizationId) {
6313 return filterFindByO_C_P(organizationId, companyId,
6314 parentOrganizationId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
6315 }
6316
6317
6331 @Override
6332 public List<Organization> filterFindByO_C_P(long organizationId,
6333 long companyId, long parentOrganizationId, int start, int end) {
6334 return filterFindByO_C_P(organizationId, companyId,
6335 parentOrganizationId, start, end, null);
6336 }
6337
6338
6353 @Override
6354 public List<Organization> filterFindByO_C_P(long organizationId,
6355 long companyId, long parentOrganizationId, int start, int end,
6356 OrderByComparator<Organization> orderByComparator) {
6357 if (!InlineSQLHelperUtil.isEnabled(companyId, 0)) {
6358 return findByO_C_P(organizationId, companyId, parentOrganizationId,
6359 start, end, orderByComparator);
6360 }
6361
6362 StringBundler query = null;
6363
6364 if (orderByComparator != null) {
6365 query = new StringBundler(5 +
6366 (orderByComparator.getOrderByFields().length * 2));
6367 }
6368 else {
6369 query = new StringBundler(6);
6370 }
6371
6372 if (getDB().isSupportsInlineDistinct()) {
6373 query.append(_FILTER_SQL_SELECT_ORGANIZATION_WHERE);
6374 }
6375 else {
6376 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1);
6377 }
6378
6379 query.append(_FINDER_COLUMN_O_C_P_ORGANIZATIONID_2);
6380
6381 query.append(_FINDER_COLUMN_O_C_P_COMPANYID_2);
6382
6383 query.append(_FINDER_COLUMN_O_C_P_PARENTORGANIZATIONID_2);
6384
6385 if (!getDB().isSupportsInlineDistinct()) {
6386 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2);
6387 }
6388
6389 if (orderByComparator != null) {
6390 if (getDB().isSupportsInlineDistinct()) {
6391 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6392 orderByComparator, true);
6393 }
6394 else {
6395 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
6396 orderByComparator, true);
6397 }
6398 }
6399 else {
6400 if (getDB().isSupportsInlineDistinct()) {
6401 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
6402 }
6403 else {
6404 query.append(OrganizationModelImpl.ORDER_BY_SQL);
6405 }
6406 }
6407
6408 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6409 Organization.class.getName(),
6410 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
6411
6412 Session session = null;
6413
6414 try {
6415 session = openSession();
6416
6417 SQLQuery q = session.createSynchronizedSQLQuery(sql);
6418
6419 if (getDB().isSupportsInlineDistinct()) {
6420 q.addEntity(_FILTER_ENTITY_ALIAS, OrganizationImpl.class);
6421 }
6422 else {
6423 q.addEntity(_FILTER_ENTITY_TABLE, OrganizationImpl.class);
6424 }
6425
6426 QueryPos qPos = QueryPos.getInstance(q);
6427
6428 qPos.add(organizationId);
6429
6430 qPos.add(companyId);
6431
6432 qPos.add(parentOrganizationId);
6433
6434 return (List<Organization>)QueryUtil.list(q, getDialect(), start,
6435 end);
6436 }
6437 catch (Exception e) {
6438 throw processException(e);
6439 }
6440 finally {
6441 closeSession(session);
6442 }
6443 }
6444
6445
6452 @Override
6453 public void removeByO_C_P(long organizationId, long companyId,
6454 long parentOrganizationId) {
6455 for (Organization organization : findByO_C_P(organizationId, companyId,
6456 parentOrganizationId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
6457 remove(organization);
6458 }
6459 }
6460
6461
6469 @Override
6470 public int countByO_C_P(long organizationId, long companyId,
6471 long parentOrganizationId) {
6472 FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_O_C_P;
6473
6474 Object[] finderArgs = new Object[] {
6475 organizationId, companyId, parentOrganizationId
6476 };
6477
6478 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
6479
6480 if (count == null) {
6481 StringBundler query = new StringBundler(4);
6482
6483 query.append(_SQL_COUNT_ORGANIZATION_WHERE);
6484
6485 query.append(_FINDER_COLUMN_O_C_P_ORGANIZATIONID_2);
6486
6487 query.append(_FINDER_COLUMN_O_C_P_COMPANYID_2);
6488
6489 query.append(_FINDER_COLUMN_O_C_P_PARENTORGANIZATIONID_2);
6490
6491 String sql = query.toString();
6492
6493 Session session = null;
6494
6495 try {
6496 session = openSession();
6497
6498 Query q = session.createQuery(sql);
6499
6500 QueryPos qPos = QueryPos.getInstance(q);
6501
6502 qPos.add(organizationId);
6503
6504 qPos.add(companyId);
6505
6506 qPos.add(parentOrganizationId);
6507
6508 count = (Long)q.uniqueResult();
6509
6510 finderCache.putResult(finderPath, finderArgs, count);
6511 }
6512 catch (Exception e) {
6513 finderCache.removeResult(finderPath, finderArgs);
6514
6515 throw processException(e);
6516 }
6517 finally {
6518 closeSession(session);
6519 }
6520 }
6521
6522 return count.intValue();
6523 }
6524
6525
6533 @Override
6534 public int filterCountByO_C_P(long organizationId, long companyId,
6535 long parentOrganizationId) {
6536 if (!InlineSQLHelperUtil.isEnabled(companyId, 0)) {
6537 return countByO_C_P(organizationId, companyId, parentOrganizationId);
6538 }
6539
6540 StringBundler query = new StringBundler(4);
6541
6542 query.append(_FILTER_SQL_COUNT_ORGANIZATION_WHERE);
6543
6544 query.append(_FINDER_COLUMN_O_C_P_ORGANIZATIONID_2);
6545
6546 query.append(_FINDER_COLUMN_O_C_P_COMPANYID_2);
6547
6548 query.append(_FINDER_COLUMN_O_C_P_PARENTORGANIZATIONID_2);
6549
6550 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6551 Organization.class.getName(),
6552 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
6553
6554 Session session = null;
6555
6556 try {
6557 session = openSession();
6558
6559 SQLQuery q = session.createSynchronizedSQLQuery(sql);
6560
6561 q.addScalar(COUNT_COLUMN_NAME,
6562 com.liferay.portal.kernel.dao.orm.Type.LONG);
6563
6564 QueryPos qPos = QueryPos.getInstance(q);
6565
6566 qPos.add(organizationId);
6567
6568 qPos.add(companyId);
6569
6570 qPos.add(parentOrganizationId);
6571
6572 Long count = (Long)q.uniqueResult();
6573
6574 return count.intValue();
6575 }
6576 catch (Exception e) {
6577 throw processException(e);
6578 }
6579 finally {
6580 closeSession(session);
6581 }
6582 }
6583
6584 private static final String _FINDER_COLUMN_O_C_P_ORGANIZATIONID_2 = "organization.organizationId > ? AND ";
6585 private static final String _FINDER_COLUMN_O_C_P_COMPANYID_2 = "organization.companyId = ? AND ";
6586 private static final String _FINDER_COLUMN_O_C_P_PARENTORGANIZATIONID_2 = "organization.parentOrganizationId = ?";
6587
6588 public OrganizationPersistenceImpl() {
6589 setModelClass(Organization.class);
6590 }
6591
6592
6597 @Override
6598 public void cacheResult(Organization organization) {
6599 entityCache.putResult(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
6600 OrganizationImpl.class, organization.getPrimaryKey(), organization);
6601
6602 finderCache.putResult(FINDER_PATH_FETCH_BY_C_N,
6603 new Object[] { organization.getCompanyId(), organization.getName() },
6604 organization);
6605
6606 organization.resetOriginalValues();
6607 }
6608
6609
6614 @Override
6615 public void cacheResult(List<Organization> organizations) {
6616 for (Organization organization : organizations) {
6617 if (entityCache.getResult(
6618 OrganizationModelImpl.ENTITY_CACHE_ENABLED,
6619 OrganizationImpl.class, organization.getPrimaryKey()) == null) {
6620 cacheResult(organization);
6621 }
6622 else {
6623 organization.resetOriginalValues();
6624 }
6625 }
6626 }
6627
6628
6635 @Override
6636 public void clearCache() {
6637 entityCache.clearCache(OrganizationImpl.class);
6638
6639 finderCache.clearCache(FINDER_CLASS_NAME_ENTITY);
6640 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
6641 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
6642 }
6643
6644
6651 @Override
6652 public void clearCache(Organization organization) {
6653 entityCache.removeResult(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
6654 OrganizationImpl.class, organization.getPrimaryKey());
6655
6656 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
6657 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
6658
6659 clearUniqueFindersCache((OrganizationModelImpl)organization);
6660 }
6661
6662 @Override
6663 public void clearCache(List<Organization> organizations) {
6664 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
6665 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
6666
6667 for (Organization organization : organizations) {
6668 entityCache.removeResult(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
6669 OrganizationImpl.class, organization.getPrimaryKey());
6670
6671 clearUniqueFindersCache((OrganizationModelImpl)organization);
6672 }
6673 }
6674
6675 protected void cacheUniqueFindersCache(
6676 OrganizationModelImpl organizationModelImpl, boolean isNew) {
6677 if (isNew) {
6678 Object[] args = new Object[] {
6679 organizationModelImpl.getCompanyId(),
6680 organizationModelImpl.getName()
6681 };
6682
6683 finderCache.putResult(FINDER_PATH_COUNT_BY_C_N, args,
6684 Long.valueOf(1));
6685 finderCache.putResult(FINDER_PATH_FETCH_BY_C_N, args,
6686 organizationModelImpl);
6687 }
6688 else {
6689 if ((organizationModelImpl.getColumnBitmask() &
6690 FINDER_PATH_FETCH_BY_C_N.getColumnBitmask()) != 0) {
6691 Object[] args = new Object[] {
6692 organizationModelImpl.getCompanyId(),
6693 organizationModelImpl.getName()
6694 };
6695
6696 finderCache.putResult(FINDER_PATH_COUNT_BY_C_N, args,
6697 Long.valueOf(1));
6698 finderCache.putResult(FINDER_PATH_FETCH_BY_C_N, args,
6699 organizationModelImpl);
6700 }
6701 }
6702 }
6703
6704 protected void clearUniqueFindersCache(
6705 OrganizationModelImpl organizationModelImpl) {
6706 Object[] args = new Object[] {
6707 organizationModelImpl.getCompanyId(),
6708 organizationModelImpl.getName()
6709 };
6710
6711 finderCache.removeResult(FINDER_PATH_COUNT_BY_C_N, args);
6712 finderCache.removeResult(FINDER_PATH_FETCH_BY_C_N, args);
6713
6714 if ((organizationModelImpl.getColumnBitmask() &
6715 FINDER_PATH_FETCH_BY_C_N.getColumnBitmask()) != 0) {
6716 args = new Object[] {
6717 organizationModelImpl.getOriginalCompanyId(),
6718 organizationModelImpl.getOriginalName()
6719 };
6720
6721 finderCache.removeResult(FINDER_PATH_COUNT_BY_C_N, args);
6722 finderCache.removeResult(FINDER_PATH_FETCH_BY_C_N, args);
6723 }
6724 }
6725
6726
6732 @Override
6733 public Organization create(long organizationId) {
6734 Organization organization = new OrganizationImpl();
6735
6736 organization.setNew(true);
6737 organization.setPrimaryKey(organizationId);
6738
6739 String uuid = PortalUUIDUtil.generate();
6740
6741 organization.setUuid(uuid);
6742
6743 organization.setCompanyId(companyProvider.getCompanyId());
6744
6745 return organization;
6746 }
6747
6748
6755 @Override
6756 public Organization remove(long organizationId)
6757 throws NoSuchOrganizationException {
6758 return remove((Serializable)organizationId);
6759 }
6760
6761
6768 @Override
6769 public Organization remove(Serializable primaryKey)
6770 throws NoSuchOrganizationException {
6771 Session session = null;
6772
6773 try {
6774 session = openSession();
6775
6776 Organization organization = (Organization)session.get(OrganizationImpl.class,
6777 primaryKey);
6778
6779 if (organization == null) {
6780 if (_log.isDebugEnabled()) {
6781 _log.debug(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
6782 }
6783
6784 throw new NoSuchOrganizationException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
6785 primaryKey);
6786 }
6787
6788 return remove(organization);
6789 }
6790 catch (NoSuchOrganizationException nsee) {
6791 throw nsee;
6792 }
6793 catch (Exception e) {
6794 throw processException(e);
6795 }
6796 finally {
6797 closeSession(session);
6798 }
6799 }
6800
6801 @Override
6802 protected Organization removeImpl(Organization organization) {
6803 organization = toUnwrappedModel(organization);
6804
6805 organizationToGroupTableMapper.deleteLeftPrimaryKeyTableMappings(organization.getPrimaryKey());
6806
6807 organizationToUserTableMapper.deleteLeftPrimaryKeyTableMappings(organization.getPrimaryKey());
6808
6809 Session session = null;
6810
6811 try {
6812 session = openSession();
6813
6814 if (!session.contains(organization)) {
6815 organization = (Organization)session.get(OrganizationImpl.class,
6816 organization.getPrimaryKeyObj());
6817 }
6818
6819 if (organization != null) {
6820 session.delete(organization);
6821 }
6822 }
6823 catch (Exception e) {
6824 throw processException(e);
6825 }
6826 finally {
6827 closeSession(session);
6828 }
6829
6830 if (organization != null) {
6831 clearCache(organization);
6832 }
6833
6834 return organization;
6835 }
6836
6837 @Override
6838 public Organization updateImpl(Organization organization) {
6839 organization = toUnwrappedModel(organization);
6840
6841 boolean isNew = organization.isNew();
6842
6843 OrganizationModelImpl organizationModelImpl = (OrganizationModelImpl)organization;
6844
6845 if (Validator.isNull(organization.getUuid())) {
6846 String uuid = PortalUUIDUtil.generate();
6847
6848 organization.setUuid(uuid);
6849 }
6850
6851 ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();
6852
6853 Date now = new Date();
6854
6855 if (isNew && (organization.getCreateDate() == null)) {
6856 if (serviceContext == null) {
6857 organization.setCreateDate(now);
6858 }
6859 else {
6860 organization.setCreateDate(serviceContext.getCreateDate(now));
6861 }
6862 }
6863
6864 if (!organizationModelImpl.hasSetModifiedDate()) {
6865 if (serviceContext == null) {
6866 organization.setModifiedDate(now);
6867 }
6868 else {
6869 organization.setModifiedDate(serviceContext.getModifiedDate(now));
6870 }
6871 }
6872
6873 Session session = null;
6874
6875 try {
6876 session = openSession();
6877
6878 if (organization.isNew()) {
6879 session.save(organization);
6880
6881 organization.setNew(false);
6882 }
6883 else {
6884 organization = (Organization)session.merge(organization);
6885 }
6886 }
6887 catch (Exception e) {
6888 throw processException(e);
6889 }
6890 finally {
6891 closeSession(session);
6892 }
6893
6894 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
6895
6896 if (isNew || !OrganizationModelImpl.COLUMN_BITMASK_ENABLED) {
6897 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
6898 }
6899
6900 else {
6901 if ((organizationModelImpl.getColumnBitmask() &
6902 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
6903 Object[] args = new Object[] {
6904 organizationModelImpl.getOriginalUuid()
6905 };
6906
6907 finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
6908 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
6909 args);
6910
6911 args = new Object[] { organizationModelImpl.getUuid() };
6912
6913 finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
6914 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
6915 args);
6916 }
6917
6918 if ((organizationModelImpl.getColumnBitmask() &
6919 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
6920 Object[] args = new Object[] {
6921 organizationModelImpl.getOriginalUuid(),
6922 organizationModelImpl.getOriginalCompanyId()
6923 };
6924
6925 finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
6926 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
6927 args);
6928
6929 args = new Object[] {
6930 organizationModelImpl.getUuid(),
6931 organizationModelImpl.getCompanyId()
6932 };
6933
6934 finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
6935 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
6936 args);
6937 }
6938
6939 if ((organizationModelImpl.getColumnBitmask() &
6940 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
6941 Object[] args = new Object[] {
6942 organizationModelImpl.getOriginalCompanyId()
6943 };
6944
6945 finderCache.removeResult(FINDER_PATH_COUNT_BY_COMPANYID, args);
6946 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
6947 args);
6948
6949 args = new Object[] { organizationModelImpl.getCompanyId() };
6950
6951 finderCache.removeResult(FINDER_PATH_COUNT_BY_COMPANYID, args);
6952 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
6953 args);
6954 }
6955
6956 if ((organizationModelImpl.getColumnBitmask() &
6957 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LOCATIONS.getColumnBitmask()) != 0) {
6958 Object[] args = new Object[] {
6959 organizationModelImpl.getOriginalCompanyId()
6960 };
6961
6962 finderCache.removeResult(FINDER_PATH_COUNT_BY_LOCATIONS, args);
6963 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LOCATIONS,
6964 args);
6965
6966 args = new Object[] { organizationModelImpl.getCompanyId() };
6967
6968 finderCache.removeResult(FINDER_PATH_COUNT_BY_LOCATIONS, args);
6969 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LOCATIONS,
6970 args);
6971 }
6972
6973 if ((organizationModelImpl.getColumnBitmask() &
6974 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P.getColumnBitmask()) != 0) {
6975 Object[] args = new Object[] {
6976 organizationModelImpl.getOriginalCompanyId(),
6977 organizationModelImpl.getOriginalParentOrganizationId()
6978 };
6979
6980 finderCache.removeResult(FINDER_PATH_COUNT_BY_C_P, args);
6981 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P,
6982 args);
6983
6984 args = new Object[] {
6985 organizationModelImpl.getCompanyId(),
6986 organizationModelImpl.getParentOrganizationId()
6987 };
6988
6989 finderCache.removeResult(FINDER_PATH_COUNT_BY_C_P, args);
6990 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P,
6991 args);
6992 }
6993 }
6994
6995 entityCache.putResult(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
6996 OrganizationImpl.class, organization.getPrimaryKey(), organization,
6997 false);
6998
6999 clearUniqueFindersCache(organizationModelImpl);
7000 cacheUniqueFindersCache(organizationModelImpl, isNew);
7001
7002 organization.resetOriginalValues();
7003
7004 return organization;
7005 }
7006
7007 protected Organization toUnwrappedModel(Organization organization) {
7008 if (organization instanceof OrganizationImpl) {
7009 return organization;
7010 }
7011
7012 OrganizationImpl organizationImpl = new OrganizationImpl();
7013
7014 organizationImpl.setNew(organization.isNew());
7015 organizationImpl.setPrimaryKey(organization.getPrimaryKey());
7016
7017 organizationImpl.setMvccVersion(organization.getMvccVersion());
7018 organizationImpl.setUuid(organization.getUuid());
7019 organizationImpl.setOrganizationId(organization.getOrganizationId());
7020 organizationImpl.setCompanyId(organization.getCompanyId());
7021 organizationImpl.setUserId(organization.getUserId());
7022 organizationImpl.setUserName(organization.getUserName());
7023 organizationImpl.setCreateDate(organization.getCreateDate());
7024 organizationImpl.setModifiedDate(organization.getModifiedDate());
7025 organizationImpl.setParentOrganizationId(organization.getParentOrganizationId());
7026 organizationImpl.setTreePath(organization.getTreePath());
7027 organizationImpl.setName(organization.getName());
7028 organizationImpl.setType(organization.getType());
7029 organizationImpl.setRecursable(organization.isRecursable());
7030 organizationImpl.setRegionId(organization.getRegionId());
7031 organizationImpl.setCountryId(organization.getCountryId());
7032 organizationImpl.setStatusId(organization.getStatusId());
7033 organizationImpl.setComments(organization.getComments());
7034 organizationImpl.setLogoId(organization.getLogoId());
7035
7036 return organizationImpl;
7037 }
7038
7039
7046 @Override
7047 public Organization findByPrimaryKey(Serializable primaryKey)
7048 throws NoSuchOrganizationException {
7049 Organization organization = fetchByPrimaryKey(primaryKey);
7050
7051 if (organization == null) {
7052 if (_log.isDebugEnabled()) {
7053 _log.debug(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
7054 }
7055
7056 throw new NoSuchOrganizationException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
7057 primaryKey);
7058 }
7059
7060 return organization;
7061 }
7062
7063
7070 @Override
7071 public Organization findByPrimaryKey(long organizationId)
7072 throws NoSuchOrganizationException {
7073 return findByPrimaryKey((Serializable)organizationId);
7074 }
7075
7076
7082 @Override
7083 public Organization fetchByPrimaryKey(Serializable primaryKey) {
7084 Organization organization = (Organization)entityCache.getResult(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
7085 OrganizationImpl.class, primaryKey);
7086
7087 if (organization == _nullOrganization) {
7088 return null;
7089 }
7090
7091 if (organization == null) {
7092 Session session = null;
7093
7094 try {
7095 session = openSession();
7096
7097 organization = (Organization)session.get(OrganizationImpl.class,
7098 primaryKey);
7099
7100 if (organization != null) {
7101 cacheResult(organization);
7102 }
7103 else {
7104 entityCache.putResult(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
7105 OrganizationImpl.class, primaryKey, _nullOrganization);
7106 }
7107 }
7108 catch (Exception e) {
7109 entityCache.removeResult(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
7110 OrganizationImpl.class, primaryKey);
7111
7112 throw processException(e);
7113 }
7114 finally {
7115 closeSession(session);
7116 }
7117 }
7118
7119 return organization;
7120 }
7121
7122
7128 @Override
7129 public Organization fetchByPrimaryKey(long organizationId) {
7130 return fetchByPrimaryKey((Serializable)organizationId);
7131 }
7132
7133 @Override
7134 public Map<Serializable, Organization> fetchByPrimaryKeys(
7135 Set<Serializable> primaryKeys) {
7136 if (primaryKeys.isEmpty()) {
7137 return Collections.emptyMap();
7138 }
7139
7140 Map<Serializable, Organization> map = new HashMap<Serializable, Organization>();
7141
7142 if (primaryKeys.size() == 1) {
7143 Iterator<Serializable> iterator = primaryKeys.iterator();
7144
7145 Serializable primaryKey = iterator.next();
7146
7147 Organization organization = fetchByPrimaryKey(primaryKey);
7148
7149 if (organization != null) {
7150 map.put(primaryKey, organization);
7151 }
7152
7153 return map;
7154 }
7155
7156 Set<Serializable> uncachedPrimaryKeys = null;
7157
7158 for (Serializable primaryKey : primaryKeys) {
7159 Organization organization = (Organization)entityCache.getResult(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
7160 OrganizationImpl.class, primaryKey);
7161
7162 if (organization == null) {
7163 if (uncachedPrimaryKeys == null) {
7164 uncachedPrimaryKeys = new HashSet<Serializable>();
7165 }
7166
7167 uncachedPrimaryKeys.add(primaryKey);
7168 }
7169 else {
7170 map.put(primaryKey, organization);
7171 }
7172 }
7173
7174 if (uncachedPrimaryKeys == null) {
7175 return map;
7176 }
7177
7178 StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
7179 1);
7180
7181 query.append(_SQL_SELECT_ORGANIZATION_WHERE_PKS_IN);
7182
7183 for (Serializable primaryKey : uncachedPrimaryKeys) {
7184 query.append(String.valueOf(primaryKey));
7185
7186 query.append(StringPool.COMMA);
7187 }
7188
7189 query.setIndex(query.index() - 1);
7190
7191 query.append(StringPool.CLOSE_PARENTHESIS);
7192
7193 String sql = query.toString();
7194
7195 Session session = null;
7196
7197 try {
7198 session = openSession();
7199
7200 Query q = session.createQuery(sql);
7201
7202 for (Organization organization : (List<Organization>)q.list()) {
7203 map.put(organization.getPrimaryKeyObj(), organization);
7204
7205 cacheResult(organization);
7206
7207 uncachedPrimaryKeys.remove(organization.getPrimaryKeyObj());
7208 }
7209
7210 for (Serializable primaryKey : uncachedPrimaryKeys) {
7211 entityCache.putResult(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
7212 OrganizationImpl.class, primaryKey, _nullOrganization);
7213 }
7214 }
7215 catch (Exception e) {
7216 throw processException(e);
7217 }
7218 finally {
7219 closeSession(session);
7220 }
7221
7222 return map;
7223 }
7224
7225
7230 @Override
7231 public List<Organization> findAll() {
7232 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
7233 }
7234
7235
7246 @Override
7247 public List<Organization> findAll(int start, int end) {
7248 return findAll(start, end, null);
7249 }
7250
7251
7263 @Override
7264 public List<Organization> findAll(int start, int end,
7265 OrderByComparator<Organization> orderByComparator) {
7266 return findAll(start, end, orderByComparator, true);
7267 }
7268
7269
7282 @Override
7283 public List<Organization> findAll(int start, int end,
7284 OrderByComparator<Organization> orderByComparator,
7285 boolean retrieveFromCache) {
7286 boolean pagination = true;
7287 FinderPath finderPath = null;
7288 Object[] finderArgs = null;
7289
7290 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7291 (orderByComparator == null)) {
7292 pagination = false;
7293 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
7294 finderArgs = FINDER_ARGS_EMPTY;
7295 }
7296 else {
7297 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
7298 finderArgs = new Object[] { start, end, orderByComparator };
7299 }
7300
7301 List<Organization> list = null;
7302
7303 if (retrieveFromCache) {
7304 list = (List<Organization>)finderCache.getResult(finderPath,
7305 finderArgs, this);
7306 }
7307
7308 if (list == null) {
7309 StringBundler query = null;
7310 String sql = null;
7311
7312 if (orderByComparator != null) {
7313 query = new StringBundler(2 +
7314 (orderByComparator.getOrderByFields().length * 2));
7315
7316 query.append(_SQL_SELECT_ORGANIZATION);
7317
7318 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7319 orderByComparator);
7320
7321 sql = query.toString();
7322 }
7323 else {
7324 sql = _SQL_SELECT_ORGANIZATION;
7325
7326 if (pagination) {
7327 sql = sql.concat(OrganizationModelImpl.ORDER_BY_JPQL);
7328 }
7329 }
7330
7331 Session session = null;
7332
7333 try {
7334 session = openSession();
7335
7336 Query q = session.createQuery(sql);
7337
7338 if (!pagination) {
7339 list = (List<Organization>)QueryUtil.list(q, getDialect(),
7340 start, end, false);
7341
7342 Collections.sort(list);
7343
7344 list = Collections.unmodifiableList(list);
7345 }
7346 else {
7347 list = (List<Organization>)QueryUtil.list(q, getDialect(),
7348 start, end);
7349 }
7350
7351 cacheResult(list);
7352
7353 finderCache.putResult(finderPath, finderArgs, list);
7354 }
7355 catch (Exception e) {
7356 finderCache.removeResult(finderPath, finderArgs);
7357
7358 throw processException(e);
7359 }
7360 finally {
7361 closeSession(session);
7362 }
7363 }
7364
7365 return list;
7366 }
7367
7368
7372 @Override
7373 public void removeAll() {
7374 for (Organization organization : findAll()) {
7375 remove(organization);
7376 }
7377 }
7378
7379
7384 @Override
7385 public int countAll() {
7386 Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL,
7387 FINDER_ARGS_EMPTY, this);
7388
7389 if (count == null) {
7390 Session session = null;
7391
7392 try {
7393 session = openSession();
7394
7395 Query q = session.createQuery(_SQL_COUNT_ORGANIZATION);
7396
7397 count = (Long)q.uniqueResult();
7398
7399 finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY,
7400 count);
7401 }
7402 catch (Exception e) {
7403 finderCache.removeResult(FINDER_PATH_COUNT_ALL,
7404 FINDER_ARGS_EMPTY);
7405
7406 throw processException(e);
7407 }
7408 finally {
7409 closeSession(session);
7410 }
7411 }
7412
7413 return count.intValue();
7414 }
7415
7416
7422 @Override
7423 public long[] getGroupPrimaryKeys(long pk) {
7424 long[] pks = organizationToGroupTableMapper.getRightPrimaryKeys(pk);
7425
7426 return pks.clone();
7427 }
7428
7429
7435 @Override
7436 public List<com.liferay.portal.kernel.model.Group> getGroups(long pk) {
7437 return getGroups(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
7438 }
7439
7440
7452 @Override
7453 public List<com.liferay.portal.kernel.model.Group> getGroups(long pk,
7454 int start, int end) {
7455 return getGroups(pk, start, end, null);
7456 }
7457
7458
7471 @Override
7472 public List<com.liferay.portal.kernel.model.Group> getGroups(long pk,
7473 int start, int end,
7474 OrderByComparator<com.liferay.portal.kernel.model.Group> orderByComparator) {
7475 return organizationToGroupTableMapper.getRightBaseModels(pk, start,
7476 end, orderByComparator);
7477 }
7478
7479
7485 @Override
7486 public int getGroupsSize(long pk) {
7487 long[] pks = organizationToGroupTableMapper.getRightPrimaryKeys(pk);
7488
7489 return pks.length;
7490 }
7491
7492
7499 @Override
7500 public boolean containsGroup(long pk, long groupPK) {
7501 return organizationToGroupTableMapper.containsTableMapping(pk, groupPK);
7502 }
7503
7504
7510 @Override
7511 public boolean containsGroups(long pk) {
7512 if (getGroupsSize(pk) > 0) {
7513 return true;
7514 }
7515 else {
7516 return false;
7517 }
7518 }
7519
7520
7526 @Override
7527 public void addGroup(long pk, long groupPK) {
7528 Organization organization = fetchByPrimaryKey(pk);
7529
7530 if (organization == null) {
7531 organizationToGroupTableMapper.addTableMapping(companyProvider.getCompanyId(),
7532 pk, groupPK);
7533 }
7534 else {
7535 organizationToGroupTableMapper.addTableMapping(organization.getCompanyId(),
7536 pk, groupPK);
7537 }
7538 }
7539
7540
7546 @Override
7547 public void addGroup(long pk, com.liferay.portal.kernel.model.Group group) {
7548 Organization organization = fetchByPrimaryKey(pk);
7549
7550 if (organization == null) {
7551 organizationToGroupTableMapper.addTableMapping(companyProvider.getCompanyId(),
7552 pk, group.getPrimaryKey());
7553 }
7554 else {
7555 organizationToGroupTableMapper.addTableMapping(organization.getCompanyId(),
7556 pk, group.getPrimaryKey());
7557 }
7558 }
7559
7560
7566 @Override
7567 public void addGroups(long pk, long[] groupPKs) {
7568 long companyId = 0;
7569
7570 Organization organization = fetchByPrimaryKey(pk);
7571
7572 if (organization == null) {
7573 companyId = companyProvider.getCompanyId();
7574 }
7575 else {
7576 companyId = organization.getCompanyId();
7577 }
7578
7579 for (long groupPK : groupPKs) {
7580 organizationToGroupTableMapper.addTableMapping(companyId, pk,
7581 groupPK);
7582 }
7583 }
7584
7585
7591 @Override
7592 public void addGroups(long pk,
7593 List<com.liferay.portal.kernel.model.Group> groups) {
7594 long companyId = 0;
7595
7596 Organization organization = fetchByPrimaryKey(pk);
7597
7598 if (organization == null) {
7599 companyId = companyProvider.getCompanyId();
7600 }
7601 else {
7602 companyId = organization.getCompanyId();
7603 }
7604
7605 for (com.liferay.portal.kernel.model.Group group : groups) {
7606 organizationToGroupTableMapper.addTableMapping(companyId, pk,
7607 group.getPrimaryKey());
7608 }
7609 }
7610
7611
7616 @Override
7617 public void clearGroups(long pk) {
7618 organizationToGroupTableMapper.deleteLeftPrimaryKeyTableMappings(pk);
7619 }
7620
7621
7627 @Override
7628 public void removeGroup(long pk, long groupPK) {
7629 organizationToGroupTableMapper.deleteTableMapping(pk, groupPK);
7630 }
7631
7632
7638 @Override
7639 public void removeGroup(long pk, com.liferay.portal.kernel.model.Group group) {
7640 organizationToGroupTableMapper.deleteTableMapping(pk,
7641 group.getPrimaryKey());
7642 }
7643
7644
7650 @Override
7651 public void removeGroups(long pk, long[] groupPKs) {
7652 for (long groupPK : groupPKs) {
7653 organizationToGroupTableMapper.deleteTableMapping(pk, groupPK);
7654 }
7655 }
7656
7657
7663 @Override
7664 public void removeGroups(long pk,
7665 List<com.liferay.portal.kernel.model.Group> groups) {
7666 for (com.liferay.portal.kernel.model.Group group : groups) {
7667 organizationToGroupTableMapper.deleteTableMapping(pk,
7668 group.getPrimaryKey());
7669 }
7670 }
7671
7672
7678 @Override
7679 public void setGroups(long pk, long[] groupPKs) {
7680 Set<Long> newGroupPKsSet = SetUtil.fromArray(groupPKs);
7681 Set<Long> oldGroupPKsSet = SetUtil.fromArray(organizationToGroupTableMapper.getRightPrimaryKeys(
7682 pk));
7683
7684 Set<Long> removeGroupPKsSet = new HashSet<Long>(oldGroupPKsSet);
7685
7686 removeGroupPKsSet.removeAll(newGroupPKsSet);
7687
7688 for (long removeGroupPK : removeGroupPKsSet) {
7689 organizationToGroupTableMapper.deleteTableMapping(pk, removeGroupPK);
7690 }
7691
7692 newGroupPKsSet.removeAll(oldGroupPKsSet);
7693
7694 long companyId = 0;
7695
7696 Organization organization = fetchByPrimaryKey(pk);
7697
7698 if (organization == null) {
7699 companyId = companyProvider.getCompanyId();
7700 }
7701 else {
7702 companyId = organization.getCompanyId();
7703 }
7704
7705 for (long newGroupPK : newGroupPKsSet) {
7706 organizationToGroupTableMapper.addTableMapping(companyId, pk,
7707 newGroupPK);
7708 }
7709 }
7710
7711
7717 @Override
7718 public void setGroups(long pk,
7719 List<com.liferay.portal.kernel.model.Group> groups) {
7720 try {
7721 long[] groupPKs = new long[groups.size()];
7722
7723 for (int i = 0; i < groups.size(); i++) {
7724 com.liferay.portal.kernel.model.Group group = groups.get(i);
7725
7726 groupPKs[i] = group.getPrimaryKey();
7727 }
7728
7729 setGroups(pk, groupPKs);
7730 }
7731 catch (Exception e) {
7732 throw processException(e);
7733 }
7734 }
7735
7736
7742 @Override
7743 public long[] getUserPrimaryKeys(long pk) {
7744 long[] pks = organizationToUserTableMapper.getRightPrimaryKeys(pk);
7745
7746 return pks.clone();
7747 }
7748
7749
7755 @Override
7756 public List<com.liferay.portal.kernel.model.User> getUsers(long pk) {
7757 return getUsers(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
7758 }
7759
7760
7772 @Override
7773 public List<com.liferay.portal.kernel.model.User> getUsers(long pk,
7774 int start, int end) {
7775 return getUsers(pk, start, end, null);
7776 }
7777
7778
7791 @Override
7792 public List<com.liferay.portal.kernel.model.User> getUsers(long pk,
7793 int start, int end,
7794 OrderByComparator<com.liferay.portal.kernel.model.User> orderByComparator) {
7795 return organizationToUserTableMapper.getRightBaseModels(pk, start, end,
7796 orderByComparator);
7797 }
7798
7799
7805 @Override
7806 public int getUsersSize(long pk) {
7807 long[] pks = organizationToUserTableMapper.getRightPrimaryKeys(pk);
7808
7809 return pks.length;
7810 }
7811
7812
7819 @Override
7820 public boolean containsUser(long pk, long userPK) {
7821 return organizationToUserTableMapper.containsTableMapping(pk, userPK);
7822 }
7823
7824
7830 @Override
7831 public boolean containsUsers(long pk) {
7832 if (getUsersSize(pk) > 0) {
7833 return true;
7834 }
7835 else {
7836 return false;
7837 }
7838 }
7839
7840
7846 @Override
7847 public void addUser(long pk, long userPK) {
7848 Organization organization = fetchByPrimaryKey(pk);
7849
7850 if (organization == null) {
7851 organizationToUserTableMapper.addTableMapping(companyProvider.getCompanyId(),
7852 pk, userPK);
7853 }
7854 else {
7855 organizationToUserTableMapper.addTableMapping(organization.getCompanyId(),
7856 pk, userPK);
7857 }
7858 }
7859
7860
7866 @Override
7867 public void addUser(long pk, com.liferay.portal.kernel.model.User user) {
7868 Organization organization = fetchByPrimaryKey(pk);
7869
7870 if (organization == null) {
7871 organizationToUserTableMapper.addTableMapping(companyProvider.getCompanyId(),
7872 pk, user.getPrimaryKey());
7873 }
7874 else {
7875 organizationToUserTableMapper.addTableMapping(organization.getCompanyId(),
7876 pk, user.getPrimaryKey());
7877 }
7878 }
7879
7880
7886 @Override
7887 public void addUsers(long pk, long[] userPKs) {
7888 long companyId = 0;
7889
7890 Organization organization = fetchByPrimaryKey(pk);
7891
7892 if (organization == null) {
7893 companyId = companyProvider.getCompanyId();
7894 }
7895 else {
7896 companyId = organization.getCompanyId();
7897 }
7898
7899 for (long userPK : userPKs) {
7900 organizationToUserTableMapper.addTableMapping(companyId, pk, userPK);
7901 }
7902 }
7903
7904
7910 @Override
7911 public void addUsers(long pk,
7912 List<com.liferay.portal.kernel.model.User> users) {
7913 long companyId = 0;
7914
7915 Organization organization = fetchByPrimaryKey(pk);
7916
7917 if (organization == null) {
7918 companyId = companyProvider.getCompanyId();
7919 }
7920 else {
7921 companyId = organization.getCompanyId();
7922 }
7923
7924 for (com.liferay.portal.kernel.model.User user : users) {
7925 organizationToUserTableMapper.addTableMapping(companyId, pk,
7926 user.getPrimaryKey());
7927 }
7928 }
7929
7930
7935 @Override
7936 public void clearUsers(long pk) {
7937 organizationToUserTableMapper.deleteLeftPrimaryKeyTableMappings(pk);
7938 }
7939
7940
7946 @Override
7947 public void removeUser(long pk, long userPK) {
7948 organizationToUserTableMapper.deleteTableMapping(pk, userPK);
7949 }
7950
7951
7957 @Override
7958 public void removeUser(long pk, com.liferay.portal.kernel.model.User user) {
7959 organizationToUserTableMapper.deleteTableMapping(pk,
7960 user.getPrimaryKey());
7961 }
7962
7963
7969 @Override
7970 public void removeUsers(long pk, long[] userPKs) {
7971 for (long userPK : userPKs) {
7972 organizationToUserTableMapper.deleteTableMapping(pk, userPK);
7973 }
7974 }
7975
7976
7982 @Override
7983 public void removeUsers(long pk,
7984 List<com.liferay.portal.kernel.model.User> users) {
7985 for (com.liferay.portal.kernel.model.User user : users) {
7986 organizationToUserTableMapper.deleteTableMapping(pk,
7987 user.getPrimaryKey());
7988 }
7989 }
7990
7991
7997 @Override
7998 public void setUsers(long pk, long[] userPKs) {
7999 Set<Long> newUserPKsSet = SetUtil.fromArray(userPKs);
8000 Set<Long> oldUserPKsSet = SetUtil.fromArray(organizationToUserTableMapper.getRightPrimaryKeys(
8001 pk));
8002
8003 Set<Long> removeUserPKsSet = new HashSet<Long>(oldUserPKsSet);
8004
8005 removeUserPKsSet.removeAll(newUserPKsSet);
8006
8007 for (long removeUserPK : removeUserPKsSet) {
8008 organizationToUserTableMapper.deleteTableMapping(pk, removeUserPK);
8009 }
8010
8011 newUserPKsSet.removeAll(oldUserPKsSet);
8012
8013 long companyId = 0;
8014
8015 Organization organization = fetchByPrimaryKey(pk);
8016
8017 if (organization == null) {
8018 companyId = companyProvider.getCompanyId();
8019 }
8020 else {
8021 companyId = organization.getCompanyId();
8022 }
8023
8024 for (long newUserPK : newUserPKsSet) {
8025 organizationToUserTableMapper.addTableMapping(companyId, pk,
8026 newUserPK);
8027 }
8028 }
8029
8030
8036 @Override
8037 public void setUsers(long pk,
8038 List<com.liferay.portal.kernel.model.User> users) {
8039 try {
8040 long[] userPKs = new long[users.size()];
8041
8042 for (int i = 0; i < users.size(); i++) {
8043 com.liferay.portal.kernel.model.User user = users.get(i);
8044
8045 userPKs[i] = user.getPrimaryKey();
8046 }
8047
8048 setUsers(pk, userPKs);
8049 }
8050 catch (Exception e) {
8051 throw processException(e);
8052 }
8053 }
8054
8055 @Override
8056 public Set<String> getBadColumnNames() {
8057 return _badColumnNames;
8058 }
8059
8060 @Override
8061 protected Map<String, Integer> getTableColumnsMap() {
8062 return OrganizationModelImpl.TABLE_COLUMNS_MAP;
8063 }
8064
8065
8068 public void afterPropertiesSet() {
8069 organizationToGroupTableMapper = TableMapperFactory.getTableMapper("Groups_Orgs",
8070 "companyId", "organizationId", "groupId", this, groupPersistence);
8071
8072 organizationToUserTableMapper = TableMapperFactory.getTableMapper("Users_Orgs",
8073 "companyId", "organizationId", "userId", this, userPersistence);
8074 }
8075
8076 public void destroy() {
8077 entityCache.removeCache(OrganizationImpl.class.getName());
8078 finderCache.removeCache(FINDER_CLASS_NAME_ENTITY);
8079 finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
8080 finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
8081
8082 TableMapperFactory.removeTableMapper("Groups_Orgs");
8083 TableMapperFactory.removeTableMapper("Users_Orgs");
8084 }
8085
8086 @BeanReference(type = CompanyProviderWrapper.class)
8087 protected CompanyProvider companyProvider;
8088 protected EntityCache entityCache = EntityCacheUtil.getEntityCache();
8089 protected FinderCache finderCache = FinderCacheUtil.getFinderCache();
8090 @BeanReference(type = GroupPersistence.class)
8091 protected GroupPersistence groupPersistence;
8092 protected TableMapper<Organization, com.liferay.portal.kernel.model.Group> organizationToGroupTableMapper;
8093 @BeanReference(type = UserPersistence.class)
8094 protected UserPersistence userPersistence;
8095 protected TableMapper<Organization, com.liferay.portal.kernel.model.User> organizationToUserTableMapper;
8096 private static final String _SQL_SELECT_ORGANIZATION = "SELECT organization FROM Organization organization";
8097 private static final String _SQL_SELECT_ORGANIZATION_WHERE_PKS_IN = "SELECT organization FROM Organization organization WHERE organizationId IN (";
8098 private static final String _SQL_SELECT_ORGANIZATION_WHERE = "SELECT organization FROM Organization organization WHERE ";
8099 private static final String _SQL_COUNT_ORGANIZATION = "SELECT COUNT(organization) FROM Organization organization";
8100 private static final String _SQL_COUNT_ORGANIZATION_WHERE = "SELECT COUNT(organization) FROM Organization organization WHERE ";
8101 private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "organization.organizationId";
8102 private static final String _FILTER_SQL_SELECT_ORGANIZATION_WHERE = "SELECT DISTINCT {organization.*} FROM Organization_ organization WHERE ";
8103 private static final String _FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1 =
8104 "SELECT {Organization_.*} FROM (SELECT DISTINCT organization.organizationId FROM Organization_ organization WHERE ";
8105 private static final String _FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2 =
8106 ") TEMP_TABLE INNER JOIN Organization_ ON TEMP_TABLE.organizationId = Organization_.organizationId";
8107 private static final String _FILTER_SQL_COUNT_ORGANIZATION_WHERE = "SELECT COUNT(DISTINCT organization.organizationId) AS COUNT_VALUE FROM Organization_ organization WHERE ";
8108 private static final String _FILTER_ENTITY_ALIAS = "organization";
8109 private static final String _FILTER_ENTITY_TABLE = "Organization_";
8110 private static final String _ORDER_BY_ENTITY_ALIAS = "organization.";
8111 private static final String _ORDER_BY_ENTITY_TABLE = "Organization_.";
8112 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Organization exists with the primary key ";
8113 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Organization exists with the key {";
8114 private static final Log _log = LogFactoryUtil.getLog(OrganizationPersistenceImpl.class);
8115 private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
8116 "uuid", "type"
8117 });
8118 private static final Organization _nullOrganization = new OrganizationImpl() {
8119 @Override
8120 public Object clone() {
8121 return this;
8122 }
8123
8124 @Override
8125 public CacheModel<Organization> toCacheModel() {
8126 return _nullOrganizationCacheModel;
8127 }
8128 };
8129
8130 private static final CacheModel<Organization> _nullOrganizationCacheModel = new NullCacheModel();
8131
8132 private static class NullCacheModel implements CacheModel<Organization>,
8133 MVCCModel {
8134 @Override
8135 public long getMvccVersion() {
8136 return -1;
8137 }
8138
8139 @Override
8140 public void setMvccVersion(long mvccVersion) {
8141 }
8142
8143 @Override
8144 public Organization toEntityModel() {
8145 return _nullOrganization;
8146 }
8147 }
8148 }