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