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