1
22
23 package com.liferay.portal.service.persistence;
24
25 import com.liferay.portal.NoSuchModelException;
26 import com.liferay.portal.NoSuchOrganizationException;
27 import com.liferay.portal.SystemException;
28 import com.liferay.portal.kernel.annotation.BeanReference;
29 import com.liferay.portal.kernel.cache.CacheRegistry;
30 import com.liferay.portal.kernel.dao.jdbc.MappingSqlQuery;
31 import com.liferay.portal.kernel.dao.jdbc.MappingSqlQueryFactoryUtil;
32 import com.liferay.portal.kernel.dao.jdbc.RowMapper;
33 import com.liferay.portal.kernel.dao.jdbc.SqlUpdate;
34 import com.liferay.portal.kernel.dao.jdbc.SqlUpdateFactoryUtil;
35 import com.liferay.portal.kernel.dao.orm.DynamicQuery;
36 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
37 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
38 import com.liferay.portal.kernel.dao.orm.FinderPath;
39 import com.liferay.portal.kernel.dao.orm.Query;
40 import com.liferay.portal.kernel.dao.orm.QueryPos;
41 import com.liferay.portal.kernel.dao.orm.QueryUtil;
42 import com.liferay.portal.kernel.dao.orm.SQLQuery;
43 import com.liferay.portal.kernel.dao.orm.Session;
44 import com.liferay.portal.kernel.dao.orm.Type;
45 import com.liferay.portal.kernel.log.Log;
46 import com.liferay.portal.kernel.log.LogFactoryUtil;
47 import com.liferay.portal.kernel.util.GetterUtil;
48 import com.liferay.portal.kernel.util.OrderByComparator;
49 import com.liferay.portal.kernel.util.SetUtil;
50 import com.liferay.portal.kernel.util.StringBundler;
51 import com.liferay.portal.kernel.util.StringPool;
52 import com.liferay.portal.kernel.util.StringUtil;
53 import com.liferay.portal.kernel.util.Validator;
54 import com.liferay.portal.model.ModelListener;
55 import com.liferay.portal.model.Organization;
56 import com.liferay.portal.model.impl.OrganizationImpl;
57 import com.liferay.portal.model.impl.OrganizationModelImpl;
58 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
59
60 import java.io.Serializable;
61
62 import java.sql.Types;
63
64 import java.util.ArrayList;
65 import java.util.Collections;
66 import java.util.List;
67 import java.util.Set;
68
69
82 public class OrganizationPersistenceImpl extends BasePersistenceImpl<Organization>
83 implements OrganizationPersistence {
84 public static final String FINDER_CLASS_NAME_ENTITY = OrganizationImpl.class.getName();
85 public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
86 ".List";
87 public static final FinderPath FINDER_PATH_FIND_BY_COMPANYID = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
88 OrganizationModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
89 "findByCompanyId", new String[] { Long.class.getName() });
90 public static final FinderPath FINDER_PATH_FIND_BY_OBC_COMPANYID = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
91 OrganizationModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
92 "findByCompanyId",
93 new String[] {
94 Long.class.getName(),
95
96 "java.lang.Integer", "java.lang.Integer",
97 "com.liferay.portal.kernel.util.OrderByComparator"
98 });
99 public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
100 OrganizationModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
101 "countByCompanyId", new String[] { Long.class.getName() });
102 public static final FinderPath FINDER_PATH_FIND_BY_LOCATIONS = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
103 OrganizationModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
104 "findByLocations", new String[] { Long.class.getName() });
105 public static final FinderPath FINDER_PATH_FIND_BY_OBC_LOCATIONS = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
106 OrganizationModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
107 "findByLocations",
108 new String[] {
109 Long.class.getName(),
110
111 "java.lang.Integer", "java.lang.Integer",
112 "com.liferay.portal.kernel.util.OrderByComparator"
113 });
114 public static final FinderPath FINDER_PATH_COUNT_BY_LOCATIONS = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
115 OrganizationModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
116 "countByLocations", new String[] { Long.class.getName() });
117 public static final FinderPath FINDER_PATH_FIND_BY_C_P = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
118 OrganizationModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
119 "findByC_P",
120 new String[] { Long.class.getName(), Long.class.getName() });
121 public static final FinderPath FINDER_PATH_FIND_BY_OBC_C_P = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
122 OrganizationModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
123 "findByC_P",
124 new String[] {
125 Long.class.getName(), Long.class.getName(),
126
127 "java.lang.Integer", "java.lang.Integer",
128 "com.liferay.portal.kernel.util.OrderByComparator"
129 });
130 public static final FinderPath FINDER_PATH_COUNT_BY_C_P = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
131 OrganizationModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
132 "countByC_P",
133 new String[] { Long.class.getName(), Long.class.getName() });
134 public static final FinderPath FINDER_PATH_FETCH_BY_C_N = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
135 OrganizationModelImpl.FINDER_CACHE_ENABLED,
136 FINDER_CLASS_NAME_ENTITY, "fetchByC_N",
137 new String[] { Long.class.getName(), String.class.getName() });
138 public static final FinderPath FINDER_PATH_COUNT_BY_C_N = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
139 OrganizationModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
140 "countByC_N",
141 new String[] { Long.class.getName(), String.class.getName() });
142 public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
143 OrganizationModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
144 "findAll", new String[0]);
145 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
146 OrganizationModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
147 "countAll", new String[0]);
148
149 public void cacheResult(Organization organization) {
150 EntityCacheUtil.putResult(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
151 OrganizationImpl.class, organization.getPrimaryKey(), organization);
152
153 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
154 new Object[] {
155 new Long(organization.getCompanyId()),
156
157 organization.getName()
158 }, organization);
159 }
160
161 public void cacheResult(List<Organization> organizations) {
162 for (Organization organization : organizations) {
163 if (EntityCacheUtil.getResult(
164 OrganizationModelImpl.ENTITY_CACHE_ENABLED,
165 OrganizationImpl.class, organization.getPrimaryKey(),
166 this) == null) {
167 cacheResult(organization);
168 }
169 }
170 }
171
172 public void clearCache() {
173 CacheRegistry.clear(OrganizationImpl.class.getName());
174 EntityCacheUtil.clearCache(OrganizationImpl.class.getName());
175 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
176 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
177 }
178
179 public Organization create(long organizationId) {
180 Organization organization = new OrganizationImpl();
181
182 organization.setNew(true);
183 organization.setPrimaryKey(organizationId);
184
185 return organization;
186 }
187
188 public Organization remove(Serializable primaryKey)
189 throws NoSuchModelException, SystemException {
190 return remove(((Long)primaryKey).longValue());
191 }
192
193 public Organization remove(long organizationId)
194 throws NoSuchOrganizationException, SystemException {
195 Session session = null;
196
197 try {
198 session = openSession();
199
200 Organization organization = (Organization)session.get(OrganizationImpl.class,
201 new Long(organizationId));
202
203 if (organization == null) {
204 if (_log.isWarnEnabled()) {
205 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
206 organizationId);
207 }
208
209 throw new NoSuchOrganizationException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
210 organizationId);
211 }
212
213 return remove(organization);
214 }
215 catch (NoSuchOrganizationException nsee) {
216 throw nsee;
217 }
218 catch (Exception e) {
219 throw processException(e);
220 }
221 finally {
222 closeSession(session);
223 }
224 }
225
226 public Organization remove(Organization organization)
227 throws SystemException {
228 for (ModelListener<Organization> listener : listeners) {
229 listener.onBeforeRemove(organization);
230 }
231
232 organization = removeImpl(organization);
233
234 for (ModelListener<Organization> listener : listeners) {
235 listener.onAfterRemove(organization);
236 }
237
238 return organization;
239 }
240
241 protected Organization removeImpl(Organization organization)
242 throws SystemException {
243 organization = toUnwrappedModel(organization);
244
245 try {
246 clearGroups.clear(organization.getPrimaryKey());
247 }
248 catch (Exception e) {
249 throw processException(e);
250 }
251 finally {
252 FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_GROUPS_ORGS_NAME);
253 }
254
255 try {
256 clearUsers.clear(organization.getPrimaryKey());
257 }
258 catch (Exception e) {
259 throw processException(e);
260 }
261 finally {
262 FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_USERS_ORGS_NAME);
263 }
264
265 shrinkTree(organization);
266
267 Session session = null;
268
269 try {
270 session = openSession();
271
272 if (organization.isCachedModel() || BatchSessionUtil.isEnabled()) {
273 Object staleObject = session.get(OrganizationImpl.class,
274 organization.getPrimaryKeyObj());
275
276 if (staleObject != null) {
277 session.evict(staleObject);
278 }
279 }
280
281 session.delete(organization);
282
283 session.flush();
284 }
285 catch (Exception e) {
286 throw processException(e);
287 }
288 finally {
289 closeSession(session);
290 }
291
292 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
293
294 OrganizationModelImpl organizationModelImpl = (OrganizationModelImpl)organization;
295
296 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N,
297 new Object[] {
298 new Long(organizationModelImpl.getOriginalCompanyId()),
299
300 organizationModelImpl.getOriginalName()
301 });
302
303 EntityCacheUtil.removeResult(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
304 OrganizationImpl.class, organization.getPrimaryKey());
305
306 return organization;
307 }
308
309
312 public Organization update(Organization organization)
313 throws SystemException {
314 if (_log.isWarnEnabled()) {
315 _log.warn(
316 "Using the deprecated update(Organization organization) method. Use update(Organization organization, boolean merge) instead.");
317 }
318
319 return update(organization, false);
320 }
321
322 public Organization updateImpl(
323 com.liferay.portal.model.Organization organization, boolean merge)
324 throws SystemException {
325 organization = toUnwrappedModel(organization);
326
327 boolean isNew = organization.isNew();
328
329 OrganizationModelImpl organizationModelImpl = (OrganizationModelImpl)organization;
330
331 if (isNew) {
332 expandTree(organization);
333 }
334 else {
335 if (organization.getParentOrganizationId() != organizationModelImpl.getOriginalParentOrganizationId()) {
336 shrinkTree(organization);
337 expandTree(organization);
338 }
339 }
340
341 Session session = null;
342
343 try {
344 session = openSession();
345
346 BatchSessionUtil.update(session, organization, merge);
347
348 organization.setNew(false);
349 }
350 catch (Exception e) {
351 throw processException(e);
352 }
353 finally {
354 closeSession(session);
355 }
356
357 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
358
359 EntityCacheUtil.putResult(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
360 OrganizationImpl.class, organization.getPrimaryKey(), organization);
361
362 if (!isNew &&
363 ((organization.getCompanyId() != organizationModelImpl.getOriginalCompanyId()) ||
364 !Validator.equals(organization.getName(),
365 organizationModelImpl.getOriginalName()))) {
366 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N,
367 new Object[] {
368 new Long(organizationModelImpl.getOriginalCompanyId()),
369
370 organizationModelImpl.getOriginalName()
371 });
372 }
373
374 if (isNew ||
375 ((organization.getCompanyId() != organizationModelImpl.getOriginalCompanyId()) ||
376 !Validator.equals(organization.getName(),
377 organizationModelImpl.getOriginalName()))) {
378 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
379 new Object[] {
380 new Long(organization.getCompanyId()),
381
382 organization.getName()
383 }, organization);
384 }
385
386 return organization;
387 }
388
389 protected Organization toUnwrappedModel(Organization organization) {
390 if (organization instanceof OrganizationImpl) {
391 return organization;
392 }
393
394 OrganizationImpl organizationImpl = new OrganizationImpl();
395
396 organizationImpl.setNew(organization.isNew());
397 organizationImpl.setPrimaryKey(organization.getPrimaryKey());
398
399 organizationImpl.setOrganizationId(organization.getOrganizationId());
400 organizationImpl.setCompanyId(organization.getCompanyId());
401 organizationImpl.setParentOrganizationId(organization.getParentOrganizationId());
402 organizationImpl.setLeftOrganizationId(organization.getLeftOrganizationId());
403 organizationImpl.setRightOrganizationId(organization.getRightOrganizationId());
404 organizationImpl.setName(organization.getName());
405 organizationImpl.setType(organization.getType());
406 organizationImpl.setRecursable(organization.isRecursable());
407 organizationImpl.setRegionId(organization.getRegionId());
408 organizationImpl.setCountryId(organization.getCountryId());
409 organizationImpl.setStatusId(organization.getStatusId());
410 organizationImpl.setComments(organization.getComments());
411
412 return organizationImpl;
413 }
414
415 public Organization findByPrimaryKey(Serializable primaryKey)
416 throws NoSuchModelException, SystemException {
417 return findByPrimaryKey(((Long)primaryKey).longValue());
418 }
419
420 public Organization findByPrimaryKey(long organizationId)
421 throws NoSuchOrganizationException, SystemException {
422 Organization organization = fetchByPrimaryKey(organizationId);
423
424 if (organization == null) {
425 if (_log.isWarnEnabled()) {
426 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + organizationId);
427 }
428
429 throw new NoSuchOrganizationException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
430 organizationId);
431 }
432
433 return organization;
434 }
435
436 public Organization fetchByPrimaryKey(Serializable primaryKey)
437 throws SystemException {
438 return fetchByPrimaryKey(((Long)primaryKey).longValue());
439 }
440
441 public Organization fetchByPrimaryKey(long organizationId)
442 throws SystemException {
443 Organization organization = (Organization)EntityCacheUtil.getResult(OrganizationModelImpl.ENTITY_CACHE_ENABLED,
444 OrganizationImpl.class, organizationId, this);
445
446 if (organization == null) {
447 Session session = null;
448
449 try {
450 session = openSession();
451
452 organization = (Organization)session.get(OrganizationImpl.class,
453 new Long(organizationId));
454 }
455 catch (Exception e) {
456 throw processException(e);
457 }
458 finally {
459 if (organization != null) {
460 cacheResult(organization);
461 }
462
463 closeSession(session);
464 }
465 }
466
467 return organization;
468 }
469
470 public List<Organization> findByCompanyId(long companyId)
471 throws SystemException {
472 Object[] finderArgs = new Object[] { new Long(companyId) };
473
474 List<Organization> list = (List<Organization>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_COMPANYID,
475 finderArgs, this);
476
477 if (list == null) {
478 Session session = null;
479
480 try {
481 session = openSession();
482
483 StringBundler query = new StringBundler(3);
484
485 query.append(_SQL_SELECT_ORGANIZATION_WHERE);
486
487 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
488
489 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
490
491 String sql = query.toString();
492
493 Query q = session.createQuery(sql);
494
495 QueryPos qPos = QueryPos.getInstance(q);
496
497 qPos.add(companyId);
498
499 list = q.list();
500 }
501 catch (Exception e) {
502 throw processException(e);
503 }
504 finally {
505 if (list == null) {
506 list = new ArrayList<Organization>();
507 }
508
509 cacheResult(list);
510
511 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_COMPANYID,
512 finderArgs, list);
513
514 closeSession(session);
515 }
516 }
517
518 return list;
519 }
520
521 public List<Organization> findByCompanyId(long companyId, int start, int end)
522 throws SystemException {
523 return findByCompanyId(companyId, start, end, null);
524 }
525
526 public List<Organization> findByCompanyId(long companyId, int start,
527 int end, OrderByComparator obc) throws SystemException {
528 Object[] finderArgs = new Object[] {
529 new Long(companyId),
530
531 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
532 };
533
534 List<Organization> list = (List<Organization>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_COMPANYID,
535 finderArgs, this);
536
537 if (list == null) {
538 Session session = null;
539
540 try {
541 session = openSession();
542
543 StringBundler query = null;
544
545 if (obc != null) {
546 query = new StringBundler(3 +
547 (obc.getOrderByFields().length * 3));
548 }
549 else {
550 query = new StringBundler(3);
551 }
552
553 query.append(_SQL_SELECT_ORGANIZATION_WHERE);
554
555 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
556
557 if (obc != null) {
558 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
559 }
560
561 else {
562 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
563 }
564
565 String sql = query.toString();
566
567 Query q = session.createQuery(sql);
568
569 QueryPos qPos = QueryPos.getInstance(q);
570
571 qPos.add(companyId);
572
573 list = (List<Organization>)QueryUtil.list(q, getDialect(),
574 start, end);
575 }
576 catch (Exception e) {
577 throw processException(e);
578 }
579 finally {
580 if (list == null) {
581 list = new ArrayList<Organization>();
582 }
583
584 cacheResult(list);
585
586 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_COMPANYID,
587 finderArgs, list);
588
589 closeSession(session);
590 }
591 }
592
593 return list;
594 }
595
596 public Organization findByCompanyId_First(long companyId,
597 OrderByComparator obc)
598 throws NoSuchOrganizationException, SystemException {
599 List<Organization> list = findByCompanyId(companyId, 0, 1, obc);
600
601 if (list.isEmpty()) {
602 StringBundler msg = new StringBundler(4);
603
604 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
605
606 msg.append("companyId=");
607 msg.append(companyId);
608
609 msg.append(StringPool.CLOSE_CURLY_BRACE);
610
611 throw new NoSuchOrganizationException(msg.toString());
612 }
613 else {
614 return list.get(0);
615 }
616 }
617
618 public Organization findByCompanyId_Last(long companyId,
619 OrderByComparator obc)
620 throws NoSuchOrganizationException, SystemException {
621 int count = countByCompanyId(companyId);
622
623 List<Organization> list = findByCompanyId(companyId, count - 1, count,
624 obc);
625
626 if (list.isEmpty()) {
627 StringBundler msg = new StringBundler(4);
628
629 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
630
631 msg.append("companyId=");
632 msg.append(companyId);
633
634 msg.append(StringPool.CLOSE_CURLY_BRACE);
635
636 throw new NoSuchOrganizationException(msg.toString());
637 }
638 else {
639 return list.get(0);
640 }
641 }
642
643 public Organization[] findByCompanyId_PrevAndNext(long organizationId,
644 long companyId, OrderByComparator obc)
645 throws NoSuchOrganizationException, SystemException {
646 Organization organization = findByPrimaryKey(organizationId);
647
648 int count = countByCompanyId(companyId);
649
650 Session session = null;
651
652 try {
653 session = openSession();
654
655 StringBundler query = null;
656
657 if (obc != null) {
658 query = new StringBundler(3 +
659 (obc.getOrderByFields().length * 3));
660 }
661 else {
662 query = new StringBundler(3);
663 }
664
665 query.append(_SQL_SELECT_ORGANIZATION_WHERE);
666
667 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
668
669 if (obc != null) {
670 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
671 }
672
673 else {
674 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
675 }
676
677 String sql = query.toString();
678
679 Query q = session.createQuery(sql);
680
681 QueryPos qPos = QueryPos.getInstance(q);
682
683 qPos.add(companyId);
684
685 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
686 organization);
687
688 Organization[] array = new OrganizationImpl[3];
689
690 array[0] = (Organization)objArray[0];
691 array[1] = (Organization)objArray[1];
692 array[2] = (Organization)objArray[2];
693
694 return array;
695 }
696 catch (Exception e) {
697 throw processException(e);
698 }
699 finally {
700 closeSession(session);
701 }
702 }
703
704 public List<Organization> findByLocations(long companyId)
705 throws SystemException {
706 Object[] finderArgs = new Object[] { new Long(companyId) };
707
708 List<Organization> list = (List<Organization>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_LOCATIONS,
709 finderArgs, this);
710
711 if (list == null) {
712 Session session = null;
713
714 try {
715 session = openSession();
716
717 StringBundler query = new StringBundler(3);
718
719 query.append(_SQL_SELECT_ORGANIZATION_WHERE);
720
721 query.append(_FINDER_COLUMN_LOCATIONS_COMPANYID_2);
722
723 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
724
725 String sql = query.toString();
726
727 Query q = session.createQuery(sql);
728
729 QueryPos qPos = QueryPos.getInstance(q);
730
731 qPos.add(companyId);
732
733 list = q.list();
734 }
735 catch (Exception e) {
736 throw processException(e);
737 }
738 finally {
739 if (list == null) {
740 list = new ArrayList<Organization>();
741 }
742
743 cacheResult(list);
744
745 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_LOCATIONS,
746 finderArgs, list);
747
748 closeSession(session);
749 }
750 }
751
752 return list;
753 }
754
755 public List<Organization> findByLocations(long companyId, int start, int end)
756 throws SystemException {
757 return findByLocations(companyId, start, end, null);
758 }
759
760 public List<Organization> findByLocations(long companyId, int start,
761 int end, OrderByComparator obc) throws SystemException {
762 Object[] finderArgs = new Object[] {
763 new Long(companyId),
764
765 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
766 };
767
768 List<Organization> list = (List<Organization>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_LOCATIONS,
769 finderArgs, this);
770
771 if (list == null) {
772 Session session = null;
773
774 try {
775 session = openSession();
776
777 StringBundler query = null;
778
779 if (obc != null) {
780 query = new StringBundler(3 +
781 (obc.getOrderByFields().length * 3));
782 }
783 else {
784 query = new StringBundler(3);
785 }
786
787 query.append(_SQL_SELECT_ORGANIZATION_WHERE);
788
789 query.append(_FINDER_COLUMN_LOCATIONS_COMPANYID_2);
790
791 if (obc != null) {
792 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
793 }
794
795 else {
796 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
797 }
798
799 String sql = query.toString();
800
801 Query q = session.createQuery(sql);
802
803 QueryPos qPos = QueryPos.getInstance(q);
804
805 qPos.add(companyId);
806
807 list = (List<Organization>)QueryUtil.list(q, getDialect(),
808 start, end);
809 }
810 catch (Exception e) {
811 throw processException(e);
812 }
813 finally {
814 if (list == null) {
815 list = new ArrayList<Organization>();
816 }
817
818 cacheResult(list);
819
820 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_LOCATIONS,
821 finderArgs, list);
822
823 closeSession(session);
824 }
825 }
826
827 return list;
828 }
829
830 public Organization findByLocations_First(long companyId,
831 OrderByComparator obc)
832 throws NoSuchOrganizationException, SystemException {
833 List<Organization> list = findByLocations(companyId, 0, 1, obc);
834
835 if (list.isEmpty()) {
836 StringBundler msg = new StringBundler(4);
837
838 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
839
840 msg.append("companyId=");
841 msg.append(companyId);
842
843 msg.append(StringPool.CLOSE_CURLY_BRACE);
844
845 throw new NoSuchOrganizationException(msg.toString());
846 }
847 else {
848 return list.get(0);
849 }
850 }
851
852 public Organization findByLocations_Last(long companyId,
853 OrderByComparator obc)
854 throws NoSuchOrganizationException, SystemException {
855 int count = countByLocations(companyId);
856
857 List<Organization> list = findByLocations(companyId, count - 1, count,
858 obc);
859
860 if (list.isEmpty()) {
861 StringBundler msg = new StringBundler(4);
862
863 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
864
865 msg.append("companyId=");
866 msg.append(companyId);
867
868 msg.append(StringPool.CLOSE_CURLY_BRACE);
869
870 throw new NoSuchOrganizationException(msg.toString());
871 }
872 else {
873 return list.get(0);
874 }
875 }
876
877 public Organization[] findByLocations_PrevAndNext(long organizationId,
878 long companyId, OrderByComparator obc)
879 throws NoSuchOrganizationException, SystemException {
880 Organization organization = findByPrimaryKey(organizationId);
881
882 int count = countByLocations(companyId);
883
884 Session session = null;
885
886 try {
887 session = openSession();
888
889 StringBundler query = null;
890
891 if (obc != null) {
892 query = new StringBundler(3 +
893 (obc.getOrderByFields().length * 3));
894 }
895 else {
896 query = new StringBundler(3);
897 }
898
899 query.append(_SQL_SELECT_ORGANIZATION_WHERE);
900
901 query.append(_FINDER_COLUMN_LOCATIONS_COMPANYID_2);
902
903 if (obc != null) {
904 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
905 }
906
907 else {
908 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
909 }
910
911 String sql = query.toString();
912
913 Query q = session.createQuery(sql);
914
915 QueryPos qPos = QueryPos.getInstance(q);
916
917 qPos.add(companyId);
918
919 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
920 organization);
921
922 Organization[] array = new OrganizationImpl[3];
923
924 array[0] = (Organization)objArray[0];
925 array[1] = (Organization)objArray[1];
926 array[2] = (Organization)objArray[2];
927
928 return array;
929 }
930 catch (Exception e) {
931 throw processException(e);
932 }
933 finally {
934 closeSession(session);
935 }
936 }
937
938 public List<Organization> findByC_P(long companyId,
939 long parentOrganizationId) throws SystemException {
940 Object[] finderArgs = new Object[] {
941 new Long(companyId), new Long(parentOrganizationId)
942 };
943
944 List<Organization> list = (List<Organization>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_P,
945 finderArgs, this);
946
947 if (list == null) {
948 Session session = null;
949
950 try {
951 session = openSession();
952
953 StringBundler query = new StringBundler(4);
954
955 query.append(_SQL_SELECT_ORGANIZATION_WHERE);
956
957 query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
958
959 query.append(_FINDER_COLUMN_C_P_PARENTORGANIZATIONID_2);
960
961 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
962
963 String sql = query.toString();
964
965 Query q = session.createQuery(sql);
966
967 QueryPos qPos = QueryPos.getInstance(q);
968
969 qPos.add(companyId);
970
971 qPos.add(parentOrganizationId);
972
973 list = q.list();
974 }
975 catch (Exception e) {
976 throw processException(e);
977 }
978 finally {
979 if (list == null) {
980 list = new ArrayList<Organization>();
981 }
982
983 cacheResult(list);
984
985 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_P, finderArgs,
986 list);
987
988 closeSession(session);
989 }
990 }
991
992 return list;
993 }
994
995 public List<Organization> findByC_P(long companyId,
996 long parentOrganizationId, int start, int end)
997 throws SystemException {
998 return findByC_P(companyId, parentOrganizationId, start, end, null);
999 }
1000
1001 public List<Organization> findByC_P(long companyId,
1002 long parentOrganizationId, int start, int end, OrderByComparator obc)
1003 throws SystemException {
1004 Object[] finderArgs = new Object[] {
1005 new Long(companyId), new Long(parentOrganizationId),
1006
1007 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1008 };
1009
1010 List<Organization> list = (List<Organization>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_C_P,
1011 finderArgs, this);
1012
1013 if (list == null) {
1014 Session session = null;
1015
1016 try {
1017 session = openSession();
1018
1019 StringBundler query = null;
1020
1021 if (obc != null) {
1022 query = new StringBundler(4 +
1023 (obc.getOrderByFields().length * 3));
1024 }
1025 else {
1026 query = new StringBundler(4);
1027 }
1028
1029 query.append(_SQL_SELECT_ORGANIZATION_WHERE);
1030
1031 query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
1032
1033 query.append(_FINDER_COLUMN_C_P_PARENTORGANIZATIONID_2);
1034
1035 if (obc != null) {
1036 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
1037 }
1038
1039 else {
1040 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
1041 }
1042
1043 String sql = query.toString();
1044
1045 Query q = session.createQuery(sql);
1046
1047 QueryPos qPos = QueryPos.getInstance(q);
1048
1049 qPos.add(companyId);
1050
1051 qPos.add(parentOrganizationId);
1052
1053 list = (List<Organization>)QueryUtil.list(q, getDialect(),
1054 start, end);
1055 }
1056 catch (Exception e) {
1057 throw processException(e);
1058 }
1059 finally {
1060 if (list == null) {
1061 list = new ArrayList<Organization>();
1062 }
1063
1064 cacheResult(list);
1065
1066 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_C_P,
1067 finderArgs, list);
1068
1069 closeSession(session);
1070 }
1071 }
1072
1073 return list;
1074 }
1075
1076 public Organization findByC_P_First(long companyId,
1077 long parentOrganizationId, OrderByComparator obc)
1078 throws NoSuchOrganizationException, SystemException {
1079 List<Organization> list = findByC_P(companyId, parentOrganizationId, 0,
1080 1, obc);
1081
1082 if (list.isEmpty()) {
1083 StringBundler msg = new StringBundler(6);
1084
1085 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1086
1087 msg.append("companyId=");
1088 msg.append(companyId);
1089
1090 msg.append(", parentOrganizationId=");
1091 msg.append(parentOrganizationId);
1092
1093 msg.append(StringPool.CLOSE_CURLY_BRACE);
1094
1095 throw new NoSuchOrganizationException(msg.toString());
1096 }
1097 else {
1098 return list.get(0);
1099 }
1100 }
1101
1102 public Organization findByC_P_Last(long companyId,
1103 long parentOrganizationId, OrderByComparator obc)
1104 throws NoSuchOrganizationException, SystemException {
1105 int count = countByC_P(companyId, parentOrganizationId);
1106
1107 List<Organization> list = findByC_P(companyId, parentOrganizationId,
1108 count - 1, count, obc);
1109
1110 if (list.isEmpty()) {
1111 StringBundler msg = new StringBundler(6);
1112
1113 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1114
1115 msg.append("companyId=");
1116 msg.append(companyId);
1117
1118 msg.append(", parentOrganizationId=");
1119 msg.append(parentOrganizationId);
1120
1121 msg.append(StringPool.CLOSE_CURLY_BRACE);
1122
1123 throw new NoSuchOrganizationException(msg.toString());
1124 }
1125 else {
1126 return list.get(0);
1127 }
1128 }
1129
1130 public Organization[] findByC_P_PrevAndNext(long organizationId,
1131 long companyId, long parentOrganizationId, OrderByComparator obc)
1132 throws NoSuchOrganizationException, SystemException {
1133 Organization organization = findByPrimaryKey(organizationId);
1134
1135 int count = countByC_P(companyId, parentOrganizationId);
1136
1137 Session session = null;
1138
1139 try {
1140 session = openSession();
1141
1142 StringBundler query = null;
1143
1144 if (obc != null) {
1145 query = new StringBundler(4 +
1146 (obc.getOrderByFields().length * 3));
1147 }
1148 else {
1149 query = new StringBundler(4);
1150 }
1151
1152 query.append(_SQL_SELECT_ORGANIZATION_WHERE);
1153
1154 query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
1155
1156 query.append(_FINDER_COLUMN_C_P_PARENTORGANIZATIONID_2);
1157
1158 if (obc != null) {
1159 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
1160 }
1161
1162 else {
1163 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
1164 }
1165
1166 String sql = query.toString();
1167
1168 Query q = session.createQuery(sql);
1169
1170 QueryPos qPos = QueryPos.getInstance(q);
1171
1172 qPos.add(companyId);
1173
1174 qPos.add(parentOrganizationId);
1175
1176 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1177 organization);
1178
1179 Organization[] array = new OrganizationImpl[3];
1180
1181 array[0] = (Organization)objArray[0];
1182 array[1] = (Organization)objArray[1];
1183 array[2] = (Organization)objArray[2];
1184
1185 return array;
1186 }
1187 catch (Exception e) {
1188 throw processException(e);
1189 }
1190 finally {
1191 closeSession(session);
1192 }
1193 }
1194
1195 public Organization findByC_N(long companyId, String name)
1196 throws NoSuchOrganizationException, SystemException {
1197 Organization organization = fetchByC_N(companyId, name);
1198
1199 if (organization == null) {
1200 StringBundler msg = new StringBundler(6);
1201
1202 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1203
1204 msg.append("companyId=");
1205 msg.append(companyId);
1206
1207 msg.append(", name=");
1208 msg.append(name);
1209
1210 msg.append(StringPool.CLOSE_CURLY_BRACE);
1211
1212 if (_log.isWarnEnabled()) {
1213 _log.warn(msg.toString());
1214 }
1215
1216 throw new NoSuchOrganizationException(msg.toString());
1217 }
1218
1219 return organization;
1220 }
1221
1222 public Organization fetchByC_N(long companyId, String name)
1223 throws SystemException {
1224 return fetchByC_N(companyId, name, true);
1225 }
1226
1227 public Organization fetchByC_N(long companyId, String name,
1228 boolean retrieveFromCache) throws SystemException {
1229 Object[] finderArgs = new Object[] { new Long(companyId), name };
1230
1231 Object result = null;
1232
1233 if (retrieveFromCache) {
1234 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_N,
1235 finderArgs, this);
1236 }
1237
1238 if (result == null) {
1239 Session session = null;
1240
1241 try {
1242 session = openSession();
1243
1244 StringBundler query = new StringBundler(4);
1245
1246 query.append(_SQL_SELECT_ORGANIZATION_WHERE);
1247
1248 query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
1249
1250 if (name == null) {
1251 query.append(_FINDER_COLUMN_C_N_NAME_1);
1252 }
1253 else {
1254 if (name.equals(StringPool.BLANK)) {
1255 query.append(_FINDER_COLUMN_C_N_NAME_3);
1256 }
1257 else {
1258 query.append(_FINDER_COLUMN_C_N_NAME_2);
1259 }
1260 }
1261
1262 query.append(OrganizationModelImpl.ORDER_BY_JPQL);
1263
1264 String sql = query.toString();
1265
1266 Query q = session.createQuery(sql);
1267
1268 QueryPos qPos = QueryPos.getInstance(q);
1269
1270 qPos.add(companyId);
1271
1272 if (name != null) {
1273 qPos.add(name);
1274 }
1275
1276 List<Organization> list = q.list();
1277
1278 result = list;
1279
1280 Organization organization = null;
1281
1282 if (list.isEmpty()) {
1283 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
1284 finderArgs, list);
1285 }
1286 else {
1287 organization = list.get(0);
1288
1289 cacheResult(organization);
1290
1291 if ((organization.getCompanyId() != companyId) ||
1292 (organization.getName() == null) ||
1293 !organization.getName().equals(name)) {
1294 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
1295 finderArgs, organization);
1296 }
1297 }
1298
1299 return organization;
1300 }
1301 catch (Exception e) {
1302 throw processException(e);
1303 }
1304 finally {
1305 if (result == null) {
1306 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
1307 finderArgs, new ArrayList<Organization>());
1308 }
1309
1310 closeSession(session);
1311 }
1312 }
1313 else {
1314 if (result instanceof List<?>) {
1315 return null;
1316 }
1317 else {
1318 return (Organization)result;
1319 }
1320 }
1321 }
1322
1323 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
1324 throws SystemException {
1325 Session session = null;
1326
1327 try {
1328 session = openSession();
1329
1330 dynamicQuery.compile(session);
1331
1332 return dynamicQuery.list();
1333 }
1334 catch (Exception e) {
1335 throw processException(e);
1336 }
1337 finally {
1338 closeSession(session);
1339 }
1340 }
1341
1342 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
1343 int start, int end) throws SystemException {
1344 Session session = null;
1345
1346 try {
1347 session = openSession();
1348
1349 dynamicQuery.setLimit(start, end);
1350
1351 dynamicQuery.compile(session);
1352
1353 return dynamicQuery.list();
1354 }
1355 catch (Exception e) {
1356 throw processException(e);
1357 }
1358 finally {
1359 closeSession(session);
1360 }
1361 }
1362
1363 public List<Organization> findAll() throws SystemException {
1364 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1365 }
1366
1367 public List<Organization> findAll(int start, int end)
1368 throws SystemException {
1369 return findAll(start, end, null);
1370 }
1371
1372 public List<Organization> findAll(int start, int end, OrderByComparator obc)
1373 throws SystemException {
1374 Object[] finderArgs = new Object[] {
1375 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1376 };
1377
1378 List<Organization> list = (List<Organization>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1379 finderArgs, this);
1380
1381 if (list == null) {
1382 Session session = null;
1383
1384 try {
1385 session = openSession();
1386
1387 StringBundler query = null;
1388 String sql = null;
1389
1390 if (obc != null) {
1391 query = new StringBundler(2 +
1392 (obc.getOrderByFields().length * 3));
1393
1394 query.append(_SQL_SELECT_ORGANIZATION);
1395
1396 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
1397
1398 sql = query.toString();
1399 }
1400
1401 else {
1402 sql = _SQL_SELECT_ORGANIZATION.concat(OrganizationModelImpl.ORDER_BY_JPQL);
1403 }
1404
1405 Query q = session.createQuery(sql);
1406
1407 if (obc == null) {
1408 list = (List<Organization>)QueryUtil.list(q, getDialect(),
1409 start, end, false);
1410
1411 Collections.sort(list);
1412 }
1413 else {
1414 list = (List<Organization>)QueryUtil.list(q, getDialect(),
1415 start, end);
1416 }
1417 }
1418 catch (Exception e) {
1419 throw processException(e);
1420 }
1421 finally {
1422 if (list == null) {
1423 list = new ArrayList<Organization>();
1424 }
1425
1426 cacheResult(list);
1427
1428 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1429
1430 closeSession(session);
1431 }
1432 }
1433
1434 return list;
1435 }
1436
1437 public void removeByCompanyId(long companyId) throws SystemException {
1438 for (Organization organization : findByCompanyId(companyId)) {
1439 remove(organization);
1440 }
1441 }
1442
1443 public void removeByLocations(long companyId) throws SystemException {
1444 for (Organization organization : findByLocations(companyId)) {
1445 remove(organization);
1446 }
1447 }
1448
1449 public void removeByC_P(long companyId, long parentOrganizationId)
1450 throws SystemException {
1451 for (Organization organization : findByC_P(companyId,
1452 parentOrganizationId)) {
1453 remove(organization);
1454 }
1455 }
1456
1457 public void removeByC_N(long companyId, String name)
1458 throws NoSuchOrganizationException, SystemException {
1459 Organization organization = findByC_N(companyId, name);
1460
1461 remove(organization);
1462 }
1463
1464 public void removeAll() throws SystemException {
1465 for (Organization organization : findAll()) {
1466 remove(organization);
1467 }
1468 }
1469
1470 public int countByCompanyId(long companyId) throws SystemException {
1471 Object[] finderArgs = new Object[] { new Long(companyId) };
1472
1473 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
1474 finderArgs, this);
1475
1476 if (count == null) {
1477 Session session = null;
1478
1479 try {
1480 session = openSession();
1481
1482 StringBundler query = new StringBundler(2);
1483
1484 query.append(_SQL_COUNT_ORGANIZATION_WHERE);
1485
1486 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1487
1488 String sql = query.toString();
1489
1490 Query q = session.createQuery(sql);
1491
1492 QueryPos qPos = QueryPos.getInstance(q);
1493
1494 qPos.add(companyId);
1495
1496 count = (Long)q.uniqueResult();
1497 }
1498 catch (Exception e) {
1499 throw processException(e);
1500 }
1501 finally {
1502 if (count == null) {
1503 count = Long.valueOf(0);
1504 }
1505
1506 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
1507 finderArgs, count);
1508
1509 closeSession(session);
1510 }
1511 }
1512
1513 return count.intValue();
1514 }
1515
1516 public int countByLocations(long companyId) throws SystemException {
1517 Object[] finderArgs = new Object[] { new Long(companyId) };
1518
1519 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_LOCATIONS,
1520 finderArgs, this);
1521
1522 if (count == null) {
1523 Session session = null;
1524
1525 try {
1526 session = openSession();
1527
1528 StringBundler query = new StringBundler(2);
1529
1530 query.append(_SQL_COUNT_ORGANIZATION_WHERE);
1531
1532 query.append(_FINDER_COLUMN_LOCATIONS_COMPANYID_2);
1533
1534 String sql = query.toString();
1535
1536 Query q = session.createQuery(sql);
1537
1538 QueryPos qPos = QueryPos.getInstance(q);
1539
1540 qPos.add(companyId);
1541
1542 count = (Long)q.uniqueResult();
1543 }
1544 catch (Exception e) {
1545 throw processException(e);
1546 }
1547 finally {
1548 if (count == null) {
1549 count = Long.valueOf(0);
1550 }
1551
1552 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_LOCATIONS,
1553 finderArgs, count);
1554
1555 closeSession(session);
1556 }
1557 }
1558
1559 return count.intValue();
1560 }
1561
1562 public int countByC_P(long companyId, long parentOrganizationId)
1563 throws SystemException {
1564 Object[] finderArgs = new Object[] {
1565 new Long(companyId), new Long(parentOrganizationId)
1566 };
1567
1568 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_P,
1569 finderArgs, this);
1570
1571 if (count == null) {
1572 Session session = null;
1573
1574 try {
1575 session = openSession();
1576
1577 StringBundler query = new StringBundler(3);
1578
1579 query.append(_SQL_COUNT_ORGANIZATION_WHERE);
1580
1581 query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
1582
1583 query.append(_FINDER_COLUMN_C_P_PARENTORGANIZATIONID_2);
1584
1585 String sql = query.toString();
1586
1587 Query q = session.createQuery(sql);
1588
1589 QueryPos qPos = QueryPos.getInstance(q);
1590
1591 qPos.add(companyId);
1592
1593 qPos.add(parentOrganizationId);
1594
1595 count = (Long)q.uniqueResult();
1596 }
1597 catch (Exception e) {
1598 throw processException(e);
1599 }
1600 finally {
1601 if (count == null) {
1602 count = Long.valueOf(0);
1603 }
1604
1605 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_P, finderArgs,
1606 count);
1607
1608 closeSession(session);
1609 }
1610 }
1611
1612 return count.intValue();
1613 }
1614
1615 public int countByC_N(long companyId, String name)
1616 throws SystemException {
1617 Object[] finderArgs = new Object[] { new Long(companyId), name };
1618
1619 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_N,
1620 finderArgs, this);
1621
1622 if (count == null) {
1623 Session session = null;
1624
1625 try {
1626 session = openSession();
1627
1628 StringBundler query = new StringBundler(3);
1629
1630 query.append(_SQL_COUNT_ORGANIZATION_WHERE);
1631
1632 query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
1633
1634 if (name == null) {
1635 query.append(_FINDER_COLUMN_C_N_NAME_1);
1636 }
1637 else {
1638 if (name.equals(StringPool.BLANK)) {
1639 query.append(_FINDER_COLUMN_C_N_NAME_3);
1640 }
1641 else {
1642 query.append(_FINDER_COLUMN_C_N_NAME_2);
1643 }
1644 }
1645
1646 String sql = query.toString();
1647
1648 Query q = session.createQuery(sql);
1649
1650 QueryPos qPos = QueryPos.getInstance(q);
1651
1652 qPos.add(companyId);
1653
1654 if (name != null) {
1655 qPos.add(name);
1656 }
1657
1658 count = (Long)q.uniqueResult();
1659 }
1660 catch (Exception e) {
1661 throw processException(e);
1662 }
1663 finally {
1664 if (count == null) {
1665 count = Long.valueOf(0);
1666 }
1667
1668 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_N, finderArgs,
1669 count);
1670
1671 closeSession(session);
1672 }
1673 }
1674
1675 return count.intValue();
1676 }
1677
1678 public int countAll() throws SystemException {
1679 Object[] finderArgs = new Object[0];
1680
1681 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1682 finderArgs, this);
1683
1684 if (count == null) {
1685 Session session = null;
1686
1687 try {
1688 session = openSession();
1689
1690 Query q = session.createQuery(_SQL_COUNT_ORGANIZATION);
1691
1692 count = (Long)q.uniqueResult();
1693 }
1694 catch (Exception e) {
1695 throw processException(e);
1696 }
1697 finally {
1698 if (count == null) {
1699 count = Long.valueOf(0);
1700 }
1701
1702 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1703 count);
1704
1705 closeSession(session);
1706 }
1707 }
1708
1709 return count.intValue();
1710 }
1711
1712 public List<com.liferay.portal.model.Group> getGroups(long pk)
1713 throws SystemException {
1714 return getGroups(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
1715 }
1716
1717 public List<com.liferay.portal.model.Group> getGroups(long pk, int start,
1718 int end) throws SystemException {
1719 return getGroups(pk, start, end, null);
1720 }
1721
1722 public static final FinderPath FINDER_PATH_GET_GROUPS = new FinderPath(com.liferay.portal.model.impl.GroupModelImpl.ENTITY_CACHE_ENABLED,
1723 OrganizationModelImpl.FINDER_CACHE_ENABLED_GROUPS_ORGS,
1724 OrganizationModelImpl.MAPPING_TABLE_GROUPS_ORGS_NAME, "getGroups",
1725 new String[] {
1726 Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
1727 "com.liferay.portal.kernel.util.OrderByComparator"
1728 });
1729
1730 public List<com.liferay.portal.model.Group> getGroups(long pk, int start,
1731 int end, OrderByComparator obc) throws SystemException {
1732 Object[] finderArgs = new Object[] {
1733 new Long(pk), String.valueOf(start), String.valueOf(end),
1734 String.valueOf(obc)
1735 };
1736
1737 List<com.liferay.portal.model.Group> list = (List<com.liferay.portal.model.Group>)FinderCacheUtil.getResult(FINDER_PATH_GET_GROUPS,
1738 finderArgs, this);
1739
1740 if (list == null) {
1741 Session session = null;
1742
1743 try {
1744 session = openSession();
1745
1746 StringBundler query = null;
1747 String sql = null;
1748
1749 if (obc != null) {
1750 query = new StringBundler(3);
1751
1752 query.append(_SQL_GETGROUPS);
1753 query.append(ORDER_BY_CLAUSE);
1754 query.append(obc.getOrderBy());
1755
1756 sql = query.toString();
1757 }
1758
1759 else {
1760 sql = _SQL_GETGROUPS.concat(com.liferay.portal.model.impl.GroupModelImpl.ORDER_BY_SQL);
1761 }
1762
1763 SQLQuery q = session.createSQLQuery(sql);
1764
1765 q.addEntity("Group_",
1766 com.liferay.portal.model.impl.GroupImpl.class);
1767
1768 QueryPos qPos = QueryPos.getInstance(q);
1769
1770 qPos.add(pk);
1771
1772 list = (List<com.liferay.portal.model.Group>)QueryUtil.list(q,
1773 getDialect(), start, end);
1774 }
1775 catch (Exception e) {
1776 throw processException(e);
1777 }
1778 finally {
1779 if (list == null) {
1780 list = new ArrayList<com.liferay.portal.model.Group>();
1781 }
1782
1783 groupPersistence.cacheResult(list);
1784
1785 FinderCacheUtil.putResult(FINDER_PATH_GET_GROUPS, finderArgs,
1786 list);
1787
1788 closeSession(session);
1789 }
1790 }
1791
1792 return list;
1793 }
1794
1795 public static final FinderPath FINDER_PATH_GET_GROUPS_SIZE = new FinderPath(com.liferay.portal.model.impl.GroupModelImpl.ENTITY_CACHE_ENABLED,
1796 OrganizationModelImpl.FINDER_CACHE_ENABLED_GROUPS_ORGS,
1797 OrganizationModelImpl.MAPPING_TABLE_GROUPS_ORGS_NAME,
1798 "getGroupsSize", new String[] { Long.class.getName() });
1799
1800 public int getGroupsSize(long pk) throws SystemException {
1801 Object[] finderArgs = new Object[] { new Long(pk) };
1802
1803 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_GROUPS_SIZE,
1804 finderArgs, this);
1805
1806 if (count == null) {
1807 Session session = null;
1808
1809 try {
1810 session = openSession();
1811
1812 SQLQuery q = session.createSQLQuery(_SQL_GETGROUPSSIZE);
1813
1814 q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
1815
1816 QueryPos qPos = QueryPos.getInstance(q);
1817
1818 qPos.add(pk);
1819
1820 count = (Long)q.uniqueResult();
1821 }
1822 catch (Exception e) {
1823 throw processException(e);
1824 }
1825 finally {
1826 if (count == null) {
1827 count = Long.valueOf(0);
1828 }
1829
1830 FinderCacheUtil.putResult(FINDER_PATH_GET_GROUPS_SIZE,
1831 finderArgs, count);
1832
1833 closeSession(session);
1834 }
1835 }
1836
1837 return count.intValue();
1838 }
1839
1840 public static final FinderPath FINDER_PATH_CONTAINS_GROUP = new FinderPath(com.liferay.portal.model.impl.GroupModelImpl.ENTITY_CACHE_ENABLED,
1841 OrganizationModelImpl.FINDER_CACHE_ENABLED_GROUPS_ORGS,
1842 OrganizationModelImpl.MAPPING_TABLE_GROUPS_ORGS_NAME,
1843 "containsGroup",
1844 new String[] { Long.class.getName(), Long.class.getName() });
1845
1846 public boolean containsGroup(long pk, long groupPK)
1847 throws SystemException {
1848 Object[] finderArgs = new Object[] { new Long(pk), new Long(groupPK) };
1849
1850 Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_GROUP,
1851 finderArgs, this);
1852
1853 if (value == null) {
1854 try {
1855 value = Boolean.valueOf(containsGroup.contains(pk, groupPK));
1856 }
1857 catch (Exception e) {
1858 throw processException(e);
1859 }
1860 finally {
1861 if (value == null) {
1862 value = Boolean.FALSE;
1863 }
1864
1865 FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_GROUP,
1866 finderArgs, value);
1867 }
1868 }
1869
1870 return value.booleanValue();
1871 }
1872
1873 public boolean containsGroups(long pk) throws SystemException {
1874 if (getGroupsSize(pk) > 0) {
1875 return true;
1876 }
1877 else {
1878 return false;
1879 }
1880 }
1881
1882 public void addGroup(long pk, long groupPK) throws SystemException {
1883 try {
1884 addGroup.add(pk, groupPK);
1885 }
1886 catch (Exception e) {
1887 throw processException(e);
1888 }
1889 finally {
1890 FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_GROUPS_ORGS_NAME);
1891 }
1892 }
1893
1894 public void addGroup(long pk, com.liferay.portal.model.Group group)
1895 throws SystemException {
1896 try {
1897 addGroup.add(pk, group.getPrimaryKey());
1898 }
1899 catch (Exception e) {
1900 throw processException(e);
1901 }
1902 finally {
1903 FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_GROUPS_ORGS_NAME);
1904 }
1905 }
1906
1907 public void addGroups(long pk, long[] groupPKs) throws SystemException {
1908 try {
1909 for (long groupPK : groupPKs) {
1910 addGroup.add(pk, groupPK);
1911 }
1912 }
1913 catch (Exception e) {
1914 throw processException(e);
1915 }
1916 finally {
1917 FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_GROUPS_ORGS_NAME);
1918 }
1919 }
1920
1921 public void addGroups(long pk, List<com.liferay.portal.model.Group> groups)
1922 throws SystemException {
1923 try {
1924 for (com.liferay.portal.model.Group group : groups) {
1925 addGroup.add(pk, group.getPrimaryKey());
1926 }
1927 }
1928 catch (Exception e) {
1929 throw processException(e);
1930 }
1931 finally {
1932 FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_GROUPS_ORGS_NAME);
1933 }
1934 }
1935
1936 public void clearGroups(long pk) throws SystemException {
1937 try {
1938 clearGroups.clear(pk);
1939 }
1940 catch (Exception e) {
1941 throw processException(e);
1942 }
1943 finally {
1944 FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_GROUPS_ORGS_NAME);
1945 }
1946 }
1947
1948 public void removeGroup(long pk, long groupPK) throws SystemException {
1949 try {
1950 removeGroup.remove(pk, groupPK);
1951 }
1952 catch (Exception e) {
1953 throw processException(e);
1954 }
1955 finally {
1956 FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_GROUPS_ORGS_NAME);
1957 }
1958 }
1959
1960 public void removeGroup(long pk, com.liferay.portal.model.Group group)
1961 throws SystemException {
1962 try {
1963 removeGroup.remove(pk, group.getPrimaryKey());
1964 }
1965 catch (Exception e) {
1966 throw processException(e);
1967 }
1968 finally {
1969 FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_GROUPS_ORGS_NAME);
1970 }
1971 }
1972
1973 public void removeGroups(long pk, long[] groupPKs)
1974 throws SystemException {
1975 try {
1976 for (long groupPK : groupPKs) {
1977 removeGroup.remove(pk, groupPK);
1978 }
1979 }
1980 catch (Exception e) {
1981 throw processException(e);
1982 }
1983 finally {
1984 FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_GROUPS_ORGS_NAME);
1985 }
1986 }
1987
1988 public void removeGroups(long pk,
1989 List<com.liferay.portal.model.Group> groups) throws SystemException {
1990 try {
1991 for (com.liferay.portal.model.Group group : groups) {
1992 removeGroup.remove(pk, group.getPrimaryKey());
1993 }
1994 }
1995 catch (Exception e) {
1996 throw processException(e);
1997 }
1998 finally {
1999 FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_GROUPS_ORGS_NAME);
2000 }
2001 }
2002
2003 public void setGroups(long pk, long[] groupPKs) throws SystemException {
2004 try {
2005 Set<Long> groupPKSet = SetUtil.fromArray(groupPKs);
2006
2007 List<com.liferay.portal.model.Group> groups = getGroups(pk);
2008
2009 for (com.liferay.portal.model.Group group : groups) {
2010 if (!groupPKSet.contains(group.getPrimaryKey())) {
2011 removeGroup.remove(pk, group.getPrimaryKey());
2012 }
2013 else {
2014 groupPKSet.remove(group.getPrimaryKey());
2015 }
2016 }
2017
2018 for (Long groupPK : groupPKSet) {
2019 addGroup.add(pk, groupPK);
2020 }
2021 }
2022 catch (Exception e) {
2023 throw processException(e);
2024 }
2025 finally {
2026 FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_GROUPS_ORGS_NAME);
2027 }
2028 }
2029
2030 public void setGroups(long pk, List<com.liferay.portal.model.Group> groups)
2031 throws SystemException {
2032 try {
2033 long[] groupPKs = new long[groups.size()];
2034
2035 for (int i = 0; i < groups.size(); i++) {
2036 com.liferay.portal.model.Group group = groups.get(i);
2037
2038 groupPKs[i] = group.getPrimaryKey();
2039 }
2040
2041 setGroups(pk, groupPKs);
2042 }
2043 catch (Exception e) {
2044 throw processException(e);
2045 }
2046 finally {
2047 FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_GROUPS_ORGS_NAME);
2048 }
2049 }
2050
2051 public List<com.liferay.portal.model.User> getUsers(long pk)
2052 throws SystemException {
2053 return getUsers(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
2054 }
2055
2056 public List<com.liferay.portal.model.User> getUsers(long pk, int start,
2057 int end) throws SystemException {
2058 return getUsers(pk, start, end, null);
2059 }
2060
2061 public static final FinderPath FINDER_PATH_GET_USERS = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
2062 OrganizationModelImpl.FINDER_CACHE_ENABLED_USERS_ORGS,
2063 OrganizationModelImpl.MAPPING_TABLE_USERS_ORGS_NAME, "getUsers",
2064 new String[] {
2065 Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
2066 "com.liferay.portal.kernel.util.OrderByComparator"
2067 });
2068
2069 public List<com.liferay.portal.model.User> getUsers(long pk, int start,
2070 int end, OrderByComparator obc) throws SystemException {
2071 Object[] finderArgs = new Object[] {
2072 new Long(pk), String.valueOf(start), String.valueOf(end),
2073 String.valueOf(obc)
2074 };
2075
2076 List<com.liferay.portal.model.User> list = (List<com.liferay.portal.model.User>)FinderCacheUtil.getResult(FINDER_PATH_GET_USERS,
2077 finderArgs, this);
2078
2079 if (list == null) {
2080 Session session = null;
2081
2082 try {
2083 session = openSession();
2084
2085 StringBundler query = null;
2086 String sql = null;
2087
2088 if (obc != null) {
2089 query = new StringBundler(3);
2090
2091 query.append(_SQL_GETUSERS);
2092 query.append(ORDER_BY_CLAUSE);
2093 query.append(obc.getOrderBy());
2094
2095 sql = query.toString();
2096 }
2097
2098 sql = _SQL_GETUSERS;
2099
2100 SQLQuery q = session.createSQLQuery(sql);
2101
2102 q.addEntity("User_",
2103 com.liferay.portal.model.impl.UserImpl.class);
2104
2105 QueryPos qPos = QueryPos.getInstance(q);
2106
2107 qPos.add(pk);
2108
2109 list = (List<com.liferay.portal.model.User>)QueryUtil.list(q,
2110 getDialect(), start, end);
2111 }
2112 catch (Exception e) {
2113 throw processException(e);
2114 }
2115 finally {
2116 if (list == null) {
2117 list = new ArrayList<com.liferay.portal.model.User>();
2118 }
2119
2120 userPersistence.cacheResult(list);
2121
2122 FinderCacheUtil.putResult(FINDER_PATH_GET_USERS, finderArgs,
2123 list);
2124
2125 closeSession(session);
2126 }
2127 }
2128
2129 return list;
2130 }
2131
2132 public static final FinderPath FINDER_PATH_GET_USERS_SIZE = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
2133 OrganizationModelImpl.FINDER_CACHE_ENABLED_USERS_ORGS,
2134 OrganizationModelImpl.MAPPING_TABLE_USERS_ORGS_NAME,
2135 "getUsersSize", new String[] { Long.class.getName() });
2136
2137 public int getUsersSize(long pk) throws SystemException {
2138 Object[] finderArgs = new Object[] { new Long(pk) };
2139
2140 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_USERS_SIZE,
2141 finderArgs, this);
2142
2143 if (count == null) {
2144 Session session = null;
2145
2146 try {
2147 session = openSession();
2148
2149 SQLQuery q = session.createSQLQuery(_SQL_GETUSERSSIZE);
2150
2151 q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
2152
2153 QueryPos qPos = QueryPos.getInstance(q);
2154
2155 qPos.add(pk);
2156
2157 count = (Long)q.uniqueResult();
2158 }
2159 catch (Exception e) {
2160 throw processException(e);
2161 }
2162 finally {
2163 if (count == null) {
2164 count = Long.valueOf(0);
2165 }
2166
2167 FinderCacheUtil.putResult(FINDER_PATH_GET_USERS_SIZE,
2168 finderArgs, count);
2169
2170 closeSession(session);
2171 }
2172 }
2173
2174 return count.intValue();
2175 }
2176
2177 public static final FinderPath FINDER_PATH_CONTAINS_USER = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
2178 OrganizationModelImpl.FINDER_CACHE_ENABLED_USERS_ORGS,
2179 OrganizationModelImpl.MAPPING_TABLE_USERS_ORGS_NAME,
2180 "containsUser",
2181 new String[] { Long.class.getName(), Long.class.getName() });
2182
2183 public boolean containsUser(long pk, long userPK) throws SystemException {
2184 Object[] finderArgs = new Object[] { new Long(pk), new Long(userPK) };
2185
2186 Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_USER,
2187 finderArgs, this);
2188
2189 if (value == null) {
2190 try {
2191 value = Boolean.valueOf(containsUser.contains(pk, userPK));
2192 }
2193 catch (Exception e) {
2194 throw processException(e);
2195 }
2196 finally {
2197 if (value == null) {
2198 value = Boolean.FALSE;
2199 }
2200
2201 FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_USER,
2202 finderArgs, value);
2203 }
2204 }
2205
2206 return value.booleanValue();
2207 }
2208
2209 public boolean containsUsers(long pk) throws SystemException {
2210 if (getUsersSize(pk) > 0) {
2211 return true;
2212 }
2213 else {
2214 return false;
2215 }
2216 }
2217
2218 public void addUser(long pk, long userPK) throws SystemException {
2219 try {
2220 addUser.add(pk, userPK);
2221 }
2222 catch (Exception e) {
2223 throw processException(e);
2224 }
2225 finally {
2226 FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_USERS_ORGS_NAME);
2227 }
2228 }
2229
2230 public void addUser(long pk, com.liferay.portal.model.User user)
2231 throws SystemException {
2232 try {
2233 addUser.add(pk, user.getPrimaryKey());
2234 }
2235 catch (Exception e) {
2236 throw processException(e);
2237 }
2238 finally {
2239 FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_USERS_ORGS_NAME);
2240 }
2241 }
2242
2243 public void addUsers(long pk, long[] userPKs) throws SystemException {
2244 try {
2245 for (long userPK : userPKs) {
2246 addUser.add(pk, userPK);
2247 }
2248 }
2249 catch (Exception e) {
2250 throw processException(e);
2251 }
2252 finally {
2253 FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_USERS_ORGS_NAME);
2254 }
2255 }
2256
2257 public void addUsers(long pk, List<com.liferay.portal.model.User> users)
2258 throws SystemException {
2259 try {
2260 for (com.liferay.portal.model.User user : users) {
2261 addUser.add(pk, user.getPrimaryKey());
2262 }
2263 }
2264 catch (Exception e) {
2265 throw processException(e);
2266 }
2267 finally {
2268 FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_USERS_ORGS_NAME);
2269 }
2270 }
2271
2272 public void clearUsers(long pk) throws SystemException {
2273 try {
2274 clearUsers.clear(pk);
2275 }
2276 catch (Exception e) {
2277 throw processException(e);
2278 }
2279 finally {
2280 FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_USERS_ORGS_NAME);
2281 }
2282 }
2283
2284 public void removeUser(long pk, long userPK) throws SystemException {
2285 try {
2286 removeUser.remove(pk, userPK);
2287 }
2288 catch (Exception e) {
2289 throw processException(e);
2290 }
2291 finally {
2292 FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_USERS_ORGS_NAME);
2293 }
2294 }
2295
2296 public void removeUser(long pk, com.liferay.portal.model.User user)
2297 throws SystemException {
2298 try {
2299 removeUser.remove(pk, user.getPrimaryKey());
2300 }
2301 catch (Exception e) {
2302 throw processException(e);
2303 }
2304 finally {
2305 FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_USERS_ORGS_NAME);
2306 }
2307 }
2308
2309 public void removeUsers(long pk, long[] userPKs) throws SystemException {
2310 try {
2311 for (long userPK : userPKs) {
2312 removeUser.remove(pk, userPK);
2313 }
2314 }
2315 catch (Exception e) {
2316 throw processException(e);
2317 }
2318 finally {
2319 FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_USERS_ORGS_NAME);
2320 }
2321 }
2322
2323 public void removeUsers(long pk, List<com.liferay.portal.model.User> users)
2324 throws SystemException {
2325 try {
2326 for (com.liferay.portal.model.User user : users) {
2327 removeUser.remove(pk, user.getPrimaryKey());
2328 }
2329 }
2330 catch (Exception e) {
2331 throw processException(e);
2332 }
2333 finally {
2334 FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_USERS_ORGS_NAME);
2335 }
2336 }
2337
2338 public void setUsers(long pk, long[] userPKs) throws SystemException {
2339 try {
2340 Set<Long> userPKSet = SetUtil.fromArray(userPKs);
2341
2342 List<com.liferay.portal.model.User> users = getUsers(pk);
2343
2344 for (com.liferay.portal.model.User user : users) {
2345 if (!userPKSet.contains(user.getPrimaryKey())) {
2346 removeUser.remove(pk, user.getPrimaryKey());
2347 }
2348 else {
2349 userPKSet.remove(user.getPrimaryKey());
2350 }
2351 }
2352
2353 for (Long userPK : userPKSet) {
2354 addUser.add(pk, userPK);
2355 }
2356 }
2357 catch (Exception e) {
2358 throw processException(e);
2359 }
2360 finally {
2361 FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_USERS_ORGS_NAME);
2362 }
2363 }
2364
2365 public void setUsers(long pk, List<com.liferay.portal.model.User> users)
2366 throws SystemException {
2367 try {
2368 long[] userPKs = new long[users.size()];
2369
2370 for (int i = 0; i < users.size(); i++) {
2371 com.liferay.portal.model.User user = users.get(i);
2372
2373 userPKs[i] = user.getPrimaryKey();
2374 }
2375
2376 setUsers(pk, userPKs);
2377 }
2378 catch (Exception e) {
2379 throw processException(e);
2380 }
2381 finally {
2382 FinderCacheUtil.clearCache(OrganizationModelImpl.MAPPING_TABLE_USERS_ORGS_NAME);
2383 }
2384 }
2385
2386 public void rebuildTree(long companyId, boolean force)
2387 throws SystemException {
2388 if (force || (countOrphanTreeNodes(companyId) > 0)) {
2389 rebuildTree(companyId, 0, 1);
2390
2391 CacheRegistry.clear(OrganizationImpl.class.getName());
2392 EntityCacheUtil.clearCache(OrganizationImpl.class.getName());
2393 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
2394 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
2395 }
2396 }
2397
2398 protected long countOrphanTreeNodes(long companyId)
2399 throws SystemException {
2400 Session session = null;
2401
2402 try {
2403 session = openSession();
2404
2405 SQLQuery q = session.createSQLQuery(
2406 "SELECT COUNT(*) AS COUNT_VALUE FROM Organization_ WHERE companyId = ? AND (leftOrganizationId = 0 OR leftOrganizationId IS NULL OR rightOrganizationId = 0 OR rightOrganizationId IS NULL)");
2407
2408 q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
2409
2410 QueryPos qPos = QueryPos.getInstance(q);
2411
2412 qPos.add(companyId);
2413
2414 return (Long)q.uniqueResult();
2415 }
2416 catch (Exception e) {
2417 throw processException(e);
2418 }
2419 finally {
2420 closeSession(session);
2421 }
2422 }
2423
2424 protected void expandTree(Organization organization)
2425 throws SystemException {
2426 long companyId = organization.getCompanyId();
2427
2428 long lastRightOrganizationId = getLastRightOrganizationId(companyId,
2429 organization.getParentOrganizationId());
2430
2431 long leftOrganizationId = 2;
2432 long rightOrganizationId = 3;
2433
2434 if (lastRightOrganizationId > 0) {
2435 leftOrganizationId = lastRightOrganizationId + 1;
2436 rightOrganizationId = lastRightOrganizationId + 2;
2437
2438 expandTreeLeftOrganizationId.expand(companyId,
2439 lastRightOrganizationId);
2440 expandTreeRightOrganizationId.expand(companyId,
2441 lastRightOrganizationId);
2442
2443 CacheRegistry.clear(OrganizationImpl.class.getName());
2444 EntityCacheUtil.clearCache(OrganizationImpl.class.getName());
2445 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
2446 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
2447 }
2448
2449 organization.setLeftOrganizationId(leftOrganizationId);
2450 organization.setRightOrganizationId(rightOrganizationId);
2451 }
2452
2453 protected long getLastRightOrganizationId(long companyId,
2454 long parentOrganizationId) throws SystemException {
2455 Session session = null;
2456
2457 try {
2458 session = openSession();
2459
2460 SQLQuery q = session.createSQLQuery(
2461 "SELECT rightOrganizationId FROM Organization_ WHERE (companyId = ?) AND (parentOrganizationId = ?) ORDER BY rightOrganizationId DESC");
2462
2463 q.addScalar("rightOrganizationId", Type.LONG);
2464
2465 QueryPos qPos = QueryPos.getInstance(q);
2466
2467 qPos.add(companyId);
2468 qPos.add(parentOrganizationId);
2469
2470 List<Long> list = (List<Long>)QueryUtil.list(q, getDialect(), 0, 1);
2471
2472 if (list.isEmpty()) {
2473 if (parentOrganizationId > 0) {
2474 Organization parentOrganization = findByPrimaryKey(parentOrganizationId);
2475
2476 return parentOrganization.getLeftOrganizationId();
2477 }
2478
2479 return 0;
2480 }
2481 else {
2482 return list.get(0);
2483 }
2484 }
2485 catch (Exception e) {
2486 throw processException(e);
2487 }
2488 finally {
2489 closeSession(session);
2490 }
2491 }
2492
2493 protected long rebuildTree(long companyId, long parentOrganizationId,
2494 long leftOrganizationId) throws SystemException {
2495 List<Long> organizationIds = null;
2496
2497 Session session = null;
2498
2499 try {
2500 session = openSession();
2501
2502 SQLQuery q = session.createSQLQuery(
2503 "SELECT organizationId FROM Organization_ WHERE companyId = ? AND parentOrganizationId = ? ORDER BY organizationId ASC");
2504
2505 q.addScalar("organizationId", Type.LONG);
2506
2507 QueryPos qPos = QueryPos.getInstance(q);
2508
2509 qPos.add(companyId);
2510 qPos.add(parentOrganizationId);
2511
2512 organizationIds = q.list();
2513 }
2514 catch (Exception e) {
2515 throw processException(e);
2516 }
2517 finally {
2518 closeSession(session);
2519 }
2520
2521 long rightOrganizationId = leftOrganizationId + 1;
2522
2523 for (long organizationId : organizationIds) {
2524 rightOrganizationId = rebuildTree(companyId, organizationId,
2525 rightOrganizationId);
2526 }
2527
2528 if (parentOrganizationId > 0) {
2529 updateTree.update(parentOrganizationId, leftOrganizationId,
2530 rightOrganizationId);
2531 }
2532
2533 return rightOrganizationId + 1;
2534 }
2535
2536 protected void shrinkTree(Organization organization) {
2537 long companyId = organization.getCompanyId();
2538
2539 long leftOrganizationId = organization.getLeftOrganizationId();
2540 long rightOrganizationId = organization.getRightOrganizationId();
2541
2542 long delta = (rightOrganizationId - leftOrganizationId) + 1;
2543
2544 shrinkTreeLeftOrganizationId.shrink(companyId, rightOrganizationId,
2545 delta);
2546 shrinkTreeRightOrganizationId.shrink(companyId, rightOrganizationId,
2547 delta);
2548
2549 CacheRegistry.clear(OrganizationImpl.class.getName());
2550 EntityCacheUtil.clearCache(OrganizationImpl.class.getName());
2551 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
2552 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
2553 }
2554
2555 public void afterPropertiesSet() {
2556 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2557 com.liferay.portal.util.PropsUtil.get(
2558 "value.object.listener.com.liferay.portal.model.Organization")));
2559
2560 if (listenerClassNames.length > 0) {
2561 try {
2562 List<ModelListener<Organization>> listenersList = new ArrayList<ModelListener<Organization>>();
2563
2564 for (String listenerClassName : listenerClassNames) {
2565 listenersList.add((ModelListener<Organization>)Class.forName(
2566 listenerClassName).newInstance());
2567 }
2568
2569 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2570 }
2571 catch (Exception e) {
2572 _log.error(e);
2573 }
2574 }
2575
2576 containsGroup = new ContainsGroup(this);
2577
2578 addGroup = new AddGroup(this);
2579 clearGroups = new ClearGroups(this);
2580 removeGroup = new RemoveGroup(this);
2581
2582 containsUser = new ContainsUser(this);
2583
2584 addUser = new AddUser(this);
2585 clearUsers = new ClearUsers(this);
2586 removeUser = new RemoveUser(this);
2587
2588 expandTreeLeftOrganizationId = new ExpandTreeLeftOrganizationId();
2589 expandTreeRightOrganizationId = new ExpandTreeRightOrganizationId();
2590 shrinkTreeLeftOrganizationId = new ShrinkTreeLeftOrganizationId();
2591 shrinkTreeRightOrganizationId = new ShrinkTreeRightOrganizationId();
2592 updateTree = new UpdateTree();
2593 }
2594
2595 @BeanReference(name = "com.liferay.portal.service.persistence.AccountPersistence")
2596 protected com.liferay.portal.service.persistence.AccountPersistence accountPersistence;
2597 @BeanReference(name = "com.liferay.portal.service.persistence.AddressPersistence")
2598 protected com.liferay.portal.service.persistence.AddressPersistence addressPersistence;
2599 @BeanReference(name = "com.liferay.portal.service.persistence.BrowserTrackerPersistence")
2600 protected com.liferay.portal.service.persistence.BrowserTrackerPersistence browserTrackerPersistence;
2601 @BeanReference(name = "com.liferay.portal.service.persistence.ClassNamePersistence")
2602 protected com.liferay.portal.service.persistence.ClassNamePersistence classNamePersistence;
2603 @BeanReference(name = "com.liferay.portal.service.persistence.CompanyPersistence")
2604 protected com.liferay.portal.service.persistence.CompanyPersistence companyPersistence;
2605 @BeanReference(name = "com.liferay.portal.service.persistence.ContactPersistence")
2606 protected com.liferay.portal.service.persistence.ContactPersistence contactPersistence;
2607 @BeanReference(name = "com.liferay.portal.service.persistence.CountryPersistence")
2608 protected com.liferay.portal.service.persistence.CountryPersistence countryPersistence;
2609 @BeanReference(name = "com.liferay.portal.service.persistence.EmailAddressPersistence")
2610 protected com.liferay.portal.service.persistence.EmailAddressPersistence emailAddressPersistence;
2611 @BeanReference(name = "com.liferay.portal.service.persistence.GroupPersistence")
2612 protected com.liferay.portal.service.persistence.GroupPersistence groupPersistence;
2613 @BeanReference(name = "com.liferay.portal.service.persistence.ImagePersistence")
2614 protected com.liferay.portal.service.persistence.ImagePersistence imagePersistence;
2615 @BeanReference(name = "com.liferay.portal.service.persistence.LayoutPersistence")
2616 protected com.liferay.portal.service.persistence.LayoutPersistence layoutPersistence;
2617 @BeanReference(name = "com.liferay.portal.service.persistence.LayoutSetPersistence")
2618 protected com.liferay.portal.service.persistence.LayoutSetPersistence layoutSetPersistence;
2619 @BeanReference(name = "com.liferay.portal.service.persistence.ListTypePersistence")
2620 protected com.liferay.portal.service.persistence.ListTypePersistence listTypePersistence;
2621 @BeanReference(name = "com.liferay.portal.service.persistence.LockPersistence")
2622 protected com.liferay.portal.service.persistence.LockPersistence lockPersistence;
2623 @BeanReference(name = "com.liferay.portal.service.persistence.MembershipRequestPersistence")
2624 protected com.liferay.portal.service.persistence.MembershipRequestPersistence membershipRequestPersistence;
2625 @BeanReference(name = "com.liferay.portal.service.persistence.OrganizationPersistence")
2626 protected com.liferay.portal.service.persistence.OrganizationPersistence organizationPersistence;
2627 @BeanReference(name = "com.liferay.portal.service.persistence.OrgGroupPermissionPersistence")
2628 protected com.liferay.portal.service.persistence.OrgGroupPermissionPersistence orgGroupPermissionPersistence;
2629 @BeanReference(name = "com.liferay.portal.service.persistence.OrgGroupRolePersistence")
2630 protected com.liferay.portal.service.persistence.OrgGroupRolePersistence orgGroupRolePersistence;
2631 @BeanReference(name = "com.liferay.portal.service.persistence.OrgLaborPersistence")
2632 protected com.liferay.portal.service.persistence.OrgLaborPersistence orgLaborPersistence;
2633 @BeanReference(name = "com.liferay.portal.service.persistence.PasswordPolicyPersistence")
2634 protected com.liferay.portal.service.persistence.PasswordPolicyPersistence passwordPolicyPersistence;
2635 @BeanReference(name = "com.liferay.portal.service.persistence.PasswordPolicyRelPersistence")
2636 protected com.liferay.portal.service.persistence.PasswordPolicyRelPersistence passwordPolicyRelPersistence;
2637 @BeanReference(name = "com.liferay.portal.service.persistence.PasswordTrackerPersistence")
2638 protected com.liferay.portal.service.persistence.PasswordTrackerPersistence passwordTrackerPersistence;
2639 @BeanReference(name = "com.liferay.portal.service.persistence.PermissionPersistence")
2640 protected com.liferay.portal.service.persistence.PermissionPersistence permissionPersistence;
2641 @BeanReference(name = "com.liferay.portal.service.persistence.PhonePersistence")
2642 protected com.liferay.portal.service.persistence.PhonePersistence phonePersistence;
2643 @BeanReference(name = "com.liferay.portal.service.persistence.PluginSettingPersistence")
2644 protected com.liferay.portal.service.persistence.PluginSettingPersistence pluginSettingPersistence;
2645 @BeanReference(name = "com.liferay.portal.service.persistence.PortletPersistence")
2646 protected com.liferay.portal.service.persistence.PortletPersistence portletPersistence;
2647 @BeanReference(name = "com.liferay.portal.service.persistence.PortletItemPersistence")
2648 protected com.liferay.portal.service.persistence.PortletItemPersistence portletItemPersistence;
2649 @BeanReference(name = "com.liferay.portal.service.persistence.PortletPreferencesPersistence")
2650 protected com.liferay.portal.service.persistence.PortletPreferencesPersistence portletPreferencesPersistence;
2651 @BeanReference(name = "com.liferay.portal.service.persistence.RegionPersistence")
2652 protected com.liferay.portal.service.persistence.RegionPersistence regionPersistence;
2653 @BeanReference(name = "com.liferay.portal.service.persistence.ReleasePersistence")
2654 protected com.liferay.portal.service.persistence.ReleasePersistence releasePersistence;
2655 @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePersistence")
2656 protected com.liferay.portal.service.persistence.ResourcePersistence resourcePersistence;
2657 @BeanReference(name = "com.liferay.portal.service.persistence.ResourceActionPersistence")
2658 protected com.liferay.portal.service.persistence.ResourceActionPersistence resourceActionPersistence;
2659 @BeanReference(name = "com.liferay.portal.service.persistence.ResourceCodePersistence")
2660 protected com.liferay.portal.service.persistence.ResourceCodePersistence resourceCodePersistence;
2661 @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePermissionPersistence")
2662 protected com.liferay.portal.service.persistence.ResourcePermissionPersistence resourcePermissionPersistence;
2663 @BeanReference(name = "com.liferay.portal.service.persistence.RolePersistence")
2664 protected com.liferay.portal.service.persistence.RolePersistence rolePersistence;
2665 @BeanReference(name = "com.liferay.portal.service.persistence.ServiceComponentPersistence")
2666 protected com.liferay.portal.service.persistence.ServiceComponentPersistence serviceComponentPersistence;
2667 @BeanReference(name = "com.liferay.portal.service.persistence.ShardPersistence")
2668 protected com.liferay.portal.service.persistence.ShardPersistence shardPersistence;
2669 @BeanReference(name = "com.liferay.portal.service.persistence.SubscriptionPersistence")
2670 protected com.liferay.portal.service.persistence.SubscriptionPersistence subscriptionPersistence;
2671 @BeanReference(name = "com.liferay.portal.service.persistence.UserPersistence")
2672 protected com.liferay.portal.service.persistence.UserPersistence userPersistence;
2673 @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupPersistence")
2674 protected com.liferay.portal.service.persistence.UserGroupPersistence userGroupPersistence;
2675 @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupGroupRolePersistence")
2676 protected com.liferay.portal.service.persistence.UserGroupGroupRolePersistence userGroupGroupRolePersistence;
2677 @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupRolePersistence")
2678 protected com.liferay.portal.service.persistence.UserGroupRolePersistence userGroupRolePersistence;
2679 @BeanReference(name = "com.liferay.portal.service.persistence.UserIdMapperPersistence")
2680 protected com.liferay.portal.service.persistence.UserIdMapperPersistence userIdMapperPersistence;
2681 @BeanReference(name = "com.liferay.portal.service.persistence.UserTrackerPersistence")
2682 protected com.liferay.portal.service.persistence.UserTrackerPersistence userTrackerPersistence;
2683 @BeanReference(name = "com.liferay.portal.service.persistence.UserTrackerPathPersistence")
2684 protected com.liferay.portal.service.persistence.UserTrackerPathPersistence userTrackerPathPersistence;
2685 @BeanReference(name = "com.liferay.portal.service.persistence.WebDAVPropsPersistence")
2686 protected com.liferay.portal.service.persistence.WebDAVPropsPersistence webDAVPropsPersistence;
2687 @BeanReference(name = "com.liferay.portal.service.persistence.WebsitePersistence")
2688 protected com.liferay.portal.service.persistence.WebsitePersistence websitePersistence;
2689 @BeanReference(name = "com.liferay.portlet.tags.service.persistence.TagsAssetPersistence")
2690 protected com.liferay.portlet.tags.service.persistence.TagsAssetPersistence tagsAssetPersistence;
2691 protected ContainsGroup containsGroup;
2692 protected AddGroup addGroup;
2693 protected ClearGroups clearGroups;
2694 protected RemoveGroup removeGroup;
2695 protected ContainsUser containsUser;
2696 protected AddUser addUser;
2697 protected ClearUsers clearUsers;
2698 protected RemoveUser removeUser;
2699
2700 protected class ContainsGroup {
2701 protected ContainsGroup(OrganizationPersistenceImpl persistenceImpl) {
2702 super();
2703
2704 _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
2705 _SQL_CONTAINSGROUP,
2706 new int[] { Types.BIGINT, Types.BIGINT }, RowMapper.COUNT);
2707 }
2708
2709 protected boolean contains(long organizationId, long groupId) {
2710 List<Integer> results = _mappingSqlQuery.execute(new Object[] {
2711 new Long(organizationId), new Long(groupId)
2712 });
2713
2714 if (results.size() > 0) {
2715 Integer count = results.get(0);
2716
2717 if (count.intValue() > 0) {
2718 return true;
2719 }
2720 }
2721
2722 return false;
2723 }
2724
2725 private MappingSqlQuery _mappingSqlQuery;
2726 }
2727
2728 protected class AddGroup {
2729 protected AddGroup(OrganizationPersistenceImpl persistenceImpl) {
2730 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2731 "INSERT INTO Groups_Orgs (organizationId, groupId) VALUES (?, ?)",
2732 new int[] { Types.BIGINT, Types.BIGINT });
2733 _persistenceImpl = persistenceImpl;
2734 }
2735
2736 protected void add(long organizationId, long groupId)
2737 throws SystemException {
2738 if (!_persistenceImpl.containsGroup.contains(organizationId, groupId)) {
2739 ModelListener<com.liferay.portal.model.Group>[] groupListeners = groupPersistence.getListeners();
2740
2741 for (ModelListener<Organization> listener : listeners) {
2742 listener.onBeforeAddAssociation(organizationId,
2743 com.liferay.portal.model.Group.class.getName(), groupId);
2744 }
2745
2746 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
2747 listener.onBeforeAddAssociation(groupId,
2748 Organization.class.getName(), organizationId);
2749 }
2750
2751 _sqlUpdate.update(new Object[] {
2752 new Long(organizationId), new Long(groupId)
2753 });
2754
2755 for (ModelListener<Organization> listener : listeners) {
2756 listener.onAfterAddAssociation(organizationId,
2757 com.liferay.portal.model.Group.class.getName(), groupId);
2758 }
2759
2760 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
2761 listener.onAfterAddAssociation(groupId,
2762 Organization.class.getName(), organizationId);
2763 }
2764 }
2765 }
2766
2767 private SqlUpdate _sqlUpdate;
2768 private OrganizationPersistenceImpl _persistenceImpl;
2769 }
2770
2771 protected class ClearGroups {
2772 protected ClearGroups(OrganizationPersistenceImpl persistenceImpl) {
2773 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2774 "DELETE FROM Groups_Orgs WHERE organizationId = ?",
2775 new int[] { Types.BIGINT });
2776 }
2777
2778 protected void clear(long organizationId) throws SystemException {
2779 ModelListener<com.liferay.portal.model.Group>[] groupListeners = groupPersistence.getListeners();
2780
2781 List<com.liferay.portal.model.Group> groups = null;
2782
2783 if ((listeners.length > 0) || (groupListeners.length > 0)) {
2784 groups = getGroups(organizationId);
2785
2786 for (com.liferay.portal.model.Group group : groups) {
2787 for (ModelListener<Organization> listener : listeners) {
2788 listener.onBeforeRemoveAssociation(organizationId,
2789 com.liferay.portal.model.Group.class.getName(),
2790 group.getPrimaryKey());
2791 }
2792
2793 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
2794 listener.onBeforeRemoveAssociation(group.getPrimaryKey(),
2795 Organization.class.getName(), organizationId);
2796 }
2797 }
2798 }
2799
2800 _sqlUpdate.update(new Object[] { new Long(organizationId) });
2801
2802 if ((listeners.length > 0) || (groupListeners.length > 0)) {
2803 for (com.liferay.portal.model.Group group : groups) {
2804 for (ModelListener<Organization> listener : listeners) {
2805 listener.onAfterRemoveAssociation(organizationId,
2806 com.liferay.portal.model.Group.class.getName(),
2807 group.getPrimaryKey());
2808 }
2809
2810 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
2811 listener.onAfterRemoveAssociation(group.getPrimaryKey(),
2812 Organization.class.getName(), organizationId);
2813 }
2814 }
2815 }
2816 }
2817
2818 private SqlUpdate _sqlUpdate;
2819 }
2820
2821 protected class RemoveGroup {
2822 protected RemoveGroup(OrganizationPersistenceImpl persistenceImpl) {
2823 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2824 "DELETE FROM Groups_Orgs WHERE organizationId = ? AND groupId = ?",
2825 new int[] { Types.BIGINT, Types.BIGINT });
2826 _persistenceImpl = persistenceImpl;
2827 }
2828
2829 protected void remove(long organizationId, long groupId)
2830 throws SystemException {
2831 if (_persistenceImpl.containsGroup.contains(organizationId, groupId)) {
2832 ModelListener<com.liferay.portal.model.Group>[] groupListeners = groupPersistence.getListeners();
2833
2834 for (ModelListener<Organization> listener : listeners) {
2835 listener.onBeforeRemoveAssociation(organizationId,
2836 com.liferay.portal.model.Group.class.getName(), groupId);
2837 }
2838
2839 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
2840 listener.onBeforeRemoveAssociation(groupId,
2841 Organization.class.getName(), organizationId);
2842 }
2843
2844 _sqlUpdate.update(new Object[] {
2845 new Long(organizationId), new Long(groupId)
2846 });
2847
2848 for (ModelListener<Organization> listener : listeners) {
2849 listener.onAfterRemoveAssociation(organizationId,
2850 com.liferay.portal.model.Group.class.getName(), groupId);
2851 }
2852
2853 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
2854 listener.onAfterRemoveAssociation(groupId,
2855 Organization.class.getName(), organizationId);
2856 }
2857 }
2858 }
2859
2860 private SqlUpdate _sqlUpdate;
2861 private OrganizationPersistenceImpl _persistenceImpl;
2862 }
2863
2864 protected class ContainsUser {
2865 protected ContainsUser(OrganizationPersistenceImpl persistenceImpl) {
2866 super();
2867
2868 _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
2869 _SQL_CONTAINSUSER,
2870 new int[] { Types.BIGINT, Types.BIGINT }, RowMapper.COUNT);
2871 }
2872
2873 protected boolean contains(long organizationId, long userId) {
2874 List<Integer> results = _mappingSqlQuery.execute(new Object[] {
2875 new Long(organizationId), new Long(userId)
2876 });
2877
2878 if (results.size() > 0) {
2879 Integer count = results.get(0);
2880
2881 if (count.intValue() > 0) {
2882 return true;
2883 }
2884 }
2885
2886 return false;
2887 }
2888
2889 private MappingSqlQuery _mappingSqlQuery;
2890 }
2891
2892 protected class AddUser {
2893 protected AddUser(OrganizationPersistenceImpl persistenceImpl) {
2894 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2895 "INSERT INTO Users_Orgs (organizationId, userId) VALUES (?, ?)",
2896 new int[] { Types.BIGINT, Types.BIGINT });
2897 _persistenceImpl = persistenceImpl;
2898 }
2899
2900 protected void add(long organizationId, long userId)
2901 throws SystemException {
2902 if (!_persistenceImpl.containsUser.contains(organizationId, userId)) {
2903 ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
2904
2905 for (ModelListener<Organization> listener : listeners) {
2906 listener.onBeforeAddAssociation(organizationId,
2907 com.liferay.portal.model.User.class.getName(), userId);
2908 }
2909
2910 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
2911 listener.onBeforeAddAssociation(userId,
2912 Organization.class.getName(), organizationId);
2913 }
2914
2915 _sqlUpdate.update(new Object[] {
2916 new Long(organizationId), new Long(userId)
2917 });
2918
2919 for (ModelListener<Organization> listener : listeners) {
2920 listener.onAfterAddAssociation(organizationId,
2921 com.liferay.portal.model.User.class.getName(), userId);
2922 }
2923
2924 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
2925 listener.onAfterAddAssociation(userId,
2926 Organization.class.getName(), organizationId);
2927 }
2928 }
2929 }
2930
2931 private SqlUpdate _sqlUpdate;
2932 private OrganizationPersistenceImpl _persistenceImpl;
2933 }
2934
2935 protected class ClearUsers {
2936 protected ClearUsers(OrganizationPersistenceImpl persistenceImpl) {
2937 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2938 "DELETE FROM Users_Orgs WHERE organizationId = ?",
2939 new int[] { Types.BIGINT });
2940 }
2941
2942 protected void clear(long organizationId) throws SystemException {
2943 ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
2944
2945 List<com.liferay.portal.model.User> users = null;
2946
2947 if ((listeners.length > 0) || (userListeners.length > 0)) {
2948 users = getUsers(organizationId);
2949
2950 for (com.liferay.portal.model.User user : users) {
2951 for (ModelListener<Organization> listener : listeners) {
2952 listener.onBeforeRemoveAssociation(organizationId,
2953 com.liferay.portal.model.User.class.getName(),
2954 user.getPrimaryKey());
2955 }
2956
2957 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
2958 listener.onBeforeRemoveAssociation(user.getPrimaryKey(),
2959 Organization.class.getName(), organizationId);
2960 }
2961 }
2962 }
2963
2964 _sqlUpdate.update(new Object[] { new Long(organizationId) });
2965
2966 if ((listeners.length > 0) || (userListeners.length > 0)) {
2967 for (com.liferay.portal.model.User user : users) {
2968 for (ModelListener<Organization> listener : listeners) {
2969 listener.onAfterRemoveAssociation(organizationId,
2970 com.liferay.portal.model.User.class.getName(),
2971 user.getPrimaryKey());
2972 }
2973
2974 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
2975 listener.onAfterRemoveAssociation(user.getPrimaryKey(),
2976 Organization.class.getName(), organizationId);
2977 }
2978 }
2979 }
2980 }
2981
2982 private SqlUpdate _sqlUpdate;
2983 }
2984
2985 protected class RemoveUser {
2986 protected RemoveUser(OrganizationPersistenceImpl persistenceImpl) {
2987 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2988 "DELETE FROM Users_Orgs WHERE organizationId = ? AND userId = ?",
2989 new int[] { Types.BIGINT, Types.BIGINT });
2990 _persistenceImpl = persistenceImpl;
2991 }
2992
2993 protected void remove(long organizationId, long userId)
2994 throws SystemException {
2995 if (_persistenceImpl.containsUser.contains(organizationId, userId)) {
2996 ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
2997
2998 for (ModelListener<Organization> listener : listeners) {
2999 listener.onBeforeRemoveAssociation(organizationId,
3000 com.liferay.portal.model.User.class.getName(), userId);
3001 }
3002
3003 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
3004 listener.onBeforeRemoveAssociation(userId,
3005 Organization.class.getName(), organizationId);
3006 }
3007
3008 _sqlUpdate.update(new Object[] {
3009 new Long(organizationId), new Long(userId)
3010 });
3011
3012 for (ModelListener<Organization> listener : listeners) {
3013 listener.onAfterRemoveAssociation(organizationId,
3014 com.liferay.portal.model.User.class.getName(), userId);
3015 }
3016
3017 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
3018 listener.onAfterRemoveAssociation(userId,
3019 Organization.class.getName(), organizationId);
3020 }
3021 }
3022 }
3023
3024 private SqlUpdate _sqlUpdate;
3025 private OrganizationPersistenceImpl _persistenceImpl;
3026 }
3027
3028 protected ExpandTreeLeftOrganizationId expandTreeLeftOrganizationId;
3029 protected ExpandTreeRightOrganizationId expandTreeRightOrganizationId;
3030 protected ShrinkTreeLeftOrganizationId shrinkTreeLeftOrganizationId;
3031 protected ShrinkTreeRightOrganizationId shrinkTreeRightOrganizationId;
3032 protected UpdateTree updateTree;
3033
3034 protected class ExpandTreeLeftOrganizationId {
3035 protected ExpandTreeLeftOrganizationId() {
3036 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
3037 "UPDATE Organization_ SET leftOrganizationId = (leftOrganizationId + 2) WHERE (companyId = ?) AND (leftOrganizationId > ?)",
3038 new int[] { Types.BIGINT, Types.BIGINT });
3039 }
3040
3041 protected void expand(long companyId, long leftOrganizationId) {
3042 _sqlUpdate.update(new Object[] { companyId, leftOrganizationId });
3043 }
3044
3045 private SqlUpdate _sqlUpdate;
3046 }
3047
3048 protected class ExpandTreeRightOrganizationId {
3049 protected ExpandTreeRightOrganizationId() {
3050 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
3051 "UPDATE Organization_ SET rightOrganizationId = (rightOrganizationId + 2) WHERE (companyId = ?) AND (rightOrganizationId > ?)",
3052 new int[] { Types.BIGINT, Types.BIGINT });
3053 }
3054
3055 protected void expand(long companyId, long rightOrganizationId) {
3056 _sqlUpdate.update(new Object[] { companyId, rightOrganizationId });
3057 }
3058
3059 private SqlUpdate _sqlUpdate;
3060 }
3061
3062 protected class ShrinkTreeLeftOrganizationId {
3063 protected ShrinkTreeLeftOrganizationId() {
3064 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
3065 "UPDATE Organization_ SET leftOrganizationId = (leftOrganizationId - ?) WHERE (companyId = ?) AND (leftOrganizationId > ?)",
3066 new int[] { Types.BIGINT, Types.BIGINT, Types.BIGINT });
3067 }
3068
3069 protected void shrink(long companyId, long leftOrganizationId,
3070 long delta) {
3071 _sqlUpdate.update(new Object[] { delta, companyId, leftOrganizationId });
3072 }
3073
3074 private SqlUpdate _sqlUpdate;
3075 }
3076
3077 protected class ShrinkTreeRightOrganizationId {
3078 protected ShrinkTreeRightOrganizationId() {
3079 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
3080 "UPDATE Organization_ SET rightOrganizationId = (rightOrganizationId - ?) WHERE (companyId = ?) AND (rightOrganizationId > ?)",
3081 new int[] { Types.BIGINT, Types.BIGINT, Types.BIGINT });
3082 }
3083
3084 protected void shrink(long companyId, long rightOrganizationId,
3085 long delta) {
3086 _sqlUpdate.update(new Object[] { delta, companyId, rightOrganizationId });
3087 }
3088
3089 private SqlUpdate _sqlUpdate;
3090 }
3091
3092 protected class UpdateTree {
3093 protected UpdateTree() {
3094 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
3095 "UPDATE Organization_ SET leftOrganizationId = ?, rightOrganizationId = ? WHERE organizationId = ?",
3096 new int[] { Types.BIGINT, Types.BIGINT, Types.BIGINT });
3097 }
3098
3099 protected void update(long organizationId, long leftOrganizationId,
3100 long rightOrganizationId) {
3101 _sqlUpdate.update(new Object[] {
3102 leftOrganizationId, rightOrganizationId, organizationId
3103 });
3104 }
3105
3106 private SqlUpdate _sqlUpdate;
3107 }
3108
3109 private static final String _SQL_SELECT_ORGANIZATION = "SELECT organization FROM Organization organization";
3110 private static final String _SQL_SELECT_ORGANIZATION_WHERE = "SELECT organization FROM Organization organization WHERE ";
3111 private static final String _SQL_COUNT_ORGANIZATION = "SELECT COUNT(organization) FROM Organization organization";
3112 private static final String _SQL_COUNT_ORGANIZATION_WHERE = "SELECT COUNT(organization) FROM Organization organization WHERE ";
3113 private static final String _SQL_GETGROUPS = "SELECT {Group_.*} FROM Group_ INNER JOIN Groups_Orgs ON (Groups_Orgs.groupId = Group_.groupId) WHERE (Groups_Orgs.organizationId = ?)";
3114 private static final String _SQL_GETGROUPSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_Orgs WHERE organizationId = ?";
3115 private static final String _SQL_CONTAINSGROUP = "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_Orgs WHERE organizationId = ? AND groupId = ?";
3116 private static final String _SQL_GETUSERS = "SELECT {User_.*} FROM User_ INNER JOIN Users_Orgs ON (Users_Orgs.userId = User_.userId) WHERE (Users_Orgs.organizationId = ?)";
3117 private static final String _SQL_GETUSERSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Orgs WHERE organizationId = ?";
3118 private static final String _SQL_CONTAINSUSER = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Orgs WHERE organizationId = ? AND userId = ?";
3119 private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "organization.companyId = ?";
3120 private static final String _FINDER_COLUMN_LOCATIONS_COMPANYID_2 = "organization.companyId = ? AND organization.parentOrganizationId != 0";
3121 private static final String _FINDER_COLUMN_C_P_COMPANYID_2 = "organization.companyId = ? AND ";
3122 private static final String _FINDER_COLUMN_C_P_PARENTORGANIZATIONID_2 = "organization.parentOrganizationId = ?";
3123 private static final String _FINDER_COLUMN_C_N_COMPANYID_2 = "organization.companyId = ? AND ";
3124 private static final String _FINDER_COLUMN_C_N_NAME_1 = "organization.name IS NULL";
3125 private static final String _FINDER_COLUMN_C_N_NAME_2 = "organization.name = ?";
3126 private static final String _FINDER_COLUMN_C_N_NAME_3 = "(organization.name IS NULL OR organization.name = ?)";
3127 private static final String _ORDER_BY_ENTITY_ALIAS = "organization.";
3128 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Organization exists with the primary key ";
3129 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Organization exists with the key {";
3130 private static Log _log = LogFactoryUtil.getLog(OrganizationPersistenceImpl.class);
3131}