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.bean.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.CacheModel;
046 import com.liferay.portal.model.ModelListener;
047 import com.liferay.portal.model.Organization;
048 import com.liferay.portal.model.impl.OrganizationImpl;
049 import com.liferay.portal.model.impl.OrganizationModelImpl;
050 import com.liferay.portal.security.permission.InlineSQLHelperUtil;
051 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
052
053 import com.liferay.portlet.asset.service.persistence.AssetEntryPersistence;
054 import com.liferay.portlet.expando.service.persistence.ExpandoValuePersistence;
055
056 import java.io.Serializable;
057
058 import java.util.ArrayList;
059 import java.util.Collections;
060 import java.util.List;
061 import java.util.Set;
062
063
075 public class OrganizationPersistenceImpl extends BasePersistenceImpl<Organization>
076 implements OrganizationPersistence {
077
082 public static final String FINDER_CLASS_NAME_ENTITY = OrganizationImpl.class.getName();
083 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
084 ".List1";
085 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
086 ".List2";
087 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
088 new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
089 OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
090 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
091 new String[] {
092 Long.class.getName(),
093
094 "java.lang.Integer", "java.lang.Integer",
095 "com.liferay.portal.kernel.util.OrderByComparator"
096 });
097 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
098 new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
099 OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
100 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
101 new String[] { Long.class.getName() },
102 OrganizationModelImpl.COMPANYID_COLUMN_BITMASK);
103 public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
104 OrganizationModelImpl.FINDER_CACHE_ENABLED, Long.class,
105 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
106 new String[] { Long.class.getName() });
107 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_LOCATIONS =
108 new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
109 OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
110 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByLocations",
111 new String[] {
112 Long.class.getName(),
113
114 "java.lang.Integer", "java.lang.Integer",
115 "com.liferay.portal.kernel.util.OrderByComparator"
116 });
117 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LOCATIONS =
118 new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
119 OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
120 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByLocations",
121 new String[] { Long.class.getName() },
122 OrganizationModelImpl.COMPANYID_COLUMN_BITMASK);
123 public static final FinderPath FINDER_PATH_COUNT_BY_LOCATIONS = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
124 OrganizationModelImpl.FINDER_CACHE_ENABLED, Long.class,
125 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByLocations",
126 new String[] { Long.class.getName() });
127 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_P = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
128 OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
129 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_P",
130 new String[] {
131 Long.class.getName(), Long.class.getName(),
132
133 "java.lang.Integer", "java.lang.Integer",
134 "com.liferay.portal.kernel.util.OrderByComparator"
135 });
136 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
137 OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
138 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_P",
139 new String[] { Long.class.getName(), Long.class.getName() },
140 OrganizationModelImpl.COMPANYID_COLUMN_BITMASK |
141 OrganizationModelImpl.PARENTORGANIZATIONID_COLUMN_BITMASK);
142 public static final FinderPath FINDER_PATH_COUNT_BY_C_P = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
143 OrganizationModelImpl.FINDER_CACHE_ENABLED, Long.class,
144 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_P",
145 new String[] { Long.class.getName(), Long.class.getName() });
146 public static final FinderPath FINDER_PATH_FETCH_BY_C_N = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
147 OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
148 FINDER_CLASS_NAME_ENTITY, "fetchByC_N",
149 new String[] { Long.class.getName(), String.class.getName() },
150 OrganizationModelImpl.COMPANYID_COLUMN_BITMASK |
151 OrganizationModelImpl.NAME_COLUMN_BITMASK);
152 public static final FinderPath FINDER_PATH_COUNT_BY_C_N = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
153 OrganizationModelImpl.FINDER_CACHE_ENABLED, Long.class,
154 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_N",
155 new String[] { Long.class.getName(), String.class.getName() });
156 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
157 OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
158 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
159 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
160 OrganizationModelImpl.FINDER_CACHE_ENABLED, OrganizationImpl.class,
161 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
162 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
163 OrganizationModelImpl.FINDER_CACHE_ENABLED, Long.class,
164 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
165
166
171 public void cacheResult(Organization organization) {
172 EntityCacheUtil.putResult(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
173 OrganizationImpl.class, organization.getPrimaryKey(), organization);
174
175 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
176 new Object[] {
177 Long.valueOf(organization.getCompanyId()),
178
179 organization.getName()
180 }, organization);
181
182 organization.resetOriginalValues();
183 }
184
185
190 public void cacheResult(List<Organization> organizations) {
191 for (Organization organization : organizations) {
192 if (EntityCacheUtil.getResult(
193 OrganizationModelImpl.ENTITY_CACHE_ENABLED,
194 OrganizationImpl.class, organization.getPrimaryKey()) == null) {
195 cacheResult(organization);
196 }
197 else {
198 organization.resetOriginalValues();
199 }
200 }
201 }
202
203
210 @Override
211 public void clearCache() {
212 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
213 CacheRegistryUtil.clear(OrganizationImpl.class.getName());
214 }
215
216 EntityCacheUtil.clearCache(OrganizationImpl.class.getName());
217
218 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
219 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
220 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
221 }
222
223
230 @Override
231 public void clearCache(Organization organization) {
232 EntityCacheUtil.removeResult(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
233 OrganizationImpl.class, organization.getPrimaryKey());
234
235 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
236 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
237
238 clearUniqueFindersCache(organization);
239 }
240
241 @Override
242 public void clearCache(List<Organization> organizations) {
243 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
244 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
245
246 for (Organization organization : organizations) {
247 EntityCacheUtil.removeResult(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
248 OrganizationImpl.class, organization.getPrimaryKey());
249
250 clearUniqueFindersCache(organization);
251 }
252 }
253
254 protected void clearUniqueFindersCache(Organization organization) {
255 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N,
256 new Object[] {
257 Long.valueOf(organization.getCompanyId()),
258
259 organization.getName()
260 });
261 }
262
263
269 public Organization create(long organizationId) {
270 Organization organization = new OrganizationImpl();
271
272 organization.setNew(true);
273 organization.setPrimaryKey(organizationId);
274
275 return organization;
276 }
277
278
286 public Organization remove(long organizationId)
287 throws NoSuchOrganizationException, SystemException {
288 return remove(Long.valueOf(organizationId));
289 }
290
291
299 @Override
300 public Organization remove(Serializable primaryKey)
301 throws NoSuchOrganizationException, SystemException {
302 Session session = null;
303
304 try {
305 session = openSession();
306
307 Organization organization = (Organization)session.get(OrganizationImpl.class,
308 primaryKey);
309
310 if (organization == null) {
311 if (_log.isWarnEnabled()) {
312 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
313 }
314
315 throw new NoSuchOrganizationException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
316 primaryKey);
317 }
318
319 return remove(organization);
320 }
321 catch (NoSuchOrganizationException nsee) {
322 throw nsee;
323 }
324 catch (Exception e) {
325 throw processException(e);
326 }
327 finally {
328 closeSession(session);
329 }
330 }
331
332 @Override
333 protected Organization removeImpl(Organization organization)
334 throws SystemException {
335 organization = toUnwrappedModel(organization);
336
337 try {
338 clearGroups.clear(organization.getPrimaryKey());
339 }
340 catch (Exception e) {
341 throw processException(e);
342 }
343 finally {
344 FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_GROUPS_ORGS_NAME);
345 }
346
347 try {
348 clearUsers.clear(organization.getPrimaryKey());
349 }
350 catch (Exception e) {
351 throw processException(e);
352 }
353 finally {
354 FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_USERS_ORGS_NAME);
355 }
356
357 Session session = null;
358
359 try {
360 session = openSession();
361
362 BatchSessionUtil.delete(session, organization);
363 }
364 catch (Exception e) {
365 throw processException(e);
366 }
367 finally {
368 closeSession(session);
369 }
370
371 clearCache(organization);
372
373 return organization;
374 }
375
376 @Override
377 public Organization updateImpl(
378 com.liferay.portal.model.Organization organization, boolean merge)
379 throws SystemException {
380 organization = toUnwrappedModel(organization);
381
382 boolean isNew = organization.isNew();
383
384 OrganizationModelImpl organizationModelImpl = (OrganizationModelImpl)organization;
385
386 Session session = null;
387
388 try {
389 session = openSession();
390
391 BatchSessionUtil.update(session, organization, merge);
392
393 organization.setNew(false);
394 }
395 catch (Exception e) {
396 throw processException(e);
397 }
398 finally {
399 closeSession(session);
400 }
401
402 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
403
404 if (isNew || !OrganizationModelImpl.COLUMN_BITMASK_ENABLED) {
405 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
406 }
407 else {
408 if ((organizationModelImpl.getColumnBitmask() &
409 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
410 Object[] args = new Object[] {
411 Long.valueOf(organizationModelImpl.getOriginalCompanyId())
412 };
413
414 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
415 args);
416 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
417 args);
418
419 args = new Object[] {
420 Long.valueOf(organizationModelImpl.getCompanyId())
421 };
422
423 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
424 args);
425 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
426 args);
427 }
428
429 if ((organizationModelImpl.getColumnBitmask() &
430 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LOCATIONS.getColumnBitmask()) != 0) {
431 Object[] args = new Object[] {
432 Long.valueOf(organizationModelImpl.getOriginalCompanyId())
433 };
434
435 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_LOCATIONS,
436 args);
437 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LOCATIONS,
438 args);
439
440 args = new Object[] {
441 Long.valueOf(organizationModelImpl.getCompanyId())
442 };
443
444 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_LOCATIONS,
445 args);
446 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LOCATIONS,
447 args);
448 }
449
450 if ((organizationModelImpl.getColumnBitmask() &
451 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P.getColumnBitmask()) != 0) {
452 Object[] args = new Object[] {
453 Long.valueOf(organizationModelImpl.getOriginalCompanyId()),
454 Long.valueOf(organizationModelImpl.getOriginalParentOrganizationId())
455 };
456
457 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_P, args);
458 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P,
459 args);
460
461 args = new Object[] {
462 Long.valueOf(organizationModelImpl.getCompanyId()),
463 Long.valueOf(organizationModelImpl.getParentOrganizationId())
464 };
465
466 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_P, args);
467 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P,
468 args);
469 }
470 }
471
472 EntityCacheUtil.putResult(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
473 OrganizationImpl.class, organization.getPrimaryKey(), organization);
474
475 if (isNew) {
476 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
477 new Object[] {
478 Long.valueOf(organization.getCompanyId()),
479
480 organization.getName()
481 }, organization);
482 }
483 else {
484 if ((organizationModelImpl.getColumnBitmask() &
485 FINDER_PATH_FETCH_BY_C_N.getColumnBitmask()) != 0) {
486 Object[] args = new Object[] {
487 Long.valueOf(organizationModelImpl.getOriginalCompanyId()),
488
489 organizationModelImpl.getOriginalName()
490 };
491
492 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N, args);
493 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N, args);
494
495 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
496 new Object[] {
497 Long.valueOf(organization.getCompanyId()),
498
499 organization.getName()
500 }, organization);
501 }
502 }
503
504 return organization;
505 }
506
507 protected Organization toUnwrappedModel(Organization organization) {
508 if (organization instanceof OrganizationImpl) {
509 return organization;
510 }
511
512 OrganizationImpl organizationImpl = new OrganizationImpl();
513
514 organizationImpl.setNew(organization.isNew());
515 organizationImpl.setPrimaryKey(organization.getPrimaryKey());
516
517 organizationImpl.setOrganizationId(organization.getOrganizationId());
518 organizationImpl.setCompanyId(organization.getCompanyId());
519 organizationImpl.setParentOrganizationId(organization.getParentOrganizationId());
520 organizationImpl.setTreePath(organization.getTreePath());
521 organizationImpl.setName(organization.getName());
522 organizationImpl.setType(organization.getType());
523 organizationImpl.setRecursable(organization.isRecursable());
524 organizationImpl.setRegionId(organization.getRegionId());
525 organizationImpl.setCountryId(organization.getCountryId());
526 organizationImpl.setStatusId(organization.getStatusId());
527 organizationImpl.setComments(organization.getComments());
528
529 return organizationImpl;
530 }
531
532
540 @Override
541 public Organization findByPrimaryKey(Serializable primaryKey)
542 throws NoSuchModelException, SystemException {
543 return findByPrimaryKey(((Long)primaryKey).longValue());
544 }
545
546
554 public Organization findByPrimaryKey(long organizationId)
555 throws NoSuchOrganizationException, SystemException {
556 Organization organization = fetchByPrimaryKey(organizationId);
557
558 if (organization == null) {
559 if (_log.isWarnEnabled()) {
560 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + organizationId);
561 }
562
563 throw new NoSuchOrganizationException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
564 organizationId);
565 }
566
567 return organization;
568 }
569
570
577 @Override
578 public Organization fetchByPrimaryKey(Serializable primaryKey)
579 throws SystemException {
580 return fetchByPrimaryKey(((Long)primaryKey).longValue());
581 }
582
583
590 public Organization fetchByPrimaryKey(long organizationId)
591 throws SystemException {
592 Organization organization = (Organization)EntityCacheUtil.getResult(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
593 OrganizationImpl.class, organizationId);
594
595 if (organization == _nullOrganization) {
596 return null;
597 }
598
599 if (organization == null) {
600 Session session = null;
601
602 boolean hasException = false;
603
604 try {
605 session = openSession();
606
607 organization = (Organization)session.get(OrganizationImpl.class,
608 Long.valueOf(organizationId));
609 }
610 catch (Exception e) {
611 hasException = true;
612
613 throw processException(e);
614 }
615 finally {
616 if (organization != null) {
617 cacheResult(organization);
618 }
619 else if (!hasException) {
620 EntityCacheUtil.putResult(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
621 OrganizationImpl.class, organizationId,
622 _nullOrganization);
623 }
624
625 closeSession(session);
626 }
627 }
628
629 return organization;
630 }
631
632
639 public List<Organization> findByCompanyId(long companyId)
640 throws SystemException {
641 return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
642 null);
643 }
644
645
658 public List<Organization> findByCompanyId(long companyId, int start, int end)
659 throws SystemException {
660 return findByCompanyId(companyId, start, end, null);
661 }
662
663
677 public List<Organization> findByCompanyId(long companyId, int start,
678 int end, OrderByComparator orderByComparator) throws SystemException {
679 FinderPath finderPath = null;
680 Object[] finderArgs = null;
681
682 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
683 (orderByComparator == null)) {
684 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
685 finderArgs = new Object[] { companyId };
686 }
687 else {
688 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
689 finderArgs = new Object[] { companyId, start, end, orderByComparator };
690 }
691
692 List<Organization> list = (List<Organization>)FinderCacheUtil.getResult(finderPath,
693 finderArgs, this);
694
695 if ((list != null) && !list.isEmpty()) {
696 for (Organization organization : list) {
697 if ((companyId != organization.getCompanyId())) {
698 list = null;
699
700 break;
701 }
702 }
703 }
704
705 if (list == null) {
706 StringBundler query = null;
707
708 if (orderByComparator != null) {
709 query = new StringBundler(3 +
710 (orderByComparator.getOrderByFields().length * 3));
711 }
712 else {
713 query = new StringBundler(3);
714 }
715
716 query.append(_SQL_SELECT_ORGANIZATION_WHERE);
717
718 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
719
720 if (orderByComparator != null) {
721 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
722 orderByComparator);
723 }
724
725 else {
726 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
727 }
728
729 String sql = query.toString();
730
731 Session session = null;
732
733 try {
734 session = openSession();
735
736 Query q = session.createQuery(sql);
737
738 QueryPos qPos = QueryPos.getInstance(q);
739
740 qPos.add(companyId);
741
742 list = (List<Organization>)QueryUtil.list(q, getDialect(),
743 start, end);
744 }
745 catch (Exception e) {
746 throw processException(e);
747 }
748 finally {
749 if (list == null) {
750 FinderCacheUtil.removeResult(finderPath, finderArgs);
751 }
752 else {
753 cacheResult(list);
754
755 FinderCacheUtil.putResult(finderPath, finderArgs, list);
756 }
757
758 closeSession(session);
759 }
760 }
761
762 return list;
763 }
764
765
778 public Organization findByCompanyId_First(long companyId,
779 OrderByComparator orderByComparator)
780 throws NoSuchOrganizationException, SystemException {
781 List<Organization> list = findByCompanyId(companyId, 0, 1,
782 orderByComparator);
783
784 if (list.isEmpty()) {
785 StringBundler msg = new StringBundler(4);
786
787 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
788
789 msg.append("companyId=");
790 msg.append(companyId);
791
792 msg.append(StringPool.CLOSE_CURLY_BRACE);
793
794 throw new NoSuchOrganizationException(msg.toString());
795 }
796 else {
797 return list.get(0);
798 }
799 }
800
801
814 public Organization findByCompanyId_Last(long companyId,
815 OrderByComparator orderByComparator)
816 throws NoSuchOrganizationException, SystemException {
817 int count = countByCompanyId(companyId);
818
819 List<Organization> list = findByCompanyId(companyId, count - 1, count,
820 orderByComparator);
821
822 if (list.isEmpty()) {
823 StringBundler msg = new StringBundler(4);
824
825 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
826
827 msg.append("companyId=");
828 msg.append(companyId);
829
830 msg.append(StringPool.CLOSE_CURLY_BRACE);
831
832 throw new NoSuchOrganizationException(msg.toString());
833 }
834 else {
835 return list.get(0);
836 }
837 }
838
839
853 public Organization[] findByCompanyId_PrevAndNext(long organizationId,
854 long companyId, OrderByComparator orderByComparator)
855 throws NoSuchOrganizationException, SystemException {
856 Organization organization = findByPrimaryKey(organizationId);
857
858 Session session = null;
859
860 try {
861 session = openSession();
862
863 Organization[] array = new OrganizationImpl[3];
864
865 array[0] = getByCompanyId_PrevAndNext(session, organization,
866 companyId, orderByComparator, true);
867
868 array[1] = organization;
869
870 array[2] = getByCompanyId_PrevAndNext(session, organization,
871 companyId, orderByComparator, false);
872
873 return array;
874 }
875 catch (Exception e) {
876 throw processException(e);
877 }
878 finally {
879 closeSession(session);
880 }
881 }
882
883 protected Organization getByCompanyId_PrevAndNext(Session session,
884 Organization organization, long companyId,
885 OrderByComparator orderByComparator, boolean previous) {
886 StringBundler query = null;
887
888 if (orderByComparator != null) {
889 query = new StringBundler(6 +
890 (orderByComparator.getOrderByFields().length * 6));
891 }
892 else {
893 query = new StringBundler(3);
894 }
895
896 query.append(_SQL_SELECT_ORGANIZATION_WHERE);
897
898 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
899
900 if (orderByComparator != null) {
901 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
902
903 if (orderByConditionFields.length > 0) {
904 query.append(WHERE_AND);
905 }
906
907 for (int i = 0; i < orderByConditionFields.length; i++) {
908 query.append(_ORDER_BY_ENTITY_ALIAS);
909 query.append(orderByConditionFields[i]);
910
911 if ((i + 1) < orderByConditionFields.length) {
912 if (orderByComparator.isAscending() ^ previous) {
913 query.append(WHERE_GREATER_THAN_HAS_NEXT);
914 }
915 else {
916 query.append(WHERE_LESSER_THAN_HAS_NEXT);
917 }
918 }
919 else {
920 if (orderByComparator.isAscending() ^ previous) {
921 query.append(WHERE_GREATER_THAN);
922 }
923 else {
924 query.append(WHERE_LESSER_THAN);
925 }
926 }
927 }
928
929 query.append(ORDER_BY_CLAUSE);
930
931 String[] orderByFields = orderByComparator.getOrderByFields();
932
933 for (int i = 0; i < orderByFields.length; i++) {
934 query.append(_ORDER_BY_ENTITY_ALIAS);
935 query.append(orderByFields[i]);
936
937 if ((i + 1) < orderByFields.length) {
938 if (orderByComparator.isAscending() ^ previous) {
939 query.append(ORDER_BY_ASC_HAS_NEXT);
940 }
941 else {
942 query.append(ORDER_BY_DESC_HAS_NEXT);
943 }
944 }
945 else {
946 if (orderByComparator.isAscending() ^ previous) {
947 query.append(ORDER_BY_ASC);
948 }
949 else {
950 query.append(ORDER_BY_DESC);
951 }
952 }
953 }
954 }
955
956 else {
957 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
958 }
959
960 String sql = query.toString();
961
962 Query q = session.createQuery(sql);
963
964 q.setFirstResult(0);
965 q.setMaxResults(2);
966
967 QueryPos qPos = QueryPos.getInstance(q);
968
969 qPos.add(companyId);
970
971 if (orderByComparator != null) {
972 Object[] values = orderByComparator.getOrderByConditionValues(organization);
973
974 for (Object value : values) {
975 qPos.add(value);
976 }
977 }
978
979 List<Organization> list = q.list();
980
981 if (list.size() == 2) {
982 return list.get(1);
983 }
984 else {
985 return null;
986 }
987 }
988
989
996 public List<Organization> filterFindByCompanyId(long companyId)
997 throws SystemException {
998 return filterFindByCompanyId(companyId, QueryUtil.ALL_POS,
999 QueryUtil.ALL_POS, null);
1000 }
1001
1002
1015 public List<Organization> filterFindByCompanyId(long companyId, int start,
1016 int end) throws SystemException {
1017 return filterFindByCompanyId(companyId, start, end, null);
1018 }
1019
1020
1034 public List<Organization> filterFindByCompanyId(long companyId, int start,
1035 int end, OrderByComparator orderByComparator) throws SystemException {
1036 if (!InlineSQLHelperUtil.isEnabled()) {
1037 return findByCompanyId(companyId, start, end, orderByComparator);
1038 }
1039
1040 StringBundler query = null;
1041
1042 if (orderByComparator != null) {
1043 query = new StringBundler(3 +
1044 (orderByComparator.getOrderByFields().length * 3));
1045 }
1046 else {
1047 query = new StringBundler(3);
1048 }
1049
1050 if (getDB().isSupportsInlineDistinct()) {
1051 query.append(_FILTER_SQL_SELECT_ORGANIZATION_WHERE);
1052 }
1053 else {
1054 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1);
1055 }
1056
1057 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1058
1059 if (!getDB().isSupportsInlineDistinct()) {
1060 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2);
1061 }
1062
1063 if (orderByComparator != null) {
1064 if (getDB().isSupportsInlineDistinct()) {
1065 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1066 orderByComparator);
1067 }
1068 else {
1069 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1070 orderByComparator);
1071 }
1072 }
1073
1074 else {
1075 if (getDB().isSupportsInlineDistinct()) {
1076 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
1077 }
1078 else {
1079 query.append(OrganizationModelImpl.ORDER_BY_SQL);
1080 }
1081 }
1082
1083 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1084 Organization.class.getName(),
1085 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1086
1087 Session session = null;
1088
1089 try {
1090 session = openSession();
1091
1092 SQLQuery q = session.createSQLQuery(sql);
1093
1094 if (getDB().isSupportsInlineDistinct()) {
1095 q.addEntity(_FILTER_ENTITY_ALIAS, OrganizationImpl.class);
1096 }
1097 else {
1098 q.addEntity(_FILTER_ENTITY_TABLE, OrganizationImpl.class);
1099 }
1100
1101 QueryPos qPos = QueryPos.getInstance(q);
1102
1103 qPos.add(companyId);
1104
1105 return (List<Organization>)QueryUtil.list(q, getDialect(), start,
1106 end);
1107 }
1108 catch (Exception e) {
1109 throw processException(e);
1110 }
1111 finally {
1112 closeSession(session);
1113 }
1114 }
1115
1116
1126 public Organization[] filterFindByCompanyId_PrevAndNext(
1127 long organizationId, long companyId, OrderByComparator orderByComparator)
1128 throws NoSuchOrganizationException, SystemException {
1129 if (!InlineSQLHelperUtil.isEnabled()) {
1130 return findByCompanyId_PrevAndNext(organizationId, companyId,
1131 orderByComparator);
1132 }
1133
1134 Organization organization = findByPrimaryKey(organizationId);
1135
1136 Session session = null;
1137
1138 try {
1139 session = openSession();
1140
1141 Organization[] array = new OrganizationImpl[3];
1142
1143 array[0] = filterGetByCompanyId_PrevAndNext(session, organization,
1144 companyId, orderByComparator, true);
1145
1146 array[1] = organization;
1147
1148 array[2] = filterGetByCompanyId_PrevAndNext(session, organization,
1149 companyId, orderByComparator, false);
1150
1151 return array;
1152 }
1153 catch (Exception e) {
1154 throw processException(e);
1155 }
1156 finally {
1157 closeSession(session);
1158 }
1159 }
1160
1161 protected Organization filterGetByCompanyId_PrevAndNext(Session session,
1162 Organization organization, long companyId,
1163 OrderByComparator orderByComparator, boolean previous) {
1164 StringBundler query = null;
1165
1166 if (orderByComparator != null) {
1167 query = new StringBundler(6 +
1168 (orderByComparator.getOrderByFields().length * 6));
1169 }
1170 else {
1171 query = new StringBundler(3);
1172 }
1173
1174 if (getDB().isSupportsInlineDistinct()) {
1175 query.append(_FILTER_SQL_SELECT_ORGANIZATION_WHERE);
1176 }
1177 else {
1178 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1);
1179 }
1180
1181 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1182
1183 if (!getDB().isSupportsInlineDistinct()) {
1184 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2);
1185 }
1186
1187 if (orderByComparator != null) {
1188 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1189
1190 if (orderByConditionFields.length > 0) {
1191 query.append(WHERE_AND);
1192 }
1193
1194 for (int i = 0; i < orderByConditionFields.length; i++) {
1195 if (getDB().isSupportsInlineDistinct()) {
1196 query.append(_ORDER_BY_ENTITY_ALIAS);
1197 }
1198 else {
1199 query.append(_ORDER_BY_ENTITY_TABLE);
1200 }
1201
1202 query.append(orderByConditionFields[i]);
1203
1204 if ((i + 1) < orderByConditionFields.length) {
1205 if (orderByComparator.isAscending() ^ previous) {
1206 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1207 }
1208 else {
1209 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1210 }
1211 }
1212 else {
1213 if (orderByComparator.isAscending() ^ previous) {
1214 query.append(WHERE_GREATER_THAN);
1215 }
1216 else {
1217 query.append(WHERE_LESSER_THAN);
1218 }
1219 }
1220 }
1221
1222 query.append(ORDER_BY_CLAUSE);
1223
1224 String[] orderByFields = orderByComparator.getOrderByFields();
1225
1226 for (int i = 0; i < orderByFields.length; i++) {
1227 if (getDB().isSupportsInlineDistinct()) {
1228 query.append(_ORDER_BY_ENTITY_ALIAS);
1229 }
1230 else {
1231 query.append(_ORDER_BY_ENTITY_TABLE);
1232 }
1233
1234 query.append(orderByFields[i]);
1235
1236 if ((i + 1) < orderByFields.length) {
1237 if (orderByComparator.isAscending() ^ previous) {
1238 query.append(ORDER_BY_ASC_HAS_NEXT);
1239 }
1240 else {
1241 query.append(ORDER_BY_DESC_HAS_NEXT);
1242 }
1243 }
1244 else {
1245 if (orderByComparator.isAscending() ^ previous) {
1246 query.append(ORDER_BY_ASC);
1247 }
1248 else {
1249 query.append(ORDER_BY_DESC);
1250 }
1251 }
1252 }
1253 }
1254
1255 else {
1256 if (getDB().isSupportsInlineDistinct()) {
1257 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
1258 }
1259 else {
1260 query.append(OrganizationModelImpl.ORDER_BY_SQL);
1261 }
1262 }
1263
1264 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1265 Organization.class.getName(),
1266 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1267
1268 SQLQuery q = session.createSQLQuery(sql);
1269
1270 q.setFirstResult(0);
1271 q.setMaxResults(2);
1272
1273 if (getDB().isSupportsInlineDistinct()) {
1274 q.addEntity(_FILTER_ENTITY_ALIAS, OrganizationImpl.class);
1275 }
1276 else {
1277 q.addEntity(_FILTER_ENTITY_TABLE, OrganizationImpl.class);
1278 }
1279
1280 QueryPos qPos = QueryPos.getInstance(q);
1281
1282 qPos.add(companyId);
1283
1284 if (orderByComparator != null) {
1285 Object[] values = orderByComparator.getOrderByConditionValues(organization);
1286
1287 for (Object value : values) {
1288 qPos.add(value);
1289 }
1290 }
1291
1292 List<Organization> list = q.list();
1293
1294 if (list.size() == 2) {
1295 return list.get(1);
1296 }
1297 else {
1298 return null;
1299 }
1300 }
1301
1302
1309 public List<Organization> findByLocations(long companyId)
1310 throws SystemException {
1311 return findByLocations(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1312 null);
1313 }
1314
1315
1328 public List<Organization> findByLocations(long companyId, int start, int end)
1329 throws SystemException {
1330 return findByLocations(companyId, start, end, null);
1331 }
1332
1333
1347 public List<Organization> findByLocations(long companyId, int start,
1348 int end, OrderByComparator orderByComparator) throws SystemException {
1349 FinderPath finderPath = null;
1350 Object[] finderArgs = null;
1351
1352 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1353 (orderByComparator == null)) {
1354 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LOCATIONS;
1355 finderArgs = new Object[] { companyId };
1356 }
1357 else {
1358 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_LOCATIONS;
1359 finderArgs = new Object[] { companyId, start, end, orderByComparator };
1360 }
1361
1362 List<Organization> list = (List<Organization>)FinderCacheUtil.getResult(finderPath,
1363 finderArgs, this);
1364
1365 if ((list != null) && !list.isEmpty()) {
1366 for (Organization organization : list) {
1367 if ((companyId != organization.getCompanyId())) {
1368 list = null;
1369
1370 break;
1371 }
1372 }
1373 }
1374
1375 if (list == null) {
1376 StringBundler query = null;
1377
1378 if (orderByComparator != null) {
1379 query = new StringBundler(3 +
1380 (orderByComparator.getOrderByFields().length * 3));
1381 }
1382 else {
1383 query = new StringBundler(3);
1384 }
1385
1386 query.append(_SQL_SELECT_ORGANIZATION_WHERE);
1387
1388 query.append(_FINDER_COLUMN_LOCATIONS_COMPANYID_2);
1389
1390 if (orderByComparator != null) {
1391 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1392 orderByComparator);
1393 }
1394
1395 else {
1396 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
1397 }
1398
1399 String sql = query.toString();
1400
1401 Session session = null;
1402
1403 try {
1404 session = openSession();
1405
1406 Query q = session.createQuery(sql);
1407
1408 QueryPos qPos = QueryPos.getInstance(q);
1409
1410 qPos.add(companyId);
1411
1412 list = (List<Organization>)QueryUtil.list(q, getDialect(),
1413 start, end);
1414 }
1415 catch (Exception e) {
1416 throw processException(e);
1417 }
1418 finally {
1419 if (list == null) {
1420 FinderCacheUtil.removeResult(finderPath, finderArgs);
1421 }
1422 else {
1423 cacheResult(list);
1424
1425 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1426 }
1427
1428 closeSession(session);
1429 }
1430 }
1431
1432 return list;
1433 }
1434
1435
1448 public Organization findByLocations_First(long companyId,
1449 OrderByComparator orderByComparator)
1450 throws NoSuchOrganizationException, SystemException {
1451 List<Organization> list = findByLocations(companyId, 0, 1,
1452 orderByComparator);
1453
1454 if (list.isEmpty()) {
1455 StringBundler msg = new StringBundler(4);
1456
1457 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1458
1459 msg.append("companyId=");
1460 msg.append(companyId);
1461
1462 msg.append(StringPool.CLOSE_CURLY_BRACE);
1463
1464 throw new NoSuchOrganizationException(msg.toString());
1465 }
1466 else {
1467 return list.get(0);
1468 }
1469 }
1470
1471
1484 public Organization findByLocations_Last(long companyId,
1485 OrderByComparator orderByComparator)
1486 throws NoSuchOrganizationException, SystemException {
1487 int count = countByLocations(companyId);
1488
1489 List<Organization> list = findByLocations(companyId, count - 1, count,
1490 orderByComparator);
1491
1492 if (list.isEmpty()) {
1493 StringBundler msg = new StringBundler(4);
1494
1495 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1496
1497 msg.append("companyId=");
1498 msg.append(companyId);
1499
1500 msg.append(StringPool.CLOSE_CURLY_BRACE);
1501
1502 throw new NoSuchOrganizationException(msg.toString());
1503 }
1504 else {
1505 return list.get(0);
1506 }
1507 }
1508
1509
1523 public Organization[] findByLocations_PrevAndNext(long organizationId,
1524 long companyId, OrderByComparator orderByComparator)
1525 throws NoSuchOrganizationException, SystemException {
1526 Organization organization = findByPrimaryKey(organizationId);
1527
1528 Session session = null;
1529
1530 try {
1531 session = openSession();
1532
1533 Organization[] array = new OrganizationImpl[3];
1534
1535 array[0] = getByLocations_PrevAndNext(session, organization,
1536 companyId, orderByComparator, true);
1537
1538 array[1] = organization;
1539
1540 array[2] = getByLocations_PrevAndNext(session, organization,
1541 companyId, orderByComparator, false);
1542
1543 return array;
1544 }
1545 catch (Exception e) {
1546 throw processException(e);
1547 }
1548 finally {
1549 closeSession(session);
1550 }
1551 }
1552
1553 protected Organization getByLocations_PrevAndNext(Session session,
1554 Organization organization, long companyId,
1555 OrderByComparator orderByComparator, boolean previous) {
1556 StringBundler query = null;
1557
1558 if (orderByComparator != null) {
1559 query = new StringBundler(6 +
1560 (orderByComparator.getOrderByFields().length * 6));
1561 }
1562 else {
1563 query = new StringBundler(3);
1564 }
1565
1566 query.append(_SQL_SELECT_ORGANIZATION_WHERE);
1567
1568 query.append(_FINDER_COLUMN_LOCATIONS_COMPANYID_2);
1569
1570 if (orderByComparator != null) {
1571 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1572
1573 if (orderByConditionFields.length > 0) {
1574 query.append(WHERE_AND);
1575 }
1576
1577 for (int i = 0; i < orderByConditionFields.length; i++) {
1578 query.append(_ORDER_BY_ENTITY_ALIAS);
1579 query.append(orderByConditionFields[i]);
1580
1581 if ((i + 1) < orderByConditionFields.length) {
1582 if (orderByComparator.isAscending() ^ previous) {
1583 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1584 }
1585 else {
1586 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1587 }
1588 }
1589 else {
1590 if (orderByComparator.isAscending() ^ previous) {
1591 query.append(WHERE_GREATER_THAN);
1592 }
1593 else {
1594 query.append(WHERE_LESSER_THAN);
1595 }
1596 }
1597 }
1598
1599 query.append(ORDER_BY_CLAUSE);
1600
1601 String[] orderByFields = orderByComparator.getOrderByFields();
1602
1603 for (int i = 0; i < orderByFields.length; i++) {
1604 query.append(_ORDER_BY_ENTITY_ALIAS);
1605 query.append(orderByFields[i]);
1606
1607 if ((i + 1) < orderByFields.length) {
1608 if (orderByComparator.isAscending() ^ previous) {
1609 query.append(ORDER_BY_ASC_HAS_NEXT);
1610 }
1611 else {
1612 query.append(ORDER_BY_DESC_HAS_NEXT);
1613 }
1614 }
1615 else {
1616 if (orderByComparator.isAscending() ^ previous) {
1617 query.append(ORDER_BY_ASC);
1618 }
1619 else {
1620 query.append(ORDER_BY_DESC);
1621 }
1622 }
1623 }
1624 }
1625
1626 else {
1627 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
1628 }
1629
1630 String sql = query.toString();
1631
1632 Query q = session.createQuery(sql);
1633
1634 q.setFirstResult(0);
1635 q.setMaxResults(2);
1636
1637 QueryPos qPos = QueryPos.getInstance(q);
1638
1639 qPos.add(companyId);
1640
1641 if (orderByComparator != null) {
1642 Object[] values = orderByComparator.getOrderByConditionValues(organization);
1643
1644 for (Object value : values) {
1645 qPos.add(value);
1646 }
1647 }
1648
1649 List<Organization> list = q.list();
1650
1651 if (list.size() == 2) {
1652 return list.get(1);
1653 }
1654 else {
1655 return null;
1656 }
1657 }
1658
1659
1666 public List<Organization> filterFindByLocations(long companyId)
1667 throws SystemException {
1668 return filterFindByLocations(companyId, QueryUtil.ALL_POS,
1669 QueryUtil.ALL_POS, null);
1670 }
1671
1672
1685 public List<Organization> filterFindByLocations(long companyId, int start,
1686 int end) throws SystemException {
1687 return filterFindByLocations(companyId, start, end, null);
1688 }
1689
1690
1704 public List<Organization> filterFindByLocations(long companyId, int start,
1705 int end, OrderByComparator orderByComparator) throws SystemException {
1706 if (!InlineSQLHelperUtil.isEnabled()) {
1707 return findByLocations(companyId, start, end, orderByComparator);
1708 }
1709
1710 StringBundler query = null;
1711
1712 if (orderByComparator != null) {
1713 query = new StringBundler(3 +
1714 (orderByComparator.getOrderByFields().length * 3));
1715 }
1716 else {
1717 query = new StringBundler(3);
1718 }
1719
1720 if (getDB().isSupportsInlineDistinct()) {
1721 query.append(_FILTER_SQL_SELECT_ORGANIZATION_WHERE);
1722 }
1723 else {
1724 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1);
1725 }
1726
1727 query.append(_FINDER_COLUMN_LOCATIONS_COMPANYID_2);
1728
1729 if (!getDB().isSupportsInlineDistinct()) {
1730 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2);
1731 }
1732
1733 if (orderByComparator != null) {
1734 if (getDB().isSupportsInlineDistinct()) {
1735 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1736 orderByComparator);
1737 }
1738 else {
1739 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1740 orderByComparator);
1741 }
1742 }
1743
1744 else {
1745 if (getDB().isSupportsInlineDistinct()) {
1746 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
1747 }
1748 else {
1749 query.append(OrganizationModelImpl.ORDER_BY_SQL);
1750 }
1751 }
1752
1753 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1754 Organization.class.getName(),
1755 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1756
1757 Session session = null;
1758
1759 try {
1760 session = openSession();
1761
1762 SQLQuery q = session.createSQLQuery(sql);
1763
1764 if (getDB().isSupportsInlineDistinct()) {
1765 q.addEntity(_FILTER_ENTITY_ALIAS, OrganizationImpl.class);
1766 }
1767 else {
1768 q.addEntity(_FILTER_ENTITY_TABLE, OrganizationImpl.class);
1769 }
1770
1771 QueryPos qPos = QueryPos.getInstance(q);
1772
1773 qPos.add(companyId);
1774
1775 return (List<Organization>)QueryUtil.list(q, getDialect(), start,
1776 end);
1777 }
1778 catch (Exception e) {
1779 throw processException(e);
1780 }
1781 finally {
1782 closeSession(session);
1783 }
1784 }
1785
1786
1796 public Organization[] filterFindByLocations_PrevAndNext(
1797 long organizationId, long companyId, OrderByComparator orderByComparator)
1798 throws NoSuchOrganizationException, SystemException {
1799 if (!InlineSQLHelperUtil.isEnabled()) {
1800 return findByLocations_PrevAndNext(organizationId, companyId,
1801 orderByComparator);
1802 }
1803
1804 Organization organization = findByPrimaryKey(organizationId);
1805
1806 Session session = null;
1807
1808 try {
1809 session = openSession();
1810
1811 Organization[] array = new OrganizationImpl[3];
1812
1813 array[0] = filterGetByLocations_PrevAndNext(session, organization,
1814 companyId, orderByComparator, true);
1815
1816 array[1] = organization;
1817
1818 array[2] = filterGetByLocations_PrevAndNext(session, organization,
1819 companyId, orderByComparator, false);
1820
1821 return array;
1822 }
1823 catch (Exception e) {
1824 throw processException(e);
1825 }
1826 finally {
1827 closeSession(session);
1828 }
1829 }
1830
1831 protected Organization filterGetByLocations_PrevAndNext(Session session,
1832 Organization organization, long companyId,
1833 OrderByComparator orderByComparator, boolean previous) {
1834 StringBundler query = null;
1835
1836 if (orderByComparator != null) {
1837 query = new StringBundler(6 +
1838 (orderByComparator.getOrderByFields().length * 6));
1839 }
1840 else {
1841 query = new StringBundler(3);
1842 }
1843
1844 if (getDB().isSupportsInlineDistinct()) {
1845 query.append(_FILTER_SQL_SELECT_ORGANIZATION_WHERE);
1846 }
1847 else {
1848 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1);
1849 }
1850
1851 query.append(_FINDER_COLUMN_LOCATIONS_COMPANYID_2);
1852
1853 if (!getDB().isSupportsInlineDistinct()) {
1854 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2);
1855 }
1856
1857 if (orderByComparator != null) {
1858 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1859
1860 if (orderByConditionFields.length > 0) {
1861 query.append(WHERE_AND);
1862 }
1863
1864 for (int i = 0; i < orderByConditionFields.length; i++) {
1865 if (getDB().isSupportsInlineDistinct()) {
1866 query.append(_ORDER_BY_ENTITY_ALIAS);
1867 }
1868 else {
1869 query.append(_ORDER_BY_ENTITY_TABLE);
1870 }
1871
1872 query.append(orderByConditionFields[i]);
1873
1874 if ((i + 1) < orderByConditionFields.length) {
1875 if (orderByComparator.isAscending() ^ previous) {
1876 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1877 }
1878 else {
1879 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1880 }
1881 }
1882 else {
1883 if (orderByComparator.isAscending() ^ previous) {
1884 query.append(WHERE_GREATER_THAN);
1885 }
1886 else {
1887 query.append(WHERE_LESSER_THAN);
1888 }
1889 }
1890 }
1891
1892 query.append(ORDER_BY_CLAUSE);
1893
1894 String[] orderByFields = orderByComparator.getOrderByFields();
1895
1896 for (int i = 0; i < orderByFields.length; i++) {
1897 if (getDB().isSupportsInlineDistinct()) {
1898 query.append(_ORDER_BY_ENTITY_ALIAS);
1899 }
1900 else {
1901 query.append(_ORDER_BY_ENTITY_TABLE);
1902 }
1903
1904 query.append(orderByFields[i]);
1905
1906 if ((i + 1) < orderByFields.length) {
1907 if (orderByComparator.isAscending() ^ previous) {
1908 query.append(ORDER_BY_ASC_HAS_NEXT);
1909 }
1910 else {
1911 query.append(ORDER_BY_DESC_HAS_NEXT);
1912 }
1913 }
1914 else {
1915 if (orderByComparator.isAscending() ^ previous) {
1916 query.append(ORDER_BY_ASC);
1917 }
1918 else {
1919 query.append(ORDER_BY_DESC);
1920 }
1921 }
1922 }
1923 }
1924
1925 else {
1926 if (getDB().isSupportsInlineDistinct()) {
1927 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
1928 }
1929 else {
1930 query.append(OrganizationModelImpl.ORDER_BY_SQL);
1931 }
1932 }
1933
1934 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1935 Organization.class.getName(),
1936 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1937
1938 SQLQuery q = session.createSQLQuery(sql);
1939
1940 q.setFirstResult(0);
1941 q.setMaxResults(2);
1942
1943 if (getDB().isSupportsInlineDistinct()) {
1944 q.addEntity(_FILTER_ENTITY_ALIAS, OrganizationImpl.class);
1945 }
1946 else {
1947 q.addEntity(_FILTER_ENTITY_TABLE, OrganizationImpl.class);
1948 }
1949
1950 QueryPos qPos = QueryPos.getInstance(q);
1951
1952 qPos.add(companyId);
1953
1954 if (orderByComparator != null) {
1955 Object[] values = orderByComparator.getOrderByConditionValues(organization);
1956
1957 for (Object value : values) {
1958 qPos.add(value);
1959 }
1960 }
1961
1962 List<Organization> list = q.list();
1963
1964 if (list.size() == 2) {
1965 return list.get(1);
1966 }
1967 else {
1968 return null;
1969 }
1970 }
1971
1972
1980 public List<Organization> findByC_P(long companyId,
1981 long parentOrganizationId) throws SystemException {
1982 return findByC_P(companyId, parentOrganizationId, QueryUtil.ALL_POS,
1983 QueryUtil.ALL_POS, null);
1984 }
1985
1986
2000 public List<Organization> findByC_P(long companyId,
2001 long parentOrganizationId, int start, int end)
2002 throws SystemException {
2003 return findByC_P(companyId, parentOrganizationId, start, end, null);
2004 }
2005
2006
2021 public List<Organization> findByC_P(long companyId,
2022 long parentOrganizationId, int start, int end,
2023 OrderByComparator orderByComparator) throws SystemException {
2024 FinderPath finderPath = null;
2025 Object[] finderArgs = null;
2026
2027 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2028 (orderByComparator == null)) {
2029 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P;
2030 finderArgs = new Object[] { companyId, parentOrganizationId };
2031 }
2032 else {
2033 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_P;
2034 finderArgs = new Object[] {
2035 companyId, parentOrganizationId,
2036
2037 start, end, orderByComparator
2038 };
2039 }
2040
2041 List<Organization> list = (List<Organization>)FinderCacheUtil.getResult(finderPath,
2042 finderArgs, this);
2043
2044 if ((list != null) && !list.isEmpty()) {
2045 for (Organization organization : list) {
2046 if ((companyId != organization.getCompanyId()) ||
2047 (parentOrganizationId != organization.getParentOrganizationId())) {
2048 list = null;
2049
2050 break;
2051 }
2052 }
2053 }
2054
2055 if (list == null) {
2056 StringBundler query = null;
2057
2058 if (orderByComparator != null) {
2059 query = new StringBundler(4 +
2060 (orderByComparator.getOrderByFields().length * 3));
2061 }
2062 else {
2063 query = new StringBundler(4);
2064 }
2065
2066 query.append(_SQL_SELECT_ORGANIZATION_WHERE);
2067
2068 query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
2069
2070 query.append(_FINDER_COLUMN_C_P_PARENTORGANIZATIONID_2);
2071
2072 if (orderByComparator != null) {
2073 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2074 orderByComparator);
2075 }
2076
2077 else {
2078 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
2079 }
2080
2081 String sql = query.toString();
2082
2083 Session session = null;
2084
2085 try {
2086 session = openSession();
2087
2088 Query q = session.createQuery(sql);
2089
2090 QueryPos qPos = QueryPos.getInstance(q);
2091
2092 qPos.add(companyId);
2093
2094 qPos.add(parentOrganizationId);
2095
2096 list = (List<Organization>)QueryUtil.list(q, getDialect(),
2097 start, end);
2098 }
2099 catch (Exception e) {
2100 throw processException(e);
2101 }
2102 finally {
2103 if (list == null) {
2104 FinderCacheUtil.removeResult(finderPath, finderArgs);
2105 }
2106 else {
2107 cacheResult(list);
2108
2109 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2110 }
2111
2112 closeSession(session);
2113 }
2114 }
2115
2116 return list;
2117 }
2118
2119
2133 public Organization findByC_P_First(long companyId,
2134 long parentOrganizationId, OrderByComparator orderByComparator)
2135 throws NoSuchOrganizationException, SystemException {
2136 List<Organization> list = findByC_P(companyId, parentOrganizationId, 0,
2137 1, orderByComparator);
2138
2139 if (list.isEmpty()) {
2140 StringBundler msg = new StringBundler(6);
2141
2142 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2143
2144 msg.append("companyId=");
2145 msg.append(companyId);
2146
2147 msg.append(", parentOrganizationId=");
2148 msg.append(parentOrganizationId);
2149
2150 msg.append(StringPool.CLOSE_CURLY_BRACE);
2151
2152 throw new NoSuchOrganizationException(msg.toString());
2153 }
2154 else {
2155 return list.get(0);
2156 }
2157 }
2158
2159
2173 public Organization findByC_P_Last(long companyId,
2174 long parentOrganizationId, OrderByComparator orderByComparator)
2175 throws NoSuchOrganizationException, SystemException {
2176 int count = countByC_P(companyId, parentOrganizationId);
2177
2178 List<Organization> list = findByC_P(companyId, parentOrganizationId,
2179 count - 1, count, orderByComparator);
2180
2181 if (list.isEmpty()) {
2182 StringBundler msg = new StringBundler(6);
2183
2184 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2185
2186 msg.append("companyId=");
2187 msg.append(companyId);
2188
2189 msg.append(", parentOrganizationId=");
2190 msg.append(parentOrganizationId);
2191
2192 msg.append(StringPool.CLOSE_CURLY_BRACE);
2193
2194 throw new NoSuchOrganizationException(msg.toString());
2195 }
2196 else {
2197 return list.get(0);
2198 }
2199 }
2200
2201
2216 public Organization[] findByC_P_PrevAndNext(long organizationId,
2217 long companyId, long parentOrganizationId,
2218 OrderByComparator orderByComparator)
2219 throws NoSuchOrganizationException, SystemException {
2220 Organization organization = findByPrimaryKey(organizationId);
2221
2222 Session session = null;
2223
2224 try {
2225 session = openSession();
2226
2227 Organization[] array = new OrganizationImpl[3];
2228
2229 array[0] = getByC_P_PrevAndNext(session, organization, companyId,
2230 parentOrganizationId, orderByComparator, true);
2231
2232 array[1] = organization;
2233
2234 array[2] = getByC_P_PrevAndNext(session, organization, companyId,
2235 parentOrganizationId, orderByComparator, false);
2236
2237 return array;
2238 }
2239 catch (Exception e) {
2240 throw processException(e);
2241 }
2242 finally {
2243 closeSession(session);
2244 }
2245 }
2246
2247 protected Organization getByC_P_PrevAndNext(Session session,
2248 Organization organization, long companyId, long parentOrganizationId,
2249 OrderByComparator orderByComparator, boolean previous) {
2250 StringBundler query = null;
2251
2252 if (orderByComparator != null) {
2253 query = new StringBundler(6 +
2254 (orderByComparator.getOrderByFields().length * 6));
2255 }
2256 else {
2257 query = new StringBundler(3);
2258 }
2259
2260 query.append(_SQL_SELECT_ORGANIZATION_WHERE);
2261
2262 query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
2263
2264 query.append(_FINDER_COLUMN_C_P_PARENTORGANIZATIONID_2);
2265
2266 if (orderByComparator != null) {
2267 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2268
2269 if (orderByConditionFields.length > 0) {
2270 query.append(WHERE_AND);
2271 }
2272
2273 for (int i = 0; i < orderByConditionFields.length; i++) {
2274 query.append(_ORDER_BY_ENTITY_ALIAS);
2275 query.append(orderByConditionFields[i]);
2276
2277 if ((i + 1) < orderByConditionFields.length) {
2278 if (orderByComparator.isAscending() ^ previous) {
2279 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2280 }
2281 else {
2282 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2283 }
2284 }
2285 else {
2286 if (orderByComparator.isAscending() ^ previous) {
2287 query.append(WHERE_GREATER_THAN);
2288 }
2289 else {
2290 query.append(WHERE_LESSER_THAN);
2291 }
2292 }
2293 }
2294
2295 query.append(ORDER_BY_CLAUSE);
2296
2297 String[] orderByFields = orderByComparator.getOrderByFields();
2298
2299 for (int i = 0; i < orderByFields.length; i++) {
2300 query.append(_ORDER_BY_ENTITY_ALIAS);
2301 query.append(orderByFields[i]);
2302
2303 if ((i + 1) < orderByFields.length) {
2304 if (orderByComparator.isAscending() ^ previous) {
2305 query.append(ORDER_BY_ASC_HAS_NEXT);
2306 }
2307 else {
2308 query.append(ORDER_BY_DESC_HAS_NEXT);
2309 }
2310 }
2311 else {
2312 if (orderByComparator.isAscending() ^ previous) {
2313 query.append(ORDER_BY_ASC);
2314 }
2315 else {
2316 query.append(ORDER_BY_DESC);
2317 }
2318 }
2319 }
2320 }
2321
2322 else {
2323 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
2324 }
2325
2326 String sql = query.toString();
2327
2328 Query q = session.createQuery(sql);
2329
2330 q.setFirstResult(0);
2331 q.setMaxResults(2);
2332
2333 QueryPos qPos = QueryPos.getInstance(q);
2334
2335 qPos.add(companyId);
2336
2337 qPos.add(parentOrganizationId);
2338
2339 if (orderByComparator != null) {
2340 Object[] values = orderByComparator.getOrderByConditionValues(organization);
2341
2342 for (Object value : values) {
2343 qPos.add(value);
2344 }
2345 }
2346
2347 List<Organization> list = q.list();
2348
2349 if (list.size() == 2) {
2350 return list.get(1);
2351 }
2352 else {
2353 return null;
2354 }
2355 }
2356
2357
2365 public List<Organization> filterFindByC_P(long companyId,
2366 long parentOrganizationId) throws SystemException {
2367 return filterFindByC_P(companyId, parentOrganizationId,
2368 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2369 }
2370
2371
2385 public List<Organization> filterFindByC_P(long companyId,
2386 long parentOrganizationId, int start, int end)
2387 throws SystemException {
2388 return filterFindByC_P(companyId, parentOrganizationId, start, end, null);
2389 }
2390
2391
2406 public List<Organization> filterFindByC_P(long companyId,
2407 long parentOrganizationId, int start, int end,
2408 OrderByComparator orderByComparator) throws SystemException {
2409 if (!InlineSQLHelperUtil.isEnabled()) {
2410 return findByC_P(companyId, parentOrganizationId, start, end,
2411 orderByComparator);
2412 }
2413
2414 StringBundler query = null;
2415
2416 if (orderByComparator != null) {
2417 query = new StringBundler(4 +
2418 (orderByComparator.getOrderByFields().length * 3));
2419 }
2420 else {
2421 query = new StringBundler(4);
2422 }
2423
2424 if (getDB().isSupportsInlineDistinct()) {
2425 query.append(_FILTER_SQL_SELECT_ORGANIZATION_WHERE);
2426 }
2427 else {
2428 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1);
2429 }
2430
2431 query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
2432
2433 query.append(_FINDER_COLUMN_C_P_PARENTORGANIZATIONID_2);
2434
2435 if (!getDB().isSupportsInlineDistinct()) {
2436 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2);
2437 }
2438
2439 if (orderByComparator != null) {
2440 if (getDB().isSupportsInlineDistinct()) {
2441 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2442 orderByComparator);
2443 }
2444 else {
2445 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
2446 orderByComparator);
2447 }
2448 }
2449
2450 else {
2451 if (getDB().isSupportsInlineDistinct()) {
2452 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
2453 }
2454 else {
2455 query.append(OrganizationModelImpl.ORDER_BY_SQL);
2456 }
2457 }
2458
2459 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2460 Organization.class.getName(),
2461 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2462
2463 Session session = null;
2464
2465 try {
2466 session = openSession();
2467
2468 SQLQuery q = session.createSQLQuery(sql);
2469
2470 if (getDB().isSupportsInlineDistinct()) {
2471 q.addEntity(_FILTER_ENTITY_ALIAS, OrganizationImpl.class);
2472 }
2473 else {
2474 q.addEntity(_FILTER_ENTITY_TABLE, OrganizationImpl.class);
2475 }
2476
2477 QueryPos qPos = QueryPos.getInstance(q);
2478
2479 qPos.add(companyId);
2480
2481 qPos.add(parentOrganizationId);
2482
2483 return (List<Organization>)QueryUtil.list(q, getDialect(), start,
2484 end);
2485 }
2486 catch (Exception e) {
2487 throw processException(e);
2488 }
2489 finally {
2490 closeSession(session);
2491 }
2492 }
2493
2494
2505 public Organization[] filterFindByC_P_PrevAndNext(long organizationId,
2506 long companyId, long parentOrganizationId,
2507 OrderByComparator orderByComparator)
2508 throws NoSuchOrganizationException, SystemException {
2509 if (!InlineSQLHelperUtil.isEnabled()) {
2510 return findByC_P_PrevAndNext(organizationId, companyId,
2511 parentOrganizationId, orderByComparator);
2512 }
2513
2514 Organization organization = findByPrimaryKey(organizationId);
2515
2516 Session session = null;
2517
2518 try {
2519 session = openSession();
2520
2521 Organization[] array = new OrganizationImpl[3];
2522
2523 array[0] = filterGetByC_P_PrevAndNext(session, organization,
2524 companyId, parentOrganizationId, orderByComparator, true);
2525
2526 array[1] = organization;
2527
2528 array[2] = filterGetByC_P_PrevAndNext(session, organization,
2529 companyId, parentOrganizationId, orderByComparator, false);
2530
2531 return array;
2532 }
2533 catch (Exception e) {
2534 throw processException(e);
2535 }
2536 finally {
2537 closeSession(session);
2538 }
2539 }
2540
2541 protected Organization filterGetByC_P_PrevAndNext(Session session,
2542 Organization organization, long companyId, long parentOrganizationId,
2543 OrderByComparator orderByComparator, boolean previous) {
2544 StringBundler query = null;
2545
2546 if (orderByComparator != null) {
2547 query = new StringBundler(6 +
2548 (orderByComparator.getOrderByFields().length * 6));
2549 }
2550 else {
2551 query = new StringBundler(3);
2552 }
2553
2554 if (getDB().isSupportsInlineDistinct()) {
2555 query.append(_FILTER_SQL_SELECT_ORGANIZATION_WHERE);
2556 }
2557 else {
2558 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1);
2559 }
2560
2561 query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
2562
2563 query.append(_FINDER_COLUMN_C_P_PARENTORGANIZATIONID_2);
2564
2565 if (!getDB().isSupportsInlineDistinct()) {
2566 query.append(_FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2);
2567 }
2568
2569 if (orderByComparator != null) {
2570 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2571
2572 if (orderByConditionFields.length > 0) {
2573 query.append(WHERE_AND);
2574 }
2575
2576 for (int i = 0; i < orderByConditionFields.length; i++) {
2577 if (getDB().isSupportsInlineDistinct()) {
2578 query.append(_ORDER_BY_ENTITY_ALIAS);
2579 }
2580 else {
2581 query.append(_ORDER_BY_ENTITY_TABLE);
2582 }
2583
2584 query.append(orderByConditionFields[i]);
2585
2586 if ((i + 1) < orderByConditionFields.length) {
2587 if (orderByComparator.isAscending() ^ previous) {
2588 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2589 }
2590 else {
2591 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2592 }
2593 }
2594 else {
2595 if (orderByComparator.isAscending() ^ previous) {
2596 query.append(WHERE_GREATER_THAN);
2597 }
2598 else {
2599 query.append(WHERE_LESSER_THAN);
2600 }
2601 }
2602 }
2603
2604 query.append(ORDER_BY_CLAUSE);
2605
2606 String[] orderByFields = orderByComparator.getOrderByFields();
2607
2608 for (int i = 0; i < orderByFields.length; i++) {
2609 if (getDB().isSupportsInlineDistinct()) {
2610 query.append(_ORDER_BY_ENTITY_ALIAS);
2611 }
2612 else {
2613 query.append(_ORDER_BY_ENTITY_TABLE);
2614 }
2615
2616 query.append(orderByFields[i]);
2617
2618 if ((i + 1) < orderByFields.length) {
2619 if (orderByComparator.isAscending() ^ previous) {
2620 query.append(ORDER_BY_ASC_HAS_NEXT);
2621 }
2622 else {
2623 query.append(ORDER_BY_DESC_HAS_NEXT);
2624 }
2625 }
2626 else {
2627 if (orderByComparator.isAscending() ^ previous) {
2628 query.append(ORDER_BY_ASC);
2629 }
2630 else {
2631 query.append(ORDER_BY_DESC);
2632 }
2633 }
2634 }
2635 }
2636
2637 else {
2638 if (getDB().isSupportsInlineDistinct()) {
2639 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
2640 }
2641 else {
2642 query.append(OrganizationModelImpl.ORDER_BY_SQL);
2643 }
2644 }
2645
2646 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2647 Organization.class.getName(),
2648 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2649
2650 SQLQuery q = session.createSQLQuery(sql);
2651
2652 q.setFirstResult(0);
2653 q.setMaxResults(2);
2654
2655 if (getDB().isSupportsInlineDistinct()) {
2656 q.addEntity(_FILTER_ENTITY_ALIAS, OrganizationImpl.class);
2657 }
2658 else {
2659 q.addEntity(_FILTER_ENTITY_TABLE, OrganizationImpl.class);
2660 }
2661
2662 QueryPos qPos = QueryPos.getInstance(q);
2663
2664 qPos.add(companyId);
2665
2666 qPos.add(parentOrganizationId);
2667
2668 if (orderByComparator != null) {
2669 Object[] values = orderByComparator.getOrderByConditionValues(organization);
2670
2671 for (Object value : values) {
2672 qPos.add(value);
2673 }
2674 }
2675
2676 List<Organization> list = q.list();
2677
2678 if (list.size() == 2) {
2679 return list.get(1);
2680 }
2681 else {
2682 return null;
2683 }
2684 }
2685
2686
2695 public Organization findByC_N(long companyId, String name)
2696 throws NoSuchOrganizationException, SystemException {
2697 Organization organization = fetchByC_N(companyId, name);
2698
2699 if (organization == null) {
2700 StringBundler msg = new StringBundler(6);
2701
2702 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2703
2704 msg.append("companyId=");
2705 msg.append(companyId);
2706
2707 msg.append(", name=");
2708 msg.append(name);
2709
2710 msg.append(StringPool.CLOSE_CURLY_BRACE);
2711
2712 if (_log.isWarnEnabled()) {
2713 _log.warn(msg.toString());
2714 }
2715
2716 throw new NoSuchOrganizationException(msg.toString());
2717 }
2718
2719 return organization;
2720 }
2721
2722
2730 public Organization fetchByC_N(long companyId, String name)
2731 throws SystemException {
2732 return fetchByC_N(companyId, name, true);
2733 }
2734
2735
2744 public Organization fetchByC_N(long companyId, String name,
2745 boolean retrieveFromCache) throws SystemException {
2746 Object[] finderArgs = new Object[] { companyId, name };
2747
2748 Object result = null;
2749
2750 if (retrieveFromCache) {
2751 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_N,
2752 finderArgs, this);
2753 }
2754
2755 if (result instanceof Organization) {
2756 Organization organization = (Organization)result;
2757
2758 if ((companyId != organization.getCompanyId()) ||
2759 !Validator.equals(name, organization.getName())) {
2760 result = null;
2761 }
2762 }
2763
2764 if (result == null) {
2765 StringBundler query = new StringBundler(4);
2766
2767 query.append(_SQL_SELECT_ORGANIZATION_WHERE);
2768
2769 query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
2770
2771 if (name == null) {
2772 query.append(_FINDER_COLUMN_C_N_NAME_1);
2773 }
2774 else {
2775 if (name.equals(StringPool.BLANK)) {
2776 query.append(_FINDER_COLUMN_C_N_NAME_3);
2777 }
2778 else {
2779 query.append(_FINDER_COLUMN_C_N_NAME_2);
2780 }
2781 }
2782
2783 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
2784
2785 String sql = query.toString();
2786
2787 Session session = null;
2788
2789 try {
2790 session = openSession();
2791
2792 Query q = session.createQuery(sql);
2793
2794 QueryPos qPos = QueryPos.getInstance(q);
2795
2796 qPos.add(companyId);
2797
2798 if (name != null) {
2799 qPos.add(name);
2800 }
2801
2802 List<Organization> list = q.list();
2803
2804 result = list;
2805
2806 Organization organization = null;
2807
2808 if (list.isEmpty()) {
2809 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
2810 finderArgs, list);
2811 }
2812 else {
2813 organization = list.get(0);
2814
2815 cacheResult(organization);
2816
2817 if ((organization.getCompanyId() != companyId) ||
2818 (organization.getName() == null) ||
2819 !organization.getName().equals(name)) {
2820 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
2821 finderArgs, organization);
2822 }
2823 }
2824
2825 return organization;
2826 }
2827 catch (Exception e) {
2828 throw processException(e);
2829 }
2830 finally {
2831 if (result == null) {
2832 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N,
2833 finderArgs);
2834 }
2835
2836 closeSession(session);
2837 }
2838 }
2839 else {
2840 if (result instanceof List<?>) {
2841 return null;
2842 }
2843 else {
2844 return (Organization)result;
2845 }
2846 }
2847 }
2848
2849
2855 public List<Organization> findAll() throws SystemException {
2856 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2857 }
2858
2859
2871 public List<Organization> findAll(int start, int end)
2872 throws SystemException {
2873 return findAll(start, end, null);
2874 }
2875
2876
2889 public List<Organization> findAll(int start, int end,
2890 OrderByComparator orderByComparator) throws SystemException {
2891 FinderPath finderPath = null;
2892 Object[] finderArgs = new Object[] { start, end, orderByComparator };
2893
2894 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2895 (orderByComparator == null)) {
2896 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2897 finderArgs = FINDER_ARGS_EMPTY;
2898 }
2899 else {
2900 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2901 finderArgs = new Object[] { start, end, orderByComparator };
2902 }
2903
2904 List<Organization> list = (List<Organization>)FinderCacheUtil.getResult(finderPath,
2905 finderArgs, this);
2906
2907 if (list == null) {
2908 StringBundler query = null;
2909 String sql = null;
2910
2911 if (orderByComparator != null) {
2912 query = new StringBundler(2 +
2913 (orderByComparator.getOrderByFields().length * 3));
2914
2915 query.append(_SQL_SELECT_ORGANIZATION);
2916
2917 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2918 orderByComparator);
2919
2920 sql = query.toString();
2921 }
2922 else {
2923 sql = _SQL_SELECT_ORGANIZATION.concat(OrganizationModelImpl.ORDER_BY_JPQL);
2924 }
2925
2926 Session session = null;
2927
2928 try {
2929 session = openSession();
2930
2931 Query q = session.createQuery(sql);
2932
2933 if (orderByComparator == null) {
2934 list = (List<Organization>)QueryUtil.list(q, getDialect(),
2935 start, end, false);
2936
2937 Collections.sort(list);
2938 }
2939 else {
2940 list = (List<Organization>)QueryUtil.list(q, getDialect(),
2941 start, end);
2942 }
2943 }
2944 catch (Exception e) {
2945 throw processException(e);
2946 }
2947 finally {
2948 if (list == null) {
2949 FinderCacheUtil.removeResult(finderPath, finderArgs);
2950 }
2951 else {
2952 cacheResult(list);
2953
2954 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2955 }
2956
2957 closeSession(session);
2958 }
2959 }
2960
2961 return list;
2962 }
2963
2964
2970 public void removeByCompanyId(long companyId) throws SystemException {
2971 for (Organization organization : findByCompanyId(companyId)) {
2972 remove(organization);
2973 }
2974 }
2975
2976
2982 public void removeByLocations(long companyId) throws SystemException {
2983 for (Organization organization : findByLocations(companyId)) {
2984 remove(organization);
2985 }
2986 }
2987
2988
2995 public void removeByC_P(long companyId, long parentOrganizationId)
2996 throws SystemException {
2997 for (Organization organization : findByC_P(companyId,
2998 parentOrganizationId)) {
2999 remove(organization);
3000 }
3001 }
3002
3003
3010 public void removeByC_N(long companyId, String name)
3011 throws NoSuchOrganizationException, SystemException {
3012 Organization organization = findByC_N(companyId, name);
3013
3014 remove(organization);
3015 }
3016
3017
3022 public void removeAll() throws SystemException {
3023 for (Organization organization : findAll()) {
3024 remove(organization);
3025 }
3026 }
3027
3028
3035 public int countByCompanyId(long companyId) throws SystemException {
3036 Object[] finderArgs = new Object[] { companyId };
3037
3038 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
3039 finderArgs, this);
3040
3041 if (count == null) {
3042 StringBundler query = new StringBundler(2);
3043
3044 query.append(_SQL_COUNT_ORGANIZATION_WHERE);
3045
3046 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
3047
3048 String sql = query.toString();
3049
3050 Session session = null;
3051
3052 try {
3053 session = openSession();
3054
3055 Query q = session.createQuery(sql);
3056
3057 QueryPos qPos = QueryPos.getInstance(q);
3058
3059 qPos.add(companyId);
3060
3061 count = (Long)q.uniqueResult();
3062 }
3063 catch (Exception e) {
3064 throw processException(e);
3065 }
3066 finally {
3067 if (count == null) {
3068 count = Long.valueOf(0);
3069 }
3070
3071 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
3072 finderArgs, count);
3073
3074 closeSession(session);
3075 }
3076 }
3077
3078 return count.intValue();
3079 }
3080
3081
3088 public int filterCountByCompanyId(long companyId) throws SystemException {
3089 if (!InlineSQLHelperUtil.isEnabled()) {
3090 return countByCompanyId(companyId);
3091 }
3092
3093 StringBundler query = new StringBundler(2);
3094
3095 query.append(_FILTER_SQL_COUNT_ORGANIZATION_WHERE);
3096
3097 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
3098
3099 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3100 Organization.class.getName(),
3101 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
3102
3103 Session session = null;
3104
3105 try {
3106 session = openSession();
3107
3108 SQLQuery q = session.createSQLQuery(sql);
3109
3110 q.addScalar(COUNT_COLUMN_NAME,
3111 com.liferay.portal.kernel.dao.orm.Type.LONG);
3112
3113 QueryPos qPos = QueryPos.getInstance(q);
3114
3115 qPos.add(companyId);
3116
3117 Long count = (Long)q.uniqueResult();
3118
3119 return count.intValue();
3120 }
3121 catch (Exception e) {
3122 throw processException(e);
3123 }
3124 finally {
3125 closeSession(session);
3126 }
3127 }
3128
3129
3136 public int countByLocations(long companyId) throws SystemException {
3137 Object[] finderArgs = new Object[] { companyId };
3138
3139 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_LOCATIONS,
3140 finderArgs, this);
3141
3142 if (count == null) {
3143 StringBundler query = new StringBundler(2);
3144
3145 query.append(_SQL_COUNT_ORGANIZATION_WHERE);
3146
3147 query.append(_FINDER_COLUMN_LOCATIONS_COMPANYID_2);
3148
3149 String sql = query.toString();
3150
3151 Session session = null;
3152
3153 try {
3154 session = openSession();
3155
3156 Query q = session.createQuery(sql);
3157
3158 QueryPos qPos = QueryPos.getInstance(q);
3159
3160 qPos.add(companyId);
3161
3162 count = (Long)q.uniqueResult();
3163 }
3164 catch (Exception e) {
3165 throw processException(e);
3166 }
3167 finally {
3168 if (count == null) {
3169 count = Long.valueOf(0);
3170 }
3171
3172 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_LOCATIONS,
3173 finderArgs, count);
3174
3175 closeSession(session);
3176 }
3177 }
3178
3179 return count.intValue();
3180 }
3181
3182
3189 public int filterCountByLocations(long companyId) throws SystemException {
3190 if (!InlineSQLHelperUtil.isEnabled()) {
3191 return countByLocations(companyId);
3192 }
3193
3194 StringBundler query = new StringBundler(2);
3195
3196 query.append(_FILTER_SQL_COUNT_ORGANIZATION_WHERE);
3197
3198 query.append(_FINDER_COLUMN_LOCATIONS_COMPANYID_2);
3199
3200 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3201 Organization.class.getName(),
3202 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
3203
3204 Session session = null;
3205
3206 try {
3207 session = openSession();
3208
3209 SQLQuery q = session.createSQLQuery(sql);
3210
3211 q.addScalar(COUNT_COLUMN_NAME,
3212 com.liferay.portal.kernel.dao.orm.Type.LONG);
3213
3214 QueryPos qPos = QueryPos.getInstance(q);
3215
3216 qPos.add(companyId);
3217
3218 Long count = (Long)q.uniqueResult();
3219
3220 return count.intValue();
3221 }
3222 catch (Exception e) {
3223 throw processException(e);
3224 }
3225 finally {
3226 closeSession(session);
3227 }
3228 }
3229
3230
3238 public int countByC_P(long companyId, long parentOrganizationId)
3239 throws SystemException {
3240 Object[] finderArgs = new Object[] { companyId, parentOrganizationId };
3241
3242 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_P,
3243 finderArgs, this);
3244
3245 if (count == null) {
3246 StringBundler query = new StringBundler(3);
3247
3248 query.append(_SQL_COUNT_ORGANIZATION_WHERE);
3249
3250 query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
3251
3252 query.append(_FINDER_COLUMN_C_P_PARENTORGANIZATIONID_2);
3253
3254 String sql = query.toString();
3255
3256 Session session = null;
3257
3258 try {
3259 session = openSession();
3260
3261 Query q = session.createQuery(sql);
3262
3263 QueryPos qPos = QueryPos.getInstance(q);
3264
3265 qPos.add(companyId);
3266
3267 qPos.add(parentOrganizationId);
3268
3269 count = (Long)q.uniqueResult();
3270 }
3271 catch (Exception e) {
3272 throw processException(e);
3273 }
3274 finally {
3275 if (count == null) {
3276 count = Long.valueOf(0);
3277 }
3278
3279 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_P, finderArgs,
3280 count);
3281
3282 closeSession(session);
3283 }
3284 }
3285
3286 return count.intValue();
3287 }
3288
3289
3297 public int filterCountByC_P(long companyId, long parentOrganizationId)
3298 throws SystemException {
3299 if (!InlineSQLHelperUtil.isEnabled()) {
3300 return countByC_P(companyId, parentOrganizationId);
3301 }
3302
3303 StringBundler query = new StringBundler(3);
3304
3305 query.append(_FILTER_SQL_COUNT_ORGANIZATION_WHERE);
3306
3307 query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
3308
3309 query.append(_FINDER_COLUMN_C_P_PARENTORGANIZATIONID_2);
3310
3311 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3312 Organization.class.getName(),
3313 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
3314
3315 Session session = null;
3316
3317 try {
3318 session = openSession();
3319
3320 SQLQuery q = session.createSQLQuery(sql);
3321
3322 q.addScalar(COUNT_COLUMN_NAME,
3323 com.liferay.portal.kernel.dao.orm.Type.LONG);
3324
3325 QueryPos qPos = QueryPos.getInstance(q);
3326
3327 qPos.add(companyId);
3328
3329 qPos.add(parentOrganizationId);
3330
3331 Long count = (Long)q.uniqueResult();
3332
3333 return count.intValue();
3334 }
3335 catch (Exception e) {
3336 throw processException(e);
3337 }
3338 finally {
3339 closeSession(session);
3340 }
3341 }
3342
3343
3351 public int countByC_N(long companyId, String name)
3352 throws SystemException {
3353 Object[] finderArgs = new Object[] { companyId, name };
3354
3355 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_N,
3356 finderArgs, this);
3357
3358 if (count == null) {
3359 StringBundler query = new StringBundler(3);
3360
3361 query.append(_SQL_COUNT_ORGANIZATION_WHERE);
3362
3363 query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
3364
3365 if (name == null) {
3366 query.append(_FINDER_COLUMN_C_N_NAME_1);
3367 }
3368 else {
3369 if (name.equals(StringPool.BLANK)) {
3370 query.append(_FINDER_COLUMN_C_N_NAME_3);
3371 }
3372 else {
3373 query.append(_FINDER_COLUMN_C_N_NAME_2);
3374 }
3375 }
3376
3377 String sql = query.toString();
3378
3379 Session session = null;
3380
3381 try {
3382 session = openSession();
3383
3384 Query q = session.createQuery(sql);
3385
3386 QueryPos qPos = QueryPos.getInstance(q);
3387
3388 qPos.add(companyId);
3389
3390 if (name != null) {
3391 qPos.add(name);
3392 }
3393
3394 count = (Long)q.uniqueResult();
3395 }
3396 catch (Exception e) {
3397 throw processException(e);
3398 }
3399 finally {
3400 if (count == null) {
3401 count = Long.valueOf(0);
3402 }
3403
3404 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_N, finderArgs,
3405 count);
3406
3407 closeSession(session);
3408 }
3409 }
3410
3411 return count.intValue();
3412 }
3413
3414
3420 public int countAll() throws SystemException {
3421 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
3422 FINDER_ARGS_EMPTY, this);
3423
3424 if (count == null) {
3425 Session session = null;
3426
3427 try {
3428 session = openSession();
3429
3430 Query q = session.createQuery(_SQL_COUNT_ORGANIZATION);
3431
3432 count = (Long)q.uniqueResult();
3433 }
3434 catch (Exception e) {
3435 throw processException(e);
3436 }
3437 finally {
3438 if (count == null) {
3439 count = Long.valueOf(0);
3440 }
3441
3442 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
3443 FINDER_ARGS_EMPTY, count);
3444
3445 closeSession(session);
3446 }
3447 }
3448
3449 return count.intValue();
3450 }
3451
3452
3459 public List<com.liferay.portal.model.Group> getGroups(long pk)
3460 throws SystemException {
3461 return getGroups(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
3462 }
3463
3464
3477 public List<com.liferay.portal.model.Group> getGroups(long pk, int start,
3478 int end) throws SystemException {
3479 return getGroups(pk, start, end, null);
3480 }
3481
3482 public static final FinderPath FINDER_PATH_GET_GROUPS = new FinderPath(com.liferay.portal.model.impl.GroupModelImpl.ENTITY_CACHE_ENABLED,
3483 OrganizationModelImpl.FINDER_CACHE_ENABLED_GROUPS_ORGS,
3484 com.liferay.portal.model.impl.GroupImpl.class,
3485 OrganizationModelImpl.MAPPING_TABLE_GROUPS_ORGS_NAME, "getGroups",
3486 new String[] {
3487 Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
3488 "com.liferay.portal.kernel.util.OrderByComparator"
3489 });
3490
3491 static {
3492 FINDER_PATH_GET_GROUPS.setCacheKeyGeneratorCacheName(null);
3493 }
3494
3495
3509 public List<com.liferay.portal.model.Group> getGroups(long pk, int start,
3510 int end, OrderByComparator orderByComparator) throws SystemException {
3511 Object[] finderArgs = new Object[] { pk, start, end, orderByComparator };
3512
3513 List<com.liferay.portal.model.Group> list = (List<com.liferay.portal.model.Group>)FinderCacheUtil.getResult(FINDER_PATH_GET_GROUPS,
3514 finderArgs, this);
3515
3516 if (list == null) {
3517 Session session = null;
3518
3519 try {
3520 session = openSession();
3521
3522 String sql = null;
3523
3524 if (orderByComparator != null) {
3525 sql = _SQL_GETGROUPS.concat(ORDER_BY_CLAUSE)
3526 .concat(orderByComparator.getOrderBy());
3527 }
3528 else {
3529 sql = _SQL_GETGROUPS.concat(com.liferay.portal.model.impl.GroupModelImpl.ORDER_BY_SQL);
3530 }
3531
3532 SQLQuery q = session.createSQLQuery(sql);
3533
3534 q.addEntity("Group_",
3535 com.liferay.portal.model.impl.GroupImpl.class);
3536
3537 QueryPos qPos = QueryPos.getInstance(q);
3538
3539 qPos.add(pk);
3540
3541 list = (List<com.liferay.portal.model.Group>)QueryUtil.list(q,
3542 getDialect(), start, end);
3543 }
3544 catch (Exception e) {
3545 throw processException(e);
3546 }
3547 finally {
3548 if (list == null) {
3549 FinderCacheUtil.removeResult(FINDER_PATH_GET_GROUPS,
3550 finderArgs);
3551 }
3552 else {
3553 groupPersistence.cacheResult(list);
3554
3555 FinderCacheUtil.putResult(FINDER_PATH_GET_GROUPS,
3556 finderArgs, list);
3557 }
3558
3559 closeSession(session);
3560 }
3561 }
3562
3563 return list;
3564 }
3565
3566 public static final FinderPath FINDER_PATH_GET_GROUPS_SIZE = new FinderPath(com.liferay.portal.model.impl.GroupModelImpl.ENTITY_CACHE_ENABLED,
3567 OrganizationModelImpl.FINDER_CACHE_ENABLED_GROUPS_ORGS, Long.class,
3568 OrganizationModelImpl.MAPPING_TABLE_GROUPS_ORGS_NAME,
3569 "getGroupsSize", new String[] { Long.class.getName() });
3570
3571 static {
3572 FINDER_PATH_GET_GROUPS_SIZE.setCacheKeyGeneratorCacheName(null);
3573 }
3574
3575
3582 public int getGroupsSize(long pk) throws SystemException {
3583 Object[] finderArgs = new Object[] { pk };
3584
3585 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_GROUPS_SIZE,
3586 finderArgs, this);
3587
3588 if (count == null) {
3589 Session session = null;
3590
3591 try {
3592 session = openSession();
3593
3594 SQLQuery q = session.createSQLQuery(_SQL_GETGROUPSSIZE);
3595
3596 q.addScalar(COUNT_COLUMN_NAME,
3597 com.liferay.portal.kernel.dao.orm.Type.LONG);
3598
3599 QueryPos qPos = QueryPos.getInstance(q);
3600
3601 qPos.add(pk);
3602
3603 count = (Long)q.uniqueResult();
3604 }
3605 catch (Exception e) {
3606 throw processException(e);
3607 }
3608 finally {
3609 if (count == null) {
3610 count = Long.valueOf(0);
3611 }
3612
3613 FinderCacheUtil.putResult(FINDER_PATH_GET_GROUPS_SIZE,
3614 finderArgs, count);
3615
3616 closeSession(session);
3617 }
3618 }
3619
3620 return count.intValue();
3621 }
3622
3623 public static final FinderPath FINDER_PATH_CONTAINS_GROUP = new FinderPath(com.liferay.portal.model.impl.GroupModelImpl.ENTITY_CACHE_ENABLED,
3624 OrganizationModelImpl.FINDER_CACHE_ENABLED_GROUPS_ORGS,
3625 Boolean.class,
3626 OrganizationModelImpl.MAPPING_TABLE_GROUPS_ORGS_NAME,
3627 "containsGroup",
3628 new String[] { Long.class.getName(), Long.class.getName() });
3629
3630
3638 public boolean containsGroup(long pk, long groupPK)
3639 throws SystemException {
3640 Object[] finderArgs = new Object[] { pk, groupPK };
3641
3642 Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_GROUP,
3643 finderArgs, this);
3644
3645 if (value == null) {
3646 try {
3647 value = Boolean.valueOf(containsGroup.contains(pk, groupPK));
3648 }
3649 catch (Exception e) {
3650 throw processException(e);
3651 }
3652 finally {
3653 if (value == null) {
3654 value = Boolean.FALSE;
3655 }
3656
3657 FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_GROUP,
3658 finderArgs, value);
3659 }
3660 }
3661
3662 return value.booleanValue();
3663 }
3664
3665
3672 public boolean containsGroups(long pk) throws SystemException {
3673 if (getGroupsSize(pk) > 0) {
3674 return true;
3675 }
3676 else {
3677 return false;
3678 }
3679 }
3680
3681
3688 public void addGroup(long pk, long groupPK) throws SystemException {
3689 try {
3690 addGroup.add(pk, groupPK);
3691 }
3692 catch (Exception e) {
3693 throw processException(e);
3694 }
3695 finally {
3696 FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_GROUPS_ORGS_NAME);
3697 }
3698 }
3699
3700
3707 public void addGroup(long pk, com.liferay.portal.model.Group group)
3708 throws SystemException {
3709 try {
3710 addGroup.add(pk, group.getPrimaryKey());
3711 }
3712 catch (Exception e) {
3713 throw processException(e);
3714 }
3715 finally {
3716 FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_GROUPS_ORGS_NAME);
3717 }
3718 }
3719
3720
3727 public void addGroups(long pk, long[] groupPKs) throws SystemException {
3728 try {
3729 for (long groupPK : groupPKs) {
3730 addGroup.add(pk, groupPK);
3731 }
3732 }
3733 catch (Exception e) {
3734 throw processException(e);
3735 }
3736 finally {
3737 FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_GROUPS_ORGS_NAME);
3738 }
3739 }
3740
3741
3748 public void addGroups(long pk, List<com.liferay.portal.model.Group> groups)
3749 throws SystemException {
3750 try {
3751 for (com.liferay.portal.model.Group group : groups) {
3752 addGroup.add(pk, group.getPrimaryKey());
3753 }
3754 }
3755 catch (Exception e) {
3756 throw processException(e);
3757 }
3758 finally {
3759 FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_GROUPS_ORGS_NAME);
3760 }
3761 }
3762
3763
3769 public void clearGroups(long pk) throws SystemException {
3770 try {
3771 clearGroups.clear(pk);
3772 }
3773 catch (Exception e) {
3774 throw processException(e);
3775 }
3776 finally {
3777 FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_GROUPS_ORGS_NAME);
3778 }
3779 }
3780
3781
3788 public void removeGroup(long pk, long groupPK) throws SystemException {
3789 try {
3790 removeGroup.remove(pk, groupPK);
3791 }
3792 catch (Exception e) {
3793 throw processException(e);
3794 }
3795 finally {
3796 FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_GROUPS_ORGS_NAME);
3797 }
3798 }
3799
3800
3807 public void removeGroup(long pk, com.liferay.portal.model.Group group)
3808 throws SystemException {
3809 try {
3810 removeGroup.remove(pk, group.getPrimaryKey());
3811 }
3812 catch (Exception e) {
3813 throw processException(e);
3814 }
3815 finally {
3816 FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_GROUPS_ORGS_NAME);
3817 }
3818 }
3819
3820
3827 public void removeGroups(long pk, long[] groupPKs)
3828 throws SystemException {
3829 try {
3830 for (long groupPK : groupPKs) {
3831 removeGroup.remove(pk, groupPK);
3832 }
3833 }
3834 catch (Exception e) {
3835 throw processException(e);
3836 }
3837 finally {
3838 FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_GROUPS_ORGS_NAME);
3839 }
3840 }
3841
3842
3849 public void removeGroups(long pk,
3850 List<com.liferay.portal.model.Group> groups) throws SystemException {
3851 try {
3852 for (com.liferay.portal.model.Group group : groups) {
3853 removeGroup.remove(pk, group.getPrimaryKey());
3854 }
3855 }
3856 catch (Exception e) {
3857 throw processException(e);
3858 }
3859 finally {
3860 FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_GROUPS_ORGS_NAME);
3861 }
3862 }
3863
3864
3871 public void setGroups(long pk, long[] groupPKs) throws SystemException {
3872 try {
3873 Set<Long> groupPKSet = SetUtil.fromArray(groupPKs);
3874
3875 List<com.liferay.portal.model.Group> groups = getGroups(pk);
3876
3877 for (com.liferay.portal.model.Group group : groups) {
3878 if (!groupPKSet.remove(group.getPrimaryKey())) {
3879 removeGroup.remove(pk, group.getPrimaryKey());
3880 }
3881 }
3882
3883 for (Long groupPK : groupPKSet) {
3884 addGroup.add(pk, groupPK);
3885 }
3886 }
3887 catch (Exception e) {
3888 throw processException(e);
3889 }
3890 finally {
3891 FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_GROUPS_ORGS_NAME);
3892 }
3893 }
3894
3895
3902 public void setGroups(long pk, List<com.liferay.portal.model.Group> groups)
3903 throws SystemException {
3904 try {
3905 long[] groupPKs = new long[groups.size()];
3906
3907 for (int i = 0; i < groups.size(); i++) {
3908 com.liferay.portal.model.Group group = groups.get(i);
3909
3910 groupPKs[i] = group.getPrimaryKey();
3911 }
3912
3913 setGroups(pk, groupPKs);
3914 }
3915 catch (Exception e) {
3916 throw processException(e);
3917 }
3918 finally {
3919 FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_GROUPS_ORGS_NAME);
3920 }
3921 }
3922
3923
3930 public List<com.liferay.portal.model.User> getUsers(long pk)
3931 throws SystemException {
3932 return getUsers(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
3933 }
3934
3935
3948 public List<com.liferay.portal.model.User> getUsers(long pk, int start,
3949 int end) throws SystemException {
3950 return getUsers(pk, start, end, null);
3951 }
3952
3953 public static final FinderPath FINDER_PATH_GET_USERS = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
3954 OrganizationModelImpl.FINDER_CACHE_ENABLED_USERS_ORGS,
3955 com.liferay.portal.model.impl.UserImpl.class,
3956 OrganizationModelImpl.MAPPING_TABLE_USERS_ORGS_NAME, "getUsers",
3957 new String[] {
3958 Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
3959 "com.liferay.portal.kernel.util.OrderByComparator"
3960 });
3961
3962 static {
3963 FINDER_PATH_GET_USERS.setCacheKeyGeneratorCacheName(null);
3964 }
3965
3966
3980 public List<com.liferay.portal.model.User> getUsers(long pk, int start,
3981 int end, OrderByComparator orderByComparator) throws SystemException {
3982 Object[] finderArgs = new Object[] { pk, start, end, orderByComparator };
3983
3984 List<com.liferay.portal.model.User> list = (List<com.liferay.portal.model.User>)FinderCacheUtil.getResult(FINDER_PATH_GET_USERS,
3985 finderArgs, this);
3986
3987 if (list == null) {
3988 Session session = null;
3989
3990 try {
3991 session = openSession();
3992
3993 String sql = null;
3994
3995 if (orderByComparator != null) {
3996 sql = _SQL_GETUSERS.concat(ORDER_BY_CLAUSE)
3997 .concat(orderByComparator.getOrderBy());
3998 }
3999 else {
4000 sql = _SQL_GETUSERS;
4001 }
4002
4003 SQLQuery q = session.createSQLQuery(sql);
4004
4005 q.addEntity("User_",
4006 com.liferay.portal.model.impl.UserImpl.class);
4007
4008 QueryPos qPos = QueryPos.getInstance(q);
4009
4010 qPos.add(pk);
4011
4012 list = (List<com.liferay.portal.model.User>)QueryUtil.list(q,
4013 getDialect(), start, end);
4014 }
4015 catch (Exception e) {
4016 throw processException(e);
4017 }
4018 finally {
4019 if (list == null) {
4020 FinderCacheUtil.removeResult(FINDER_PATH_GET_USERS,
4021 finderArgs);
4022 }
4023 else {
4024 userPersistence.cacheResult(list);
4025
4026 FinderCacheUtil.putResult(FINDER_PATH_GET_USERS,
4027 finderArgs, list);
4028 }
4029
4030 closeSession(session);
4031 }
4032 }
4033
4034 return list;
4035 }
4036
4037 public static final FinderPath FINDER_PATH_GET_USERS_SIZE = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
4038 OrganizationModelImpl.FINDER_CACHE_ENABLED_USERS_ORGS, Long.class,
4039 OrganizationModelImpl.MAPPING_TABLE_USERS_ORGS_NAME,
4040 "getUsersSize", new String[] { Long.class.getName() });
4041
4042 static {
4043 FINDER_PATH_GET_USERS_SIZE.setCacheKeyGeneratorCacheName(null);
4044 }
4045
4046
4053 public int getUsersSize(long pk) throws SystemException {
4054 Object[] finderArgs = new Object[] { pk };
4055
4056 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_USERS_SIZE,
4057 finderArgs, this);
4058
4059 if (count == null) {
4060 Session session = null;
4061
4062 try {
4063 session = openSession();
4064
4065 SQLQuery q = session.createSQLQuery(_SQL_GETUSERSSIZE);
4066
4067 q.addScalar(COUNT_COLUMN_NAME,
4068 com.liferay.portal.kernel.dao.orm.Type.LONG);
4069
4070 QueryPos qPos = QueryPos.getInstance(q);
4071
4072 qPos.add(pk);
4073
4074 count = (Long)q.uniqueResult();
4075 }
4076 catch (Exception e) {
4077 throw processException(e);
4078 }
4079 finally {
4080 if (count == null) {
4081 count = Long.valueOf(0);
4082 }
4083
4084 FinderCacheUtil.putResult(FINDER_PATH_GET_USERS_SIZE,
4085 finderArgs, count);
4086
4087 closeSession(session);
4088 }
4089 }
4090
4091 return count.intValue();
4092 }
4093
4094 public static final FinderPath FINDER_PATH_CONTAINS_USER = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
4095 OrganizationModelImpl.FINDER_CACHE_ENABLED_USERS_ORGS,
4096 Boolean.class, OrganizationModelImpl.MAPPING_TABLE_USERS_ORGS_NAME,
4097 "containsUser",
4098 new String[] { Long.class.getName(), Long.class.getName() });
4099
4100
4108 public boolean containsUser(long pk, long userPK) throws SystemException {
4109 Object[] finderArgs = new Object[] { pk, userPK };
4110
4111 Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_USER,
4112 finderArgs, this);
4113
4114 if (value == null) {
4115 try {
4116 value = Boolean.valueOf(containsUser.contains(pk, userPK));
4117 }
4118 catch (Exception e) {
4119 throw processException(e);
4120 }
4121 finally {
4122 if (value == null) {
4123 value = Boolean.FALSE;
4124 }
4125
4126 FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_USER,
4127 finderArgs, value);
4128 }
4129 }
4130
4131 return value.booleanValue();
4132 }
4133
4134
4141 public boolean containsUsers(long pk) throws SystemException {
4142 if (getUsersSize(pk) > 0) {
4143 return true;
4144 }
4145 else {
4146 return false;
4147 }
4148 }
4149
4150
4157 public void addUser(long pk, long userPK) throws SystemException {
4158 try {
4159 addUser.add(pk, userPK);
4160 }
4161 catch (Exception e) {
4162 throw processException(e);
4163 }
4164 finally {
4165 FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_USERS_ORGS_NAME);
4166 }
4167 }
4168
4169
4176 public void addUser(long pk, com.liferay.portal.model.User user)
4177 throws SystemException {
4178 try {
4179 addUser.add(pk, user.getPrimaryKey());
4180 }
4181 catch (Exception e) {
4182 throw processException(e);
4183 }
4184 finally {
4185 FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_USERS_ORGS_NAME);
4186 }
4187 }
4188
4189
4196 public void addUsers(long pk, long[] userPKs) throws SystemException {
4197 try {
4198 for (long userPK : userPKs) {
4199 addUser.add(pk, userPK);
4200 }
4201 }
4202 catch (Exception e) {
4203 throw processException(e);
4204 }
4205 finally {
4206 FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_USERS_ORGS_NAME);
4207 }
4208 }
4209
4210
4217 public void addUsers(long pk, List<com.liferay.portal.model.User> users)
4218 throws SystemException {
4219 try {
4220 for (com.liferay.portal.model.User user : users) {
4221 addUser.add(pk, user.getPrimaryKey());
4222 }
4223 }
4224 catch (Exception e) {
4225 throw processException(e);
4226 }
4227 finally {
4228 FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_USERS_ORGS_NAME);
4229 }
4230 }
4231
4232
4238 public void clearUsers(long pk) throws SystemException {
4239 try {
4240 clearUsers.clear(pk);
4241 }
4242 catch (Exception e) {
4243 throw processException(e);
4244 }
4245 finally {
4246 FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_USERS_ORGS_NAME);
4247 }
4248 }
4249
4250
4257 public void removeUser(long pk, long userPK) throws SystemException {
4258 try {
4259 removeUser.remove(pk, userPK);
4260 }
4261 catch (Exception e) {
4262 throw processException(e);
4263 }
4264 finally {
4265 FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_USERS_ORGS_NAME);
4266 }
4267 }
4268
4269
4276 public void removeUser(long pk, com.liferay.portal.model.User user)
4277 throws SystemException {
4278 try {
4279 removeUser.remove(pk, user.getPrimaryKey());
4280 }
4281 catch (Exception e) {
4282 throw processException(e);
4283 }
4284 finally {
4285 FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_USERS_ORGS_NAME);
4286 }
4287 }
4288
4289
4296 public void removeUsers(long pk, long[] userPKs) throws SystemException {
4297 try {
4298 for (long userPK : userPKs) {
4299 removeUser.remove(pk, userPK);
4300 }
4301 }
4302 catch (Exception e) {
4303 throw processException(e);
4304 }
4305 finally {
4306 FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_USERS_ORGS_NAME);
4307 }
4308 }
4309
4310
4317 public void removeUsers(long pk, List<com.liferay.portal.model.User> users)
4318 throws SystemException {
4319 try {
4320 for (com.liferay.portal.model.User user : users) {
4321 removeUser.remove(pk, user.getPrimaryKey());
4322 }
4323 }
4324 catch (Exception e) {
4325 throw processException(e);
4326 }
4327 finally {
4328 FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_USERS_ORGS_NAME);
4329 }
4330 }
4331
4332
4339 public void setUsers(long pk, long[] userPKs) throws SystemException {
4340 try {
4341 Set<Long> userPKSet = SetUtil.fromArray(userPKs);
4342
4343 List<com.liferay.portal.model.User> users = getUsers(pk);
4344
4345 for (com.liferay.portal.model.User user : users) {
4346 if (!userPKSet.remove(user.getPrimaryKey())) {
4347 removeUser.remove(pk, user.getPrimaryKey());
4348 }
4349 }
4350
4351 for (Long userPK : userPKSet) {
4352 addUser.add(pk, userPK);
4353 }
4354 }
4355 catch (Exception e) {
4356 throw processException(e);
4357 }
4358 finally {
4359 FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_USERS_ORGS_NAME);
4360 }
4361 }
4362
4363
4370 public void setUsers(long pk, List<com.liferay.portal.model.User> users)
4371 throws SystemException {
4372 try {
4373 long[] userPKs = new long[users.size()];
4374
4375 for (int i = 0; i < users.size(); i++) {
4376 com.liferay.portal.model.User user = users.get(i);
4377
4378 userPKs[i] = user.getPrimaryKey();
4379 }
4380
4381 setUsers(pk, userPKs);
4382 }
4383 catch (Exception e) {
4384 throw processException(e);
4385 }
4386 finally {
4387 FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_USERS_ORGS_NAME);
4388 }
4389 }
4390
4391
4394 public void afterPropertiesSet() {
4395 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
4396 com.liferay.portal.util.PropsUtil.get(
4397 "value.object.listener.com.liferay.portal.model.Organization")));
4398
4399 if (listenerClassNames.length > 0) {
4400 try {
4401 List<ModelListener<Organization>> listenersList = new ArrayList<ModelListener<Organization>>();
4402
4403 for (String listenerClassName : listenerClassNames) {
4404 listenersList.add((ModelListener<Organization>)InstanceFactory.newInstance(
4405 listenerClassName));
4406 }
4407
4408 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
4409 }
4410 catch (Exception e) {
4411 _log.error(e);
4412 }
4413 }
4414
4415 containsGroup = new ContainsGroup();
4416
4417 addGroup = new AddGroup();
4418 clearGroups = new ClearGroups();
4419 removeGroup = new RemoveGroup();
4420
4421 containsUser = new ContainsUser();
4422
4423 addUser = new AddUser();
4424 clearUsers = new ClearUsers();
4425 removeUser = new RemoveUser();
4426 }
4427
4428 public void destroy() {
4429 EntityCacheUtil.removeCache(OrganizationImpl.class.getName());
4430 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
4431 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4432 }
4433
4434 @BeanReference(type = AccountPersistence.class)
4435 protected AccountPersistence accountPersistence;
4436 @BeanReference(type = AddressPersistence.class)
4437 protected AddressPersistence addressPersistence;
4438 @BeanReference(type = BrowserTrackerPersistence.class)
4439 protected BrowserTrackerPersistence browserTrackerPersistence;
4440 @BeanReference(type = ClassNamePersistence.class)
4441 protected ClassNamePersistence classNamePersistence;
4442 @BeanReference(type = ClusterGroupPersistence.class)
4443 protected ClusterGroupPersistence clusterGroupPersistence;
4444 @BeanReference(type = CompanyPersistence.class)
4445 protected CompanyPersistence companyPersistence;
4446 @BeanReference(type = ContactPersistence.class)
4447 protected ContactPersistence contactPersistence;
4448 @BeanReference(type = CountryPersistence.class)
4449 protected CountryPersistence countryPersistence;
4450 @BeanReference(type = EmailAddressPersistence.class)
4451 protected EmailAddressPersistence emailAddressPersistence;
4452 @BeanReference(type = GroupPersistence.class)
4453 protected GroupPersistence groupPersistence;
4454 @BeanReference(type = ImagePersistence.class)
4455 protected ImagePersistence imagePersistence;
4456 @BeanReference(type = LayoutPersistence.class)
4457 protected LayoutPersistence layoutPersistence;
4458 @BeanReference(type = LayoutBranchPersistence.class)
4459 protected LayoutBranchPersistence layoutBranchPersistence;
4460 @BeanReference(type = LayoutPrototypePersistence.class)
4461 protected LayoutPrototypePersistence layoutPrototypePersistence;
4462 @BeanReference(type = LayoutRevisionPersistence.class)
4463 protected LayoutRevisionPersistence layoutRevisionPersistence;
4464 @BeanReference(type = LayoutSetPersistence.class)
4465 protected LayoutSetPersistence layoutSetPersistence;
4466 @BeanReference(type = LayoutSetBranchPersistence.class)
4467 protected LayoutSetBranchPersistence layoutSetBranchPersistence;
4468 @BeanReference(type = LayoutSetPrototypePersistence.class)
4469 protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
4470 @BeanReference(type = ListTypePersistence.class)
4471 protected ListTypePersistence listTypePersistence;
4472 @BeanReference(type = LockPersistence.class)
4473 protected LockPersistence lockPersistence;
4474 @BeanReference(type = MembershipRequestPersistence.class)
4475 protected MembershipRequestPersistence membershipRequestPersistence;
4476 @BeanReference(type = OrganizationPersistence.class)
4477 protected OrganizationPersistence organizationPersistence;
4478 @BeanReference(type = OrgGroupPermissionPersistence.class)
4479 protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
4480 @BeanReference(type = OrgGroupRolePersistence.class)
4481 protected OrgGroupRolePersistence orgGroupRolePersistence;
4482 @BeanReference(type = OrgLaborPersistence.class)
4483 protected OrgLaborPersistence orgLaborPersistence;
4484 @BeanReference(type = PasswordPolicyPersistence.class)
4485 protected PasswordPolicyPersistence passwordPolicyPersistence;
4486 @BeanReference(type = PasswordPolicyRelPersistence.class)
4487 protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
4488 @BeanReference(type = PasswordTrackerPersistence.class)
4489 protected PasswordTrackerPersistence passwordTrackerPersistence;
4490 @BeanReference(type = PermissionPersistence.class)
4491 protected PermissionPersistence permissionPersistence;
4492 @BeanReference(type = PhonePersistence.class)
4493 protected PhonePersistence phonePersistence;
4494 @BeanReference(type = PluginSettingPersistence.class)
4495 protected PluginSettingPersistence pluginSettingPersistence;
4496 @BeanReference(type = PortalPreferencesPersistence.class)
4497 protected PortalPreferencesPersistence portalPreferencesPersistence;
4498 @BeanReference(type = PortletPersistence.class)
4499 protected PortletPersistence portletPersistence;
4500 @BeanReference(type = PortletItemPersistence.class)
4501 protected PortletItemPersistence portletItemPersistence;
4502 @BeanReference(type = PortletPreferencesPersistence.class)
4503 protected PortletPreferencesPersistence portletPreferencesPersistence;
4504 @BeanReference(type = RegionPersistence.class)
4505 protected RegionPersistence regionPersistence;
4506 @BeanReference(type = ReleasePersistence.class)
4507 protected ReleasePersistence releasePersistence;
4508 @BeanReference(type = RepositoryPersistence.class)
4509 protected RepositoryPersistence repositoryPersistence;
4510 @BeanReference(type = RepositoryEntryPersistence.class)
4511 protected RepositoryEntryPersistence repositoryEntryPersistence;
4512 @BeanReference(type = ResourcePersistence.class)
4513 protected ResourcePersistence resourcePersistence;
4514 @BeanReference(type = ResourceActionPersistence.class)
4515 protected ResourceActionPersistence resourceActionPersistence;
4516 @BeanReference(type = ResourceBlockPersistence.class)
4517 protected ResourceBlockPersistence resourceBlockPersistence;
4518 @BeanReference(type = ResourceBlockPermissionPersistence.class)
4519 protected ResourceBlockPermissionPersistence resourceBlockPermissionPersistence;
4520 @BeanReference(type = ResourceCodePersistence.class)
4521 protected ResourceCodePersistence resourceCodePersistence;
4522 @BeanReference(type = ResourcePermissionPersistence.class)
4523 protected ResourcePermissionPersistence resourcePermissionPersistence;
4524 @BeanReference(type = ResourceTypePermissionPersistence.class)
4525 protected ResourceTypePermissionPersistence resourceTypePermissionPersistence;
4526 @BeanReference(type = RolePersistence.class)
4527 protected RolePersistence rolePersistence;
4528 @BeanReference(type = ServiceComponentPersistence.class)
4529 protected ServiceComponentPersistence serviceComponentPersistence;
4530 @BeanReference(type = ShardPersistence.class)
4531 protected ShardPersistence shardPersistence;
4532 @BeanReference(type = SubscriptionPersistence.class)
4533 protected SubscriptionPersistence subscriptionPersistence;
4534 @BeanReference(type = TeamPersistence.class)
4535 protected TeamPersistence teamPersistence;
4536 @BeanReference(type = TicketPersistence.class)
4537 protected TicketPersistence ticketPersistence;
4538 @BeanReference(type = UserPersistence.class)
4539 protected UserPersistence userPersistence;
4540 @BeanReference(type = UserGroupPersistence.class)
4541 protected UserGroupPersistence userGroupPersistence;
4542 @BeanReference(type = UserGroupGroupRolePersistence.class)
4543 protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
4544 @BeanReference(type = UserGroupRolePersistence.class)
4545 protected UserGroupRolePersistence userGroupRolePersistence;
4546 @BeanReference(type = UserIdMapperPersistence.class)
4547 protected UserIdMapperPersistence userIdMapperPersistence;
4548 @BeanReference(type = UserNotificationEventPersistence.class)
4549 protected UserNotificationEventPersistence userNotificationEventPersistence;
4550 @BeanReference(type = UserTrackerPersistence.class)
4551 protected UserTrackerPersistence userTrackerPersistence;
4552 @BeanReference(type = UserTrackerPathPersistence.class)
4553 protected UserTrackerPathPersistence userTrackerPathPersistence;
4554 @BeanReference(type = VirtualHostPersistence.class)
4555 protected VirtualHostPersistence virtualHostPersistence;
4556 @BeanReference(type = WebDAVPropsPersistence.class)
4557 protected WebDAVPropsPersistence webDAVPropsPersistence;
4558 @BeanReference(type = WebsitePersistence.class)
4559 protected WebsitePersistence websitePersistence;
4560 @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
4561 protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
4562 @BeanReference(type = WorkflowInstanceLinkPersistence.class)
4563 protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
4564 @BeanReference(type = AssetEntryPersistence.class)
4565 protected AssetEntryPersistence assetEntryPersistence;
4566 @BeanReference(type = ExpandoValuePersistence.class)
4567 protected ExpandoValuePersistence expandoValuePersistence;
4568 protected ContainsGroup containsGroup;
4569 protected AddGroup addGroup;
4570 protected ClearGroups clearGroups;
4571 protected RemoveGroup removeGroup;
4572 protected ContainsUser containsUser;
4573 protected AddUser addUser;
4574 protected ClearUsers clearUsers;
4575 protected RemoveUser removeUser;
4576
4577 protected class ContainsGroup {
4578 protected ContainsGroup() {
4579 _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
4580 _SQL_CONTAINSGROUP,
4581 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT },
4582 RowMapper.COUNT);
4583 }
4584
4585 protected boolean contains(long organizationId, long groupId) {
4586 List<Integer> results = _mappingSqlQuery.execute(new Object[] {
4587 new Long(organizationId), new Long(groupId)
4588 });
4589
4590 if (results.size() > 0) {
4591 Integer count = results.get(0);
4592
4593 if (count.intValue() > 0) {
4594 return true;
4595 }
4596 }
4597
4598 return false;
4599 }
4600
4601 private MappingSqlQuery<Integer> _mappingSqlQuery;
4602 }
4603
4604 protected class AddGroup {
4605 protected AddGroup() {
4606 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
4607 "INSERT INTO Groups_Orgs (organizationId, groupId) VALUES (?, ?)",
4608 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
4609 }
4610
4611 protected void add(long organizationId, long groupId)
4612 throws SystemException {
4613 if (!containsGroup.contains(organizationId, groupId)) {
4614 ModelListener<com.liferay.portal.model.Group>[] groupListeners = groupPersistence.getListeners();
4615
4616 for (ModelListener<Organization> listener : listeners) {
4617 listener.onBeforeAddAssociation(organizationId,
4618 com.liferay.portal.model.Group.class.getName(), groupId);
4619 }
4620
4621 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
4622 listener.onBeforeAddAssociation(groupId,
4623 Organization.class.getName(), organizationId);
4624 }
4625
4626 _sqlUpdate.update(new Object[] {
4627 new Long(organizationId), new Long(groupId)
4628 });
4629
4630 for (ModelListener<Organization> listener : listeners) {
4631 listener.onAfterAddAssociation(organizationId,
4632 com.liferay.portal.model.Group.class.getName(), groupId);
4633 }
4634
4635 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
4636 listener.onAfterAddAssociation(groupId,
4637 Organization.class.getName(), organizationId);
4638 }
4639 }
4640 }
4641
4642 private SqlUpdate _sqlUpdate;
4643 }
4644
4645 protected class ClearGroups {
4646 protected ClearGroups() {
4647 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
4648 "DELETE FROM Groups_Orgs WHERE organizationId = ?",
4649 new int[] { java.sql.Types.BIGINT });
4650 }
4651
4652 protected void clear(long organizationId) throws SystemException {
4653 ModelListener<com.liferay.portal.model.Group>[] groupListeners = groupPersistence.getListeners();
4654
4655 List<com.liferay.portal.model.Group> groups = null;
4656
4657 if ((listeners.length > 0) || (groupListeners.length > 0)) {
4658 groups = getGroups(organizationId);
4659
4660 for (com.liferay.portal.model.Group group : groups) {
4661 for (ModelListener<Organization> listener : listeners) {
4662 listener.onBeforeRemoveAssociation(organizationId,
4663 com.liferay.portal.model.Group.class.getName(),
4664 group.getPrimaryKey());
4665 }
4666
4667 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
4668 listener.onBeforeRemoveAssociation(group.getPrimaryKey(),
4669 Organization.class.getName(), organizationId);
4670 }
4671 }
4672 }
4673
4674 _sqlUpdate.update(new Object[] { new Long(organizationId) });
4675
4676 if ((listeners.length > 0) || (groupListeners.length > 0)) {
4677 for (com.liferay.portal.model.Group group : groups) {
4678 for (ModelListener<Organization> listener : listeners) {
4679 listener.onAfterRemoveAssociation(organizationId,
4680 com.liferay.portal.model.Group.class.getName(),
4681 group.getPrimaryKey());
4682 }
4683
4684 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
4685 listener.onAfterRemoveAssociation(group.getPrimaryKey(),
4686 Organization.class.getName(), organizationId);
4687 }
4688 }
4689 }
4690 }
4691
4692 private SqlUpdate _sqlUpdate;
4693 }
4694
4695 protected class RemoveGroup {
4696 protected RemoveGroup() {
4697 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
4698 "DELETE FROM Groups_Orgs WHERE organizationId = ? AND groupId = ?",
4699 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
4700 }
4701
4702 protected void remove(long organizationId, long groupId)
4703 throws SystemException {
4704 if (containsGroup.contains(organizationId, groupId)) {
4705 ModelListener<com.liferay.portal.model.Group>[] groupListeners = groupPersistence.getListeners();
4706
4707 for (ModelListener<Organization> listener : listeners) {
4708 listener.onBeforeRemoveAssociation(organizationId,
4709 com.liferay.portal.model.Group.class.getName(), groupId);
4710 }
4711
4712 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
4713 listener.onBeforeRemoveAssociation(groupId,
4714 Organization.class.getName(), organizationId);
4715 }
4716
4717 _sqlUpdate.update(new Object[] {
4718 new Long(organizationId), new Long(groupId)
4719 });
4720
4721 for (ModelListener<Organization> listener : listeners) {
4722 listener.onAfterRemoveAssociation(organizationId,
4723 com.liferay.portal.model.Group.class.getName(), groupId);
4724 }
4725
4726 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
4727 listener.onAfterRemoveAssociation(groupId,
4728 Organization.class.getName(), organizationId);
4729 }
4730 }
4731 }
4732
4733 private SqlUpdate _sqlUpdate;
4734 }
4735
4736 protected class ContainsUser {
4737 protected ContainsUser() {
4738 _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
4739 _SQL_CONTAINSUSER,
4740 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT },
4741 RowMapper.COUNT);
4742 }
4743
4744 protected boolean contains(long organizationId, long userId) {
4745 List<Integer> results = _mappingSqlQuery.execute(new Object[] {
4746 new Long(organizationId), new Long(userId)
4747 });
4748
4749 if (results.size() > 0) {
4750 Integer count = results.get(0);
4751
4752 if (count.intValue() > 0) {
4753 return true;
4754 }
4755 }
4756
4757 return false;
4758 }
4759
4760 private MappingSqlQuery<Integer> _mappingSqlQuery;
4761 }
4762
4763 protected class AddUser {
4764 protected AddUser() {
4765 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
4766 "INSERT INTO Users_Orgs (organizationId, userId) VALUES (?, ?)",
4767 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
4768 }
4769
4770 protected void add(long organizationId, long userId)
4771 throws SystemException {
4772 if (!containsUser.contains(organizationId, userId)) {
4773 ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
4774
4775 for (ModelListener<Organization> listener : listeners) {
4776 listener.onBeforeAddAssociation(organizationId,
4777 com.liferay.portal.model.User.class.getName(), userId);
4778 }
4779
4780 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
4781 listener.onBeforeAddAssociation(userId,
4782 Organization.class.getName(), organizationId);
4783 }
4784
4785 _sqlUpdate.update(new Object[] {
4786 new Long(organizationId), new Long(userId)
4787 });
4788
4789 for (ModelListener<Organization> listener : listeners) {
4790 listener.onAfterAddAssociation(organizationId,
4791 com.liferay.portal.model.User.class.getName(), userId);
4792 }
4793
4794 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
4795 listener.onAfterAddAssociation(userId,
4796 Organization.class.getName(), organizationId);
4797 }
4798 }
4799 }
4800
4801 private SqlUpdate _sqlUpdate;
4802 }
4803
4804 protected class ClearUsers {
4805 protected ClearUsers() {
4806 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
4807 "DELETE FROM Users_Orgs WHERE organizationId = ?",
4808 new int[] { java.sql.Types.BIGINT });
4809 }
4810
4811 protected void clear(long organizationId) throws SystemException {
4812 ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
4813
4814 List<com.liferay.portal.model.User> users = null;
4815
4816 if ((listeners.length > 0) || (userListeners.length > 0)) {
4817 users = getUsers(organizationId);
4818
4819 for (com.liferay.portal.model.User user : users) {
4820 for (ModelListener<Organization> listener : listeners) {
4821 listener.onBeforeRemoveAssociation(organizationId,
4822 com.liferay.portal.model.User.class.getName(),
4823 user.getPrimaryKey());
4824 }
4825
4826 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
4827 listener.onBeforeRemoveAssociation(user.getPrimaryKey(),
4828 Organization.class.getName(), organizationId);
4829 }
4830 }
4831 }
4832
4833 _sqlUpdate.update(new Object[] { new Long(organizationId) });
4834
4835 if ((listeners.length > 0) || (userListeners.length > 0)) {
4836 for (com.liferay.portal.model.User user : users) {
4837 for (ModelListener<Organization> listener : listeners) {
4838 listener.onAfterRemoveAssociation(organizationId,
4839 com.liferay.portal.model.User.class.getName(),
4840 user.getPrimaryKey());
4841 }
4842
4843 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
4844 listener.onAfterRemoveAssociation(user.getPrimaryKey(),
4845 Organization.class.getName(), organizationId);
4846 }
4847 }
4848 }
4849 }
4850
4851 private SqlUpdate _sqlUpdate;
4852 }
4853
4854 protected class RemoveUser {
4855 protected RemoveUser() {
4856 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
4857 "DELETE FROM Users_Orgs WHERE organizationId = ? AND userId = ?",
4858 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
4859 }
4860
4861 protected void remove(long organizationId, long userId)
4862 throws SystemException {
4863 if (containsUser.contains(organizationId, userId)) {
4864 ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
4865
4866 for (ModelListener<Organization> listener : listeners) {
4867 listener.onBeforeRemoveAssociation(organizationId,
4868 com.liferay.portal.model.User.class.getName(), userId);
4869 }
4870
4871 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
4872 listener.onBeforeRemoveAssociation(userId,
4873 Organization.class.getName(), organizationId);
4874 }
4875
4876 _sqlUpdate.update(new Object[] {
4877 new Long(organizationId), new Long(userId)
4878 });
4879
4880 for (ModelListener<Organization> listener : listeners) {
4881 listener.onAfterRemoveAssociation(organizationId,
4882 com.liferay.portal.model.User.class.getName(), userId);
4883 }
4884
4885 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
4886 listener.onAfterRemoveAssociation(userId,
4887 Organization.class.getName(), organizationId);
4888 }
4889 }
4890 }
4891
4892 private SqlUpdate _sqlUpdate;
4893 }
4894
4895 private static final String _SQL_SELECT_ORGANIZATION = "SELECT organization FROM Organization organization";
4896 private static final String _SQL_SELECT_ORGANIZATION_WHERE = "SELECT organization FROM Organization organization WHERE ";
4897 private static final String _SQL_COUNT_ORGANIZATION = "SELECT COUNT(organization) FROM Organization organization";
4898 private static final String _SQL_COUNT_ORGANIZATION_WHERE = "SELECT COUNT(organization) FROM Organization organization WHERE ";
4899 private static final String _SQL_GETGROUPS = "SELECT {Group_.*} FROM Group_ INNER JOIN Groups_Orgs ON (Groups_Orgs.groupId = Group_.groupId) WHERE (Groups_Orgs.organizationId = ?)";
4900 private static final String _SQL_GETGROUPSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_Orgs WHERE organizationId = ?";
4901 private static final String _SQL_CONTAINSGROUP = "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_Orgs WHERE organizationId = ? AND groupId = ?";
4902 private static final String _SQL_GETUSERS = "SELECT {User_.*} FROM User_ INNER JOIN Users_Orgs ON (Users_Orgs.userId = User_.userId) WHERE (Users_Orgs.organizationId = ?)";
4903 private static final String _SQL_GETUSERSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Orgs WHERE organizationId = ?";
4904 private static final String _SQL_CONTAINSUSER = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Orgs WHERE organizationId = ? AND userId = ?";
4905 private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "organization.companyId = ?";
4906 private static final String _FINDER_COLUMN_LOCATIONS_COMPANYID_2 = "organization.companyId = ? AND organization.parentOrganizationId != 0";
4907 private static final String _FINDER_COLUMN_C_P_COMPANYID_2 = "organization.companyId = ? AND ";
4908 private static final String _FINDER_COLUMN_C_P_PARENTORGANIZATIONID_2 = "organization.parentOrganizationId = ?";
4909 private static final String _FINDER_COLUMN_C_N_COMPANYID_2 = "organization.companyId = ? AND ";
4910 private static final String _FINDER_COLUMN_C_N_NAME_1 = "organization.name IS NULL";
4911 private static final String _FINDER_COLUMN_C_N_NAME_2 = "organization.name = ?";
4912 private static final String _FINDER_COLUMN_C_N_NAME_3 = "(organization.name IS NULL OR organization.name = ?)";
4913 private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "organization.organizationId";
4914 private static final String _FILTER_SQL_SELECT_ORGANIZATION_WHERE = "SELECT DISTINCT {organization.*} FROM Organization_ organization WHERE ";
4915 private static final String _FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_1 =
4916 "SELECT {Organization_.*} FROM (SELECT DISTINCT organization.organizationId FROM Organization_ organization WHERE ";
4917 private static final String _FILTER_SQL_SELECT_ORGANIZATION_NO_INLINE_DISTINCT_WHERE_2 =
4918 ") TEMP_TABLE INNER JOIN Organization_ ON TEMP_TABLE.organizationId = Organization_.organizationId";
4919 private static final String _FILTER_SQL_COUNT_ORGANIZATION_WHERE = "SELECT COUNT(DISTINCT organization.organizationId) AS COUNT_VALUE FROM Organization_ organization WHERE ";
4920 private static final String _FILTER_ENTITY_ALIAS = "organization";
4921 private static final String _FILTER_ENTITY_TABLE = "Organization_";
4922 private static final String _ORDER_BY_ENTITY_ALIAS = "organization.";
4923 private static final String _ORDER_BY_ENTITY_TABLE = "Organization_.";
4924 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Organization exists with the primary key ";
4925 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Organization exists with the key {";
4926 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
4927 private static Log _log = LogFactoryUtil.getLog(OrganizationPersistenceImpl.class);
4928 private static Organization _nullOrganization = new OrganizationImpl() {
4929 @Override
4930 public Object clone() {
4931 return this;
4932 }
4933
4934 @Override
4935 public CacheModel<Organization> toCacheModel() {
4936 return _nullOrganizationCacheModel;
4937 }
4938 };
4939
4940 private static CacheModel<Organization> _nullOrganizationCacheModel = new CacheModel<Organization>() {
4941 public Organization toEntityModel() {
4942 return _nullOrganization;
4943 }
4944 };
4945 }