001
014
015 package com.liferay.portal.service.persistence;
016
017 import com.liferay.portal.NoSuchOrganizationException;
018 import com.liferay.portal.kernel.bean.BeanReference;
019 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderPath;
023 import com.liferay.portal.kernel.dao.orm.Query;
024 import com.liferay.portal.kernel.dao.orm.QueryPos;
025 import com.liferay.portal.kernel.dao.orm.QueryUtil;
026 import com.liferay.portal.kernel.dao.orm.SQLQuery;
027 import com.liferay.portal.kernel.dao.orm.Session;
028 import com.liferay.portal.kernel.exception.SystemException;
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.GetterUtil;
033 import com.liferay.portal.kernel.util.InstanceFactory;
034 import com.liferay.portal.kernel.util.OrderByComparator;
035 import com.liferay.portal.kernel.util.SetUtil;
036 import com.liferay.portal.kernel.util.StringBundler;
037 import com.liferay.portal.kernel.util.StringPool;
038 import com.liferay.portal.kernel.util.StringUtil;
039 import com.liferay.portal.kernel.util.UnmodifiableList;
040 import com.liferay.portal.kernel.util.Validator;
041 import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
042 import com.liferay.portal.model.CacheModel;
043 import com.liferay.portal.model.ModelListener;
044 import com.liferay.portal.model.Organization;
045 import com.liferay.portal.model.impl.OrganizationImpl;
046 import com.liferay.portal.model.impl.OrganizationModelImpl;
047 import com.liferay.portal.security.permission.InlineSQLHelperUtil;
048 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
049 import com.liferay.portal.service.persistence.impl.TableMapper;
050 import com.liferay.portal.service.persistence.impl.TableMapperFactory;
051
052 import java.io.Serializable;
053
054 import java.util.ArrayList;
055 import java.util.Collections;
056 import java.util.HashSet;
057 import java.util.List;
058 import java.util.Set;
059
060
072 public class OrganizationPersistenceImpl extends BasePersistenceImpl<Organization>
073 implements OrganizationPersistence {
074
079 public static final String FINDER_CLASS_NAME_ENTITY = OrganizationImpl.class.getName();
080 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
081 ".List1";
082 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
083 ".List2";
084 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
085 OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
086 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
087 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
088 OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
089 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
090 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
091 OrganizationModelImpl.FINDER_CACHE_ENABLED, Long.class,
092 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
093 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
094 OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
095 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
096 new String[] {
097 String.class.getName(),
098
099 Integer.class.getName(), Integer.class.getName(),
100 OrderByComparator.class.getName()
101 });
102 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
103 OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
104 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
105 new String[] { String.class.getName() },
106 OrganizationModelImpl.UUID_COLUMN_BITMASK |
107 OrganizationModelImpl.NAME_COLUMN_BITMASK);
108 public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
109 OrganizationModelImpl.FINDER_CACHE_ENABLED, Long.class,
110 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
111 new String[] { String.class.getName() });
112
113
120 @Override
121 public List<Organization> findByUuid(String uuid) throws SystemException {
122 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
123 }
124
125
138 @Override
139 public List<Organization> findByUuid(String uuid, int start, int end)
140 throws SystemException {
141 return findByUuid(uuid, start, end, null);
142 }
143
144
158 @Override
159 public List<Organization> findByUuid(String uuid, int start, int end,
160 OrderByComparator orderByComparator) throws SystemException {
161 boolean pagination = true;
162 FinderPath finderPath = null;
163 Object[] finderArgs = null;
164
165 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
166 (orderByComparator == null)) {
167 pagination = false;
168 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
169 finderArgs = new Object[] { uuid };
170 }
171 else {
172 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
173 finderArgs = new Object[] { uuid, start, end, orderByComparator };
174 }
175
176 List<Organization> list = (List<Organization>)FinderCacheUtil.getResult(finderPath,
177 finderArgs, this);
178
179 if ((list != null) && !list.isEmpty()) {
180 for (Organization organization : list) {
181 if (!Validator.equals(uuid, organization.getUuid())) {
182 list = null;
183
184 break;
185 }
186 }
187 }
188
189 if (list == null) {
190 StringBundler query = null;
191
192 if (orderByComparator != null) {
193 query = new StringBundler(3 +
194 (orderByComparator.getOrderByFields().length * 3));
195 }
196 else {
197 query = new StringBundler(3);
198 }
199
200 query.append(_SQL_SELECT_ORGANIZATION_WHERE);
201
202 boolean bindUuid = false;
203
204 if (uuid == null) {
205 query.append(_FINDER_COLUMN_UUID_UUID_1);
206 }
207 else if (uuid.equals(StringPool.BLANK)) {
208 query.append(_FINDER_COLUMN_UUID_UUID_3);
209 }
210 else {
211 bindUuid = true;
212
213 query.append(_FINDER_COLUMN_UUID_UUID_2);
214 }
215
216 if (orderByComparator != null) {
217 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
218 orderByComparator);
219 }
220 else
221 if (pagination) {
222 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
223 }
224
225 String sql = query.toString();
226
227 Session session = null;
228
229 try {
230 session = openSession();
231
232 Query q = session.createQuery(sql);
233
234 QueryPos qPos = QueryPos.getInstance(q);
235
236 if (bindUuid) {
237 qPos.add(uuid);
238 }
239
240 if (!pagination) {
241 list = (List<Organization>)QueryUtil.list(q, getDialect(),
242 start, end, false);
243
244 Collections.sort(list);
245
246 list = new UnmodifiableList<Organization>(list);
247 }
248 else {
249 list = (List<Organization>)QueryUtil.list(q, getDialect(),
250 start, end);
251 }
252
253 cacheResult(list);
254
255 FinderCacheUtil.putResult(finderPath, finderArgs, list);
256 }
257 catch (Exception e) {
258 FinderCacheUtil.removeResult(finderPath, finderArgs);
259
260 throw processException(e);
261 }
262 finally {
263 closeSession(session);
264 }
265 }
266
267 return list;
268 }
269
270
279 @Override
280 public Organization findByUuid_First(String uuid,
281 OrderByComparator orderByComparator)
282 throws NoSuchOrganizationException, SystemException {
283 Organization organization = fetchByUuid_First(uuid, orderByComparator);
284
285 if (organization != null) {
286 return organization;
287 }
288
289 StringBundler msg = new StringBundler(4);
290
291 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
292
293 msg.append("uuid=");
294 msg.append(uuid);
295
296 msg.append(StringPool.CLOSE_CURLY_BRACE);
297
298 throw new NoSuchOrganizationException(msg.toString());
299 }
300
301
309 @Override
310 public Organization fetchByUuid_First(String uuid,
311 OrderByComparator orderByComparator) throws SystemException {
312 List<Organization> list = findByUuid(uuid, 0, 1, orderByComparator);
313
314 if (!list.isEmpty()) {
315 return list.get(0);
316 }
317
318 return null;
319 }
320
321
330 @Override
331 public Organization findByUuid_Last(String uuid,
332 OrderByComparator orderByComparator)
333 throws NoSuchOrganizationException, SystemException {
334 Organization organization = fetchByUuid_Last(uuid, orderByComparator);
335
336 if (organization != null) {
337 return organization;
338 }
339
340 StringBundler msg = new StringBundler(4);
341
342 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
343
344 msg.append("uuid=");
345 msg.append(uuid);
346
347 msg.append(StringPool.CLOSE_CURLY_BRACE);
348
349 throw new NoSuchOrganizationException(msg.toString());
350 }
351
352
360 @Override
361 public Organization fetchByUuid_Last(String uuid,
362 OrderByComparator orderByComparator) throws SystemException {
363 int count = countByUuid(uuid);
364
365 if (count == 0) {
366 return null;
367 }
368
369 List<Organization> list = findByUuid(uuid, count - 1, count,
370 orderByComparator);
371
372 if (!list.isEmpty()) {
373 return list.get(0);
374 }
375
376 return null;
377 }
378
379
389 @Override
390 public Organization[] findByUuid_PrevAndNext(long organizationId,
391 String uuid, OrderByComparator orderByComparator)
392 throws NoSuchOrganizationException, SystemException {
393 Organization organization = findByPrimaryKey(organizationId);
394
395 Session session = null;
396
397 try {
398 session = openSession();
399
400 Organization[] array = new OrganizationImpl[3];
401
402 array[0] = getByUuid_PrevAndNext(session, organization, uuid,
403 orderByComparator, true);
404
405 array[1] = organization;
406
407 array[2] = getByUuid_PrevAndNext(session, organization, uuid,
408 orderByComparator, false);
409
410 return array;
411 }
412 catch (Exception e) {
413 throw processException(e);
414 }
415 finally {
416 closeSession(session);
417 }
418 }
419
420 protected Organization getByUuid_PrevAndNext(Session session,
421 Organization organization, String uuid,
422 OrderByComparator orderByComparator, boolean previous) {
423 StringBundler query = null;
424
425 if (orderByComparator != null) {
426 query = new StringBundler(6 +
427 (orderByComparator.getOrderByFields().length * 6));
428 }
429 else {
430 query = new StringBundler(3);
431 }
432
433 query.append(_SQL_SELECT_ORGANIZATION_WHERE);
434
435 boolean bindUuid = false;
436
437 if (uuid == null) {
438 query.append(_FINDER_COLUMN_UUID_UUID_1);
439 }
440 else if (uuid.equals(StringPool.BLANK)) {
441 query.append(_FINDER_COLUMN_UUID_UUID_3);
442 }
443 else {
444 bindUuid = true;
445
446 query.append(_FINDER_COLUMN_UUID_UUID_2);
447 }
448
449 if (orderByComparator != null) {
450 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
451
452 if (orderByConditionFields.length > 0) {
453 query.append(WHERE_AND);
454 }
455
456 for (int i = 0; i < orderByConditionFields.length; i++) {
457 query.append(_ORDER_BY_ENTITY_ALIAS);
458 query.append(orderByConditionFields[i]);
459
460 if ((i + 1) < orderByConditionFields.length) {
461 if (orderByComparator.isAscending() ^ previous) {
462 query.append(WHERE_GREATER_THAN_HAS_NEXT);
463 }
464 else {
465 query.append(WHERE_LESSER_THAN_HAS_NEXT);
466 }
467 }
468 else {
469 if (orderByComparator.isAscending() ^ previous) {
470 query.append(WHERE_GREATER_THAN);
471 }
472 else {
473 query.append(WHERE_LESSER_THAN);
474 }
475 }
476 }
477
478 query.append(ORDER_BY_CLAUSE);
479
480 String[] orderByFields = orderByComparator.getOrderByFields();
481
482 for (int i = 0; i < orderByFields.length; i++) {
483 query.append(_ORDER_BY_ENTITY_ALIAS);
484 query.append(orderByFields[i]);
485
486 if ((i + 1) < orderByFields.length) {
487 if (orderByComparator.isAscending() ^ previous) {
488 query.append(ORDER_BY_ASC_HAS_NEXT);
489 }
490 else {
491 query.append(ORDER_BY_DESC_HAS_NEXT);
492 }
493 }
494 else {
495 if (orderByComparator.isAscending() ^ previous) {
496 query.append(ORDER_BY_ASC);
497 }
498 else {
499 query.append(ORDER_BY_DESC);
500 }
501 }
502 }
503 }
504 else {
505 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
506 }
507
508 String sql = query.toString();
509
510 Query q = session.createQuery(sql);
511
512 q.setFirstResult(0);
513 q.setMaxResults(2);
514
515 QueryPos qPos = QueryPos.getInstance(q);
516
517 if (bindUuid) {
518 qPos.add(uuid);
519 }
520
521 if (orderByComparator != null) {
522 Object[] values = orderByComparator.getOrderByConditionValues(organization);
523
524 for (Object value : values) {
525 qPos.add(value);
526 }
527 }
528
529 List<Organization> list = q.list();
530
531 if (list.size() == 2) {
532 return list.get(1);
533 }
534 else {
535 return null;
536 }
537 }
538
539
546 @Override
547 public List<Organization> filterFindByUuid(String uuid)
548 throws SystemException {
549 return filterFindByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
550 }
551
552
565 @Override
566 public List<Organization> filterFindByUuid(String uuid, int start, int end)
567 throws SystemException {
568 return filterFindByUuid(uuid, start, end, null);
569 }
570
571
585 @Override
586 public List<Organization> filterFindByUuid(String uuid, int start, int end,
587 OrderByComparator orderByComparator) throws SystemException {
588 if (!InlineSQLHelperUtil.isEnabled()) {
589 return findByUuid(uuid, start, end, orderByComparator);
590 }
591
592 StringBundler query = null;
593
594 if (orderByComparator != null) {
595 query = new StringBundler(3 +
596 (orderByComparator.getOrderByFields().length * 3));
597 }
598 else {
599 query = new StringBundler(3);
600 }
601
602 if (getDB().isSupportsInlineDistinct()) {
603 query.append(_FILTER_SQL_SELECT_ORGANIZATION_WHERE);
604 }
605 else {
606 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1);
607 }
608
609 boolean bindUuid = false;
610
611 if (uuid == null) {
612 query.append(_FINDER_COLUMN_UUID_UUID_1_SQL);
613 }
614 else if (uuid.equals(StringPool.BLANK)) {
615 query.append(_FINDER_COLUMN_UUID_UUID_3_SQL);
616 }
617 else {
618 bindUuid = true;
619
620 query.append(_FINDER_COLUMN_UUID_UUID_2_SQL);
621 }
622
623 if (!getDB().isSupportsInlineDistinct()) {
624 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2);
625 }
626
627 if (orderByComparator != null) {
628 if (getDB().isSupportsInlineDistinct()) {
629 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
630 orderByComparator, true);
631 }
632 else {
633 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
634 orderByComparator, true);
635 }
636 }
637 else {
638 if (getDB().isSupportsInlineDistinct()) {
639 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
640 }
641 else {
642 query.append(OrganizationModelImpl.ORDER_BY_SQL);
643 }
644 }
645
646 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
647 Organization.class.getName(),
648 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
649
650 Session session = null;
651
652 try {
653 session = openSession();
654
655 SQLQuery q = session.createSQLQuery(sql);
656
657 if (getDB().isSupportsInlineDistinct()) {
658 q.addEntity(_FILTER_ENTITY_ALIAS, OrganizationImpl.class);
659 }
660 else {
661 q.addEntity(_FILTER_ENTITY_TABLE, OrganizationImpl.class);
662 }
663
664 QueryPos qPos = QueryPos.getInstance(q);
665
666 if (bindUuid) {
667 qPos.add(uuid);
668 }
669
670 return (List<Organization>)QueryUtil.list(q, getDialect(), start,
671 end);
672 }
673 catch (Exception e) {
674 throw processException(e);
675 }
676 finally {
677 closeSession(session);
678 }
679 }
680
681
691 @Override
692 public Organization[] filterFindByUuid_PrevAndNext(long organizationId,
693 String uuid, OrderByComparator orderByComparator)
694 throws NoSuchOrganizationException, SystemException {
695 if (!InlineSQLHelperUtil.isEnabled()) {
696 return findByUuid_PrevAndNext(organizationId, uuid,
697 orderByComparator);
698 }
699
700 Organization organization = findByPrimaryKey(organizationId);
701
702 Session session = null;
703
704 try {
705 session = openSession();
706
707 Organization[] array = new OrganizationImpl[3];
708
709 array[0] = filterGetByUuid_PrevAndNext(session, organization, uuid,
710 orderByComparator, true);
711
712 array[1] = organization;
713
714 array[2] = filterGetByUuid_PrevAndNext(session, organization, uuid,
715 orderByComparator, false);
716
717 return array;
718 }
719 catch (Exception e) {
720 throw processException(e);
721 }
722 finally {
723 closeSession(session);
724 }
725 }
726
727 protected Organization filterGetByUuid_PrevAndNext(Session session,
728 Organization organization, String uuid,
729 OrderByComparator orderByComparator, boolean previous) {
730 StringBundler query = null;
731
732 if (orderByComparator != null) {
733 query = new StringBundler(6 +
734 (orderByComparator.getOrderByFields().length * 6));
735 }
736 else {
737 query = new StringBundler(3);
738 }
739
740 if (getDB().isSupportsInlineDistinct()) {
741 query.append(_FILTER_SQL_SELECT_ORGANIZATION_WHERE);
742 }
743 else {
744 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1);
745 }
746
747 boolean bindUuid = false;
748
749 if (uuid == null) {
750 query.append(_FINDER_COLUMN_UUID_UUID_1_SQL);
751 }
752 else if (uuid.equals(StringPool.BLANK)) {
753 query.append(_FINDER_COLUMN_UUID_UUID_3_SQL);
754 }
755 else {
756 bindUuid = true;
757
758 query.append(_FINDER_COLUMN_UUID_UUID_2_SQL);
759 }
760
761 if (!getDB().isSupportsInlineDistinct()) {
762 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2);
763 }
764
765 if (orderByComparator != null) {
766 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
767
768 if (orderByConditionFields.length > 0) {
769 query.append(WHERE_AND);
770 }
771
772 for (int i = 0; i < orderByConditionFields.length; i++) {
773 if (getDB().isSupportsInlineDistinct()) {
774 query.append(_ORDER_BY_ENTITY_ALIAS);
775 }
776 else {
777 query.append(_ORDER_BY_ENTITY_TABLE);
778 }
779
780 query.append(orderByConditionFields[i]);
781
782 if ((i + 1) < orderByConditionFields.length) {
783 if (orderByComparator.isAscending() ^ previous) {
784 query.append(WHERE_GREATER_THAN_HAS_NEXT);
785 }
786 else {
787 query.append(WHERE_LESSER_THAN_HAS_NEXT);
788 }
789 }
790 else {
791 if (orderByComparator.isAscending() ^ previous) {
792 query.append(WHERE_GREATER_THAN);
793 }
794 else {
795 query.append(WHERE_LESSER_THAN);
796 }
797 }
798 }
799
800 query.append(ORDER_BY_CLAUSE);
801
802 String[] orderByFields = orderByComparator.getOrderByFields();
803
804 for (int i = 0; i < orderByFields.length; i++) {
805 if (getDB().isSupportsInlineDistinct()) {
806 query.append(_ORDER_BY_ENTITY_ALIAS);
807 }
808 else {
809 query.append(_ORDER_BY_ENTITY_TABLE);
810 }
811
812 query.append(orderByFields[i]);
813
814 if ((i + 1) < orderByFields.length) {
815 if (orderByComparator.isAscending() ^ previous) {
816 query.append(ORDER_BY_ASC_HAS_NEXT);
817 }
818 else {
819 query.append(ORDER_BY_DESC_HAS_NEXT);
820 }
821 }
822 else {
823 if (orderByComparator.isAscending() ^ previous) {
824 query.append(ORDER_BY_ASC);
825 }
826 else {
827 query.append(ORDER_BY_DESC);
828 }
829 }
830 }
831 }
832 else {
833 if (getDB().isSupportsInlineDistinct()) {
834 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
835 }
836 else {
837 query.append(OrganizationModelImpl.ORDER_BY_SQL);
838 }
839 }
840
841 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
842 Organization.class.getName(),
843 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
844
845 SQLQuery q = session.createSQLQuery(sql);
846
847 q.setFirstResult(0);
848 q.setMaxResults(2);
849
850 if (getDB().isSupportsInlineDistinct()) {
851 q.addEntity(_FILTER_ENTITY_ALIAS, OrganizationImpl.class);
852 }
853 else {
854 q.addEntity(_FILTER_ENTITY_TABLE, OrganizationImpl.class);
855 }
856
857 QueryPos qPos = QueryPos.getInstance(q);
858
859 if (bindUuid) {
860 qPos.add(uuid);
861 }
862
863 if (orderByComparator != null) {
864 Object[] values = orderByComparator.getOrderByConditionValues(organization);
865
866 for (Object value : values) {
867 qPos.add(value);
868 }
869 }
870
871 List<Organization> list = q.list();
872
873 if (list.size() == 2) {
874 return list.get(1);
875 }
876 else {
877 return null;
878 }
879 }
880
881
887 @Override
888 public void removeByUuid(String uuid) throws SystemException {
889 for (Organization organization : findByUuid(uuid, QueryUtil.ALL_POS,
890 QueryUtil.ALL_POS, null)) {
891 remove(organization);
892 }
893 }
894
895
902 @Override
903 public int countByUuid(String uuid) throws SystemException {
904 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
905
906 Object[] finderArgs = new Object[] { uuid };
907
908 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
909 this);
910
911 if (count == null) {
912 StringBundler query = new StringBundler(2);
913
914 query.append(_SQL_COUNT_ORGANIZATION_WHERE);
915
916 boolean bindUuid = false;
917
918 if (uuid == null) {
919 query.append(_FINDER_COLUMN_UUID_UUID_1);
920 }
921 else if (uuid.equals(StringPool.BLANK)) {
922 query.append(_FINDER_COLUMN_UUID_UUID_3);
923 }
924 else {
925 bindUuid = true;
926
927 query.append(_FINDER_COLUMN_UUID_UUID_2);
928 }
929
930 String sql = query.toString();
931
932 Session session = null;
933
934 try {
935 session = openSession();
936
937 Query q = session.createQuery(sql);
938
939 QueryPos qPos = QueryPos.getInstance(q);
940
941 if (bindUuid) {
942 qPos.add(uuid);
943 }
944
945 count = (Long)q.uniqueResult();
946
947 FinderCacheUtil.putResult(finderPath, finderArgs, count);
948 }
949 catch (Exception e) {
950 FinderCacheUtil.removeResult(finderPath, finderArgs);
951
952 throw processException(e);
953 }
954 finally {
955 closeSession(session);
956 }
957 }
958
959 return count.intValue();
960 }
961
962
969 @Override
970 public int filterCountByUuid(String uuid) throws SystemException {
971 if (!InlineSQLHelperUtil.isEnabled()) {
972 return countByUuid(uuid);
973 }
974
975 StringBundler query = new StringBundler(2);
976
977 query.append(_FILTER_SQL_COUNT_ORGANIZATION_WHERE);
978
979 boolean bindUuid = false;
980
981 if (uuid == null) {
982 query.append(_FINDER_COLUMN_UUID_UUID_1_SQL);
983 }
984 else if (uuid.equals(StringPool.BLANK)) {
985 query.append(_FINDER_COLUMN_UUID_UUID_3_SQL);
986 }
987 else {
988 bindUuid = true;
989
990 query.append(_FINDER_COLUMN_UUID_UUID_2_SQL);
991 }
992
993 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
994 Organization.class.getName(),
995 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
996
997 Session session = null;
998
999 try {
1000 session = openSession();
1001
1002 SQLQuery q = session.createSQLQuery(sql);
1003
1004 q.addScalar(COUNT_COLUMN_NAME,
1005 com.liferay.portal.kernel.dao.orm.Type.LONG);
1006
1007 QueryPos qPos = QueryPos.getInstance(q);
1008
1009 if (bindUuid) {
1010 qPos.add(uuid);
1011 }
1012
1013 Long count = (Long)q.uniqueResult();
1014
1015 return count.intValue();
1016 }
1017 catch (Exception e) {
1018 throw processException(e);
1019 }
1020 finally {
1021 closeSession(session);
1022 }
1023 }
1024
1025 private static final String _FINDER_COLUMN_UUID_UUID_1 = "organization.uuid IS NULL";
1026 private static final String _FINDER_COLUMN_UUID_UUID_2 = "organization.uuid = ?";
1027 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(organization.uuid IS NULL OR organization.uuid = '')";
1028 private static final String _FINDER_COLUMN_UUID_UUID_1_SQL = "organization.uuid_ IS NULL";
1029 private static final String _FINDER_COLUMN_UUID_UUID_2_SQL = "organization.uuid_ = ?";
1030 private static final String _FINDER_COLUMN_UUID_UUID_3_SQL = "(organization.uuid_ IS NULL OR organization.uuid_ = '')";
1031 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
1032 OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
1033 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
1034 new String[] {
1035 String.class.getName(), Long.class.getName(),
1036
1037 Integer.class.getName(), Integer.class.getName(),
1038 OrderByComparator.class.getName()
1039 });
1040 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
1041 new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
1042 OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
1043 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
1044 new String[] { String.class.getName(), Long.class.getName() },
1045 OrganizationModelImpl.UUID_COLUMN_BITMASK |
1046 OrganizationModelImpl.COMPANYID_COLUMN_BITMASK |
1047 OrganizationModelImpl.NAME_COLUMN_BITMASK);
1048 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
1049 OrganizationModelImpl.FINDER_CACHE_ENABLED, Long.class,
1050 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
1051 new String[] { String.class.getName(), Long.class.getName() });
1052
1053
1061 @Override
1062 public List<Organization> findByUuid_C(String uuid, long companyId)
1063 throws SystemException {
1064 return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
1065 QueryUtil.ALL_POS, null);
1066 }
1067
1068
1082 @Override
1083 public List<Organization> findByUuid_C(String uuid, long companyId,
1084 int start, int end) throws SystemException {
1085 return findByUuid_C(uuid, companyId, start, end, null);
1086 }
1087
1088
1103 @Override
1104 public List<Organization> findByUuid_C(String uuid, long companyId,
1105 int start, int end, OrderByComparator orderByComparator)
1106 throws SystemException {
1107 boolean pagination = true;
1108 FinderPath finderPath = null;
1109 Object[] finderArgs = null;
1110
1111 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1112 (orderByComparator == null)) {
1113 pagination = false;
1114 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
1115 finderArgs = new Object[] { uuid, companyId };
1116 }
1117 else {
1118 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
1119 finderArgs = new Object[] {
1120 uuid, companyId,
1121
1122 start, end, orderByComparator
1123 };
1124 }
1125
1126 List<Organization> list = (List<Organization>)FinderCacheUtil.getResult(finderPath,
1127 finderArgs, this);
1128
1129 if ((list != null) && !list.isEmpty()) {
1130 for (Organization organization : list) {
1131 if (!Validator.equals(uuid, organization.getUuid()) ||
1132 (companyId != organization.getCompanyId())) {
1133 list = null;
1134
1135 break;
1136 }
1137 }
1138 }
1139
1140 if (list == null) {
1141 StringBundler query = null;
1142
1143 if (orderByComparator != null) {
1144 query = new StringBundler(4 +
1145 (orderByComparator.getOrderByFields().length * 3));
1146 }
1147 else {
1148 query = new StringBundler(4);
1149 }
1150
1151 query.append(_SQL_SELECT_ORGANIZATION_WHERE);
1152
1153 boolean bindUuid = false;
1154
1155 if (uuid == null) {
1156 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1157 }
1158 else if (uuid.equals(StringPool.BLANK)) {
1159 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1160 }
1161 else {
1162 bindUuid = true;
1163
1164 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1165 }
1166
1167 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1168
1169 if (orderByComparator != null) {
1170 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1171 orderByComparator);
1172 }
1173 else
1174 if (pagination) {
1175 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
1176 }
1177
1178 String sql = query.toString();
1179
1180 Session session = null;
1181
1182 try {
1183 session = openSession();
1184
1185 Query q = session.createQuery(sql);
1186
1187 QueryPos qPos = QueryPos.getInstance(q);
1188
1189 if (bindUuid) {
1190 qPos.add(uuid);
1191 }
1192
1193 qPos.add(companyId);
1194
1195 if (!pagination) {
1196 list = (List<Organization>)QueryUtil.list(q, getDialect(),
1197 start, end, false);
1198
1199 Collections.sort(list);
1200
1201 list = new UnmodifiableList<Organization>(list);
1202 }
1203 else {
1204 list = (List<Organization>)QueryUtil.list(q, getDialect(),
1205 start, end);
1206 }
1207
1208 cacheResult(list);
1209
1210 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1211 }
1212 catch (Exception e) {
1213 FinderCacheUtil.removeResult(finderPath, finderArgs);
1214
1215 throw processException(e);
1216 }
1217 finally {
1218 closeSession(session);
1219 }
1220 }
1221
1222 return list;
1223 }
1224
1225
1235 @Override
1236 public Organization findByUuid_C_First(String uuid, long companyId,
1237 OrderByComparator orderByComparator)
1238 throws NoSuchOrganizationException, SystemException {
1239 Organization organization = fetchByUuid_C_First(uuid, companyId,
1240 orderByComparator);
1241
1242 if (organization != null) {
1243 return organization;
1244 }
1245
1246 StringBundler msg = new StringBundler(6);
1247
1248 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1249
1250 msg.append("uuid=");
1251 msg.append(uuid);
1252
1253 msg.append(", companyId=");
1254 msg.append(companyId);
1255
1256 msg.append(StringPool.CLOSE_CURLY_BRACE);
1257
1258 throw new NoSuchOrganizationException(msg.toString());
1259 }
1260
1261
1270 @Override
1271 public Organization fetchByUuid_C_First(String uuid, long companyId,
1272 OrderByComparator orderByComparator) throws SystemException {
1273 List<Organization> list = findByUuid_C(uuid, companyId, 0, 1,
1274 orderByComparator);
1275
1276 if (!list.isEmpty()) {
1277 return list.get(0);
1278 }
1279
1280 return null;
1281 }
1282
1283
1293 @Override
1294 public Organization findByUuid_C_Last(String uuid, long companyId,
1295 OrderByComparator orderByComparator)
1296 throws NoSuchOrganizationException, SystemException {
1297 Organization organization = fetchByUuid_C_Last(uuid, companyId,
1298 orderByComparator);
1299
1300 if (organization != null) {
1301 return organization;
1302 }
1303
1304 StringBundler msg = new StringBundler(6);
1305
1306 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1307
1308 msg.append("uuid=");
1309 msg.append(uuid);
1310
1311 msg.append(", companyId=");
1312 msg.append(companyId);
1313
1314 msg.append(StringPool.CLOSE_CURLY_BRACE);
1315
1316 throw new NoSuchOrganizationException(msg.toString());
1317 }
1318
1319
1328 @Override
1329 public Organization fetchByUuid_C_Last(String uuid, long companyId,
1330 OrderByComparator orderByComparator) throws SystemException {
1331 int count = countByUuid_C(uuid, companyId);
1332
1333 if (count == 0) {
1334 return null;
1335 }
1336
1337 List<Organization> list = findByUuid_C(uuid, companyId, count - 1,
1338 count, orderByComparator);
1339
1340 if (!list.isEmpty()) {
1341 return list.get(0);
1342 }
1343
1344 return null;
1345 }
1346
1347
1358 @Override
1359 public Organization[] findByUuid_C_PrevAndNext(long organizationId,
1360 String uuid, long companyId, OrderByComparator orderByComparator)
1361 throws NoSuchOrganizationException, SystemException {
1362 Organization organization = findByPrimaryKey(organizationId);
1363
1364 Session session = null;
1365
1366 try {
1367 session = openSession();
1368
1369 Organization[] array = new OrganizationImpl[3];
1370
1371 array[0] = getByUuid_C_PrevAndNext(session, organization, uuid,
1372 companyId, orderByComparator, true);
1373
1374 array[1] = organization;
1375
1376 array[2] = getByUuid_C_PrevAndNext(session, organization, uuid,
1377 companyId, orderByComparator, false);
1378
1379 return array;
1380 }
1381 catch (Exception e) {
1382 throw processException(e);
1383 }
1384 finally {
1385 closeSession(session);
1386 }
1387 }
1388
1389 protected Organization getByUuid_C_PrevAndNext(Session session,
1390 Organization organization, String uuid, long companyId,
1391 OrderByComparator orderByComparator, boolean previous) {
1392 StringBundler query = null;
1393
1394 if (orderByComparator != null) {
1395 query = new StringBundler(6 +
1396 (orderByComparator.getOrderByFields().length * 6));
1397 }
1398 else {
1399 query = new StringBundler(3);
1400 }
1401
1402 query.append(_SQL_SELECT_ORGANIZATION_WHERE);
1403
1404 boolean bindUuid = false;
1405
1406 if (uuid == null) {
1407 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1408 }
1409 else if (uuid.equals(StringPool.BLANK)) {
1410 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1411 }
1412 else {
1413 bindUuid = true;
1414
1415 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1416 }
1417
1418 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1419
1420 if (orderByComparator != null) {
1421 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1422
1423 if (orderByConditionFields.length > 0) {
1424 query.append(WHERE_AND);
1425 }
1426
1427 for (int i = 0; i < orderByConditionFields.length; i++) {
1428 query.append(_ORDER_BY_ENTITY_ALIAS);
1429 query.append(orderByConditionFields[i]);
1430
1431 if ((i + 1) < orderByConditionFields.length) {
1432 if (orderByComparator.isAscending() ^ previous) {
1433 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1434 }
1435 else {
1436 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1437 }
1438 }
1439 else {
1440 if (orderByComparator.isAscending() ^ previous) {
1441 query.append(WHERE_GREATER_THAN);
1442 }
1443 else {
1444 query.append(WHERE_LESSER_THAN);
1445 }
1446 }
1447 }
1448
1449 query.append(ORDER_BY_CLAUSE);
1450
1451 String[] orderByFields = orderByComparator.getOrderByFields();
1452
1453 for (int i = 0; i < orderByFields.length; i++) {
1454 query.append(_ORDER_BY_ENTITY_ALIAS);
1455 query.append(orderByFields[i]);
1456
1457 if ((i + 1) < orderByFields.length) {
1458 if (orderByComparator.isAscending() ^ previous) {
1459 query.append(ORDER_BY_ASC_HAS_NEXT);
1460 }
1461 else {
1462 query.append(ORDER_BY_DESC_HAS_NEXT);
1463 }
1464 }
1465 else {
1466 if (orderByComparator.isAscending() ^ previous) {
1467 query.append(ORDER_BY_ASC);
1468 }
1469 else {
1470 query.append(ORDER_BY_DESC);
1471 }
1472 }
1473 }
1474 }
1475 else {
1476 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
1477 }
1478
1479 String sql = query.toString();
1480
1481 Query q = session.createQuery(sql);
1482
1483 q.setFirstResult(0);
1484 q.setMaxResults(2);
1485
1486 QueryPos qPos = QueryPos.getInstance(q);
1487
1488 if (bindUuid) {
1489 qPos.add(uuid);
1490 }
1491
1492 qPos.add(companyId);
1493
1494 if (orderByComparator != null) {
1495 Object[] values = orderByComparator.getOrderByConditionValues(organization);
1496
1497 for (Object value : values) {
1498 qPos.add(value);
1499 }
1500 }
1501
1502 List<Organization> list = q.list();
1503
1504 if (list.size() == 2) {
1505 return list.get(1);
1506 }
1507 else {
1508 return null;
1509 }
1510 }
1511
1512
1520 @Override
1521 public List<Organization> filterFindByUuid_C(String uuid, long companyId)
1522 throws SystemException {
1523 return filterFindByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
1524 QueryUtil.ALL_POS, null);
1525 }
1526
1527
1541 @Override
1542 public List<Organization> filterFindByUuid_C(String uuid, long companyId,
1543 int start, int end) throws SystemException {
1544 return filterFindByUuid_C(uuid, companyId, start, end, null);
1545 }
1546
1547
1562 @Override
1563 public List<Organization> filterFindByUuid_C(String uuid, long companyId,
1564 int start, int end, OrderByComparator orderByComparator)
1565 throws SystemException {
1566 if (!InlineSQLHelperUtil.isEnabled()) {
1567 return findByUuid_C(uuid, companyId, start, end, orderByComparator);
1568 }
1569
1570 StringBundler query = null;
1571
1572 if (orderByComparator != null) {
1573 query = new StringBundler(4 +
1574 (orderByComparator.getOrderByFields().length * 3));
1575 }
1576 else {
1577 query = new StringBundler(4);
1578 }
1579
1580 if (getDB().isSupportsInlineDistinct()) {
1581 query.append(_FILTER_SQL_SELECT_ORGANIZATION_WHERE);
1582 }
1583 else {
1584 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1);
1585 }
1586
1587 boolean bindUuid = false;
1588
1589 if (uuid == null) {
1590 query.append(_FINDER_COLUMN_UUID_C_UUID_1_SQL);
1591 }
1592 else if (uuid.equals(StringPool.BLANK)) {
1593 query.append(_FINDER_COLUMN_UUID_C_UUID_3_SQL);
1594 }
1595 else {
1596 bindUuid = true;
1597
1598 query.append(_FINDER_COLUMN_UUID_C_UUID_2_SQL);
1599 }
1600
1601 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1602
1603 if (!getDB().isSupportsInlineDistinct()) {
1604 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2);
1605 }
1606
1607 if (orderByComparator != null) {
1608 if (getDB().isSupportsInlineDistinct()) {
1609 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1610 orderByComparator, true);
1611 }
1612 else {
1613 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1614 orderByComparator, true);
1615 }
1616 }
1617 else {
1618 if (getDB().isSupportsInlineDistinct()) {
1619 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
1620 }
1621 else {
1622 query.append(OrganizationModelImpl.ORDER_BY_SQL);
1623 }
1624 }
1625
1626 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1627 Organization.class.getName(),
1628 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1629
1630 Session session = null;
1631
1632 try {
1633 session = openSession();
1634
1635 SQLQuery q = session.createSQLQuery(sql);
1636
1637 if (getDB().isSupportsInlineDistinct()) {
1638 q.addEntity(_FILTER_ENTITY_ALIAS, OrganizationImpl.class);
1639 }
1640 else {
1641 q.addEntity(_FILTER_ENTITY_TABLE, OrganizationImpl.class);
1642 }
1643
1644 QueryPos qPos = QueryPos.getInstance(q);
1645
1646 if (bindUuid) {
1647 qPos.add(uuid);
1648 }
1649
1650 qPos.add(companyId);
1651
1652 return (List<Organization>)QueryUtil.list(q, getDialect(), start,
1653 end);
1654 }
1655 catch (Exception e) {
1656 throw processException(e);
1657 }
1658 finally {
1659 closeSession(session);
1660 }
1661 }
1662
1663
1674 @Override
1675 public Organization[] filterFindByUuid_C_PrevAndNext(long organizationId,
1676 String uuid, long companyId, OrderByComparator orderByComparator)
1677 throws NoSuchOrganizationException, SystemException {
1678 if (!InlineSQLHelperUtil.isEnabled()) {
1679 return findByUuid_C_PrevAndNext(organizationId, uuid, companyId,
1680 orderByComparator);
1681 }
1682
1683 Organization organization = findByPrimaryKey(organizationId);
1684
1685 Session session = null;
1686
1687 try {
1688 session = openSession();
1689
1690 Organization[] array = new OrganizationImpl[3];
1691
1692 array[0] = filterGetByUuid_C_PrevAndNext(session, organization,
1693 uuid, companyId, orderByComparator, true);
1694
1695 array[1] = organization;
1696
1697 array[2] = filterGetByUuid_C_PrevAndNext(session, organization,
1698 uuid, companyId, orderByComparator, false);
1699
1700 return array;
1701 }
1702 catch (Exception e) {
1703 throw processException(e);
1704 }
1705 finally {
1706 closeSession(session);
1707 }
1708 }
1709
1710 protected Organization filterGetByUuid_C_PrevAndNext(Session session,
1711 Organization organization, String uuid, long companyId,
1712 OrderByComparator orderByComparator, boolean previous) {
1713 StringBundler query = null;
1714
1715 if (orderByComparator != null) {
1716 query = new StringBundler(6 +
1717 (orderByComparator.getOrderByFields().length * 6));
1718 }
1719 else {
1720 query = new StringBundler(3);
1721 }
1722
1723 if (getDB().isSupportsInlineDistinct()) {
1724 query.append(_FILTER_SQL_SELECT_ORGANIZATION_WHERE);
1725 }
1726 else {
1727 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1);
1728 }
1729
1730 boolean bindUuid = false;
1731
1732 if (uuid == null) {
1733 query.append(_FINDER_COLUMN_UUID_C_UUID_1_SQL);
1734 }
1735 else if (uuid.equals(StringPool.BLANK)) {
1736 query.append(_FINDER_COLUMN_UUID_C_UUID_3_SQL);
1737 }
1738 else {
1739 bindUuid = true;
1740
1741 query.append(_FINDER_COLUMN_UUID_C_UUID_2_SQL);
1742 }
1743
1744 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1745
1746 if (!getDB().isSupportsInlineDistinct()) {
1747 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2);
1748 }
1749
1750 if (orderByComparator != null) {
1751 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1752
1753 if (orderByConditionFields.length > 0) {
1754 query.append(WHERE_AND);
1755 }
1756
1757 for (int i = 0; i < orderByConditionFields.length; i++) {
1758 if (getDB().isSupportsInlineDistinct()) {
1759 query.append(_ORDER_BY_ENTITY_ALIAS);
1760 }
1761 else {
1762 query.append(_ORDER_BY_ENTITY_TABLE);
1763 }
1764
1765 query.append(orderByConditionFields[i]);
1766
1767 if ((i + 1) < orderByConditionFields.length) {
1768 if (orderByComparator.isAscending() ^ previous) {
1769 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1770 }
1771 else {
1772 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1773 }
1774 }
1775 else {
1776 if (orderByComparator.isAscending() ^ previous) {
1777 query.append(WHERE_GREATER_THAN);
1778 }
1779 else {
1780 query.append(WHERE_LESSER_THAN);
1781 }
1782 }
1783 }
1784
1785 query.append(ORDER_BY_CLAUSE);
1786
1787 String[] orderByFields = orderByComparator.getOrderByFields();
1788
1789 for (int i = 0; i < orderByFields.length; i++) {
1790 if (getDB().isSupportsInlineDistinct()) {
1791 query.append(_ORDER_BY_ENTITY_ALIAS);
1792 }
1793 else {
1794 query.append(_ORDER_BY_ENTITY_TABLE);
1795 }
1796
1797 query.append(orderByFields[i]);
1798
1799 if ((i + 1) < orderByFields.length) {
1800 if (orderByComparator.isAscending() ^ previous) {
1801 query.append(ORDER_BY_ASC_HAS_NEXT);
1802 }
1803 else {
1804 query.append(ORDER_BY_DESC_HAS_NEXT);
1805 }
1806 }
1807 else {
1808 if (orderByComparator.isAscending() ^ previous) {
1809 query.append(ORDER_BY_ASC);
1810 }
1811 else {
1812 query.append(ORDER_BY_DESC);
1813 }
1814 }
1815 }
1816 }
1817 else {
1818 if (getDB().isSupportsInlineDistinct()) {
1819 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
1820 }
1821 else {
1822 query.append(OrganizationModelImpl.ORDER_BY_SQL);
1823 }
1824 }
1825
1826 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1827 Organization.class.getName(),
1828 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1829
1830 SQLQuery q = session.createSQLQuery(sql);
1831
1832 q.setFirstResult(0);
1833 q.setMaxResults(2);
1834
1835 if (getDB().isSupportsInlineDistinct()) {
1836 q.addEntity(_FILTER_ENTITY_ALIAS, OrganizationImpl.class);
1837 }
1838 else {
1839 q.addEntity(_FILTER_ENTITY_TABLE, OrganizationImpl.class);
1840 }
1841
1842 QueryPos qPos = QueryPos.getInstance(q);
1843
1844 if (bindUuid) {
1845 qPos.add(uuid);
1846 }
1847
1848 qPos.add(companyId);
1849
1850 if (orderByComparator != null) {
1851 Object[] values = orderByComparator.getOrderByConditionValues(organization);
1852
1853 for (Object value : values) {
1854 qPos.add(value);
1855 }
1856 }
1857
1858 List<Organization> list = q.list();
1859
1860 if (list.size() == 2) {
1861 return list.get(1);
1862 }
1863 else {
1864 return null;
1865 }
1866 }
1867
1868
1875 @Override
1876 public void removeByUuid_C(String uuid, long companyId)
1877 throws SystemException {
1878 for (Organization organization : findByUuid_C(uuid, companyId,
1879 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1880 remove(organization);
1881 }
1882 }
1883
1884
1892 @Override
1893 public int countByUuid_C(String uuid, long companyId)
1894 throws SystemException {
1895 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1896
1897 Object[] finderArgs = new Object[] { uuid, companyId };
1898
1899 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1900 this);
1901
1902 if (count == null) {
1903 StringBundler query = new StringBundler(3);
1904
1905 query.append(_SQL_COUNT_ORGANIZATION_WHERE);
1906
1907 boolean bindUuid = false;
1908
1909 if (uuid == null) {
1910 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1911 }
1912 else if (uuid.equals(StringPool.BLANK)) {
1913 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1914 }
1915 else {
1916 bindUuid = true;
1917
1918 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1919 }
1920
1921 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1922
1923 String sql = query.toString();
1924
1925 Session session = null;
1926
1927 try {
1928 session = openSession();
1929
1930 Query q = session.createQuery(sql);
1931
1932 QueryPos qPos = QueryPos.getInstance(q);
1933
1934 if (bindUuid) {
1935 qPos.add(uuid);
1936 }
1937
1938 qPos.add(companyId);
1939
1940 count = (Long)q.uniqueResult();
1941
1942 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1943 }
1944 catch (Exception e) {
1945 FinderCacheUtil.removeResult(finderPath, finderArgs);
1946
1947 throw processException(e);
1948 }
1949 finally {
1950 closeSession(session);
1951 }
1952 }
1953
1954 return count.intValue();
1955 }
1956
1957
1965 @Override
1966 public int filterCountByUuid_C(String uuid, long companyId)
1967 throws SystemException {
1968 if (!InlineSQLHelperUtil.isEnabled()) {
1969 return countByUuid_C(uuid, companyId);
1970 }
1971
1972 StringBundler query = new StringBundler(3);
1973
1974 query.append(_FILTER_SQL_COUNT_ORGANIZATION_WHERE);
1975
1976 boolean bindUuid = false;
1977
1978 if (uuid == null) {
1979 query.append(_FINDER_COLUMN_UUID_C_UUID_1_SQL);
1980 }
1981 else if (uuid.equals(StringPool.BLANK)) {
1982 query.append(_FINDER_COLUMN_UUID_C_UUID_3_SQL);
1983 }
1984 else {
1985 bindUuid = true;
1986
1987 query.append(_FINDER_COLUMN_UUID_C_UUID_2_SQL);
1988 }
1989
1990 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1991
1992 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1993 Organization.class.getName(),
1994 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1995
1996 Session session = null;
1997
1998 try {
1999 session = openSession();
2000
2001 SQLQuery q = session.createSQLQuery(sql);
2002
2003 q.addScalar(COUNT_COLUMN_NAME,
2004 com.liferay.portal.kernel.dao.orm.Type.LONG);
2005
2006 QueryPos qPos = QueryPos.getInstance(q);
2007
2008 if (bindUuid) {
2009 qPos.add(uuid);
2010 }
2011
2012 qPos.add(companyId);
2013
2014 Long count = (Long)q.uniqueResult();
2015
2016 return count.intValue();
2017 }
2018 catch (Exception e) {
2019 throw processException(e);
2020 }
2021 finally {
2022 closeSession(session);
2023 }
2024 }
2025
2026 private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "organization.uuid IS NULL AND ";
2027 private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "organization.uuid = ? AND ";
2028 private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(organization.uuid IS NULL OR organization.uuid = '') AND ";
2029 private static final String _FINDER_COLUMN_UUID_C_UUID_1_SQL = "organization.uuid_ IS NULL AND ";
2030 private static final String _FINDER_COLUMN_UUID_C_UUID_2_SQL = "organization.uuid_ = ? AND ";
2031 private static final String _FINDER_COLUMN_UUID_C_UUID_3_SQL = "(organization.uuid_ IS NULL OR organization.uuid_ = '') AND ";
2032 private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "organization.companyId = ?";
2033 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
2034 new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
2035 OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
2036 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
2037 new String[] {
2038 Long.class.getName(),
2039
2040 Integer.class.getName(), Integer.class.getName(),
2041 OrderByComparator.class.getName()
2042 });
2043 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
2044 new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
2045 OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
2046 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
2047 new String[] { Long.class.getName() },
2048 OrganizationModelImpl.COMPANYID_COLUMN_BITMASK |
2049 OrganizationModelImpl.NAME_COLUMN_BITMASK);
2050 public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
2051 OrganizationModelImpl.FINDER_CACHE_ENABLED, Long.class,
2052 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
2053 new String[] { Long.class.getName() });
2054
2055
2062 @Override
2063 public List<Organization> findByCompanyId(long companyId)
2064 throws SystemException {
2065 return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2066 null);
2067 }
2068
2069
2082 @Override
2083 public List<Organization> findByCompanyId(long companyId, int start, int end)
2084 throws SystemException {
2085 return findByCompanyId(companyId, start, end, null);
2086 }
2087
2088
2102 @Override
2103 public List<Organization> findByCompanyId(long companyId, int start,
2104 int end, OrderByComparator orderByComparator) throws SystemException {
2105 boolean pagination = true;
2106 FinderPath finderPath = null;
2107 Object[] finderArgs = null;
2108
2109 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2110 (orderByComparator == null)) {
2111 pagination = false;
2112 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
2113 finderArgs = new Object[] { companyId };
2114 }
2115 else {
2116 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
2117 finderArgs = new Object[] { companyId, start, end, orderByComparator };
2118 }
2119
2120 List<Organization> list = (List<Organization>)FinderCacheUtil.getResult(finderPath,
2121 finderArgs, this);
2122
2123 if ((list != null) && !list.isEmpty()) {
2124 for (Organization organization : list) {
2125 if ((companyId != organization.getCompanyId())) {
2126 list = null;
2127
2128 break;
2129 }
2130 }
2131 }
2132
2133 if (list == null) {
2134 StringBundler query = null;
2135
2136 if (orderByComparator != null) {
2137 query = new StringBundler(3 +
2138 (orderByComparator.getOrderByFields().length * 3));
2139 }
2140 else {
2141 query = new StringBundler(3);
2142 }
2143
2144 query.append(_SQL_SELECT_ORGANIZATION_WHERE);
2145
2146 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2147
2148 if (orderByComparator != null) {
2149 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2150 orderByComparator);
2151 }
2152 else
2153 if (pagination) {
2154 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
2155 }
2156
2157 String sql = query.toString();
2158
2159 Session session = null;
2160
2161 try {
2162 session = openSession();
2163
2164 Query q = session.createQuery(sql);
2165
2166 QueryPos qPos = QueryPos.getInstance(q);
2167
2168 qPos.add(companyId);
2169
2170 if (!pagination) {
2171 list = (List<Organization>)QueryUtil.list(q, getDialect(),
2172 start, end, false);
2173
2174 Collections.sort(list);
2175
2176 list = new UnmodifiableList<Organization>(list);
2177 }
2178 else {
2179 list = (List<Organization>)QueryUtil.list(q, getDialect(),
2180 start, end);
2181 }
2182
2183 cacheResult(list);
2184
2185 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2186 }
2187 catch (Exception e) {
2188 FinderCacheUtil.removeResult(finderPath, finderArgs);
2189
2190 throw processException(e);
2191 }
2192 finally {
2193 closeSession(session);
2194 }
2195 }
2196
2197 return list;
2198 }
2199
2200
2209 @Override
2210 public Organization findByCompanyId_First(long companyId,
2211 OrderByComparator orderByComparator)
2212 throws NoSuchOrganizationException, SystemException {
2213 Organization organization = fetchByCompanyId_First(companyId,
2214 orderByComparator);
2215
2216 if (organization != null) {
2217 return organization;
2218 }
2219
2220 StringBundler msg = new StringBundler(4);
2221
2222 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2223
2224 msg.append("companyId=");
2225 msg.append(companyId);
2226
2227 msg.append(StringPool.CLOSE_CURLY_BRACE);
2228
2229 throw new NoSuchOrganizationException(msg.toString());
2230 }
2231
2232
2240 @Override
2241 public Organization fetchByCompanyId_First(long companyId,
2242 OrderByComparator orderByComparator) throws SystemException {
2243 List<Organization> list = findByCompanyId(companyId, 0, 1,
2244 orderByComparator);
2245
2246 if (!list.isEmpty()) {
2247 return list.get(0);
2248 }
2249
2250 return null;
2251 }
2252
2253
2262 @Override
2263 public Organization findByCompanyId_Last(long companyId,
2264 OrderByComparator orderByComparator)
2265 throws NoSuchOrganizationException, SystemException {
2266 Organization organization = fetchByCompanyId_Last(companyId,
2267 orderByComparator);
2268
2269 if (organization != null) {
2270 return organization;
2271 }
2272
2273 StringBundler msg = new StringBundler(4);
2274
2275 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2276
2277 msg.append("companyId=");
2278 msg.append(companyId);
2279
2280 msg.append(StringPool.CLOSE_CURLY_BRACE);
2281
2282 throw new NoSuchOrganizationException(msg.toString());
2283 }
2284
2285
2293 @Override
2294 public Organization fetchByCompanyId_Last(long companyId,
2295 OrderByComparator orderByComparator) throws SystemException {
2296 int count = countByCompanyId(companyId);
2297
2298 if (count == 0) {
2299 return null;
2300 }
2301
2302 List<Organization> list = findByCompanyId(companyId, count - 1, count,
2303 orderByComparator);
2304
2305 if (!list.isEmpty()) {
2306 return list.get(0);
2307 }
2308
2309 return null;
2310 }
2311
2312
2322 @Override
2323 public Organization[] findByCompanyId_PrevAndNext(long organizationId,
2324 long companyId, OrderByComparator orderByComparator)
2325 throws NoSuchOrganizationException, SystemException {
2326 Organization organization = findByPrimaryKey(organizationId);
2327
2328 Session session = null;
2329
2330 try {
2331 session = openSession();
2332
2333 Organization[] array = new OrganizationImpl[3];
2334
2335 array[0] = getByCompanyId_PrevAndNext(session, organization,
2336 companyId, orderByComparator, true);
2337
2338 array[1] = organization;
2339
2340 array[2] = getByCompanyId_PrevAndNext(session, organization,
2341 companyId, orderByComparator, false);
2342
2343 return array;
2344 }
2345 catch (Exception e) {
2346 throw processException(e);
2347 }
2348 finally {
2349 closeSession(session);
2350 }
2351 }
2352
2353 protected Organization getByCompanyId_PrevAndNext(Session session,
2354 Organization organization, long companyId,
2355 OrderByComparator orderByComparator, boolean previous) {
2356 StringBundler query = null;
2357
2358 if (orderByComparator != null) {
2359 query = new StringBundler(6 +
2360 (orderByComparator.getOrderByFields().length * 6));
2361 }
2362 else {
2363 query = new StringBundler(3);
2364 }
2365
2366 query.append(_SQL_SELECT_ORGANIZATION_WHERE);
2367
2368 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2369
2370 if (orderByComparator != null) {
2371 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2372
2373 if (orderByConditionFields.length > 0) {
2374 query.append(WHERE_AND);
2375 }
2376
2377 for (int i = 0; i < orderByConditionFields.length; i++) {
2378 query.append(_ORDER_BY_ENTITY_ALIAS);
2379 query.append(orderByConditionFields[i]);
2380
2381 if ((i + 1) < orderByConditionFields.length) {
2382 if (orderByComparator.isAscending() ^ previous) {
2383 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2384 }
2385 else {
2386 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2387 }
2388 }
2389 else {
2390 if (orderByComparator.isAscending() ^ previous) {
2391 query.append(WHERE_GREATER_THAN);
2392 }
2393 else {
2394 query.append(WHERE_LESSER_THAN);
2395 }
2396 }
2397 }
2398
2399 query.append(ORDER_BY_CLAUSE);
2400
2401 String[] orderByFields = orderByComparator.getOrderByFields();
2402
2403 for (int i = 0; i < orderByFields.length; i++) {
2404 query.append(_ORDER_BY_ENTITY_ALIAS);
2405 query.append(orderByFields[i]);
2406
2407 if ((i + 1) < orderByFields.length) {
2408 if (orderByComparator.isAscending() ^ previous) {
2409 query.append(ORDER_BY_ASC_HAS_NEXT);
2410 }
2411 else {
2412 query.append(ORDER_BY_DESC_HAS_NEXT);
2413 }
2414 }
2415 else {
2416 if (orderByComparator.isAscending() ^ previous) {
2417 query.append(ORDER_BY_ASC);
2418 }
2419 else {
2420 query.append(ORDER_BY_DESC);
2421 }
2422 }
2423 }
2424 }
2425 else {
2426 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
2427 }
2428
2429 String sql = query.toString();
2430
2431 Query q = session.createQuery(sql);
2432
2433 q.setFirstResult(0);
2434 q.setMaxResults(2);
2435
2436 QueryPos qPos = QueryPos.getInstance(q);
2437
2438 qPos.add(companyId);
2439
2440 if (orderByComparator != null) {
2441 Object[] values = orderByComparator.getOrderByConditionValues(organization);
2442
2443 for (Object value : values) {
2444 qPos.add(value);
2445 }
2446 }
2447
2448 List<Organization> list = q.list();
2449
2450 if (list.size() == 2) {
2451 return list.get(1);
2452 }
2453 else {
2454 return null;
2455 }
2456 }
2457
2458
2465 @Override
2466 public List<Organization> filterFindByCompanyId(long companyId)
2467 throws SystemException {
2468 return filterFindByCompanyId(companyId, QueryUtil.ALL_POS,
2469 QueryUtil.ALL_POS, null);
2470 }
2471
2472
2485 @Override
2486 public List<Organization> filterFindByCompanyId(long companyId, int start,
2487 int end) throws SystemException {
2488 return filterFindByCompanyId(companyId, start, end, null);
2489 }
2490
2491
2505 @Override
2506 public List<Organization> filterFindByCompanyId(long companyId, int start,
2507 int end, OrderByComparator orderByComparator) throws SystemException {
2508 if (!InlineSQLHelperUtil.isEnabled()) {
2509 return findByCompanyId(companyId, start, end, orderByComparator);
2510 }
2511
2512 StringBundler query = null;
2513
2514 if (orderByComparator != null) {
2515 query = new StringBundler(3 +
2516 (orderByComparator.getOrderByFields().length * 3));
2517 }
2518 else {
2519 query = new StringBundler(3);
2520 }
2521
2522 if (getDB().isSupportsInlineDistinct()) {
2523 query.append(_FILTER_SQL_SELECT_ORGANIZATION_WHERE);
2524 }
2525 else {
2526 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1);
2527 }
2528
2529 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2530
2531 if (!getDB().isSupportsInlineDistinct()) {
2532 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2);
2533 }
2534
2535 if (orderByComparator != null) {
2536 if (getDB().isSupportsInlineDistinct()) {
2537 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2538 orderByComparator, true);
2539 }
2540 else {
2541 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
2542 orderByComparator, true);
2543 }
2544 }
2545 else {
2546 if (getDB().isSupportsInlineDistinct()) {
2547 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
2548 }
2549 else {
2550 query.append(OrganizationModelImpl.ORDER_BY_SQL);
2551 }
2552 }
2553
2554 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2555 Organization.class.getName(),
2556 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2557
2558 Session session = null;
2559
2560 try {
2561 session = openSession();
2562
2563 SQLQuery q = session.createSQLQuery(sql);
2564
2565 if (getDB().isSupportsInlineDistinct()) {
2566 q.addEntity(_FILTER_ENTITY_ALIAS, OrganizationImpl.class);
2567 }
2568 else {
2569 q.addEntity(_FILTER_ENTITY_TABLE, OrganizationImpl.class);
2570 }
2571
2572 QueryPos qPos = QueryPos.getInstance(q);
2573
2574 qPos.add(companyId);
2575
2576 return (List<Organization>)QueryUtil.list(q, getDialect(), start,
2577 end);
2578 }
2579 catch (Exception e) {
2580 throw processException(e);
2581 }
2582 finally {
2583 closeSession(session);
2584 }
2585 }
2586
2587
2597 @Override
2598 public Organization[] filterFindByCompanyId_PrevAndNext(
2599 long organizationId, long companyId, OrderByComparator orderByComparator)
2600 throws NoSuchOrganizationException, SystemException {
2601 if (!InlineSQLHelperUtil.isEnabled()) {
2602 return findByCompanyId_PrevAndNext(organizationId, companyId,
2603 orderByComparator);
2604 }
2605
2606 Organization organization = findByPrimaryKey(organizationId);
2607
2608 Session session = null;
2609
2610 try {
2611 session = openSession();
2612
2613 Organization[] array = new OrganizationImpl[3];
2614
2615 array[0] = filterGetByCompanyId_PrevAndNext(session, organization,
2616 companyId, orderByComparator, true);
2617
2618 array[1] = organization;
2619
2620 array[2] = filterGetByCompanyId_PrevAndNext(session, organization,
2621 companyId, orderByComparator, false);
2622
2623 return array;
2624 }
2625 catch (Exception e) {
2626 throw processException(e);
2627 }
2628 finally {
2629 closeSession(session);
2630 }
2631 }
2632
2633 protected Organization filterGetByCompanyId_PrevAndNext(Session session,
2634 Organization organization, long companyId,
2635 OrderByComparator orderByComparator, boolean previous) {
2636 StringBundler query = null;
2637
2638 if (orderByComparator != null) {
2639 query = new StringBundler(6 +
2640 (orderByComparator.getOrderByFields().length * 6));
2641 }
2642 else {
2643 query = new StringBundler(3);
2644 }
2645
2646 if (getDB().isSupportsInlineDistinct()) {
2647 query.append(_FILTER_SQL_SELECT_ORGANIZATION_WHERE);
2648 }
2649 else {
2650 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1);
2651 }
2652
2653 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2654
2655 if (!getDB().isSupportsInlineDistinct()) {
2656 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2);
2657 }
2658
2659 if (orderByComparator != null) {
2660 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2661
2662 if (orderByConditionFields.length > 0) {
2663 query.append(WHERE_AND);
2664 }
2665
2666 for (int i = 0; i < orderByConditionFields.length; i++) {
2667 if (getDB().isSupportsInlineDistinct()) {
2668 query.append(_ORDER_BY_ENTITY_ALIAS);
2669 }
2670 else {
2671 query.append(_ORDER_BY_ENTITY_TABLE);
2672 }
2673
2674 query.append(orderByConditionFields[i]);
2675
2676 if ((i + 1) < orderByConditionFields.length) {
2677 if (orderByComparator.isAscending() ^ previous) {
2678 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2679 }
2680 else {
2681 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2682 }
2683 }
2684 else {
2685 if (orderByComparator.isAscending() ^ previous) {
2686 query.append(WHERE_GREATER_THAN);
2687 }
2688 else {
2689 query.append(WHERE_LESSER_THAN);
2690 }
2691 }
2692 }
2693
2694 query.append(ORDER_BY_CLAUSE);
2695
2696 String[] orderByFields = orderByComparator.getOrderByFields();
2697
2698 for (int i = 0; i < orderByFields.length; i++) {
2699 if (getDB().isSupportsInlineDistinct()) {
2700 query.append(_ORDER_BY_ENTITY_ALIAS);
2701 }
2702 else {
2703 query.append(_ORDER_BY_ENTITY_TABLE);
2704 }
2705
2706 query.append(orderByFields[i]);
2707
2708 if ((i + 1) < orderByFields.length) {
2709 if (orderByComparator.isAscending() ^ previous) {
2710 query.append(ORDER_BY_ASC_HAS_NEXT);
2711 }
2712 else {
2713 query.append(ORDER_BY_DESC_HAS_NEXT);
2714 }
2715 }
2716 else {
2717 if (orderByComparator.isAscending() ^ previous) {
2718 query.append(ORDER_BY_ASC);
2719 }
2720 else {
2721 query.append(ORDER_BY_DESC);
2722 }
2723 }
2724 }
2725 }
2726 else {
2727 if (getDB().isSupportsInlineDistinct()) {
2728 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
2729 }
2730 else {
2731 query.append(OrganizationModelImpl.ORDER_BY_SQL);
2732 }
2733 }
2734
2735 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2736 Organization.class.getName(),
2737 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2738
2739 SQLQuery q = session.createSQLQuery(sql);
2740
2741 q.setFirstResult(0);
2742 q.setMaxResults(2);
2743
2744 if (getDB().isSupportsInlineDistinct()) {
2745 q.addEntity(_FILTER_ENTITY_ALIAS, OrganizationImpl.class);
2746 }
2747 else {
2748 q.addEntity(_FILTER_ENTITY_TABLE, OrganizationImpl.class);
2749 }
2750
2751 QueryPos qPos = QueryPos.getInstance(q);
2752
2753 qPos.add(companyId);
2754
2755 if (orderByComparator != null) {
2756 Object[] values = orderByComparator.getOrderByConditionValues(organization);
2757
2758 for (Object value : values) {
2759 qPos.add(value);
2760 }
2761 }
2762
2763 List<Organization> list = q.list();
2764
2765 if (list.size() == 2) {
2766 return list.get(1);
2767 }
2768 else {
2769 return null;
2770 }
2771 }
2772
2773
2779 @Override
2780 public void removeByCompanyId(long companyId) throws SystemException {
2781 for (Organization organization : findByCompanyId(companyId,
2782 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2783 remove(organization);
2784 }
2785 }
2786
2787
2794 @Override
2795 public int countByCompanyId(long companyId) throws SystemException {
2796 FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
2797
2798 Object[] finderArgs = new Object[] { companyId };
2799
2800 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2801 this);
2802
2803 if (count == null) {
2804 StringBundler query = new StringBundler(2);
2805
2806 query.append(_SQL_COUNT_ORGANIZATION_WHERE);
2807
2808 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2809
2810 String sql = query.toString();
2811
2812 Session session = null;
2813
2814 try {
2815 session = openSession();
2816
2817 Query q = session.createQuery(sql);
2818
2819 QueryPos qPos = QueryPos.getInstance(q);
2820
2821 qPos.add(companyId);
2822
2823 count = (Long)q.uniqueResult();
2824
2825 FinderCacheUtil.putResult(finderPath, finderArgs, count);
2826 }
2827 catch (Exception e) {
2828 FinderCacheUtil.removeResult(finderPath, finderArgs);
2829
2830 throw processException(e);
2831 }
2832 finally {
2833 closeSession(session);
2834 }
2835 }
2836
2837 return count.intValue();
2838 }
2839
2840
2847 @Override
2848 public int filterCountByCompanyId(long companyId) throws SystemException {
2849 if (!InlineSQLHelperUtil.isEnabled()) {
2850 return countByCompanyId(companyId);
2851 }
2852
2853 StringBundler query = new StringBundler(2);
2854
2855 query.append(_FILTER_SQL_COUNT_ORGANIZATION_WHERE);
2856
2857 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2858
2859 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2860 Organization.class.getName(),
2861 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2862
2863 Session session = null;
2864
2865 try {
2866 session = openSession();
2867
2868 SQLQuery q = session.createSQLQuery(sql);
2869
2870 q.addScalar(COUNT_COLUMN_NAME,
2871 com.liferay.portal.kernel.dao.orm.Type.LONG);
2872
2873 QueryPos qPos = QueryPos.getInstance(q);
2874
2875 qPos.add(companyId);
2876
2877 Long count = (Long)q.uniqueResult();
2878
2879 return count.intValue();
2880 }
2881 catch (Exception e) {
2882 throw processException(e);
2883 }
2884 finally {
2885 closeSession(session);
2886 }
2887 }
2888
2889 private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "organization.companyId = ?";
2890 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_LOCATIONS =
2891 new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
2892 OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
2893 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByLocations",
2894 new String[] {
2895 Long.class.getName(),
2896
2897 Integer.class.getName(), Integer.class.getName(),
2898 OrderByComparator.class.getName()
2899 });
2900 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LOCATIONS =
2901 new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
2902 OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
2903 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByLocations",
2904 new String[] { Long.class.getName() },
2905 OrganizationModelImpl.COMPANYID_COLUMN_BITMASK |
2906 OrganizationModelImpl.NAME_COLUMN_BITMASK);
2907 public static final FinderPath FINDER_PATH_COUNT_BY_LOCATIONS = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
2908 OrganizationModelImpl.FINDER_CACHE_ENABLED, Long.class,
2909 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByLocations",
2910 new String[] { Long.class.getName() });
2911
2912
2919 @Override
2920 public List<Organization> findByLocations(long companyId)
2921 throws SystemException {
2922 return findByLocations(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2923 null);
2924 }
2925
2926
2939 @Override
2940 public List<Organization> findByLocations(long companyId, int start, int end)
2941 throws SystemException {
2942 return findByLocations(companyId, start, end, null);
2943 }
2944
2945
2959 @Override
2960 public List<Organization> findByLocations(long companyId, int start,
2961 int end, OrderByComparator orderByComparator) throws SystemException {
2962 boolean pagination = true;
2963 FinderPath finderPath = null;
2964 Object[] finderArgs = null;
2965
2966 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2967 (orderByComparator == null)) {
2968 pagination = false;
2969 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LOCATIONS;
2970 finderArgs = new Object[] { companyId };
2971 }
2972 else {
2973 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_LOCATIONS;
2974 finderArgs = new Object[] { companyId, start, end, orderByComparator };
2975 }
2976
2977 List<Organization> list = (List<Organization>)FinderCacheUtil.getResult(finderPath,
2978 finderArgs, this);
2979
2980 if ((list != null) && !list.isEmpty()) {
2981 for (Organization organization : list) {
2982 if ((companyId != organization.getCompanyId())) {
2983 list = null;
2984
2985 break;
2986 }
2987 }
2988 }
2989
2990 if (list == null) {
2991 StringBundler query = null;
2992
2993 if (orderByComparator != null) {
2994 query = new StringBundler(3 +
2995 (orderByComparator.getOrderByFields().length * 3));
2996 }
2997 else {
2998 query = new StringBundler(3);
2999 }
3000
3001 query.append(_SQL_SELECT_ORGANIZATION_WHERE);
3002
3003 query.append(_FINDER_COLUMN_LOCATIONS_COMPANYID_2);
3004
3005 if (orderByComparator != null) {
3006 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3007 orderByComparator);
3008 }
3009 else
3010 if (pagination) {
3011 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
3012 }
3013
3014 String sql = query.toString();
3015
3016 Session session = null;
3017
3018 try {
3019 session = openSession();
3020
3021 Query q = session.createQuery(sql);
3022
3023 QueryPos qPos = QueryPos.getInstance(q);
3024
3025 qPos.add(companyId);
3026
3027 if (!pagination) {
3028 list = (List<Organization>)QueryUtil.list(q, getDialect(),
3029 start, end, false);
3030
3031 Collections.sort(list);
3032
3033 list = new UnmodifiableList<Organization>(list);
3034 }
3035 else {
3036 list = (List<Organization>)QueryUtil.list(q, getDialect(),
3037 start, end);
3038 }
3039
3040 cacheResult(list);
3041
3042 FinderCacheUtil.putResult(finderPath, finderArgs, list);
3043 }
3044 catch (Exception e) {
3045 FinderCacheUtil.removeResult(finderPath, finderArgs);
3046
3047 throw processException(e);
3048 }
3049 finally {
3050 closeSession(session);
3051 }
3052 }
3053
3054 return list;
3055 }
3056
3057
3066 @Override
3067 public Organization findByLocations_First(long companyId,
3068 OrderByComparator orderByComparator)
3069 throws NoSuchOrganizationException, SystemException {
3070 Organization organization = fetchByLocations_First(companyId,
3071 orderByComparator);
3072
3073 if (organization != null) {
3074 return organization;
3075 }
3076
3077 StringBundler msg = new StringBundler(4);
3078
3079 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3080
3081 msg.append("companyId=");
3082 msg.append(companyId);
3083
3084 msg.append(StringPool.CLOSE_CURLY_BRACE);
3085
3086 throw new NoSuchOrganizationException(msg.toString());
3087 }
3088
3089
3097 @Override
3098 public Organization fetchByLocations_First(long companyId,
3099 OrderByComparator orderByComparator) throws SystemException {
3100 List<Organization> list = findByLocations(companyId, 0, 1,
3101 orderByComparator);
3102
3103 if (!list.isEmpty()) {
3104 return list.get(0);
3105 }
3106
3107 return null;
3108 }
3109
3110
3119 @Override
3120 public Organization findByLocations_Last(long companyId,
3121 OrderByComparator orderByComparator)
3122 throws NoSuchOrganizationException, SystemException {
3123 Organization organization = fetchByLocations_Last(companyId,
3124 orderByComparator);
3125
3126 if (organization != null) {
3127 return organization;
3128 }
3129
3130 StringBundler msg = new StringBundler(4);
3131
3132 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3133
3134 msg.append("companyId=");
3135 msg.append(companyId);
3136
3137 msg.append(StringPool.CLOSE_CURLY_BRACE);
3138
3139 throw new NoSuchOrganizationException(msg.toString());
3140 }
3141
3142
3150 @Override
3151 public Organization fetchByLocations_Last(long companyId,
3152 OrderByComparator orderByComparator) throws SystemException {
3153 int count = countByLocations(companyId);
3154
3155 if (count == 0) {
3156 return null;
3157 }
3158
3159 List<Organization> list = findByLocations(companyId, count - 1, count,
3160 orderByComparator);
3161
3162 if (!list.isEmpty()) {
3163 return list.get(0);
3164 }
3165
3166 return null;
3167 }
3168
3169
3179 @Override
3180 public Organization[] findByLocations_PrevAndNext(long organizationId,
3181 long companyId, OrderByComparator orderByComparator)
3182 throws NoSuchOrganizationException, SystemException {
3183 Organization organization = findByPrimaryKey(organizationId);
3184
3185 Session session = null;
3186
3187 try {
3188 session = openSession();
3189
3190 Organization[] array = new OrganizationImpl[3];
3191
3192 array[0] = getByLocations_PrevAndNext(session, organization,
3193 companyId, orderByComparator, true);
3194
3195 array[1] = organization;
3196
3197 array[2] = getByLocations_PrevAndNext(session, organization,
3198 companyId, orderByComparator, false);
3199
3200 return array;
3201 }
3202 catch (Exception e) {
3203 throw processException(e);
3204 }
3205 finally {
3206 closeSession(session);
3207 }
3208 }
3209
3210 protected Organization getByLocations_PrevAndNext(Session session,
3211 Organization organization, long companyId,
3212 OrderByComparator orderByComparator, boolean previous) {
3213 StringBundler query = null;
3214
3215 if (orderByComparator != null) {
3216 query = new StringBundler(6 +
3217 (orderByComparator.getOrderByFields().length * 6));
3218 }
3219 else {
3220 query = new StringBundler(3);
3221 }
3222
3223 query.append(_SQL_SELECT_ORGANIZATION_WHERE);
3224
3225 query.append(_FINDER_COLUMN_LOCATIONS_COMPANYID_2);
3226
3227 if (orderByComparator != null) {
3228 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3229
3230 if (orderByConditionFields.length > 0) {
3231 query.append(WHERE_AND);
3232 }
3233
3234 for (int i = 0; i < orderByConditionFields.length; i++) {
3235 query.append(_ORDER_BY_ENTITY_ALIAS);
3236 query.append(orderByConditionFields[i]);
3237
3238 if ((i + 1) < orderByConditionFields.length) {
3239 if (orderByComparator.isAscending() ^ previous) {
3240 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3241 }
3242 else {
3243 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3244 }
3245 }
3246 else {
3247 if (orderByComparator.isAscending() ^ previous) {
3248 query.append(WHERE_GREATER_THAN);
3249 }
3250 else {
3251 query.append(WHERE_LESSER_THAN);
3252 }
3253 }
3254 }
3255
3256 query.append(ORDER_BY_CLAUSE);
3257
3258 String[] orderByFields = orderByComparator.getOrderByFields();
3259
3260 for (int i = 0; i < orderByFields.length; i++) {
3261 query.append(_ORDER_BY_ENTITY_ALIAS);
3262 query.append(orderByFields[i]);
3263
3264 if ((i + 1) < orderByFields.length) {
3265 if (orderByComparator.isAscending() ^ previous) {
3266 query.append(ORDER_BY_ASC_HAS_NEXT);
3267 }
3268 else {
3269 query.append(ORDER_BY_DESC_HAS_NEXT);
3270 }
3271 }
3272 else {
3273 if (orderByComparator.isAscending() ^ previous) {
3274 query.append(ORDER_BY_ASC);
3275 }
3276 else {
3277 query.append(ORDER_BY_DESC);
3278 }
3279 }
3280 }
3281 }
3282 else {
3283 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
3284 }
3285
3286 String sql = query.toString();
3287
3288 Query q = session.createQuery(sql);
3289
3290 q.setFirstResult(0);
3291 q.setMaxResults(2);
3292
3293 QueryPos qPos = QueryPos.getInstance(q);
3294
3295 qPos.add(companyId);
3296
3297 if (orderByComparator != null) {
3298 Object[] values = orderByComparator.getOrderByConditionValues(organization);
3299
3300 for (Object value : values) {
3301 qPos.add(value);
3302 }
3303 }
3304
3305 List<Organization> list = q.list();
3306
3307 if (list.size() == 2) {
3308 return list.get(1);
3309 }
3310 else {
3311 return null;
3312 }
3313 }
3314
3315
3322 @Override
3323 public List<Organization> filterFindByLocations(long companyId)
3324 throws SystemException {
3325 return filterFindByLocations(companyId, QueryUtil.ALL_POS,
3326 QueryUtil.ALL_POS, null);
3327 }
3328
3329
3342 @Override
3343 public List<Organization> filterFindByLocations(long companyId, int start,
3344 int end) throws SystemException {
3345 return filterFindByLocations(companyId, start, end, null);
3346 }
3347
3348
3362 @Override
3363 public List<Organization> filterFindByLocations(long companyId, int start,
3364 int end, OrderByComparator orderByComparator) throws SystemException {
3365 if (!InlineSQLHelperUtil.isEnabled()) {
3366 return findByLocations(companyId, start, end, orderByComparator);
3367 }
3368
3369 StringBundler query = null;
3370
3371 if (orderByComparator != null) {
3372 query = new StringBundler(3 +
3373 (orderByComparator.getOrderByFields().length * 3));
3374 }
3375 else {
3376 query = new StringBundler(3);
3377 }
3378
3379 if (getDB().isSupportsInlineDistinct()) {
3380 query.append(_FILTER_SQL_SELECT_ORGANIZATION_WHERE);
3381 }
3382 else {
3383 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1);
3384 }
3385
3386 query.append(_FINDER_COLUMN_LOCATIONS_COMPANYID_2);
3387
3388 if (!getDB().isSupportsInlineDistinct()) {
3389 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2);
3390 }
3391
3392 if (orderByComparator != null) {
3393 if (getDB().isSupportsInlineDistinct()) {
3394 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3395 orderByComparator, true);
3396 }
3397 else {
3398 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
3399 orderByComparator, true);
3400 }
3401 }
3402 else {
3403 if (getDB().isSupportsInlineDistinct()) {
3404 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
3405 }
3406 else {
3407 query.append(OrganizationModelImpl.ORDER_BY_SQL);
3408 }
3409 }
3410
3411 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3412 Organization.class.getName(),
3413 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
3414
3415 Session session = null;
3416
3417 try {
3418 session = openSession();
3419
3420 SQLQuery q = session.createSQLQuery(sql);
3421
3422 if (getDB().isSupportsInlineDistinct()) {
3423 q.addEntity(_FILTER_ENTITY_ALIAS, OrganizationImpl.class);
3424 }
3425 else {
3426 q.addEntity(_FILTER_ENTITY_TABLE, OrganizationImpl.class);
3427 }
3428
3429 QueryPos qPos = QueryPos.getInstance(q);
3430
3431 qPos.add(companyId);
3432
3433 return (List<Organization>)QueryUtil.list(q, getDialect(), start,
3434 end);
3435 }
3436 catch (Exception e) {
3437 throw processException(e);
3438 }
3439 finally {
3440 closeSession(session);
3441 }
3442 }
3443
3444
3454 @Override
3455 public Organization[] filterFindByLocations_PrevAndNext(
3456 long organizationId, long companyId, OrderByComparator orderByComparator)
3457 throws NoSuchOrganizationException, SystemException {
3458 if (!InlineSQLHelperUtil.isEnabled()) {
3459 return findByLocations_PrevAndNext(organizationId, companyId,
3460 orderByComparator);
3461 }
3462
3463 Organization organization = findByPrimaryKey(organizationId);
3464
3465 Session session = null;
3466
3467 try {
3468 session = openSession();
3469
3470 Organization[] array = new OrganizationImpl[3];
3471
3472 array[0] = filterGetByLocations_PrevAndNext(session, organization,
3473 companyId, orderByComparator, true);
3474
3475 array[1] = organization;
3476
3477 array[2] = filterGetByLocations_PrevAndNext(session, organization,
3478 companyId, orderByComparator, false);
3479
3480 return array;
3481 }
3482 catch (Exception e) {
3483 throw processException(e);
3484 }
3485 finally {
3486 closeSession(session);
3487 }
3488 }
3489
3490 protected Organization filterGetByLocations_PrevAndNext(Session session,
3491 Organization organization, long companyId,
3492 OrderByComparator orderByComparator, boolean previous) {
3493 StringBundler query = null;
3494
3495 if (orderByComparator != null) {
3496 query = new StringBundler(6 +
3497 (orderByComparator.getOrderByFields().length * 6));
3498 }
3499 else {
3500 query = new StringBundler(3);
3501 }
3502
3503 if (getDB().isSupportsInlineDistinct()) {
3504 query.append(_FILTER_SQL_SELECT_ORGANIZATION_WHERE);
3505 }
3506 else {
3507 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1);
3508 }
3509
3510 query.append(_FINDER_COLUMN_LOCATIONS_COMPANYID_2);
3511
3512 if (!getDB().isSupportsInlineDistinct()) {
3513 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2);
3514 }
3515
3516 if (orderByComparator != null) {
3517 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3518
3519 if (orderByConditionFields.length > 0) {
3520 query.append(WHERE_AND);
3521 }
3522
3523 for (int i = 0; i < orderByConditionFields.length; i++) {
3524 if (getDB().isSupportsInlineDistinct()) {
3525 query.append(_ORDER_BY_ENTITY_ALIAS);
3526 }
3527 else {
3528 query.append(_ORDER_BY_ENTITY_TABLE);
3529 }
3530
3531 query.append(orderByConditionFields[i]);
3532
3533 if ((i + 1) < orderByConditionFields.length) {
3534 if (orderByComparator.isAscending() ^ previous) {
3535 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3536 }
3537 else {
3538 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3539 }
3540 }
3541 else {
3542 if (orderByComparator.isAscending() ^ previous) {
3543 query.append(WHERE_GREATER_THAN);
3544 }
3545 else {
3546 query.append(WHERE_LESSER_THAN);
3547 }
3548 }
3549 }
3550
3551 query.append(ORDER_BY_CLAUSE);
3552
3553 String[] orderByFields = orderByComparator.getOrderByFields();
3554
3555 for (int i = 0; i < orderByFields.length; i++) {
3556 if (getDB().isSupportsInlineDistinct()) {
3557 query.append(_ORDER_BY_ENTITY_ALIAS);
3558 }
3559 else {
3560 query.append(_ORDER_BY_ENTITY_TABLE);
3561 }
3562
3563 query.append(orderByFields[i]);
3564
3565 if ((i + 1) < orderByFields.length) {
3566 if (orderByComparator.isAscending() ^ previous) {
3567 query.append(ORDER_BY_ASC_HAS_NEXT);
3568 }
3569 else {
3570 query.append(ORDER_BY_DESC_HAS_NEXT);
3571 }
3572 }
3573 else {
3574 if (orderByComparator.isAscending() ^ previous) {
3575 query.append(ORDER_BY_ASC);
3576 }
3577 else {
3578 query.append(ORDER_BY_DESC);
3579 }
3580 }
3581 }
3582 }
3583 else {
3584 if (getDB().isSupportsInlineDistinct()) {
3585 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
3586 }
3587 else {
3588 query.append(OrganizationModelImpl.ORDER_BY_SQL);
3589 }
3590 }
3591
3592 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3593 Organization.class.getName(),
3594 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
3595
3596 SQLQuery q = session.createSQLQuery(sql);
3597
3598 q.setFirstResult(0);
3599 q.setMaxResults(2);
3600
3601 if (getDB().isSupportsInlineDistinct()) {
3602 q.addEntity(_FILTER_ENTITY_ALIAS, OrganizationImpl.class);
3603 }
3604 else {
3605 q.addEntity(_FILTER_ENTITY_TABLE, OrganizationImpl.class);
3606 }
3607
3608 QueryPos qPos = QueryPos.getInstance(q);
3609
3610 qPos.add(companyId);
3611
3612 if (orderByComparator != null) {
3613 Object[] values = orderByComparator.getOrderByConditionValues(organization);
3614
3615 for (Object value : values) {
3616 qPos.add(value);
3617 }
3618 }
3619
3620 List<Organization> list = q.list();
3621
3622 if (list.size() == 2) {
3623 return list.get(1);
3624 }
3625 else {
3626 return null;
3627 }
3628 }
3629
3630
3636 @Override
3637 public void removeByLocations(long companyId) throws SystemException {
3638 for (Organization organization : findByLocations(companyId,
3639 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3640 remove(organization);
3641 }
3642 }
3643
3644
3651 @Override
3652 public int countByLocations(long companyId) throws SystemException {
3653 FinderPath finderPath = FINDER_PATH_COUNT_BY_LOCATIONS;
3654
3655 Object[] finderArgs = new Object[] { companyId };
3656
3657 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3658 this);
3659
3660 if (count == null) {
3661 StringBundler query = new StringBundler(2);
3662
3663 query.append(_SQL_COUNT_ORGANIZATION_WHERE);
3664
3665 query.append(_FINDER_COLUMN_LOCATIONS_COMPANYID_2);
3666
3667 String sql = query.toString();
3668
3669 Session session = null;
3670
3671 try {
3672 session = openSession();
3673
3674 Query q = session.createQuery(sql);
3675
3676 QueryPos qPos = QueryPos.getInstance(q);
3677
3678 qPos.add(companyId);
3679
3680 count = (Long)q.uniqueResult();
3681
3682 FinderCacheUtil.putResult(finderPath, finderArgs, count);
3683 }
3684 catch (Exception e) {
3685 FinderCacheUtil.removeResult(finderPath, finderArgs);
3686
3687 throw processException(e);
3688 }
3689 finally {
3690 closeSession(session);
3691 }
3692 }
3693
3694 return count.intValue();
3695 }
3696
3697
3704 @Override
3705 public int filterCountByLocations(long companyId) throws SystemException {
3706 if (!InlineSQLHelperUtil.isEnabled()) {
3707 return countByLocations(companyId);
3708 }
3709
3710 StringBundler query = new StringBundler(2);
3711
3712 query.append(_FILTER_SQL_COUNT_ORGANIZATION_WHERE);
3713
3714 query.append(_FINDER_COLUMN_LOCATIONS_COMPANYID_2);
3715
3716 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3717 Organization.class.getName(),
3718 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
3719
3720 Session session = null;
3721
3722 try {
3723 session = openSession();
3724
3725 SQLQuery q = session.createSQLQuery(sql);
3726
3727 q.addScalar(COUNT_COLUMN_NAME,
3728 com.liferay.portal.kernel.dao.orm.Type.LONG);
3729
3730 QueryPos qPos = QueryPos.getInstance(q);
3731
3732 qPos.add(companyId);
3733
3734 Long count = (Long)q.uniqueResult();
3735
3736 return count.intValue();
3737 }
3738 catch (Exception e) {
3739 throw processException(e);
3740 }
3741 finally {
3742 closeSession(session);
3743 }
3744 }
3745
3746 private static final String _FINDER_COLUMN_LOCATIONS_COMPANYID_2 = "organization.companyId = ? AND organization.parentOrganizationId != 0";
3747 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_P = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
3748 OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
3749 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_P",
3750 new String[] {
3751 Long.class.getName(), Long.class.getName(),
3752
3753 Integer.class.getName(), Integer.class.getName(),
3754 OrderByComparator.class.getName()
3755 });
3756 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
3757 OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
3758 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_P",
3759 new String[] { Long.class.getName(), Long.class.getName() },
3760 OrganizationModelImpl.COMPANYID_COLUMN_BITMASK |
3761 OrganizationModelImpl.PARENTORGANIZATIONID_COLUMN_BITMASK |
3762 OrganizationModelImpl.NAME_COLUMN_BITMASK);
3763 public static final FinderPath FINDER_PATH_COUNT_BY_C_P = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
3764 OrganizationModelImpl.FINDER_CACHE_ENABLED, Long.class,
3765 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_P",
3766 new String[] { Long.class.getName(), Long.class.getName() });
3767
3768
3776 @Override
3777 public List<Organization> findByC_P(long companyId,
3778 long parentOrganizationId) throws SystemException {
3779 return findByC_P(companyId, parentOrganizationId, QueryUtil.ALL_POS,
3780 QueryUtil.ALL_POS, null);
3781 }
3782
3783
3797 @Override
3798 public List<Organization> findByC_P(long companyId,
3799 long parentOrganizationId, int start, int end)
3800 throws SystemException {
3801 return findByC_P(companyId, parentOrganizationId, start, end, null);
3802 }
3803
3804
3819 @Override
3820 public List<Organization> findByC_P(long companyId,
3821 long parentOrganizationId, int start, int end,
3822 OrderByComparator orderByComparator) throws SystemException {
3823 boolean pagination = true;
3824 FinderPath finderPath = null;
3825 Object[] finderArgs = null;
3826
3827 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3828 (orderByComparator == null)) {
3829 pagination = false;
3830 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P;
3831 finderArgs = new Object[] { companyId, parentOrganizationId };
3832 }
3833 else {
3834 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_P;
3835 finderArgs = new Object[] {
3836 companyId, parentOrganizationId,
3837
3838 start, end, orderByComparator
3839 };
3840 }
3841
3842 List<Organization> list = (List<Organization>)FinderCacheUtil.getResult(finderPath,
3843 finderArgs, this);
3844
3845 if ((list != null) && !list.isEmpty()) {
3846 for (Organization organization : list) {
3847 if ((companyId != organization.getCompanyId()) ||
3848 (parentOrganizationId != organization.getParentOrganizationId())) {
3849 list = null;
3850
3851 break;
3852 }
3853 }
3854 }
3855
3856 if (list == null) {
3857 StringBundler query = null;
3858
3859 if (orderByComparator != null) {
3860 query = new StringBundler(4 +
3861 (orderByComparator.getOrderByFields().length * 3));
3862 }
3863 else {
3864 query = new StringBundler(4);
3865 }
3866
3867 query.append(_SQL_SELECT_ORGANIZATION_WHERE);
3868
3869 query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
3870
3871 query.append(_FINDER_COLUMN_C_P_PARENTORGANIZATIONID_2);
3872
3873 if (orderByComparator != null) {
3874 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3875 orderByComparator);
3876 }
3877 else
3878 if (pagination) {
3879 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
3880 }
3881
3882 String sql = query.toString();
3883
3884 Session session = null;
3885
3886 try {
3887 session = openSession();
3888
3889 Query q = session.createQuery(sql);
3890
3891 QueryPos qPos = QueryPos.getInstance(q);
3892
3893 qPos.add(companyId);
3894
3895 qPos.add(parentOrganizationId);
3896
3897 if (!pagination) {
3898 list = (List<Organization>)QueryUtil.list(q, getDialect(),
3899 start, end, false);
3900
3901 Collections.sort(list);
3902
3903 list = new UnmodifiableList<Organization>(list);
3904 }
3905 else {
3906 list = (List<Organization>)QueryUtil.list(q, getDialect(),
3907 start, end);
3908 }
3909
3910 cacheResult(list);
3911
3912 FinderCacheUtil.putResult(finderPath, finderArgs, list);
3913 }
3914 catch (Exception e) {
3915 FinderCacheUtil.removeResult(finderPath, finderArgs);
3916
3917 throw processException(e);
3918 }
3919 finally {
3920 closeSession(session);
3921 }
3922 }
3923
3924 return list;
3925 }
3926
3927
3937 @Override
3938 public Organization findByC_P_First(long companyId,
3939 long parentOrganizationId, OrderByComparator orderByComparator)
3940 throws NoSuchOrganizationException, SystemException {
3941 Organization organization = fetchByC_P_First(companyId,
3942 parentOrganizationId, orderByComparator);
3943
3944 if (organization != null) {
3945 return organization;
3946 }
3947
3948 StringBundler msg = new StringBundler(6);
3949
3950 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3951
3952 msg.append("companyId=");
3953 msg.append(companyId);
3954
3955 msg.append(", parentOrganizationId=");
3956 msg.append(parentOrganizationId);
3957
3958 msg.append(StringPool.CLOSE_CURLY_BRACE);
3959
3960 throw new NoSuchOrganizationException(msg.toString());
3961 }
3962
3963
3972 @Override
3973 public Organization fetchByC_P_First(long companyId,
3974 long parentOrganizationId, OrderByComparator orderByComparator)
3975 throws SystemException {
3976 List<Organization> list = findByC_P(companyId, parentOrganizationId, 0,
3977 1, orderByComparator);
3978
3979 if (!list.isEmpty()) {
3980 return list.get(0);
3981 }
3982
3983 return null;
3984 }
3985
3986
3996 @Override
3997 public Organization findByC_P_Last(long companyId,
3998 long parentOrganizationId, OrderByComparator orderByComparator)
3999 throws NoSuchOrganizationException, SystemException {
4000 Organization organization = fetchByC_P_Last(companyId,
4001 parentOrganizationId, orderByComparator);
4002
4003 if (organization != null) {
4004 return organization;
4005 }
4006
4007 StringBundler msg = new StringBundler(6);
4008
4009 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4010
4011 msg.append("companyId=");
4012 msg.append(companyId);
4013
4014 msg.append(", parentOrganizationId=");
4015 msg.append(parentOrganizationId);
4016
4017 msg.append(StringPool.CLOSE_CURLY_BRACE);
4018
4019 throw new NoSuchOrganizationException(msg.toString());
4020 }
4021
4022
4031 @Override
4032 public Organization fetchByC_P_Last(long companyId,
4033 long parentOrganizationId, OrderByComparator orderByComparator)
4034 throws SystemException {
4035 int count = countByC_P(companyId, parentOrganizationId);
4036
4037 if (count == 0) {
4038 return null;
4039 }
4040
4041 List<Organization> list = findByC_P(companyId, parentOrganizationId,
4042 count - 1, count, orderByComparator);
4043
4044 if (!list.isEmpty()) {
4045 return list.get(0);
4046 }
4047
4048 return null;
4049 }
4050
4051
4062 @Override
4063 public Organization[] findByC_P_PrevAndNext(long organizationId,
4064 long companyId, long parentOrganizationId,
4065 OrderByComparator orderByComparator)
4066 throws NoSuchOrganizationException, SystemException {
4067 Organization organization = findByPrimaryKey(organizationId);
4068
4069 Session session = null;
4070
4071 try {
4072 session = openSession();
4073
4074 Organization[] array = new OrganizationImpl[3];
4075
4076 array[0] = getByC_P_PrevAndNext(session, organization, companyId,
4077 parentOrganizationId, orderByComparator, true);
4078
4079 array[1] = organization;
4080
4081 array[2] = getByC_P_PrevAndNext(session, organization, companyId,
4082 parentOrganizationId, orderByComparator, false);
4083
4084 return array;
4085 }
4086 catch (Exception e) {
4087 throw processException(e);
4088 }
4089 finally {
4090 closeSession(session);
4091 }
4092 }
4093
4094 protected Organization getByC_P_PrevAndNext(Session session,
4095 Organization organization, long companyId, long parentOrganizationId,
4096 OrderByComparator orderByComparator, boolean previous) {
4097 StringBundler query = null;
4098
4099 if (orderByComparator != null) {
4100 query = new StringBundler(6 +
4101 (orderByComparator.getOrderByFields().length * 6));
4102 }
4103 else {
4104 query = new StringBundler(3);
4105 }
4106
4107 query.append(_SQL_SELECT_ORGANIZATION_WHERE);
4108
4109 query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
4110
4111 query.append(_FINDER_COLUMN_C_P_PARENTORGANIZATIONID_2);
4112
4113 if (orderByComparator != null) {
4114 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4115
4116 if (orderByConditionFields.length > 0) {
4117 query.append(WHERE_AND);
4118 }
4119
4120 for (int i = 0; i < orderByConditionFields.length; i++) {
4121 query.append(_ORDER_BY_ENTITY_ALIAS);
4122 query.append(orderByConditionFields[i]);
4123
4124 if ((i + 1) < orderByConditionFields.length) {
4125 if (orderByComparator.isAscending() ^ previous) {
4126 query.append(WHERE_GREATER_THAN_HAS_NEXT);
4127 }
4128 else {
4129 query.append(WHERE_LESSER_THAN_HAS_NEXT);
4130 }
4131 }
4132 else {
4133 if (orderByComparator.isAscending() ^ previous) {
4134 query.append(WHERE_GREATER_THAN);
4135 }
4136 else {
4137 query.append(WHERE_LESSER_THAN);
4138 }
4139 }
4140 }
4141
4142 query.append(ORDER_BY_CLAUSE);
4143
4144 String[] orderByFields = orderByComparator.getOrderByFields();
4145
4146 for (int i = 0; i < orderByFields.length; i++) {
4147 query.append(_ORDER_BY_ENTITY_ALIAS);
4148 query.append(orderByFields[i]);
4149
4150 if ((i + 1) < orderByFields.length) {
4151 if (orderByComparator.isAscending() ^ previous) {
4152 query.append(ORDER_BY_ASC_HAS_NEXT);
4153 }
4154 else {
4155 query.append(ORDER_BY_DESC_HAS_NEXT);
4156 }
4157 }
4158 else {
4159 if (orderByComparator.isAscending() ^ previous) {
4160 query.append(ORDER_BY_ASC);
4161 }
4162 else {
4163 query.append(ORDER_BY_DESC);
4164 }
4165 }
4166 }
4167 }
4168 else {
4169 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
4170 }
4171
4172 String sql = query.toString();
4173
4174 Query q = session.createQuery(sql);
4175
4176 q.setFirstResult(0);
4177 q.setMaxResults(2);
4178
4179 QueryPos qPos = QueryPos.getInstance(q);
4180
4181 qPos.add(companyId);
4182
4183 qPos.add(parentOrganizationId);
4184
4185 if (orderByComparator != null) {
4186 Object[] values = orderByComparator.getOrderByConditionValues(organization);
4187
4188 for (Object value : values) {
4189 qPos.add(value);
4190 }
4191 }
4192
4193 List<Organization> list = q.list();
4194
4195 if (list.size() == 2) {
4196 return list.get(1);
4197 }
4198 else {
4199 return null;
4200 }
4201 }
4202
4203
4211 @Override
4212 public List<Organization> filterFindByC_P(long companyId,
4213 long parentOrganizationId) throws SystemException {
4214 return filterFindByC_P(companyId, parentOrganizationId,
4215 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
4216 }
4217
4218
4232 @Override
4233 public List<Organization> filterFindByC_P(long companyId,
4234 long parentOrganizationId, int start, int end)
4235 throws SystemException {
4236 return filterFindByC_P(companyId, parentOrganizationId, start, end, null);
4237 }
4238
4239
4254 @Override
4255 public List<Organization> filterFindByC_P(long companyId,
4256 long parentOrganizationId, int start, int end,
4257 OrderByComparator orderByComparator) throws SystemException {
4258 if (!InlineSQLHelperUtil.isEnabled()) {
4259 return findByC_P(companyId, parentOrganizationId, start, end,
4260 orderByComparator);
4261 }
4262
4263 StringBundler query = null;
4264
4265 if (orderByComparator != null) {
4266 query = new StringBundler(4 +
4267 (orderByComparator.getOrderByFields().length * 3));
4268 }
4269 else {
4270 query = new StringBundler(4);
4271 }
4272
4273 if (getDB().isSupportsInlineDistinct()) {
4274 query.append(_FILTER_SQL_SELECT_ORGANIZATION_WHERE);
4275 }
4276 else {
4277 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1);
4278 }
4279
4280 query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
4281
4282 query.append(_FINDER_COLUMN_C_P_PARENTORGANIZATIONID_2);
4283
4284 if (!getDB().isSupportsInlineDistinct()) {
4285 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2);
4286 }
4287
4288 if (orderByComparator != null) {
4289 if (getDB().isSupportsInlineDistinct()) {
4290 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4291 orderByComparator, true);
4292 }
4293 else {
4294 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
4295 orderByComparator, true);
4296 }
4297 }
4298 else {
4299 if (getDB().isSupportsInlineDistinct()) {
4300 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
4301 }
4302 else {
4303 query.append(OrganizationModelImpl.ORDER_BY_SQL);
4304 }
4305 }
4306
4307 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4308 Organization.class.getName(),
4309 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
4310
4311 Session session = null;
4312
4313 try {
4314 session = openSession();
4315
4316 SQLQuery q = session.createSQLQuery(sql);
4317
4318 if (getDB().isSupportsInlineDistinct()) {
4319 q.addEntity(_FILTER_ENTITY_ALIAS, OrganizationImpl.class);
4320 }
4321 else {
4322 q.addEntity(_FILTER_ENTITY_TABLE, OrganizationImpl.class);
4323 }
4324
4325 QueryPos qPos = QueryPos.getInstance(q);
4326
4327 qPos.add(companyId);
4328
4329 qPos.add(parentOrganizationId);
4330
4331 return (List<Organization>)QueryUtil.list(q, getDialect(), start,
4332 end);
4333 }
4334 catch (Exception e) {
4335 throw processException(e);
4336 }
4337 finally {
4338 closeSession(session);
4339 }
4340 }
4341
4342
4353 @Override
4354 public Organization[] filterFindByC_P_PrevAndNext(long organizationId,
4355 long companyId, long parentOrganizationId,
4356 OrderByComparator orderByComparator)
4357 throws NoSuchOrganizationException, SystemException {
4358 if (!InlineSQLHelperUtil.isEnabled()) {
4359 return findByC_P_PrevAndNext(organizationId, companyId,
4360 parentOrganizationId, orderByComparator);
4361 }
4362
4363 Organization organization = findByPrimaryKey(organizationId);
4364
4365 Session session = null;
4366
4367 try {
4368 session = openSession();
4369
4370 Organization[] array = new OrganizationImpl[3];
4371
4372 array[0] = filterGetByC_P_PrevAndNext(session, organization,
4373 companyId, parentOrganizationId, orderByComparator, true);
4374
4375 array[1] = organization;
4376
4377 array[2] = filterGetByC_P_PrevAndNext(session, organization,
4378 companyId, parentOrganizationId, orderByComparator, false);
4379
4380 return array;
4381 }
4382 catch (Exception e) {
4383 throw processException(e);
4384 }
4385 finally {
4386 closeSession(session);
4387 }
4388 }
4389
4390 protected Organization filterGetByC_P_PrevAndNext(Session session,
4391 Organization organization, long companyId, long parentOrganizationId,
4392 OrderByComparator orderByComparator, boolean previous) {
4393 StringBundler query = null;
4394
4395 if (orderByComparator != null) {
4396 query = new StringBundler(6 +
4397 (orderByComparator.getOrderByFields().length * 6));
4398 }
4399 else {
4400 query = new StringBundler(3);
4401 }
4402
4403 if (getDB().isSupportsInlineDistinct()) {
4404 query.append(_FILTER_SQL_SELECT_ORGANIZATION_WHERE);
4405 }
4406 else {
4407 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1);
4408 }
4409
4410 query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
4411
4412 query.append(_FINDER_COLUMN_C_P_PARENTORGANIZATIONID_2);
4413
4414 if (!getDB().isSupportsInlineDistinct()) {
4415 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2);
4416 }
4417
4418 if (orderByComparator != null) {
4419 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4420
4421 if (orderByConditionFields.length > 0) {
4422 query.append(WHERE_AND);
4423 }
4424
4425 for (int i = 0; i < orderByConditionFields.length; i++) {
4426 if (getDB().isSupportsInlineDistinct()) {
4427 query.append(_ORDER_BY_ENTITY_ALIAS);
4428 }
4429 else {
4430 query.append(_ORDER_BY_ENTITY_TABLE);
4431 }
4432
4433 query.append(orderByConditionFields[i]);
4434
4435 if ((i + 1) < orderByConditionFields.length) {
4436 if (orderByComparator.isAscending() ^ previous) {
4437 query.append(WHERE_GREATER_THAN_HAS_NEXT);
4438 }
4439 else {
4440 query.append(WHERE_LESSER_THAN_HAS_NEXT);
4441 }
4442 }
4443 else {
4444 if (orderByComparator.isAscending() ^ previous) {
4445 query.append(WHERE_GREATER_THAN);
4446 }
4447 else {
4448 query.append(WHERE_LESSER_THAN);
4449 }
4450 }
4451 }
4452
4453 query.append(ORDER_BY_CLAUSE);
4454
4455 String[] orderByFields = orderByComparator.getOrderByFields();
4456
4457 for (int i = 0; i < orderByFields.length; i++) {
4458 if (getDB().isSupportsInlineDistinct()) {
4459 query.append(_ORDER_BY_ENTITY_ALIAS);
4460 }
4461 else {
4462 query.append(_ORDER_BY_ENTITY_TABLE);
4463 }
4464
4465 query.append(orderByFields[i]);
4466
4467 if ((i + 1) < orderByFields.length) {
4468 if (orderByComparator.isAscending() ^ previous) {
4469 query.append(ORDER_BY_ASC_HAS_NEXT);
4470 }
4471 else {
4472 query.append(ORDER_BY_DESC_HAS_NEXT);
4473 }
4474 }
4475 else {
4476 if (orderByComparator.isAscending() ^ previous) {
4477 query.append(ORDER_BY_ASC);
4478 }
4479 else {
4480 query.append(ORDER_BY_DESC);
4481 }
4482 }
4483 }
4484 }
4485 else {
4486 if (getDB().isSupportsInlineDistinct()) {
4487 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
4488 }
4489 else {
4490 query.append(OrganizationModelImpl.ORDER_BY_SQL);
4491 }
4492 }
4493
4494 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4495 Organization.class.getName(),
4496 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
4497
4498 SQLQuery q = session.createSQLQuery(sql);
4499
4500 q.setFirstResult(0);
4501 q.setMaxResults(2);
4502
4503 if (getDB().isSupportsInlineDistinct()) {
4504 q.addEntity(_FILTER_ENTITY_ALIAS, OrganizationImpl.class);
4505 }
4506 else {
4507 q.addEntity(_FILTER_ENTITY_TABLE, OrganizationImpl.class);
4508 }
4509
4510 QueryPos qPos = QueryPos.getInstance(q);
4511
4512 qPos.add(companyId);
4513
4514 qPos.add(parentOrganizationId);
4515
4516 if (orderByComparator != null) {
4517 Object[] values = orderByComparator.getOrderByConditionValues(organization);
4518
4519 for (Object value : values) {
4520 qPos.add(value);
4521 }
4522 }
4523
4524 List<Organization> list = q.list();
4525
4526 if (list.size() == 2) {
4527 return list.get(1);
4528 }
4529 else {
4530 return null;
4531 }
4532 }
4533
4534
4541 @Override
4542 public void removeByC_P(long companyId, long parentOrganizationId)
4543 throws SystemException {
4544 for (Organization organization : findByC_P(companyId,
4545 parentOrganizationId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
4546 remove(organization);
4547 }
4548 }
4549
4550
4558 @Override
4559 public int countByC_P(long companyId, long parentOrganizationId)
4560 throws SystemException {
4561 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_P;
4562
4563 Object[] finderArgs = new Object[] { companyId, parentOrganizationId };
4564
4565 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4566 this);
4567
4568 if (count == null) {
4569 StringBundler query = new StringBundler(3);
4570
4571 query.append(_SQL_COUNT_ORGANIZATION_WHERE);
4572
4573 query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
4574
4575 query.append(_FINDER_COLUMN_C_P_PARENTORGANIZATIONID_2);
4576
4577 String sql = query.toString();
4578
4579 Session session = null;
4580
4581 try {
4582 session = openSession();
4583
4584 Query q = session.createQuery(sql);
4585
4586 QueryPos qPos = QueryPos.getInstance(q);
4587
4588 qPos.add(companyId);
4589
4590 qPos.add(parentOrganizationId);
4591
4592 count = (Long)q.uniqueResult();
4593
4594 FinderCacheUtil.putResult(finderPath, finderArgs, count);
4595 }
4596 catch (Exception e) {
4597 FinderCacheUtil.removeResult(finderPath, finderArgs);
4598
4599 throw processException(e);
4600 }
4601 finally {
4602 closeSession(session);
4603 }
4604 }
4605
4606 return count.intValue();
4607 }
4608
4609
4617 @Override
4618 public int filterCountByC_P(long companyId, long parentOrganizationId)
4619 throws SystemException {
4620 if (!InlineSQLHelperUtil.isEnabled()) {
4621 return countByC_P(companyId, parentOrganizationId);
4622 }
4623
4624 StringBundler query = new StringBundler(3);
4625
4626 query.append(_FILTER_SQL_COUNT_ORGANIZATION_WHERE);
4627
4628 query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
4629
4630 query.append(_FINDER_COLUMN_C_P_PARENTORGANIZATIONID_2);
4631
4632 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4633 Organization.class.getName(),
4634 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
4635
4636 Session session = null;
4637
4638 try {
4639 session = openSession();
4640
4641 SQLQuery q = session.createSQLQuery(sql);
4642
4643 q.addScalar(COUNT_COLUMN_NAME,
4644 com.liferay.portal.kernel.dao.orm.Type.LONG);
4645
4646 QueryPos qPos = QueryPos.getInstance(q);
4647
4648 qPos.add(companyId);
4649
4650 qPos.add(parentOrganizationId);
4651
4652 Long count = (Long)q.uniqueResult();
4653
4654 return count.intValue();
4655 }
4656 catch (Exception e) {
4657 throw processException(e);
4658 }
4659 finally {
4660 closeSession(session);
4661 }
4662 }
4663
4664 private static final String _FINDER_COLUMN_C_P_COMPANYID_2 = "organization.companyId = ? AND ";
4665 private static final String _FINDER_COLUMN_C_P_PARENTORGANIZATIONID_2 = "organization.parentOrganizationId = ?";
4666 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_T = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
4667 OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
4668 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_T",
4669 new String[] {
4670 Long.class.getName(), String.class.getName(),
4671
4672 Integer.class.getName(), Integer.class.getName(),
4673 OrderByComparator.class.getName()
4674 });
4675 public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_T = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
4676 OrganizationModelImpl.FINDER_CACHE_ENABLED, Long.class,
4677 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByC_T",
4678 new String[] { Long.class.getName(), String.class.getName() });
4679
4680
4688 @Override
4689 public List<Organization> findByC_T(long companyId, String treePath)
4690 throws SystemException {
4691 return findByC_T(companyId, treePath, QueryUtil.ALL_POS,
4692 QueryUtil.ALL_POS, null);
4693 }
4694
4695
4709 @Override
4710 public List<Organization> findByC_T(long companyId, String treePath,
4711 int start, int end) throws SystemException {
4712 return findByC_T(companyId, treePath, start, end, null);
4713 }
4714
4715
4730 @Override
4731 public List<Organization> findByC_T(long companyId, String treePath,
4732 int start, int end, OrderByComparator orderByComparator)
4733 throws SystemException {
4734 boolean pagination = true;
4735 FinderPath finderPath = null;
4736 Object[] finderArgs = null;
4737
4738 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_T;
4739 finderArgs = new Object[] {
4740 companyId, treePath,
4741
4742 start, end, orderByComparator
4743 };
4744
4745 List<Organization> list = (List<Organization>)FinderCacheUtil.getResult(finderPath,
4746 finderArgs, this);
4747
4748 if ((list != null) && !list.isEmpty()) {
4749 for (Organization organization : list) {
4750 if ((companyId != organization.getCompanyId()) ||
4751 !StringUtil.wildcardMatches(
4752 organization.getTreePath(), treePath,
4753 CharPool.UNDERLINE, CharPool.PERCENT,
4754 CharPool.BACK_SLASH, true)) {
4755 list = null;
4756
4757 break;
4758 }
4759 }
4760 }
4761
4762 if (list == null) {
4763 StringBundler query = null;
4764
4765 if (orderByComparator != null) {
4766 query = new StringBundler(4 +
4767 (orderByComparator.getOrderByFields().length * 3));
4768 }
4769 else {
4770 query = new StringBundler(4);
4771 }
4772
4773 query.append(_SQL_SELECT_ORGANIZATION_WHERE);
4774
4775 query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
4776
4777 boolean bindTreePath = false;
4778
4779 if (treePath == null) {
4780 query.append(_FINDER_COLUMN_C_T_TREEPATH_1);
4781 }
4782 else if (treePath.equals(StringPool.BLANK)) {
4783 query.append(_FINDER_COLUMN_C_T_TREEPATH_3);
4784 }
4785 else {
4786 bindTreePath = true;
4787
4788 query.append(_FINDER_COLUMN_C_T_TREEPATH_2);
4789 }
4790
4791 if (orderByComparator != null) {
4792 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4793 orderByComparator);
4794 }
4795 else
4796 if (pagination) {
4797 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
4798 }
4799
4800 String sql = query.toString();
4801
4802 Session session = null;
4803
4804 try {
4805 session = openSession();
4806
4807 Query q = session.createQuery(sql);
4808
4809 QueryPos qPos = QueryPos.getInstance(q);
4810
4811 qPos.add(companyId);
4812
4813 if (bindTreePath) {
4814 qPos.add(treePath);
4815 }
4816
4817 if (!pagination) {
4818 list = (List<Organization>)QueryUtil.list(q, getDialect(),
4819 start, end, false);
4820
4821 Collections.sort(list);
4822
4823 list = new UnmodifiableList<Organization>(list);
4824 }
4825 else {
4826 list = (List<Organization>)QueryUtil.list(q, getDialect(),
4827 start, end);
4828 }
4829
4830 cacheResult(list);
4831
4832 FinderCacheUtil.putResult(finderPath, finderArgs, list);
4833 }
4834 catch (Exception e) {
4835 FinderCacheUtil.removeResult(finderPath, finderArgs);
4836
4837 throw processException(e);
4838 }
4839 finally {
4840 closeSession(session);
4841 }
4842 }
4843
4844 return list;
4845 }
4846
4847
4857 @Override
4858 public Organization findByC_T_First(long companyId, String treePath,
4859 OrderByComparator orderByComparator)
4860 throws NoSuchOrganizationException, SystemException {
4861 Organization organization = fetchByC_T_First(companyId, treePath,
4862 orderByComparator);
4863
4864 if (organization != null) {
4865 return organization;
4866 }
4867
4868 StringBundler msg = new StringBundler(6);
4869
4870 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4871
4872 msg.append("companyId=");
4873 msg.append(companyId);
4874
4875 msg.append(", treePath=");
4876 msg.append(treePath);
4877
4878 msg.append(StringPool.CLOSE_CURLY_BRACE);
4879
4880 throw new NoSuchOrganizationException(msg.toString());
4881 }
4882
4883
4892 @Override
4893 public Organization fetchByC_T_First(long companyId, String treePath,
4894 OrderByComparator orderByComparator) throws SystemException {
4895 List<Organization> list = findByC_T(companyId, treePath, 0, 1,
4896 orderByComparator);
4897
4898 if (!list.isEmpty()) {
4899 return list.get(0);
4900 }
4901
4902 return null;
4903 }
4904
4905
4915 @Override
4916 public Organization findByC_T_Last(long companyId, String treePath,
4917 OrderByComparator orderByComparator)
4918 throws NoSuchOrganizationException, SystemException {
4919 Organization organization = fetchByC_T_Last(companyId, treePath,
4920 orderByComparator);
4921
4922 if (organization != null) {
4923 return organization;
4924 }
4925
4926 StringBundler msg = new StringBundler(6);
4927
4928 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4929
4930 msg.append("companyId=");
4931 msg.append(companyId);
4932
4933 msg.append(", treePath=");
4934 msg.append(treePath);
4935
4936 msg.append(StringPool.CLOSE_CURLY_BRACE);
4937
4938 throw new NoSuchOrganizationException(msg.toString());
4939 }
4940
4941
4950 @Override
4951 public Organization fetchByC_T_Last(long companyId, String treePath,
4952 OrderByComparator orderByComparator) throws SystemException {
4953 int count = countByC_T(companyId, treePath);
4954
4955 if (count == 0) {
4956 return null;
4957 }
4958
4959 List<Organization> list = findByC_T(companyId, treePath, count - 1,
4960 count, orderByComparator);
4961
4962 if (!list.isEmpty()) {
4963 return list.get(0);
4964 }
4965
4966 return null;
4967 }
4968
4969
4980 @Override
4981 public Organization[] findByC_T_PrevAndNext(long organizationId,
4982 long companyId, String treePath, OrderByComparator orderByComparator)
4983 throws NoSuchOrganizationException, SystemException {
4984 Organization organization = findByPrimaryKey(organizationId);
4985
4986 Session session = null;
4987
4988 try {
4989 session = openSession();
4990
4991 Organization[] array = new OrganizationImpl[3];
4992
4993 array[0] = getByC_T_PrevAndNext(session, organization, companyId,
4994 treePath, orderByComparator, true);
4995
4996 array[1] = organization;
4997
4998 array[2] = getByC_T_PrevAndNext(session, organization, companyId,
4999 treePath, orderByComparator, false);
5000
5001 return array;
5002 }
5003 catch (Exception e) {
5004 throw processException(e);
5005 }
5006 finally {
5007 closeSession(session);
5008 }
5009 }
5010
5011 protected Organization getByC_T_PrevAndNext(Session session,
5012 Organization organization, long companyId, String treePath,
5013 OrderByComparator orderByComparator, boolean previous) {
5014 StringBundler query = null;
5015
5016 if (orderByComparator != null) {
5017 query = new StringBundler(6 +
5018 (orderByComparator.getOrderByFields().length * 6));
5019 }
5020 else {
5021 query = new StringBundler(3);
5022 }
5023
5024 query.append(_SQL_SELECT_ORGANIZATION_WHERE);
5025
5026 query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
5027
5028 boolean bindTreePath = false;
5029
5030 if (treePath == null) {
5031 query.append(_FINDER_COLUMN_C_T_TREEPATH_1);
5032 }
5033 else if (treePath.equals(StringPool.BLANK)) {
5034 query.append(_FINDER_COLUMN_C_T_TREEPATH_3);
5035 }
5036 else {
5037 bindTreePath = true;
5038
5039 query.append(_FINDER_COLUMN_C_T_TREEPATH_2);
5040 }
5041
5042 if (orderByComparator != null) {
5043 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5044
5045 if (orderByConditionFields.length > 0) {
5046 query.append(WHERE_AND);
5047 }
5048
5049 for (int i = 0; i < orderByConditionFields.length; i++) {
5050 query.append(_ORDER_BY_ENTITY_ALIAS);
5051 query.append(orderByConditionFields[i]);
5052
5053 if ((i + 1) < orderByConditionFields.length) {
5054 if (orderByComparator.isAscending() ^ previous) {
5055 query.append(WHERE_GREATER_THAN_HAS_NEXT);
5056 }
5057 else {
5058 query.append(WHERE_LESSER_THAN_HAS_NEXT);
5059 }
5060 }
5061 else {
5062 if (orderByComparator.isAscending() ^ previous) {
5063 query.append(WHERE_GREATER_THAN);
5064 }
5065 else {
5066 query.append(WHERE_LESSER_THAN);
5067 }
5068 }
5069 }
5070
5071 query.append(ORDER_BY_CLAUSE);
5072
5073 String[] orderByFields = orderByComparator.getOrderByFields();
5074
5075 for (int i = 0; i < orderByFields.length; i++) {
5076 query.append(_ORDER_BY_ENTITY_ALIAS);
5077 query.append(orderByFields[i]);
5078
5079 if ((i + 1) < orderByFields.length) {
5080 if (orderByComparator.isAscending() ^ previous) {
5081 query.append(ORDER_BY_ASC_HAS_NEXT);
5082 }
5083 else {
5084 query.append(ORDER_BY_DESC_HAS_NEXT);
5085 }
5086 }
5087 else {
5088 if (orderByComparator.isAscending() ^ previous) {
5089 query.append(ORDER_BY_ASC);
5090 }
5091 else {
5092 query.append(ORDER_BY_DESC);
5093 }
5094 }
5095 }
5096 }
5097 else {
5098 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
5099 }
5100
5101 String sql = query.toString();
5102
5103 Query q = session.createQuery(sql);
5104
5105 q.setFirstResult(0);
5106 q.setMaxResults(2);
5107
5108 QueryPos qPos = QueryPos.getInstance(q);
5109
5110 qPos.add(companyId);
5111
5112 if (bindTreePath) {
5113 qPos.add(treePath);
5114 }
5115
5116 if (orderByComparator != null) {
5117 Object[] values = orderByComparator.getOrderByConditionValues(organization);
5118
5119 for (Object value : values) {
5120 qPos.add(value);
5121 }
5122 }
5123
5124 List<Organization> list = q.list();
5125
5126 if (list.size() == 2) {
5127 return list.get(1);
5128 }
5129 else {
5130 return null;
5131 }
5132 }
5133
5134
5142 @Override
5143 public List<Organization> filterFindByC_T(long companyId, String treePath)
5144 throws SystemException {
5145 return filterFindByC_T(companyId, treePath, QueryUtil.ALL_POS,
5146 QueryUtil.ALL_POS, null);
5147 }
5148
5149
5163 @Override
5164 public List<Organization> filterFindByC_T(long companyId, String treePath,
5165 int start, int end) throws SystemException {
5166 return filterFindByC_T(companyId, treePath, start, end, null);
5167 }
5168
5169
5184 @Override
5185 public List<Organization> filterFindByC_T(long companyId, String treePath,
5186 int start, int end, OrderByComparator orderByComparator)
5187 throws SystemException {
5188 if (!InlineSQLHelperUtil.isEnabled()) {
5189 return findByC_T(companyId, treePath, start, end, orderByComparator);
5190 }
5191
5192 StringBundler query = null;
5193
5194 if (orderByComparator != null) {
5195 query = new StringBundler(4 +
5196 (orderByComparator.getOrderByFields().length * 3));
5197 }
5198 else {
5199 query = new StringBundler(4);
5200 }
5201
5202 if (getDB().isSupportsInlineDistinct()) {
5203 query.append(_FILTER_SQL_SELECT_ORGANIZATION_WHERE);
5204 }
5205 else {
5206 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1);
5207 }
5208
5209 query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
5210
5211 boolean bindTreePath = false;
5212
5213 if (treePath == null) {
5214 query.append(_FINDER_COLUMN_C_T_TREEPATH_1);
5215 }
5216 else if (treePath.equals(StringPool.BLANK)) {
5217 query.append(_FINDER_COLUMN_C_T_TREEPATH_3);
5218 }
5219 else {
5220 bindTreePath = true;
5221
5222 query.append(_FINDER_COLUMN_C_T_TREEPATH_2);
5223 }
5224
5225 if (!getDB().isSupportsInlineDistinct()) {
5226 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2);
5227 }
5228
5229 if (orderByComparator != null) {
5230 if (getDB().isSupportsInlineDistinct()) {
5231 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5232 orderByComparator, true);
5233 }
5234 else {
5235 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
5236 orderByComparator, true);
5237 }
5238 }
5239 else {
5240 if (getDB().isSupportsInlineDistinct()) {
5241 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
5242 }
5243 else {
5244 query.append(OrganizationModelImpl.ORDER_BY_SQL);
5245 }
5246 }
5247
5248 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5249 Organization.class.getName(),
5250 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
5251
5252 Session session = null;
5253
5254 try {
5255 session = openSession();
5256
5257 SQLQuery q = session.createSQLQuery(sql);
5258
5259 if (getDB().isSupportsInlineDistinct()) {
5260 q.addEntity(_FILTER_ENTITY_ALIAS, OrganizationImpl.class);
5261 }
5262 else {
5263 q.addEntity(_FILTER_ENTITY_TABLE, OrganizationImpl.class);
5264 }
5265
5266 QueryPos qPos = QueryPos.getInstance(q);
5267
5268 qPos.add(companyId);
5269
5270 if (bindTreePath) {
5271 qPos.add(treePath);
5272 }
5273
5274 return (List<Organization>)QueryUtil.list(q, getDialect(), start,
5275 end);
5276 }
5277 catch (Exception e) {
5278 throw processException(e);
5279 }
5280 finally {
5281 closeSession(session);
5282 }
5283 }
5284
5285
5296 @Override
5297 public Organization[] filterFindByC_T_PrevAndNext(long organizationId,
5298 long companyId, String treePath, OrderByComparator orderByComparator)
5299 throws NoSuchOrganizationException, SystemException {
5300 if (!InlineSQLHelperUtil.isEnabled()) {
5301 return findByC_T_PrevAndNext(organizationId, companyId, treePath,
5302 orderByComparator);
5303 }
5304
5305 Organization organization = findByPrimaryKey(organizationId);
5306
5307 Session session = null;
5308
5309 try {
5310 session = openSession();
5311
5312 Organization[] array = new OrganizationImpl[3];
5313
5314 array[0] = filterGetByC_T_PrevAndNext(session, organization,
5315 companyId, treePath, orderByComparator, true);
5316
5317 array[1] = organization;
5318
5319 array[2] = filterGetByC_T_PrevAndNext(session, organization,
5320 companyId, treePath, orderByComparator, false);
5321
5322 return array;
5323 }
5324 catch (Exception e) {
5325 throw processException(e);
5326 }
5327 finally {
5328 closeSession(session);
5329 }
5330 }
5331
5332 protected Organization filterGetByC_T_PrevAndNext(Session session,
5333 Organization organization, long companyId, String treePath,
5334 OrderByComparator orderByComparator, boolean previous) {
5335 StringBundler query = null;
5336
5337 if (orderByComparator != null) {
5338 query = new StringBundler(6 +
5339 (orderByComparator.getOrderByFields().length * 6));
5340 }
5341 else {
5342 query = new StringBundler(3);
5343 }
5344
5345 if (getDB().isSupportsInlineDistinct()) {
5346 query.append(_FILTER_SQL_SELECT_ORGANIZATION_WHERE);
5347 }
5348 else {
5349 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1);
5350 }
5351
5352 query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
5353
5354 boolean bindTreePath = false;
5355
5356 if (treePath == null) {
5357 query.append(_FINDER_COLUMN_C_T_TREEPATH_1);
5358 }
5359 else if (treePath.equals(StringPool.BLANK)) {
5360 query.append(_FINDER_COLUMN_C_T_TREEPATH_3);
5361 }
5362 else {
5363 bindTreePath = true;
5364
5365 query.append(_FINDER_COLUMN_C_T_TREEPATH_2);
5366 }
5367
5368 if (!getDB().isSupportsInlineDistinct()) {
5369 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2);
5370 }
5371
5372 if (orderByComparator != null) {
5373 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5374
5375 if (orderByConditionFields.length > 0) {
5376 query.append(WHERE_AND);
5377 }
5378
5379 for (int i = 0; i < orderByConditionFields.length; i++) {
5380 if (getDB().isSupportsInlineDistinct()) {
5381 query.append(_ORDER_BY_ENTITY_ALIAS);
5382 }
5383 else {
5384 query.append(_ORDER_BY_ENTITY_TABLE);
5385 }
5386
5387 query.append(orderByConditionFields[i]);
5388
5389 if ((i + 1) < orderByConditionFields.length) {
5390 if (orderByComparator.isAscending() ^ previous) {
5391 query.append(WHERE_GREATER_THAN_HAS_NEXT);
5392 }
5393 else {
5394 query.append(WHERE_LESSER_THAN_HAS_NEXT);
5395 }
5396 }
5397 else {
5398 if (orderByComparator.isAscending() ^ previous) {
5399 query.append(WHERE_GREATER_THAN);
5400 }
5401 else {
5402 query.append(WHERE_LESSER_THAN);
5403 }
5404 }
5405 }
5406
5407 query.append(ORDER_BY_CLAUSE);
5408
5409 String[] orderByFields = orderByComparator.getOrderByFields();
5410
5411 for (int i = 0; i < orderByFields.length; i++) {
5412 if (getDB().isSupportsInlineDistinct()) {
5413 query.append(_ORDER_BY_ENTITY_ALIAS);
5414 }
5415 else {
5416 query.append(_ORDER_BY_ENTITY_TABLE);
5417 }
5418
5419 query.append(orderByFields[i]);
5420
5421 if ((i + 1) < orderByFields.length) {
5422 if (orderByComparator.isAscending() ^ previous) {
5423 query.append(ORDER_BY_ASC_HAS_NEXT);
5424 }
5425 else {
5426 query.append(ORDER_BY_DESC_HAS_NEXT);
5427 }
5428 }
5429 else {
5430 if (orderByComparator.isAscending() ^ previous) {
5431 query.append(ORDER_BY_ASC);
5432 }
5433 else {
5434 query.append(ORDER_BY_DESC);
5435 }
5436 }
5437 }
5438 }
5439 else {
5440 if (getDB().isSupportsInlineDistinct()) {
5441 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
5442 }
5443 else {
5444 query.append(OrganizationModelImpl.ORDER_BY_SQL);
5445 }
5446 }
5447
5448 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5449 Organization.class.getName(),
5450 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
5451
5452 SQLQuery q = session.createSQLQuery(sql);
5453
5454 q.setFirstResult(0);
5455 q.setMaxResults(2);
5456
5457 if (getDB().isSupportsInlineDistinct()) {
5458 q.addEntity(_FILTER_ENTITY_ALIAS, OrganizationImpl.class);
5459 }
5460 else {
5461 q.addEntity(_FILTER_ENTITY_TABLE, OrganizationImpl.class);
5462 }
5463
5464 QueryPos qPos = QueryPos.getInstance(q);
5465
5466 qPos.add(companyId);
5467
5468 if (bindTreePath) {
5469 qPos.add(treePath);
5470 }
5471
5472 if (orderByComparator != null) {
5473 Object[] values = orderByComparator.getOrderByConditionValues(organization);
5474
5475 for (Object value : values) {
5476 qPos.add(value);
5477 }
5478 }
5479
5480 List<Organization> list = q.list();
5481
5482 if (list.size() == 2) {
5483 return list.get(1);
5484 }
5485 else {
5486 return null;
5487 }
5488 }
5489
5490
5497 @Override
5498 public void removeByC_T(long companyId, String treePath)
5499 throws SystemException {
5500 for (Organization organization : findByC_T(companyId, treePath,
5501 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
5502 remove(organization);
5503 }
5504 }
5505
5506
5514 @Override
5515 public int countByC_T(long companyId, String treePath)
5516 throws SystemException {
5517 FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_T;
5518
5519 Object[] finderArgs = new Object[] { companyId, treePath };
5520
5521 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5522 this);
5523
5524 if (count == null) {
5525 StringBundler query = new StringBundler(3);
5526
5527 query.append(_SQL_COUNT_ORGANIZATION_WHERE);
5528
5529 query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
5530
5531 boolean bindTreePath = false;
5532
5533 if (treePath == null) {
5534 query.append(_FINDER_COLUMN_C_T_TREEPATH_1);
5535 }
5536 else if (treePath.equals(StringPool.BLANK)) {
5537 query.append(_FINDER_COLUMN_C_T_TREEPATH_3);
5538 }
5539 else {
5540 bindTreePath = true;
5541
5542 query.append(_FINDER_COLUMN_C_T_TREEPATH_2);
5543 }
5544
5545 String sql = query.toString();
5546
5547 Session session = null;
5548
5549 try {
5550 session = openSession();
5551
5552 Query q = session.createQuery(sql);
5553
5554 QueryPos qPos = QueryPos.getInstance(q);
5555
5556 qPos.add(companyId);
5557
5558 if (bindTreePath) {
5559 qPos.add(treePath);
5560 }
5561
5562 count = (Long)q.uniqueResult();
5563
5564 FinderCacheUtil.putResult(finderPath, finderArgs, count);
5565 }
5566 catch (Exception e) {
5567 FinderCacheUtil.removeResult(finderPath, finderArgs);
5568
5569 throw processException(e);
5570 }
5571 finally {
5572 closeSession(session);
5573 }
5574 }
5575
5576 return count.intValue();
5577 }
5578
5579
5587 @Override
5588 public int filterCountByC_T(long companyId, String treePath)
5589 throws SystemException {
5590 if (!InlineSQLHelperUtil.isEnabled()) {
5591 return countByC_T(companyId, treePath);
5592 }
5593
5594 StringBundler query = new StringBundler(3);
5595
5596 query.append(_FILTER_SQL_COUNT_ORGANIZATION_WHERE);
5597
5598 query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
5599
5600 boolean bindTreePath = false;
5601
5602 if (treePath == null) {
5603 query.append(_FINDER_COLUMN_C_T_TREEPATH_1);
5604 }
5605 else if (treePath.equals(StringPool.BLANK)) {
5606 query.append(_FINDER_COLUMN_C_T_TREEPATH_3);
5607 }
5608 else {
5609 bindTreePath = true;
5610
5611 query.append(_FINDER_COLUMN_C_T_TREEPATH_2);
5612 }
5613
5614 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5615 Organization.class.getName(),
5616 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
5617
5618 Session session = null;
5619
5620 try {
5621 session = openSession();
5622
5623 SQLQuery q = session.createSQLQuery(sql);
5624
5625 q.addScalar(COUNT_COLUMN_NAME,
5626 com.liferay.portal.kernel.dao.orm.Type.LONG);
5627
5628 QueryPos qPos = QueryPos.getInstance(q);
5629
5630 qPos.add(companyId);
5631
5632 if (bindTreePath) {
5633 qPos.add(treePath);
5634 }
5635
5636 Long count = (Long)q.uniqueResult();
5637
5638 return count.intValue();
5639 }
5640 catch (Exception e) {
5641 throw processException(e);
5642 }
5643 finally {
5644 closeSession(session);
5645 }
5646 }
5647
5648 private static final String _FINDER_COLUMN_C_T_COMPANYID_2 = "organization.companyId = ? AND ";
5649 private static final String _FINDER_COLUMN_C_T_TREEPATH_1 = "organization.treePath LIKE NULL";
5650 private static final String _FINDER_COLUMN_C_T_TREEPATH_2 = "organization.treePath LIKE ?";
5651 private static final String _FINDER_COLUMN_C_T_TREEPATH_3 = "(organization.treePath IS NULL OR organization.treePath LIKE '')";
5652 public static final FinderPath FINDER_PATH_FETCH_BY_C_N = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
5653 OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
5654 FINDER_CLASS_NAME_ENTITY, "fetchByC_N",
5655 new String[] { Long.class.getName(), String.class.getName() },
5656 OrganizationModelImpl.COMPANYID_COLUMN_BITMASK |
5657 OrganizationModelImpl.NAME_COLUMN_BITMASK);
5658 public static final FinderPath FINDER_PATH_COUNT_BY_C_N = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
5659 OrganizationModelImpl.FINDER_CACHE_ENABLED, Long.class,
5660 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_N",
5661 new String[] { Long.class.getName(), String.class.getName() });
5662
5663
5672 @Override
5673 public Organization findByC_N(long companyId, String name)
5674 throws NoSuchOrganizationException, SystemException {
5675 Organization organization = fetchByC_N(companyId, name);
5676
5677 if (organization == null) {
5678 StringBundler msg = new StringBundler(6);
5679
5680 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5681
5682 msg.append("companyId=");
5683 msg.append(companyId);
5684
5685 msg.append(", name=");
5686 msg.append(name);
5687
5688 msg.append(StringPool.CLOSE_CURLY_BRACE);
5689
5690 if (_log.isWarnEnabled()) {
5691 _log.warn(msg.toString());
5692 }
5693
5694 throw new NoSuchOrganizationException(msg.toString());
5695 }
5696
5697 return organization;
5698 }
5699
5700
5708 @Override
5709 public Organization fetchByC_N(long companyId, String name)
5710 throws SystemException {
5711 return fetchByC_N(companyId, name, true);
5712 }
5713
5714
5723 @Override
5724 public Organization fetchByC_N(long companyId, String name,
5725 boolean retrieveFromCache) throws SystemException {
5726 Object[] finderArgs = new Object[] { companyId, name };
5727
5728 Object result = null;
5729
5730 if (retrieveFromCache) {
5731 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_N,
5732 finderArgs, this);
5733 }
5734
5735 if (result instanceof Organization) {
5736 Organization organization = (Organization)result;
5737
5738 if ((companyId != organization.getCompanyId()) ||
5739 !Validator.equals(name, organization.getName())) {
5740 result = null;
5741 }
5742 }
5743
5744 if (result == null) {
5745 StringBundler query = new StringBundler(4);
5746
5747 query.append(_SQL_SELECT_ORGANIZATION_WHERE);
5748
5749 query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
5750
5751 boolean bindName = false;
5752
5753 if (name == null) {
5754 query.append(_FINDER_COLUMN_C_N_NAME_1);
5755 }
5756 else if (name.equals(StringPool.BLANK)) {
5757 query.append(_FINDER_COLUMN_C_N_NAME_3);
5758 }
5759 else {
5760 bindName = true;
5761
5762 query.append(_FINDER_COLUMN_C_N_NAME_2);
5763 }
5764
5765 String sql = query.toString();
5766
5767 Session session = null;
5768
5769 try {
5770 session = openSession();
5771
5772 Query q = session.createQuery(sql);
5773
5774 QueryPos qPos = QueryPos.getInstance(q);
5775
5776 qPos.add(companyId);
5777
5778 if (bindName) {
5779 qPos.add(name);
5780 }
5781
5782 List<Organization> list = q.list();
5783
5784 if (list.isEmpty()) {
5785 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
5786 finderArgs, list);
5787 }
5788 else {
5789 Organization organization = list.get(0);
5790
5791 result = organization;
5792
5793 cacheResult(organization);
5794
5795 if ((organization.getCompanyId() != companyId) ||
5796 (organization.getName() == null) ||
5797 !organization.getName().equals(name)) {
5798 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
5799 finderArgs, organization);
5800 }
5801 }
5802 }
5803 catch (Exception e) {
5804 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N,
5805 finderArgs);
5806
5807 throw processException(e);
5808 }
5809 finally {
5810 closeSession(session);
5811 }
5812 }
5813
5814 if (result instanceof List<?>) {
5815 return null;
5816 }
5817 else {
5818 return (Organization)result;
5819 }
5820 }
5821
5822
5830 @Override
5831 public Organization removeByC_N(long companyId, String name)
5832 throws NoSuchOrganizationException, SystemException {
5833 Organization organization = findByC_N(companyId, name);
5834
5835 return remove(organization);
5836 }
5837
5838
5846 @Override
5847 public int countByC_N(long companyId, String name)
5848 throws SystemException {
5849 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_N;
5850
5851 Object[] finderArgs = new Object[] { companyId, name };
5852
5853 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5854 this);
5855
5856 if (count == null) {
5857 StringBundler query = new StringBundler(3);
5858
5859 query.append(_SQL_COUNT_ORGANIZATION_WHERE);
5860
5861 query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
5862
5863 boolean bindName = false;
5864
5865 if (name == null) {
5866 query.append(_FINDER_COLUMN_C_N_NAME_1);
5867 }
5868 else if (name.equals(StringPool.BLANK)) {
5869 query.append(_FINDER_COLUMN_C_N_NAME_3);
5870 }
5871 else {
5872 bindName = true;
5873
5874 query.append(_FINDER_COLUMN_C_N_NAME_2);
5875 }
5876
5877 String sql = query.toString();
5878
5879 Session session = null;
5880
5881 try {
5882 session = openSession();
5883
5884 Query q = session.createQuery(sql);
5885
5886 QueryPos qPos = QueryPos.getInstance(q);
5887
5888 qPos.add(companyId);
5889
5890 if (bindName) {
5891 qPos.add(name);
5892 }
5893
5894 count = (Long)q.uniqueResult();
5895
5896 FinderCacheUtil.putResult(finderPath, finderArgs, count);
5897 }
5898 catch (Exception e) {
5899 FinderCacheUtil.removeResult(finderPath, finderArgs);
5900
5901 throw processException(e);
5902 }
5903 finally {
5904 closeSession(session);
5905 }
5906 }
5907
5908 return count.intValue();
5909 }
5910
5911 private static final String _FINDER_COLUMN_C_N_COMPANYID_2 = "organization.companyId = ? AND ";
5912 private static final String _FINDER_COLUMN_C_N_NAME_1 = "organization.name IS NULL";
5913 private static final String _FINDER_COLUMN_C_N_NAME_2 = "organization.name = ?";
5914 private static final String _FINDER_COLUMN_C_N_NAME_3 = "(organization.name IS NULL OR organization.name = '')";
5915 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_O_C_P = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
5916 OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
5917 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByO_C_P",
5918 new String[] {
5919 Long.class.getName(), Long.class.getName(), Long.class.getName(),
5920
5921 Integer.class.getName(), Integer.class.getName(),
5922 OrderByComparator.class.getName()
5923 });
5924 public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_O_C_P = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
5925 OrganizationModelImpl.FINDER_CACHE_ENABLED, Long.class,
5926 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByO_C_P",
5927 new String[] {
5928 Long.class.getName(), Long.class.getName(), Long.class.getName()
5929 });
5930
5931
5940 @Override
5941 public List<Organization> findByO_C_P(long organizationId, long companyId,
5942 long parentOrganizationId) throws SystemException {
5943 return findByO_C_P(organizationId, companyId, parentOrganizationId,
5944 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
5945 }
5946
5947
5962 @Override
5963 public List<Organization> findByO_C_P(long organizationId, long companyId,
5964 long parentOrganizationId, int start, int end)
5965 throws SystemException {
5966 return findByO_C_P(organizationId, companyId, parentOrganizationId,
5967 start, end, null);
5968 }
5969
5970
5986 @Override
5987 public List<Organization> findByO_C_P(long organizationId, long companyId,
5988 long parentOrganizationId, int start, int end,
5989 OrderByComparator orderByComparator) throws SystemException {
5990 boolean pagination = true;
5991 FinderPath finderPath = null;
5992 Object[] finderArgs = null;
5993
5994 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_O_C_P;
5995 finderArgs = new Object[] {
5996 organizationId, companyId, parentOrganizationId,
5997
5998 start, end, orderByComparator
5999 };
6000
6001 List<Organization> list = (List<Organization>)FinderCacheUtil.getResult(finderPath,
6002 finderArgs, this);
6003
6004 if ((list != null) && !list.isEmpty()) {
6005 for (Organization organization : list) {
6006 if ((organizationId >= organization.getOrganizationId()) ||
6007 (companyId != organization.getCompanyId()) ||
6008 (parentOrganizationId != organization.getParentOrganizationId())) {
6009 list = null;
6010
6011 break;
6012 }
6013 }
6014 }
6015
6016 if (list == null) {
6017 StringBundler query = null;
6018
6019 if (orderByComparator != null) {
6020 query = new StringBundler(5 +
6021 (orderByComparator.getOrderByFields().length * 3));
6022 }
6023 else {
6024 query = new StringBundler(5);
6025 }
6026
6027 query.append(_SQL_SELECT_ORGANIZATION_WHERE);
6028
6029 query.append(_FINDER_COLUMN_O_C_P_ORGANIZATIONID_2);
6030
6031 query.append(_FINDER_COLUMN_O_C_P_COMPANYID_2);
6032
6033 query.append(_FINDER_COLUMN_O_C_P_PARENTORGANIZATIONID_2);
6034
6035 if (orderByComparator != null) {
6036 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6037 orderByComparator);
6038 }
6039 else
6040 if (pagination) {
6041 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
6042 }
6043
6044 String sql = query.toString();
6045
6046 Session session = null;
6047
6048 try {
6049 session = openSession();
6050
6051 Query q = session.createQuery(sql);
6052
6053 QueryPos qPos = QueryPos.getInstance(q);
6054
6055 qPos.add(organizationId);
6056
6057 qPos.add(companyId);
6058
6059 qPos.add(parentOrganizationId);
6060
6061 if (!pagination) {
6062 list = (List<Organization>)QueryUtil.list(q, getDialect(),
6063 start, end, false);
6064
6065 Collections.sort(list);
6066
6067 list = new UnmodifiableList<Organization>(list);
6068 }
6069 else {
6070 list = (List<Organization>)QueryUtil.list(q, getDialect(),
6071 start, end);
6072 }
6073
6074 cacheResult(list);
6075
6076 FinderCacheUtil.putResult(finderPath, finderArgs, list);
6077 }
6078 catch (Exception e) {
6079 FinderCacheUtil.removeResult(finderPath, finderArgs);
6080
6081 throw processException(e);
6082 }
6083 finally {
6084 closeSession(session);
6085 }
6086 }
6087
6088 return list;
6089 }
6090
6091
6102 @Override
6103 public Organization findByO_C_P_First(long organizationId, long companyId,
6104 long parentOrganizationId, OrderByComparator orderByComparator)
6105 throws NoSuchOrganizationException, SystemException {
6106 Organization organization = fetchByO_C_P_First(organizationId,
6107 companyId, parentOrganizationId, orderByComparator);
6108
6109 if (organization != null) {
6110 return organization;
6111 }
6112
6113 StringBundler msg = new StringBundler(8);
6114
6115 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6116
6117 msg.append("organizationId=");
6118 msg.append(organizationId);
6119
6120 msg.append(", companyId=");
6121 msg.append(companyId);
6122
6123 msg.append(", parentOrganizationId=");
6124 msg.append(parentOrganizationId);
6125
6126 msg.append(StringPool.CLOSE_CURLY_BRACE);
6127
6128 throw new NoSuchOrganizationException(msg.toString());
6129 }
6130
6131
6141 @Override
6142 public Organization fetchByO_C_P_First(long organizationId, long companyId,
6143 long parentOrganizationId, OrderByComparator orderByComparator)
6144 throws SystemException {
6145 List<Organization> list = findByO_C_P(organizationId, companyId,
6146 parentOrganizationId, 0, 1, orderByComparator);
6147
6148 if (!list.isEmpty()) {
6149 return list.get(0);
6150 }
6151
6152 return null;
6153 }
6154
6155
6166 @Override
6167 public Organization findByO_C_P_Last(long organizationId, long companyId,
6168 long parentOrganizationId, OrderByComparator orderByComparator)
6169 throws NoSuchOrganizationException, SystemException {
6170 Organization organization = fetchByO_C_P_Last(organizationId,
6171 companyId, parentOrganizationId, orderByComparator);
6172
6173 if (organization != null) {
6174 return organization;
6175 }
6176
6177 StringBundler msg = new StringBundler(8);
6178
6179 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6180
6181 msg.append("organizationId=");
6182 msg.append(organizationId);
6183
6184 msg.append(", companyId=");
6185 msg.append(companyId);
6186
6187 msg.append(", parentOrganizationId=");
6188 msg.append(parentOrganizationId);
6189
6190 msg.append(StringPool.CLOSE_CURLY_BRACE);
6191
6192 throw new NoSuchOrganizationException(msg.toString());
6193 }
6194
6195
6205 @Override
6206 public Organization fetchByO_C_P_Last(long organizationId, long companyId,
6207 long parentOrganizationId, OrderByComparator orderByComparator)
6208 throws SystemException {
6209 int count = countByO_C_P(organizationId, companyId, parentOrganizationId);
6210
6211 if (count == 0) {
6212 return null;
6213 }
6214
6215 List<Organization> list = findByO_C_P(organizationId, companyId,
6216 parentOrganizationId, count - 1, count, orderByComparator);
6217
6218 if (!list.isEmpty()) {
6219 return list.get(0);
6220 }
6221
6222 return null;
6223 }
6224
6225
6234 @Override
6235 public List<Organization> filterFindByO_C_P(long organizationId,
6236 long companyId, long parentOrganizationId) throws SystemException {
6237 return filterFindByO_C_P(organizationId, companyId,
6238 parentOrganizationId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
6239 }
6240
6241
6256 @Override
6257 public List<Organization> filterFindByO_C_P(long organizationId,
6258 long companyId, long parentOrganizationId, int start, int end)
6259 throws SystemException {
6260 return filterFindByO_C_P(organizationId, companyId,
6261 parentOrganizationId, start, end, null);
6262 }
6263
6264
6280 @Override
6281 public List<Organization> filterFindByO_C_P(long organizationId,
6282 long companyId, long parentOrganizationId, int start, int end,
6283 OrderByComparator orderByComparator) throws SystemException {
6284 if (!InlineSQLHelperUtil.isEnabled()) {
6285 return findByO_C_P(organizationId, companyId, parentOrganizationId,
6286 start, end, orderByComparator);
6287 }
6288
6289 StringBundler query = null;
6290
6291 if (orderByComparator != null) {
6292 query = new StringBundler(5 +
6293 (orderByComparator.getOrderByFields().length * 3));
6294 }
6295 else {
6296 query = new StringBundler(5);
6297 }
6298
6299 if (getDB().isSupportsInlineDistinct()) {
6300 query.append(_FILTER_SQL_SELECT_ORGANIZATION_WHERE);
6301 }
6302 else {
6303 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1);
6304 }
6305
6306 query.append(_FINDER_COLUMN_O_C_P_ORGANIZATIONID_2);
6307
6308 query.append(_FINDER_COLUMN_O_C_P_COMPANYID_2);
6309
6310 query.append(_FINDER_COLUMN_O_C_P_PARENTORGANIZATIONID_2);
6311
6312 if (!getDB().isSupportsInlineDistinct()) {
6313 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2);
6314 }
6315
6316 if (orderByComparator != null) {
6317 if (getDB().isSupportsInlineDistinct()) {
6318 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6319 orderByComparator, true);
6320 }
6321 else {
6322 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
6323 orderByComparator, true);
6324 }
6325 }
6326 else {
6327 if (getDB().isSupportsInlineDistinct()) {
6328 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
6329 }
6330 else {
6331 query.append(OrganizationModelImpl.ORDER_BY_SQL);
6332 }
6333 }
6334
6335 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6336 Organization.class.getName(),
6337 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
6338
6339 Session session = null;
6340
6341 try {
6342 session = openSession();
6343
6344 SQLQuery q = session.createSQLQuery(sql);
6345
6346 if (getDB().isSupportsInlineDistinct()) {
6347 q.addEntity(_FILTER_ENTITY_ALIAS, OrganizationImpl.class);
6348 }
6349 else {
6350 q.addEntity(_FILTER_ENTITY_TABLE, OrganizationImpl.class);
6351 }
6352
6353 QueryPos qPos = QueryPos.getInstance(q);
6354
6355 qPos.add(organizationId);
6356
6357 qPos.add(companyId);
6358
6359 qPos.add(parentOrganizationId);
6360
6361 return (List<Organization>)QueryUtil.list(q, getDialect(), start,
6362 end);
6363 }
6364 catch (Exception e) {
6365 throw processException(e);
6366 }
6367 finally {
6368 closeSession(session);
6369 }
6370 }
6371
6372
6380 @Override
6381 public void removeByO_C_P(long organizationId, long companyId,
6382 long parentOrganizationId) throws SystemException {
6383 for (Organization organization : findByO_C_P(organizationId, companyId,
6384 parentOrganizationId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
6385 remove(organization);
6386 }
6387 }
6388
6389
6398 @Override
6399 public int countByO_C_P(long organizationId, long companyId,
6400 long parentOrganizationId) throws SystemException {
6401 FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_O_C_P;
6402
6403 Object[] finderArgs = new Object[] {
6404 organizationId, companyId, parentOrganizationId
6405 };
6406
6407 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
6408 this);
6409
6410 if (count == null) {
6411 StringBundler query = new StringBundler(4);
6412
6413 query.append(_SQL_COUNT_ORGANIZATION_WHERE);
6414
6415 query.append(_FINDER_COLUMN_O_C_P_ORGANIZATIONID_2);
6416
6417 query.append(_FINDER_COLUMN_O_C_P_COMPANYID_2);
6418
6419 query.append(_FINDER_COLUMN_O_C_P_PARENTORGANIZATIONID_2);
6420
6421 String sql = query.toString();
6422
6423 Session session = null;
6424
6425 try {
6426 session = openSession();
6427
6428 Query q = session.createQuery(sql);
6429
6430 QueryPos qPos = QueryPos.getInstance(q);
6431
6432 qPos.add(organizationId);
6433
6434 qPos.add(companyId);
6435
6436 qPos.add(parentOrganizationId);
6437
6438 count = (Long)q.uniqueResult();
6439
6440 FinderCacheUtil.putResult(finderPath, finderArgs, count);
6441 }
6442 catch (Exception e) {
6443 FinderCacheUtil.removeResult(finderPath, finderArgs);
6444
6445 throw processException(e);
6446 }
6447 finally {
6448 closeSession(session);
6449 }
6450 }
6451
6452 return count.intValue();
6453 }
6454
6455
6464 @Override
6465 public int filterCountByO_C_P(long organizationId, long companyId,
6466 long parentOrganizationId) throws SystemException {
6467 if (!InlineSQLHelperUtil.isEnabled()) {
6468 return countByO_C_P(organizationId, companyId, parentOrganizationId);
6469 }
6470
6471 StringBundler query = new StringBundler(4);
6472
6473 query.append(_FILTER_SQL_COUNT_ORGANIZATION_WHERE);
6474
6475 query.append(_FINDER_COLUMN_O_C_P_ORGANIZATIONID_2);
6476
6477 query.append(_FINDER_COLUMN_O_C_P_COMPANYID_2);
6478
6479 query.append(_FINDER_COLUMN_O_C_P_PARENTORGANIZATIONID_2);
6480
6481 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6482 Organization.class.getName(),
6483 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
6484
6485 Session session = null;
6486
6487 try {
6488 session = openSession();
6489
6490 SQLQuery q = session.createSQLQuery(sql);
6491
6492 q.addScalar(COUNT_COLUMN_NAME,
6493 com.liferay.portal.kernel.dao.orm.Type.LONG);
6494
6495 QueryPos qPos = QueryPos.getInstance(q);
6496
6497 qPos.add(organizationId);
6498
6499 qPos.add(companyId);
6500
6501 qPos.add(parentOrganizationId);
6502
6503 Long count = (Long)q.uniqueResult();
6504
6505 return count.intValue();
6506 }
6507 catch (Exception e) {
6508 throw processException(e);
6509 }
6510 finally {
6511 closeSession(session);
6512 }
6513 }
6514
6515 private static final String _FINDER_COLUMN_O_C_P_ORGANIZATIONID_2 = "organization.organizationId > ? AND ";
6516 private static final String _FINDER_COLUMN_O_C_P_COMPANYID_2 = "organization.companyId = ? AND ";
6517 private static final String _FINDER_COLUMN_O_C_P_PARENTORGANIZATIONID_2 = "organization.parentOrganizationId = ?";
6518
6519 public OrganizationPersistenceImpl() {
6520 setModelClass(Organization.class);
6521 }
6522
6523
6528 @Override
6529 public void cacheResult(Organization organization) {
6530 EntityCacheUtil.putResult(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
6531 OrganizationImpl.class, organization.getPrimaryKey(), organization);
6532
6533 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
6534 new Object[] { organization.getCompanyId(), organization.getName() },
6535 organization);
6536
6537 organization.resetOriginalValues();
6538 }
6539
6540
6545 @Override
6546 public void cacheResult(List<Organization> organizations) {
6547 for (Organization organization : organizations) {
6548 if (EntityCacheUtil.getResult(
6549 OrganizationModelImpl.ENTITY_CACHE_ENABLED,
6550 OrganizationImpl.class, organization.getPrimaryKey()) == null) {
6551 cacheResult(organization);
6552 }
6553 else {
6554 organization.resetOriginalValues();
6555 }
6556 }
6557 }
6558
6559
6566 @Override
6567 public void clearCache() {
6568 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
6569 CacheRegistryUtil.clear(OrganizationImpl.class.getName());
6570 }
6571
6572 EntityCacheUtil.clearCache(OrganizationImpl.class.getName());
6573
6574 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
6575 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
6576 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
6577 }
6578
6579
6586 @Override
6587 public void clearCache(Organization organization) {
6588 EntityCacheUtil.removeResult(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
6589 OrganizationImpl.class, organization.getPrimaryKey());
6590
6591 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
6592 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
6593
6594 clearUniqueFindersCache(organization);
6595 }
6596
6597 @Override
6598 public void clearCache(List<Organization> organizations) {
6599 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
6600 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
6601
6602 for (Organization organization : organizations) {
6603 EntityCacheUtil.removeResult(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
6604 OrganizationImpl.class, organization.getPrimaryKey());
6605
6606 clearUniqueFindersCache(organization);
6607 }
6608 }
6609
6610 protected void cacheUniqueFindersCache(Organization organization) {
6611 if (organization.isNew()) {
6612 Object[] args = new Object[] {
6613 organization.getCompanyId(), organization.getName()
6614 };
6615
6616 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_N, args,
6617 Long.valueOf(1));
6618 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N, args,
6619 organization);
6620 }
6621 else {
6622 OrganizationModelImpl organizationModelImpl = (OrganizationModelImpl)organization;
6623
6624 if ((organizationModelImpl.getColumnBitmask() &
6625 FINDER_PATH_FETCH_BY_C_N.getColumnBitmask()) != 0) {
6626 Object[] args = new Object[] {
6627 organization.getCompanyId(), organization.getName()
6628 };
6629
6630 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_N, args,
6631 Long.valueOf(1));
6632 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N, args,
6633 organization);
6634 }
6635 }
6636 }
6637
6638 protected void clearUniqueFindersCache(Organization organization) {
6639 OrganizationModelImpl organizationModelImpl = (OrganizationModelImpl)organization;
6640
6641 Object[] args = new Object[] {
6642 organization.getCompanyId(), organization.getName()
6643 };
6644
6645 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N, args);
6646 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N, args);
6647
6648 if ((organizationModelImpl.getColumnBitmask() &
6649 FINDER_PATH_FETCH_BY_C_N.getColumnBitmask()) != 0) {
6650 args = new Object[] {
6651 organizationModelImpl.getOriginalCompanyId(),
6652 organizationModelImpl.getOriginalName()
6653 };
6654
6655 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N, args);
6656 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N, args);
6657 }
6658 }
6659
6660
6666 @Override
6667 public Organization create(long organizationId) {
6668 Organization organization = new OrganizationImpl();
6669
6670 organization.setNew(true);
6671 organization.setPrimaryKey(organizationId);
6672
6673 String uuid = PortalUUIDUtil.generate();
6674
6675 organization.setUuid(uuid);
6676
6677 return organization;
6678 }
6679
6680
6688 @Override
6689 public Organization remove(long organizationId)
6690 throws NoSuchOrganizationException, SystemException {
6691 return remove((Serializable)organizationId);
6692 }
6693
6694
6702 @Override
6703 public Organization remove(Serializable primaryKey)
6704 throws NoSuchOrganizationException, SystemException {
6705 Session session = null;
6706
6707 try {
6708 session = openSession();
6709
6710 Organization organization = (Organization)session.get(OrganizationImpl.class,
6711 primaryKey);
6712
6713 if (organization == null) {
6714 if (_log.isWarnEnabled()) {
6715 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
6716 }
6717
6718 throw new NoSuchOrganizationException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
6719 primaryKey);
6720 }
6721
6722 return remove(organization);
6723 }
6724 catch (NoSuchOrganizationException nsee) {
6725 throw nsee;
6726 }
6727 catch (Exception e) {
6728 throw processException(e);
6729 }
6730 finally {
6731 closeSession(session);
6732 }
6733 }
6734
6735 @Override
6736 protected Organization removeImpl(Organization organization)
6737 throws SystemException {
6738 organization = toUnwrappedModel(organization);
6739
6740 organizationToGroupTableMapper.deleteLeftPrimaryKeyTableMappings(organization.getPrimaryKey());
6741
6742 organizationToUserTableMapper.deleteLeftPrimaryKeyTableMappings(organization.getPrimaryKey());
6743
6744 Session session = null;
6745
6746 try {
6747 session = openSession();
6748
6749 if (!session.contains(organization)) {
6750 organization = (Organization)session.get(OrganizationImpl.class,
6751 organization.getPrimaryKeyObj());
6752 }
6753
6754 if (organization != null) {
6755 session.delete(organization);
6756 }
6757 }
6758 catch (Exception e) {
6759 throw processException(e);
6760 }
6761 finally {
6762 closeSession(session);
6763 }
6764
6765 if (organization != null) {
6766 clearCache(organization);
6767 }
6768
6769 return organization;
6770 }
6771
6772 @Override
6773 public Organization updateImpl(
6774 com.liferay.portal.model.Organization organization)
6775 throws SystemException {
6776 organization = toUnwrappedModel(organization);
6777
6778 boolean isNew = organization.isNew();
6779
6780 OrganizationModelImpl organizationModelImpl = (OrganizationModelImpl)organization;
6781
6782 if (Validator.isNull(organization.getUuid())) {
6783 String uuid = PortalUUIDUtil.generate();
6784
6785 organization.setUuid(uuid);
6786 }
6787
6788 Session session = null;
6789
6790 try {
6791 session = openSession();
6792
6793 if (organization.isNew()) {
6794 session.save(organization);
6795
6796 organization.setNew(false);
6797 }
6798 else {
6799 session.merge(organization);
6800 }
6801 }
6802 catch (Exception e) {
6803 throw processException(e);
6804 }
6805 finally {
6806 closeSession(session);
6807 }
6808
6809 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
6810
6811 if (isNew || !OrganizationModelImpl.COLUMN_BITMASK_ENABLED) {
6812 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
6813 }
6814
6815 else {
6816 if ((organizationModelImpl.getColumnBitmask() &
6817 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
6818 Object[] args = new Object[] {
6819 organizationModelImpl.getOriginalUuid()
6820 };
6821
6822 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
6823 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
6824 args);
6825
6826 args = new Object[] { organizationModelImpl.getUuid() };
6827
6828 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
6829 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
6830 args);
6831 }
6832
6833 if ((organizationModelImpl.getColumnBitmask() &
6834 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
6835 Object[] args = new Object[] {
6836 organizationModelImpl.getOriginalUuid(),
6837 organizationModelImpl.getOriginalCompanyId()
6838 };
6839
6840 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
6841 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
6842 args);
6843
6844 args = new Object[] {
6845 organizationModelImpl.getUuid(),
6846 organizationModelImpl.getCompanyId()
6847 };
6848
6849 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
6850 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
6851 args);
6852 }
6853
6854 if ((organizationModelImpl.getColumnBitmask() &
6855 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
6856 Object[] args = new Object[] {
6857 organizationModelImpl.getOriginalCompanyId()
6858 };
6859
6860 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
6861 args);
6862 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
6863 args);
6864
6865 args = new Object[] { organizationModelImpl.getCompanyId() };
6866
6867 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
6868 args);
6869 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
6870 args);
6871 }
6872
6873 if ((organizationModelImpl.getColumnBitmask() &
6874 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LOCATIONS.getColumnBitmask()) != 0) {
6875 Object[] args = new Object[] {
6876 organizationModelImpl.getOriginalCompanyId()
6877 };
6878
6879 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_LOCATIONS,
6880 args);
6881 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LOCATIONS,
6882 args);
6883
6884 args = new Object[] { organizationModelImpl.getCompanyId() };
6885
6886 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_LOCATIONS,
6887 args);
6888 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LOCATIONS,
6889 args);
6890 }
6891
6892 if ((organizationModelImpl.getColumnBitmask() &
6893 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P.getColumnBitmask()) != 0) {
6894 Object[] args = new Object[] {
6895 organizationModelImpl.getOriginalCompanyId(),
6896 organizationModelImpl.getOriginalParentOrganizationId()
6897 };
6898
6899 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_P, args);
6900 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P,
6901 args);
6902
6903 args = new Object[] {
6904 organizationModelImpl.getCompanyId(),
6905 organizationModelImpl.getParentOrganizationId()
6906 };
6907
6908 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_P, args);
6909 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P,
6910 args);
6911 }
6912 }
6913
6914 EntityCacheUtil.putResult(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
6915 OrganizationImpl.class, organization.getPrimaryKey(), organization);
6916
6917 clearUniqueFindersCache(organization);
6918 cacheUniqueFindersCache(organization);
6919
6920 return organization;
6921 }
6922
6923 protected Organization toUnwrappedModel(Organization organization) {
6924 if (organization instanceof OrganizationImpl) {
6925 return organization;
6926 }
6927
6928 OrganizationImpl organizationImpl = new OrganizationImpl();
6929
6930 organizationImpl.setNew(organization.isNew());
6931 organizationImpl.setPrimaryKey(organization.getPrimaryKey());
6932
6933 organizationImpl.setUuid(organization.getUuid());
6934 organizationImpl.setOrganizationId(organization.getOrganizationId());
6935 organizationImpl.setCompanyId(organization.getCompanyId());
6936 organizationImpl.setUserId(organization.getUserId());
6937 organizationImpl.setUserName(organization.getUserName());
6938 organizationImpl.setCreateDate(organization.getCreateDate());
6939 organizationImpl.setModifiedDate(organization.getModifiedDate());
6940 organizationImpl.setParentOrganizationId(organization.getParentOrganizationId());
6941 organizationImpl.setTreePath(organization.getTreePath());
6942 organizationImpl.setName(organization.getName());
6943 organizationImpl.setType(organization.getType());
6944 organizationImpl.setRecursable(organization.isRecursable());
6945 organizationImpl.setRegionId(organization.getRegionId());
6946 organizationImpl.setCountryId(organization.getCountryId());
6947 organizationImpl.setStatusId(organization.getStatusId());
6948 organizationImpl.setComments(organization.getComments());
6949
6950 return organizationImpl;
6951 }
6952
6953
6961 @Override
6962 public Organization findByPrimaryKey(Serializable primaryKey)
6963 throws NoSuchOrganizationException, SystemException {
6964 Organization organization = fetchByPrimaryKey(primaryKey);
6965
6966 if (organization == null) {
6967 if (_log.isWarnEnabled()) {
6968 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
6969 }
6970
6971 throw new NoSuchOrganizationException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
6972 primaryKey);
6973 }
6974
6975 return organization;
6976 }
6977
6978
6986 @Override
6987 public Organization findByPrimaryKey(long organizationId)
6988 throws NoSuchOrganizationException, SystemException {
6989 return findByPrimaryKey((Serializable)organizationId);
6990 }
6991
6992
6999 @Override
7000 public Organization fetchByPrimaryKey(Serializable primaryKey)
7001 throws SystemException {
7002 Organization organization = (Organization)EntityCacheUtil.getResult(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
7003 OrganizationImpl.class, primaryKey);
7004
7005 if (organization == _nullOrganization) {
7006 return null;
7007 }
7008
7009 if (organization == null) {
7010 Session session = null;
7011
7012 try {
7013 session = openSession();
7014
7015 organization = (Organization)session.get(OrganizationImpl.class,
7016 primaryKey);
7017
7018 if (organization != null) {
7019 cacheResult(organization);
7020 }
7021 else {
7022 EntityCacheUtil.putResult(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
7023 OrganizationImpl.class, primaryKey, _nullOrganization);
7024 }
7025 }
7026 catch (Exception e) {
7027 EntityCacheUtil.removeResult(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
7028 OrganizationImpl.class, primaryKey);
7029
7030 throw processException(e);
7031 }
7032 finally {
7033 closeSession(session);
7034 }
7035 }
7036
7037 return organization;
7038 }
7039
7040
7047 @Override
7048 public Organization fetchByPrimaryKey(long organizationId)
7049 throws SystemException {
7050 return fetchByPrimaryKey((Serializable)organizationId);
7051 }
7052
7053
7059 @Override
7060 public List<Organization> findAll() throws SystemException {
7061 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
7062 }
7063
7064
7076 @Override
7077 public List<Organization> findAll(int start, int end)
7078 throws SystemException {
7079 return findAll(start, end, null);
7080 }
7081
7082
7095 @Override
7096 public List<Organization> findAll(int start, int end,
7097 OrderByComparator orderByComparator) throws SystemException {
7098 boolean pagination = true;
7099 FinderPath finderPath = null;
7100 Object[] finderArgs = null;
7101
7102 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7103 (orderByComparator == null)) {
7104 pagination = false;
7105 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
7106 finderArgs = FINDER_ARGS_EMPTY;
7107 }
7108 else {
7109 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
7110 finderArgs = new Object[] { start, end, orderByComparator };
7111 }
7112
7113 List<Organization> list = (List<Organization>)FinderCacheUtil.getResult(finderPath,
7114 finderArgs, this);
7115
7116 if (list == null) {
7117 StringBundler query = null;
7118 String sql = null;
7119
7120 if (orderByComparator != null) {
7121 query = new StringBundler(2 +
7122 (orderByComparator.getOrderByFields().length * 3));
7123
7124 query.append(_SQL_SELECT_ORGANIZATION);
7125
7126 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7127 orderByComparator);
7128
7129 sql = query.toString();
7130 }
7131 else {
7132 sql = _SQL_SELECT_ORGANIZATION;
7133
7134 if (pagination) {
7135 sql = sql.concat(OrganizationModelImpl.ORDER_BY_JPQL);
7136 }
7137 }
7138
7139 Session session = null;
7140
7141 try {
7142 session = openSession();
7143
7144 Query q = session.createQuery(sql);
7145
7146 if (!pagination) {
7147 list = (List<Organization>)QueryUtil.list(q, getDialect(),
7148 start, end, false);
7149
7150 Collections.sort(list);
7151
7152 list = new UnmodifiableList<Organization>(list);
7153 }
7154 else {
7155 list = (List<Organization>)QueryUtil.list(q, getDialect(),
7156 start, end);
7157 }
7158
7159 cacheResult(list);
7160
7161 FinderCacheUtil.putResult(finderPath, finderArgs, list);
7162 }
7163 catch (Exception e) {
7164 FinderCacheUtil.removeResult(finderPath, finderArgs);
7165
7166 throw processException(e);
7167 }
7168 finally {
7169 closeSession(session);
7170 }
7171 }
7172
7173 return list;
7174 }
7175
7176
7181 @Override
7182 public void removeAll() throws SystemException {
7183 for (Organization organization : findAll()) {
7184 remove(organization);
7185 }
7186 }
7187
7188
7194 @Override
7195 public int countAll() throws SystemException {
7196 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
7197 FINDER_ARGS_EMPTY, this);
7198
7199 if (count == null) {
7200 Session session = null;
7201
7202 try {
7203 session = openSession();
7204
7205 Query q = session.createQuery(_SQL_COUNT_ORGANIZATION);
7206
7207 count = (Long)q.uniqueResult();
7208
7209 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
7210 FINDER_ARGS_EMPTY, count);
7211 }
7212 catch (Exception e) {
7213 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
7214 FINDER_ARGS_EMPTY);
7215
7216 throw processException(e);
7217 }
7218 finally {
7219 closeSession(session);
7220 }
7221 }
7222
7223 return count.intValue();
7224 }
7225
7226
7233 @Override
7234 public List<com.liferay.portal.model.Group> getGroups(long pk)
7235 throws SystemException {
7236 return getGroups(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
7237 }
7238
7239
7252 @Override
7253 public List<com.liferay.portal.model.Group> getGroups(long pk, int start,
7254 int end) throws SystemException {
7255 return getGroups(pk, start, end, null);
7256 }
7257
7258
7272 @Override
7273 public List<com.liferay.portal.model.Group> getGroups(long pk, int start,
7274 int end, OrderByComparator orderByComparator) throws SystemException {
7275 return organizationToGroupTableMapper.getRightBaseModels(pk, start,
7276 end, orderByComparator);
7277 }
7278
7279
7286 @Override
7287 public int getGroupsSize(long pk) throws SystemException {
7288 long[] pks = organizationToGroupTableMapper.getRightPrimaryKeys(pk);
7289
7290 return pks.length;
7291 }
7292
7293
7301 @Override
7302 public boolean containsGroup(long pk, long groupPK)
7303 throws SystemException {
7304 return organizationToGroupTableMapper.containsTableMapping(pk, groupPK);
7305 }
7306
7307
7314 @Override
7315 public boolean containsGroups(long pk) throws SystemException {
7316 if (getGroupsSize(pk) > 0) {
7317 return true;
7318 }
7319 else {
7320 return false;
7321 }
7322 }
7323
7324
7331 @Override
7332 public void addGroup(long pk, long groupPK) throws SystemException {
7333 organizationToGroupTableMapper.addTableMapping(pk, groupPK);
7334 }
7335
7336
7343 @Override
7344 public void addGroup(long pk, com.liferay.portal.model.Group group)
7345 throws SystemException {
7346 organizationToGroupTableMapper.addTableMapping(pk, group.getPrimaryKey());
7347 }
7348
7349
7356 @Override
7357 public void addGroups(long pk, long[] groupPKs) throws SystemException {
7358 for (long groupPK : groupPKs) {
7359 organizationToGroupTableMapper.addTableMapping(pk, groupPK);
7360 }
7361 }
7362
7363
7370 @Override
7371 public void addGroups(long pk, List<com.liferay.portal.model.Group> groups)
7372 throws SystemException {
7373 for (com.liferay.portal.model.Group group : groups) {
7374 organizationToGroupTableMapper.addTableMapping(pk,
7375 group.getPrimaryKey());
7376 }
7377 }
7378
7379
7385 @Override
7386 public void clearGroups(long pk) throws SystemException {
7387 organizationToGroupTableMapper.deleteLeftPrimaryKeyTableMappings(pk);
7388 }
7389
7390
7397 @Override
7398 public void removeGroup(long pk, long groupPK) throws SystemException {
7399 organizationToGroupTableMapper.deleteTableMapping(pk, groupPK);
7400 }
7401
7402
7409 @Override
7410 public void removeGroup(long pk, com.liferay.portal.model.Group group)
7411 throws SystemException {
7412 organizationToGroupTableMapper.deleteTableMapping(pk,
7413 group.getPrimaryKey());
7414 }
7415
7416
7423 @Override
7424 public void removeGroups(long pk, long[] groupPKs)
7425 throws SystemException {
7426 for (long groupPK : groupPKs) {
7427 organizationToGroupTableMapper.deleteTableMapping(pk, groupPK);
7428 }
7429 }
7430
7431
7438 @Override
7439 public void removeGroups(long pk,
7440 List<com.liferay.portal.model.Group> groups) throws SystemException {
7441 for (com.liferay.portal.model.Group group : groups) {
7442 organizationToGroupTableMapper.deleteTableMapping(pk,
7443 group.getPrimaryKey());
7444 }
7445 }
7446
7447
7454 @Override
7455 public void setGroups(long pk, long[] groupPKs) throws SystemException {
7456 Set<Long> newGroupPKsSet = SetUtil.fromArray(groupPKs);
7457 Set<Long> oldGroupPKsSet = SetUtil.fromArray(organizationToGroupTableMapper.getRightPrimaryKeys(
7458 pk));
7459
7460 Set<Long> removeGroupPKsSet = new HashSet<Long>(oldGroupPKsSet);
7461
7462 removeGroupPKsSet.removeAll(newGroupPKsSet);
7463
7464 for (long removeGroupPK : removeGroupPKsSet) {
7465 organizationToGroupTableMapper.deleteTableMapping(pk, removeGroupPK);
7466 }
7467
7468 newGroupPKsSet.removeAll(oldGroupPKsSet);
7469
7470 for (long newGroupPK : newGroupPKsSet) {
7471 organizationToGroupTableMapper.addTableMapping(pk, newGroupPK);
7472 }
7473 }
7474
7475
7482 @Override
7483 public void setGroups(long pk, List<com.liferay.portal.model.Group> groups)
7484 throws SystemException {
7485 try {
7486 long[] groupPKs = new long[groups.size()];
7487
7488 for (int i = 0; i < groups.size(); i++) {
7489 com.liferay.portal.model.Group group = groups.get(i);
7490
7491 groupPKs[i] = group.getPrimaryKey();
7492 }
7493
7494 setGroups(pk, groupPKs);
7495 }
7496 catch (Exception e) {
7497 throw processException(e);
7498 }
7499 finally {
7500 FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_GROUPS_ORGS_NAME);
7501 }
7502 }
7503
7504
7511 @Override
7512 public List<com.liferay.portal.model.User> getUsers(long pk)
7513 throws SystemException {
7514 return getUsers(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
7515 }
7516
7517
7530 @Override
7531 public List<com.liferay.portal.model.User> getUsers(long pk, int start,
7532 int end) throws SystemException {
7533 return getUsers(pk, start, end, null);
7534 }
7535
7536
7550 @Override
7551 public List<com.liferay.portal.model.User> getUsers(long pk, int start,
7552 int end, OrderByComparator orderByComparator) throws SystemException {
7553 return organizationToUserTableMapper.getRightBaseModels(pk, start, end,
7554 orderByComparator);
7555 }
7556
7557
7564 @Override
7565 public int getUsersSize(long pk) throws SystemException {
7566 long[] pks = organizationToUserTableMapper.getRightPrimaryKeys(pk);
7567
7568 return pks.length;
7569 }
7570
7571
7579 @Override
7580 public boolean containsUser(long pk, long userPK) throws SystemException {
7581 return organizationToUserTableMapper.containsTableMapping(pk, userPK);
7582 }
7583
7584
7591 @Override
7592 public boolean containsUsers(long pk) throws SystemException {
7593 if (getUsersSize(pk) > 0) {
7594 return true;
7595 }
7596 else {
7597 return false;
7598 }
7599 }
7600
7601
7608 @Override
7609 public void addUser(long pk, long userPK) throws SystemException {
7610 organizationToUserTableMapper.addTableMapping(pk, userPK);
7611 }
7612
7613
7620 @Override
7621 public void addUser(long pk, com.liferay.portal.model.User user)
7622 throws SystemException {
7623 organizationToUserTableMapper.addTableMapping(pk, user.getPrimaryKey());
7624 }
7625
7626
7633 @Override
7634 public void addUsers(long pk, long[] userPKs) throws SystemException {
7635 for (long userPK : userPKs) {
7636 organizationToUserTableMapper.addTableMapping(pk, userPK);
7637 }
7638 }
7639
7640
7647 @Override
7648 public void addUsers(long pk, List<com.liferay.portal.model.User> users)
7649 throws SystemException {
7650 for (com.liferay.portal.model.User user : users) {
7651 organizationToUserTableMapper.addTableMapping(pk,
7652 user.getPrimaryKey());
7653 }
7654 }
7655
7656
7662 @Override
7663 public void clearUsers(long pk) throws SystemException {
7664 organizationToUserTableMapper.deleteLeftPrimaryKeyTableMappings(pk);
7665 }
7666
7667
7674 @Override
7675 public void removeUser(long pk, long userPK) throws SystemException {
7676 organizationToUserTableMapper.deleteTableMapping(pk, userPK);
7677 }
7678
7679
7686 @Override
7687 public void removeUser(long pk, com.liferay.portal.model.User user)
7688 throws SystemException {
7689 organizationToUserTableMapper.deleteTableMapping(pk,
7690 user.getPrimaryKey());
7691 }
7692
7693
7700 @Override
7701 public void removeUsers(long pk, long[] userPKs) throws SystemException {
7702 for (long userPK : userPKs) {
7703 organizationToUserTableMapper.deleteTableMapping(pk, userPK);
7704 }
7705 }
7706
7707
7714 @Override
7715 public void removeUsers(long pk, List<com.liferay.portal.model.User> users)
7716 throws SystemException {
7717 for (com.liferay.portal.model.User user : users) {
7718 organizationToUserTableMapper.deleteTableMapping(pk,
7719 user.getPrimaryKey());
7720 }
7721 }
7722
7723
7730 @Override
7731 public void setUsers(long pk, long[] userPKs) throws SystemException {
7732 Set<Long> newUserPKsSet = SetUtil.fromArray(userPKs);
7733 Set<Long> oldUserPKsSet = SetUtil.fromArray(organizationToUserTableMapper.getRightPrimaryKeys(
7734 pk));
7735
7736 Set<Long> removeUserPKsSet = new HashSet<Long>(oldUserPKsSet);
7737
7738 removeUserPKsSet.removeAll(newUserPKsSet);
7739
7740 for (long removeUserPK : removeUserPKsSet) {
7741 organizationToUserTableMapper.deleteTableMapping(pk, removeUserPK);
7742 }
7743
7744 newUserPKsSet.removeAll(oldUserPKsSet);
7745
7746 for (long newUserPK : newUserPKsSet) {
7747 organizationToUserTableMapper.addTableMapping(pk, newUserPK);
7748 }
7749 }
7750
7751
7758 @Override
7759 public void setUsers(long pk, List<com.liferay.portal.model.User> users)
7760 throws SystemException {
7761 try {
7762 long[] userPKs = new long[users.size()];
7763
7764 for (int i = 0; i < users.size(); i++) {
7765 com.liferay.portal.model.User user = users.get(i);
7766
7767 userPKs[i] = user.getPrimaryKey();
7768 }
7769
7770 setUsers(pk, userPKs);
7771 }
7772 catch (Exception e) {
7773 throw processException(e);
7774 }
7775 finally {
7776 FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_USERS_ORGS_NAME);
7777 }
7778 }
7779
7780 @Override
7781 protected Set<String> getBadColumnNames() {
7782 return _badColumnNames;
7783 }
7784
7785
7788 public void afterPropertiesSet() {
7789 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
7790 com.liferay.portal.util.PropsUtil.get(
7791 "value.object.listener.com.liferay.portal.model.Organization")));
7792
7793 if (listenerClassNames.length > 0) {
7794 try {
7795 List<ModelListener<Organization>> listenersList = new ArrayList<ModelListener<Organization>>();
7796
7797 for (String listenerClassName : listenerClassNames) {
7798 listenersList.add((ModelListener<Organization>)InstanceFactory.newInstance(
7799 getClassLoader(), listenerClassName));
7800 }
7801
7802 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
7803 }
7804 catch (Exception e) {
7805 _log.error(e);
7806 }
7807 }
7808
7809 organizationToGroupTableMapper = TableMapperFactory.getTableMapper("Groups_Orgs",
7810 "organizationId", "groupId", this, groupPersistence);
7811
7812 organizationToUserTableMapper = TableMapperFactory.getTableMapper("Users_Orgs",
7813 "organizationId", "userId", this, userPersistence);
7814 }
7815
7816 public void destroy() {
7817 EntityCacheUtil.removeCache(OrganizationImpl.class.getName());
7818 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
7819 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
7820 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
7821
7822 TableMapperFactory.removeTableMapper("Groups_Orgs");
7823 TableMapperFactory.removeTableMapper("Users_Orgs");
7824 }
7825
7826 @BeanReference(type = GroupPersistence.class)
7827 protected GroupPersistence groupPersistence;
7828 protected TableMapper<Organization, com.liferay.portal.model.Group> organizationToGroupTableMapper;
7829 @BeanReference(type = UserPersistence.class)
7830 protected UserPersistence userPersistence;
7831 protected TableMapper<Organization, com.liferay.portal.model.User> organizationToUserTableMapper;
7832 private static final String _SQL_SELECT_ORGANIZATION = "SELECT organization FROM Organization organization";
7833 private static final String _SQL_SELECT_ORGANIZATION_WHERE = "SELECT organization FROM Organization organization WHERE ";
7834 private static final String _SQL_COUNT_ORGANIZATION = "SELECT COUNT(organization) FROM Organization organization";
7835 private static final String _SQL_COUNT_ORGANIZATION_WHERE = "SELECT COUNT(organization) FROM Organization organization WHERE ";
7836 private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "organization.organizationId";
7837 private static final String _FILTER_SQL_SELECT_ORGANIZATION_WHERE = "SELECT DISTINCT {organization.*} FROM Organization_ organization WHERE ";
7838 private static final String _FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1 =
7839 "SELECT {Organization_.*} FROM (SELECT DISTINCT organization.organizationId FROM Organization_ organization WHERE ";
7840 private static final String _FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2 =
7841 ") TEMP_TABLE INNER JOIN Organization_ ON TEMP_TABLE.organizationId = Organization_.organizationId";
7842 private static final String _FILTER_SQL_COUNT_ORGANIZATION_WHERE = "SELECT COUNT(DISTINCT organization.organizationId) AS COUNT_VALUE FROM Organization_ organization WHERE ";
7843 private static final String _FILTER_ENTITY_ALIAS = "organization";
7844 private static final String _FILTER_ENTITY_TABLE = "Organization_";
7845 private static final String _ORDER_BY_ENTITY_ALIAS = "organization.";
7846 private static final String _ORDER_BY_ENTITY_TABLE = "Organization_.";
7847 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Organization exists with the primary key ";
7848 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Organization exists with the key {";
7849 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
7850 private static Log _log = LogFactoryUtil.getLog(OrganizationPersistenceImpl.class);
7851 private static Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
7852 "uuid", "type"
7853 });
7854 private static Organization _nullOrganization = new OrganizationImpl() {
7855 @Override
7856 public Object clone() {
7857 return this;
7858 }
7859
7860 @Override
7861 public CacheModel<Organization> toCacheModel() {
7862 return _nullOrganizationCacheModel;
7863 }
7864 };
7865
7866 private static CacheModel<Organization> _nullOrganizationCacheModel = new CacheModel<Organization>() {
7867 @Override
7868 public Organization toEntityModel() {
7869 return _nullOrganization;
7870 }
7871 };
7872 }