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