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