001
014
015 package com.liferay.portal.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
018 import com.liferay.portal.NoSuchOrganizationException;
019 import com.liferay.portal.kernel.annotation.BeanReference;
020 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
021 import com.liferay.portal.kernel.dao.jdbc.MappingSqlQuery;
022 import com.liferay.portal.kernel.dao.jdbc.MappingSqlQueryFactoryUtil;
023 import com.liferay.portal.kernel.dao.jdbc.RowMapper;
024 import com.liferay.portal.kernel.dao.jdbc.SqlUpdate;
025 import com.liferay.portal.kernel.dao.jdbc.SqlUpdateFactoryUtil;
026 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
027 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
028 import com.liferay.portal.kernel.dao.orm.FinderPath;
029 import com.liferay.portal.kernel.dao.orm.Query;
030 import com.liferay.portal.kernel.dao.orm.QueryPos;
031 import com.liferay.portal.kernel.dao.orm.QueryUtil;
032 import com.liferay.portal.kernel.dao.orm.SQLQuery;
033 import com.liferay.portal.kernel.dao.orm.Session;
034 import com.liferay.portal.kernel.exception.SystemException;
035 import com.liferay.portal.kernel.log.Log;
036 import com.liferay.portal.kernel.log.LogFactoryUtil;
037 import com.liferay.portal.kernel.util.GetterUtil;
038 import com.liferay.portal.kernel.util.InstanceFactory;
039 import com.liferay.portal.kernel.util.OrderByComparator;
040 import com.liferay.portal.kernel.util.SetUtil;
041 import com.liferay.portal.kernel.util.StringBundler;
042 import com.liferay.portal.kernel.util.StringPool;
043 import com.liferay.portal.kernel.util.StringUtil;
044 import com.liferay.portal.kernel.util.Validator;
045 import com.liferay.portal.model.ModelListener;
046 import com.liferay.portal.model.Organization;
047 import com.liferay.portal.model.impl.OrganizationImpl;
048 import com.liferay.portal.model.impl.OrganizationModelImpl;
049 import com.liferay.portal.security.permission.InlineSQLHelperUtil;
050 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
051
052 import com.liferay.portlet.asset.service.persistence.AssetEntryPersistence;
053 import com.liferay.portlet.expando.service.persistence.ExpandoValuePersistence;
054
055 import java.io.Serializable;
056
057 import java.util.ArrayList;
058 import java.util.Collections;
059 import java.util.List;
060 import java.util.Set;
061
062
078 public class OrganizationPersistenceImpl extends BasePersistenceImpl<Organization>
079 implements OrganizationPersistence {
080 public static final String FINDER_CLASS_NAME_ENTITY = OrganizationImpl.class.getName();
081 public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
082 ".List";
083 public static final FinderPath FINDER_PATH_FIND_BY_COMPANYID = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
084 OrganizationModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
085 "findByCompanyId",
086 new String[] {
087 Long.class.getName(),
088
089 "java.lang.Integer", "java.lang.Integer",
090 "com.liferay.portal.kernel.util.OrderByComparator"
091 });
092 public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
093 OrganizationModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
094 "countByCompanyId", new String[] { Long.class.getName() });
095 public static final FinderPath FINDER_PATH_FIND_BY_LOCATIONS = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
096 OrganizationModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
097 "findByLocations",
098 new String[] {
099 Long.class.getName(),
100
101 "java.lang.Integer", "java.lang.Integer",
102 "com.liferay.portal.kernel.util.OrderByComparator"
103 });
104 public static final FinderPath FINDER_PATH_COUNT_BY_LOCATIONS = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
105 OrganizationModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
106 "countByLocations", new String[] { Long.class.getName() });
107 public static final FinderPath FINDER_PATH_FIND_BY_C_P = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
108 OrganizationModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
109 "findByC_P",
110 new String[] {
111 Long.class.getName(), Long.class.getName(),
112
113 "java.lang.Integer", "java.lang.Integer",
114 "com.liferay.portal.kernel.util.OrderByComparator"
115 });
116 public static final FinderPath FINDER_PATH_COUNT_BY_C_P = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
117 OrganizationModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
118 "countByC_P",
119 new String[] { Long.class.getName(), Long.class.getName() });
120 public static final FinderPath FINDER_PATH_FETCH_BY_C_N = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
121 OrganizationModelImpl.FINDER_CACHE_ENABLED,
122 FINDER_CLASS_NAME_ENTITY, "fetchByC_N",
123 new String[] { Long.class.getName(), String.class.getName() });
124 public static final FinderPath FINDER_PATH_COUNT_BY_C_N = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
125 OrganizationModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
126 "countByC_N",
127 new String[] { Long.class.getName(), String.class.getName() });
128 public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
129 OrganizationModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
130 "findAll", new String[0]);
131 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
132 OrganizationModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
133 "countAll", new String[0]);
134
135
140 public void cacheResult(Organization organization) {
141 EntityCacheUtil.putResult(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
142 OrganizationImpl.class, organization.getPrimaryKey(), organization);
143
144 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
145 new Object[] {
146 new Long(organization.getCompanyId()),
147
148 organization.getName()
149 }, organization);
150 }
151
152
157 public void cacheResult(List<Organization> organizations) {
158 for (Organization organization : organizations) {
159 if (EntityCacheUtil.getResult(
160 OrganizationModelImpl.ENTITY_CACHE_ENABLED,
161 OrganizationImpl.class, organization.getPrimaryKey(),
162 this) == null) {
163 cacheResult(organization);
164 }
165 }
166 }
167
168
175 public void clearCache() {
176 CacheRegistryUtil.clear(OrganizationImpl.class.getName());
177 EntityCacheUtil.clearCache(OrganizationImpl.class.getName());
178 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
179 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
180 }
181
182
189 public void clearCache(Organization organization) {
190 EntityCacheUtil.removeResult(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
191 OrganizationImpl.class, organization.getPrimaryKey());
192
193 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N,
194 new Object[] {
195 new Long(organization.getCompanyId()),
196
197 organization.getName()
198 });
199 }
200
201
207 public Organization create(long organizationId) {
208 Organization organization = new OrganizationImpl();
209
210 organization.setNew(true);
211 organization.setPrimaryKey(organizationId);
212
213 return organization;
214 }
215
216
224 public Organization remove(Serializable primaryKey)
225 throws NoSuchModelException, SystemException {
226 return remove(((Long)primaryKey).longValue());
227 }
228
229
237 public Organization remove(long organizationId)
238 throws NoSuchOrganizationException, SystemException {
239 Session session = null;
240
241 try {
242 session = openSession();
243
244 Organization organization = (Organization)session.get(OrganizationImpl.class,
245 new Long(organizationId));
246
247 if (organization == null) {
248 if (_log.isWarnEnabled()) {
249 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
250 organizationId);
251 }
252
253 throw new NoSuchOrganizationException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
254 organizationId);
255 }
256
257 return remove(organization);
258 }
259 catch (NoSuchOrganizationException nsee) {
260 throw nsee;
261 }
262 catch (Exception e) {
263 throw processException(e);
264 }
265 finally {
266 closeSession(session);
267 }
268 }
269
270 protected Organization removeImpl(Organization organization)
271 throws SystemException {
272 organization = toUnwrappedModel(organization);
273
274 try {
275 clearGroups.clear(organization.getPrimaryKey());
276 }
277 catch (Exception e) {
278 throw processException(e);
279 }
280 finally {
281 FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_GROUPS_ORGS_NAME);
282 }
283
284 try {
285 clearUsers.clear(organization.getPrimaryKey());
286 }
287 catch (Exception e) {
288 throw processException(e);
289 }
290 finally {
291 FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_USERS_ORGS_NAME);
292 }
293
294 shrinkTree(organization);
295
296 Session session = null;
297
298 try {
299 session = openSession();
300
301 BatchSessionUtil.delete(session, organization);
302 }
303 catch (Exception e) {
304 throw processException(e);
305 }
306 finally {
307 closeSession(session);
308 }
309
310 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
311
312 OrganizationModelImpl organizationModelImpl = (OrganizationModelImpl)organization;
313
314 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N,
315 new Object[] {
316 new Long(organizationModelImpl.getCompanyId()),
317
318 organizationModelImpl.getName()
319 });
320
321 EntityCacheUtil.removeResult(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
322 OrganizationImpl.class, organization.getPrimaryKey());
323
324 return organization;
325 }
326
327 public Organization updateImpl(
328 com.liferay.portal.model.Organization organization, boolean merge)
329 throws SystemException {
330 organization = toUnwrappedModel(organization);
331
332 boolean isNew = organization.isNew();
333
334 OrganizationModelImpl organizationModelImpl = (OrganizationModelImpl)organization;
335
336 if (isNew) {
337 expandTree(organization);
338 }
339 else {
340 if (organization.getParentOrganizationId() != organizationModelImpl.getOriginalParentOrganizationId()) {
341 shrinkTree(organization);
342 expandTree(organization);
343 }
344 }
345
346 Session session = null;
347
348 try {
349 session = openSession();
350
351 BatchSessionUtil.update(session, organization, merge);
352
353 organization.setNew(false);
354 }
355 catch (Exception e) {
356 throw processException(e);
357 }
358 finally {
359 closeSession(session);
360 }
361
362 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
363
364 EntityCacheUtil.putResult(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
365 OrganizationImpl.class, organization.getPrimaryKey(), organization);
366
367 if (!isNew &&
368 ((organization.getCompanyId() != organizationModelImpl.getOriginalCompanyId()) ||
369 !Validator.equals(organization.getName(),
370 organizationModelImpl.getOriginalName()))) {
371 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N,
372 new Object[] {
373 new Long(organizationModelImpl.getOriginalCompanyId()),
374
375 organizationModelImpl.getOriginalName()
376 });
377 }
378
379 if (isNew ||
380 ((organization.getCompanyId() != organizationModelImpl.getOriginalCompanyId()) ||
381 !Validator.equals(organization.getName(),
382 organizationModelImpl.getOriginalName()))) {
383 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
384 new Object[] {
385 new Long(organization.getCompanyId()),
386
387 organization.getName()
388 }, organization);
389 }
390
391 return organization;
392 }
393
394 protected Organization toUnwrappedModel(Organization organization) {
395 if (organization instanceof OrganizationImpl) {
396 return organization;
397 }
398
399 OrganizationImpl organizationImpl = new OrganizationImpl();
400
401 organizationImpl.setNew(organization.isNew());
402 organizationImpl.setPrimaryKey(organization.getPrimaryKey());
403
404 organizationImpl.setOrganizationId(organization.getOrganizationId());
405 organizationImpl.setCompanyId(organization.getCompanyId());
406 organizationImpl.setParentOrganizationId(organization.getParentOrganizationId());
407 organizationImpl.setLeftOrganizationId(organization.getLeftOrganizationId());
408 organizationImpl.setRightOrganizationId(organization.getRightOrganizationId());
409 organizationImpl.setName(organization.getName());
410 organizationImpl.setType(organization.getType());
411 organizationImpl.setRecursable(organization.isRecursable());
412 organizationImpl.setRegionId(organization.getRegionId());
413 organizationImpl.setCountryId(organization.getCountryId());
414 organizationImpl.setStatusId(organization.getStatusId());
415 organizationImpl.setComments(organization.getComments());
416
417 return organizationImpl;
418 }
419
420
428 public Organization findByPrimaryKey(Serializable primaryKey)
429 throws NoSuchModelException, SystemException {
430 return findByPrimaryKey(((Long)primaryKey).longValue());
431 }
432
433
441 public Organization findByPrimaryKey(long organizationId)
442 throws NoSuchOrganizationException, SystemException {
443 Organization organization = fetchByPrimaryKey(organizationId);
444
445 if (organization == null) {
446 if (_log.isWarnEnabled()) {
447 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + organizationId);
448 }
449
450 throw new NoSuchOrganizationException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
451 organizationId);
452 }
453
454 return organization;
455 }
456
457
464 public Organization fetchByPrimaryKey(Serializable primaryKey)
465 throws SystemException {
466 return fetchByPrimaryKey(((Long)primaryKey).longValue());
467 }
468
469
476 public Organization fetchByPrimaryKey(long organizationId)
477 throws SystemException {
478 Organization organization = (Organization)EntityCacheUtil.getResult(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
479 OrganizationImpl.class, organizationId, this);
480
481 if (organization == null) {
482 Session session = null;
483
484 try {
485 session = openSession();
486
487 organization = (Organization)session.get(OrganizationImpl.class,
488 new Long(organizationId));
489 }
490 catch (Exception e) {
491 throw processException(e);
492 }
493 finally {
494 if (organization != null) {
495 cacheResult(organization);
496 }
497
498 closeSession(session);
499 }
500 }
501
502 return organization;
503 }
504
505
512 public List<Organization> findByCompanyId(long companyId)
513 throws SystemException {
514 return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
515 null);
516 }
517
518
531 public List<Organization> findByCompanyId(long companyId, int start, int end)
532 throws SystemException {
533 return findByCompanyId(companyId, start, end, null);
534 }
535
536
550 public List<Organization> findByCompanyId(long companyId, int start,
551 int end, OrderByComparator orderByComparator) throws SystemException {
552 Object[] finderArgs = new Object[] {
553 companyId,
554
555 String.valueOf(start), String.valueOf(end),
556 String.valueOf(orderByComparator)
557 };
558
559 List<Organization> list = (List<Organization>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_COMPANYID,
560 finderArgs, this);
561
562 if (list == null) {
563 StringBundler query = null;
564
565 if (orderByComparator != null) {
566 query = new StringBundler(3 +
567 (orderByComparator.getOrderByFields().length * 3));
568 }
569 else {
570 query = new StringBundler(3);
571 }
572
573 query.append(_SQL_SELECT_ORGANIZATION_WHERE);
574
575 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
576
577 if (orderByComparator != null) {
578 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
579 orderByComparator);
580 }
581
582 else {
583 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
584 }
585
586 String sql = query.toString();
587
588 Session session = null;
589
590 try {
591 session = openSession();
592
593 Query q = session.createQuery(sql);
594
595 QueryPos qPos = QueryPos.getInstance(q);
596
597 qPos.add(companyId);
598
599 list = (List<Organization>)QueryUtil.list(q, getDialect(),
600 start, end);
601 }
602 catch (Exception e) {
603 throw processException(e);
604 }
605 finally {
606 if (list == null) {
607 FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_COMPANYID,
608 finderArgs);
609 }
610 else {
611 cacheResult(list);
612
613 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_COMPANYID,
614 finderArgs, list);
615 }
616
617 closeSession(session);
618 }
619 }
620
621 return list;
622 }
623
624
637 public Organization findByCompanyId_First(long companyId,
638 OrderByComparator orderByComparator)
639 throws NoSuchOrganizationException, SystemException {
640 List<Organization> list = findByCompanyId(companyId, 0, 1,
641 orderByComparator);
642
643 if (list.isEmpty()) {
644 StringBundler msg = new StringBundler(4);
645
646 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
647
648 msg.append("companyId=");
649 msg.append(companyId);
650
651 msg.append(StringPool.CLOSE_CURLY_BRACE);
652
653 throw new NoSuchOrganizationException(msg.toString());
654 }
655 else {
656 return list.get(0);
657 }
658 }
659
660
673 public Organization findByCompanyId_Last(long companyId,
674 OrderByComparator orderByComparator)
675 throws NoSuchOrganizationException, SystemException {
676 int count = countByCompanyId(companyId);
677
678 List<Organization> list = findByCompanyId(companyId, count - 1, count,
679 orderByComparator);
680
681 if (list.isEmpty()) {
682 StringBundler msg = new StringBundler(4);
683
684 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
685
686 msg.append("companyId=");
687 msg.append(companyId);
688
689 msg.append(StringPool.CLOSE_CURLY_BRACE);
690
691 throw new NoSuchOrganizationException(msg.toString());
692 }
693 else {
694 return list.get(0);
695 }
696 }
697
698
712 public Organization[] findByCompanyId_PrevAndNext(long organizationId,
713 long companyId, OrderByComparator orderByComparator)
714 throws NoSuchOrganizationException, SystemException {
715 Organization organization = findByPrimaryKey(organizationId);
716
717 Session session = null;
718
719 try {
720 session = openSession();
721
722 Organization[] array = new OrganizationImpl[3];
723
724 array[0] = getByCompanyId_PrevAndNext(session, organization,
725 companyId, orderByComparator, true);
726
727 array[1] = organization;
728
729 array[2] = getByCompanyId_PrevAndNext(session, organization,
730 companyId, orderByComparator, false);
731
732 return array;
733 }
734 catch (Exception e) {
735 throw processException(e);
736 }
737 finally {
738 closeSession(session);
739 }
740 }
741
742 protected Organization getByCompanyId_PrevAndNext(Session session,
743 Organization organization, long companyId,
744 OrderByComparator orderByComparator, boolean previous) {
745 StringBundler query = null;
746
747 if (orderByComparator != null) {
748 query = new StringBundler(6 +
749 (orderByComparator.getOrderByFields().length * 6));
750 }
751 else {
752 query = new StringBundler(3);
753 }
754
755 query.append(_SQL_SELECT_ORGANIZATION_WHERE);
756
757 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
758
759 if (orderByComparator != null) {
760 String[] orderByFields = orderByComparator.getOrderByFields();
761
762 if (orderByFields.length > 0) {
763 query.append(WHERE_AND);
764 }
765
766 for (int i = 0; i < orderByFields.length; i++) {
767 query.append(_ORDER_BY_ENTITY_ALIAS);
768 query.append(orderByFields[i]);
769
770 if ((i + 1) < orderByFields.length) {
771 if (orderByComparator.isAscending() ^ previous) {
772 query.append(WHERE_GREATER_THAN_HAS_NEXT);
773 }
774 else {
775 query.append(WHERE_LESSER_THAN_HAS_NEXT);
776 }
777 }
778 else {
779 if (orderByComparator.isAscending() ^ previous) {
780 query.append(WHERE_GREATER_THAN);
781 }
782 else {
783 query.append(WHERE_LESSER_THAN);
784 }
785 }
786 }
787
788 query.append(ORDER_BY_CLAUSE);
789
790 for (int i = 0; i < orderByFields.length; i++) {
791 query.append(_ORDER_BY_ENTITY_ALIAS);
792 query.append(orderByFields[i]);
793
794 if ((i + 1) < orderByFields.length) {
795 if (orderByComparator.isAscending() ^ previous) {
796 query.append(ORDER_BY_ASC_HAS_NEXT);
797 }
798 else {
799 query.append(ORDER_BY_DESC_HAS_NEXT);
800 }
801 }
802 else {
803 if (orderByComparator.isAscending() ^ previous) {
804 query.append(ORDER_BY_ASC);
805 }
806 else {
807 query.append(ORDER_BY_DESC);
808 }
809 }
810 }
811 }
812
813 else {
814 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
815 }
816
817 String sql = query.toString();
818
819 Query q = session.createQuery(sql);
820
821 q.setFirstResult(0);
822 q.setMaxResults(2);
823
824 QueryPos qPos = QueryPos.getInstance(q);
825
826 qPos.add(companyId);
827
828 if (orderByComparator != null) {
829 Object[] values = orderByComparator.getOrderByValues(organization);
830
831 for (Object value : values) {
832 qPos.add(value);
833 }
834 }
835
836 List<Organization> list = q.list();
837
838 if (list.size() == 2) {
839 return list.get(1);
840 }
841 else {
842 return null;
843 }
844 }
845
846
853 public List<Organization> filterFindByCompanyId(long companyId)
854 throws SystemException {
855 return filterFindByCompanyId(companyId, QueryUtil.ALL_POS,
856 QueryUtil.ALL_POS, null);
857 }
858
859
872 public List<Organization> filterFindByCompanyId(long companyId, int start,
873 int end) throws SystemException {
874 return filterFindByCompanyId(companyId, start, end, null);
875 }
876
877
891 public List<Organization> filterFindByCompanyId(long companyId, int start,
892 int end, OrderByComparator orderByComparator) throws SystemException {
893 if (!InlineSQLHelperUtil.isEnabled()) {
894 return findByCompanyId(companyId, start, end, orderByComparator);
895 }
896
897 StringBundler query = null;
898
899 if (orderByComparator != null) {
900 query = new StringBundler(3 +
901 (orderByComparator.getOrderByFields().length * 3));
902 }
903 else {
904 query = new StringBundler(3);
905 }
906
907 if (getDB().isSupportsInlineDistinct()) {
908 query.append(_FILTER_SQL_SELECT_ORGANIZATION_WHERE);
909 }
910 else {
911 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1);
912 }
913
914 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
915
916 if (!getDB().isSupportsInlineDistinct()) {
917 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2);
918 }
919
920 if (orderByComparator != null) {
921 if (getDB().isSupportsInlineDistinct()) {
922 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
923 orderByComparator);
924 }
925 else {
926 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
927 orderByComparator);
928 }
929 }
930
931 else {
932 if (getDB().isSupportsInlineDistinct()) {
933 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
934 }
935 else {
936 query.append(OrganizationModelImpl.ORDER_BY_SQL);
937 }
938 }
939
940 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
941 Organization.class.getName(), _FILTER_COLUMN_PK,
942 _FILTER_COLUMN_USERID);
943
944 Session session = null;
945
946 try {
947 session = openSession();
948
949 SQLQuery q = session.createSQLQuery(sql);
950
951 if (getDB().isSupportsInlineDistinct()) {
952 q.addEntity(_FILTER_ENTITY_ALIAS, OrganizationImpl.class);
953 }
954 else {
955 q.addEntity(_FILTER_ENTITY_TABLE, OrganizationImpl.class);
956 }
957
958 QueryPos qPos = QueryPos.getInstance(q);
959
960 qPos.add(companyId);
961
962 return (List<Organization>)QueryUtil.list(q, getDialect(), start,
963 end);
964 }
965 catch (Exception e) {
966 throw processException(e);
967 }
968 finally {
969 closeSession(session);
970 }
971 }
972
973
980 public List<Organization> findByLocations(long companyId)
981 throws SystemException {
982 return findByLocations(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
983 null);
984 }
985
986
999 public List<Organization> findByLocations(long companyId, int start, int end)
1000 throws SystemException {
1001 return findByLocations(companyId, start, end, null);
1002 }
1003
1004
1018 public List<Organization> findByLocations(long companyId, int start,
1019 int end, OrderByComparator orderByComparator) throws SystemException {
1020 Object[] finderArgs = new Object[] {
1021 companyId,
1022
1023 String.valueOf(start), String.valueOf(end),
1024 String.valueOf(orderByComparator)
1025 };
1026
1027 List<Organization> list = (List<Organization>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_LOCATIONS,
1028 finderArgs, this);
1029
1030 if (list == null) {
1031 StringBundler query = null;
1032
1033 if (orderByComparator != null) {
1034 query = new StringBundler(3 +
1035 (orderByComparator.getOrderByFields().length * 3));
1036 }
1037 else {
1038 query = new StringBundler(3);
1039 }
1040
1041 query.append(_SQL_SELECT_ORGANIZATION_WHERE);
1042
1043 query.append(_FINDER_COLUMN_LOCATIONS_COMPANYID_2);
1044
1045 if (orderByComparator != null) {
1046 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1047 orderByComparator);
1048 }
1049
1050 else {
1051 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
1052 }
1053
1054 String sql = query.toString();
1055
1056 Session session = null;
1057
1058 try {
1059 session = openSession();
1060
1061 Query q = session.createQuery(sql);
1062
1063 QueryPos qPos = QueryPos.getInstance(q);
1064
1065 qPos.add(companyId);
1066
1067 list = (List<Organization>)QueryUtil.list(q, getDialect(),
1068 start, end);
1069 }
1070 catch (Exception e) {
1071 throw processException(e);
1072 }
1073 finally {
1074 if (list == null) {
1075 FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_LOCATIONS,
1076 finderArgs);
1077 }
1078 else {
1079 cacheResult(list);
1080
1081 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_LOCATIONS,
1082 finderArgs, list);
1083 }
1084
1085 closeSession(session);
1086 }
1087 }
1088
1089 return list;
1090 }
1091
1092
1105 public Organization findByLocations_First(long companyId,
1106 OrderByComparator orderByComparator)
1107 throws NoSuchOrganizationException, SystemException {
1108 List<Organization> list = findByLocations(companyId, 0, 1,
1109 orderByComparator);
1110
1111 if (list.isEmpty()) {
1112 StringBundler msg = new StringBundler(4);
1113
1114 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1115
1116 msg.append("companyId=");
1117 msg.append(companyId);
1118
1119 msg.append(StringPool.CLOSE_CURLY_BRACE);
1120
1121 throw new NoSuchOrganizationException(msg.toString());
1122 }
1123 else {
1124 return list.get(0);
1125 }
1126 }
1127
1128
1141 public Organization findByLocations_Last(long companyId,
1142 OrderByComparator orderByComparator)
1143 throws NoSuchOrganizationException, SystemException {
1144 int count = countByLocations(companyId);
1145
1146 List<Organization> list = findByLocations(companyId, count - 1, count,
1147 orderByComparator);
1148
1149 if (list.isEmpty()) {
1150 StringBundler msg = new StringBundler(4);
1151
1152 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1153
1154 msg.append("companyId=");
1155 msg.append(companyId);
1156
1157 msg.append(StringPool.CLOSE_CURLY_BRACE);
1158
1159 throw new NoSuchOrganizationException(msg.toString());
1160 }
1161 else {
1162 return list.get(0);
1163 }
1164 }
1165
1166
1180 public Organization[] findByLocations_PrevAndNext(long organizationId,
1181 long companyId, OrderByComparator orderByComparator)
1182 throws NoSuchOrganizationException, SystemException {
1183 Organization organization = findByPrimaryKey(organizationId);
1184
1185 Session session = null;
1186
1187 try {
1188 session = openSession();
1189
1190 Organization[] array = new OrganizationImpl[3];
1191
1192 array[0] = getByLocations_PrevAndNext(session, organization,
1193 companyId, orderByComparator, true);
1194
1195 array[1] = organization;
1196
1197 array[2] = getByLocations_PrevAndNext(session, organization,
1198 companyId, orderByComparator, false);
1199
1200 return array;
1201 }
1202 catch (Exception e) {
1203 throw processException(e);
1204 }
1205 finally {
1206 closeSession(session);
1207 }
1208 }
1209
1210 protected Organization getByLocations_PrevAndNext(Session session,
1211 Organization organization, long companyId,
1212 OrderByComparator orderByComparator, boolean previous) {
1213 StringBundler query = null;
1214
1215 if (orderByComparator != null) {
1216 query = new StringBundler(6 +
1217 (orderByComparator.getOrderByFields().length * 6));
1218 }
1219 else {
1220 query = new StringBundler(3);
1221 }
1222
1223 query.append(_SQL_SELECT_ORGANIZATION_WHERE);
1224
1225 query.append(_FINDER_COLUMN_LOCATIONS_COMPANYID_2);
1226
1227 if (orderByComparator != null) {
1228 String[] orderByFields = orderByComparator.getOrderByFields();
1229
1230 if (orderByFields.length > 0) {
1231 query.append(WHERE_AND);
1232 }
1233
1234 for (int i = 0; i < orderByFields.length; i++) {
1235 query.append(_ORDER_BY_ENTITY_ALIAS);
1236 query.append(orderByFields[i]);
1237
1238 if ((i + 1) < orderByFields.length) {
1239 if (orderByComparator.isAscending() ^ previous) {
1240 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1241 }
1242 else {
1243 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1244 }
1245 }
1246 else {
1247 if (orderByComparator.isAscending() ^ previous) {
1248 query.append(WHERE_GREATER_THAN);
1249 }
1250 else {
1251 query.append(WHERE_LESSER_THAN);
1252 }
1253 }
1254 }
1255
1256 query.append(ORDER_BY_CLAUSE);
1257
1258 for (int i = 0; i < orderByFields.length; i++) {
1259 query.append(_ORDER_BY_ENTITY_ALIAS);
1260 query.append(orderByFields[i]);
1261
1262 if ((i + 1) < orderByFields.length) {
1263 if (orderByComparator.isAscending() ^ previous) {
1264 query.append(ORDER_BY_ASC_HAS_NEXT);
1265 }
1266 else {
1267 query.append(ORDER_BY_DESC_HAS_NEXT);
1268 }
1269 }
1270 else {
1271 if (orderByComparator.isAscending() ^ previous) {
1272 query.append(ORDER_BY_ASC);
1273 }
1274 else {
1275 query.append(ORDER_BY_DESC);
1276 }
1277 }
1278 }
1279 }
1280
1281 else {
1282 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
1283 }
1284
1285 String sql = query.toString();
1286
1287 Query q = session.createQuery(sql);
1288
1289 q.setFirstResult(0);
1290 q.setMaxResults(2);
1291
1292 QueryPos qPos = QueryPos.getInstance(q);
1293
1294 qPos.add(companyId);
1295
1296 if (orderByComparator != null) {
1297 Object[] values = orderByComparator.getOrderByValues(organization);
1298
1299 for (Object value : values) {
1300 qPos.add(value);
1301 }
1302 }
1303
1304 List<Organization> list = q.list();
1305
1306 if (list.size() == 2) {
1307 return list.get(1);
1308 }
1309 else {
1310 return null;
1311 }
1312 }
1313
1314
1321 public List<Organization> filterFindByLocations(long companyId)
1322 throws SystemException {
1323 return filterFindByLocations(companyId, QueryUtil.ALL_POS,
1324 QueryUtil.ALL_POS, null);
1325 }
1326
1327
1340 public List<Organization> filterFindByLocations(long companyId, int start,
1341 int end) throws SystemException {
1342 return filterFindByLocations(companyId, start, end, null);
1343 }
1344
1345
1359 public List<Organization> filterFindByLocations(long companyId, int start,
1360 int end, OrderByComparator orderByComparator) throws SystemException {
1361 if (!InlineSQLHelperUtil.isEnabled()) {
1362 return findByLocations(companyId, start, end, orderByComparator);
1363 }
1364
1365 StringBundler query = null;
1366
1367 if (orderByComparator != null) {
1368 query = new StringBundler(3 +
1369 (orderByComparator.getOrderByFields().length * 3));
1370 }
1371 else {
1372 query = new StringBundler(3);
1373 }
1374
1375 if (getDB().isSupportsInlineDistinct()) {
1376 query.append(_FILTER_SQL_SELECT_ORGANIZATION_WHERE);
1377 }
1378 else {
1379 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1);
1380 }
1381
1382 query.append(_FINDER_COLUMN_LOCATIONS_COMPANYID_2);
1383
1384 if (!getDB().isSupportsInlineDistinct()) {
1385 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2);
1386 }
1387
1388 if (orderByComparator != null) {
1389 if (getDB().isSupportsInlineDistinct()) {
1390 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1391 orderByComparator);
1392 }
1393 else {
1394 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1395 orderByComparator);
1396 }
1397 }
1398
1399 else {
1400 if (getDB().isSupportsInlineDistinct()) {
1401 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
1402 }
1403 else {
1404 query.append(OrganizationModelImpl.ORDER_BY_SQL);
1405 }
1406 }
1407
1408 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1409 Organization.class.getName(), _FILTER_COLUMN_PK,
1410 _FILTER_COLUMN_USERID);
1411
1412 Session session = null;
1413
1414 try {
1415 session = openSession();
1416
1417 SQLQuery q = session.createSQLQuery(sql);
1418
1419 if (getDB().isSupportsInlineDistinct()) {
1420 q.addEntity(_FILTER_ENTITY_ALIAS, OrganizationImpl.class);
1421 }
1422 else {
1423 q.addEntity(_FILTER_ENTITY_TABLE, OrganizationImpl.class);
1424 }
1425
1426 QueryPos qPos = QueryPos.getInstance(q);
1427
1428 qPos.add(companyId);
1429
1430 return (List<Organization>)QueryUtil.list(q, getDialect(), start,
1431 end);
1432 }
1433 catch (Exception e) {
1434 throw processException(e);
1435 }
1436 finally {
1437 closeSession(session);
1438 }
1439 }
1440
1441
1449 public List<Organization> findByC_P(long companyId,
1450 long parentOrganizationId) throws SystemException {
1451 return findByC_P(companyId, parentOrganizationId, QueryUtil.ALL_POS,
1452 QueryUtil.ALL_POS, null);
1453 }
1454
1455
1469 public List<Organization> findByC_P(long companyId,
1470 long parentOrganizationId, int start, int end)
1471 throws SystemException {
1472 return findByC_P(companyId, parentOrganizationId, start, end, null);
1473 }
1474
1475
1490 public List<Organization> findByC_P(long companyId,
1491 long parentOrganizationId, int start, int end,
1492 OrderByComparator orderByComparator) throws SystemException {
1493 Object[] finderArgs = new Object[] {
1494 companyId, parentOrganizationId,
1495
1496 String.valueOf(start), String.valueOf(end),
1497 String.valueOf(orderByComparator)
1498 };
1499
1500 List<Organization> list = (List<Organization>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_P,
1501 finderArgs, this);
1502
1503 if (list == null) {
1504 StringBundler query = null;
1505
1506 if (orderByComparator != null) {
1507 query = new StringBundler(4 +
1508 (orderByComparator.getOrderByFields().length * 3));
1509 }
1510 else {
1511 query = new StringBundler(4);
1512 }
1513
1514 query.append(_SQL_SELECT_ORGANIZATION_WHERE);
1515
1516 query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
1517
1518 query.append(_FINDER_COLUMN_C_P_PARENTORGANIZATIONID_2);
1519
1520 if (orderByComparator != null) {
1521 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1522 orderByComparator);
1523 }
1524
1525 else {
1526 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
1527 }
1528
1529 String sql = query.toString();
1530
1531 Session session = null;
1532
1533 try {
1534 session = openSession();
1535
1536 Query q = session.createQuery(sql);
1537
1538 QueryPos qPos = QueryPos.getInstance(q);
1539
1540 qPos.add(companyId);
1541
1542 qPos.add(parentOrganizationId);
1543
1544 list = (List<Organization>)QueryUtil.list(q, getDialect(),
1545 start, end);
1546 }
1547 catch (Exception e) {
1548 throw processException(e);
1549 }
1550 finally {
1551 if (list == null) {
1552 FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_C_P,
1553 finderArgs);
1554 }
1555 else {
1556 cacheResult(list);
1557
1558 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_P,
1559 finderArgs, list);
1560 }
1561
1562 closeSession(session);
1563 }
1564 }
1565
1566 return list;
1567 }
1568
1569
1583 public Organization findByC_P_First(long companyId,
1584 long parentOrganizationId, OrderByComparator orderByComparator)
1585 throws NoSuchOrganizationException, SystemException {
1586 List<Organization> list = findByC_P(companyId, parentOrganizationId, 0,
1587 1, orderByComparator);
1588
1589 if (list.isEmpty()) {
1590 StringBundler msg = new StringBundler(6);
1591
1592 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1593
1594 msg.append("companyId=");
1595 msg.append(companyId);
1596
1597 msg.append(", parentOrganizationId=");
1598 msg.append(parentOrganizationId);
1599
1600 msg.append(StringPool.CLOSE_CURLY_BRACE);
1601
1602 throw new NoSuchOrganizationException(msg.toString());
1603 }
1604 else {
1605 return list.get(0);
1606 }
1607 }
1608
1609
1623 public Organization findByC_P_Last(long companyId,
1624 long parentOrganizationId, OrderByComparator orderByComparator)
1625 throws NoSuchOrganizationException, SystemException {
1626 int count = countByC_P(companyId, parentOrganizationId);
1627
1628 List<Organization> list = findByC_P(companyId, parentOrganizationId,
1629 count - 1, count, orderByComparator);
1630
1631 if (list.isEmpty()) {
1632 StringBundler msg = new StringBundler(6);
1633
1634 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1635
1636 msg.append("companyId=");
1637 msg.append(companyId);
1638
1639 msg.append(", parentOrganizationId=");
1640 msg.append(parentOrganizationId);
1641
1642 msg.append(StringPool.CLOSE_CURLY_BRACE);
1643
1644 throw new NoSuchOrganizationException(msg.toString());
1645 }
1646 else {
1647 return list.get(0);
1648 }
1649 }
1650
1651
1666 public Organization[] findByC_P_PrevAndNext(long organizationId,
1667 long companyId, long parentOrganizationId,
1668 OrderByComparator orderByComparator)
1669 throws NoSuchOrganizationException, SystemException {
1670 Organization organization = findByPrimaryKey(organizationId);
1671
1672 Session session = null;
1673
1674 try {
1675 session = openSession();
1676
1677 Organization[] array = new OrganizationImpl[3];
1678
1679 array[0] = getByC_P_PrevAndNext(session, organization, companyId,
1680 parentOrganizationId, orderByComparator, true);
1681
1682 array[1] = organization;
1683
1684 array[2] = getByC_P_PrevAndNext(session, organization, companyId,
1685 parentOrganizationId, orderByComparator, false);
1686
1687 return array;
1688 }
1689 catch (Exception e) {
1690 throw processException(e);
1691 }
1692 finally {
1693 closeSession(session);
1694 }
1695 }
1696
1697 protected Organization getByC_P_PrevAndNext(Session session,
1698 Organization organization, long companyId, long parentOrganizationId,
1699 OrderByComparator orderByComparator, boolean previous) {
1700 StringBundler query = null;
1701
1702 if (orderByComparator != null) {
1703 query = new StringBundler(6 +
1704 (orderByComparator.getOrderByFields().length * 6));
1705 }
1706 else {
1707 query = new StringBundler(3);
1708 }
1709
1710 query.append(_SQL_SELECT_ORGANIZATION_WHERE);
1711
1712 query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
1713
1714 query.append(_FINDER_COLUMN_C_P_PARENTORGANIZATIONID_2);
1715
1716 if (orderByComparator != null) {
1717 String[] orderByFields = orderByComparator.getOrderByFields();
1718
1719 if (orderByFields.length > 0) {
1720 query.append(WHERE_AND);
1721 }
1722
1723 for (int i = 0; i < orderByFields.length; i++) {
1724 query.append(_ORDER_BY_ENTITY_ALIAS);
1725 query.append(orderByFields[i]);
1726
1727 if ((i + 1) < orderByFields.length) {
1728 if (orderByComparator.isAscending() ^ previous) {
1729 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1730 }
1731 else {
1732 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1733 }
1734 }
1735 else {
1736 if (orderByComparator.isAscending() ^ previous) {
1737 query.append(WHERE_GREATER_THAN);
1738 }
1739 else {
1740 query.append(WHERE_LESSER_THAN);
1741 }
1742 }
1743 }
1744
1745 query.append(ORDER_BY_CLAUSE);
1746
1747 for (int i = 0; i < orderByFields.length; i++) {
1748 query.append(_ORDER_BY_ENTITY_ALIAS);
1749 query.append(orderByFields[i]);
1750
1751 if ((i + 1) < orderByFields.length) {
1752 if (orderByComparator.isAscending() ^ previous) {
1753 query.append(ORDER_BY_ASC_HAS_NEXT);
1754 }
1755 else {
1756 query.append(ORDER_BY_DESC_HAS_NEXT);
1757 }
1758 }
1759 else {
1760 if (orderByComparator.isAscending() ^ previous) {
1761 query.append(ORDER_BY_ASC);
1762 }
1763 else {
1764 query.append(ORDER_BY_DESC);
1765 }
1766 }
1767 }
1768 }
1769
1770 else {
1771 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
1772 }
1773
1774 String sql = query.toString();
1775
1776 Query q = session.createQuery(sql);
1777
1778 q.setFirstResult(0);
1779 q.setMaxResults(2);
1780
1781 QueryPos qPos = QueryPos.getInstance(q);
1782
1783 qPos.add(companyId);
1784
1785 qPos.add(parentOrganizationId);
1786
1787 if (orderByComparator != null) {
1788 Object[] values = orderByComparator.getOrderByValues(organization);
1789
1790 for (Object value : values) {
1791 qPos.add(value);
1792 }
1793 }
1794
1795 List<Organization> list = q.list();
1796
1797 if (list.size() == 2) {
1798 return list.get(1);
1799 }
1800 else {
1801 return null;
1802 }
1803 }
1804
1805
1813 public List<Organization> filterFindByC_P(long companyId,
1814 long parentOrganizationId) throws SystemException {
1815 return filterFindByC_P(companyId, parentOrganizationId,
1816 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1817 }
1818
1819
1833 public List<Organization> filterFindByC_P(long companyId,
1834 long parentOrganizationId, int start, int end)
1835 throws SystemException {
1836 return filterFindByC_P(companyId, parentOrganizationId, start, end, null);
1837 }
1838
1839
1854 public List<Organization> filterFindByC_P(long companyId,
1855 long parentOrganizationId, int start, int end,
1856 OrderByComparator orderByComparator) throws SystemException {
1857 if (!InlineSQLHelperUtil.isEnabled()) {
1858 return findByC_P(companyId, parentOrganizationId, start, end,
1859 orderByComparator);
1860 }
1861
1862 StringBundler query = null;
1863
1864 if (orderByComparator != null) {
1865 query = new StringBundler(4 +
1866 (orderByComparator.getOrderByFields().length * 3));
1867 }
1868 else {
1869 query = new StringBundler(4);
1870 }
1871
1872 if (getDB().isSupportsInlineDistinct()) {
1873 query.append(_FILTER_SQL_SELECT_ORGANIZATION_WHERE);
1874 }
1875 else {
1876 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1);
1877 }
1878
1879 query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
1880
1881 query.append(_FINDER_COLUMN_C_P_PARENTORGANIZATIONID_2);
1882
1883 if (!getDB().isSupportsInlineDistinct()) {
1884 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2);
1885 }
1886
1887 if (orderByComparator != null) {
1888 if (getDB().isSupportsInlineDistinct()) {
1889 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1890 orderByComparator);
1891 }
1892 else {
1893 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1894 orderByComparator);
1895 }
1896 }
1897
1898 else {
1899 if (getDB().isSupportsInlineDistinct()) {
1900 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
1901 }
1902 else {
1903 query.append(OrganizationModelImpl.ORDER_BY_SQL);
1904 }
1905 }
1906
1907 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1908 Organization.class.getName(), _FILTER_COLUMN_PK,
1909 _FILTER_COLUMN_USERID);
1910
1911 Session session = null;
1912
1913 try {
1914 session = openSession();
1915
1916 SQLQuery q = session.createSQLQuery(sql);
1917
1918 if (getDB().isSupportsInlineDistinct()) {
1919 q.addEntity(_FILTER_ENTITY_ALIAS, OrganizationImpl.class);
1920 }
1921 else {
1922 q.addEntity(_FILTER_ENTITY_TABLE, OrganizationImpl.class);
1923 }
1924
1925 QueryPos qPos = QueryPos.getInstance(q);
1926
1927 qPos.add(companyId);
1928
1929 qPos.add(parentOrganizationId);
1930
1931 return (List<Organization>)QueryUtil.list(q, getDialect(), start,
1932 end);
1933 }
1934 catch (Exception e) {
1935 throw processException(e);
1936 }
1937 finally {
1938 closeSession(session);
1939 }
1940 }
1941
1942
1951 public Organization findByC_N(long companyId, String name)
1952 throws NoSuchOrganizationException, SystemException {
1953 Organization organization = fetchByC_N(companyId, name);
1954
1955 if (organization == null) {
1956 StringBundler msg = new StringBundler(6);
1957
1958 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1959
1960 msg.append("companyId=");
1961 msg.append(companyId);
1962
1963 msg.append(", name=");
1964 msg.append(name);
1965
1966 msg.append(StringPool.CLOSE_CURLY_BRACE);
1967
1968 if (_log.isWarnEnabled()) {
1969 _log.warn(msg.toString());
1970 }
1971
1972 throw new NoSuchOrganizationException(msg.toString());
1973 }
1974
1975 return organization;
1976 }
1977
1978
1986 public Organization fetchByC_N(long companyId, String name)
1987 throws SystemException {
1988 return fetchByC_N(companyId, name, true);
1989 }
1990
1991
1999 public Organization fetchByC_N(long companyId, String name,
2000 boolean retrieveFromCache) throws SystemException {
2001 Object[] finderArgs = new Object[] { companyId, name };
2002
2003 Object result = null;
2004
2005 if (retrieveFromCache) {
2006 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_N,
2007 finderArgs, this);
2008 }
2009
2010 if (result == null) {
2011 StringBundler query = new StringBundler(4);
2012
2013 query.append(_SQL_SELECT_ORGANIZATION_WHERE);
2014
2015 query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
2016
2017 if (name == null) {
2018 query.append(_FINDER_COLUMN_C_N_NAME_1);
2019 }
2020 else {
2021 if (name.equals(StringPool.BLANK)) {
2022 query.append(_FINDER_COLUMN_C_N_NAME_3);
2023 }
2024 else {
2025 query.append(_FINDER_COLUMN_C_N_NAME_2);
2026 }
2027 }
2028
2029 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
2030
2031 String sql = query.toString();
2032
2033 Session session = null;
2034
2035 try {
2036 session = openSession();
2037
2038 Query q = session.createQuery(sql);
2039
2040 QueryPos qPos = QueryPos.getInstance(q);
2041
2042 qPos.add(companyId);
2043
2044 if (name != null) {
2045 qPos.add(name);
2046 }
2047
2048 List<Organization> list = q.list();
2049
2050 result = list;
2051
2052 Organization organization = null;
2053
2054 if (list.isEmpty()) {
2055 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
2056 finderArgs, list);
2057 }
2058 else {
2059 organization = list.get(0);
2060
2061 cacheResult(organization);
2062
2063 if ((organization.getCompanyId() != companyId) ||
2064 (organization.getName() == null) ||
2065 !organization.getName().equals(name)) {
2066 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
2067 finderArgs, organization);
2068 }
2069 }
2070
2071 return organization;
2072 }
2073 catch (Exception e) {
2074 throw processException(e);
2075 }
2076 finally {
2077 if (result == null) {
2078 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N,
2079 finderArgs);
2080 }
2081
2082 closeSession(session);
2083 }
2084 }
2085 else {
2086 if (result instanceof List<?>) {
2087 return null;
2088 }
2089 else {
2090 return (Organization)result;
2091 }
2092 }
2093 }
2094
2095
2101 public List<Organization> findAll() throws SystemException {
2102 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2103 }
2104
2105
2117 public List<Organization> findAll(int start, int end)
2118 throws SystemException {
2119 return findAll(start, end, null);
2120 }
2121
2122
2135 public List<Organization> findAll(int start, int end,
2136 OrderByComparator orderByComparator) throws SystemException {
2137 Object[] finderArgs = new Object[] {
2138 String.valueOf(start), String.valueOf(end),
2139 String.valueOf(orderByComparator)
2140 };
2141
2142 List<Organization> list = (List<Organization>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
2143 finderArgs, this);
2144
2145 if (list == null) {
2146 StringBundler query = null;
2147 String sql = null;
2148
2149 if (orderByComparator != null) {
2150 query = new StringBundler(2 +
2151 (orderByComparator.getOrderByFields().length * 3));
2152
2153 query.append(_SQL_SELECT_ORGANIZATION);
2154
2155 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2156 orderByComparator);
2157
2158 sql = query.toString();
2159 }
2160 else {
2161 sql = _SQL_SELECT_ORGANIZATION.concat(OrganizationModelImpl.ORDER_BY_JPQL);
2162 }
2163
2164 Session session = null;
2165
2166 try {
2167 session = openSession();
2168
2169 Query q = session.createQuery(sql);
2170
2171 if (orderByComparator == null) {
2172 list = (List<Organization>)QueryUtil.list(q, getDialect(),
2173 start, end, false);
2174
2175 Collections.sort(list);
2176 }
2177 else {
2178 list = (List<Organization>)QueryUtil.list(q, getDialect(),
2179 start, end);
2180 }
2181 }
2182 catch (Exception e) {
2183 throw processException(e);
2184 }
2185 finally {
2186 if (list == null) {
2187 FinderCacheUtil.removeResult(FINDER_PATH_FIND_ALL,
2188 finderArgs);
2189 }
2190 else {
2191 cacheResult(list);
2192
2193 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs,
2194 list);
2195 }
2196
2197 closeSession(session);
2198 }
2199 }
2200
2201 return list;
2202 }
2203
2204
2210 public void removeByCompanyId(long companyId) throws SystemException {
2211 for (Organization organization : findByCompanyId(companyId)) {
2212 remove(organization);
2213 }
2214 }
2215
2216
2222 public void removeByLocations(long companyId) throws SystemException {
2223 for (Organization organization : findByLocations(companyId)) {
2224 remove(organization);
2225 }
2226 }
2227
2228
2235 public void removeByC_P(long companyId, long parentOrganizationId)
2236 throws SystemException {
2237 for (Organization organization : findByC_P(companyId,
2238 parentOrganizationId)) {
2239 remove(organization);
2240 }
2241 }
2242
2243
2250 public void removeByC_N(long companyId, String name)
2251 throws NoSuchOrganizationException, SystemException {
2252 Organization organization = findByC_N(companyId, name);
2253
2254 remove(organization);
2255 }
2256
2257
2262 public void removeAll() throws SystemException {
2263 for (Organization organization : findAll()) {
2264 remove(organization);
2265 }
2266 }
2267
2268
2275 public int countByCompanyId(long companyId) throws SystemException {
2276 Object[] finderArgs = new Object[] { companyId };
2277
2278 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
2279 finderArgs, this);
2280
2281 if (count == null) {
2282 StringBundler query = new StringBundler(2);
2283
2284 query.append(_SQL_COUNT_ORGANIZATION_WHERE);
2285
2286 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2287
2288 String sql = query.toString();
2289
2290 Session session = null;
2291
2292 try {
2293 session = openSession();
2294
2295 Query q = session.createQuery(sql);
2296
2297 QueryPos qPos = QueryPos.getInstance(q);
2298
2299 qPos.add(companyId);
2300
2301 count = (Long)q.uniqueResult();
2302 }
2303 catch (Exception e) {
2304 throw processException(e);
2305 }
2306 finally {
2307 if (count == null) {
2308 count = Long.valueOf(0);
2309 }
2310
2311 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
2312 finderArgs, count);
2313
2314 closeSession(session);
2315 }
2316 }
2317
2318 return count.intValue();
2319 }
2320
2321
2328 public int filterCountByCompanyId(long companyId) throws SystemException {
2329 if (!InlineSQLHelperUtil.isEnabled()) {
2330 return countByCompanyId(companyId);
2331 }
2332
2333 StringBundler query = new StringBundler(2);
2334
2335 query.append(_FILTER_SQL_COUNT_ORGANIZATION_WHERE);
2336
2337 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2338
2339 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2340 Organization.class.getName(), _FILTER_COLUMN_PK,
2341 _FILTER_COLUMN_USERID);
2342
2343 Session session = null;
2344
2345 try {
2346 session = openSession();
2347
2348 SQLQuery q = session.createSQLQuery(sql);
2349
2350 q.addScalar(COUNT_COLUMN_NAME,
2351 com.liferay.portal.kernel.dao.orm.Type.LONG);
2352
2353 QueryPos qPos = QueryPos.getInstance(q);
2354
2355 qPos.add(companyId);
2356
2357 Long count = (Long)q.uniqueResult();
2358
2359 return count.intValue();
2360 }
2361 catch (Exception e) {
2362 throw processException(e);
2363 }
2364 finally {
2365 closeSession(session);
2366 }
2367 }
2368
2369
2376 public int countByLocations(long companyId) throws SystemException {
2377 Object[] finderArgs = new Object[] { companyId };
2378
2379 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_LOCATIONS,
2380 finderArgs, this);
2381
2382 if (count == null) {
2383 StringBundler query = new StringBundler(2);
2384
2385 query.append(_SQL_COUNT_ORGANIZATION_WHERE);
2386
2387 query.append(_FINDER_COLUMN_LOCATIONS_COMPANYID_2);
2388
2389 String sql = query.toString();
2390
2391 Session session = null;
2392
2393 try {
2394 session = openSession();
2395
2396 Query q = session.createQuery(sql);
2397
2398 QueryPos qPos = QueryPos.getInstance(q);
2399
2400 qPos.add(companyId);
2401
2402 count = (Long)q.uniqueResult();
2403 }
2404 catch (Exception e) {
2405 throw processException(e);
2406 }
2407 finally {
2408 if (count == null) {
2409 count = Long.valueOf(0);
2410 }
2411
2412 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_LOCATIONS,
2413 finderArgs, count);
2414
2415 closeSession(session);
2416 }
2417 }
2418
2419 return count.intValue();
2420 }
2421
2422
2429 public int filterCountByLocations(long companyId) throws SystemException {
2430 if (!InlineSQLHelperUtil.isEnabled()) {
2431 return countByLocations(companyId);
2432 }
2433
2434 StringBundler query = new StringBundler(2);
2435
2436 query.append(_FILTER_SQL_COUNT_ORGANIZATION_WHERE);
2437
2438 query.append(_FINDER_COLUMN_LOCATIONS_COMPANYID_2);
2439
2440 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2441 Organization.class.getName(), _FILTER_COLUMN_PK,
2442 _FILTER_COLUMN_USERID);
2443
2444 Session session = null;
2445
2446 try {
2447 session = openSession();
2448
2449 SQLQuery q = session.createSQLQuery(sql);
2450
2451 q.addScalar(COUNT_COLUMN_NAME,
2452 com.liferay.portal.kernel.dao.orm.Type.LONG);
2453
2454 QueryPos qPos = QueryPos.getInstance(q);
2455
2456 qPos.add(companyId);
2457
2458 Long count = (Long)q.uniqueResult();
2459
2460 return count.intValue();
2461 }
2462 catch (Exception e) {
2463 throw processException(e);
2464 }
2465 finally {
2466 closeSession(session);
2467 }
2468 }
2469
2470
2478 public int countByC_P(long companyId, long parentOrganizationId)
2479 throws SystemException {
2480 Object[] finderArgs = new Object[] { companyId, parentOrganizationId };
2481
2482 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_P,
2483 finderArgs, this);
2484
2485 if (count == null) {
2486 StringBundler query = new StringBundler(3);
2487
2488 query.append(_SQL_COUNT_ORGANIZATION_WHERE);
2489
2490 query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
2491
2492 query.append(_FINDER_COLUMN_C_P_PARENTORGANIZATIONID_2);
2493
2494 String sql = query.toString();
2495
2496 Session session = null;
2497
2498 try {
2499 session = openSession();
2500
2501 Query q = session.createQuery(sql);
2502
2503 QueryPos qPos = QueryPos.getInstance(q);
2504
2505 qPos.add(companyId);
2506
2507 qPos.add(parentOrganizationId);
2508
2509 count = (Long)q.uniqueResult();
2510 }
2511 catch (Exception e) {
2512 throw processException(e);
2513 }
2514 finally {
2515 if (count == null) {
2516 count = Long.valueOf(0);
2517 }
2518
2519 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_P, finderArgs,
2520 count);
2521
2522 closeSession(session);
2523 }
2524 }
2525
2526 return count.intValue();
2527 }
2528
2529
2537 public int filterCountByC_P(long companyId, long parentOrganizationId)
2538 throws SystemException {
2539 if (!InlineSQLHelperUtil.isEnabled()) {
2540 return countByC_P(companyId, parentOrganizationId);
2541 }
2542
2543 StringBundler query = new StringBundler(3);
2544
2545 query.append(_FILTER_SQL_COUNT_ORGANIZATION_WHERE);
2546
2547 query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
2548
2549 query.append(_FINDER_COLUMN_C_P_PARENTORGANIZATIONID_2);
2550
2551 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2552 Organization.class.getName(), _FILTER_COLUMN_PK,
2553 _FILTER_COLUMN_USERID);
2554
2555 Session session = null;
2556
2557 try {
2558 session = openSession();
2559
2560 SQLQuery q = session.createSQLQuery(sql);
2561
2562 q.addScalar(COUNT_COLUMN_NAME,
2563 com.liferay.portal.kernel.dao.orm.Type.LONG);
2564
2565 QueryPos qPos = QueryPos.getInstance(q);
2566
2567 qPos.add(companyId);
2568
2569 qPos.add(parentOrganizationId);
2570
2571 Long count = (Long)q.uniqueResult();
2572
2573 return count.intValue();
2574 }
2575 catch (Exception e) {
2576 throw processException(e);
2577 }
2578 finally {
2579 closeSession(session);
2580 }
2581 }
2582
2583
2591 public int countByC_N(long companyId, String name)
2592 throws SystemException {
2593 Object[] finderArgs = new Object[] { companyId, name };
2594
2595 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_N,
2596 finderArgs, this);
2597
2598 if (count == null) {
2599 StringBundler query = new StringBundler(3);
2600
2601 query.append(_SQL_COUNT_ORGANIZATION_WHERE);
2602
2603 query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
2604
2605 if (name == null) {
2606 query.append(_FINDER_COLUMN_C_N_NAME_1);
2607 }
2608 else {
2609 if (name.equals(StringPool.BLANK)) {
2610 query.append(_FINDER_COLUMN_C_N_NAME_3);
2611 }
2612 else {
2613 query.append(_FINDER_COLUMN_C_N_NAME_2);
2614 }
2615 }
2616
2617 String sql = query.toString();
2618
2619 Session session = null;
2620
2621 try {
2622 session = openSession();
2623
2624 Query q = session.createQuery(sql);
2625
2626 QueryPos qPos = QueryPos.getInstance(q);
2627
2628 qPos.add(companyId);
2629
2630 if (name != null) {
2631 qPos.add(name);
2632 }
2633
2634 count = (Long)q.uniqueResult();
2635 }
2636 catch (Exception e) {
2637 throw processException(e);
2638 }
2639 finally {
2640 if (count == null) {
2641 count = Long.valueOf(0);
2642 }
2643
2644 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_N, finderArgs,
2645 count);
2646
2647 closeSession(session);
2648 }
2649 }
2650
2651 return count.intValue();
2652 }
2653
2654
2660 public int countAll() throws SystemException {
2661 Object[] finderArgs = new Object[0];
2662
2663 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2664 finderArgs, this);
2665
2666 if (count == null) {
2667 Session session = null;
2668
2669 try {
2670 session = openSession();
2671
2672 Query q = session.createQuery(_SQL_COUNT_ORGANIZATION);
2673
2674 count = (Long)q.uniqueResult();
2675 }
2676 catch (Exception e) {
2677 throw processException(e);
2678 }
2679 finally {
2680 if (count == null) {
2681 count = Long.valueOf(0);
2682 }
2683
2684 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
2685 count);
2686
2687 closeSession(session);
2688 }
2689 }
2690
2691 return count.intValue();
2692 }
2693
2694
2701 public List<com.liferay.portal.model.Group> getGroups(long pk)
2702 throws SystemException {
2703 return getGroups(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
2704 }
2705
2706
2719 public List<com.liferay.portal.model.Group> getGroups(long pk, int start,
2720 int end) throws SystemException {
2721 return getGroups(pk, start, end, null);
2722 }
2723
2724 public static final FinderPath FINDER_PATH_GET_GROUPS = new FinderPath(com.liferay.portal.model.impl.GroupModelImpl.ENTITY_CACHE_ENABLED,
2725 OrganizationModelImpl.FINDER_CACHE_ENABLED_GROUPS_ORGS,
2726 OrganizationModelImpl.MAPPING_TABLE_GROUPS_ORGS_NAME, "getGroups",
2727 new String[] {
2728 Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
2729 "com.liferay.portal.kernel.util.OrderByComparator"
2730 });
2731
2732
2746 public List<com.liferay.portal.model.Group> getGroups(long pk, int start,
2747 int end, OrderByComparator orderByComparator) throws SystemException {
2748 Object[] finderArgs = new Object[] {
2749 pk, String.valueOf(start), String.valueOf(end),
2750 String.valueOf(orderByComparator)
2751 };
2752
2753 List<com.liferay.portal.model.Group> list = (List<com.liferay.portal.model.Group>)FinderCacheUtil.getResult(FINDER_PATH_GET_GROUPS,
2754 finderArgs, this);
2755
2756 if (list == null) {
2757 Session session = null;
2758
2759 try {
2760 session = openSession();
2761
2762 String sql = null;
2763
2764 if (orderByComparator != null) {
2765 sql = _SQL_GETGROUPS.concat(ORDER_BY_CLAUSE)
2766 .concat(orderByComparator.getOrderBy());
2767 }
2768 else {
2769 sql = _SQL_GETGROUPS.concat(com.liferay.portal.model.impl.GroupModelImpl.ORDER_BY_SQL);
2770 }
2771
2772 SQLQuery q = session.createSQLQuery(sql);
2773
2774 q.addEntity("Group_",
2775 com.liferay.portal.model.impl.GroupImpl.class);
2776
2777 QueryPos qPos = QueryPos.getInstance(q);
2778
2779 qPos.add(pk);
2780
2781 list = (List<com.liferay.portal.model.Group>)QueryUtil.list(q,
2782 getDialect(), start, end);
2783 }
2784 catch (Exception e) {
2785 throw processException(e);
2786 }
2787 finally {
2788 if (list == null) {
2789 FinderCacheUtil.removeResult(FINDER_PATH_GET_GROUPS,
2790 finderArgs);
2791 }
2792 else {
2793 groupPersistence.cacheResult(list);
2794
2795 FinderCacheUtil.putResult(FINDER_PATH_GET_GROUPS,
2796 finderArgs, list);
2797 }
2798
2799 closeSession(session);
2800 }
2801 }
2802
2803 return list;
2804 }
2805
2806 public static final FinderPath FINDER_PATH_GET_GROUPS_SIZE = new FinderPath(com.liferay.portal.model.impl.GroupModelImpl.ENTITY_CACHE_ENABLED,
2807 OrganizationModelImpl.FINDER_CACHE_ENABLED_GROUPS_ORGS,
2808 OrganizationModelImpl.MAPPING_TABLE_GROUPS_ORGS_NAME,
2809 "getGroupsSize", new String[] { Long.class.getName() });
2810
2811
2818 public int getGroupsSize(long pk) throws SystemException {
2819 Object[] finderArgs = new Object[] { pk };
2820
2821 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_GROUPS_SIZE,
2822 finderArgs, this);
2823
2824 if (count == null) {
2825 Session session = null;
2826
2827 try {
2828 session = openSession();
2829
2830 SQLQuery q = session.createSQLQuery(_SQL_GETGROUPSSIZE);
2831
2832 q.addScalar(COUNT_COLUMN_NAME,
2833 com.liferay.portal.kernel.dao.orm.Type.LONG);
2834
2835 QueryPos qPos = QueryPos.getInstance(q);
2836
2837 qPos.add(pk);
2838
2839 count = (Long)q.uniqueResult();
2840 }
2841 catch (Exception e) {
2842 throw processException(e);
2843 }
2844 finally {
2845 if (count == null) {
2846 count = Long.valueOf(0);
2847 }
2848
2849 FinderCacheUtil.putResult(FINDER_PATH_GET_GROUPS_SIZE,
2850 finderArgs, count);
2851
2852 closeSession(session);
2853 }
2854 }
2855
2856 return count.intValue();
2857 }
2858
2859 public static final FinderPath FINDER_PATH_CONTAINS_GROUP = new FinderPath(com.liferay.portal.model.impl.GroupModelImpl.ENTITY_CACHE_ENABLED,
2860 OrganizationModelImpl.FINDER_CACHE_ENABLED_GROUPS_ORGS,
2861 OrganizationModelImpl.MAPPING_TABLE_GROUPS_ORGS_NAME,
2862 "containsGroup",
2863 new String[] { Long.class.getName(), Long.class.getName() });
2864
2865
2873 public boolean containsGroup(long pk, long groupPK)
2874 throws SystemException {
2875 Object[] finderArgs = new Object[] { pk, groupPK };
2876
2877 Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_GROUP,
2878 finderArgs, this);
2879
2880 if (value == null) {
2881 try {
2882 value = Boolean.valueOf(containsGroup.contains(pk, groupPK));
2883 }
2884 catch (Exception e) {
2885 throw processException(e);
2886 }
2887 finally {
2888 if (value == null) {
2889 value = Boolean.FALSE;
2890 }
2891
2892 FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_GROUP,
2893 finderArgs, value);
2894 }
2895 }
2896
2897 return value.booleanValue();
2898 }
2899
2900
2907 public boolean containsGroups(long pk) throws SystemException {
2908 if (getGroupsSize(pk) > 0) {
2909 return true;
2910 }
2911 else {
2912 return false;
2913 }
2914 }
2915
2916
2923 public void addGroup(long pk, long groupPK) throws SystemException {
2924 try {
2925 addGroup.add(pk, groupPK);
2926 }
2927 catch (Exception e) {
2928 throw processException(e);
2929 }
2930 finally {
2931 FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_GROUPS_ORGS_NAME);
2932 }
2933 }
2934
2935
2942 public void addGroup(long pk, com.liferay.portal.model.Group group)
2943 throws SystemException {
2944 try {
2945 addGroup.add(pk, group.getPrimaryKey());
2946 }
2947 catch (Exception e) {
2948 throw processException(e);
2949 }
2950 finally {
2951 FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_GROUPS_ORGS_NAME);
2952 }
2953 }
2954
2955
2962 public void addGroups(long pk, long[] groupPKs) throws SystemException {
2963 try {
2964 for (long groupPK : groupPKs) {
2965 addGroup.add(pk, groupPK);
2966 }
2967 }
2968 catch (Exception e) {
2969 throw processException(e);
2970 }
2971 finally {
2972 FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_GROUPS_ORGS_NAME);
2973 }
2974 }
2975
2976
2983 public void addGroups(long pk, List<com.liferay.portal.model.Group> groups)
2984 throws SystemException {
2985 try {
2986 for (com.liferay.portal.model.Group group : groups) {
2987 addGroup.add(pk, group.getPrimaryKey());
2988 }
2989 }
2990 catch (Exception e) {
2991 throw processException(e);
2992 }
2993 finally {
2994 FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_GROUPS_ORGS_NAME);
2995 }
2996 }
2997
2998
3004 public void clearGroups(long pk) throws SystemException {
3005 try {
3006 clearGroups.clear(pk);
3007 }
3008 catch (Exception e) {
3009 throw processException(e);
3010 }
3011 finally {
3012 FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_GROUPS_ORGS_NAME);
3013 }
3014 }
3015
3016
3023 public void removeGroup(long pk, long groupPK) throws SystemException {
3024 try {
3025 removeGroup.remove(pk, groupPK);
3026 }
3027 catch (Exception e) {
3028 throw processException(e);
3029 }
3030 finally {
3031 FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_GROUPS_ORGS_NAME);
3032 }
3033 }
3034
3035
3042 public void removeGroup(long pk, com.liferay.portal.model.Group group)
3043 throws SystemException {
3044 try {
3045 removeGroup.remove(pk, group.getPrimaryKey());
3046 }
3047 catch (Exception e) {
3048 throw processException(e);
3049 }
3050 finally {
3051 FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_GROUPS_ORGS_NAME);
3052 }
3053 }
3054
3055
3062 public void removeGroups(long pk, long[] groupPKs)
3063 throws SystemException {
3064 try {
3065 for (long groupPK : groupPKs) {
3066 removeGroup.remove(pk, groupPK);
3067 }
3068 }
3069 catch (Exception e) {
3070 throw processException(e);
3071 }
3072 finally {
3073 FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_GROUPS_ORGS_NAME);
3074 }
3075 }
3076
3077
3084 public void removeGroups(long pk,
3085 List<com.liferay.portal.model.Group> groups) throws SystemException {
3086 try {
3087 for (com.liferay.portal.model.Group group : groups) {
3088 removeGroup.remove(pk, group.getPrimaryKey());
3089 }
3090 }
3091 catch (Exception e) {
3092 throw processException(e);
3093 }
3094 finally {
3095 FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_GROUPS_ORGS_NAME);
3096 }
3097 }
3098
3099
3106 public void setGroups(long pk, long[] groupPKs) throws SystemException {
3107 try {
3108 Set<Long> groupPKSet = SetUtil.fromArray(groupPKs);
3109
3110 List<com.liferay.portal.model.Group> groups = getGroups(pk);
3111
3112 for (com.liferay.portal.model.Group group : groups) {
3113 if (!groupPKSet.remove(group.getPrimaryKey())) {
3114 removeGroup.remove(pk, group.getPrimaryKey());
3115 }
3116 }
3117
3118 for (Long groupPK : groupPKSet) {
3119 addGroup.add(pk, groupPK);
3120 }
3121 }
3122 catch (Exception e) {
3123 throw processException(e);
3124 }
3125 finally {
3126 FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_GROUPS_ORGS_NAME);
3127 }
3128 }
3129
3130
3137 public void setGroups(long pk, List<com.liferay.portal.model.Group> groups)
3138 throws SystemException {
3139 try {
3140 long[] groupPKs = new long[groups.size()];
3141
3142 for (int i = 0; i < groups.size(); i++) {
3143 com.liferay.portal.model.Group group = groups.get(i);
3144
3145 groupPKs[i] = group.getPrimaryKey();
3146 }
3147
3148 setGroups(pk, groupPKs);
3149 }
3150 catch (Exception e) {
3151 throw processException(e);
3152 }
3153 finally {
3154 FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_GROUPS_ORGS_NAME);
3155 }
3156 }
3157
3158
3165 public List<com.liferay.portal.model.User> getUsers(long pk)
3166 throws SystemException {
3167 return getUsers(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
3168 }
3169
3170
3183 public List<com.liferay.portal.model.User> getUsers(long pk, int start,
3184 int end) throws SystemException {
3185 return getUsers(pk, start, end, null);
3186 }
3187
3188 public static final FinderPath FINDER_PATH_GET_USERS = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
3189 OrganizationModelImpl.FINDER_CACHE_ENABLED_USERS_ORGS,
3190 OrganizationModelImpl.MAPPING_TABLE_USERS_ORGS_NAME, "getUsers",
3191 new String[] {
3192 Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
3193 "com.liferay.portal.kernel.util.OrderByComparator"
3194 });
3195
3196
3210 public List<com.liferay.portal.model.User> getUsers(long pk, int start,
3211 int end, OrderByComparator orderByComparator) throws SystemException {
3212 Object[] finderArgs = new Object[] {
3213 pk, String.valueOf(start), String.valueOf(end),
3214 String.valueOf(orderByComparator)
3215 };
3216
3217 List<com.liferay.portal.model.User> list = (List<com.liferay.portal.model.User>)FinderCacheUtil.getResult(FINDER_PATH_GET_USERS,
3218 finderArgs, this);
3219
3220 if (list == null) {
3221 Session session = null;
3222
3223 try {
3224 session = openSession();
3225
3226 String sql = null;
3227
3228 if (orderByComparator != null) {
3229 sql = _SQL_GETUSERS.concat(ORDER_BY_CLAUSE)
3230 .concat(orderByComparator.getOrderBy());
3231 }
3232 else {
3233 sql = _SQL_GETUSERS;
3234 }
3235
3236 SQLQuery q = session.createSQLQuery(sql);
3237
3238 q.addEntity("User_",
3239 com.liferay.portal.model.impl.UserImpl.class);
3240
3241 QueryPos qPos = QueryPos.getInstance(q);
3242
3243 qPos.add(pk);
3244
3245 list = (List<com.liferay.portal.model.User>)QueryUtil.list(q,
3246 getDialect(), start, end);
3247 }
3248 catch (Exception e) {
3249 throw processException(e);
3250 }
3251 finally {
3252 if (list == null) {
3253 FinderCacheUtil.removeResult(FINDER_PATH_GET_USERS,
3254 finderArgs);
3255 }
3256 else {
3257 userPersistence.cacheResult(list);
3258
3259 FinderCacheUtil.putResult(FINDER_PATH_GET_USERS,
3260 finderArgs, list);
3261 }
3262
3263 closeSession(session);
3264 }
3265 }
3266
3267 return list;
3268 }
3269
3270 public static final FinderPath FINDER_PATH_GET_USERS_SIZE = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
3271 OrganizationModelImpl.FINDER_CACHE_ENABLED_USERS_ORGS,
3272 OrganizationModelImpl.MAPPING_TABLE_USERS_ORGS_NAME,
3273 "getUsersSize", new String[] { Long.class.getName() });
3274
3275
3282 public int getUsersSize(long pk) throws SystemException {
3283 Object[] finderArgs = new Object[] { pk };
3284
3285 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_USERS_SIZE,
3286 finderArgs, this);
3287
3288 if (count == null) {
3289 Session session = null;
3290
3291 try {
3292 session = openSession();
3293
3294 SQLQuery q = session.createSQLQuery(_SQL_GETUSERSSIZE);
3295
3296 q.addScalar(COUNT_COLUMN_NAME,
3297 com.liferay.portal.kernel.dao.orm.Type.LONG);
3298
3299 QueryPos qPos = QueryPos.getInstance(q);
3300
3301 qPos.add(pk);
3302
3303 count = (Long)q.uniqueResult();
3304 }
3305 catch (Exception e) {
3306 throw processException(e);
3307 }
3308 finally {
3309 if (count == null) {
3310 count = Long.valueOf(0);
3311 }
3312
3313 FinderCacheUtil.putResult(FINDER_PATH_GET_USERS_SIZE,
3314 finderArgs, count);
3315
3316 closeSession(session);
3317 }
3318 }
3319
3320 return count.intValue();
3321 }
3322
3323 public static final FinderPath FINDER_PATH_CONTAINS_USER = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
3324 OrganizationModelImpl.FINDER_CACHE_ENABLED_USERS_ORGS,
3325 OrganizationModelImpl.MAPPING_TABLE_USERS_ORGS_NAME,
3326 "containsUser",
3327 new String[] { Long.class.getName(), Long.class.getName() });
3328
3329
3337 public boolean containsUser(long pk, long userPK) throws SystemException {
3338 Object[] finderArgs = new Object[] { pk, userPK };
3339
3340 Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_USER,
3341 finderArgs, this);
3342
3343 if (value == null) {
3344 try {
3345 value = Boolean.valueOf(containsUser.contains(pk, userPK));
3346 }
3347 catch (Exception e) {
3348 throw processException(e);
3349 }
3350 finally {
3351 if (value == null) {
3352 value = Boolean.FALSE;
3353 }
3354
3355 FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_USER,
3356 finderArgs, value);
3357 }
3358 }
3359
3360 return value.booleanValue();
3361 }
3362
3363
3370 public boolean containsUsers(long pk) throws SystemException {
3371 if (getUsersSize(pk) > 0) {
3372 return true;
3373 }
3374 else {
3375 return false;
3376 }
3377 }
3378
3379
3386 public void addUser(long pk, long userPK) throws SystemException {
3387 try {
3388 addUser.add(pk, userPK);
3389 }
3390 catch (Exception e) {
3391 throw processException(e);
3392 }
3393 finally {
3394 FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_USERS_ORGS_NAME);
3395 }
3396 }
3397
3398
3405 public void addUser(long pk, com.liferay.portal.model.User user)
3406 throws SystemException {
3407 try {
3408 addUser.add(pk, user.getPrimaryKey());
3409 }
3410 catch (Exception e) {
3411 throw processException(e);
3412 }
3413 finally {
3414 FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_USERS_ORGS_NAME);
3415 }
3416 }
3417
3418
3425 public void addUsers(long pk, long[] userPKs) throws SystemException {
3426 try {
3427 for (long userPK : userPKs) {
3428 addUser.add(pk, userPK);
3429 }
3430 }
3431 catch (Exception e) {
3432 throw processException(e);
3433 }
3434 finally {
3435 FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_USERS_ORGS_NAME);
3436 }
3437 }
3438
3439
3446 public void addUsers(long pk, List<com.liferay.portal.model.User> users)
3447 throws SystemException {
3448 try {
3449 for (com.liferay.portal.model.User user : users) {
3450 addUser.add(pk, user.getPrimaryKey());
3451 }
3452 }
3453 catch (Exception e) {
3454 throw processException(e);
3455 }
3456 finally {
3457 FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_USERS_ORGS_NAME);
3458 }
3459 }
3460
3461
3467 public void clearUsers(long pk) throws SystemException {
3468 try {
3469 clearUsers.clear(pk);
3470 }
3471 catch (Exception e) {
3472 throw processException(e);
3473 }
3474 finally {
3475 FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_USERS_ORGS_NAME);
3476 }
3477 }
3478
3479
3486 public void removeUser(long pk, long userPK) throws SystemException {
3487 try {
3488 removeUser.remove(pk, userPK);
3489 }
3490 catch (Exception e) {
3491 throw processException(e);
3492 }
3493 finally {
3494 FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_USERS_ORGS_NAME);
3495 }
3496 }
3497
3498
3505 public void removeUser(long pk, com.liferay.portal.model.User user)
3506 throws SystemException {
3507 try {
3508 removeUser.remove(pk, user.getPrimaryKey());
3509 }
3510 catch (Exception e) {
3511 throw processException(e);
3512 }
3513 finally {
3514 FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_USERS_ORGS_NAME);
3515 }
3516 }
3517
3518
3525 public void removeUsers(long pk, long[] userPKs) throws SystemException {
3526 try {
3527 for (long userPK : userPKs) {
3528 removeUser.remove(pk, userPK);
3529 }
3530 }
3531 catch (Exception e) {
3532 throw processException(e);
3533 }
3534 finally {
3535 FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_USERS_ORGS_NAME);
3536 }
3537 }
3538
3539
3546 public void removeUsers(long pk, List<com.liferay.portal.model.User> users)
3547 throws SystemException {
3548 try {
3549 for (com.liferay.portal.model.User user : users) {
3550 removeUser.remove(pk, user.getPrimaryKey());
3551 }
3552 }
3553 catch (Exception e) {
3554 throw processException(e);
3555 }
3556 finally {
3557 FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_USERS_ORGS_NAME);
3558 }
3559 }
3560
3561
3568 public void setUsers(long pk, long[] userPKs) throws SystemException {
3569 try {
3570 Set<Long> userPKSet = SetUtil.fromArray(userPKs);
3571
3572 List<com.liferay.portal.model.User> users = getUsers(pk);
3573
3574 for (com.liferay.portal.model.User user : users) {
3575 if (!userPKSet.remove(user.getPrimaryKey())) {
3576 removeUser.remove(pk, user.getPrimaryKey());
3577 }
3578 }
3579
3580 for (Long userPK : userPKSet) {
3581 addUser.add(pk, userPK);
3582 }
3583 }
3584 catch (Exception e) {
3585 throw processException(e);
3586 }
3587 finally {
3588 FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_USERS_ORGS_NAME);
3589 }
3590 }
3591
3592
3599 public void setUsers(long pk, List<com.liferay.portal.model.User> users)
3600 throws SystemException {
3601 try {
3602 long[] userPKs = new long[users.size()];
3603
3604 for (int i = 0; i < users.size(); i++) {
3605 com.liferay.portal.model.User user = users.get(i);
3606
3607 userPKs[i] = user.getPrimaryKey();
3608 }
3609
3610 setUsers(pk, userPKs);
3611 }
3612 catch (Exception e) {
3613 throw processException(e);
3614 }
3615 finally {
3616 FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_USERS_ORGS_NAME);
3617 }
3618 }
3619
3620
3630 public void rebuildTree(long companyId, boolean force)
3631 throws SystemException {
3632 if (force || (countOrphanTreeNodes(companyId) > 0)) {
3633 rebuildTree(companyId, 0, 1);
3634
3635 CacheRegistryUtil.clear(OrganizationImpl.class.getName());
3636 EntityCacheUtil.clearCache(OrganizationImpl.class.getName());
3637 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
3638 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
3639 }
3640 }
3641
3642 protected long countOrphanTreeNodes(long companyId)
3643 throws SystemException {
3644 Session session = null;
3645
3646 try {
3647 session = openSession();
3648
3649 SQLQuery q = session.createSQLQuery(
3650 "SELECT COUNT(*) AS COUNT_VALUE FROM Organization_ WHERE companyId = ? AND (leftOrganizationId = 0 OR leftOrganizationId IS NULL OR rightOrganizationId = 0 OR rightOrganizationId IS NULL)");
3651
3652 q.addScalar(COUNT_COLUMN_NAME,
3653 com.liferay.portal.kernel.dao.orm.Type.LONG);
3654
3655 QueryPos qPos = QueryPos.getInstance(q);
3656
3657 qPos.add(companyId);
3658
3659 return (Long)q.uniqueResult();
3660 }
3661 catch (Exception e) {
3662 throw processException(e);
3663 }
3664 finally {
3665 closeSession(session);
3666 }
3667 }
3668
3669 protected void expandTree(Organization organization)
3670 throws SystemException {
3671 long companyId = organization.getCompanyId();
3672
3673 long lastRightOrganizationId = getLastRightOrganizationId(companyId,
3674 organization.getParentOrganizationId());
3675
3676 long leftOrganizationId = 2;
3677 long rightOrganizationId = 3;
3678
3679 if (lastRightOrganizationId > 0) {
3680 leftOrganizationId = lastRightOrganizationId + 1;
3681 rightOrganizationId = lastRightOrganizationId + 2;
3682
3683 expandTreeLeftOrganizationId.expand(companyId,
3684 lastRightOrganizationId);
3685 expandTreeRightOrganizationId.expand(companyId,
3686 lastRightOrganizationId);
3687
3688 CacheRegistryUtil.clear(OrganizationImpl.class.getName());
3689 EntityCacheUtil.clearCache(OrganizationImpl.class.getName());
3690 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
3691 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
3692 }
3693
3694 organization.setLeftOrganizationId(leftOrganizationId);
3695 organization.setRightOrganizationId(rightOrganizationId);
3696 }
3697
3698 protected long getLastRightOrganizationId(long companyId,
3699 long parentOrganizationId) throws SystemException {
3700 Session session = null;
3701
3702 try {
3703 session = openSession();
3704
3705 SQLQuery q = session.createSQLQuery(
3706 "SELECT rightOrganizationId FROM Organization_ WHERE (companyId = ?) AND (parentOrganizationId = ?) ORDER BY rightOrganizationId DESC");
3707
3708 q.addScalar("rightOrganizationId",
3709 com.liferay.portal.kernel.dao.orm.Type.LONG);
3710
3711 QueryPos qPos = QueryPos.getInstance(q);
3712
3713 qPos.add(companyId);
3714 qPos.add(parentOrganizationId);
3715
3716 List<Long> list = (List<Long>)QueryUtil.list(q, getDialect(), 0, 1);
3717
3718 if (list.isEmpty()) {
3719 if (parentOrganizationId > 0) {
3720 Organization parentOrganization = findByPrimaryKey(parentOrganizationId);
3721
3722 return parentOrganization.getLeftOrganizationId();
3723 }
3724
3725 return 0;
3726 }
3727 else {
3728 return list.get(0);
3729 }
3730 }
3731 catch (Exception e) {
3732 throw processException(e);
3733 }
3734 finally {
3735 closeSession(session);
3736 }
3737 }
3738
3739 protected long rebuildTree(long companyId, long parentOrganizationId,
3740 long leftOrganizationId) throws SystemException {
3741 List<Long> organizationIds = null;
3742
3743 Session session = null;
3744
3745 try {
3746 session = openSession();
3747
3748 SQLQuery q = session.createSQLQuery(
3749 "SELECT organizationId FROM Organization_ WHERE companyId = ? AND parentOrganizationId = ? ORDER BY organizationId ASC");
3750
3751 q.addScalar("organizationId",
3752 com.liferay.portal.kernel.dao.orm.Type.LONG);
3753
3754 QueryPos qPos = QueryPos.getInstance(q);
3755
3756 qPos.add(companyId);
3757 qPos.add(parentOrganizationId);
3758
3759 organizationIds = q.list();
3760 }
3761 catch (Exception e) {
3762 throw processException(e);
3763 }
3764 finally {
3765 closeSession(session);
3766 }
3767
3768 long rightOrganizationId = leftOrganizationId + 1;
3769
3770 for (long organizationId : organizationIds) {
3771 rightOrganizationId = rebuildTree(companyId, organizationId,
3772 rightOrganizationId);
3773 }
3774
3775 if (parentOrganizationId > 0) {
3776 updateTree.update(parentOrganizationId, leftOrganizationId,
3777 rightOrganizationId);
3778 }
3779
3780 return rightOrganizationId + 1;
3781 }
3782
3783 protected void shrinkTree(Organization organization) {
3784 long companyId = organization.getCompanyId();
3785
3786 long leftOrganizationId = organization.getLeftOrganizationId();
3787 long rightOrganizationId = organization.getRightOrganizationId();
3788
3789 long delta = (rightOrganizationId - leftOrganizationId) + 1;
3790
3791 shrinkTreeLeftOrganizationId.shrink(companyId, rightOrganizationId,
3792 delta);
3793 shrinkTreeRightOrganizationId.shrink(companyId, rightOrganizationId,
3794 delta);
3795
3796 CacheRegistryUtil.clear(OrganizationImpl.class.getName());
3797 EntityCacheUtil.clearCache(OrganizationImpl.class.getName());
3798 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
3799 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
3800 }
3801
3802
3805 public void afterPropertiesSet() {
3806 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
3807 com.liferay.portal.util.PropsUtil.get(
3808 "value.object.listener.com.liferay.portal.model.Organization")));
3809
3810 if (listenerClassNames.length > 0) {
3811 try {
3812 List<ModelListener<Organization>> listenersList = new ArrayList<ModelListener<Organization>>();
3813
3814 for (String listenerClassName : listenerClassNames) {
3815 listenersList.add((ModelListener<Organization>)InstanceFactory.newInstance(
3816 listenerClassName));
3817 }
3818
3819 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
3820 }
3821 catch (Exception e) {
3822 _log.error(e);
3823 }
3824 }
3825
3826 containsGroup = new ContainsGroup(this);
3827
3828 addGroup = new AddGroup(this);
3829 clearGroups = new ClearGroups(this);
3830 removeGroup = new RemoveGroup(this);
3831
3832 containsUser = new ContainsUser(this);
3833
3834 addUser = new AddUser(this);
3835 clearUsers = new ClearUsers(this);
3836 removeUser = new RemoveUser(this);
3837
3838 expandTreeLeftOrganizationId = new ExpandTreeLeftOrganizationId();
3839 expandTreeRightOrganizationId = new ExpandTreeRightOrganizationId();
3840 shrinkTreeLeftOrganizationId = new ShrinkTreeLeftOrganizationId();
3841 shrinkTreeRightOrganizationId = new ShrinkTreeRightOrganizationId();
3842 updateTree = new UpdateTree();
3843 }
3844
3845 public void destroy() {
3846 EntityCacheUtil.removeCache(OrganizationImpl.class.getName());
3847 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
3848 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
3849 }
3850
3851 @BeanReference(type = AccountPersistence.class)
3852 protected AccountPersistence accountPersistence;
3853 @BeanReference(type = AddressPersistence.class)
3854 protected AddressPersistence addressPersistence;
3855 @BeanReference(type = BrowserTrackerPersistence.class)
3856 protected BrowserTrackerPersistence browserTrackerPersistence;
3857 @BeanReference(type = ClassNamePersistence.class)
3858 protected ClassNamePersistence classNamePersistence;
3859 @BeanReference(type = ClusterGroupPersistence.class)
3860 protected ClusterGroupPersistence clusterGroupPersistence;
3861 @BeanReference(type = CompanyPersistence.class)
3862 protected CompanyPersistence companyPersistence;
3863 @BeanReference(type = ContactPersistence.class)
3864 protected ContactPersistence contactPersistence;
3865 @BeanReference(type = CountryPersistence.class)
3866 protected CountryPersistence countryPersistence;
3867 @BeanReference(type = EmailAddressPersistence.class)
3868 protected EmailAddressPersistence emailAddressPersistence;
3869 @BeanReference(type = GroupPersistence.class)
3870 protected GroupPersistence groupPersistence;
3871 @BeanReference(type = ImagePersistence.class)
3872 protected ImagePersistence imagePersistence;
3873 @BeanReference(type = LayoutPersistence.class)
3874 protected LayoutPersistence layoutPersistence;
3875 @BeanReference(type = LayoutPrototypePersistence.class)
3876 protected LayoutPrototypePersistence layoutPrototypePersistence;
3877 @BeanReference(type = LayoutSetPersistence.class)
3878 protected LayoutSetPersistence layoutSetPersistence;
3879 @BeanReference(type = LayoutSetPrototypePersistence.class)
3880 protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
3881 @BeanReference(type = ListTypePersistence.class)
3882 protected ListTypePersistence listTypePersistence;
3883 @BeanReference(type = LockPersistence.class)
3884 protected LockPersistence lockPersistence;
3885 @BeanReference(type = MembershipRequestPersistence.class)
3886 protected MembershipRequestPersistence membershipRequestPersistence;
3887 @BeanReference(type = OrganizationPersistence.class)
3888 protected OrganizationPersistence organizationPersistence;
3889 @BeanReference(type = OrgGroupPermissionPersistence.class)
3890 protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
3891 @BeanReference(type = OrgGroupRolePersistence.class)
3892 protected OrgGroupRolePersistence orgGroupRolePersistence;
3893 @BeanReference(type = OrgLaborPersistence.class)
3894 protected OrgLaborPersistence orgLaborPersistence;
3895 @BeanReference(type = PasswordPolicyPersistence.class)
3896 protected PasswordPolicyPersistence passwordPolicyPersistence;
3897 @BeanReference(type = PasswordPolicyRelPersistence.class)
3898 protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
3899 @BeanReference(type = PasswordTrackerPersistence.class)
3900 protected PasswordTrackerPersistence passwordTrackerPersistence;
3901 @BeanReference(type = PermissionPersistence.class)
3902 protected PermissionPersistence permissionPersistence;
3903 @BeanReference(type = PhonePersistence.class)
3904 protected PhonePersistence phonePersistence;
3905 @BeanReference(type = PluginSettingPersistence.class)
3906 protected PluginSettingPersistence pluginSettingPersistence;
3907 @BeanReference(type = PortletPersistence.class)
3908 protected PortletPersistence portletPersistence;
3909 @BeanReference(type = PortletItemPersistence.class)
3910 protected PortletItemPersistence portletItemPersistence;
3911 @BeanReference(type = PortletPreferencesPersistence.class)
3912 protected PortletPreferencesPersistence portletPreferencesPersistence;
3913 @BeanReference(type = RegionPersistence.class)
3914 protected RegionPersistence regionPersistence;
3915 @BeanReference(type = ReleasePersistence.class)
3916 protected ReleasePersistence releasePersistence;
3917 @BeanReference(type = ResourcePersistence.class)
3918 protected ResourcePersistence resourcePersistence;
3919 @BeanReference(type = ResourceActionPersistence.class)
3920 protected ResourceActionPersistence resourceActionPersistence;
3921 @BeanReference(type = ResourceCodePersistence.class)
3922 protected ResourceCodePersistence resourceCodePersistence;
3923 @BeanReference(type = ResourcePermissionPersistence.class)
3924 protected ResourcePermissionPersistence resourcePermissionPersistence;
3925 @BeanReference(type = RolePersistence.class)
3926 protected RolePersistence rolePersistence;
3927 @BeanReference(type = ServiceComponentPersistence.class)
3928 protected ServiceComponentPersistence serviceComponentPersistence;
3929 @BeanReference(type = ShardPersistence.class)
3930 protected ShardPersistence shardPersistence;
3931 @BeanReference(type = SubscriptionPersistence.class)
3932 protected SubscriptionPersistence subscriptionPersistence;
3933 @BeanReference(type = TicketPersistence.class)
3934 protected TicketPersistence ticketPersistence;
3935 @BeanReference(type = TeamPersistence.class)
3936 protected TeamPersistence teamPersistence;
3937 @BeanReference(type = UserPersistence.class)
3938 protected UserPersistence userPersistence;
3939 @BeanReference(type = UserGroupPersistence.class)
3940 protected UserGroupPersistence userGroupPersistence;
3941 @BeanReference(type = UserGroupGroupRolePersistence.class)
3942 protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
3943 @BeanReference(type = UserGroupRolePersistence.class)
3944 protected UserGroupRolePersistence userGroupRolePersistence;
3945 @BeanReference(type = UserIdMapperPersistence.class)
3946 protected UserIdMapperPersistence userIdMapperPersistence;
3947 @BeanReference(type = UserTrackerPersistence.class)
3948 protected UserTrackerPersistence userTrackerPersistence;
3949 @BeanReference(type = UserTrackerPathPersistence.class)
3950 protected UserTrackerPathPersistence userTrackerPathPersistence;
3951 @BeanReference(type = WebDAVPropsPersistence.class)
3952 protected WebDAVPropsPersistence webDAVPropsPersistence;
3953 @BeanReference(type = WebsitePersistence.class)
3954 protected WebsitePersistence websitePersistence;
3955 @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
3956 protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
3957 @BeanReference(type = WorkflowInstanceLinkPersistence.class)
3958 protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
3959 @BeanReference(type = AssetEntryPersistence.class)
3960 protected AssetEntryPersistence assetEntryPersistence;
3961 @BeanReference(type = ExpandoValuePersistence.class)
3962 protected ExpandoValuePersistence expandoValuePersistence;
3963 protected ContainsGroup containsGroup;
3964 protected AddGroup addGroup;
3965 protected ClearGroups clearGroups;
3966 protected RemoveGroup removeGroup;
3967 protected ContainsUser containsUser;
3968 protected AddUser addUser;
3969 protected ClearUsers clearUsers;
3970 protected RemoveUser removeUser;
3971
3972 protected class ContainsGroup {
3973 protected ContainsGroup(OrganizationPersistenceImpl persistenceImpl) {
3974 super();
3975
3976 _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
3977 _SQL_CONTAINSGROUP,
3978 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT },
3979 RowMapper.COUNT);
3980 }
3981
3982 protected boolean contains(long organizationId, long groupId) {
3983 List<Integer> results = _mappingSqlQuery.execute(new Object[] {
3984 new Long(organizationId), new Long(groupId)
3985 });
3986
3987 if (results.size() > 0) {
3988 Integer count = results.get(0);
3989
3990 if (count.intValue() > 0) {
3991 return true;
3992 }
3993 }
3994
3995 return false;
3996 }
3997
3998 private MappingSqlQuery<Integer> _mappingSqlQuery;
3999 }
4000
4001 protected class AddGroup {
4002 protected AddGroup(OrganizationPersistenceImpl persistenceImpl) {
4003 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
4004 "INSERT INTO Groups_Orgs (organizationId, groupId) VALUES (?, ?)",
4005 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
4006 _persistenceImpl = persistenceImpl;
4007 }
4008
4009 protected void add(long organizationId, long groupId)
4010 throws SystemException {
4011 if (!_persistenceImpl.containsGroup.contains(organizationId, groupId)) {
4012 ModelListener<com.liferay.portal.model.Group>[] groupListeners = groupPersistence.getListeners();
4013
4014 for (ModelListener<Organization> listener : listeners) {
4015 listener.onBeforeAddAssociation(organizationId,
4016 com.liferay.portal.model.Group.class.getName(), groupId);
4017 }
4018
4019 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
4020 listener.onBeforeAddAssociation(groupId,
4021 Organization.class.getName(), organizationId);
4022 }
4023
4024 _sqlUpdate.update(new Object[] {
4025 new Long(organizationId), new Long(groupId)
4026 });
4027
4028 for (ModelListener<Organization> listener : listeners) {
4029 listener.onAfterAddAssociation(organizationId,
4030 com.liferay.portal.model.Group.class.getName(), groupId);
4031 }
4032
4033 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
4034 listener.onAfterAddAssociation(groupId,
4035 Organization.class.getName(), organizationId);
4036 }
4037 }
4038 }
4039
4040 private SqlUpdate _sqlUpdate;
4041 private OrganizationPersistenceImpl _persistenceImpl;
4042 }
4043
4044 protected class ClearGroups {
4045 protected ClearGroups(OrganizationPersistenceImpl persistenceImpl) {
4046 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
4047 "DELETE FROM Groups_Orgs WHERE organizationId = ?",
4048 new int[] { java.sql.Types.BIGINT });
4049 }
4050
4051 protected void clear(long organizationId) throws SystemException {
4052 ModelListener<com.liferay.portal.model.Group>[] groupListeners = groupPersistence.getListeners();
4053
4054 List<com.liferay.portal.model.Group> groups = null;
4055
4056 if ((listeners.length > 0) || (groupListeners.length > 0)) {
4057 groups = getGroups(organizationId);
4058
4059 for (com.liferay.portal.model.Group group : groups) {
4060 for (ModelListener<Organization> listener : listeners) {
4061 listener.onBeforeRemoveAssociation(organizationId,
4062 com.liferay.portal.model.Group.class.getName(),
4063 group.getPrimaryKey());
4064 }
4065
4066 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
4067 listener.onBeforeRemoveAssociation(group.getPrimaryKey(),
4068 Organization.class.getName(), organizationId);
4069 }
4070 }
4071 }
4072
4073 _sqlUpdate.update(new Object[] { new Long(organizationId) });
4074
4075 if ((listeners.length > 0) || (groupListeners.length > 0)) {
4076 for (com.liferay.portal.model.Group group : groups) {
4077 for (ModelListener<Organization> listener : listeners) {
4078 listener.onAfterRemoveAssociation(organizationId,
4079 com.liferay.portal.model.Group.class.getName(),
4080 group.getPrimaryKey());
4081 }
4082
4083 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
4084 listener.onAfterRemoveAssociation(group.getPrimaryKey(),
4085 Organization.class.getName(), organizationId);
4086 }
4087 }
4088 }
4089 }
4090
4091 private SqlUpdate _sqlUpdate;
4092 }
4093
4094 protected class RemoveGroup {
4095 protected RemoveGroup(OrganizationPersistenceImpl persistenceImpl) {
4096 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
4097 "DELETE FROM Groups_Orgs WHERE organizationId = ? AND groupId = ?",
4098 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
4099 _persistenceImpl = persistenceImpl;
4100 }
4101
4102 protected void remove(long organizationId, long groupId)
4103 throws SystemException {
4104 if (_persistenceImpl.containsGroup.contains(organizationId, groupId)) {
4105 ModelListener<com.liferay.portal.model.Group>[] groupListeners = groupPersistence.getListeners();
4106
4107 for (ModelListener<Organization> listener : listeners) {
4108 listener.onBeforeRemoveAssociation(organizationId,
4109 com.liferay.portal.model.Group.class.getName(), groupId);
4110 }
4111
4112 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
4113 listener.onBeforeRemoveAssociation(groupId,
4114 Organization.class.getName(), organizationId);
4115 }
4116
4117 _sqlUpdate.update(new Object[] {
4118 new Long(organizationId), new Long(groupId)
4119 });
4120
4121 for (ModelListener<Organization> listener : listeners) {
4122 listener.onAfterRemoveAssociation(organizationId,
4123 com.liferay.portal.model.Group.class.getName(), groupId);
4124 }
4125
4126 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
4127 listener.onAfterRemoveAssociation(groupId,
4128 Organization.class.getName(), organizationId);
4129 }
4130 }
4131 }
4132
4133 private SqlUpdate _sqlUpdate;
4134 private OrganizationPersistenceImpl _persistenceImpl;
4135 }
4136
4137 protected class ContainsUser {
4138 protected ContainsUser(OrganizationPersistenceImpl persistenceImpl) {
4139 super();
4140
4141 _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
4142 _SQL_CONTAINSUSER,
4143 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT },
4144 RowMapper.COUNT);
4145 }
4146
4147 protected boolean contains(long organizationId, long userId) {
4148 List<Integer> results = _mappingSqlQuery.execute(new Object[] {
4149 new Long(organizationId), new Long(userId)
4150 });
4151
4152 if (results.size() > 0) {
4153 Integer count = results.get(0);
4154
4155 if (count.intValue() > 0) {
4156 return true;
4157 }
4158 }
4159
4160 return false;
4161 }
4162
4163 private MappingSqlQuery<Integer> _mappingSqlQuery;
4164 }
4165
4166 protected class AddUser {
4167 protected AddUser(OrganizationPersistenceImpl persistenceImpl) {
4168 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
4169 "INSERT INTO Users_Orgs (organizationId, userId) VALUES (?, ?)",
4170 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
4171 _persistenceImpl = persistenceImpl;
4172 }
4173
4174 protected void add(long organizationId, long userId)
4175 throws SystemException {
4176 if (!_persistenceImpl.containsUser.contains(organizationId, userId)) {
4177 ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
4178
4179 for (ModelListener<Organization> listener : listeners) {
4180 listener.onBeforeAddAssociation(organizationId,
4181 com.liferay.portal.model.User.class.getName(), userId);
4182 }
4183
4184 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
4185 listener.onBeforeAddAssociation(userId,
4186 Organization.class.getName(), organizationId);
4187 }
4188
4189 _sqlUpdate.update(new Object[] {
4190 new Long(organizationId), new Long(userId)
4191 });
4192
4193 for (ModelListener<Organization> listener : listeners) {
4194 listener.onAfterAddAssociation(organizationId,
4195 com.liferay.portal.model.User.class.getName(), userId);
4196 }
4197
4198 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
4199 listener.onAfterAddAssociation(userId,
4200 Organization.class.getName(), organizationId);
4201 }
4202 }
4203 }
4204
4205 private SqlUpdate _sqlUpdate;
4206 private OrganizationPersistenceImpl _persistenceImpl;
4207 }
4208
4209 protected class ClearUsers {
4210 protected ClearUsers(OrganizationPersistenceImpl persistenceImpl) {
4211 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
4212 "DELETE FROM Users_Orgs WHERE organizationId = ?",
4213 new int[] { java.sql.Types.BIGINT });
4214 }
4215
4216 protected void clear(long organizationId) throws SystemException {
4217 ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
4218
4219 List<com.liferay.portal.model.User> users = null;
4220
4221 if ((listeners.length > 0) || (userListeners.length > 0)) {
4222 users = getUsers(organizationId);
4223
4224 for (com.liferay.portal.model.User user : users) {
4225 for (ModelListener<Organization> listener : listeners) {
4226 listener.onBeforeRemoveAssociation(organizationId,
4227 com.liferay.portal.model.User.class.getName(),
4228 user.getPrimaryKey());
4229 }
4230
4231 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
4232 listener.onBeforeRemoveAssociation(user.getPrimaryKey(),
4233 Organization.class.getName(), organizationId);
4234 }
4235 }
4236 }
4237
4238 _sqlUpdate.update(new Object[] { new Long(organizationId) });
4239
4240 if ((listeners.length > 0) || (userListeners.length > 0)) {
4241 for (com.liferay.portal.model.User user : users) {
4242 for (ModelListener<Organization> listener : listeners) {
4243 listener.onAfterRemoveAssociation(organizationId,
4244 com.liferay.portal.model.User.class.getName(),
4245 user.getPrimaryKey());
4246 }
4247
4248 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
4249 listener.onAfterRemoveAssociation(user.getPrimaryKey(),
4250 Organization.class.getName(), organizationId);
4251 }
4252 }
4253 }
4254 }
4255
4256 private SqlUpdate _sqlUpdate;
4257 }
4258
4259 protected class RemoveUser {
4260 protected RemoveUser(OrganizationPersistenceImpl persistenceImpl) {
4261 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
4262 "DELETE FROM Users_Orgs WHERE organizationId = ? AND userId = ?",
4263 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
4264 _persistenceImpl = persistenceImpl;
4265 }
4266
4267 protected void remove(long organizationId, long userId)
4268 throws SystemException {
4269 if (_persistenceImpl.containsUser.contains(organizationId, userId)) {
4270 ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
4271
4272 for (ModelListener<Organization> listener : listeners) {
4273 listener.onBeforeRemoveAssociation(organizationId,
4274 com.liferay.portal.model.User.class.getName(), userId);
4275 }
4276
4277 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
4278 listener.onBeforeRemoveAssociation(userId,
4279 Organization.class.getName(), organizationId);
4280 }
4281
4282 _sqlUpdate.update(new Object[] {
4283 new Long(organizationId), new Long(userId)
4284 });
4285
4286 for (ModelListener<Organization> listener : listeners) {
4287 listener.onAfterRemoveAssociation(organizationId,
4288 com.liferay.portal.model.User.class.getName(), userId);
4289 }
4290
4291 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
4292 listener.onAfterRemoveAssociation(userId,
4293 Organization.class.getName(), organizationId);
4294 }
4295 }
4296 }
4297
4298 private SqlUpdate _sqlUpdate;
4299 private OrganizationPersistenceImpl _persistenceImpl;
4300 }
4301
4302 protected ExpandTreeLeftOrganizationId expandTreeLeftOrganizationId;
4303 protected ExpandTreeRightOrganizationId expandTreeRightOrganizationId;
4304 protected ShrinkTreeLeftOrganizationId shrinkTreeLeftOrganizationId;
4305 protected ShrinkTreeRightOrganizationId shrinkTreeRightOrganizationId;
4306 protected UpdateTree updateTree;
4307
4308 protected class ExpandTreeLeftOrganizationId {
4309 protected ExpandTreeLeftOrganizationId() {
4310 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
4311 "UPDATE Organization_ SET leftOrganizationId = (leftOrganizationId + 2) WHERE (companyId = ?) AND (leftOrganizationId > ?)",
4312 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
4313 }
4314
4315 protected void expand(long companyId, long leftOrganizationId) {
4316 _sqlUpdate.update(new Object[] { companyId, leftOrganizationId });
4317 }
4318
4319 private SqlUpdate _sqlUpdate;
4320 }
4321
4322 protected class ExpandTreeRightOrganizationId {
4323 protected ExpandTreeRightOrganizationId() {
4324 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
4325 "UPDATE Organization_ SET rightOrganizationId = (rightOrganizationId + 2) WHERE (companyId = ?) AND (rightOrganizationId > ?)",
4326 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
4327 }
4328
4329 protected void expand(long companyId, long rightOrganizationId) {
4330 _sqlUpdate.update(new Object[] { companyId, rightOrganizationId });
4331 }
4332
4333 private SqlUpdate _sqlUpdate;
4334 }
4335
4336 protected class ShrinkTreeLeftOrganizationId {
4337 protected ShrinkTreeLeftOrganizationId() {
4338 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
4339 "UPDATE Organization_ SET leftOrganizationId = (leftOrganizationId - ?) WHERE (companyId = ?) AND (leftOrganizationId > ?)",
4340 new int[] {
4341 java.sql.Types.BIGINT, java.sql.Types.BIGINT,
4342 java.sql.Types.BIGINT
4343 });
4344 }
4345
4346 protected void shrink(long companyId, long leftOrganizationId,
4347 long delta) {
4348 _sqlUpdate.update(new Object[] { delta, companyId, leftOrganizationId });
4349 }
4350
4351 private SqlUpdate _sqlUpdate;
4352 }
4353
4354 protected class ShrinkTreeRightOrganizationId {
4355 protected ShrinkTreeRightOrganizationId() {
4356 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
4357 "UPDATE Organization_ SET rightOrganizationId = (rightOrganizationId - ?) WHERE (companyId = ?) AND (rightOrganizationId > ?)",
4358 new int[] {
4359 java.sql.Types.BIGINT, java.sql.Types.BIGINT,
4360 java.sql.Types.BIGINT
4361 });
4362 }
4363
4364 protected void shrink(long companyId, long rightOrganizationId,
4365 long delta) {
4366 _sqlUpdate.update(new Object[] { delta, companyId, rightOrganizationId });
4367 }
4368
4369 private SqlUpdate _sqlUpdate;
4370 }
4371
4372 protected class UpdateTree {
4373 protected UpdateTree() {
4374 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
4375 "UPDATE Organization_ SET leftOrganizationId = ?, rightOrganizationId = ? WHERE organizationId = ?",
4376 new int[] {
4377 java.sql.Types.BIGINT, java.sql.Types.BIGINT,
4378 java.sql.Types.BIGINT
4379 });
4380 }
4381
4382 protected void update(long organizationId, long leftOrganizationId,
4383 long rightOrganizationId) {
4384 _sqlUpdate.update(new Object[] {
4385 leftOrganizationId, rightOrganizationId, organizationId
4386 });
4387 }
4388
4389 private SqlUpdate _sqlUpdate;
4390 }
4391
4392 private static final String _SQL_SELECT_ORGANIZATION = "SELECT organization FROM Organization organization";
4393 private static final String _SQL_SELECT_ORGANIZATION_WHERE = "SELECT organization FROM Organization organization WHERE ";
4394 private static final String _SQL_COUNT_ORGANIZATION = "SELECT COUNT(organization) FROM Organization organization";
4395 private static final String _SQL_COUNT_ORGANIZATION_WHERE = "SELECT COUNT(organization) FROM Organization organization WHERE ";
4396 private static final String _SQL_GETGROUPS = "SELECT {Group_.*} FROM Group_ INNER JOIN Groups_Orgs ON (Groups_Orgs.groupId = Group_.groupId) WHERE (Groups_Orgs.organizationId = ?)";
4397 private static final String _SQL_GETGROUPSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_Orgs WHERE organizationId = ?";
4398 private static final String _SQL_CONTAINSGROUP = "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_Orgs WHERE organizationId = ? AND groupId = ?";
4399 private static final String _SQL_GETUSERS = "SELECT {User_.*} FROM User_ INNER JOIN Users_Orgs ON (Users_Orgs.userId = User_.userId) WHERE (Users_Orgs.organizationId = ?)";
4400 private static final String _SQL_GETUSERSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Orgs WHERE organizationId = ?";
4401 private static final String _SQL_CONTAINSUSER = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Orgs WHERE organizationId = ? AND userId = ?";
4402 private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "organization.companyId = ?";
4403 private static final String _FINDER_COLUMN_LOCATIONS_COMPANYID_2 = "organization.companyId = ? AND organization.parentOrganizationId != 0";
4404 private static final String _FINDER_COLUMN_C_P_COMPANYID_2 = "organization.companyId = ? AND ";
4405 private static final String _FINDER_COLUMN_C_P_PARENTORGANIZATIONID_2 = "organization.parentOrganizationId = ?";
4406 private static final String _FINDER_COLUMN_C_N_COMPANYID_2 = "organization.companyId = ? AND ";
4407 private static final String _FINDER_COLUMN_C_N_NAME_1 = "organization.name IS NULL";
4408 private static final String _FINDER_COLUMN_C_N_NAME_2 = "organization.name = ?";
4409 private static final String _FINDER_COLUMN_C_N_NAME_3 = "(organization.name IS NULL OR organization.name = ?)";
4410 private static final String _FILTER_SQL_SELECT_ORGANIZATION_WHERE = "SELECT DISTINCT {organization.*} FROM Organization_ organization WHERE ";
4411 private static final String _FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1 =
4412 "SELECT {Organization_.*} FROM (SELECT DISTINCT organization.organizationId FROM Organization_ organization WHERE ";
4413 private static final String _FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2 =
4414 ") TEMP_TABLE INNER JOIN Organization_ ON TEMP_TABLE.organizationId = Organization_.organizationId";
4415 private static final String _FILTER_SQL_COUNT_ORGANIZATION_WHERE = "SELECT COUNT(DISTINCT organization.organizationId) AS COUNT_VALUE FROM Organization_ organization WHERE ";
4416 private static final String _FILTER_COLUMN_PK = "organization.organizationId";
4417 private static final String _FILTER_COLUMN_USERID = null;
4418 private static final String _FILTER_ENTITY_ALIAS = "organization";
4419 private static final String _FILTER_ENTITY_TABLE = "Organization_";
4420 private static final String _ORDER_BY_ENTITY_ALIAS = "organization.";
4421 private static final String _ORDER_BY_ENTITY_TABLE = "Organization_.";
4422 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Organization exists with the primary key ";
4423 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Organization exists with the key {";
4424 private static Log _log = LogFactoryUtil.getLog(OrganizationPersistenceImpl.class);
4425 }