001
014
015 package com.liferay.portal.service.persistence;
016
017 import com.liferay.portal.NoSuchGroupException;
018 import com.liferay.portal.kernel.dao.orm.QueryPos;
019 import com.liferay.portal.kernel.dao.orm.QueryUtil;
020 import com.liferay.portal.kernel.dao.orm.SQLQuery;
021 import com.liferay.portal.kernel.dao.orm.Session;
022 import com.liferay.portal.kernel.dao.orm.Type;
023 import com.liferay.portal.kernel.exception.SystemException;
024 import com.liferay.portal.kernel.util.GetterUtil;
025 import com.liferay.portal.kernel.util.OrderByComparator;
026 import com.liferay.portal.kernel.util.StringBundler;
027 import com.liferay.portal.kernel.util.StringPool;
028 import com.liferay.portal.kernel.util.StringUtil;
029 import com.liferay.portal.kernel.util.Validator;
030 import com.liferay.portal.model.Group;
031 import com.liferay.portal.model.GroupConstants;
032 import com.liferay.portal.model.Organization;
033 import com.liferay.portal.model.impl.GroupImpl;
034 import com.liferay.portal.service.ClassNameLocalServiceUtil;
035 import com.liferay.portal.service.ResourceBlockLocalServiceUtil;
036 import com.liferay.portal.service.impl.GroupLocalServiceImpl;
037 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
038 import com.liferay.portal.util.comparator.GroupNameComparator;
039 import com.liferay.util.dao.orm.CustomSQLUtil;
040
041 import java.util.ArrayList;
042 import java.util.HashMap;
043 import java.util.HashSet;
044 import java.util.Iterator;
045 import java.util.LinkedHashMap;
046 import java.util.List;
047 import java.util.Map;
048 import java.util.Set;
049 import java.util.concurrent.ConcurrentHashMap;
050
051
055 public class GroupFinderImpl
056 extends BasePersistenceImpl<Group> implements GroupFinder {
057
058 public static final String COUNT_BY_LAYOUTS =
059 GroupFinder.class.getName() + ".countByLayouts";
060
061 public static final String COUNT_BY_GROUP_ID =
062 GroupFinder.class.getName() + ".countByGroupId";
063
064 public static final String COUNT_BY_C_C_PG_N_D =
065 GroupFinder.class.getName() + ".countByC_C_PG_N_D";
066
067 public static final String FIND_BY_LAYOUTS =
068 GroupFinder.class.getName() + ".findByLayouts";
069
070 public static final String FIND_BY_LIVE_GROUPS =
071 GroupFinder.class.getName() + ".findByLiveGroups";
072
073 public static final String FIND_BY_NO_LAYOUTS =
074 GroupFinder.class.getName() + ".findByNoLayouts";
075
076 public static final String FIND_BY_NULL_FRIENDLY_URL =
077 GroupFinder.class.getName() + ".findByNullFriendlyURL";
078
079 public static final String FIND_BY_SYSTEM =
080 GroupFinder.class.getName() + ".findBySystem";
081
082 public static final String FIND_BY_C_C =
083 GroupFinder.class.getName() + ".findByC_C";
084
085 public static final String FIND_BY_C_N =
086 GroupFinder.class.getName() + ".findByC_N";
087
088 public static final String FIND_BY_C_C_PG_N_D =
089 GroupFinder.class.getName() + ".findByC_C_PG_N_D";
090
091 public static final String JOIN_BY_ACTIVE =
092 GroupFinder.class.getName() + ".joinByActive";
093
094 public static final String JOIN_BY_CREATOR_USER_ID =
095 GroupFinder.class.getName() + ".joinByCreatorUserId";
096
097 public static final String JOIN_BY_GROUP_ORG =
098 GroupFinder.class.getName() + ".joinByGroupOrg";
099
100 public static final String JOIN_BY_GROUPS_ORGS =
101 GroupFinder.class.getName() + ".joinByGroupsOrgs";
102
103 public static final String JOIN_BY_GROUPS_ROLES =
104 GroupFinder.class.getName() + ".joinByGroupsRoles";
105
106 public static final String JOIN_BY_GROUPS_USER_GROUPS =
107 GroupFinder.class.getName() + ".joinByGroupsUserGroups";
108
109 public static final String JOIN_BY_LAYOUT_SET =
110 GroupFinder.class.getName() + ".joinByLayoutSet";
111
112 public static final String JOIN_BY_PAGE_COUNT =
113 GroupFinder.class.getName() + ".joinByPageCount";
114
115 public static final String JOIN_BY_ROLE_PERMISSIONS =
116 GroupFinder.class.getName() + ".joinByRolePermissions";
117
118 public static final String JOIN_BY_ROLE_RESOURCE_PERMISSIONS =
119 GroupFinder.class.getName() + ".joinByRoleResourcePermissions";
120
121 public static final String JOIN_BY_ROLE_RESOURCE_TYPE_PERMISSIONS =
122 GroupFinder.class.getName() + ".joinByRoleResourceTypePermissions";
123
124 public static final String JOIN_BY_SITE =
125 GroupFinder.class.getName() + ".joinBySite";
126
127 public static final String JOIN_BY_TYPE =
128 GroupFinder.class.getName() + ".joinByType";
129
130 public static final String JOIN_BY_USER_GROUP_ROLE =
131 GroupFinder.class.getName() + ".joinByUserGroupRole";
132
133 public static final String JOIN_BY_USERS_GROUPS =
134 GroupFinder.class.getName() + ".joinByUsersGroups";
135
136 public int countByKeywords(
137 long companyId, long parentGroupId, String parentGroupIdComparator,
138 String keywords, LinkedHashMap<String, Object> params)
139 throws SystemException {
140
141 String[] names = null;
142 String[] realNames = null;
143 String[] descriptions = null;
144 boolean andOperator = false;
145
146 if (Validator.isNotNull(keywords)) {
147 names = CustomSQLUtil.keywords(keywords);
148 realNames = CustomSQLUtil.keywords(keywords);
149 descriptions = CustomSQLUtil.keywords(keywords);
150 }
151 else {
152 andOperator = true;
153 }
154
155 return countByC_C_PG_N_D(
156 companyId, _getGroupOrganizationClassNameIds(), parentGroupId,
157 parentGroupIdComparator, names, realNames, descriptions, params,
158 andOperator);
159 }
160
161 public int countByKeywords(
162 long companyId, long[] classNameIds, long parentGroupId,
163 String parentGroupIdComparator, String keywords,
164 LinkedHashMap<String, Object> params)
165 throws SystemException {
166
167 String[] names = null;
168 String[] realNames = null;
169 String[] descriptions = null;
170 boolean andOperator = false;
171
172 if (Validator.isNotNull(keywords)) {
173 names = CustomSQLUtil.keywords(keywords);
174 realNames = CustomSQLUtil.keywords(keywords);
175 descriptions = CustomSQLUtil.keywords(keywords);
176 }
177 else {
178 andOperator = true;
179 }
180
181 return countByC_C_PG_N_D(
182 companyId, classNameIds, parentGroupId, parentGroupIdComparator,
183 names, realNames, descriptions, params, andOperator);
184 }
185
186 public int countByKeywords(
187 long companyId, long[] classNameIds, String keywords,
188 LinkedHashMap<String, Object> params)
189 throws SystemException {
190
191 String[] names = null;
192 String[] realNames = null;
193 String[] descriptions = null;
194 boolean andOperator = false;
195
196 if (Validator.isNotNull(keywords)) {
197 names = CustomSQLUtil.keywords(keywords);
198 realNames = CustomSQLUtil.keywords(keywords);
199 descriptions = CustomSQLUtil.keywords(keywords);
200 }
201 else {
202 andOperator = true;
203 }
204
205 return countByC_C_PG_N_D(
206 companyId, classNameIds, GroupConstants.ANY_PARENT_GROUP_ID,
207 StringPool.NOT_EQUAL, names, realNames, descriptions, params,
208 andOperator);
209 }
210
211 public int countByKeywords(
212 long companyId, String keywords,
213 LinkedHashMap<String, Object> params)
214 throws SystemException {
215
216 String[] names = null;
217 String[] realNames = null;
218 String[] descriptions = null;
219 boolean andOperator = false;
220
221 if (Validator.isNotNull(keywords)) {
222 names = CustomSQLUtil.keywords(keywords);
223 realNames = CustomSQLUtil.keywords(keywords);
224 descriptions = CustomSQLUtil.keywords(keywords);
225 }
226 else {
227 andOperator = true;
228 }
229
230 return countByC_C_PG_N_D(
231 companyId, _getGroupOrganizationClassNameIds(),
232 GroupConstants.ANY_PARENT_GROUP_ID, StringPool.NOT_EQUAL, names,
233 realNames, descriptions, params, andOperator);
234 }
235
236 public int countByLayouts(long companyId, long parentGroupId, boolean site)
237 throws SystemException {
238
239 Session session = null;
240
241 try {
242 session = openSession();
243
244 String sql = CustomSQLUtil.get(COUNT_BY_LAYOUTS);
245
246 SQLQuery q = session.createSQLQuery(sql);
247
248 q.addEntity("Group_", GroupImpl.class);
249
250 QueryPos qPos = QueryPos.getInstance(q);
251
252 qPos.add(companyId);
253 qPos.add(parentGroupId);
254 qPos.add(site);
255
256 Iterator<Long> itr = q.iterate();
257
258 if (itr.hasNext()) {
259 Long count = itr.next();
260
261 if (count != null) {
262 return count.intValue();
263 }
264 }
265
266 return 0;
267 }
268 catch (Exception e) {
269 throw new SystemException(e);
270 }
271 finally {
272 closeSession(session);
273 }
274 }
275
276 public int countByG_U(long groupId, long userId, boolean inherit)
277 throws SystemException {
278
279 LinkedHashMap<String, Object> params1 =
280 new LinkedHashMap<String, Object>();
281
282 params1.put("usersGroups", userId);
283
284 LinkedHashMap<String, Object> params2 =
285 new LinkedHashMap<String, Object>();
286
287 params2.put("groupOrg", userId);
288
289 LinkedHashMap<String, Object> params3 =
290 new LinkedHashMap<String, Object>();
291
292 params3.put("groupsOrgs", userId);
293
294 LinkedHashMap<String, Object> params4 =
295 new LinkedHashMap<String, Object>();
296
297 params4.put("groupsUserGroups", userId);
298
299 Session session = null;
300
301 try {
302 session = openSession();
303
304 int count = countByGroupId(session, groupId, params1);
305
306 if (inherit) {
307 count += countByGroupId(session, groupId, params2);
308 count += countByGroupId(session, groupId, params3);
309 count += countByGroupId(session, groupId, params4);
310 }
311
312 return count;
313 }
314 catch (Exception e) {
315 throw new SystemException(e);
316 }
317 finally {
318 closeSession(session);
319 }
320 }
321
322 public int countByC_N_D(
323 long companyId, String name, String realName, String description,
324 LinkedHashMap<String, Object> params, boolean andOperator)
325 throws SystemException {
326
327 name = StringUtil.lowerCase(name);
328 description = StringUtil.lowerCase(description);
329
330 String[] names = CustomSQLUtil.keywords(name);
331 String[] realNames = CustomSQLUtil.keywords(realName);
332 String[] descriptions = CustomSQLUtil.keywords(description);
333
334 return countByC_C_PG_N_D(
335 companyId, _getGroupOrganizationClassNameIds(),
336 GroupConstants.ANY_PARENT_GROUP_ID, StringPool.NOT_EQUAL, names,
337 realNames, descriptions, params, andOperator);
338 }
339
340 public int countByC_N_D(
341 long companyId, String[] names, String[] realNames,
342 String[] descriptions, LinkedHashMap<String, Object> params,
343 boolean andOperator)
344 throws SystemException {
345
346 return countByC_C_PG_N_D(
347 companyId, _getGroupOrganizationClassNameIds(),
348 GroupConstants.ANY_PARENT_GROUP_ID, StringPool.NOT_EQUAL, names,
349 realNames, descriptions, params, andOperator);
350 }
351
352 public int countByC_C_N_D(
353 long companyId, long[] classNameIds, String name, String realName,
354 String description, LinkedHashMap<String, Object> params,
355 boolean andOperator)
356 throws SystemException {
357
358 String[] names = CustomSQLUtil.keywords(name);
359 String[] realNames = CustomSQLUtil.keywords(realName);
360 String[] descriptions = CustomSQLUtil.keywords(description);
361
362 return countByC_C_PG_N_D(
363 companyId, classNameIds, GroupConstants.ANY_PARENT_GROUP_ID,
364 StringPool.NOT_EQUAL, names, realNames, descriptions, params,
365 andOperator);
366 }
367
368 public int countByC_PG_N_D(
369 long companyId, long parentGroupId, String parentGroupIdComparator,
370 String name, String realName, String description,
371 LinkedHashMap<String, Object> params, boolean andOperator)
372 throws SystemException {
373
374 name = StringUtil.lowerCase(name);
375 description = StringUtil.lowerCase(description);
376
377 String[] names = CustomSQLUtil.keywords(name);
378 String[] realNames = CustomSQLUtil.keywords(realName);
379 String[] descriptions = CustomSQLUtil.keywords(description);
380
381 return countByC_C_PG_N_D(
382 companyId, _getGroupOrganizationClassNameIds(), parentGroupId,
383 parentGroupIdComparator, names, realNames, descriptions, params,
384 andOperator);
385 }
386
387 public int countByC_PG_N_D(
388 long companyId, long parentGroupId, String parentGroupIdComparator,
389 String[] names, String[] realNames, String[] descriptions,
390 LinkedHashMap<String, Object> params, boolean andOperator)
391 throws SystemException {
392
393 return countByC_C_PG_N_D(
394 companyId, _getGroupOrganizationClassNameIds(), parentGroupId,
395 parentGroupIdComparator, names, realNames, descriptions, params,
396 andOperator);
397 }
398
399 public int countByC_C_PG_N_D(
400 long companyId, long[] classNameIds, long parentGroupId,
401 String parentGroupIdComparator, String name, String realName,
402 String description, LinkedHashMap<String, Object> params,
403 boolean andOperator)
404 throws SystemException {
405
406 String[] names = CustomSQLUtil.keywords(name);
407 String[] realNames = CustomSQLUtil.keywords(realName);
408 String[] descriptions = CustomSQLUtil.keywords(description);
409
410 return countByC_C_PG_N_D(
411 companyId, classNameIds, parentGroupId, parentGroupIdComparator,
412 names, realNames, descriptions, params, andOperator);
413 }
414
415 public int countByC_C_PG_N_D(
416 long companyId, long[] classNameIds, long parentGroupId,
417 String parentGroupIdComparator, String[] names, String[] realNames,
418 String[] descriptions, LinkedHashMap<String, Object> params,
419 boolean andOperator)
420 throws SystemException {
421
422 names = CustomSQLUtil.keywords(names);
423 realNames = CustomSQLUtil.keywords(realNames);
424 descriptions = CustomSQLUtil.keywords(descriptions);
425
426 if (params == null) {
427 params = _emptyLinkedHashMap;
428 }
429
430 Long userId = (Long)params.get("usersGroups");
431
432 boolean doUnion = Validator.isNotNull(userId);
433
434 LinkedHashMap<String, Object> params1 = params;
435
436 LinkedHashMap<String, Object> params2 = null;
437
438 LinkedHashMap<String, Object> params3 = null;
439
440 LinkedHashMap<String, Object> params4 = null;
441
442 if (doUnion) {
443 params2 = new LinkedHashMap<String, Object>(params1);
444
445 params2.remove("usersGroups");
446 params2.put("groupOrg", userId);
447
448 params3 = new LinkedHashMap<String, Object>(params1);
449
450 params3.remove("usersGroups");
451 params3.put("groupsOrgs", userId);
452
453 params4 = new LinkedHashMap<String, Object>(params1);
454
455 params4.remove("usersGroups");
456 params4.put("groupsUserGroups", userId);
457 }
458
459 Session session = null;
460
461 try {
462 session = openSession();
463
464 Set<Long> groupIds = new HashSet<Long>();
465
466 groupIds.addAll(
467 countByC_C_PG_N_D(
468 session, companyId, classNameIds, parentGroupId,
469 parentGroupIdComparator, names, realNames, descriptions,
470 params1, andOperator));
471
472 if (doUnion) {
473 groupIds.addAll(
474 countByC_C_PG_N_D(
475 session, companyId, classNameIds, parentGroupId,
476 parentGroupIdComparator, names, realNames, descriptions,
477 params2, andOperator));
478
479 groupIds.addAll(
480 countByC_C_PG_N_D(
481 session, companyId, classNameIds, parentGroupId,
482 parentGroupIdComparator, names, realNames, descriptions,
483 params3, andOperator));
484
485 groupIds.addAll(
486 countByC_C_PG_N_D(
487 session, companyId, classNameIds, parentGroupId,
488 parentGroupIdComparator, names, realNames, descriptions,
489 params4, andOperator));
490 }
491
492 return groupIds.size();
493 }
494 catch (Exception e) {
495 throw new SystemException(e);
496 }
497 finally {
498 closeSession(session);
499 }
500 }
501
502 public List<Group> findByKeywords(
503 long companyId, long parentGroupId, String parentGroupIdComparator,
504 String keywords, LinkedHashMap<String, Object> params, int start,
505 int end, OrderByComparator obc)
506 throws SystemException {
507
508 String[] names = null;
509 String[] realNames = null;
510 String[] descriptions = null;
511 boolean andOperator = false;
512
513 if (Validator.isNotNull(keywords)) {
514 names = CustomSQLUtil.keywords(keywords);
515 realNames = CustomSQLUtil.keywords(keywords);
516 descriptions = CustomSQLUtil.keywords(keywords);
517 }
518 else {
519 andOperator = true;
520 }
521
522 return findByC_C_PG_N_D(
523 companyId, _getGroupOrganizationClassNameIds(), parentGroupId,
524 parentGroupIdComparator, names, realNames, descriptions, params,
525 andOperator, start, end, obc);
526 }
527
528 public List<Group> findByKeywords(
529 long companyId, long[] classNameIds, long parentGroupId,
530 String parentGroupIdComparator, String keywords,
531 LinkedHashMap<String, Object> params, int start, int end,
532 OrderByComparator obc)
533 throws SystemException {
534
535 String[] names = null;
536 String[] realNames = null;
537 String[] descriptions = null;
538 boolean andOperator = false;
539
540 if (Validator.isNotNull(keywords)) {
541 names = CustomSQLUtil.keywords(keywords);
542 realNames = CustomSQLUtil.keywords(keywords);
543 descriptions = CustomSQLUtil.keywords(keywords);
544 }
545 else {
546 andOperator = true;
547 }
548
549 return findByC_C_PG_N_D(
550 companyId, classNameIds, parentGroupId, parentGroupIdComparator,
551 names, realNames, descriptions, params, andOperator, start, end,
552 obc);
553 }
554
555 public List<Group> findByKeywords(
556 long companyId, long[] classNameIds, String keywords,
557 LinkedHashMap<String, Object> params, int start, int end,
558 OrderByComparator obc)
559 throws SystemException {
560
561 String[] names = null;
562 String[] realNames = null;
563 String[] descriptions = null;
564 boolean andOperator = false;
565
566 if (Validator.isNotNull(keywords)) {
567 names = CustomSQLUtil.keywords(keywords);
568 realNames = CustomSQLUtil.keywords(keywords);
569 descriptions = CustomSQLUtil.keywords(keywords);
570 }
571 else {
572 andOperator = true;
573 }
574
575 return findByC_C_PG_N_D(
576 companyId, classNameIds, GroupConstants.ANY_PARENT_GROUP_ID,
577 StringPool.NOT_EQUAL, names, realNames, descriptions, params,
578 andOperator, start, end, obc);
579 }
580
581 public List<Group> findByKeywords(
582 long companyId, String keywords,
583 LinkedHashMap<String, Object> params, int start, int end,
584 OrderByComparator obc)
585 throws SystemException {
586
587 String[] names = null;
588 String[] realNames = null;
589 String[] descriptions = null;
590 boolean andOperator = false;
591
592 if (Validator.isNotNull(keywords)) {
593 names = CustomSQLUtil.keywords(keywords);
594 realNames = CustomSQLUtil.keywords(keywords);
595 descriptions = CustomSQLUtil.keywords(keywords);
596 }
597 else {
598 andOperator = true;
599 }
600
601 return findByC_C_PG_N_D(
602 companyId, _getGroupOrganizationClassNameIds(),
603 GroupConstants.ANY_PARENT_GROUP_ID, StringPool.NOT_EQUAL, names,
604 realNames, descriptions, params, andOperator, start, end, obc);
605 }
606
607 public List<Group> findByLayouts(
608 long companyId, long parentGroupId, boolean site, int start,
609 int end)
610 throws SystemException {
611
612 Session session = null;
613
614 try {
615 session = openSession();
616
617 String sql = CustomSQLUtil.get(FIND_BY_LAYOUTS);
618
619 SQLQuery q = session.createSQLQuery(sql);
620
621 q.addEntity("Group_", GroupImpl.class);
622
623 QueryPos qPos = QueryPos.getInstance(q);
624
625 qPos.add(companyId);
626 qPos.add(parentGroupId);
627 qPos.add(site);
628
629 return q.list(true);
630 }
631 catch (Exception e) {
632 throw new SystemException(e);
633 }
634 finally {
635 closeSession(session);
636 }
637 }
638
639 public List<Group> findByLiveGroups() throws SystemException {
640 Session session = null;
641
642 try {
643 session = openSession();
644
645 String sql = CustomSQLUtil.get(FIND_BY_LIVE_GROUPS);
646
647 SQLQuery q = session.createSQLQuery(sql);
648
649 q.addEntity("Group_", GroupImpl.class);
650
651 return q.list(true);
652 }
653 catch (Exception e) {
654 throw new SystemException(e);
655 }
656 finally {
657 closeSession(session);
658 }
659 }
660
661 public List<Group> findByNoLayouts(
662 long classNameId, boolean privateLayout, int start, int end)
663 throws SystemException {
664
665 Session session = null;
666
667 try {
668 session = openSession();
669
670 String sql = CustomSQLUtil.get(FIND_BY_NO_LAYOUTS);
671
672 SQLQuery q = session.createSQLQuery(sql);
673
674 q.addEntity("Group_", GroupImpl.class);
675
676 QueryPos qPos = QueryPos.getInstance(q);
677
678 qPos.add(classNameId);
679 qPos.add(privateLayout);
680
681 return q.list(true);
682 }
683 catch (Exception e) {
684 throw new SystemException(e);
685 }
686 finally {
687 closeSession(session);
688 }
689 }
690
691 public List<Group> findByNullFriendlyURL() throws SystemException {
692 Session session = null;
693
694 try {
695 session = openSession();
696
697 String sql = CustomSQLUtil.get(FIND_BY_NULL_FRIENDLY_URL);
698
699 SQLQuery q = session.createSQLQuery(sql);
700
701 q.addEntity("Group_", GroupImpl.class);
702
703 return q.list(true);
704 }
705 catch (Exception e) {
706 throw new SystemException(e);
707 }
708 finally {
709 closeSession(session);
710 }
711 }
712
713 public List<Group> findBySystem(long companyId) throws SystemException {
714 Session session = null;
715
716 try {
717 session = openSession();
718
719 String sql = CustomSQLUtil.get(FIND_BY_SYSTEM);
720
721 SQLQuery q = session.createSQLQuery(sql);
722
723 q.addEntity("Group_", GroupImpl.class);
724
725 QueryPos qPos = QueryPos.getInstance(q);
726
727 qPos.add(companyId);
728
729 return q.list(true);
730 }
731 catch (Exception e) {
732 throw new SystemException(e);
733 }
734 finally {
735 closeSession(session);
736 }
737 }
738
739 public List<Group> findByCompanyId(
740 long companyId, LinkedHashMap<String, Object> params, int start,
741 int end, OrderByComparator obc)
742 throws SystemException {
743
744 if (params == null) {
745 params = _emptyLinkedHashMap;
746 }
747
748 Long userId = (Long)params.get("usersGroups");
749 boolean inherit = GetterUtil.getBoolean(params.get("inherit"), true);
750
751 boolean doUnion = Validator.isNotNull(userId) && inherit;
752
753 LinkedHashMap<String, Object> params1 = params;
754
755 LinkedHashMap<String, Object> params2 = null;
756
757 LinkedHashMap<String, Object> params3 = null;
758
759 LinkedHashMap<String, Object> params4 = null;
760
761 if (doUnion) {
762 params2 = new LinkedHashMap<String, Object>(params1);
763
764 params2.remove("usersGroups");
765 params2.put("groupOrg", userId);
766
767 params3 = new LinkedHashMap<String, Object>(params1);
768
769 params3.remove("usersGroups");
770 params3.put("groupsOrgs", userId);
771
772 params4 = new LinkedHashMap<String, Object>(params1);
773
774 params4.remove("usersGroups");
775 params4.put("groupsUserGroups", userId);
776 }
777
778 String sql = null;
779
780 String sqlKey = _buildSQLKey(
781 params1, params2, params3, params4, obc, doUnion);
782
783 sql = _findByCompanyIdSQLCache.get(sqlKey);
784
785 if (sql == null) {
786 String findByC_C_SQL = CustomSQLUtil.get(FIND_BY_C_C);
787
788 if (params.get("active") == Boolean.TRUE) {
789 findByC_C_SQL = StringUtil.replace(
790 findByC_C_SQL, "(Group_.liveGroupId = 0) AND",
791 StringPool.BLANK);
792 }
793
794 findByC_C_SQL = StringUtil.replace(
795 findByC_C_SQL, "Group_.classNameId = ?",
796 "Group_.classNameId = ".concat(
797 StringUtil.merge(
798 _getGroupOrganizationClassNameIds(),
799 " OR Group_.classNameId = ")));
800 findByC_C_SQL = replaceOrderBy(findByC_C_SQL, obc);
801
802 StringBundler sb = new StringBundler();
803
804 sb.append("(");
805 sb.append(replaceJoinAndWhere(findByC_C_SQL, params1));
806 sb.append(")");
807
808 if (doUnion) {
809 sb.append(" UNION (");
810 sb.append(replaceJoinAndWhere(findByC_C_SQL, params2));
811 sb.append(") UNION (");
812 sb.append(replaceJoinAndWhere(findByC_C_SQL, params3));
813 sb.append(") UNION (");
814 sb.append(replaceJoinAndWhere(findByC_C_SQL, params4));
815 sb.append(")");
816 }
817
818 if (obc != null) {
819 sb.append(" ORDER BY ");
820 sb.append(obc.toString());
821 }
822
823 sql = sb.toString();
824
825 _findByCompanyIdSQLCache.put(sqlKey, sql);
826 }
827
828 Session session = null;
829
830 try {
831 session = openSession();
832
833 SQLQuery q = session.createSQLQuery(sql);
834
835 q.addScalar("groupId", Type.LONG);
836
837 QueryPos qPos = QueryPos.getInstance(q);
838
839 setJoin(qPos, params1);
840
841 qPos.add(companyId);
842
843 if (doUnion) {
844 setJoin(qPos, params2);
845
846 qPos.add(companyId);
847
848 setJoin(qPos, params3);
849
850 qPos.add(companyId);
851
852 setJoin(qPos, params4);
853
854 qPos.add(companyId);
855 }
856
857 List<Long> groupIds = (List<Long>)QueryUtil.list(
858 q, getDialect(), start, end);
859
860 List<Group> groups = new ArrayList<Group>(groupIds.size());
861
862 for (Long groupId : groupIds) {
863 Group group = GroupUtil.findByPrimaryKey(groupId);
864
865 groups.add(group);
866 }
867
868 return groups;
869 }
870 catch (Exception e) {
871 throw new SystemException(e);
872 }
873 finally {
874 closeSession(session);
875 }
876 }
877
878 public Group findByC_N(long companyId, String name)
879 throws NoSuchGroupException, SystemException {
880
881 name = StringUtil.lowerCase(name);
882
883 Session session = null;
884
885 try {
886 session = openSession();
887
888 String sql = CustomSQLUtil.get(FIND_BY_C_N);
889
890 SQLQuery q = session.createSQLQuery(sql);
891
892 q.addEntity("Group_", GroupImpl.class);
893
894 QueryPos qPos = QueryPos.getInstance(q);
895
896 qPos.add(companyId);
897 qPos.add(name);
898
899 List<Group> groups = q.list();
900
901 if (!groups.isEmpty()) {
902 return groups.get(0);
903 }
904 }
905 catch (Exception e) {
906 throw new SystemException(e);
907 }
908 finally {
909 closeSession(session);
910 }
911
912 StringBundler sb = new StringBundler(5);
913
914 sb.append("No Group exists with the key {companyId=");
915 sb.append(companyId);
916 sb.append(", name=");
917 sb.append(name);
918 sb.append("}");
919
920 throw new NoSuchGroupException(sb.toString());
921 }
922
923 public List<Group> findByC_N_D(
924 long companyId, String name, String realName, String description,
925 LinkedHashMap<String, Object> params, boolean andOperator,
926 int start, int end, OrderByComparator obc)
927 throws SystemException {
928
929 name = StringUtil.lowerCase(name);
930 description = StringUtil.lowerCase(description);
931
932 String[] names = CustomSQLUtil.keywords(name);
933 String[] realNames = CustomSQLUtil.keywords(realName);
934 String[] descriptions = CustomSQLUtil.keywords(description);
935
936 return findByC_C_PG_N_D(
937 companyId, _getGroupOrganizationClassNameIds(),
938 GroupConstants.ANY_PARENT_GROUP_ID, StringPool.NOT_EQUAL, names,
939 realNames, descriptions, params, andOperator, start, end, obc);
940 }
941
942 public List<Group> findByC_N_D(
943 long companyId, String[] names, String[] realNames,
944 String[] descriptions, LinkedHashMap<String, Object> params,
945 boolean andOperator, int start, int end, OrderByComparator obc)
946 throws SystemException {
947
948 return findByC_C_PG_N_D(
949 companyId, _getGroupOrganizationClassNameIds(),
950 GroupConstants.ANY_PARENT_GROUP_ID, StringPool.NOT_EQUAL, names,
951 realNames, descriptions, params, andOperator, start, end, obc);
952 }
953
954 public List<Group> findByC_C_N_D(
955 long companyId, long[] classNameIds, String name, String realName,
956 String description, LinkedHashMap<String, Object> params,
957 boolean andOperator, int start, int end, OrderByComparator obc)
958 throws SystemException {
959
960 String[] names = CustomSQLUtil.keywords(name);
961 String[] realNames = CustomSQLUtil.keywords(realName);
962 String[] descriptions = CustomSQLUtil.keywords(description);
963
964 return findByC_C_PG_N_D(
965 companyId, classNameIds, GroupConstants.ANY_PARENT_GROUP_ID,
966 StringPool.NOT_EQUAL, names, realNames, descriptions, params,
967 andOperator, start, end, obc);
968 }
969
970 public List<Group> findByC_PG_N_D(
971 long companyId, long parentGroupId, String parentGroupIdComparator,
972 String name, String realName, String description,
973 LinkedHashMap<String, Object> params, boolean andOperator,
974 int start, int end, OrderByComparator obc)
975 throws SystemException {
976
977 name = StringUtil.lowerCase(name);
978 description = StringUtil.lowerCase(description);
979
980 String[] names = CustomSQLUtil.keywords(name);
981 String[] realNames = CustomSQLUtil.keywords(realName);
982 String[] descriptions = CustomSQLUtil.keywords(description);
983
984 return findByC_C_PG_N_D(
985 companyId, _getGroupOrganizationClassNameIds(), parentGroupId,
986 parentGroupIdComparator, names, realNames, descriptions, params,
987 andOperator, start, end, obc);
988 }
989
990 public List<Group> findByC_PG_N_D(
991 long companyId, long parentGroupId, String parentGroupIdComparator,
992 String[] names, String[] realNames, String[] descriptions,
993 LinkedHashMap<String, Object> params, boolean andOperator,
994 int start, int end, OrderByComparator obc)
995 throws SystemException {
996
997 return findByC_C_PG_N_D(
998 companyId, _getGroupOrganizationClassNameIds(), parentGroupId,
999 parentGroupIdComparator, names, realNames, descriptions, params,
1000 andOperator, start, end, obc);
1001 }
1002
1003 public List<Group> findByC_C_PG_N_D(
1004 long companyId, long[] classNameIds, long parentGroupId,
1005 String parentGroupIdComparator, String name, String realName,
1006 String description, LinkedHashMap<String, Object> params,
1007 boolean andOperator, int start, int end, OrderByComparator obc)
1008 throws SystemException {
1009
1010 String[] names = CustomSQLUtil.keywords(name);
1011 String[] realNames = CustomSQLUtil.keywords(realName);
1012 String[] descriptions = CustomSQLUtil.keywords(description);
1013
1014 return findByC_C_PG_N_D(
1015 companyId, classNameIds, parentGroupId, parentGroupIdComparator,
1016 names, realNames, descriptions, params, andOperator, start, end,
1017 obc);
1018 }
1019
1020 public List<Group> findByC_C_PG_N_D(
1021 long companyId, long[] classNameIds, long parentGroupId,
1022 String parentGroupIdComparator, String[] names, String[] realNames,
1023 String[] descriptions, LinkedHashMap<String, Object> params,
1024 boolean andOperator, int start, int end, OrderByComparator obc)
1025 throws SystemException {
1026
1027 names = CustomSQLUtil.keywords(names);
1028 realNames = CustomSQLUtil.keywords(realNames);
1029 descriptions = CustomSQLUtil.keywords(descriptions);
1030
1031 if (params == null) {
1032 params = _emptyLinkedHashMap;
1033 }
1034
1035 Long userId = (Long)params.get("usersGroups");
1036 boolean inherit = GetterUtil.getBoolean(params.get("inherit"), true);
1037
1038 boolean doUnion = Validator.isNotNull(userId) && inherit;
1039
1040 LinkedHashMap<String, Object> params1 = params;
1041
1042 LinkedHashMap<String, Object> params2 = null;
1043
1044 LinkedHashMap<String, Object> params3 = null;
1045
1046 LinkedHashMap<String, Object> params4 = null;
1047
1048 if (doUnion) {
1049 params2 = new LinkedHashMap<String, Object>(params1);
1050
1051 params2.remove("usersGroups");
1052 params2.put("groupOrg", userId);
1053
1054 params3 = new LinkedHashMap<String, Object>(params1);
1055
1056 params3.remove("usersGroups");
1057 params3.put("groupsOrgs", userId);
1058
1059 params4 = new LinkedHashMap<String, Object>(params1);
1060
1061 params4.remove("usersGroups");
1062 params4.put("groupsUserGroups", userId);
1063 }
1064
1065 String sql = null;
1066
1067 if (classNameIds == _getGroupOrganizationClassNameIds()) {
1068 String sqlKey = _buildSQLKey(
1069 params1, params2, params3, params4, obc, doUnion);
1070
1071 sql = _findByC_C_PG_N_DSQLCache.get(sqlKey);
1072 }
1073
1074 if (sql == null) {
1075 String findByC_PG_N_D_SQL = CustomSQLUtil.get(FIND_BY_C_C_PG_N_D);
1076
1077 if (classNameIds == null) {
1078 findByC_PG_N_D_SQL = StringUtil.replace(
1079 findByC_PG_N_D_SQL, "AND (Group_.classNameId = ?)",
1080 StringPool.BLANK);
1081 }
1082 else {
1083 findByC_PG_N_D_SQL = StringUtil.replace(
1084 findByC_PG_N_D_SQL, "Group_.classNameId = ?",
1085 "Group_.classNameId = ".concat(
1086 StringUtil.merge(
1087 classNameIds, " OR Group_.classNameId = ")));
1088 }
1089
1090 findByC_PG_N_D_SQL = replaceOrderBy(findByC_PG_N_D_SQL, obc);
1091
1092 StringBundler sb = new StringBundler();
1093
1094 sb.append("(");
1095 sb.append(replaceJoinAndWhere(findByC_PG_N_D_SQL, params1));
1096 sb.append(")");
1097
1098 if (doUnion) {
1099 sb.append(" UNION (");
1100 sb.append(replaceJoinAndWhere(findByC_PG_N_D_SQL, params2));
1101 sb.append(") UNION (");
1102 sb.append(replaceJoinAndWhere(findByC_PG_N_D_SQL, params3));
1103 sb.append(") UNION (");
1104 sb.append(replaceJoinAndWhere(findByC_PG_N_D_SQL, params4));
1105 sb.append(")");
1106 }
1107
1108 if (obc != null) {
1109 sb.append(" ORDER BY ");
1110 sb.append(obc.toString());
1111 }
1112
1113 sql = sb.toString();
1114
1115 if (classNameIds == _getGroupOrganizationClassNameIds()) {
1116 String sqlKey = _buildSQLKey(
1117 params1, params2, params3, params4, obc, doUnion);
1118
1119 _findByC_C_PG_N_DSQLCache.put(sqlKey, sql);
1120 }
1121 }
1122
1123 sql = StringUtil.replace(
1124 sql, "[$PARENT_GROUP_ID_COMPARATOR$]",
1125 parentGroupIdComparator.equals(StringPool.EQUAL) ?
1126 StringPool.EQUAL : StringPool.NOT_EQUAL);
1127 sql = CustomSQLUtil.replaceKeywords(
1128 sql, "lower(Group_.name) LIKE ? OR lower(Group_.name)",
1129 StringPool.LIKE, false, names);
1130 sql = CustomSQLUtil.replaceKeywords(
1131 sql, "lower(Group_.description)", StringPool.LIKE, true,
1132 descriptions);
1133 sql = CustomSQLUtil.replaceAndOperator(sql, andOperator);
1134
1135 Session session = null;
1136
1137 try {
1138 session = openSession();
1139
1140 SQLQuery q = session.createSQLQuery(sql);
1141
1142 q.addScalar("groupId", Type.LONG);
1143
1144 QueryPos qPos = QueryPos.getInstance(q);
1145
1146 setJoin(qPos, params1);
1147
1148 qPos.add(companyId);
1149 qPos.add(parentGroupId);
1150 qPos.add(names);
1151 qPos.add(realNames);
1152 qPos.add(names);
1153 qPos.add(descriptions, 2);
1154
1155 if (doUnion) {
1156 setJoin(qPos, params2);
1157
1158 qPos.add(companyId);
1159 qPos.add(parentGroupId);
1160 qPos.add(names);
1161 qPos.add(realNames);
1162 qPos.add(names);
1163 qPos.add(descriptions, 2);
1164
1165 setJoin(qPos, params3);
1166
1167 qPos.add(companyId);
1168 qPos.add(parentGroupId);
1169 qPos.add(names);
1170 qPos.add(realNames);
1171 qPos.add(names);
1172 qPos.add(descriptions, 2);
1173
1174 setJoin(qPos, params4);
1175
1176 qPos.add(companyId);
1177 qPos.add(parentGroupId);
1178 qPos.add(names);
1179 qPos.add(realNames);
1180 qPos.add(names);
1181 qPos.add(descriptions, 2);
1182 }
1183
1184 List<Long> groupIds = (List<Long>)QueryUtil.list(
1185 q, getDialect(), start, end);
1186
1187 List<Group> groups = new ArrayList<Group>(groupIds.size());
1188
1189 for (Long groupId : groupIds) {
1190 Group group = GroupUtil.findByPrimaryKey(groupId);
1191
1192 groups.add(group);
1193 }
1194
1195 return groups;
1196 }
1197 catch (Exception e) {
1198 throw new SystemException(e);
1199 }
1200 finally {
1201 closeSession(session);
1202 }
1203 }
1204
1205 protected int countByGroupId(
1206 Session session, long groupId, LinkedHashMap<String, Object> params) {
1207
1208 String sql = CustomSQLUtil.get(COUNT_BY_GROUP_ID);
1209
1210 sql = replaceJoinAndWhere(sql, params);
1211
1212 SQLQuery q = session.createSQLQuery(sql);
1213
1214 q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
1215
1216 QueryPos qPos = QueryPos.getInstance(q);
1217
1218 setJoin(qPos, params);
1219
1220 qPos.add(groupId);
1221
1222 Iterator<Long> itr = q.iterate();
1223
1224 if (itr.hasNext()) {
1225 Long count = itr.next();
1226
1227 if (count != null) {
1228 return count.intValue();
1229 }
1230 }
1231
1232 return 0;
1233 }
1234
1235 protected List<Long> countByC_C_PG_N_D(
1236 Session session, long companyId, long[] classNameIds,
1237 long parentGroupId, String parentGroupIdComparator, String[] names,
1238 String[] realNames, String[] descriptions,
1239 LinkedHashMap<String, Object> params, boolean andOperator) {
1240
1241 String sql = CustomSQLUtil.get(COUNT_BY_C_C_PG_N_D);
1242
1243 if (classNameIds == null) {
1244 sql = StringUtil.replace(
1245 sql, "AND (Group_.classNameId = ?)", StringPool.BLANK);
1246 }
1247 else {
1248 sql = StringUtil.replace(
1249 sql, "Group_.classNameId = ?",
1250 "Group_.classNameId = ".concat(
1251 StringUtil.merge(
1252 classNameIds, " OR Group_.classNameId = ")));
1253 }
1254
1255 sql = StringUtil.replace(
1256 sql, "[$PARENT_GROUP_ID_COMPARATOR$]",
1257 parentGroupIdComparator.equals(StringPool.EQUAL) ?
1258 StringPool.EQUAL : StringPool.NOT_EQUAL);
1259 sql = CustomSQLUtil.replaceKeywords(
1260 sql, "lower(Group_.name) LIKE ? OR lower(Group_.name)",
1261 StringPool.LIKE, false, names);
1262 sql = CustomSQLUtil.replaceKeywords(
1263 sql, "lower(Group_.description)", StringPool.LIKE, true,
1264 descriptions);
1265
1266 sql = replaceJoinAndWhere(sql, params);
1267 sql = CustomSQLUtil.replaceAndOperator(sql, andOperator);
1268
1269 SQLQuery q = session.createSQLQuery(sql);
1270
1271 q.addScalar("groupId", Type.LONG);
1272
1273 QueryPos qPos = QueryPos.getInstance(q);
1274
1275 setJoin(qPos, params);
1276
1277 qPos.add(companyId);
1278 qPos.add(parentGroupId);
1279 qPos.add(names);
1280 qPos.add(realNames);
1281 qPos.add(names);
1282 qPos.add(descriptions, 2);
1283
1284 return q.list(true);
1285 }
1286
1287 protected String getJoin(LinkedHashMap<String, Object> params) {
1288 if ((params == null) || params.isEmpty()) {
1289 return StringPool.BLANK;
1290 }
1291
1292 StringBundler sb = new StringBundler(params.size());
1293
1294 for (Map.Entry<String, Object> entry : params.entrySet()) {
1295 String key = entry.getKey();
1296 Object value = entry.getValue();
1297
1298 if (Validator.isNull(value)) {
1299 continue;
1300 }
1301
1302 if (key.equals("rolePermissions")) {
1303
1304 List<Object> values = (List<Object>)value;
1305
1306 String name = (String)values.get(0);
1307
1308 if (ResourceBlockLocalServiceUtil.isSupported(name)) {
1309 key = "rolePermissions_6_block";
1310 }
1311 else {
1312 key = "rolePermissions_6";
1313 }
1314 }
1315
1316 Map<String, String> joinMap = _getJoinMap();
1317
1318 String joinValue = joinMap.get(key);
1319
1320 if (Validator.isNotNull(joinValue)) {
1321 sb.append(joinValue);
1322 }
1323 }
1324
1325 return sb.toString();
1326 }
1327
1328 protected String getWhere(LinkedHashMap<String, Object> params) {
1329 if ((params == null) || params.isEmpty()) {
1330 return StringPool.BLANK;
1331 }
1332
1333 StringBundler sb = new StringBundler(params.size());
1334
1335 for (Map.Entry<String, Object> entry : params.entrySet()) {
1336 String key = entry.getKey();
1337
1338 if (key.equals("types")) {
1339 List<Integer> types = (List<Integer>)entry.getValue();
1340
1341 if (!types.isEmpty()) {
1342 sb.append("(");
1343
1344 for (int i = 0; i < types.size(); i++) {
1345 sb.append("(Group_.type_ = ?) ");
1346
1347 if ((i + 1) < types.size()) {
1348 sb.append("OR ");
1349 }
1350 }
1351
1352 sb.append(") AND ");
1353 }
1354 }
1355 else {
1356 if (key.equals("rolePermissions")) {
1357
1358 List<Object> values = (List<Object>)entry.getValue();
1359
1360 String name = (String)values.get(0);
1361
1362 if (ResourceBlockLocalServiceUtil.isSupported(name)) {
1363 key = "rolePermissions_6_block";
1364 }
1365 else {
1366 key = "rolePermissions_6";
1367 }
1368 }
1369
1370 Map<String, String> whereMap = _getWhereMap();
1371
1372 String whereValue = whereMap.get(key);
1373
1374 if (Validator.isNotNull(whereValue)) {
1375 sb.append(whereValue);
1376 }
1377 }
1378 }
1379
1380 return sb.toString();
1381 }
1382
1383 protected String replaceJoinAndWhere(
1384 String sql, LinkedHashMap<String, Object> params) {
1385
1386 if (params.isEmpty()) {
1387 return StringUtil.replace(
1388 sql,
1389 new String[] {
1390 "[$JOIN$]", "[$WHERE$]"
1391 },
1392 new String[] {
1393 StringPool.BLANK, StringPool.BLANK
1394 });
1395 }
1396
1397 String cacheKey = _getCacheKey(sql, params);
1398
1399 String resultSQL = _replaceJoinAndWhereSQLCache.get(cacheKey);
1400
1401 if (resultSQL == null) {
1402 sql = StringUtil.replace(sql, "[$JOIN$]", getJoin(params));
1403
1404 resultSQL = StringUtil.replace(sql, "[$WHERE$]", getWhere(params));
1405
1406 _replaceJoinAndWhereSQLCache.put(cacheKey, resultSQL);
1407 }
1408
1409 return resultSQL;
1410 }
1411
1412 protected String replaceOrderBy(String sql, OrderByComparator obc) {
1413 if (obc instanceof GroupNameComparator) {
1414 sql = StringUtil.replace(
1415 sql, "Group_.name AS groupName",
1416 "REPLACE(Group_.name, '" +
1417 GroupLocalServiceImpl.ORGANIZATION_NAME_SUFFIX +
1418 "', '') AS groupName");
1419 }
1420
1421 return sql;
1422 }
1423
1424 protected void setJoin(
1425 QueryPos qPos, LinkedHashMap<String, Object> params) {
1426
1427 if (params == null) {
1428 return;
1429 }
1430
1431 for (Map.Entry<String, Object> entry : params.entrySet()) {
1432 String key = entry.getKey();
1433
1434 if (key.equals("active") || key.equals("layoutSet") ||
1435 key.equals("site")) {
1436
1437 Boolean value = (Boolean)entry.getValue();
1438
1439 qPos.add(value);
1440 }
1441 else if (key.equals("pageCount")) {
1442 }
1443 else if (key.equals("rolePermissions")) {
1444 List<Object> values = (List<Object>)entry.getValue();
1445
1446 String name = (String)values.get(0);
1447 Integer scope = (Integer)values.get(1);
1448 String actionId = (String)values.get(2);
1449 Long roleId = (Long)values.get(3);
1450
1451 if (ResourceBlockLocalServiceUtil.isSupported(name)) {
1452
1453
1454
1455 qPos.add(name);
1456 qPos.add(roleId);
1457 qPos.add(actionId);
1458 }
1459 else {
1460 qPos.add(name);
1461 qPos.add(scope);
1462 qPos.add(actionId);
1463 qPos.add(roleId);
1464 }
1465 }
1466 else if (key.equals("types")) {
1467 List<Integer> values = (List<Integer>)entry.getValue();
1468
1469 for (int i = 0; i < values.size(); i++) {
1470 Integer value = values.get(i);
1471
1472 qPos.add(value);
1473 }
1474 }
1475 else if (key.equals("userGroupRole")) {
1476 List<Long> values = (List<Long>)entry.getValue();
1477
1478 Long userId = values.get(0);
1479 Long roleId = values.get(1);
1480
1481 qPos.add(userId);
1482 qPos.add(roleId);
1483 }
1484 else {
1485 Object value = entry.getValue();
1486
1487 if (value instanceof Integer) {
1488 Integer valueInteger = (Integer)value;
1489
1490 if (Validator.isNotNull(valueInteger)) {
1491 qPos.add(valueInteger);
1492 }
1493 }
1494 else if (value instanceof Long) {
1495 Long valueLong = (Long)value;
1496
1497 if (Validator.isNotNull(valueLong)) {
1498 qPos.add(valueLong);
1499 }
1500 }
1501 else if (value instanceof String) {
1502 String valueString = (String)value;
1503
1504 if (Validator.isNotNull(valueString)) {
1505 qPos.add(valueString);
1506 }
1507 }
1508 }
1509 }
1510 }
1511
1512 private String _buildSQLKey(
1513 LinkedHashMap<String, Object> param1,
1514 LinkedHashMap<String, Object> param2,
1515 LinkedHashMap<String, Object> param3,
1516 LinkedHashMap<String, Object> param4, OrderByComparator obc,
1517 boolean doUnion) {
1518
1519 StringBundler sb = null;
1520
1521 if (doUnion) {
1522 sb = new StringBundler(
1523 param1.size() + param2.size() + param3.size() + param4.size() +
1524 1);
1525
1526 for (String key : param1.keySet()) {
1527 sb.append(key);
1528 }
1529
1530 for (String key : param2.keySet()) {
1531 sb.append(key);
1532 }
1533
1534 for (String key : param3.keySet()) {
1535 sb.append(key);
1536 }
1537
1538 for (String key : param4.keySet()) {
1539 sb.append(key);
1540 }
1541 }
1542 else {
1543 sb = new StringBundler(param1.size() + 1);
1544
1545 for (String key : param1.keySet()) {
1546 sb.append(key);
1547 }
1548 }
1549
1550 sb.append(obc.getOrderBy());
1551
1552 return sb.toString();
1553 }
1554
1555 private String _getCacheKey(
1556 String sql, LinkedHashMap<String, Object> params) {
1557
1558 StringBundler sb = new StringBundler(params.size() + 1);
1559
1560 sb.append(sql);
1561
1562 for (Map.Entry<String, Object> entry : params.entrySet()) {
1563 String key = entry.getKey();
1564
1565 if (key.equals("rolePermissions")) {
1566
1567 List<Object> values = (List<Object>)entry.getValue();
1568
1569 String name = (String)values.get(0);
1570
1571 if (ResourceBlockLocalServiceUtil.isSupported(name)) {
1572 key = "rolePermissions_6_block";
1573 }
1574 else {
1575 key = "rolePermissions_6";
1576 }
1577 }
1578
1579 sb.append(key);
1580 }
1581
1582 return sb.toString();
1583 }
1584
1585 private String _getCondition(String join) {
1586 if (Validator.isNotNull(join)) {
1587 int pos = join.indexOf("WHERE");
1588
1589 if (pos != -1) {
1590 join = join.substring(pos + 5, join.length()).concat(" AND ");
1591 }
1592 else {
1593 join = StringPool.BLANK;
1594 }
1595 }
1596
1597 return join;
1598 }
1599
1600 private long[] _getGroupOrganizationClassNameIds() {
1601 if (_groupOrganizationClassNameIds == null) {
1602 _groupOrganizationClassNameIds = new long[] {
1603 ClassNameLocalServiceUtil.getClassNameId(Group.class),
1604 ClassNameLocalServiceUtil.getClassNameId(Organization.class)
1605 };
1606 }
1607
1608 return _groupOrganizationClassNameIds;
1609 }
1610
1611 private Map<String, String> _getJoinMap() {
1612 if (_joinMap != null) {
1613 return _joinMap;
1614 }
1615
1616 Map<String, String> joinMap = new HashMap<String, String>();
1617
1618 joinMap.put("active", _removeWhere(CustomSQLUtil.get(JOIN_BY_ACTIVE)));
1619 joinMap.put(
1620 "groupOrg", _removeWhere(CustomSQLUtil.get(JOIN_BY_GROUP_ORG)));
1621 joinMap.put(
1622 "groupsOrgs", _removeWhere(CustomSQLUtil.get(JOIN_BY_GROUPS_ORGS)));
1623 joinMap.put(
1624 "groupsRoles",
1625 _removeWhere(CustomSQLUtil.get(JOIN_BY_GROUPS_ROLES)));
1626 joinMap.put(
1627 "groupsUserGroups",
1628 _removeWhere(CustomSQLUtil.get(JOIN_BY_GROUPS_USER_GROUPS)));
1629 joinMap.put(
1630 "layoutSet", _removeWhere(CustomSQLUtil.get(JOIN_BY_LAYOUT_SET)));
1631 joinMap.put(
1632 "pageCount", _removeWhere(CustomSQLUtil.get(JOIN_BY_PAGE_COUNT)));
1633 joinMap.put(
1634 "rolePermissions",
1635 _removeWhere(CustomSQLUtil.get(JOIN_BY_ROLE_PERMISSIONS)));
1636 joinMap.put(
1637 "rolePermissions_6",
1638 _removeWhere(CustomSQLUtil.get(JOIN_BY_ROLE_RESOURCE_PERMISSIONS)));
1639 joinMap.put(
1640 "rolePermissions_6_block",
1641 _removeWhere(
1642 CustomSQLUtil.get(JOIN_BY_ROLE_RESOURCE_TYPE_PERMISSIONS)));
1643 joinMap.put("site", _removeWhere(CustomSQLUtil.get(JOIN_BY_SITE)));
1644 joinMap.put("type", _removeWhere(CustomSQLUtil.get(JOIN_BY_TYPE)));
1645 joinMap.put(
1646 "userGroupRole",
1647 _removeWhere(CustomSQLUtil.get(JOIN_BY_USER_GROUP_ROLE)));
1648 joinMap.put(
1649 "usersGroups",
1650 _removeWhere(CustomSQLUtil.get(JOIN_BY_USERS_GROUPS)));
1651
1652 _joinMap = joinMap;
1653
1654 return _joinMap;
1655 }
1656
1657 private Map<String, String> _getWhereMap() {
1658 if (_whereMap != null) {
1659 return _whereMap;
1660 }
1661
1662 Map<String, String> whereMap = new HashMap<String, String>();
1663
1664 whereMap.put(
1665 "active", _getCondition(CustomSQLUtil.get(JOIN_BY_ACTIVE)));
1666 whereMap.put(
1667 "creatorUserId",
1668 _getCondition(CustomSQLUtil.get(JOIN_BY_CREATOR_USER_ID)));
1669 whereMap.put(
1670 "groupOrg", _getCondition(CustomSQLUtil.get(JOIN_BY_GROUP_ORG)));
1671 whereMap.put(
1672 "groupsOrgs",
1673 _getCondition(CustomSQLUtil.get(JOIN_BY_GROUPS_ORGS)));
1674 whereMap.put(
1675 "groupsRoles",
1676 _getCondition(CustomSQLUtil.get(JOIN_BY_GROUPS_ROLES)));
1677 whereMap.put(
1678 "groupsUserGroups",
1679 _getCondition(CustomSQLUtil.get(JOIN_BY_GROUPS_USER_GROUPS)));
1680 whereMap.put(
1681 "layoutSet", _getCondition(CustomSQLUtil.get(JOIN_BY_LAYOUT_SET)));
1682 whereMap.put(
1683 "pageCount", _getCondition(CustomSQLUtil.get(JOIN_BY_PAGE_COUNT)));
1684 whereMap.put(
1685 "rolePermissions",
1686 _getCondition(CustomSQLUtil.get(JOIN_BY_ROLE_PERMISSIONS)));
1687 whereMap.put(
1688 "rolePermissions_6",
1689 _getCondition(
1690 CustomSQLUtil.get(JOIN_BY_ROLE_RESOURCE_PERMISSIONS)));
1691 whereMap.put(
1692 "rolePermissions_6_block",
1693 _getCondition(
1694 CustomSQLUtil.get(JOIN_BY_ROLE_RESOURCE_TYPE_PERMISSIONS)));
1695 whereMap.put("site", _getCondition(CustomSQLUtil.get(JOIN_BY_SITE)));
1696 whereMap.put("type", _getCondition(CustomSQLUtil.get(JOIN_BY_TYPE)));
1697 whereMap.put(
1698 "userGroupRole",
1699 _getCondition(CustomSQLUtil.get(JOIN_BY_USER_GROUP_ROLE)));
1700 whereMap.put(
1701 "usersGroups",
1702 _getCondition(CustomSQLUtil.get(JOIN_BY_USERS_GROUPS)));
1703
1704 _whereMap = whereMap;
1705
1706 return _whereMap;
1707 }
1708
1709 private String _removeWhere(String join) {
1710 if (Validator.isNotNull(join)) {
1711 int pos = join.indexOf("WHERE");
1712
1713 if (pos != -1) {
1714 join = join.substring(0, pos);
1715 }
1716 }
1717
1718 return join;
1719 }
1720
1721 private LinkedHashMap<String, Object> _emptyLinkedHashMap =
1722 new LinkedHashMap<String, Object>(0);
1723 private Map<String, String> _findByC_C_PG_N_DSQLCache =
1724 new ConcurrentHashMap<String, String>();
1725 private Map<String, String> _findByCompanyIdSQLCache =
1726 new ConcurrentHashMap<String, String>();
1727 private volatile long[] _groupOrganizationClassNameIds;
1728 private volatile Map<String, String> _joinMap;
1729 private Map<String, String> _replaceJoinAndWhereSQLCache =
1730 new ConcurrentHashMap<String, String>();
1731 private volatile Map<String, String> _whereMap;
1732
1733 }