001
014
015 package com.liferay.portal.service.persistence.impl;
016
017 import aQute.bnd.annotation.ProviderType;
018
019 import com.liferay.portal.NoSuchOrganizationException;
020 import com.liferay.portal.kernel.bean.BeanReference;
021 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
023 import com.liferay.portal.kernel.dao.orm.FinderPath;
024 import com.liferay.portal.kernel.dao.orm.Query;
025 import com.liferay.portal.kernel.dao.orm.QueryPos;
026 import com.liferay.portal.kernel.dao.orm.QueryUtil;
027 import com.liferay.portal.kernel.dao.orm.SQLQuery;
028 import com.liferay.portal.kernel.dao.orm.Session;
029 import com.liferay.portal.kernel.log.Log;
030 import com.liferay.portal.kernel.log.LogFactoryUtil;
031 import com.liferay.portal.kernel.util.CharPool;
032 import com.liferay.portal.kernel.util.OrderByComparator;
033 import com.liferay.portal.kernel.util.SetUtil;
034 import com.liferay.portal.kernel.util.StringBundler;
035 import com.liferay.portal.kernel.util.StringPool;
036 import com.liferay.portal.kernel.util.StringUtil;
037 import com.liferay.portal.kernel.util.Validator;
038 import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
039 import com.liferay.portal.model.CacheModel;
040 import com.liferay.portal.model.MVCCModel;
041 import com.liferay.portal.model.Organization;
042 import com.liferay.portal.model.impl.OrganizationImpl;
043 import com.liferay.portal.model.impl.OrganizationModelImpl;
044 import com.liferay.portal.security.permission.InlineSQLHelperUtil;
045 import com.liferay.portal.service.ServiceContext;
046 import com.liferay.portal.service.ServiceContextThreadLocal;
047 import com.liferay.portal.service.persistence.GroupPersistence;
048 import com.liferay.portal.service.persistence.OrganizationPersistence;
049 import com.liferay.portal.service.persistence.UserPersistence;
050
051 import java.io.Serializable;
052
053 import java.util.Collections;
054 import java.util.Date;
055 import java.util.HashMap;
056 import java.util.HashSet;
057 import java.util.Iterator;
058 import java.util.List;
059 import java.util.Map;
060 import java.util.Set;
061
062
074 @ProviderType
075 public class OrganizationPersistenceImpl extends BasePersistenceImpl<Organization>
076 implements OrganizationPersistence {
077
082 public static final String FINDER_CLASS_NAME_ENTITY = OrganizationImpl.class.getName();
083 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
084 ".List1";
085 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
086 ".List2";
087 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
088 OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
089 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
090 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
091 OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
092 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
093 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
094 OrganizationModelImpl.FINDER_CACHE_ENABLED, Long.class,
095 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
096 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
097 OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
098 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
099 new String[] {
100 String.class.getName(),
101
102 Integer.class.getName(), Integer.class.getName(),
103 OrderByComparator.class.getName()
104 });
105 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
106 OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
107 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
108 new String[] { String.class.getName() },
109 OrganizationModelImpl.UUID_COLUMN_BITMASK |
110 OrganizationModelImpl.NAME_COLUMN_BITMASK);
111 public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
112 OrganizationModelImpl.FINDER_CACHE_ENABLED, Long.class,
113 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
114 new String[] { String.class.getName() });
115
116
122 @Override
123 public List<Organization> findByUuid(String uuid) {
124 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
125 }
126
127
139 @Override
140 public List<Organization> findByUuid(String uuid, int start, int end) {
141 return findByUuid(uuid, start, end, null);
142 }
143
144
157 @Override
158 public List<Organization> findByUuid(String uuid, int start, int end,
159 OrderByComparator<Organization> orderByComparator) {
160 boolean pagination = true;
161 FinderPath finderPath = null;
162 Object[] finderArgs = null;
163
164 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
165 (orderByComparator == null)) {
166 pagination = false;
167 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
168 finderArgs = new Object[] { uuid };
169 }
170 else {
171 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
172 finderArgs = new Object[] { uuid, start, end, orderByComparator };
173 }
174
175 List<Organization> list = (List<Organization>)FinderCacheUtil.getResult(finderPath,
176 finderArgs, this);
177
178 if ((list != null) && !list.isEmpty()) {
179 for (Organization organization : list) {
180 if (!Validator.equals(uuid, organization.getUuid())) {
181 list = null;
182
183 break;
184 }
185 }
186 }
187
188 if (list == null) {
189 StringBundler query = null;
190
191 if (orderByComparator != null) {
192 query = new StringBundler(3 +
193 (orderByComparator.getOrderByFields().length * 3));
194 }
195 else {
196 query = new StringBundler(3);
197 }
198
199 query.append(_SQL_SELECT_ORGANIZATION_WHERE);
200
201 boolean bindUuid = false;
202
203 if (uuid == null) {
204 query.append(_FINDER_COLUMN_UUID_UUID_1);
205 }
206 else if (uuid.equals(StringPool.BLANK)) {
207 query.append(_FINDER_COLUMN_UUID_UUID_3);
208 }
209 else {
210 bindUuid = true;
211
212 query.append(_FINDER_COLUMN_UUID_UUID_2);
213 }
214
215 if (orderByComparator != null) {
216 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
217 orderByComparator);
218 }
219 else
220 if (pagination) {
221 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
222 }
223
224 String sql = query.toString();
225
226 Session session = null;
227
228 try {
229 session = openSession();
230
231 Query q = session.createQuery(sql);
232
233 QueryPos qPos = QueryPos.getInstance(q);
234
235 if (bindUuid) {
236 qPos.add(uuid);
237 }
238
239 if (!pagination) {
240 list = (List<Organization>)QueryUtil.list(q, getDialect(),
241 start, end, false);
242
243 Collections.sort(list);
244
245 list = Collections.unmodifiableList(list);
246 }
247 else {
248 list = (List<Organization>)QueryUtil.list(q, getDialect(),
249 start, end);
250 }
251
252 cacheResult(list);
253
254 FinderCacheUtil.putResult(finderPath, finderArgs, list);
255 }
256 catch (Exception e) {
257 FinderCacheUtil.removeResult(finderPath, finderArgs);
258
259 throw processException(e);
260 }
261 finally {
262 closeSession(session);
263 }
264 }
265
266 return list;
267 }
268
269
277 @Override
278 public Organization findByUuid_First(String uuid,
279 OrderByComparator<Organization> orderByComparator)
280 throws NoSuchOrganizationException {
281 Organization organization = fetchByUuid_First(uuid, orderByComparator);
282
283 if (organization != null) {
284 return organization;
285 }
286
287 StringBundler msg = new StringBundler(4);
288
289 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
290
291 msg.append("uuid=");
292 msg.append(uuid);
293
294 msg.append(StringPool.CLOSE_CURLY_BRACE);
295
296 throw new NoSuchOrganizationException(msg.toString());
297 }
298
299
306 @Override
307 public Organization fetchByUuid_First(String uuid,
308 OrderByComparator<Organization> orderByComparator) {
309 List<Organization> list = findByUuid(uuid, 0, 1, orderByComparator);
310
311 if (!list.isEmpty()) {
312 return list.get(0);
313 }
314
315 return null;
316 }
317
318
326 @Override
327 public Organization findByUuid_Last(String uuid,
328 OrderByComparator<Organization> orderByComparator)
329 throws NoSuchOrganizationException {
330 Organization organization = fetchByUuid_Last(uuid, orderByComparator);
331
332 if (organization != null) {
333 return organization;
334 }
335
336 StringBundler msg = new StringBundler(4);
337
338 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
339
340 msg.append("uuid=");
341 msg.append(uuid);
342
343 msg.append(StringPool.CLOSE_CURLY_BRACE);
344
345 throw new NoSuchOrganizationException(msg.toString());
346 }
347
348
355 @Override
356 public Organization fetchByUuid_Last(String uuid,
357 OrderByComparator<Organization> orderByComparator) {
358 int count = countByUuid(uuid);
359
360 if (count == 0) {
361 return null;
362 }
363
364 List<Organization> list = findByUuid(uuid, count - 1, count,
365 orderByComparator);
366
367 if (!list.isEmpty()) {
368 return list.get(0);
369 }
370
371 return null;
372 }
373
374
383 @Override
384 public Organization[] findByUuid_PrevAndNext(long organizationId,
385 String uuid, OrderByComparator<Organization> orderByComparator)
386 throws NoSuchOrganizationException {
387 Organization organization = findByPrimaryKey(organizationId);
388
389 Session session = null;
390
391 try {
392 session = openSession();
393
394 Organization[] array = new OrganizationImpl[3];
395
396 array[0] = getByUuid_PrevAndNext(session, organization, uuid,
397 orderByComparator, true);
398
399 array[1] = organization;
400
401 array[2] = getByUuid_PrevAndNext(session, organization, uuid,
402 orderByComparator, false);
403
404 return array;
405 }
406 catch (Exception e) {
407 throw processException(e);
408 }
409 finally {
410 closeSession(session);
411 }
412 }
413
414 protected Organization getByUuid_PrevAndNext(Session session,
415 Organization organization, String uuid,
416 OrderByComparator<Organization> orderByComparator, boolean previous) {
417 StringBundler query = null;
418
419 if (orderByComparator != null) {
420 query = new StringBundler(6 +
421 (orderByComparator.getOrderByFields().length * 6));
422 }
423 else {
424 query = new StringBundler(3);
425 }
426
427 query.append(_SQL_SELECT_ORGANIZATION_WHERE);
428
429 boolean bindUuid = false;
430
431 if (uuid == null) {
432 query.append(_FINDER_COLUMN_UUID_UUID_1);
433 }
434 else if (uuid.equals(StringPool.BLANK)) {
435 query.append(_FINDER_COLUMN_UUID_UUID_3);
436 }
437 else {
438 bindUuid = true;
439
440 query.append(_FINDER_COLUMN_UUID_UUID_2);
441 }
442
443 if (orderByComparator != null) {
444 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
445
446 if (orderByConditionFields.length > 0) {
447 query.append(WHERE_AND);
448 }
449
450 for (int i = 0; i < orderByConditionFields.length; i++) {
451 query.append(_ORDER_BY_ENTITY_ALIAS);
452 query.append(orderByConditionFields[i]);
453
454 if ((i + 1) < orderByConditionFields.length) {
455 if (orderByComparator.isAscending() ^ previous) {
456 query.append(WHERE_GREATER_THAN_HAS_NEXT);
457 }
458 else {
459 query.append(WHERE_LESSER_THAN_HAS_NEXT);
460 }
461 }
462 else {
463 if (orderByComparator.isAscending() ^ previous) {
464 query.append(WHERE_GREATER_THAN);
465 }
466 else {
467 query.append(WHERE_LESSER_THAN);
468 }
469 }
470 }
471
472 query.append(ORDER_BY_CLAUSE);
473
474 String[] orderByFields = orderByComparator.getOrderByFields();
475
476 for (int i = 0; i < orderByFields.length; i++) {
477 query.append(_ORDER_BY_ENTITY_ALIAS);
478 query.append(orderByFields[i]);
479
480 if ((i + 1) < orderByFields.length) {
481 if (orderByComparator.isAscending() ^ previous) {
482 query.append(ORDER_BY_ASC_HAS_NEXT);
483 }
484 else {
485 query.append(ORDER_BY_DESC_HAS_NEXT);
486 }
487 }
488 else {
489 if (orderByComparator.isAscending() ^ previous) {
490 query.append(ORDER_BY_ASC);
491 }
492 else {
493 query.append(ORDER_BY_DESC);
494 }
495 }
496 }
497 }
498 else {
499 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
500 }
501
502 String sql = query.toString();
503
504 Query q = session.createQuery(sql);
505
506 q.setFirstResult(0);
507 q.setMaxResults(2);
508
509 QueryPos qPos = QueryPos.getInstance(q);
510
511 if (bindUuid) {
512 qPos.add(uuid);
513 }
514
515 if (orderByComparator != null) {
516 Object[] values = orderByComparator.getOrderByConditionValues(organization);
517
518 for (Object value : values) {
519 qPos.add(value);
520 }
521 }
522
523 List<Organization> list = q.list();
524
525 if (list.size() == 2) {
526 return list.get(1);
527 }
528 else {
529 return null;
530 }
531 }
532
533
539 @Override
540 public List<Organization> filterFindByUuid(String uuid) {
541 return filterFindByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
542 }
543
544
556 @Override
557 public List<Organization> filterFindByUuid(String uuid, int start, int end) {
558 return filterFindByUuid(uuid, start, end, null);
559 }
560
561
574 @Override
575 public List<Organization> filterFindByUuid(String uuid, int start, int end,
576 OrderByComparator<Organization> orderByComparator) {
577 if (!InlineSQLHelperUtil.isEnabled()) {
578 return findByUuid(uuid, start, end, orderByComparator);
579 }
580
581 StringBundler query = null;
582
583 if (orderByComparator != null) {
584 query = new StringBundler(3 +
585 (orderByComparator.getOrderByFields().length * 3));
586 }
587 else {
588 query = new StringBundler(3);
589 }
590
591 if (getDB().isSupportsInlineDistinct()) {
592 query.append(_FILTER_SQL_SELECT_ORGANIZATION_WHERE);
593 }
594 else {
595 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1);
596 }
597
598 boolean bindUuid = false;
599
600 if (uuid == null) {
601 query.append(_FINDER_COLUMN_UUID_UUID_1_SQL);
602 }
603 else if (uuid.equals(StringPool.BLANK)) {
604 query.append(_FINDER_COLUMN_UUID_UUID_3_SQL);
605 }
606 else {
607 bindUuid = true;
608
609 query.append(_FINDER_COLUMN_UUID_UUID_2_SQL);
610 }
611
612 if (!getDB().isSupportsInlineDistinct()) {
613 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2);
614 }
615
616 if (orderByComparator != null) {
617 if (getDB().isSupportsInlineDistinct()) {
618 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
619 orderByComparator, true);
620 }
621 else {
622 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
623 orderByComparator, true);
624 }
625 }
626 else {
627 if (getDB().isSupportsInlineDistinct()) {
628 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
629 }
630 else {
631 query.append(OrganizationModelImpl.ORDER_BY_SQL);
632 }
633 }
634
635 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
636 Organization.class.getName(),
637 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
638
639 Session session = null;
640
641 try {
642 session = openSession();
643
644 SQLQuery q = session.createSynchronizedSQLQuery(sql);
645
646 if (getDB().isSupportsInlineDistinct()) {
647 q.addEntity(_FILTER_ENTITY_ALIAS, OrganizationImpl.class);
648 }
649 else {
650 q.addEntity(_FILTER_ENTITY_TABLE, OrganizationImpl.class);
651 }
652
653 QueryPos qPos = QueryPos.getInstance(q);
654
655 if (bindUuid) {
656 qPos.add(uuid);
657 }
658
659 return (List<Organization>)QueryUtil.list(q, getDialect(), start,
660 end);
661 }
662 catch (Exception e) {
663 throw processException(e);
664 }
665 finally {
666 closeSession(session);
667 }
668 }
669
670
679 @Override
680 public Organization[] filterFindByUuid_PrevAndNext(long organizationId,
681 String uuid, OrderByComparator<Organization> orderByComparator)
682 throws NoSuchOrganizationException {
683 if (!InlineSQLHelperUtil.isEnabled()) {
684 return findByUuid_PrevAndNext(organizationId, uuid,
685 orderByComparator);
686 }
687
688 Organization organization = findByPrimaryKey(organizationId);
689
690 Session session = null;
691
692 try {
693 session = openSession();
694
695 Organization[] array = new OrganizationImpl[3];
696
697 array[0] = filterGetByUuid_PrevAndNext(session, organization, uuid,
698 orderByComparator, true);
699
700 array[1] = organization;
701
702 array[2] = filterGetByUuid_PrevAndNext(session, organization, uuid,
703 orderByComparator, false);
704
705 return array;
706 }
707 catch (Exception e) {
708 throw processException(e);
709 }
710 finally {
711 closeSession(session);
712 }
713 }
714
715 protected Organization filterGetByUuid_PrevAndNext(Session session,
716 Organization organization, String uuid,
717 OrderByComparator<Organization> orderByComparator, boolean previous) {
718 StringBundler query = null;
719
720 if (orderByComparator != null) {
721 query = new StringBundler(6 +
722 (orderByComparator.getOrderByFields().length * 6));
723 }
724 else {
725 query = new StringBundler(3);
726 }
727
728 if (getDB().isSupportsInlineDistinct()) {
729 query.append(_FILTER_SQL_SELECT_ORGANIZATION_WHERE);
730 }
731 else {
732 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1);
733 }
734
735 boolean bindUuid = false;
736
737 if (uuid == null) {
738 query.append(_FINDER_COLUMN_UUID_UUID_1_SQL);
739 }
740 else if (uuid.equals(StringPool.BLANK)) {
741 query.append(_FINDER_COLUMN_UUID_UUID_3_SQL);
742 }
743 else {
744 bindUuid = true;
745
746 query.append(_FINDER_COLUMN_UUID_UUID_2_SQL);
747 }
748
749 if (!getDB().isSupportsInlineDistinct()) {
750 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2);
751 }
752
753 if (orderByComparator != null) {
754 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
755
756 if (orderByConditionFields.length > 0) {
757 query.append(WHERE_AND);
758 }
759
760 for (int i = 0; i < orderByConditionFields.length; i++) {
761 if (getDB().isSupportsInlineDistinct()) {
762 query.append(_ORDER_BY_ENTITY_ALIAS);
763 }
764 else {
765 query.append(_ORDER_BY_ENTITY_TABLE);
766 }
767
768 query.append(orderByConditionFields[i]);
769
770 if ((i + 1) < orderByConditionFields.length) {
771 if (orderByComparator.isAscending() ^ previous) {
772 query.append(WHERE_GREATER_THAN_HAS_NEXT);
773 }
774 else {
775 query.append(WHERE_LESSER_THAN_HAS_NEXT);
776 }
777 }
778 else {
779 if (orderByComparator.isAscending() ^ previous) {
780 query.append(WHERE_GREATER_THAN);
781 }
782 else {
783 query.append(WHERE_LESSER_THAN);
784 }
785 }
786 }
787
788 query.append(ORDER_BY_CLAUSE);
789
790 String[] orderByFields = orderByComparator.getOrderByFields();
791
792 for (int i = 0; i < orderByFields.length; i++) {
793 if (getDB().isSupportsInlineDistinct()) {
794 query.append(_ORDER_BY_ENTITY_ALIAS);
795 }
796 else {
797 query.append(_ORDER_BY_ENTITY_TABLE);
798 }
799
800 query.append(orderByFields[i]);
801
802 if ((i + 1) < orderByFields.length) {
803 if (orderByComparator.isAscending() ^ previous) {
804 query.append(ORDER_BY_ASC_HAS_NEXT);
805 }
806 else {
807 query.append(ORDER_BY_DESC_HAS_NEXT);
808 }
809 }
810 else {
811 if (orderByComparator.isAscending() ^ previous) {
812 query.append(ORDER_BY_ASC);
813 }
814 else {
815 query.append(ORDER_BY_DESC);
816 }
817 }
818 }
819 }
820 else {
821 if (getDB().isSupportsInlineDistinct()) {
822 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
823 }
824 else {
825 query.append(OrganizationModelImpl.ORDER_BY_SQL);
826 }
827 }
828
829 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
830 Organization.class.getName(),
831 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
832
833 SQLQuery q = session.createSynchronizedSQLQuery(sql);
834
835 q.setFirstResult(0);
836 q.setMaxResults(2);
837
838 if (getDB().isSupportsInlineDistinct()) {
839 q.addEntity(_FILTER_ENTITY_ALIAS, OrganizationImpl.class);
840 }
841 else {
842 q.addEntity(_FILTER_ENTITY_TABLE, OrganizationImpl.class);
843 }
844
845 QueryPos qPos = QueryPos.getInstance(q);
846
847 if (bindUuid) {
848 qPos.add(uuid);
849 }
850
851 if (orderByComparator != null) {
852 Object[] values = orderByComparator.getOrderByConditionValues(organization);
853
854 for (Object value : values) {
855 qPos.add(value);
856 }
857 }
858
859 List<Organization> list = q.list();
860
861 if (list.size() == 2) {
862 return list.get(1);
863 }
864 else {
865 return null;
866 }
867 }
868
869
874 @Override
875 public void removeByUuid(String uuid) {
876 for (Organization organization : findByUuid(uuid, QueryUtil.ALL_POS,
877 QueryUtil.ALL_POS, null)) {
878 remove(organization);
879 }
880 }
881
882
888 @Override
889 public int countByUuid(String uuid) {
890 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
891
892 Object[] finderArgs = new Object[] { uuid };
893
894 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
895 this);
896
897 if (count == null) {
898 StringBundler query = new StringBundler(2);
899
900 query.append(_SQL_COUNT_ORGANIZATION_WHERE);
901
902 boolean bindUuid = false;
903
904 if (uuid == null) {
905 query.append(_FINDER_COLUMN_UUID_UUID_1);
906 }
907 else if (uuid.equals(StringPool.BLANK)) {
908 query.append(_FINDER_COLUMN_UUID_UUID_3);
909 }
910 else {
911 bindUuid = true;
912
913 query.append(_FINDER_COLUMN_UUID_UUID_2);
914 }
915
916 String sql = query.toString();
917
918 Session session = null;
919
920 try {
921 session = openSession();
922
923 Query q = session.createQuery(sql);
924
925 QueryPos qPos = QueryPos.getInstance(q);
926
927 if (bindUuid) {
928 qPos.add(uuid);
929 }
930
931 count = (Long)q.uniqueResult();
932
933 FinderCacheUtil.putResult(finderPath, finderArgs, count);
934 }
935 catch (Exception e) {
936 FinderCacheUtil.removeResult(finderPath, finderArgs);
937
938 throw processException(e);
939 }
940 finally {
941 closeSession(session);
942 }
943 }
944
945 return count.intValue();
946 }
947
948
954 @Override
955 public int filterCountByUuid(String uuid) {
956 if (!InlineSQLHelperUtil.isEnabled()) {
957 return countByUuid(uuid);
958 }
959
960 StringBundler query = new StringBundler(2);
961
962 query.append(_FILTER_SQL_COUNT_ORGANIZATION_WHERE);
963
964 boolean bindUuid = false;
965
966 if (uuid == null) {
967 query.append(_FINDER_COLUMN_UUID_UUID_1_SQL);
968 }
969 else if (uuid.equals(StringPool.BLANK)) {
970 query.append(_FINDER_COLUMN_UUID_UUID_3_SQL);
971 }
972 else {
973 bindUuid = true;
974
975 query.append(_FINDER_COLUMN_UUID_UUID_2_SQL);
976 }
977
978 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
979 Organization.class.getName(),
980 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
981
982 Session session = null;
983
984 try {
985 session = openSession();
986
987 SQLQuery q = session.createSynchronizedSQLQuery(sql);
988
989 q.addScalar(COUNT_COLUMN_NAME,
990 com.liferay.portal.kernel.dao.orm.Type.LONG);
991
992 QueryPos qPos = QueryPos.getInstance(q);
993
994 if (bindUuid) {
995 qPos.add(uuid);
996 }
997
998 Long count = (Long)q.uniqueResult();
999
1000 return count.intValue();
1001 }
1002 catch (Exception e) {
1003 throw processException(e);
1004 }
1005 finally {
1006 closeSession(session);
1007 }
1008 }
1009
1010 private static final String _FINDER_COLUMN_UUID_UUID_1 = "organization.uuid IS NULL";
1011 private static final String _FINDER_COLUMN_UUID_UUID_2 = "organization.uuid = ?";
1012 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(organization.uuid IS NULL OR organization.uuid = '')";
1013 private static final String _FINDER_COLUMN_UUID_UUID_1_SQL = "organization.uuid_ IS NULL";
1014 private static final String _FINDER_COLUMN_UUID_UUID_2_SQL = "organization.uuid_ = ?";
1015 private static final String _FINDER_COLUMN_UUID_UUID_3_SQL = "(organization.uuid_ IS NULL OR organization.uuid_ = '')";
1016 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
1017 OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
1018 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
1019 new String[] {
1020 String.class.getName(), Long.class.getName(),
1021
1022 Integer.class.getName(), Integer.class.getName(),
1023 OrderByComparator.class.getName()
1024 });
1025 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
1026 new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
1027 OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
1028 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
1029 new String[] { String.class.getName(), Long.class.getName() },
1030 OrganizationModelImpl.UUID_COLUMN_BITMASK |
1031 OrganizationModelImpl.COMPANYID_COLUMN_BITMASK |
1032 OrganizationModelImpl.NAME_COLUMN_BITMASK);
1033 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
1034 OrganizationModelImpl.FINDER_CACHE_ENABLED, Long.class,
1035 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
1036 new String[] { String.class.getName(), Long.class.getName() });
1037
1038
1045 @Override
1046 public List<Organization> findByUuid_C(String uuid, long companyId) {
1047 return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
1048 QueryUtil.ALL_POS, null);
1049 }
1050
1051
1064 @Override
1065 public List<Organization> findByUuid_C(String uuid, long companyId,
1066 int start, int end) {
1067 return findByUuid_C(uuid, companyId, start, end, null);
1068 }
1069
1070
1084 @Override
1085 public List<Organization> findByUuid_C(String uuid, long companyId,
1086 int start, int end, OrderByComparator<Organization> orderByComparator) {
1087 boolean pagination = true;
1088 FinderPath finderPath = null;
1089 Object[] finderArgs = null;
1090
1091 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1092 (orderByComparator == null)) {
1093 pagination = false;
1094 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
1095 finderArgs = new Object[] { uuid, companyId };
1096 }
1097 else {
1098 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
1099 finderArgs = new Object[] {
1100 uuid, companyId,
1101
1102 start, end, orderByComparator
1103 };
1104 }
1105
1106 List<Organization> list = (List<Organization>)FinderCacheUtil.getResult(finderPath,
1107 finderArgs, this);
1108
1109 if ((list != null) && !list.isEmpty()) {
1110 for (Organization organization : list) {
1111 if (!Validator.equals(uuid, organization.getUuid()) ||
1112 (companyId != organization.getCompanyId())) {
1113 list = null;
1114
1115 break;
1116 }
1117 }
1118 }
1119
1120 if (list == null) {
1121 StringBundler query = null;
1122
1123 if (orderByComparator != null) {
1124 query = new StringBundler(4 +
1125 (orderByComparator.getOrderByFields().length * 3));
1126 }
1127 else {
1128 query = new StringBundler(4);
1129 }
1130
1131 query.append(_SQL_SELECT_ORGANIZATION_WHERE);
1132
1133 boolean bindUuid = false;
1134
1135 if (uuid == null) {
1136 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1137 }
1138 else if (uuid.equals(StringPool.BLANK)) {
1139 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1140 }
1141 else {
1142 bindUuid = true;
1143
1144 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1145 }
1146
1147 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1148
1149 if (orderByComparator != null) {
1150 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1151 orderByComparator);
1152 }
1153 else
1154 if (pagination) {
1155 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
1156 }
1157
1158 String sql = query.toString();
1159
1160 Session session = null;
1161
1162 try {
1163 session = openSession();
1164
1165 Query q = session.createQuery(sql);
1166
1167 QueryPos qPos = QueryPos.getInstance(q);
1168
1169 if (bindUuid) {
1170 qPos.add(uuid);
1171 }
1172
1173 qPos.add(companyId);
1174
1175 if (!pagination) {
1176 list = (List<Organization>)QueryUtil.list(q, getDialect(),
1177 start, end, false);
1178
1179 Collections.sort(list);
1180
1181 list = Collections.unmodifiableList(list);
1182 }
1183 else {
1184 list = (List<Organization>)QueryUtil.list(q, getDialect(),
1185 start, end);
1186 }
1187
1188 cacheResult(list);
1189
1190 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1191 }
1192 catch (Exception e) {
1193 FinderCacheUtil.removeResult(finderPath, finderArgs);
1194
1195 throw processException(e);
1196 }
1197 finally {
1198 closeSession(session);
1199 }
1200 }
1201
1202 return list;
1203 }
1204
1205
1214 @Override
1215 public Organization findByUuid_C_First(String uuid, long companyId,
1216 OrderByComparator<Organization> orderByComparator)
1217 throws NoSuchOrganizationException {
1218 Organization organization = fetchByUuid_C_First(uuid, companyId,
1219 orderByComparator);
1220
1221 if (organization != null) {
1222 return organization;
1223 }
1224
1225 StringBundler msg = new StringBundler(6);
1226
1227 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1228
1229 msg.append("uuid=");
1230 msg.append(uuid);
1231
1232 msg.append(", companyId=");
1233 msg.append(companyId);
1234
1235 msg.append(StringPool.CLOSE_CURLY_BRACE);
1236
1237 throw new NoSuchOrganizationException(msg.toString());
1238 }
1239
1240
1248 @Override
1249 public Organization fetchByUuid_C_First(String uuid, long companyId,
1250 OrderByComparator<Organization> orderByComparator) {
1251 List<Organization> list = findByUuid_C(uuid, companyId, 0, 1,
1252 orderByComparator);
1253
1254 if (!list.isEmpty()) {
1255 return list.get(0);
1256 }
1257
1258 return null;
1259 }
1260
1261
1270 @Override
1271 public Organization findByUuid_C_Last(String uuid, long companyId,
1272 OrderByComparator<Organization> orderByComparator)
1273 throws NoSuchOrganizationException {
1274 Organization organization = fetchByUuid_C_Last(uuid, companyId,
1275 orderByComparator);
1276
1277 if (organization != null) {
1278 return organization;
1279 }
1280
1281 StringBundler msg = new StringBundler(6);
1282
1283 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1284
1285 msg.append("uuid=");
1286 msg.append(uuid);
1287
1288 msg.append(", companyId=");
1289 msg.append(companyId);
1290
1291 msg.append(StringPool.CLOSE_CURLY_BRACE);
1292
1293 throw new NoSuchOrganizationException(msg.toString());
1294 }
1295
1296
1304 @Override
1305 public Organization fetchByUuid_C_Last(String uuid, long companyId,
1306 OrderByComparator<Organization> orderByComparator) {
1307 int count = countByUuid_C(uuid, companyId);
1308
1309 if (count == 0) {
1310 return null;
1311 }
1312
1313 List<Organization> list = findByUuid_C(uuid, companyId, count - 1,
1314 count, orderByComparator);
1315
1316 if (!list.isEmpty()) {
1317 return list.get(0);
1318 }
1319
1320 return null;
1321 }
1322
1323
1333 @Override
1334 public Organization[] findByUuid_C_PrevAndNext(long organizationId,
1335 String uuid, long companyId,
1336 OrderByComparator<Organization> orderByComparator)
1337 throws NoSuchOrganizationException {
1338 Organization organization = findByPrimaryKey(organizationId);
1339
1340 Session session = null;
1341
1342 try {
1343 session = openSession();
1344
1345 Organization[] array = new OrganizationImpl[3];
1346
1347 array[0] = getByUuid_C_PrevAndNext(session, organization, uuid,
1348 companyId, orderByComparator, true);
1349
1350 array[1] = organization;
1351
1352 array[2] = getByUuid_C_PrevAndNext(session, organization, uuid,
1353 companyId, orderByComparator, false);
1354
1355 return array;
1356 }
1357 catch (Exception e) {
1358 throw processException(e);
1359 }
1360 finally {
1361 closeSession(session);
1362 }
1363 }
1364
1365 protected Organization getByUuid_C_PrevAndNext(Session session,
1366 Organization organization, String uuid, long companyId,
1367 OrderByComparator<Organization> orderByComparator, boolean previous) {
1368 StringBundler query = null;
1369
1370 if (orderByComparator != null) {
1371 query = new StringBundler(6 +
1372 (orderByComparator.getOrderByFields().length * 6));
1373 }
1374 else {
1375 query = new StringBundler(3);
1376 }
1377
1378 query.append(_SQL_SELECT_ORGANIZATION_WHERE);
1379
1380 boolean bindUuid = false;
1381
1382 if (uuid == null) {
1383 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1384 }
1385 else if (uuid.equals(StringPool.BLANK)) {
1386 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1387 }
1388 else {
1389 bindUuid = true;
1390
1391 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1392 }
1393
1394 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1395
1396 if (orderByComparator != null) {
1397 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1398
1399 if (orderByConditionFields.length > 0) {
1400 query.append(WHERE_AND);
1401 }
1402
1403 for (int i = 0; i < orderByConditionFields.length; i++) {
1404 query.append(_ORDER_BY_ENTITY_ALIAS);
1405 query.append(orderByConditionFields[i]);
1406
1407 if ((i + 1) < orderByConditionFields.length) {
1408 if (orderByComparator.isAscending() ^ previous) {
1409 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1410 }
1411 else {
1412 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1413 }
1414 }
1415 else {
1416 if (orderByComparator.isAscending() ^ previous) {
1417 query.append(WHERE_GREATER_THAN);
1418 }
1419 else {
1420 query.append(WHERE_LESSER_THAN);
1421 }
1422 }
1423 }
1424
1425 query.append(ORDER_BY_CLAUSE);
1426
1427 String[] orderByFields = orderByComparator.getOrderByFields();
1428
1429 for (int i = 0; i < orderByFields.length; i++) {
1430 query.append(_ORDER_BY_ENTITY_ALIAS);
1431 query.append(orderByFields[i]);
1432
1433 if ((i + 1) < orderByFields.length) {
1434 if (orderByComparator.isAscending() ^ previous) {
1435 query.append(ORDER_BY_ASC_HAS_NEXT);
1436 }
1437 else {
1438 query.append(ORDER_BY_DESC_HAS_NEXT);
1439 }
1440 }
1441 else {
1442 if (orderByComparator.isAscending() ^ previous) {
1443 query.append(ORDER_BY_ASC);
1444 }
1445 else {
1446 query.append(ORDER_BY_DESC);
1447 }
1448 }
1449 }
1450 }
1451 else {
1452 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
1453 }
1454
1455 String sql = query.toString();
1456
1457 Query q = session.createQuery(sql);
1458
1459 q.setFirstResult(0);
1460 q.setMaxResults(2);
1461
1462 QueryPos qPos = QueryPos.getInstance(q);
1463
1464 if (bindUuid) {
1465 qPos.add(uuid);
1466 }
1467
1468 qPos.add(companyId);
1469
1470 if (orderByComparator != null) {
1471 Object[] values = orderByComparator.getOrderByConditionValues(organization);
1472
1473 for (Object value : values) {
1474 qPos.add(value);
1475 }
1476 }
1477
1478 List<Organization> list = q.list();
1479
1480 if (list.size() == 2) {
1481 return list.get(1);
1482 }
1483 else {
1484 return null;
1485 }
1486 }
1487
1488
1495 @Override
1496 public List<Organization> filterFindByUuid_C(String uuid, long companyId) {
1497 return filterFindByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
1498 QueryUtil.ALL_POS, null);
1499 }
1500
1501
1514 @Override
1515 public List<Organization> filterFindByUuid_C(String uuid, long companyId,
1516 int start, int end) {
1517 return filterFindByUuid_C(uuid, companyId, start, end, null);
1518 }
1519
1520
1534 @Override
1535 public List<Organization> filterFindByUuid_C(String uuid, long companyId,
1536 int start, int end, OrderByComparator<Organization> orderByComparator) {
1537 if (!InlineSQLHelperUtil.isEnabled()) {
1538 return findByUuid_C(uuid, companyId, start, end, orderByComparator);
1539 }
1540
1541 StringBundler query = null;
1542
1543 if (orderByComparator != null) {
1544 query = new StringBundler(4 +
1545 (orderByComparator.getOrderByFields().length * 3));
1546 }
1547 else {
1548 query = new StringBundler(4);
1549 }
1550
1551 if (getDB().isSupportsInlineDistinct()) {
1552 query.append(_FILTER_SQL_SELECT_ORGANIZATION_WHERE);
1553 }
1554 else {
1555 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1);
1556 }
1557
1558 boolean bindUuid = false;
1559
1560 if (uuid == null) {
1561 query.append(_FINDER_COLUMN_UUID_C_UUID_1_SQL);
1562 }
1563 else if (uuid.equals(StringPool.BLANK)) {
1564 query.append(_FINDER_COLUMN_UUID_C_UUID_3_SQL);
1565 }
1566 else {
1567 bindUuid = true;
1568
1569 query.append(_FINDER_COLUMN_UUID_C_UUID_2_SQL);
1570 }
1571
1572 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1573
1574 if (!getDB().isSupportsInlineDistinct()) {
1575 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2);
1576 }
1577
1578 if (orderByComparator != null) {
1579 if (getDB().isSupportsInlineDistinct()) {
1580 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1581 orderByComparator, true);
1582 }
1583 else {
1584 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1585 orderByComparator, true);
1586 }
1587 }
1588 else {
1589 if (getDB().isSupportsInlineDistinct()) {
1590 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
1591 }
1592 else {
1593 query.append(OrganizationModelImpl.ORDER_BY_SQL);
1594 }
1595 }
1596
1597 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1598 Organization.class.getName(),
1599 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1600
1601 Session session = null;
1602
1603 try {
1604 session = openSession();
1605
1606 SQLQuery q = session.createSynchronizedSQLQuery(sql);
1607
1608 if (getDB().isSupportsInlineDistinct()) {
1609 q.addEntity(_FILTER_ENTITY_ALIAS, OrganizationImpl.class);
1610 }
1611 else {
1612 q.addEntity(_FILTER_ENTITY_TABLE, OrganizationImpl.class);
1613 }
1614
1615 QueryPos qPos = QueryPos.getInstance(q);
1616
1617 if (bindUuid) {
1618 qPos.add(uuid);
1619 }
1620
1621 qPos.add(companyId);
1622
1623 return (List<Organization>)QueryUtil.list(q, getDialect(), start,
1624 end);
1625 }
1626 catch (Exception e) {
1627 throw processException(e);
1628 }
1629 finally {
1630 closeSession(session);
1631 }
1632 }
1633
1634
1644 @Override
1645 public Organization[] filterFindByUuid_C_PrevAndNext(long organizationId,
1646 String uuid, long companyId,
1647 OrderByComparator<Organization> orderByComparator)
1648 throws NoSuchOrganizationException {
1649 if (!InlineSQLHelperUtil.isEnabled()) {
1650 return findByUuid_C_PrevAndNext(organizationId, uuid, companyId,
1651 orderByComparator);
1652 }
1653
1654 Organization organization = findByPrimaryKey(organizationId);
1655
1656 Session session = null;
1657
1658 try {
1659 session = openSession();
1660
1661 Organization[] array = new OrganizationImpl[3];
1662
1663 array[0] = filterGetByUuid_C_PrevAndNext(session, organization,
1664 uuid, companyId, orderByComparator, true);
1665
1666 array[1] = organization;
1667
1668 array[2] = filterGetByUuid_C_PrevAndNext(session, organization,
1669 uuid, companyId, orderByComparator, false);
1670
1671 return array;
1672 }
1673 catch (Exception e) {
1674 throw processException(e);
1675 }
1676 finally {
1677 closeSession(session);
1678 }
1679 }
1680
1681 protected Organization filterGetByUuid_C_PrevAndNext(Session session,
1682 Organization organization, String uuid, long companyId,
1683 OrderByComparator<Organization> orderByComparator, boolean previous) {
1684 StringBundler query = null;
1685
1686 if (orderByComparator != null) {
1687 query = new StringBundler(6 +
1688 (orderByComparator.getOrderByFields().length * 6));
1689 }
1690 else {
1691 query = new StringBundler(3);
1692 }
1693
1694 if (getDB().isSupportsInlineDistinct()) {
1695 query.append(_FILTER_SQL_SELECT_ORGANIZATION_WHERE);
1696 }
1697 else {
1698 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1);
1699 }
1700
1701 boolean bindUuid = false;
1702
1703 if (uuid == null) {
1704 query.append(_FINDER_COLUMN_UUID_C_UUID_1_SQL);
1705 }
1706 else if (uuid.equals(StringPool.BLANK)) {
1707 query.append(_FINDER_COLUMN_UUID_C_UUID_3_SQL);
1708 }
1709 else {
1710 bindUuid = true;
1711
1712 query.append(_FINDER_COLUMN_UUID_C_UUID_2_SQL);
1713 }
1714
1715 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1716
1717 if (!getDB().isSupportsInlineDistinct()) {
1718 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2);
1719 }
1720
1721 if (orderByComparator != null) {
1722 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1723
1724 if (orderByConditionFields.length > 0) {
1725 query.append(WHERE_AND);
1726 }
1727
1728 for (int i = 0; i < orderByConditionFields.length; i++) {
1729 if (getDB().isSupportsInlineDistinct()) {
1730 query.append(_ORDER_BY_ENTITY_ALIAS);
1731 }
1732 else {
1733 query.append(_ORDER_BY_ENTITY_TABLE);
1734 }
1735
1736 query.append(orderByConditionFields[i]);
1737
1738 if ((i + 1) < orderByConditionFields.length) {
1739 if (orderByComparator.isAscending() ^ previous) {
1740 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1741 }
1742 else {
1743 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1744 }
1745 }
1746 else {
1747 if (orderByComparator.isAscending() ^ previous) {
1748 query.append(WHERE_GREATER_THAN);
1749 }
1750 else {
1751 query.append(WHERE_LESSER_THAN);
1752 }
1753 }
1754 }
1755
1756 query.append(ORDER_BY_CLAUSE);
1757
1758 String[] orderByFields = orderByComparator.getOrderByFields();
1759
1760 for (int i = 0; i < orderByFields.length; i++) {
1761 if (getDB().isSupportsInlineDistinct()) {
1762 query.append(_ORDER_BY_ENTITY_ALIAS);
1763 }
1764 else {
1765 query.append(_ORDER_BY_ENTITY_TABLE);
1766 }
1767
1768 query.append(orderByFields[i]);
1769
1770 if ((i + 1) < orderByFields.length) {
1771 if (orderByComparator.isAscending() ^ previous) {
1772 query.append(ORDER_BY_ASC_HAS_NEXT);
1773 }
1774 else {
1775 query.append(ORDER_BY_DESC_HAS_NEXT);
1776 }
1777 }
1778 else {
1779 if (orderByComparator.isAscending() ^ previous) {
1780 query.append(ORDER_BY_ASC);
1781 }
1782 else {
1783 query.append(ORDER_BY_DESC);
1784 }
1785 }
1786 }
1787 }
1788 else {
1789 if (getDB().isSupportsInlineDistinct()) {
1790 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
1791 }
1792 else {
1793 query.append(OrganizationModelImpl.ORDER_BY_SQL);
1794 }
1795 }
1796
1797 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1798 Organization.class.getName(),
1799 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1800
1801 SQLQuery q = session.createSynchronizedSQLQuery(sql);
1802
1803 q.setFirstResult(0);
1804 q.setMaxResults(2);
1805
1806 if (getDB().isSupportsInlineDistinct()) {
1807 q.addEntity(_FILTER_ENTITY_ALIAS, OrganizationImpl.class);
1808 }
1809 else {
1810 q.addEntity(_FILTER_ENTITY_TABLE, OrganizationImpl.class);
1811 }
1812
1813 QueryPos qPos = QueryPos.getInstance(q);
1814
1815 if (bindUuid) {
1816 qPos.add(uuid);
1817 }
1818
1819 qPos.add(companyId);
1820
1821 if (orderByComparator != null) {
1822 Object[] values = orderByComparator.getOrderByConditionValues(organization);
1823
1824 for (Object value : values) {
1825 qPos.add(value);
1826 }
1827 }
1828
1829 List<Organization> list = q.list();
1830
1831 if (list.size() == 2) {
1832 return list.get(1);
1833 }
1834 else {
1835 return null;
1836 }
1837 }
1838
1839
1845 @Override
1846 public void removeByUuid_C(String uuid, long companyId) {
1847 for (Organization organization : findByUuid_C(uuid, companyId,
1848 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1849 remove(organization);
1850 }
1851 }
1852
1853
1860 @Override
1861 public int countByUuid_C(String uuid, long companyId) {
1862 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1863
1864 Object[] finderArgs = new Object[] { uuid, companyId };
1865
1866 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1867 this);
1868
1869 if (count == null) {
1870 StringBundler query = new StringBundler(3);
1871
1872 query.append(_SQL_COUNT_ORGANIZATION_WHERE);
1873
1874 boolean bindUuid = false;
1875
1876 if (uuid == null) {
1877 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1878 }
1879 else if (uuid.equals(StringPool.BLANK)) {
1880 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1881 }
1882 else {
1883 bindUuid = true;
1884
1885 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1886 }
1887
1888 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1889
1890 String sql = query.toString();
1891
1892 Session session = null;
1893
1894 try {
1895 session = openSession();
1896
1897 Query q = session.createQuery(sql);
1898
1899 QueryPos qPos = QueryPos.getInstance(q);
1900
1901 if (bindUuid) {
1902 qPos.add(uuid);
1903 }
1904
1905 qPos.add(companyId);
1906
1907 count = (Long)q.uniqueResult();
1908
1909 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1910 }
1911 catch (Exception e) {
1912 FinderCacheUtil.removeResult(finderPath, finderArgs);
1913
1914 throw processException(e);
1915 }
1916 finally {
1917 closeSession(session);
1918 }
1919 }
1920
1921 return count.intValue();
1922 }
1923
1924
1931 @Override
1932 public int filterCountByUuid_C(String uuid, long companyId) {
1933 if (!InlineSQLHelperUtil.isEnabled()) {
1934 return countByUuid_C(uuid, companyId);
1935 }
1936
1937 StringBundler query = new StringBundler(3);
1938
1939 query.append(_FILTER_SQL_COUNT_ORGANIZATION_WHERE);
1940
1941 boolean bindUuid = false;
1942
1943 if (uuid == null) {
1944 query.append(_FINDER_COLUMN_UUID_C_UUID_1_SQL);
1945 }
1946 else if (uuid.equals(StringPool.BLANK)) {
1947 query.append(_FINDER_COLUMN_UUID_C_UUID_3_SQL);
1948 }
1949 else {
1950 bindUuid = true;
1951
1952 query.append(_FINDER_COLUMN_UUID_C_UUID_2_SQL);
1953 }
1954
1955 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1956
1957 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1958 Organization.class.getName(),
1959 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1960
1961 Session session = null;
1962
1963 try {
1964 session = openSession();
1965
1966 SQLQuery q = session.createSynchronizedSQLQuery(sql);
1967
1968 q.addScalar(COUNT_COLUMN_NAME,
1969 com.liferay.portal.kernel.dao.orm.Type.LONG);
1970
1971 QueryPos qPos = QueryPos.getInstance(q);
1972
1973 if (bindUuid) {
1974 qPos.add(uuid);
1975 }
1976
1977 qPos.add(companyId);
1978
1979 Long count = (Long)q.uniqueResult();
1980
1981 return count.intValue();
1982 }
1983 catch (Exception e) {
1984 throw processException(e);
1985 }
1986 finally {
1987 closeSession(session);
1988 }
1989 }
1990
1991 private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "organization.uuid IS NULL AND ";
1992 private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "organization.uuid = ? AND ";
1993 private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(organization.uuid IS NULL OR organization.uuid = '') AND ";
1994 private static final String _FINDER_COLUMN_UUID_C_UUID_1_SQL = "organization.uuid_ IS NULL AND ";
1995 private static final String _FINDER_COLUMN_UUID_C_UUID_2_SQL = "organization.uuid_ = ? AND ";
1996 private static final String _FINDER_COLUMN_UUID_C_UUID_3_SQL = "(organization.uuid_ IS NULL OR organization.uuid_ = '') AND ";
1997 private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "organization.companyId = ?";
1998 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
1999 new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
2000 OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
2001 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
2002 new String[] {
2003 Long.class.getName(),
2004
2005 Integer.class.getName(), Integer.class.getName(),
2006 OrderByComparator.class.getName()
2007 });
2008 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
2009 new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
2010 OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
2011 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
2012 new String[] { Long.class.getName() },
2013 OrganizationModelImpl.COMPANYID_COLUMN_BITMASK |
2014 OrganizationModelImpl.NAME_COLUMN_BITMASK);
2015 public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
2016 OrganizationModelImpl.FINDER_CACHE_ENABLED, Long.class,
2017 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
2018 new String[] { Long.class.getName() });
2019
2020
2026 @Override
2027 public List<Organization> findByCompanyId(long companyId) {
2028 return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2029 null);
2030 }
2031
2032
2044 @Override
2045 public List<Organization> findByCompanyId(long companyId, int start, int end) {
2046 return findByCompanyId(companyId, start, end, null);
2047 }
2048
2049
2062 @Override
2063 public List<Organization> findByCompanyId(long companyId, int start,
2064 int end, OrderByComparator<Organization> orderByComparator) {
2065 boolean pagination = true;
2066 FinderPath finderPath = null;
2067 Object[] finderArgs = null;
2068
2069 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2070 (orderByComparator == null)) {
2071 pagination = false;
2072 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
2073 finderArgs = new Object[] { companyId };
2074 }
2075 else {
2076 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
2077 finderArgs = new Object[] { companyId, start, end, orderByComparator };
2078 }
2079
2080 List<Organization> list = (List<Organization>)FinderCacheUtil.getResult(finderPath,
2081 finderArgs, this);
2082
2083 if ((list != null) && !list.isEmpty()) {
2084 for (Organization organization : list) {
2085 if ((companyId != organization.getCompanyId())) {
2086 list = null;
2087
2088 break;
2089 }
2090 }
2091 }
2092
2093 if (list == null) {
2094 StringBundler query = null;
2095
2096 if (orderByComparator != null) {
2097 query = new StringBundler(3 +
2098 (orderByComparator.getOrderByFields().length * 3));
2099 }
2100 else {
2101 query = new StringBundler(3);
2102 }
2103
2104 query.append(_SQL_SELECT_ORGANIZATION_WHERE);
2105
2106 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2107
2108 if (orderByComparator != null) {
2109 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2110 orderByComparator);
2111 }
2112 else
2113 if (pagination) {
2114 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
2115 }
2116
2117 String sql = query.toString();
2118
2119 Session session = null;
2120
2121 try {
2122 session = openSession();
2123
2124 Query q = session.createQuery(sql);
2125
2126 QueryPos qPos = QueryPos.getInstance(q);
2127
2128 qPos.add(companyId);
2129
2130 if (!pagination) {
2131 list = (List<Organization>)QueryUtil.list(q, getDialect(),
2132 start, end, false);
2133
2134 Collections.sort(list);
2135
2136 list = Collections.unmodifiableList(list);
2137 }
2138 else {
2139 list = (List<Organization>)QueryUtil.list(q, getDialect(),
2140 start, end);
2141 }
2142
2143 cacheResult(list);
2144
2145 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2146 }
2147 catch (Exception e) {
2148 FinderCacheUtil.removeResult(finderPath, finderArgs);
2149
2150 throw processException(e);
2151 }
2152 finally {
2153 closeSession(session);
2154 }
2155 }
2156
2157 return list;
2158 }
2159
2160
2168 @Override
2169 public Organization findByCompanyId_First(long companyId,
2170 OrderByComparator<Organization> orderByComparator)
2171 throws NoSuchOrganizationException {
2172 Organization organization = fetchByCompanyId_First(companyId,
2173 orderByComparator);
2174
2175 if (organization != null) {
2176 return organization;
2177 }
2178
2179 StringBundler msg = new StringBundler(4);
2180
2181 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2182
2183 msg.append("companyId=");
2184 msg.append(companyId);
2185
2186 msg.append(StringPool.CLOSE_CURLY_BRACE);
2187
2188 throw new NoSuchOrganizationException(msg.toString());
2189 }
2190
2191
2198 @Override
2199 public Organization fetchByCompanyId_First(long companyId,
2200 OrderByComparator<Organization> orderByComparator) {
2201 List<Organization> list = findByCompanyId(companyId, 0, 1,
2202 orderByComparator);
2203
2204 if (!list.isEmpty()) {
2205 return list.get(0);
2206 }
2207
2208 return null;
2209 }
2210
2211
2219 @Override
2220 public Organization findByCompanyId_Last(long companyId,
2221 OrderByComparator<Organization> orderByComparator)
2222 throws NoSuchOrganizationException {
2223 Organization organization = fetchByCompanyId_Last(companyId,
2224 orderByComparator);
2225
2226 if (organization != null) {
2227 return organization;
2228 }
2229
2230 StringBundler msg = new StringBundler(4);
2231
2232 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2233
2234 msg.append("companyId=");
2235 msg.append(companyId);
2236
2237 msg.append(StringPool.CLOSE_CURLY_BRACE);
2238
2239 throw new NoSuchOrganizationException(msg.toString());
2240 }
2241
2242
2249 @Override
2250 public Organization fetchByCompanyId_Last(long companyId,
2251 OrderByComparator<Organization> orderByComparator) {
2252 int count = countByCompanyId(companyId);
2253
2254 if (count == 0) {
2255 return null;
2256 }
2257
2258 List<Organization> list = findByCompanyId(companyId, count - 1, count,
2259 orderByComparator);
2260
2261 if (!list.isEmpty()) {
2262 return list.get(0);
2263 }
2264
2265 return null;
2266 }
2267
2268
2277 @Override
2278 public Organization[] findByCompanyId_PrevAndNext(long organizationId,
2279 long companyId, OrderByComparator<Organization> orderByComparator)
2280 throws NoSuchOrganizationException {
2281 Organization organization = findByPrimaryKey(organizationId);
2282
2283 Session session = null;
2284
2285 try {
2286 session = openSession();
2287
2288 Organization[] array = new OrganizationImpl[3];
2289
2290 array[0] = getByCompanyId_PrevAndNext(session, organization,
2291 companyId, orderByComparator, true);
2292
2293 array[1] = organization;
2294
2295 array[2] = getByCompanyId_PrevAndNext(session, organization,
2296 companyId, orderByComparator, false);
2297
2298 return array;
2299 }
2300 catch (Exception e) {
2301 throw processException(e);
2302 }
2303 finally {
2304 closeSession(session);
2305 }
2306 }
2307
2308 protected Organization getByCompanyId_PrevAndNext(Session session,
2309 Organization organization, long companyId,
2310 OrderByComparator<Organization> orderByComparator, boolean previous) {
2311 StringBundler query = null;
2312
2313 if (orderByComparator != null) {
2314 query = new StringBundler(6 +
2315 (orderByComparator.getOrderByFields().length * 6));
2316 }
2317 else {
2318 query = new StringBundler(3);
2319 }
2320
2321 query.append(_SQL_SELECT_ORGANIZATION_WHERE);
2322
2323 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2324
2325 if (orderByComparator != null) {
2326 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2327
2328 if (orderByConditionFields.length > 0) {
2329 query.append(WHERE_AND);
2330 }
2331
2332 for (int i = 0; i < orderByConditionFields.length; i++) {
2333 query.append(_ORDER_BY_ENTITY_ALIAS);
2334 query.append(orderByConditionFields[i]);
2335
2336 if ((i + 1) < orderByConditionFields.length) {
2337 if (orderByComparator.isAscending() ^ previous) {
2338 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2339 }
2340 else {
2341 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2342 }
2343 }
2344 else {
2345 if (orderByComparator.isAscending() ^ previous) {
2346 query.append(WHERE_GREATER_THAN);
2347 }
2348 else {
2349 query.append(WHERE_LESSER_THAN);
2350 }
2351 }
2352 }
2353
2354 query.append(ORDER_BY_CLAUSE);
2355
2356 String[] orderByFields = orderByComparator.getOrderByFields();
2357
2358 for (int i = 0; i < orderByFields.length; i++) {
2359 query.append(_ORDER_BY_ENTITY_ALIAS);
2360 query.append(orderByFields[i]);
2361
2362 if ((i + 1) < orderByFields.length) {
2363 if (orderByComparator.isAscending() ^ previous) {
2364 query.append(ORDER_BY_ASC_HAS_NEXT);
2365 }
2366 else {
2367 query.append(ORDER_BY_DESC_HAS_NEXT);
2368 }
2369 }
2370 else {
2371 if (orderByComparator.isAscending() ^ previous) {
2372 query.append(ORDER_BY_ASC);
2373 }
2374 else {
2375 query.append(ORDER_BY_DESC);
2376 }
2377 }
2378 }
2379 }
2380 else {
2381 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
2382 }
2383
2384 String sql = query.toString();
2385
2386 Query q = session.createQuery(sql);
2387
2388 q.setFirstResult(0);
2389 q.setMaxResults(2);
2390
2391 QueryPos qPos = QueryPos.getInstance(q);
2392
2393 qPos.add(companyId);
2394
2395 if (orderByComparator != null) {
2396 Object[] values = orderByComparator.getOrderByConditionValues(organization);
2397
2398 for (Object value : values) {
2399 qPos.add(value);
2400 }
2401 }
2402
2403 List<Organization> list = q.list();
2404
2405 if (list.size() == 2) {
2406 return list.get(1);
2407 }
2408 else {
2409 return null;
2410 }
2411 }
2412
2413
2419 @Override
2420 public List<Organization> filterFindByCompanyId(long companyId) {
2421 return filterFindByCompanyId(companyId, QueryUtil.ALL_POS,
2422 QueryUtil.ALL_POS, null);
2423 }
2424
2425
2437 @Override
2438 public List<Organization> filterFindByCompanyId(long companyId, int start,
2439 int end) {
2440 return filterFindByCompanyId(companyId, start, end, null);
2441 }
2442
2443
2456 @Override
2457 public List<Organization> filterFindByCompanyId(long companyId, int start,
2458 int end, OrderByComparator<Organization> orderByComparator) {
2459 if (!InlineSQLHelperUtil.isEnabled()) {
2460 return findByCompanyId(companyId, start, end, orderByComparator);
2461 }
2462
2463 StringBundler query = null;
2464
2465 if (orderByComparator != null) {
2466 query = new StringBundler(3 +
2467 (orderByComparator.getOrderByFields().length * 3));
2468 }
2469 else {
2470 query = new StringBundler(3);
2471 }
2472
2473 if (getDB().isSupportsInlineDistinct()) {
2474 query.append(_FILTER_SQL_SELECT_ORGANIZATION_WHERE);
2475 }
2476 else {
2477 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1);
2478 }
2479
2480 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2481
2482 if (!getDB().isSupportsInlineDistinct()) {
2483 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2);
2484 }
2485
2486 if (orderByComparator != null) {
2487 if (getDB().isSupportsInlineDistinct()) {
2488 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2489 orderByComparator, true);
2490 }
2491 else {
2492 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
2493 orderByComparator, true);
2494 }
2495 }
2496 else {
2497 if (getDB().isSupportsInlineDistinct()) {
2498 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
2499 }
2500 else {
2501 query.append(OrganizationModelImpl.ORDER_BY_SQL);
2502 }
2503 }
2504
2505 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2506 Organization.class.getName(),
2507 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2508
2509 Session session = null;
2510
2511 try {
2512 session = openSession();
2513
2514 SQLQuery q = session.createSynchronizedSQLQuery(sql);
2515
2516 if (getDB().isSupportsInlineDistinct()) {
2517 q.addEntity(_FILTER_ENTITY_ALIAS, OrganizationImpl.class);
2518 }
2519 else {
2520 q.addEntity(_FILTER_ENTITY_TABLE, OrganizationImpl.class);
2521 }
2522
2523 QueryPos qPos = QueryPos.getInstance(q);
2524
2525 qPos.add(companyId);
2526
2527 return (List<Organization>)QueryUtil.list(q, getDialect(), start,
2528 end);
2529 }
2530 catch (Exception e) {
2531 throw processException(e);
2532 }
2533 finally {
2534 closeSession(session);
2535 }
2536 }
2537
2538
2547 @Override
2548 public Organization[] filterFindByCompanyId_PrevAndNext(
2549 long organizationId, long companyId,
2550 OrderByComparator<Organization> orderByComparator)
2551 throws NoSuchOrganizationException {
2552 if (!InlineSQLHelperUtil.isEnabled()) {
2553 return findByCompanyId_PrevAndNext(organizationId, companyId,
2554 orderByComparator);
2555 }
2556
2557 Organization organization = findByPrimaryKey(organizationId);
2558
2559 Session session = null;
2560
2561 try {
2562 session = openSession();
2563
2564 Organization[] array = new OrganizationImpl[3];
2565
2566 array[0] = filterGetByCompanyId_PrevAndNext(session, organization,
2567 companyId, orderByComparator, true);
2568
2569 array[1] = organization;
2570
2571 array[2] = filterGetByCompanyId_PrevAndNext(session, organization,
2572 companyId, orderByComparator, false);
2573
2574 return array;
2575 }
2576 catch (Exception e) {
2577 throw processException(e);
2578 }
2579 finally {
2580 closeSession(session);
2581 }
2582 }
2583
2584 protected Organization filterGetByCompanyId_PrevAndNext(Session session,
2585 Organization organization, long companyId,
2586 OrderByComparator<Organization> orderByComparator, boolean previous) {
2587 StringBundler query = null;
2588
2589 if (orderByComparator != null) {
2590 query = new StringBundler(6 +
2591 (orderByComparator.getOrderByFields().length * 6));
2592 }
2593 else {
2594 query = new StringBundler(3);
2595 }
2596
2597 if (getDB().isSupportsInlineDistinct()) {
2598 query.append(_FILTER_SQL_SELECT_ORGANIZATION_WHERE);
2599 }
2600 else {
2601 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1);
2602 }
2603
2604 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2605
2606 if (!getDB().isSupportsInlineDistinct()) {
2607 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2);
2608 }
2609
2610 if (orderByComparator != null) {
2611 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2612
2613 if (orderByConditionFields.length > 0) {
2614 query.append(WHERE_AND);
2615 }
2616
2617 for (int i = 0; i < orderByConditionFields.length; i++) {
2618 if (getDB().isSupportsInlineDistinct()) {
2619 query.append(_ORDER_BY_ENTITY_ALIAS);
2620 }
2621 else {
2622 query.append(_ORDER_BY_ENTITY_TABLE);
2623 }
2624
2625 query.append(orderByConditionFields[i]);
2626
2627 if ((i + 1) < orderByConditionFields.length) {
2628 if (orderByComparator.isAscending() ^ previous) {
2629 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2630 }
2631 else {
2632 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2633 }
2634 }
2635 else {
2636 if (orderByComparator.isAscending() ^ previous) {
2637 query.append(WHERE_GREATER_THAN);
2638 }
2639 else {
2640 query.append(WHERE_LESSER_THAN);
2641 }
2642 }
2643 }
2644
2645 query.append(ORDER_BY_CLAUSE);
2646
2647 String[] orderByFields = orderByComparator.getOrderByFields();
2648
2649 for (int i = 0; i < orderByFields.length; i++) {
2650 if (getDB().isSupportsInlineDistinct()) {
2651 query.append(_ORDER_BY_ENTITY_ALIAS);
2652 }
2653 else {
2654 query.append(_ORDER_BY_ENTITY_TABLE);
2655 }
2656
2657 query.append(orderByFields[i]);
2658
2659 if ((i + 1) < orderByFields.length) {
2660 if (orderByComparator.isAscending() ^ previous) {
2661 query.append(ORDER_BY_ASC_HAS_NEXT);
2662 }
2663 else {
2664 query.append(ORDER_BY_DESC_HAS_NEXT);
2665 }
2666 }
2667 else {
2668 if (orderByComparator.isAscending() ^ previous) {
2669 query.append(ORDER_BY_ASC);
2670 }
2671 else {
2672 query.append(ORDER_BY_DESC);
2673 }
2674 }
2675 }
2676 }
2677 else {
2678 if (getDB().isSupportsInlineDistinct()) {
2679 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
2680 }
2681 else {
2682 query.append(OrganizationModelImpl.ORDER_BY_SQL);
2683 }
2684 }
2685
2686 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2687 Organization.class.getName(),
2688 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2689
2690 SQLQuery q = session.createSynchronizedSQLQuery(sql);
2691
2692 q.setFirstResult(0);
2693 q.setMaxResults(2);
2694
2695 if (getDB().isSupportsInlineDistinct()) {
2696 q.addEntity(_FILTER_ENTITY_ALIAS, OrganizationImpl.class);
2697 }
2698 else {
2699 q.addEntity(_FILTER_ENTITY_TABLE, OrganizationImpl.class);
2700 }
2701
2702 QueryPos qPos = QueryPos.getInstance(q);
2703
2704 qPos.add(companyId);
2705
2706 if (orderByComparator != null) {
2707 Object[] values = orderByComparator.getOrderByConditionValues(organization);
2708
2709 for (Object value : values) {
2710 qPos.add(value);
2711 }
2712 }
2713
2714 List<Organization> list = q.list();
2715
2716 if (list.size() == 2) {
2717 return list.get(1);
2718 }
2719 else {
2720 return null;
2721 }
2722 }
2723
2724
2729 @Override
2730 public void removeByCompanyId(long companyId) {
2731 for (Organization organization : findByCompanyId(companyId,
2732 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2733 remove(organization);
2734 }
2735 }
2736
2737
2743 @Override
2744 public int countByCompanyId(long companyId) {
2745 FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
2746
2747 Object[] finderArgs = new Object[] { companyId };
2748
2749 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2750 this);
2751
2752 if (count == null) {
2753 StringBundler query = new StringBundler(2);
2754
2755 query.append(_SQL_COUNT_ORGANIZATION_WHERE);
2756
2757 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2758
2759 String sql = query.toString();
2760
2761 Session session = null;
2762
2763 try {
2764 session = openSession();
2765
2766 Query q = session.createQuery(sql);
2767
2768 QueryPos qPos = QueryPos.getInstance(q);
2769
2770 qPos.add(companyId);
2771
2772 count = (Long)q.uniqueResult();
2773
2774 FinderCacheUtil.putResult(finderPath, finderArgs, count);
2775 }
2776 catch (Exception e) {
2777 FinderCacheUtil.removeResult(finderPath, finderArgs);
2778
2779 throw processException(e);
2780 }
2781 finally {
2782 closeSession(session);
2783 }
2784 }
2785
2786 return count.intValue();
2787 }
2788
2789
2795 @Override
2796 public int filterCountByCompanyId(long companyId) {
2797 if (!InlineSQLHelperUtil.isEnabled()) {
2798 return countByCompanyId(companyId);
2799 }
2800
2801 StringBundler query = new StringBundler(2);
2802
2803 query.append(_FILTER_SQL_COUNT_ORGANIZATION_WHERE);
2804
2805 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2806
2807 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2808 Organization.class.getName(),
2809 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2810
2811 Session session = null;
2812
2813 try {
2814 session = openSession();
2815
2816 SQLQuery q = session.createSynchronizedSQLQuery(sql);
2817
2818 q.addScalar(COUNT_COLUMN_NAME,
2819 com.liferay.portal.kernel.dao.orm.Type.LONG);
2820
2821 QueryPos qPos = QueryPos.getInstance(q);
2822
2823 qPos.add(companyId);
2824
2825 Long count = (Long)q.uniqueResult();
2826
2827 return count.intValue();
2828 }
2829 catch (Exception e) {
2830 throw processException(e);
2831 }
2832 finally {
2833 closeSession(session);
2834 }
2835 }
2836
2837 private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "organization.companyId = ?";
2838 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_LOCATIONS =
2839 new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
2840 OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
2841 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByLocations",
2842 new String[] {
2843 Long.class.getName(),
2844
2845 Integer.class.getName(), Integer.class.getName(),
2846 OrderByComparator.class.getName()
2847 });
2848 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LOCATIONS =
2849 new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
2850 OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
2851 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByLocations",
2852 new String[] { Long.class.getName() },
2853 OrganizationModelImpl.COMPANYID_COLUMN_BITMASK |
2854 OrganizationModelImpl.NAME_COLUMN_BITMASK);
2855 public static final FinderPath FINDER_PATH_COUNT_BY_LOCATIONS = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
2856 OrganizationModelImpl.FINDER_CACHE_ENABLED, Long.class,
2857 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByLocations",
2858 new String[] { Long.class.getName() });
2859
2860
2866 @Override
2867 public List<Organization> findByLocations(long companyId) {
2868 return findByLocations(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2869 null);
2870 }
2871
2872
2884 @Override
2885 public List<Organization> findByLocations(long companyId, int start, int end) {
2886 return findByLocations(companyId, start, end, null);
2887 }
2888
2889
2902 @Override
2903 public List<Organization> findByLocations(long companyId, int start,
2904 int end, OrderByComparator<Organization> orderByComparator) {
2905 boolean pagination = true;
2906 FinderPath finderPath = null;
2907 Object[] finderArgs = null;
2908
2909 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2910 (orderByComparator == null)) {
2911 pagination = false;
2912 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LOCATIONS;
2913 finderArgs = new Object[] { companyId };
2914 }
2915 else {
2916 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_LOCATIONS;
2917 finderArgs = new Object[] { companyId, start, end, orderByComparator };
2918 }
2919
2920 List<Organization> list = (List<Organization>)FinderCacheUtil.getResult(finderPath,
2921 finderArgs, this);
2922
2923 if ((list != null) && !list.isEmpty()) {
2924 for (Organization organization : list) {
2925 if ((companyId != organization.getCompanyId())) {
2926 list = null;
2927
2928 break;
2929 }
2930 }
2931 }
2932
2933 if (list == null) {
2934 StringBundler query = null;
2935
2936 if (orderByComparator != null) {
2937 query = new StringBundler(3 +
2938 (orderByComparator.getOrderByFields().length * 3));
2939 }
2940 else {
2941 query = new StringBundler(3);
2942 }
2943
2944 query.append(_SQL_SELECT_ORGANIZATION_WHERE);
2945
2946 query.append(_FINDER_COLUMN_LOCATIONS_COMPANYID_2);
2947
2948 if (orderByComparator != null) {
2949 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2950 orderByComparator);
2951 }
2952 else
2953 if (pagination) {
2954 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
2955 }
2956
2957 String sql = query.toString();
2958
2959 Session session = null;
2960
2961 try {
2962 session = openSession();
2963
2964 Query q = session.createQuery(sql);
2965
2966 QueryPos qPos = QueryPos.getInstance(q);
2967
2968 qPos.add(companyId);
2969
2970 if (!pagination) {
2971 list = (List<Organization>)QueryUtil.list(q, getDialect(),
2972 start, end, false);
2973
2974 Collections.sort(list);
2975
2976 list = Collections.unmodifiableList(list);
2977 }
2978 else {
2979 list = (List<Organization>)QueryUtil.list(q, getDialect(),
2980 start, end);
2981 }
2982
2983 cacheResult(list);
2984
2985 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2986 }
2987 catch (Exception e) {
2988 FinderCacheUtil.removeResult(finderPath, finderArgs);
2989
2990 throw processException(e);
2991 }
2992 finally {
2993 closeSession(session);
2994 }
2995 }
2996
2997 return list;
2998 }
2999
3000
3008 @Override
3009 public Organization findByLocations_First(long companyId,
3010 OrderByComparator<Organization> orderByComparator)
3011 throws NoSuchOrganizationException {
3012 Organization organization = fetchByLocations_First(companyId,
3013 orderByComparator);
3014
3015 if (organization != null) {
3016 return organization;
3017 }
3018
3019 StringBundler msg = new StringBundler(4);
3020
3021 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3022
3023 msg.append("companyId=");
3024 msg.append(companyId);
3025
3026 msg.append(StringPool.CLOSE_CURLY_BRACE);
3027
3028 throw new NoSuchOrganizationException(msg.toString());
3029 }
3030
3031
3038 @Override
3039 public Organization fetchByLocations_First(long companyId,
3040 OrderByComparator<Organization> orderByComparator) {
3041 List<Organization> list = findByLocations(companyId, 0, 1,
3042 orderByComparator);
3043
3044 if (!list.isEmpty()) {
3045 return list.get(0);
3046 }
3047
3048 return null;
3049 }
3050
3051
3059 @Override
3060 public Organization findByLocations_Last(long companyId,
3061 OrderByComparator<Organization> orderByComparator)
3062 throws NoSuchOrganizationException {
3063 Organization organization = fetchByLocations_Last(companyId,
3064 orderByComparator);
3065
3066 if (organization != null) {
3067 return organization;
3068 }
3069
3070 StringBundler msg = new StringBundler(4);
3071
3072 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3073
3074 msg.append("companyId=");
3075 msg.append(companyId);
3076
3077 msg.append(StringPool.CLOSE_CURLY_BRACE);
3078
3079 throw new NoSuchOrganizationException(msg.toString());
3080 }
3081
3082
3089 @Override
3090 public Organization fetchByLocations_Last(long companyId,
3091 OrderByComparator<Organization> orderByComparator) {
3092 int count = countByLocations(companyId);
3093
3094 if (count == 0) {
3095 return null;
3096 }
3097
3098 List<Organization> list = findByLocations(companyId, count - 1, count,
3099 orderByComparator);
3100
3101 if (!list.isEmpty()) {
3102 return list.get(0);
3103 }
3104
3105 return null;
3106 }
3107
3108
3117 @Override
3118 public Organization[] findByLocations_PrevAndNext(long organizationId,
3119 long companyId, OrderByComparator<Organization> orderByComparator)
3120 throws NoSuchOrganizationException {
3121 Organization organization = findByPrimaryKey(organizationId);
3122
3123 Session session = null;
3124
3125 try {
3126 session = openSession();
3127
3128 Organization[] array = new OrganizationImpl[3];
3129
3130 array[0] = getByLocations_PrevAndNext(session, organization,
3131 companyId, orderByComparator, true);
3132
3133 array[1] = organization;
3134
3135 array[2] = getByLocations_PrevAndNext(session, organization,
3136 companyId, orderByComparator, false);
3137
3138 return array;
3139 }
3140 catch (Exception e) {
3141 throw processException(e);
3142 }
3143 finally {
3144 closeSession(session);
3145 }
3146 }
3147
3148 protected Organization getByLocations_PrevAndNext(Session session,
3149 Organization organization, long companyId,
3150 OrderByComparator<Organization> orderByComparator, boolean previous) {
3151 StringBundler query = null;
3152
3153 if (orderByComparator != null) {
3154 query = new StringBundler(6 +
3155 (orderByComparator.getOrderByFields().length * 6));
3156 }
3157 else {
3158 query = new StringBundler(3);
3159 }
3160
3161 query.append(_SQL_SELECT_ORGANIZATION_WHERE);
3162
3163 query.append(_FINDER_COLUMN_LOCATIONS_COMPANYID_2);
3164
3165 if (orderByComparator != null) {
3166 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3167
3168 if (orderByConditionFields.length > 0) {
3169 query.append(WHERE_AND);
3170 }
3171
3172 for (int i = 0; i < orderByConditionFields.length; i++) {
3173 query.append(_ORDER_BY_ENTITY_ALIAS);
3174 query.append(orderByConditionFields[i]);
3175
3176 if ((i + 1) < orderByConditionFields.length) {
3177 if (orderByComparator.isAscending() ^ previous) {
3178 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3179 }
3180 else {
3181 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3182 }
3183 }
3184 else {
3185 if (orderByComparator.isAscending() ^ previous) {
3186 query.append(WHERE_GREATER_THAN);
3187 }
3188 else {
3189 query.append(WHERE_LESSER_THAN);
3190 }
3191 }
3192 }
3193
3194 query.append(ORDER_BY_CLAUSE);
3195
3196 String[] orderByFields = orderByComparator.getOrderByFields();
3197
3198 for (int i = 0; i < orderByFields.length; i++) {
3199 query.append(_ORDER_BY_ENTITY_ALIAS);
3200 query.append(orderByFields[i]);
3201
3202 if ((i + 1) < orderByFields.length) {
3203 if (orderByComparator.isAscending() ^ previous) {
3204 query.append(ORDER_BY_ASC_HAS_NEXT);
3205 }
3206 else {
3207 query.append(ORDER_BY_DESC_HAS_NEXT);
3208 }
3209 }
3210 else {
3211 if (orderByComparator.isAscending() ^ previous) {
3212 query.append(ORDER_BY_ASC);
3213 }
3214 else {
3215 query.append(ORDER_BY_DESC);
3216 }
3217 }
3218 }
3219 }
3220 else {
3221 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
3222 }
3223
3224 String sql = query.toString();
3225
3226 Query q = session.createQuery(sql);
3227
3228 q.setFirstResult(0);
3229 q.setMaxResults(2);
3230
3231 QueryPos qPos = QueryPos.getInstance(q);
3232
3233 qPos.add(companyId);
3234
3235 if (orderByComparator != null) {
3236 Object[] values = orderByComparator.getOrderByConditionValues(organization);
3237
3238 for (Object value : values) {
3239 qPos.add(value);
3240 }
3241 }
3242
3243 List<Organization> list = q.list();
3244
3245 if (list.size() == 2) {
3246 return list.get(1);
3247 }
3248 else {
3249 return null;
3250 }
3251 }
3252
3253
3259 @Override
3260 public List<Organization> filterFindByLocations(long companyId) {
3261 return filterFindByLocations(companyId, QueryUtil.ALL_POS,
3262 QueryUtil.ALL_POS, null);
3263 }
3264
3265
3277 @Override
3278 public List<Organization> filterFindByLocations(long companyId, int start,
3279 int end) {
3280 return filterFindByLocations(companyId, start, end, null);
3281 }
3282
3283
3296 @Override
3297 public List<Organization> filterFindByLocations(long companyId, int start,
3298 int end, OrderByComparator<Organization> orderByComparator) {
3299 if (!InlineSQLHelperUtil.isEnabled()) {
3300 return findByLocations(companyId, start, end, orderByComparator);
3301 }
3302
3303 StringBundler query = null;
3304
3305 if (orderByComparator != null) {
3306 query = new StringBundler(3 +
3307 (orderByComparator.getOrderByFields().length * 3));
3308 }
3309 else {
3310 query = new StringBundler(3);
3311 }
3312
3313 if (getDB().isSupportsInlineDistinct()) {
3314 query.append(_FILTER_SQL_SELECT_ORGANIZATION_WHERE);
3315 }
3316 else {
3317 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1);
3318 }
3319
3320 query.append(_FINDER_COLUMN_LOCATIONS_COMPANYID_2);
3321
3322 if (!getDB().isSupportsInlineDistinct()) {
3323 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2);
3324 }
3325
3326 if (orderByComparator != null) {
3327 if (getDB().isSupportsInlineDistinct()) {
3328 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3329 orderByComparator, true);
3330 }
3331 else {
3332 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
3333 orderByComparator, true);
3334 }
3335 }
3336 else {
3337 if (getDB().isSupportsInlineDistinct()) {
3338 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
3339 }
3340 else {
3341 query.append(OrganizationModelImpl.ORDER_BY_SQL);
3342 }
3343 }
3344
3345 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3346 Organization.class.getName(),
3347 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
3348
3349 Session session = null;
3350
3351 try {
3352 session = openSession();
3353
3354 SQLQuery q = session.createSynchronizedSQLQuery(sql);
3355
3356 if (getDB().isSupportsInlineDistinct()) {
3357 q.addEntity(_FILTER_ENTITY_ALIAS, OrganizationImpl.class);
3358 }
3359 else {
3360 q.addEntity(_FILTER_ENTITY_TABLE, OrganizationImpl.class);
3361 }
3362
3363 QueryPos qPos = QueryPos.getInstance(q);
3364
3365 qPos.add(companyId);
3366
3367 return (List<Organization>)QueryUtil.list(q, getDialect(), start,
3368 end);
3369 }
3370 catch (Exception e) {
3371 throw processException(e);
3372 }
3373 finally {
3374 closeSession(session);
3375 }
3376 }
3377
3378
3387 @Override
3388 public Organization[] filterFindByLocations_PrevAndNext(
3389 long organizationId, long companyId,
3390 OrderByComparator<Organization> orderByComparator)
3391 throws NoSuchOrganizationException {
3392 if (!InlineSQLHelperUtil.isEnabled()) {
3393 return findByLocations_PrevAndNext(organizationId, companyId,
3394 orderByComparator);
3395 }
3396
3397 Organization organization = findByPrimaryKey(organizationId);
3398
3399 Session session = null;
3400
3401 try {
3402 session = openSession();
3403
3404 Organization[] array = new OrganizationImpl[3];
3405
3406 array[0] = filterGetByLocations_PrevAndNext(session, organization,
3407 companyId, orderByComparator, true);
3408
3409 array[1] = organization;
3410
3411 array[2] = filterGetByLocations_PrevAndNext(session, organization,
3412 companyId, orderByComparator, false);
3413
3414 return array;
3415 }
3416 catch (Exception e) {
3417 throw processException(e);
3418 }
3419 finally {
3420 closeSession(session);
3421 }
3422 }
3423
3424 protected Organization filterGetByLocations_PrevAndNext(Session session,
3425 Organization organization, long companyId,
3426 OrderByComparator<Organization> orderByComparator, boolean previous) {
3427 StringBundler query = null;
3428
3429 if (orderByComparator != null) {
3430 query = new StringBundler(6 +
3431 (orderByComparator.getOrderByFields().length * 6));
3432 }
3433 else {
3434 query = new StringBundler(3);
3435 }
3436
3437 if (getDB().isSupportsInlineDistinct()) {
3438 query.append(_FILTER_SQL_SELECT_ORGANIZATION_WHERE);
3439 }
3440 else {
3441 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1);
3442 }
3443
3444 query.append(_FINDER_COLUMN_LOCATIONS_COMPANYID_2);
3445
3446 if (!getDB().isSupportsInlineDistinct()) {
3447 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2);
3448 }
3449
3450 if (orderByComparator != null) {
3451 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3452
3453 if (orderByConditionFields.length > 0) {
3454 query.append(WHERE_AND);
3455 }
3456
3457 for (int i = 0; i < orderByConditionFields.length; i++) {
3458 if (getDB().isSupportsInlineDistinct()) {
3459 query.append(_ORDER_BY_ENTITY_ALIAS);
3460 }
3461 else {
3462 query.append(_ORDER_BY_ENTITY_TABLE);
3463 }
3464
3465 query.append(orderByConditionFields[i]);
3466
3467 if ((i + 1) < orderByConditionFields.length) {
3468 if (orderByComparator.isAscending() ^ previous) {
3469 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3470 }
3471 else {
3472 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3473 }
3474 }
3475 else {
3476 if (orderByComparator.isAscending() ^ previous) {
3477 query.append(WHERE_GREATER_THAN);
3478 }
3479 else {
3480 query.append(WHERE_LESSER_THAN);
3481 }
3482 }
3483 }
3484
3485 query.append(ORDER_BY_CLAUSE);
3486
3487 String[] orderByFields = orderByComparator.getOrderByFields();
3488
3489 for (int i = 0; i < orderByFields.length; i++) {
3490 if (getDB().isSupportsInlineDistinct()) {
3491 query.append(_ORDER_BY_ENTITY_ALIAS);
3492 }
3493 else {
3494 query.append(_ORDER_BY_ENTITY_TABLE);
3495 }
3496
3497 query.append(orderByFields[i]);
3498
3499 if ((i + 1) < orderByFields.length) {
3500 if (orderByComparator.isAscending() ^ previous) {
3501 query.append(ORDER_BY_ASC_HAS_NEXT);
3502 }
3503 else {
3504 query.append(ORDER_BY_DESC_HAS_NEXT);
3505 }
3506 }
3507 else {
3508 if (orderByComparator.isAscending() ^ previous) {
3509 query.append(ORDER_BY_ASC);
3510 }
3511 else {
3512 query.append(ORDER_BY_DESC);
3513 }
3514 }
3515 }
3516 }
3517 else {
3518 if (getDB().isSupportsInlineDistinct()) {
3519 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
3520 }
3521 else {
3522 query.append(OrganizationModelImpl.ORDER_BY_SQL);
3523 }
3524 }
3525
3526 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3527 Organization.class.getName(),
3528 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
3529
3530 SQLQuery q = session.createSynchronizedSQLQuery(sql);
3531
3532 q.setFirstResult(0);
3533 q.setMaxResults(2);
3534
3535 if (getDB().isSupportsInlineDistinct()) {
3536 q.addEntity(_FILTER_ENTITY_ALIAS, OrganizationImpl.class);
3537 }
3538 else {
3539 q.addEntity(_FILTER_ENTITY_TABLE, OrganizationImpl.class);
3540 }
3541
3542 QueryPos qPos = QueryPos.getInstance(q);
3543
3544 qPos.add(companyId);
3545
3546 if (orderByComparator != null) {
3547 Object[] values = orderByComparator.getOrderByConditionValues(organization);
3548
3549 for (Object value : values) {
3550 qPos.add(value);
3551 }
3552 }
3553
3554 List<Organization> list = q.list();
3555
3556 if (list.size() == 2) {
3557 return list.get(1);
3558 }
3559 else {
3560 return null;
3561 }
3562 }
3563
3564
3569 @Override
3570 public void removeByLocations(long companyId) {
3571 for (Organization organization : findByLocations(companyId,
3572 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3573 remove(organization);
3574 }
3575 }
3576
3577
3583 @Override
3584 public int countByLocations(long companyId) {
3585 FinderPath finderPath = FINDER_PATH_COUNT_BY_LOCATIONS;
3586
3587 Object[] finderArgs = new Object[] { companyId };
3588
3589 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3590 this);
3591
3592 if (count == null) {
3593 StringBundler query = new StringBundler(2);
3594
3595 query.append(_SQL_COUNT_ORGANIZATION_WHERE);
3596
3597 query.append(_FINDER_COLUMN_LOCATIONS_COMPANYID_2);
3598
3599 String sql = query.toString();
3600
3601 Session session = null;
3602
3603 try {
3604 session = openSession();
3605
3606 Query q = session.createQuery(sql);
3607
3608 QueryPos qPos = QueryPos.getInstance(q);
3609
3610 qPos.add(companyId);
3611
3612 count = (Long)q.uniqueResult();
3613
3614 FinderCacheUtil.putResult(finderPath, finderArgs, count);
3615 }
3616 catch (Exception e) {
3617 FinderCacheUtil.removeResult(finderPath, finderArgs);
3618
3619 throw processException(e);
3620 }
3621 finally {
3622 closeSession(session);
3623 }
3624 }
3625
3626 return count.intValue();
3627 }
3628
3629
3635 @Override
3636 public int filterCountByLocations(long companyId) {
3637 if (!InlineSQLHelperUtil.isEnabled()) {
3638 return countByLocations(companyId);
3639 }
3640
3641 StringBundler query = new StringBundler(2);
3642
3643 query.append(_FILTER_SQL_COUNT_ORGANIZATION_WHERE);
3644
3645 query.append(_FINDER_COLUMN_LOCATIONS_COMPANYID_2);
3646
3647 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3648 Organization.class.getName(),
3649 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
3650
3651 Session session = null;
3652
3653 try {
3654 session = openSession();
3655
3656 SQLQuery q = session.createSynchronizedSQLQuery(sql);
3657
3658 q.addScalar(COUNT_COLUMN_NAME,
3659 com.liferay.portal.kernel.dao.orm.Type.LONG);
3660
3661 QueryPos qPos = QueryPos.getInstance(q);
3662
3663 qPos.add(companyId);
3664
3665 Long count = (Long)q.uniqueResult();
3666
3667 return count.intValue();
3668 }
3669 catch (Exception e) {
3670 throw processException(e);
3671 }
3672 finally {
3673 closeSession(session);
3674 }
3675 }
3676
3677 private static final String _FINDER_COLUMN_LOCATIONS_COMPANYID_2 = "organization.companyId = ? AND organization.parentOrganizationId != 0";
3678 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_P = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
3679 OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
3680 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_P",
3681 new String[] {
3682 Long.class.getName(), Long.class.getName(),
3683
3684 Integer.class.getName(), Integer.class.getName(),
3685 OrderByComparator.class.getName()
3686 });
3687 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
3688 OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
3689 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_P",
3690 new String[] { Long.class.getName(), Long.class.getName() },
3691 OrganizationModelImpl.COMPANYID_COLUMN_BITMASK |
3692 OrganizationModelImpl.PARENTORGANIZATIONID_COLUMN_BITMASK |
3693 OrganizationModelImpl.NAME_COLUMN_BITMASK);
3694 public static final FinderPath FINDER_PATH_COUNT_BY_C_P = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
3695 OrganizationModelImpl.FINDER_CACHE_ENABLED, Long.class,
3696 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_P",
3697 new String[] { Long.class.getName(), Long.class.getName() });
3698
3699
3706 @Override
3707 public List<Organization> findByC_P(long companyId,
3708 long parentOrganizationId) {
3709 return findByC_P(companyId, parentOrganizationId, QueryUtil.ALL_POS,
3710 QueryUtil.ALL_POS, null);
3711 }
3712
3713
3726 @Override
3727 public List<Organization> findByC_P(long companyId,
3728 long parentOrganizationId, int start, int end) {
3729 return findByC_P(companyId, parentOrganizationId, start, end, null);
3730 }
3731
3732
3746 @Override
3747 public List<Organization> findByC_P(long companyId,
3748 long parentOrganizationId, int start, int end,
3749 OrderByComparator<Organization> orderByComparator) {
3750 boolean pagination = true;
3751 FinderPath finderPath = null;
3752 Object[] finderArgs = null;
3753
3754 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3755 (orderByComparator == null)) {
3756 pagination = false;
3757 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P;
3758 finderArgs = new Object[] { companyId, parentOrganizationId };
3759 }
3760 else {
3761 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_P;
3762 finderArgs = new Object[] {
3763 companyId, parentOrganizationId,
3764
3765 start, end, orderByComparator
3766 };
3767 }
3768
3769 List<Organization> list = (List<Organization>)FinderCacheUtil.getResult(finderPath,
3770 finderArgs, this);
3771
3772 if ((list != null) && !list.isEmpty()) {
3773 for (Organization organization : list) {
3774 if ((companyId != organization.getCompanyId()) ||
3775 (parentOrganizationId != organization.getParentOrganizationId())) {
3776 list = null;
3777
3778 break;
3779 }
3780 }
3781 }
3782
3783 if (list == null) {
3784 StringBundler query = null;
3785
3786 if (orderByComparator != null) {
3787 query = new StringBundler(4 +
3788 (orderByComparator.getOrderByFields().length * 3));
3789 }
3790 else {
3791 query = new StringBundler(4);
3792 }
3793
3794 query.append(_SQL_SELECT_ORGANIZATION_WHERE);
3795
3796 query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
3797
3798 query.append(_FINDER_COLUMN_C_P_PARENTORGANIZATIONID_2);
3799
3800 if (orderByComparator != null) {
3801 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3802 orderByComparator);
3803 }
3804 else
3805 if (pagination) {
3806 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
3807 }
3808
3809 String sql = query.toString();
3810
3811 Session session = null;
3812
3813 try {
3814 session = openSession();
3815
3816 Query q = session.createQuery(sql);
3817
3818 QueryPos qPos = QueryPos.getInstance(q);
3819
3820 qPos.add(companyId);
3821
3822 qPos.add(parentOrganizationId);
3823
3824 if (!pagination) {
3825 list = (List<Organization>)QueryUtil.list(q, getDialect(),
3826 start, end, false);
3827
3828 Collections.sort(list);
3829
3830 list = Collections.unmodifiableList(list);
3831 }
3832 else {
3833 list = (List<Organization>)QueryUtil.list(q, getDialect(),
3834 start, end);
3835 }
3836
3837 cacheResult(list);
3838
3839 FinderCacheUtil.putResult(finderPath, finderArgs, list);
3840 }
3841 catch (Exception e) {
3842 FinderCacheUtil.removeResult(finderPath, finderArgs);
3843
3844 throw processException(e);
3845 }
3846 finally {
3847 closeSession(session);
3848 }
3849 }
3850
3851 return list;
3852 }
3853
3854
3863 @Override
3864 public Organization findByC_P_First(long companyId,
3865 long parentOrganizationId,
3866 OrderByComparator<Organization> orderByComparator)
3867 throws NoSuchOrganizationException {
3868 Organization organization = fetchByC_P_First(companyId,
3869 parentOrganizationId, orderByComparator);
3870
3871 if (organization != null) {
3872 return organization;
3873 }
3874
3875 StringBundler msg = new StringBundler(6);
3876
3877 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3878
3879 msg.append("companyId=");
3880 msg.append(companyId);
3881
3882 msg.append(", parentOrganizationId=");
3883 msg.append(parentOrganizationId);
3884
3885 msg.append(StringPool.CLOSE_CURLY_BRACE);
3886
3887 throw new NoSuchOrganizationException(msg.toString());
3888 }
3889
3890
3898 @Override
3899 public Organization fetchByC_P_First(long companyId,
3900 long parentOrganizationId,
3901 OrderByComparator<Organization> orderByComparator) {
3902 List<Organization> list = findByC_P(companyId, parentOrganizationId, 0,
3903 1, orderByComparator);
3904
3905 if (!list.isEmpty()) {
3906 return list.get(0);
3907 }
3908
3909 return null;
3910 }
3911
3912
3921 @Override
3922 public Organization findByC_P_Last(long companyId,
3923 long parentOrganizationId,
3924 OrderByComparator<Organization> orderByComparator)
3925 throws NoSuchOrganizationException {
3926 Organization organization = fetchByC_P_Last(companyId,
3927 parentOrganizationId, orderByComparator);
3928
3929 if (organization != null) {
3930 return organization;
3931 }
3932
3933 StringBundler msg = new StringBundler(6);
3934
3935 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3936
3937 msg.append("companyId=");
3938 msg.append(companyId);
3939
3940 msg.append(", parentOrganizationId=");
3941 msg.append(parentOrganizationId);
3942
3943 msg.append(StringPool.CLOSE_CURLY_BRACE);
3944
3945 throw new NoSuchOrganizationException(msg.toString());
3946 }
3947
3948
3956 @Override
3957 public Organization fetchByC_P_Last(long companyId,
3958 long parentOrganizationId,
3959 OrderByComparator<Organization> orderByComparator) {
3960 int count = countByC_P(companyId, parentOrganizationId);
3961
3962 if (count == 0) {
3963 return null;
3964 }
3965
3966 List<Organization> list = findByC_P(companyId, parentOrganizationId,
3967 count - 1, count, orderByComparator);
3968
3969 if (!list.isEmpty()) {
3970 return list.get(0);
3971 }
3972
3973 return null;
3974 }
3975
3976
3986 @Override
3987 public Organization[] findByC_P_PrevAndNext(long organizationId,
3988 long companyId, long parentOrganizationId,
3989 OrderByComparator<Organization> orderByComparator)
3990 throws NoSuchOrganizationException {
3991 Organization organization = findByPrimaryKey(organizationId);
3992
3993 Session session = null;
3994
3995 try {
3996 session = openSession();
3997
3998 Organization[] array = new OrganizationImpl[3];
3999
4000 array[0] = getByC_P_PrevAndNext(session, organization, companyId,
4001 parentOrganizationId, orderByComparator, true);
4002
4003 array[1] = organization;
4004
4005 array[2] = getByC_P_PrevAndNext(session, organization, companyId,
4006 parentOrganizationId, orderByComparator, false);
4007
4008 return array;
4009 }
4010 catch (Exception e) {
4011 throw processException(e);
4012 }
4013 finally {
4014 closeSession(session);
4015 }
4016 }
4017
4018 protected Organization getByC_P_PrevAndNext(Session session,
4019 Organization organization, long companyId, long parentOrganizationId,
4020 OrderByComparator<Organization> orderByComparator, boolean previous) {
4021 StringBundler query = null;
4022
4023 if (orderByComparator != null) {
4024 query = new StringBundler(6 +
4025 (orderByComparator.getOrderByFields().length * 6));
4026 }
4027 else {
4028 query = new StringBundler(3);
4029 }
4030
4031 query.append(_SQL_SELECT_ORGANIZATION_WHERE);
4032
4033 query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
4034
4035 query.append(_FINDER_COLUMN_C_P_PARENTORGANIZATIONID_2);
4036
4037 if (orderByComparator != null) {
4038 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4039
4040 if (orderByConditionFields.length > 0) {
4041 query.append(WHERE_AND);
4042 }
4043
4044 for (int i = 0; i < orderByConditionFields.length; i++) {
4045 query.append(_ORDER_BY_ENTITY_ALIAS);
4046 query.append(orderByConditionFields[i]);
4047
4048 if ((i + 1) < orderByConditionFields.length) {
4049 if (orderByComparator.isAscending() ^ previous) {
4050 query.append(WHERE_GREATER_THAN_HAS_NEXT);
4051 }
4052 else {
4053 query.append(WHERE_LESSER_THAN_HAS_NEXT);
4054 }
4055 }
4056 else {
4057 if (orderByComparator.isAscending() ^ previous) {
4058 query.append(WHERE_GREATER_THAN);
4059 }
4060 else {
4061 query.append(WHERE_LESSER_THAN);
4062 }
4063 }
4064 }
4065
4066 query.append(ORDER_BY_CLAUSE);
4067
4068 String[] orderByFields = orderByComparator.getOrderByFields();
4069
4070 for (int i = 0; i < orderByFields.length; i++) {
4071 query.append(_ORDER_BY_ENTITY_ALIAS);
4072 query.append(orderByFields[i]);
4073
4074 if ((i + 1) < orderByFields.length) {
4075 if (orderByComparator.isAscending() ^ previous) {
4076 query.append(ORDER_BY_ASC_HAS_NEXT);
4077 }
4078 else {
4079 query.append(ORDER_BY_DESC_HAS_NEXT);
4080 }
4081 }
4082 else {
4083 if (orderByComparator.isAscending() ^ previous) {
4084 query.append(ORDER_BY_ASC);
4085 }
4086 else {
4087 query.append(ORDER_BY_DESC);
4088 }
4089 }
4090 }
4091 }
4092 else {
4093 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
4094 }
4095
4096 String sql = query.toString();
4097
4098 Query q = session.createQuery(sql);
4099
4100 q.setFirstResult(0);
4101 q.setMaxResults(2);
4102
4103 QueryPos qPos = QueryPos.getInstance(q);
4104
4105 qPos.add(companyId);
4106
4107 qPos.add(parentOrganizationId);
4108
4109 if (orderByComparator != null) {
4110 Object[] values = orderByComparator.getOrderByConditionValues(organization);
4111
4112 for (Object value : values) {
4113 qPos.add(value);
4114 }
4115 }
4116
4117 List<Organization> list = q.list();
4118
4119 if (list.size() == 2) {
4120 return list.get(1);
4121 }
4122 else {
4123 return null;
4124 }
4125 }
4126
4127
4134 @Override
4135 public List<Organization> filterFindByC_P(long companyId,
4136 long parentOrganizationId) {
4137 return filterFindByC_P(companyId, parentOrganizationId,
4138 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
4139 }
4140
4141
4154 @Override
4155 public List<Organization> filterFindByC_P(long companyId,
4156 long parentOrganizationId, int start, int end) {
4157 return filterFindByC_P(companyId, parentOrganizationId, start, end, null);
4158 }
4159
4160
4174 @Override
4175 public List<Organization> filterFindByC_P(long companyId,
4176 long parentOrganizationId, int start, int end,
4177 OrderByComparator<Organization> orderByComparator) {
4178 if (!InlineSQLHelperUtil.isEnabled()) {
4179 return findByC_P(companyId, parentOrganizationId, start, end,
4180 orderByComparator);
4181 }
4182
4183 StringBundler query = null;
4184
4185 if (orderByComparator != null) {
4186 query = new StringBundler(4 +
4187 (orderByComparator.getOrderByFields().length * 3));
4188 }
4189 else {
4190 query = new StringBundler(4);
4191 }
4192
4193 if (getDB().isSupportsInlineDistinct()) {
4194 query.append(_FILTER_SQL_SELECT_ORGANIZATION_WHERE);
4195 }
4196 else {
4197 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1);
4198 }
4199
4200 query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
4201
4202 query.append(_FINDER_COLUMN_C_P_PARENTORGANIZATIONID_2);
4203
4204 if (!getDB().isSupportsInlineDistinct()) {
4205 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2);
4206 }
4207
4208 if (orderByComparator != null) {
4209 if (getDB().isSupportsInlineDistinct()) {
4210 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4211 orderByComparator, true);
4212 }
4213 else {
4214 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
4215 orderByComparator, true);
4216 }
4217 }
4218 else {
4219 if (getDB().isSupportsInlineDistinct()) {
4220 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
4221 }
4222 else {
4223 query.append(OrganizationModelImpl.ORDER_BY_SQL);
4224 }
4225 }
4226
4227 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4228 Organization.class.getName(),
4229 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
4230
4231 Session session = null;
4232
4233 try {
4234 session = openSession();
4235
4236 SQLQuery q = session.createSynchronizedSQLQuery(sql);
4237
4238 if (getDB().isSupportsInlineDistinct()) {
4239 q.addEntity(_FILTER_ENTITY_ALIAS, OrganizationImpl.class);
4240 }
4241 else {
4242 q.addEntity(_FILTER_ENTITY_TABLE, OrganizationImpl.class);
4243 }
4244
4245 QueryPos qPos = QueryPos.getInstance(q);
4246
4247 qPos.add(companyId);
4248
4249 qPos.add(parentOrganizationId);
4250
4251 return (List<Organization>)QueryUtil.list(q, getDialect(), start,
4252 end);
4253 }
4254 catch (Exception e) {
4255 throw processException(e);
4256 }
4257 finally {
4258 closeSession(session);
4259 }
4260 }
4261
4262
4272 @Override
4273 public Organization[] filterFindByC_P_PrevAndNext(long organizationId,
4274 long companyId, long parentOrganizationId,
4275 OrderByComparator<Organization> orderByComparator)
4276 throws NoSuchOrganizationException {
4277 if (!InlineSQLHelperUtil.isEnabled()) {
4278 return findByC_P_PrevAndNext(organizationId, companyId,
4279 parentOrganizationId, orderByComparator);
4280 }
4281
4282 Organization organization = findByPrimaryKey(organizationId);
4283
4284 Session session = null;
4285
4286 try {
4287 session = openSession();
4288
4289 Organization[] array = new OrganizationImpl[3];
4290
4291 array[0] = filterGetByC_P_PrevAndNext(session, organization,
4292 companyId, parentOrganizationId, orderByComparator, true);
4293
4294 array[1] = organization;
4295
4296 array[2] = filterGetByC_P_PrevAndNext(session, organization,
4297 companyId, parentOrganizationId, orderByComparator, false);
4298
4299 return array;
4300 }
4301 catch (Exception e) {
4302 throw processException(e);
4303 }
4304 finally {
4305 closeSession(session);
4306 }
4307 }
4308
4309 protected Organization filterGetByC_P_PrevAndNext(Session session,
4310 Organization organization, long companyId, long parentOrganizationId,
4311 OrderByComparator<Organization> orderByComparator, boolean previous) {
4312 StringBundler query = null;
4313
4314 if (orderByComparator != null) {
4315 query = new StringBundler(6 +
4316 (orderByComparator.getOrderByFields().length * 6));
4317 }
4318 else {
4319 query = new StringBundler(3);
4320 }
4321
4322 if (getDB().isSupportsInlineDistinct()) {
4323 query.append(_FILTER_SQL_SELECT_ORGANIZATION_WHERE);
4324 }
4325 else {
4326 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1);
4327 }
4328
4329 query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
4330
4331 query.append(_FINDER_COLUMN_C_P_PARENTORGANIZATIONID_2);
4332
4333 if (!getDB().isSupportsInlineDistinct()) {
4334 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2);
4335 }
4336
4337 if (orderByComparator != null) {
4338 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4339
4340 if (orderByConditionFields.length > 0) {
4341 query.append(WHERE_AND);
4342 }
4343
4344 for (int i = 0; i < orderByConditionFields.length; i++) {
4345 if (getDB().isSupportsInlineDistinct()) {
4346 query.append(_ORDER_BY_ENTITY_ALIAS);
4347 }
4348 else {
4349 query.append(_ORDER_BY_ENTITY_TABLE);
4350 }
4351
4352 query.append(orderByConditionFields[i]);
4353
4354 if ((i + 1) < orderByConditionFields.length) {
4355 if (orderByComparator.isAscending() ^ previous) {
4356 query.append(WHERE_GREATER_THAN_HAS_NEXT);
4357 }
4358 else {
4359 query.append(WHERE_LESSER_THAN_HAS_NEXT);
4360 }
4361 }
4362 else {
4363 if (orderByComparator.isAscending() ^ previous) {
4364 query.append(WHERE_GREATER_THAN);
4365 }
4366 else {
4367 query.append(WHERE_LESSER_THAN);
4368 }
4369 }
4370 }
4371
4372 query.append(ORDER_BY_CLAUSE);
4373
4374 String[] orderByFields = orderByComparator.getOrderByFields();
4375
4376 for (int i = 0; i < orderByFields.length; i++) {
4377 if (getDB().isSupportsInlineDistinct()) {
4378 query.append(_ORDER_BY_ENTITY_ALIAS);
4379 }
4380 else {
4381 query.append(_ORDER_BY_ENTITY_TABLE);
4382 }
4383
4384 query.append(orderByFields[i]);
4385
4386 if ((i + 1) < orderByFields.length) {
4387 if (orderByComparator.isAscending() ^ previous) {
4388 query.append(ORDER_BY_ASC_HAS_NEXT);
4389 }
4390 else {
4391 query.append(ORDER_BY_DESC_HAS_NEXT);
4392 }
4393 }
4394 else {
4395 if (orderByComparator.isAscending() ^ previous) {
4396 query.append(ORDER_BY_ASC);
4397 }
4398 else {
4399 query.append(ORDER_BY_DESC);
4400 }
4401 }
4402 }
4403 }
4404 else {
4405 if (getDB().isSupportsInlineDistinct()) {
4406 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
4407 }
4408 else {
4409 query.append(OrganizationModelImpl.ORDER_BY_SQL);
4410 }
4411 }
4412
4413 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4414 Organization.class.getName(),
4415 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
4416
4417 SQLQuery q = session.createSynchronizedSQLQuery(sql);
4418
4419 q.setFirstResult(0);
4420 q.setMaxResults(2);
4421
4422 if (getDB().isSupportsInlineDistinct()) {
4423 q.addEntity(_FILTER_ENTITY_ALIAS, OrganizationImpl.class);
4424 }
4425 else {
4426 q.addEntity(_FILTER_ENTITY_TABLE, OrganizationImpl.class);
4427 }
4428
4429 QueryPos qPos = QueryPos.getInstance(q);
4430
4431 qPos.add(companyId);
4432
4433 qPos.add(parentOrganizationId);
4434
4435 if (orderByComparator != null) {
4436 Object[] values = orderByComparator.getOrderByConditionValues(organization);
4437
4438 for (Object value : values) {
4439 qPos.add(value);
4440 }
4441 }
4442
4443 List<Organization> list = q.list();
4444
4445 if (list.size() == 2) {
4446 return list.get(1);
4447 }
4448 else {
4449 return null;
4450 }
4451 }
4452
4453
4459 @Override
4460 public void removeByC_P(long companyId, long parentOrganizationId) {
4461 for (Organization organization : findByC_P(companyId,
4462 parentOrganizationId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
4463 remove(organization);
4464 }
4465 }
4466
4467
4474 @Override
4475 public int countByC_P(long companyId, long parentOrganizationId) {
4476 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_P;
4477
4478 Object[] finderArgs = new Object[] { companyId, parentOrganizationId };
4479
4480 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4481 this);
4482
4483 if (count == null) {
4484 StringBundler query = new StringBundler(3);
4485
4486 query.append(_SQL_COUNT_ORGANIZATION_WHERE);
4487
4488 query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
4489
4490 query.append(_FINDER_COLUMN_C_P_PARENTORGANIZATIONID_2);
4491
4492 String sql = query.toString();
4493
4494 Session session = null;
4495
4496 try {
4497 session = openSession();
4498
4499 Query q = session.createQuery(sql);
4500
4501 QueryPos qPos = QueryPos.getInstance(q);
4502
4503 qPos.add(companyId);
4504
4505 qPos.add(parentOrganizationId);
4506
4507 count = (Long)q.uniqueResult();
4508
4509 FinderCacheUtil.putResult(finderPath, finderArgs, count);
4510 }
4511 catch (Exception e) {
4512 FinderCacheUtil.removeResult(finderPath, finderArgs);
4513
4514 throw processException(e);
4515 }
4516 finally {
4517 closeSession(session);
4518 }
4519 }
4520
4521 return count.intValue();
4522 }
4523
4524
4531 @Override
4532 public int filterCountByC_P(long companyId, long parentOrganizationId) {
4533 if (!InlineSQLHelperUtil.isEnabled()) {
4534 return countByC_P(companyId, parentOrganizationId);
4535 }
4536
4537 StringBundler query = new StringBundler(3);
4538
4539 query.append(_FILTER_SQL_COUNT_ORGANIZATION_WHERE);
4540
4541 query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
4542
4543 query.append(_FINDER_COLUMN_C_P_PARENTORGANIZATIONID_2);
4544
4545 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4546 Organization.class.getName(),
4547 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
4548
4549 Session session = null;
4550
4551 try {
4552 session = openSession();
4553
4554 SQLQuery q = session.createSynchronizedSQLQuery(sql);
4555
4556 q.addScalar(COUNT_COLUMN_NAME,
4557 com.liferay.portal.kernel.dao.orm.Type.LONG);
4558
4559 QueryPos qPos = QueryPos.getInstance(q);
4560
4561 qPos.add(companyId);
4562
4563 qPos.add(parentOrganizationId);
4564
4565 Long count = (Long)q.uniqueResult();
4566
4567 return count.intValue();
4568 }
4569 catch (Exception e) {
4570 throw processException(e);
4571 }
4572 finally {
4573 closeSession(session);
4574 }
4575 }
4576
4577 private static final String _FINDER_COLUMN_C_P_COMPANYID_2 = "organization.companyId = ? AND ";
4578 private static final String _FINDER_COLUMN_C_P_PARENTORGANIZATIONID_2 = "organization.parentOrganizationId = ?";
4579 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_T = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
4580 OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
4581 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_T",
4582 new String[] {
4583 Long.class.getName(), String.class.getName(),
4584
4585 Integer.class.getName(), Integer.class.getName(),
4586 OrderByComparator.class.getName()
4587 });
4588 public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_T = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
4589 OrganizationModelImpl.FINDER_CACHE_ENABLED, Long.class,
4590 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByC_T",
4591 new String[] { Long.class.getName(), String.class.getName() });
4592
4593
4600 @Override
4601 public List<Organization> findByC_T(long companyId, String treePath) {
4602 return findByC_T(companyId, treePath, QueryUtil.ALL_POS,
4603 QueryUtil.ALL_POS, null);
4604 }
4605
4606
4619 @Override
4620 public List<Organization> findByC_T(long companyId, String treePath,
4621 int start, int end) {
4622 return findByC_T(companyId, treePath, start, end, null);
4623 }
4624
4625
4639 @Override
4640 public List<Organization> findByC_T(long companyId, String treePath,
4641 int start, int end, OrderByComparator<Organization> orderByComparator) {
4642 boolean pagination = true;
4643 FinderPath finderPath = null;
4644 Object[] finderArgs = null;
4645
4646 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_T;
4647 finderArgs = new Object[] {
4648 companyId, treePath,
4649
4650 start, end, orderByComparator
4651 };
4652
4653 List<Organization> list = (List<Organization>)FinderCacheUtil.getResult(finderPath,
4654 finderArgs, this);
4655
4656 if ((list != null) && !list.isEmpty()) {
4657 for (Organization organization : list) {
4658 if ((companyId != organization.getCompanyId()) ||
4659 !StringUtil.wildcardMatches(
4660 organization.getTreePath(), treePath,
4661 CharPool.UNDERLINE, CharPool.PERCENT,
4662 CharPool.BACK_SLASH, true)) {
4663 list = null;
4664
4665 break;
4666 }
4667 }
4668 }
4669
4670 if (list == null) {
4671 StringBundler query = null;
4672
4673 if (orderByComparator != null) {
4674 query = new StringBundler(4 +
4675 (orderByComparator.getOrderByFields().length * 3));
4676 }
4677 else {
4678 query = new StringBundler(4);
4679 }
4680
4681 query.append(_SQL_SELECT_ORGANIZATION_WHERE);
4682
4683 query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
4684
4685 boolean bindTreePath = false;
4686
4687 if (treePath == null) {
4688 query.append(_FINDER_COLUMN_C_T_TREEPATH_1);
4689 }
4690 else if (treePath.equals(StringPool.BLANK)) {
4691 query.append(_FINDER_COLUMN_C_T_TREEPATH_3);
4692 }
4693 else {
4694 bindTreePath = true;
4695
4696 query.append(_FINDER_COLUMN_C_T_TREEPATH_2);
4697 }
4698
4699 if (orderByComparator != null) {
4700 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4701 orderByComparator);
4702 }
4703 else
4704 if (pagination) {
4705 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
4706 }
4707
4708 String sql = query.toString();
4709
4710 Session session = null;
4711
4712 try {
4713 session = openSession();
4714
4715 Query q = session.createQuery(sql);
4716
4717 QueryPos qPos = QueryPos.getInstance(q);
4718
4719 qPos.add(companyId);
4720
4721 if (bindTreePath) {
4722 qPos.add(treePath);
4723 }
4724
4725 if (!pagination) {
4726 list = (List<Organization>)QueryUtil.list(q, getDialect(),
4727 start, end, false);
4728
4729 Collections.sort(list);
4730
4731 list = Collections.unmodifiableList(list);
4732 }
4733 else {
4734 list = (List<Organization>)QueryUtil.list(q, getDialect(),
4735 start, end);
4736 }
4737
4738 cacheResult(list);
4739
4740 FinderCacheUtil.putResult(finderPath, finderArgs, list);
4741 }
4742 catch (Exception e) {
4743 FinderCacheUtil.removeResult(finderPath, finderArgs);
4744
4745 throw processException(e);
4746 }
4747 finally {
4748 closeSession(session);
4749 }
4750 }
4751
4752 return list;
4753 }
4754
4755
4764 @Override
4765 public Organization findByC_T_First(long companyId, String treePath,
4766 OrderByComparator<Organization> orderByComparator)
4767 throws NoSuchOrganizationException {
4768 Organization organization = fetchByC_T_First(companyId, treePath,
4769 orderByComparator);
4770
4771 if (organization != null) {
4772 return organization;
4773 }
4774
4775 StringBundler msg = new StringBundler(6);
4776
4777 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4778
4779 msg.append("companyId=");
4780 msg.append(companyId);
4781
4782 msg.append(", treePath=");
4783 msg.append(treePath);
4784
4785 msg.append(StringPool.CLOSE_CURLY_BRACE);
4786
4787 throw new NoSuchOrganizationException(msg.toString());
4788 }
4789
4790
4798 @Override
4799 public Organization fetchByC_T_First(long companyId, String treePath,
4800 OrderByComparator<Organization> orderByComparator) {
4801 List<Organization> list = findByC_T(companyId, treePath, 0, 1,
4802 orderByComparator);
4803
4804 if (!list.isEmpty()) {
4805 return list.get(0);
4806 }
4807
4808 return null;
4809 }
4810
4811
4820 @Override
4821 public Organization findByC_T_Last(long companyId, String treePath,
4822 OrderByComparator<Organization> orderByComparator)
4823 throws NoSuchOrganizationException {
4824 Organization organization = fetchByC_T_Last(companyId, treePath,
4825 orderByComparator);
4826
4827 if (organization != null) {
4828 return organization;
4829 }
4830
4831 StringBundler msg = new StringBundler(6);
4832
4833 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4834
4835 msg.append("companyId=");
4836 msg.append(companyId);
4837
4838 msg.append(", treePath=");
4839 msg.append(treePath);
4840
4841 msg.append(StringPool.CLOSE_CURLY_BRACE);
4842
4843 throw new NoSuchOrganizationException(msg.toString());
4844 }
4845
4846
4854 @Override
4855 public Organization fetchByC_T_Last(long companyId, String treePath,
4856 OrderByComparator<Organization> orderByComparator) {
4857 int count = countByC_T(companyId, treePath);
4858
4859 if (count == 0) {
4860 return null;
4861 }
4862
4863 List<Organization> list = findByC_T(companyId, treePath, count - 1,
4864 count, orderByComparator);
4865
4866 if (!list.isEmpty()) {
4867 return list.get(0);
4868 }
4869
4870 return null;
4871 }
4872
4873
4883 @Override
4884 public Organization[] findByC_T_PrevAndNext(long organizationId,
4885 long companyId, String treePath,
4886 OrderByComparator<Organization> orderByComparator)
4887 throws NoSuchOrganizationException {
4888 Organization organization = findByPrimaryKey(organizationId);
4889
4890 Session session = null;
4891
4892 try {
4893 session = openSession();
4894
4895 Organization[] array = new OrganizationImpl[3];
4896
4897 array[0] = getByC_T_PrevAndNext(session, organization, companyId,
4898 treePath, orderByComparator, true);
4899
4900 array[1] = organization;
4901
4902 array[2] = getByC_T_PrevAndNext(session, organization, companyId,
4903 treePath, orderByComparator, false);
4904
4905 return array;
4906 }
4907 catch (Exception e) {
4908 throw processException(e);
4909 }
4910 finally {
4911 closeSession(session);
4912 }
4913 }
4914
4915 protected Organization getByC_T_PrevAndNext(Session session,
4916 Organization organization, long companyId, String treePath,
4917 OrderByComparator<Organization> orderByComparator, boolean previous) {
4918 StringBundler query = null;
4919
4920 if (orderByComparator != null) {
4921 query = new StringBundler(6 +
4922 (orderByComparator.getOrderByFields().length * 6));
4923 }
4924 else {
4925 query = new StringBundler(3);
4926 }
4927
4928 query.append(_SQL_SELECT_ORGANIZATION_WHERE);
4929
4930 query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
4931
4932 boolean bindTreePath = false;
4933
4934 if (treePath == null) {
4935 query.append(_FINDER_COLUMN_C_T_TREEPATH_1);
4936 }
4937 else if (treePath.equals(StringPool.BLANK)) {
4938 query.append(_FINDER_COLUMN_C_T_TREEPATH_3);
4939 }
4940 else {
4941 bindTreePath = true;
4942
4943 query.append(_FINDER_COLUMN_C_T_TREEPATH_2);
4944 }
4945
4946 if (orderByComparator != null) {
4947 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4948
4949 if (orderByConditionFields.length > 0) {
4950 query.append(WHERE_AND);
4951 }
4952
4953 for (int i = 0; i < orderByConditionFields.length; i++) {
4954 query.append(_ORDER_BY_ENTITY_ALIAS);
4955 query.append(orderByConditionFields[i]);
4956
4957 if ((i + 1) < orderByConditionFields.length) {
4958 if (orderByComparator.isAscending() ^ previous) {
4959 query.append(WHERE_GREATER_THAN_HAS_NEXT);
4960 }
4961 else {
4962 query.append(WHERE_LESSER_THAN_HAS_NEXT);
4963 }
4964 }
4965 else {
4966 if (orderByComparator.isAscending() ^ previous) {
4967 query.append(WHERE_GREATER_THAN);
4968 }
4969 else {
4970 query.append(WHERE_LESSER_THAN);
4971 }
4972 }
4973 }
4974
4975 query.append(ORDER_BY_CLAUSE);
4976
4977 String[] orderByFields = orderByComparator.getOrderByFields();
4978
4979 for (int i = 0; i < orderByFields.length; i++) {
4980 query.append(_ORDER_BY_ENTITY_ALIAS);
4981 query.append(orderByFields[i]);
4982
4983 if ((i + 1) < orderByFields.length) {
4984 if (orderByComparator.isAscending() ^ previous) {
4985 query.append(ORDER_BY_ASC_HAS_NEXT);
4986 }
4987 else {
4988 query.append(ORDER_BY_DESC_HAS_NEXT);
4989 }
4990 }
4991 else {
4992 if (orderByComparator.isAscending() ^ previous) {
4993 query.append(ORDER_BY_ASC);
4994 }
4995 else {
4996 query.append(ORDER_BY_DESC);
4997 }
4998 }
4999 }
5000 }
5001 else {
5002 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
5003 }
5004
5005 String sql = query.toString();
5006
5007 Query q = session.createQuery(sql);
5008
5009 q.setFirstResult(0);
5010 q.setMaxResults(2);
5011
5012 QueryPos qPos = QueryPos.getInstance(q);
5013
5014 qPos.add(companyId);
5015
5016 if (bindTreePath) {
5017 qPos.add(treePath);
5018 }
5019
5020 if (orderByComparator != null) {
5021 Object[] values = orderByComparator.getOrderByConditionValues(organization);
5022
5023 for (Object value : values) {
5024 qPos.add(value);
5025 }
5026 }
5027
5028 List<Organization> list = q.list();
5029
5030 if (list.size() == 2) {
5031 return list.get(1);
5032 }
5033 else {
5034 return null;
5035 }
5036 }
5037
5038
5045 @Override
5046 public List<Organization> filterFindByC_T(long companyId, String treePath) {
5047 return filterFindByC_T(companyId, treePath, QueryUtil.ALL_POS,
5048 QueryUtil.ALL_POS, null);
5049 }
5050
5051
5064 @Override
5065 public List<Organization> filterFindByC_T(long companyId, String treePath,
5066 int start, int end) {
5067 return filterFindByC_T(companyId, treePath, start, end, null);
5068 }
5069
5070
5084 @Override
5085 public List<Organization> filterFindByC_T(long companyId, String treePath,
5086 int start, int end, OrderByComparator<Organization> orderByComparator) {
5087 if (!InlineSQLHelperUtil.isEnabled()) {
5088 return findByC_T(companyId, treePath, start, end, orderByComparator);
5089 }
5090
5091 StringBundler query = null;
5092
5093 if (orderByComparator != null) {
5094 query = new StringBundler(4 +
5095 (orderByComparator.getOrderByFields().length * 3));
5096 }
5097 else {
5098 query = new StringBundler(4);
5099 }
5100
5101 if (getDB().isSupportsInlineDistinct()) {
5102 query.append(_FILTER_SQL_SELECT_ORGANIZATION_WHERE);
5103 }
5104 else {
5105 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1);
5106 }
5107
5108 query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
5109
5110 boolean bindTreePath = false;
5111
5112 if (treePath == null) {
5113 query.append(_FINDER_COLUMN_C_T_TREEPATH_1);
5114 }
5115 else if (treePath.equals(StringPool.BLANK)) {
5116 query.append(_FINDER_COLUMN_C_T_TREEPATH_3);
5117 }
5118 else {
5119 bindTreePath = true;
5120
5121 query.append(_FINDER_COLUMN_C_T_TREEPATH_2);
5122 }
5123
5124 if (!getDB().isSupportsInlineDistinct()) {
5125 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2);
5126 }
5127
5128 if (orderByComparator != null) {
5129 if (getDB().isSupportsInlineDistinct()) {
5130 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5131 orderByComparator, true);
5132 }
5133 else {
5134 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
5135 orderByComparator, true);
5136 }
5137 }
5138 else {
5139 if (getDB().isSupportsInlineDistinct()) {
5140 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
5141 }
5142 else {
5143 query.append(OrganizationModelImpl.ORDER_BY_SQL);
5144 }
5145 }
5146
5147 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5148 Organization.class.getName(),
5149 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
5150
5151 Session session = null;
5152
5153 try {
5154 session = openSession();
5155
5156 SQLQuery q = session.createSynchronizedSQLQuery(sql);
5157
5158 if (getDB().isSupportsInlineDistinct()) {
5159 q.addEntity(_FILTER_ENTITY_ALIAS, OrganizationImpl.class);
5160 }
5161 else {
5162 q.addEntity(_FILTER_ENTITY_TABLE, OrganizationImpl.class);
5163 }
5164
5165 QueryPos qPos = QueryPos.getInstance(q);
5166
5167 qPos.add(companyId);
5168
5169 if (bindTreePath) {
5170 qPos.add(treePath);
5171 }
5172
5173 return (List<Organization>)QueryUtil.list(q, getDialect(), start,
5174 end);
5175 }
5176 catch (Exception e) {
5177 throw processException(e);
5178 }
5179 finally {
5180 closeSession(session);
5181 }
5182 }
5183
5184
5194 @Override
5195 public Organization[] filterFindByC_T_PrevAndNext(long organizationId,
5196 long companyId, String treePath,
5197 OrderByComparator<Organization> orderByComparator)
5198 throws NoSuchOrganizationException {
5199 if (!InlineSQLHelperUtil.isEnabled()) {
5200 return findByC_T_PrevAndNext(organizationId, companyId, treePath,
5201 orderByComparator);
5202 }
5203
5204 Organization organization = findByPrimaryKey(organizationId);
5205
5206 Session session = null;
5207
5208 try {
5209 session = openSession();
5210
5211 Organization[] array = new OrganizationImpl[3];
5212
5213 array[0] = filterGetByC_T_PrevAndNext(session, organization,
5214 companyId, treePath, orderByComparator, true);
5215
5216 array[1] = organization;
5217
5218 array[2] = filterGetByC_T_PrevAndNext(session, organization,
5219 companyId, treePath, orderByComparator, false);
5220
5221 return array;
5222 }
5223 catch (Exception e) {
5224 throw processException(e);
5225 }
5226 finally {
5227 closeSession(session);
5228 }
5229 }
5230
5231 protected Organization filterGetByC_T_PrevAndNext(Session session,
5232 Organization organization, long companyId, String treePath,
5233 OrderByComparator<Organization> orderByComparator, boolean previous) {
5234 StringBundler query = null;
5235
5236 if (orderByComparator != null) {
5237 query = new StringBundler(6 +
5238 (orderByComparator.getOrderByFields().length * 6));
5239 }
5240 else {
5241 query = new StringBundler(3);
5242 }
5243
5244 if (getDB().isSupportsInlineDistinct()) {
5245 query.append(_FILTER_SQL_SELECT_ORGANIZATION_WHERE);
5246 }
5247 else {
5248 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1);
5249 }
5250
5251 query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
5252
5253 boolean bindTreePath = false;
5254
5255 if (treePath == null) {
5256 query.append(_FINDER_COLUMN_C_T_TREEPATH_1);
5257 }
5258 else if (treePath.equals(StringPool.BLANK)) {
5259 query.append(_FINDER_COLUMN_C_T_TREEPATH_3);
5260 }
5261 else {
5262 bindTreePath = true;
5263
5264 query.append(_FINDER_COLUMN_C_T_TREEPATH_2);
5265 }
5266
5267 if (!getDB().isSupportsInlineDistinct()) {
5268 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2);
5269 }
5270
5271 if (orderByComparator != null) {
5272 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5273
5274 if (orderByConditionFields.length > 0) {
5275 query.append(WHERE_AND);
5276 }
5277
5278 for (int i = 0; i < orderByConditionFields.length; i++) {
5279 if (getDB().isSupportsInlineDistinct()) {
5280 query.append(_ORDER_BY_ENTITY_ALIAS);
5281 }
5282 else {
5283 query.append(_ORDER_BY_ENTITY_TABLE);
5284 }
5285
5286 query.append(orderByConditionFields[i]);
5287
5288 if ((i + 1) < orderByConditionFields.length) {
5289 if (orderByComparator.isAscending() ^ previous) {
5290 query.append(WHERE_GREATER_THAN_HAS_NEXT);
5291 }
5292 else {
5293 query.append(WHERE_LESSER_THAN_HAS_NEXT);
5294 }
5295 }
5296 else {
5297 if (orderByComparator.isAscending() ^ previous) {
5298 query.append(WHERE_GREATER_THAN);
5299 }
5300 else {
5301 query.append(WHERE_LESSER_THAN);
5302 }
5303 }
5304 }
5305
5306 query.append(ORDER_BY_CLAUSE);
5307
5308 String[] orderByFields = orderByComparator.getOrderByFields();
5309
5310 for (int i = 0; i < orderByFields.length; i++) {
5311 if (getDB().isSupportsInlineDistinct()) {
5312 query.append(_ORDER_BY_ENTITY_ALIAS);
5313 }
5314 else {
5315 query.append(_ORDER_BY_ENTITY_TABLE);
5316 }
5317
5318 query.append(orderByFields[i]);
5319
5320 if ((i + 1) < orderByFields.length) {
5321 if (orderByComparator.isAscending() ^ previous) {
5322 query.append(ORDER_BY_ASC_HAS_NEXT);
5323 }
5324 else {
5325 query.append(ORDER_BY_DESC_HAS_NEXT);
5326 }
5327 }
5328 else {
5329 if (orderByComparator.isAscending() ^ previous) {
5330 query.append(ORDER_BY_ASC);
5331 }
5332 else {
5333 query.append(ORDER_BY_DESC);
5334 }
5335 }
5336 }
5337 }
5338 else {
5339 if (getDB().isSupportsInlineDistinct()) {
5340 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
5341 }
5342 else {
5343 query.append(OrganizationModelImpl.ORDER_BY_SQL);
5344 }
5345 }
5346
5347 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5348 Organization.class.getName(),
5349 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
5350
5351 SQLQuery q = session.createSynchronizedSQLQuery(sql);
5352
5353 q.setFirstResult(0);
5354 q.setMaxResults(2);
5355
5356 if (getDB().isSupportsInlineDistinct()) {
5357 q.addEntity(_FILTER_ENTITY_ALIAS, OrganizationImpl.class);
5358 }
5359 else {
5360 q.addEntity(_FILTER_ENTITY_TABLE, OrganizationImpl.class);
5361 }
5362
5363 QueryPos qPos = QueryPos.getInstance(q);
5364
5365 qPos.add(companyId);
5366
5367 if (bindTreePath) {
5368 qPos.add(treePath);
5369 }
5370
5371 if (orderByComparator != null) {
5372 Object[] values = orderByComparator.getOrderByConditionValues(organization);
5373
5374 for (Object value : values) {
5375 qPos.add(value);
5376 }
5377 }
5378
5379 List<Organization> list = q.list();
5380
5381 if (list.size() == 2) {
5382 return list.get(1);
5383 }
5384 else {
5385 return null;
5386 }
5387 }
5388
5389
5395 @Override
5396 public void removeByC_T(long companyId, String treePath) {
5397 for (Organization organization : findByC_T(companyId, treePath,
5398 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
5399 remove(organization);
5400 }
5401 }
5402
5403
5410 @Override
5411 public int countByC_T(long companyId, String treePath) {
5412 FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_T;
5413
5414 Object[] finderArgs = new Object[] { companyId, treePath };
5415
5416 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5417 this);
5418
5419 if (count == null) {
5420 StringBundler query = new StringBundler(3);
5421
5422 query.append(_SQL_COUNT_ORGANIZATION_WHERE);
5423
5424 query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
5425
5426 boolean bindTreePath = false;
5427
5428 if (treePath == null) {
5429 query.append(_FINDER_COLUMN_C_T_TREEPATH_1);
5430 }
5431 else if (treePath.equals(StringPool.BLANK)) {
5432 query.append(_FINDER_COLUMN_C_T_TREEPATH_3);
5433 }
5434 else {
5435 bindTreePath = true;
5436
5437 query.append(_FINDER_COLUMN_C_T_TREEPATH_2);
5438 }
5439
5440 String sql = query.toString();
5441
5442 Session session = null;
5443
5444 try {
5445 session = openSession();
5446
5447 Query q = session.createQuery(sql);
5448
5449 QueryPos qPos = QueryPos.getInstance(q);
5450
5451 qPos.add(companyId);
5452
5453 if (bindTreePath) {
5454 qPos.add(treePath);
5455 }
5456
5457 count = (Long)q.uniqueResult();
5458
5459 FinderCacheUtil.putResult(finderPath, finderArgs, count);
5460 }
5461 catch (Exception e) {
5462 FinderCacheUtil.removeResult(finderPath, finderArgs);
5463
5464 throw processException(e);
5465 }
5466 finally {
5467 closeSession(session);
5468 }
5469 }
5470
5471 return count.intValue();
5472 }
5473
5474
5481 @Override
5482 public int filterCountByC_T(long companyId, String treePath) {
5483 if (!InlineSQLHelperUtil.isEnabled()) {
5484 return countByC_T(companyId, treePath);
5485 }
5486
5487 StringBundler query = new StringBundler(3);
5488
5489 query.append(_FILTER_SQL_COUNT_ORGANIZATION_WHERE);
5490
5491 query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
5492
5493 boolean bindTreePath = false;
5494
5495 if (treePath == null) {
5496 query.append(_FINDER_COLUMN_C_T_TREEPATH_1);
5497 }
5498 else if (treePath.equals(StringPool.BLANK)) {
5499 query.append(_FINDER_COLUMN_C_T_TREEPATH_3);
5500 }
5501 else {
5502 bindTreePath = true;
5503
5504 query.append(_FINDER_COLUMN_C_T_TREEPATH_2);
5505 }
5506
5507 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5508 Organization.class.getName(),
5509 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
5510
5511 Session session = null;
5512
5513 try {
5514 session = openSession();
5515
5516 SQLQuery q = session.createSynchronizedSQLQuery(sql);
5517
5518 q.addScalar(COUNT_COLUMN_NAME,
5519 com.liferay.portal.kernel.dao.orm.Type.LONG);
5520
5521 QueryPos qPos = QueryPos.getInstance(q);
5522
5523 qPos.add(companyId);
5524
5525 if (bindTreePath) {
5526 qPos.add(treePath);
5527 }
5528
5529 Long count = (Long)q.uniqueResult();
5530
5531 return count.intValue();
5532 }
5533 catch (Exception e) {
5534 throw processException(e);
5535 }
5536 finally {
5537 closeSession(session);
5538 }
5539 }
5540
5541 private static final String _FINDER_COLUMN_C_T_COMPANYID_2 = "organization.companyId = ? AND ";
5542 private static final String _FINDER_COLUMN_C_T_TREEPATH_1 = "organization.treePath LIKE NULL";
5543 private static final String _FINDER_COLUMN_C_T_TREEPATH_2 = "organization.treePath LIKE ?";
5544 private static final String _FINDER_COLUMN_C_T_TREEPATH_3 = "(organization.treePath IS NULL OR organization.treePath LIKE '')";
5545 public static final FinderPath FINDER_PATH_FETCH_BY_C_N = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
5546 OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
5547 FINDER_CLASS_NAME_ENTITY, "fetchByC_N",
5548 new String[] { Long.class.getName(), String.class.getName() },
5549 OrganizationModelImpl.COMPANYID_COLUMN_BITMASK |
5550 OrganizationModelImpl.NAME_COLUMN_BITMASK);
5551 public static final FinderPath FINDER_PATH_COUNT_BY_C_N = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
5552 OrganizationModelImpl.FINDER_CACHE_ENABLED, Long.class,
5553 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_N",
5554 new String[] { Long.class.getName(), String.class.getName() });
5555
5556
5564 @Override
5565 public Organization findByC_N(long companyId, String name)
5566 throws NoSuchOrganizationException {
5567 Organization organization = fetchByC_N(companyId, name);
5568
5569 if (organization == null) {
5570 StringBundler msg = new StringBundler(6);
5571
5572 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5573
5574 msg.append("companyId=");
5575 msg.append(companyId);
5576
5577 msg.append(", name=");
5578 msg.append(name);
5579
5580 msg.append(StringPool.CLOSE_CURLY_BRACE);
5581
5582 if (_log.isWarnEnabled()) {
5583 _log.warn(msg.toString());
5584 }
5585
5586 throw new NoSuchOrganizationException(msg.toString());
5587 }
5588
5589 return organization;
5590 }
5591
5592
5599 @Override
5600 public Organization fetchByC_N(long companyId, String name) {
5601 return fetchByC_N(companyId, name, true);
5602 }
5603
5604
5612 @Override
5613 public Organization fetchByC_N(long companyId, String name,
5614 boolean retrieveFromCache) {
5615 Object[] finderArgs = new Object[] { companyId, name };
5616
5617 Object result = null;
5618
5619 if (retrieveFromCache) {
5620 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_N,
5621 finderArgs, this);
5622 }
5623
5624 if (result instanceof Organization) {
5625 Organization organization = (Organization)result;
5626
5627 if ((companyId != organization.getCompanyId()) ||
5628 !Validator.equals(name, organization.getName())) {
5629 result = null;
5630 }
5631 }
5632
5633 if (result == null) {
5634 StringBundler query = new StringBundler(4);
5635
5636 query.append(_SQL_SELECT_ORGANIZATION_WHERE);
5637
5638 query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
5639
5640 boolean bindName = false;
5641
5642 if (name == null) {
5643 query.append(_FINDER_COLUMN_C_N_NAME_1);
5644 }
5645 else if (name.equals(StringPool.BLANK)) {
5646 query.append(_FINDER_COLUMN_C_N_NAME_3);
5647 }
5648 else {
5649 bindName = true;
5650
5651 query.append(_FINDER_COLUMN_C_N_NAME_2);
5652 }
5653
5654 String sql = query.toString();
5655
5656 Session session = null;
5657
5658 try {
5659 session = openSession();
5660
5661 Query q = session.createQuery(sql);
5662
5663 QueryPos qPos = QueryPos.getInstance(q);
5664
5665 qPos.add(companyId);
5666
5667 if (bindName) {
5668 qPos.add(name);
5669 }
5670
5671 List<Organization> list = q.list();
5672
5673 if (list.isEmpty()) {
5674 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
5675 finderArgs, list);
5676 }
5677 else {
5678 Organization organization = list.get(0);
5679
5680 result = organization;
5681
5682 cacheResult(organization);
5683
5684 if ((organization.getCompanyId() != companyId) ||
5685 (organization.getName() == null) ||
5686 !organization.getName().equals(name)) {
5687 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
5688 finderArgs, organization);
5689 }
5690 }
5691 }
5692 catch (Exception e) {
5693 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N,
5694 finderArgs);
5695
5696 throw processException(e);
5697 }
5698 finally {
5699 closeSession(session);
5700 }
5701 }
5702
5703 if (result instanceof List<?>) {
5704 return null;
5705 }
5706 else {
5707 return (Organization)result;
5708 }
5709 }
5710
5711
5718 @Override
5719 public Organization removeByC_N(long companyId, String name)
5720 throws NoSuchOrganizationException {
5721 Organization organization = findByC_N(companyId, name);
5722
5723 return remove(organization);
5724 }
5725
5726
5733 @Override
5734 public int countByC_N(long companyId, String name) {
5735 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_N;
5736
5737 Object[] finderArgs = new Object[] { companyId, name };
5738
5739 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5740 this);
5741
5742 if (count == null) {
5743 StringBundler query = new StringBundler(3);
5744
5745 query.append(_SQL_COUNT_ORGANIZATION_WHERE);
5746
5747 query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
5748
5749 boolean bindName = false;
5750
5751 if (name == null) {
5752 query.append(_FINDER_COLUMN_C_N_NAME_1);
5753 }
5754 else if (name.equals(StringPool.BLANK)) {
5755 query.append(_FINDER_COLUMN_C_N_NAME_3);
5756 }
5757 else {
5758 bindName = true;
5759
5760 query.append(_FINDER_COLUMN_C_N_NAME_2);
5761 }
5762
5763 String sql = query.toString();
5764
5765 Session session = null;
5766
5767 try {
5768 session = openSession();
5769
5770 Query q = session.createQuery(sql);
5771
5772 QueryPos qPos = QueryPos.getInstance(q);
5773
5774 qPos.add(companyId);
5775
5776 if (bindName) {
5777 qPos.add(name);
5778 }
5779
5780 count = (Long)q.uniqueResult();
5781
5782 FinderCacheUtil.putResult(finderPath, finderArgs, count);
5783 }
5784 catch (Exception e) {
5785 FinderCacheUtil.removeResult(finderPath, finderArgs);
5786
5787 throw processException(e);
5788 }
5789 finally {
5790 closeSession(session);
5791 }
5792 }
5793
5794 return count.intValue();
5795 }
5796
5797 private static final String _FINDER_COLUMN_C_N_COMPANYID_2 = "organization.companyId = ? AND ";
5798 private static final String _FINDER_COLUMN_C_N_NAME_1 = "organization.name IS NULL";
5799 private static final String _FINDER_COLUMN_C_N_NAME_2 = "organization.name = ?";
5800 private static final String _FINDER_COLUMN_C_N_NAME_3 = "(organization.name IS NULL OR organization.name = '')";
5801 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_O_C_P = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
5802 OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
5803 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByO_C_P",
5804 new String[] {
5805 Long.class.getName(), Long.class.getName(), Long.class.getName(),
5806
5807 Integer.class.getName(), Integer.class.getName(),
5808 OrderByComparator.class.getName()
5809 });
5810 public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_O_C_P = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
5811 OrganizationModelImpl.FINDER_CACHE_ENABLED, Long.class,
5812 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByO_C_P",
5813 new String[] {
5814 Long.class.getName(), Long.class.getName(), Long.class.getName()
5815 });
5816
5817
5825 @Override
5826 public List<Organization> findByO_C_P(long organizationId, long companyId,
5827 long parentOrganizationId) {
5828 return findByO_C_P(organizationId, companyId, parentOrganizationId,
5829 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
5830 }
5831
5832
5846 @Override
5847 public List<Organization> findByO_C_P(long organizationId, long companyId,
5848 long parentOrganizationId, int start, int end) {
5849 return findByO_C_P(organizationId, companyId, parentOrganizationId,
5850 start, end, null);
5851 }
5852
5853
5868 @Override
5869 public List<Organization> findByO_C_P(long organizationId, long companyId,
5870 long parentOrganizationId, int start, int end,
5871 OrderByComparator<Organization> orderByComparator) {
5872 boolean pagination = true;
5873 FinderPath finderPath = null;
5874 Object[] finderArgs = null;
5875
5876 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_O_C_P;
5877 finderArgs = new Object[] {
5878 organizationId, companyId, parentOrganizationId,
5879
5880 start, end, orderByComparator
5881 };
5882
5883 List<Organization> list = (List<Organization>)FinderCacheUtil.getResult(finderPath,
5884 finderArgs, this);
5885
5886 if ((list != null) && !list.isEmpty()) {
5887 for (Organization organization : list) {
5888 if ((organizationId >= organization.getOrganizationId()) ||
5889 (companyId != organization.getCompanyId()) ||
5890 (parentOrganizationId != organization.getParentOrganizationId())) {
5891 list = null;
5892
5893 break;
5894 }
5895 }
5896 }
5897
5898 if (list == null) {
5899 StringBundler query = null;
5900
5901 if (orderByComparator != null) {
5902 query = new StringBundler(5 +
5903 (orderByComparator.getOrderByFields().length * 3));
5904 }
5905 else {
5906 query = new StringBundler(5);
5907 }
5908
5909 query.append(_SQL_SELECT_ORGANIZATION_WHERE);
5910
5911 query.append(_FINDER_COLUMN_O_C_P_ORGANIZATIONID_2);
5912
5913 query.append(_FINDER_COLUMN_O_C_P_COMPANYID_2);
5914
5915 query.append(_FINDER_COLUMN_O_C_P_PARENTORGANIZATIONID_2);
5916
5917 if (orderByComparator != null) {
5918 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5919 orderByComparator);
5920 }
5921 else
5922 if (pagination) {
5923 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
5924 }
5925
5926 String sql = query.toString();
5927
5928 Session session = null;
5929
5930 try {
5931 session = openSession();
5932
5933 Query q = session.createQuery(sql);
5934
5935 QueryPos qPos = QueryPos.getInstance(q);
5936
5937 qPos.add(organizationId);
5938
5939 qPos.add(companyId);
5940
5941 qPos.add(parentOrganizationId);
5942
5943 if (!pagination) {
5944 list = (List<Organization>)QueryUtil.list(q, getDialect(),
5945 start, end, false);
5946
5947 Collections.sort(list);
5948
5949 list = Collections.unmodifiableList(list);
5950 }
5951 else {
5952 list = (List<Organization>)QueryUtil.list(q, getDialect(),
5953 start, end);
5954 }
5955
5956 cacheResult(list);
5957
5958 FinderCacheUtil.putResult(finderPath, finderArgs, list);
5959 }
5960 catch (Exception e) {
5961 FinderCacheUtil.removeResult(finderPath, finderArgs);
5962
5963 throw processException(e);
5964 }
5965 finally {
5966 closeSession(session);
5967 }
5968 }
5969
5970 return list;
5971 }
5972
5973
5983 @Override
5984 public Organization findByO_C_P_First(long organizationId, long companyId,
5985 long parentOrganizationId,
5986 OrderByComparator<Organization> orderByComparator)
5987 throws NoSuchOrganizationException {
5988 Organization organization = fetchByO_C_P_First(organizationId,
5989 companyId, parentOrganizationId, orderByComparator);
5990
5991 if (organization != null) {
5992 return organization;
5993 }
5994
5995 StringBundler msg = new StringBundler(8);
5996
5997 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5998
5999 msg.append("organizationId=");
6000 msg.append(organizationId);
6001
6002 msg.append(", companyId=");
6003 msg.append(companyId);
6004
6005 msg.append(", parentOrganizationId=");
6006 msg.append(parentOrganizationId);
6007
6008 msg.append(StringPool.CLOSE_CURLY_BRACE);
6009
6010 throw new NoSuchOrganizationException(msg.toString());
6011 }
6012
6013
6022 @Override
6023 public Organization fetchByO_C_P_First(long organizationId, long companyId,
6024 long parentOrganizationId,
6025 OrderByComparator<Organization> orderByComparator) {
6026 List<Organization> list = findByO_C_P(organizationId, companyId,
6027 parentOrganizationId, 0, 1, orderByComparator);
6028
6029 if (!list.isEmpty()) {
6030 return list.get(0);
6031 }
6032
6033 return null;
6034 }
6035
6036
6046 @Override
6047 public Organization findByO_C_P_Last(long organizationId, long companyId,
6048 long parentOrganizationId,
6049 OrderByComparator<Organization> orderByComparator)
6050 throws NoSuchOrganizationException {
6051 Organization organization = fetchByO_C_P_Last(organizationId,
6052 companyId, parentOrganizationId, orderByComparator);
6053
6054 if (organization != null) {
6055 return organization;
6056 }
6057
6058 StringBundler msg = new StringBundler(8);
6059
6060 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6061
6062 msg.append("organizationId=");
6063 msg.append(organizationId);
6064
6065 msg.append(", companyId=");
6066 msg.append(companyId);
6067
6068 msg.append(", parentOrganizationId=");
6069 msg.append(parentOrganizationId);
6070
6071 msg.append(StringPool.CLOSE_CURLY_BRACE);
6072
6073 throw new NoSuchOrganizationException(msg.toString());
6074 }
6075
6076
6085 @Override
6086 public Organization fetchByO_C_P_Last(long organizationId, long companyId,
6087 long parentOrganizationId,
6088 OrderByComparator<Organization> orderByComparator) {
6089 int count = countByO_C_P(organizationId, companyId, parentOrganizationId);
6090
6091 if (count == 0) {
6092 return null;
6093 }
6094
6095 List<Organization> list = findByO_C_P(organizationId, companyId,
6096 parentOrganizationId, count - 1, count, orderByComparator);
6097
6098 if (!list.isEmpty()) {
6099 return list.get(0);
6100 }
6101
6102 return null;
6103 }
6104
6105
6113 @Override
6114 public List<Organization> filterFindByO_C_P(long organizationId,
6115 long companyId, long parentOrganizationId) {
6116 return filterFindByO_C_P(organizationId, companyId,
6117 parentOrganizationId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
6118 }
6119
6120
6134 @Override
6135 public List<Organization> filterFindByO_C_P(long organizationId,
6136 long companyId, long parentOrganizationId, int start, int end) {
6137 return filterFindByO_C_P(organizationId, companyId,
6138 parentOrganizationId, start, end, null);
6139 }
6140
6141
6156 @Override
6157 public List<Organization> filterFindByO_C_P(long organizationId,
6158 long companyId, long parentOrganizationId, int start, int end,
6159 OrderByComparator<Organization> orderByComparator) {
6160 if (!InlineSQLHelperUtil.isEnabled()) {
6161 return findByO_C_P(organizationId, companyId, parentOrganizationId,
6162 start, end, orderByComparator);
6163 }
6164
6165 StringBundler query = null;
6166
6167 if (orderByComparator != null) {
6168 query = new StringBundler(5 +
6169 (orderByComparator.getOrderByFields().length * 3));
6170 }
6171 else {
6172 query = new StringBundler(5);
6173 }
6174
6175 if (getDB().isSupportsInlineDistinct()) {
6176 query.append(_FILTER_SQL_SELECT_ORGANIZATION_WHERE);
6177 }
6178 else {
6179 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1);
6180 }
6181
6182 query.append(_FINDER_COLUMN_O_C_P_ORGANIZATIONID_2);
6183
6184 query.append(_FINDER_COLUMN_O_C_P_COMPANYID_2);
6185
6186 query.append(_FINDER_COLUMN_O_C_P_PARENTORGANIZATIONID_2);
6187
6188 if (!getDB().isSupportsInlineDistinct()) {
6189 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2);
6190 }
6191
6192 if (orderByComparator != null) {
6193 if (getDB().isSupportsInlineDistinct()) {
6194 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6195 orderByComparator, true);
6196 }
6197 else {
6198 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
6199 orderByComparator, true);
6200 }
6201 }
6202 else {
6203 if (getDB().isSupportsInlineDistinct()) {
6204 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
6205 }
6206 else {
6207 query.append(OrganizationModelImpl.ORDER_BY_SQL);
6208 }
6209 }
6210
6211 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6212 Organization.class.getName(),
6213 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
6214
6215 Session session = null;
6216
6217 try {
6218 session = openSession();
6219
6220 SQLQuery q = session.createSynchronizedSQLQuery(sql);
6221
6222 if (getDB().isSupportsInlineDistinct()) {
6223 q.addEntity(_FILTER_ENTITY_ALIAS, OrganizationImpl.class);
6224 }
6225 else {
6226 q.addEntity(_FILTER_ENTITY_TABLE, OrganizationImpl.class);
6227 }
6228
6229 QueryPos qPos = QueryPos.getInstance(q);
6230
6231 qPos.add(organizationId);
6232
6233 qPos.add(companyId);
6234
6235 qPos.add(parentOrganizationId);
6236
6237 return (List<Organization>)QueryUtil.list(q, getDialect(), start,
6238 end);
6239 }
6240 catch (Exception e) {
6241 throw processException(e);
6242 }
6243 finally {
6244 closeSession(session);
6245 }
6246 }
6247
6248
6255 @Override
6256 public void removeByO_C_P(long organizationId, long companyId,
6257 long parentOrganizationId) {
6258 for (Organization organization : findByO_C_P(organizationId, companyId,
6259 parentOrganizationId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
6260 remove(organization);
6261 }
6262 }
6263
6264
6272 @Override
6273 public int countByO_C_P(long organizationId, long companyId,
6274 long parentOrganizationId) {
6275 FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_O_C_P;
6276
6277 Object[] finderArgs = new Object[] {
6278 organizationId, companyId, parentOrganizationId
6279 };
6280
6281 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
6282 this);
6283
6284 if (count == null) {
6285 StringBundler query = new StringBundler(4);
6286
6287 query.append(_SQL_COUNT_ORGANIZATION_WHERE);
6288
6289 query.append(_FINDER_COLUMN_O_C_P_ORGANIZATIONID_2);
6290
6291 query.append(_FINDER_COLUMN_O_C_P_COMPANYID_2);
6292
6293 query.append(_FINDER_COLUMN_O_C_P_PARENTORGANIZATIONID_2);
6294
6295 String sql = query.toString();
6296
6297 Session session = null;
6298
6299 try {
6300 session = openSession();
6301
6302 Query q = session.createQuery(sql);
6303
6304 QueryPos qPos = QueryPos.getInstance(q);
6305
6306 qPos.add(organizationId);
6307
6308 qPos.add(companyId);
6309
6310 qPos.add(parentOrganizationId);
6311
6312 count = (Long)q.uniqueResult();
6313
6314 FinderCacheUtil.putResult(finderPath, finderArgs, count);
6315 }
6316 catch (Exception e) {
6317 FinderCacheUtil.removeResult(finderPath, finderArgs);
6318
6319 throw processException(e);
6320 }
6321 finally {
6322 closeSession(session);
6323 }
6324 }
6325
6326 return count.intValue();
6327 }
6328
6329
6337 @Override
6338 public int filterCountByO_C_P(long organizationId, long companyId,
6339 long parentOrganizationId) {
6340 if (!InlineSQLHelperUtil.isEnabled()) {
6341 return countByO_C_P(organizationId, companyId, parentOrganizationId);
6342 }
6343
6344 StringBundler query = new StringBundler(4);
6345
6346 query.append(_FILTER_SQL_COUNT_ORGANIZATION_WHERE);
6347
6348 query.append(_FINDER_COLUMN_O_C_P_ORGANIZATIONID_2);
6349
6350 query.append(_FINDER_COLUMN_O_C_P_COMPANYID_2);
6351
6352 query.append(_FINDER_COLUMN_O_C_P_PARENTORGANIZATIONID_2);
6353
6354 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6355 Organization.class.getName(),
6356 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
6357
6358 Session session = null;
6359
6360 try {
6361 session = openSession();
6362
6363 SQLQuery q = session.createSynchronizedSQLQuery(sql);
6364
6365 q.addScalar(COUNT_COLUMN_NAME,
6366 com.liferay.portal.kernel.dao.orm.Type.LONG);
6367
6368 QueryPos qPos = QueryPos.getInstance(q);
6369
6370 qPos.add(organizationId);
6371
6372 qPos.add(companyId);
6373
6374 qPos.add(parentOrganizationId);
6375
6376 Long count = (Long)q.uniqueResult();
6377
6378 return count.intValue();
6379 }
6380 catch (Exception e) {
6381 throw processException(e);
6382 }
6383 finally {
6384 closeSession(session);
6385 }
6386 }
6387
6388 private static final String _FINDER_COLUMN_O_C_P_ORGANIZATIONID_2 = "organization.organizationId > ? AND ";
6389 private static final String _FINDER_COLUMN_O_C_P_COMPANYID_2 = "organization.companyId = ? AND ";
6390 private static final String _FINDER_COLUMN_O_C_P_PARENTORGANIZATIONID_2 = "organization.parentOrganizationId = ?";
6391
6392 public OrganizationPersistenceImpl() {
6393 setModelClass(Organization.class);
6394 }
6395
6396
6401 @Override
6402 public void cacheResult(Organization organization) {
6403 EntityCacheUtil.putResult(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
6404 OrganizationImpl.class, organization.getPrimaryKey(), organization);
6405
6406 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
6407 new Object[] { organization.getCompanyId(), organization.getName() },
6408 organization);
6409
6410 organization.resetOriginalValues();
6411 }
6412
6413
6418 @Override
6419 public void cacheResult(List<Organization> organizations) {
6420 for (Organization organization : organizations) {
6421 if (EntityCacheUtil.getResult(
6422 OrganizationModelImpl.ENTITY_CACHE_ENABLED,
6423 OrganizationImpl.class, organization.getPrimaryKey()) == null) {
6424 cacheResult(organization);
6425 }
6426 else {
6427 organization.resetOriginalValues();
6428 }
6429 }
6430 }
6431
6432
6439 @Override
6440 public void clearCache() {
6441 EntityCacheUtil.clearCache(OrganizationImpl.class);
6442
6443 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
6444 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
6445 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
6446 }
6447
6448
6455 @Override
6456 public void clearCache(Organization organization) {
6457 EntityCacheUtil.removeResult(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
6458 OrganizationImpl.class, organization.getPrimaryKey());
6459
6460 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
6461 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
6462
6463 clearUniqueFindersCache(organization);
6464 }
6465
6466 @Override
6467 public void clearCache(List<Organization> organizations) {
6468 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
6469 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
6470
6471 for (Organization organization : organizations) {
6472 EntityCacheUtil.removeResult(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
6473 OrganizationImpl.class, organization.getPrimaryKey());
6474
6475 clearUniqueFindersCache(organization);
6476 }
6477 }
6478
6479 protected void cacheUniqueFindersCache(Organization organization) {
6480 if (organization.isNew()) {
6481 Object[] args = new Object[] {
6482 organization.getCompanyId(), organization.getName()
6483 };
6484
6485 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_N, args,
6486 Long.valueOf(1));
6487 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N, args,
6488 organization);
6489 }
6490 else {
6491 OrganizationModelImpl organizationModelImpl = (OrganizationModelImpl)organization;
6492
6493 if ((organizationModelImpl.getColumnBitmask() &
6494 FINDER_PATH_FETCH_BY_C_N.getColumnBitmask()) != 0) {
6495 Object[] args = new Object[] {
6496 organization.getCompanyId(), organization.getName()
6497 };
6498
6499 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_N, args,
6500 Long.valueOf(1));
6501 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N, args,
6502 organization);
6503 }
6504 }
6505 }
6506
6507 protected void clearUniqueFindersCache(Organization organization) {
6508 OrganizationModelImpl organizationModelImpl = (OrganizationModelImpl)organization;
6509
6510 Object[] args = new Object[] {
6511 organization.getCompanyId(), organization.getName()
6512 };
6513
6514 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N, args);
6515 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N, args);
6516
6517 if ((organizationModelImpl.getColumnBitmask() &
6518 FINDER_PATH_FETCH_BY_C_N.getColumnBitmask()) != 0) {
6519 args = new Object[] {
6520 organizationModelImpl.getOriginalCompanyId(),
6521 organizationModelImpl.getOriginalName()
6522 };
6523
6524 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N, args);
6525 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N, args);
6526 }
6527 }
6528
6529
6535 @Override
6536 public Organization create(long organizationId) {
6537 Organization organization = new OrganizationImpl();
6538
6539 organization.setNew(true);
6540 organization.setPrimaryKey(organizationId);
6541
6542 String uuid = PortalUUIDUtil.generate();
6543
6544 organization.setUuid(uuid);
6545
6546 return organization;
6547 }
6548
6549
6556 @Override
6557 public Organization remove(long organizationId)
6558 throws NoSuchOrganizationException {
6559 return remove((Serializable)organizationId);
6560 }
6561
6562
6569 @Override
6570 public Organization remove(Serializable primaryKey)
6571 throws NoSuchOrganizationException {
6572 Session session = null;
6573
6574 try {
6575 session = openSession();
6576
6577 Organization organization = (Organization)session.get(OrganizationImpl.class,
6578 primaryKey);
6579
6580 if (organization == null) {
6581 if (_log.isWarnEnabled()) {
6582 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
6583 }
6584
6585 throw new NoSuchOrganizationException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
6586 primaryKey);
6587 }
6588
6589 return remove(organization);
6590 }
6591 catch (NoSuchOrganizationException nsee) {
6592 throw nsee;
6593 }
6594 catch (Exception e) {
6595 throw processException(e);
6596 }
6597 finally {
6598 closeSession(session);
6599 }
6600 }
6601
6602 @Override
6603 protected Organization removeImpl(Organization organization) {
6604 organization = toUnwrappedModel(organization);
6605
6606 organizationToGroupTableMapper.deleteLeftPrimaryKeyTableMappings(organization.getPrimaryKey());
6607
6608 organizationToUserTableMapper.deleteLeftPrimaryKeyTableMappings(organization.getPrimaryKey());
6609
6610 Session session = null;
6611
6612 try {
6613 session = openSession();
6614
6615 if (!session.contains(organization)) {
6616 organization = (Organization)session.get(OrganizationImpl.class,
6617 organization.getPrimaryKeyObj());
6618 }
6619
6620 if (organization != null) {
6621 session.delete(organization);
6622 }
6623 }
6624 catch (Exception e) {
6625 throw processException(e);
6626 }
6627 finally {
6628 closeSession(session);
6629 }
6630
6631 if (organization != null) {
6632 clearCache(organization);
6633 }
6634
6635 return organization;
6636 }
6637
6638 @Override
6639 public Organization updateImpl(Organization organization) {
6640 organization = toUnwrappedModel(organization);
6641
6642 boolean isNew = organization.isNew();
6643
6644 OrganizationModelImpl organizationModelImpl = (OrganizationModelImpl)organization;
6645
6646 if (Validator.isNull(organization.getUuid())) {
6647 String uuid = PortalUUIDUtil.generate();
6648
6649 organization.setUuid(uuid);
6650 }
6651
6652 ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();
6653
6654 Date now = new Date();
6655
6656 if (isNew && (organization.getCreateDate() == null)) {
6657 if (serviceContext == null) {
6658 organization.setCreateDate(now);
6659 }
6660 else {
6661 organization.setCreateDate(serviceContext.getCreateDate(now));
6662 }
6663 }
6664
6665 if (!organizationModelImpl.hasSetModifiedDate()) {
6666 if (serviceContext == null) {
6667 organization.setModifiedDate(now);
6668 }
6669 else {
6670 organization.setModifiedDate(serviceContext.getModifiedDate(now));
6671 }
6672 }
6673
6674 Session session = null;
6675
6676 try {
6677 session = openSession();
6678
6679 if (organization.isNew()) {
6680 session.save(organization);
6681
6682 organization.setNew(false);
6683 }
6684 else {
6685 session.merge(organization);
6686 }
6687 }
6688 catch (Exception e) {
6689 throw processException(e);
6690 }
6691 finally {
6692 closeSession(session);
6693 }
6694
6695 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
6696
6697 if (isNew || !OrganizationModelImpl.COLUMN_BITMASK_ENABLED) {
6698 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
6699 }
6700
6701 else {
6702 if ((organizationModelImpl.getColumnBitmask() &
6703 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
6704 Object[] args = new Object[] {
6705 organizationModelImpl.getOriginalUuid()
6706 };
6707
6708 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
6709 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
6710 args);
6711
6712 args = new Object[] { organizationModelImpl.getUuid() };
6713
6714 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
6715 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
6716 args);
6717 }
6718
6719 if ((organizationModelImpl.getColumnBitmask() &
6720 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
6721 Object[] args = new Object[] {
6722 organizationModelImpl.getOriginalUuid(),
6723 organizationModelImpl.getOriginalCompanyId()
6724 };
6725
6726 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
6727 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
6728 args);
6729
6730 args = new Object[] {
6731 organizationModelImpl.getUuid(),
6732 organizationModelImpl.getCompanyId()
6733 };
6734
6735 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
6736 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
6737 args);
6738 }
6739
6740 if ((organizationModelImpl.getColumnBitmask() &
6741 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
6742 Object[] args = new Object[] {
6743 organizationModelImpl.getOriginalCompanyId()
6744 };
6745
6746 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
6747 args);
6748 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
6749 args);
6750
6751 args = new Object[] { organizationModelImpl.getCompanyId() };
6752
6753 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
6754 args);
6755 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
6756 args);
6757 }
6758
6759 if ((organizationModelImpl.getColumnBitmask() &
6760 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LOCATIONS.getColumnBitmask()) != 0) {
6761 Object[] args = new Object[] {
6762 organizationModelImpl.getOriginalCompanyId()
6763 };
6764
6765 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_LOCATIONS,
6766 args);
6767 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LOCATIONS,
6768 args);
6769
6770 args = new Object[] { organizationModelImpl.getCompanyId() };
6771
6772 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_LOCATIONS,
6773 args);
6774 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LOCATIONS,
6775 args);
6776 }
6777
6778 if ((organizationModelImpl.getColumnBitmask() &
6779 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P.getColumnBitmask()) != 0) {
6780 Object[] args = new Object[] {
6781 organizationModelImpl.getOriginalCompanyId(),
6782 organizationModelImpl.getOriginalParentOrganizationId()
6783 };
6784
6785 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_P, args);
6786 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P,
6787 args);
6788
6789 args = new Object[] {
6790 organizationModelImpl.getCompanyId(),
6791 organizationModelImpl.getParentOrganizationId()
6792 };
6793
6794 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_P, args);
6795 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P,
6796 args);
6797 }
6798 }
6799
6800 EntityCacheUtil.putResult(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
6801 OrganizationImpl.class, organization.getPrimaryKey(), organization,
6802 false);
6803
6804 clearUniqueFindersCache(organization);
6805 cacheUniqueFindersCache(organization);
6806
6807 organization.resetOriginalValues();
6808
6809 return organization;
6810 }
6811
6812 protected Organization toUnwrappedModel(Organization organization) {
6813 if (organization instanceof OrganizationImpl) {
6814 return organization;
6815 }
6816
6817 OrganizationImpl organizationImpl = new OrganizationImpl();
6818
6819 organizationImpl.setNew(organization.isNew());
6820 organizationImpl.setPrimaryKey(organization.getPrimaryKey());
6821
6822 organizationImpl.setMvccVersion(organization.getMvccVersion());
6823 organizationImpl.setUuid(organization.getUuid());
6824 organizationImpl.setOrganizationId(organization.getOrganizationId());
6825 organizationImpl.setCompanyId(organization.getCompanyId());
6826 organizationImpl.setUserId(organization.getUserId());
6827 organizationImpl.setUserName(organization.getUserName());
6828 organizationImpl.setCreateDate(organization.getCreateDate());
6829 organizationImpl.setModifiedDate(organization.getModifiedDate());
6830 organizationImpl.setParentOrganizationId(organization.getParentOrganizationId());
6831 organizationImpl.setTreePath(organization.getTreePath());
6832 organizationImpl.setName(organization.getName());
6833 organizationImpl.setType(organization.getType());
6834 organizationImpl.setRecursable(organization.isRecursable());
6835 organizationImpl.setRegionId(organization.getRegionId());
6836 organizationImpl.setCountryId(organization.getCountryId());
6837 organizationImpl.setStatusId(organization.getStatusId());
6838 organizationImpl.setComments(organization.getComments());
6839 organizationImpl.setLogoId(organization.getLogoId());
6840
6841 return organizationImpl;
6842 }
6843
6844
6851 @Override
6852 public Organization findByPrimaryKey(Serializable primaryKey)
6853 throws NoSuchOrganizationException {
6854 Organization organization = fetchByPrimaryKey(primaryKey);
6855
6856 if (organization == null) {
6857 if (_log.isWarnEnabled()) {
6858 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
6859 }
6860
6861 throw new NoSuchOrganizationException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
6862 primaryKey);
6863 }
6864
6865 return organization;
6866 }
6867
6868
6875 @Override
6876 public Organization findByPrimaryKey(long organizationId)
6877 throws NoSuchOrganizationException {
6878 return findByPrimaryKey((Serializable)organizationId);
6879 }
6880
6881
6887 @Override
6888 public Organization fetchByPrimaryKey(Serializable primaryKey) {
6889 Organization organization = (Organization)EntityCacheUtil.getResult(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
6890 OrganizationImpl.class, primaryKey);
6891
6892 if (organization == _nullOrganization) {
6893 return null;
6894 }
6895
6896 if (organization == null) {
6897 Session session = null;
6898
6899 try {
6900 session = openSession();
6901
6902 organization = (Organization)session.get(OrganizationImpl.class,
6903 primaryKey);
6904
6905 if (organization != null) {
6906 cacheResult(organization);
6907 }
6908 else {
6909 EntityCacheUtil.putResult(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
6910 OrganizationImpl.class, primaryKey, _nullOrganization);
6911 }
6912 }
6913 catch (Exception e) {
6914 EntityCacheUtil.removeResult(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
6915 OrganizationImpl.class, primaryKey);
6916
6917 throw processException(e);
6918 }
6919 finally {
6920 closeSession(session);
6921 }
6922 }
6923
6924 return organization;
6925 }
6926
6927
6933 @Override
6934 public Organization fetchByPrimaryKey(long organizationId) {
6935 return fetchByPrimaryKey((Serializable)organizationId);
6936 }
6937
6938 @Override
6939 public Map<Serializable, Organization> fetchByPrimaryKeys(
6940 Set<Serializable> primaryKeys) {
6941 if (primaryKeys.isEmpty()) {
6942 return Collections.emptyMap();
6943 }
6944
6945 Map<Serializable, Organization> map = new HashMap<Serializable, Organization>();
6946
6947 if (primaryKeys.size() == 1) {
6948 Iterator<Serializable> iterator = primaryKeys.iterator();
6949
6950 Serializable primaryKey = iterator.next();
6951
6952 Organization organization = fetchByPrimaryKey(primaryKey);
6953
6954 if (organization != null) {
6955 map.put(primaryKey, organization);
6956 }
6957
6958 return map;
6959 }
6960
6961 Set<Serializable> uncachedPrimaryKeys = null;
6962
6963 for (Serializable primaryKey : primaryKeys) {
6964 Organization organization = (Organization)EntityCacheUtil.getResult(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
6965 OrganizationImpl.class, primaryKey);
6966
6967 if (organization == null) {
6968 if (uncachedPrimaryKeys == null) {
6969 uncachedPrimaryKeys = new HashSet<Serializable>();
6970 }
6971
6972 uncachedPrimaryKeys.add(primaryKey);
6973 }
6974 else {
6975 map.put(primaryKey, organization);
6976 }
6977 }
6978
6979 if (uncachedPrimaryKeys == null) {
6980 return map;
6981 }
6982
6983 StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
6984 1);
6985
6986 query.append(_SQL_SELECT_ORGANIZATION_WHERE_PKS_IN);
6987
6988 for (Serializable primaryKey : uncachedPrimaryKeys) {
6989 query.append(String.valueOf(primaryKey));
6990
6991 query.append(StringPool.COMMA);
6992 }
6993
6994 query.setIndex(query.index() - 1);
6995
6996 query.append(StringPool.CLOSE_PARENTHESIS);
6997
6998 String sql = query.toString();
6999
7000 Session session = null;
7001
7002 try {
7003 session = openSession();
7004
7005 Query q = session.createQuery(sql);
7006
7007 for (Organization organization : (List<Organization>)q.list()) {
7008 map.put(organization.getPrimaryKeyObj(), organization);
7009
7010 cacheResult(organization);
7011
7012 uncachedPrimaryKeys.remove(organization.getPrimaryKeyObj());
7013 }
7014
7015 for (Serializable primaryKey : uncachedPrimaryKeys) {
7016 EntityCacheUtil.putResult(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
7017 OrganizationImpl.class, primaryKey, _nullOrganization);
7018 }
7019 }
7020 catch (Exception e) {
7021 throw processException(e);
7022 }
7023 finally {
7024 closeSession(session);
7025 }
7026
7027 return map;
7028 }
7029
7030
7035 @Override
7036 public List<Organization> findAll() {
7037 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
7038 }
7039
7040
7051 @Override
7052 public List<Organization> findAll(int start, int end) {
7053 return findAll(start, end, null);
7054 }
7055
7056
7068 @Override
7069 public List<Organization> findAll(int start, int end,
7070 OrderByComparator<Organization> orderByComparator) {
7071 boolean pagination = true;
7072 FinderPath finderPath = null;
7073 Object[] finderArgs = null;
7074
7075 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7076 (orderByComparator == null)) {
7077 pagination = false;
7078 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
7079 finderArgs = FINDER_ARGS_EMPTY;
7080 }
7081 else {
7082 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
7083 finderArgs = new Object[] { start, end, orderByComparator };
7084 }
7085
7086 List<Organization> list = (List<Organization>)FinderCacheUtil.getResult(finderPath,
7087 finderArgs, this);
7088
7089 if (list == null) {
7090 StringBundler query = null;
7091 String sql = null;
7092
7093 if (orderByComparator != null) {
7094 query = new StringBundler(2 +
7095 (orderByComparator.getOrderByFields().length * 3));
7096
7097 query.append(_SQL_SELECT_ORGANIZATION);
7098
7099 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7100 orderByComparator);
7101
7102 sql = query.toString();
7103 }
7104 else {
7105 sql = _SQL_SELECT_ORGANIZATION;
7106
7107 if (pagination) {
7108 sql = sql.concat(OrganizationModelImpl.ORDER_BY_JPQL);
7109 }
7110 }
7111
7112 Session session = null;
7113
7114 try {
7115 session = openSession();
7116
7117 Query q = session.createQuery(sql);
7118
7119 if (!pagination) {
7120 list = (List<Organization>)QueryUtil.list(q, getDialect(),
7121 start, end, false);
7122
7123 Collections.sort(list);
7124
7125 list = Collections.unmodifiableList(list);
7126 }
7127 else {
7128 list = (List<Organization>)QueryUtil.list(q, getDialect(),
7129 start, end);
7130 }
7131
7132 cacheResult(list);
7133
7134 FinderCacheUtil.putResult(finderPath, finderArgs, list);
7135 }
7136 catch (Exception e) {
7137 FinderCacheUtil.removeResult(finderPath, finderArgs);
7138
7139 throw processException(e);
7140 }
7141 finally {
7142 closeSession(session);
7143 }
7144 }
7145
7146 return list;
7147 }
7148
7149
7153 @Override
7154 public void removeAll() {
7155 for (Organization organization : findAll()) {
7156 remove(organization);
7157 }
7158 }
7159
7160
7165 @Override
7166 public int countAll() {
7167 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
7168 FINDER_ARGS_EMPTY, this);
7169
7170 if (count == null) {
7171 Session session = null;
7172
7173 try {
7174 session = openSession();
7175
7176 Query q = session.createQuery(_SQL_COUNT_ORGANIZATION);
7177
7178 count = (Long)q.uniqueResult();
7179
7180 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
7181 FINDER_ARGS_EMPTY, count);
7182 }
7183 catch (Exception e) {
7184 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
7185 FINDER_ARGS_EMPTY);
7186
7187 throw processException(e);
7188 }
7189 finally {
7190 closeSession(session);
7191 }
7192 }
7193
7194 return count.intValue();
7195 }
7196
7197
7203 @Override
7204 public long[] getGroupPrimaryKeys(long pk) {
7205 long[] pks = organizationToGroupTableMapper.getRightPrimaryKeys(pk);
7206
7207 return pks.clone();
7208 }
7209
7210
7216 @Override
7217 public List<com.liferay.portal.model.Group> getGroups(long pk) {
7218 return getGroups(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
7219 }
7220
7221
7233 @Override
7234 public List<com.liferay.portal.model.Group> getGroups(long pk, int start,
7235 int end) {
7236 return getGroups(pk, start, end, null);
7237 }
7238
7239
7252 @Override
7253 public List<com.liferay.portal.model.Group> getGroups(long pk, int start,
7254 int end,
7255 OrderByComparator<com.liferay.portal.model.Group> orderByComparator) {
7256 return organizationToGroupTableMapper.getRightBaseModels(pk, start,
7257 end, orderByComparator);
7258 }
7259
7260
7266 @Override
7267 public int getGroupsSize(long pk) {
7268 long[] pks = organizationToGroupTableMapper.getRightPrimaryKeys(pk);
7269
7270 return pks.length;
7271 }
7272
7273
7280 @Override
7281 public boolean containsGroup(long pk, long groupPK) {
7282 return organizationToGroupTableMapper.containsTableMapping(pk, groupPK);
7283 }
7284
7285
7291 @Override
7292 public boolean containsGroups(long pk) {
7293 if (getGroupsSize(pk) > 0) {
7294 return true;
7295 }
7296 else {
7297 return false;
7298 }
7299 }
7300
7301
7307 @Override
7308 public void addGroup(long pk, long groupPK) {
7309 organizationToGroupTableMapper.addTableMapping(pk, groupPK);
7310 }
7311
7312
7318 @Override
7319 public void addGroup(long pk, com.liferay.portal.model.Group group) {
7320 organizationToGroupTableMapper.addTableMapping(pk, group.getPrimaryKey());
7321 }
7322
7323
7329 @Override
7330 public void addGroups(long pk, long[] groupPKs) {
7331 for (long groupPK : groupPKs) {
7332 organizationToGroupTableMapper.addTableMapping(pk, groupPK);
7333 }
7334 }
7335
7336
7342 @Override
7343 public void addGroups(long pk, List<com.liferay.portal.model.Group> groups) {
7344 for (com.liferay.portal.model.Group group : groups) {
7345 organizationToGroupTableMapper.addTableMapping(pk,
7346 group.getPrimaryKey());
7347 }
7348 }
7349
7350
7355 @Override
7356 public void clearGroups(long pk) {
7357 organizationToGroupTableMapper.deleteLeftPrimaryKeyTableMappings(pk);
7358 }
7359
7360
7366 @Override
7367 public void removeGroup(long pk, long groupPK) {
7368 organizationToGroupTableMapper.deleteTableMapping(pk, groupPK);
7369 }
7370
7371
7377 @Override
7378 public void removeGroup(long pk, com.liferay.portal.model.Group group) {
7379 organizationToGroupTableMapper.deleteTableMapping(pk,
7380 group.getPrimaryKey());
7381 }
7382
7383
7389 @Override
7390 public void removeGroups(long pk, long[] groupPKs) {
7391 for (long groupPK : groupPKs) {
7392 organizationToGroupTableMapper.deleteTableMapping(pk, groupPK);
7393 }
7394 }
7395
7396
7402 @Override
7403 public void removeGroups(long pk,
7404 List<com.liferay.portal.model.Group> groups) {
7405 for (com.liferay.portal.model.Group group : groups) {
7406 organizationToGroupTableMapper.deleteTableMapping(pk,
7407 group.getPrimaryKey());
7408 }
7409 }
7410
7411
7417 @Override
7418 public void setGroups(long pk, long[] groupPKs) {
7419 Set<Long> newGroupPKsSet = SetUtil.fromArray(groupPKs);
7420 Set<Long> oldGroupPKsSet = SetUtil.fromArray(organizationToGroupTableMapper.getRightPrimaryKeys(
7421 pk));
7422
7423 Set<Long> removeGroupPKsSet = new HashSet<Long>(oldGroupPKsSet);
7424
7425 removeGroupPKsSet.removeAll(newGroupPKsSet);
7426
7427 for (long removeGroupPK : removeGroupPKsSet) {
7428 organizationToGroupTableMapper.deleteTableMapping(pk, removeGroupPK);
7429 }
7430
7431 newGroupPKsSet.removeAll(oldGroupPKsSet);
7432
7433 for (long newGroupPK : newGroupPKsSet) {
7434 organizationToGroupTableMapper.addTableMapping(pk, newGroupPK);
7435 }
7436 }
7437
7438
7444 @Override
7445 public void setGroups(long pk, List<com.liferay.portal.model.Group> groups) {
7446 try {
7447 long[] groupPKs = new long[groups.size()];
7448
7449 for (int i = 0; i < groups.size(); i++) {
7450 com.liferay.portal.model.Group group = groups.get(i);
7451
7452 groupPKs[i] = group.getPrimaryKey();
7453 }
7454
7455 setGroups(pk, groupPKs);
7456 }
7457 catch (Exception e) {
7458 throw processException(e);
7459 }
7460 }
7461
7462
7468 @Override
7469 public long[] getUserPrimaryKeys(long pk) {
7470 long[] pks = organizationToUserTableMapper.getRightPrimaryKeys(pk);
7471
7472 return pks.clone();
7473 }
7474
7475
7481 @Override
7482 public List<com.liferay.portal.model.User> getUsers(long pk) {
7483 return getUsers(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
7484 }
7485
7486
7498 @Override
7499 public List<com.liferay.portal.model.User> getUsers(long pk, int start,
7500 int end) {
7501 return getUsers(pk, start, end, null);
7502 }
7503
7504
7517 @Override
7518 public List<com.liferay.portal.model.User> getUsers(long pk, int start,
7519 int end,
7520 OrderByComparator<com.liferay.portal.model.User> orderByComparator) {
7521 return organizationToUserTableMapper.getRightBaseModels(pk, start, end,
7522 orderByComparator);
7523 }
7524
7525
7531 @Override
7532 public int getUsersSize(long pk) {
7533 long[] pks = organizationToUserTableMapper.getRightPrimaryKeys(pk);
7534
7535 return pks.length;
7536 }
7537
7538
7545 @Override
7546 public boolean containsUser(long pk, long userPK) {
7547 return organizationToUserTableMapper.containsTableMapping(pk, userPK);
7548 }
7549
7550
7556 @Override
7557 public boolean containsUsers(long pk) {
7558 if (getUsersSize(pk) > 0) {
7559 return true;
7560 }
7561 else {
7562 return false;
7563 }
7564 }
7565
7566
7572 @Override
7573 public void addUser(long pk, long userPK) {
7574 organizationToUserTableMapper.addTableMapping(pk, userPK);
7575 }
7576
7577
7583 @Override
7584 public void addUser(long pk, com.liferay.portal.model.User user) {
7585 organizationToUserTableMapper.addTableMapping(pk, user.getPrimaryKey());
7586 }
7587
7588
7594 @Override
7595 public void addUsers(long pk, long[] userPKs) {
7596 for (long userPK : userPKs) {
7597 organizationToUserTableMapper.addTableMapping(pk, userPK);
7598 }
7599 }
7600
7601
7607 @Override
7608 public void addUsers(long pk, List<com.liferay.portal.model.User> users) {
7609 for (com.liferay.portal.model.User user : users) {
7610 organizationToUserTableMapper.addTableMapping(pk,
7611 user.getPrimaryKey());
7612 }
7613 }
7614
7615
7620 @Override
7621 public void clearUsers(long pk) {
7622 organizationToUserTableMapper.deleteLeftPrimaryKeyTableMappings(pk);
7623 }
7624
7625
7631 @Override
7632 public void removeUser(long pk, long userPK) {
7633 organizationToUserTableMapper.deleteTableMapping(pk, userPK);
7634 }
7635
7636
7642 @Override
7643 public void removeUser(long pk, com.liferay.portal.model.User user) {
7644 organizationToUserTableMapper.deleteTableMapping(pk,
7645 user.getPrimaryKey());
7646 }
7647
7648
7654 @Override
7655 public void removeUsers(long pk, long[] userPKs) {
7656 for (long userPK : userPKs) {
7657 organizationToUserTableMapper.deleteTableMapping(pk, userPK);
7658 }
7659 }
7660
7661
7667 @Override
7668 public void removeUsers(long pk, List<com.liferay.portal.model.User> users) {
7669 for (com.liferay.portal.model.User user : users) {
7670 organizationToUserTableMapper.deleteTableMapping(pk,
7671 user.getPrimaryKey());
7672 }
7673 }
7674
7675
7681 @Override
7682 public void setUsers(long pk, long[] userPKs) {
7683 Set<Long> newUserPKsSet = SetUtil.fromArray(userPKs);
7684 Set<Long> oldUserPKsSet = SetUtil.fromArray(organizationToUserTableMapper.getRightPrimaryKeys(
7685 pk));
7686
7687 Set<Long> removeUserPKsSet = new HashSet<Long>(oldUserPKsSet);
7688
7689 removeUserPKsSet.removeAll(newUserPKsSet);
7690
7691 for (long removeUserPK : removeUserPKsSet) {
7692 organizationToUserTableMapper.deleteTableMapping(pk, removeUserPK);
7693 }
7694
7695 newUserPKsSet.removeAll(oldUserPKsSet);
7696
7697 for (long newUserPK : newUserPKsSet) {
7698 organizationToUserTableMapper.addTableMapping(pk, newUserPK);
7699 }
7700 }
7701
7702
7708 @Override
7709 public void setUsers(long pk, List<com.liferay.portal.model.User> users) {
7710 try {
7711 long[] userPKs = new long[users.size()];
7712
7713 for (int i = 0; i < users.size(); i++) {
7714 com.liferay.portal.model.User user = users.get(i);
7715
7716 userPKs[i] = user.getPrimaryKey();
7717 }
7718
7719 setUsers(pk, userPKs);
7720 }
7721 catch (Exception e) {
7722 throw processException(e);
7723 }
7724 }
7725
7726 @Override
7727 protected Set<String> getBadColumnNames() {
7728 return _badColumnNames;
7729 }
7730
7731
7734 public void afterPropertiesSet() {
7735 organizationToGroupTableMapper = TableMapperFactory.getTableMapper("Groups_Orgs",
7736 "organizationId", "groupId", this, groupPersistence);
7737
7738 organizationToUserTableMapper = TableMapperFactory.getTableMapper("Users_Orgs",
7739 "organizationId", "userId", this, userPersistence);
7740 }
7741
7742 public void destroy() {
7743 EntityCacheUtil.removeCache(OrganizationImpl.class.getName());
7744 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
7745 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
7746 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
7747
7748 TableMapperFactory.removeTableMapper("Groups_Orgs");
7749 TableMapperFactory.removeTableMapper("Users_Orgs");
7750 }
7751
7752 @BeanReference(type = GroupPersistence.class)
7753 protected GroupPersistence groupPersistence;
7754 protected TableMapper<Organization, com.liferay.portal.model.Group> organizationToGroupTableMapper;
7755 @BeanReference(type = UserPersistence.class)
7756 protected UserPersistence userPersistence;
7757 protected TableMapper<Organization, com.liferay.portal.model.User> organizationToUserTableMapper;
7758 private static final String _SQL_SELECT_ORGANIZATION = "SELECT organization FROM Organization organization";
7759 private static final String _SQL_SELECT_ORGANIZATION_WHERE_PKS_IN = "SELECT organization FROM Organization organization WHERE organizationId IN (";
7760 private static final String _SQL_SELECT_ORGANIZATION_WHERE = "SELECT organization FROM Organization organization WHERE ";
7761 private static final String _SQL_COUNT_ORGANIZATION = "SELECT COUNT(organization) FROM Organization organization";
7762 private static final String _SQL_COUNT_ORGANIZATION_WHERE = "SELECT COUNT(organization) FROM Organization organization WHERE ";
7763 private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "organization.organizationId";
7764 private static final String _FILTER_SQL_SELECT_ORGANIZATION_WHERE = "SELECT DISTINCT {organization.*} FROM Organization_ organization WHERE ";
7765 private static final String _FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1 =
7766 "SELECT {Organization_.*} FROM (SELECT DISTINCT organization.organizationId FROM Organization_ organization WHERE ";
7767 private static final String _FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2 =
7768 ") TEMP_TABLE INNER JOIN Organization_ ON TEMP_TABLE.organizationId = Organization_.organizationId";
7769 private static final String _FILTER_SQL_COUNT_ORGANIZATION_WHERE = "SELECT COUNT(DISTINCT organization.organizationId) AS COUNT_VALUE FROM Organization_ organization WHERE ";
7770 private static final String _FILTER_ENTITY_ALIAS = "organization";
7771 private static final String _FILTER_ENTITY_TABLE = "Organization_";
7772 private static final String _ORDER_BY_ENTITY_ALIAS = "organization.";
7773 private static final String _ORDER_BY_ENTITY_TABLE = "Organization_.";
7774 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Organization exists with the primary key ";
7775 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Organization exists with the key {";
7776 private static final Log _log = LogFactoryUtil.getLog(OrganizationPersistenceImpl.class);
7777 private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
7778 "uuid", "type"
7779 });
7780 private static final Organization _nullOrganization = new OrganizationImpl() {
7781 @Override
7782 public Object clone() {
7783 return this;
7784 }
7785
7786 @Override
7787 public CacheModel<Organization> toCacheModel() {
7788 return _nullOrganizationCacheModel;
7789 }
7790 };
7791
7792 private static final CacheModel<Organization> _nullOrganizationCacheModel = new NullCacheModel();
7793
7794 private static class NullCacheModel implements CacheModel<Organization>,
7795 MVCCModel {
7796 @Override
7797 public long getMvccVersion() {
7798 return -1;
7799 }
7800
7801 @Override
7802 public void setMvccVersion(long mvccVersion) {
7803 }
7804
7805 @Override
7806 public Organization toEntityModel() {
7807 return _nullOrganization;
7808 }
7809 }
7810 }