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