1   /**
2    * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portal.service.persistence;
24  
25  import com.liferay.portal.NoSuchGroupException;
26  import com.liferay.portal.SystemException;
27  import com.liferay.portal.kernel.util.ArrayUtil;
28  import com.liferay.portal.kernel.util.GetterUtil;
29  import com.liferay.portal.kernel.util.OrderByComparator;
30  import com.liferay.portal.kernel.util.StringMaker;
31  import com.liferay.portal.kernel.util.StringPool;
32  import com.liferay.portal.kernel.util.StringUtil;
33  import com.liferay.portal.kernel.util.Validator;
34  import com.liferay.portal.model.Group;
35  import com.liferay.portal.model.LayoutSet;
36  import com.liferay.portal.model.Permission;
37  import com.liferay.portal.model.Resource;
38  import com.liferay.portal.model.ResourceCode;
39  import com.liferay.portal.model.UserGroupRole;
40  import com.liferay.portal.model.impl.GroupImpl;
41  import com.liferay.portal.model.impl.GroupModelImpl;
42  import com.liferay.portal.model.impl.LayoutSetModelImpl;
43  import com.liferay.portal.model.impl.PermissionModelImpl;
44  import com.liferay.portal.model.impl.ResourceCodeModelImpl;
45  import com.liferay.portal.model.impl.ResourceModelImpl;
46  import com.liferay.portal.model.impl.RoleModelImpl;
47  import com.liferay.portal.model.impl.UserGroupRoleModelImpl;
48  import com.liferay.portal.model.impl.UserModelImpl;
49  import com.liferay.portal.spring.hibernate.CustomSQLUtil;
50  import com.liferay.portal.spring.hibernate.FinderCache;
51  import com.liferay.portal.spring.hibernate.HibernateUtil;
52  import com.liferay.util.dao.hibernate.QueryPos;
53  import com.liferay.util.dao.hibernate.QueryUtil;
54  
55  import java.util.ArrayList;
56  import java.util.Iterator;
57  import java.util.LinkedHashMap;
58  import java.util.List;
59  import java.util.Map;
60  
61  import org.hibernate.Hibernate;
62  import org.hibernate.SQLQuery;
63  import org.hibernate.Session;
64  
65  /**
66   * <a href="GroupFinderImpl.java.html"><b><i>View Source</i></b></a>
67   *
68   * @author Brian Wing Shun Chan
69   *
70   */
71  public class GroupFinderImpl implements GroupFinder {
72  
73      public static String COUNT_BY_GROUP_ID =
74          GroupFinder.class.getName() + ".countByGroupId";
75  
76      public static String COUNT_BY_C_N_D =
77          GroupFinder.class.getName() + ".countByC_N_D";
78  
79      public static String FIND_BY_C_N =
80          GroupFinder.class.getName() + ".findByC_N";
81  
82      public static String FIND_BY_C_N_D =
83          GroupFinder.class.getName() + ".findByC_N_D";
84  
85      public static String JOIN_BY_ACTIVE =
86          GroupFinder.class.getName() + ".joinByActive";
87  
88      public static String JOIN_BY_CREATOR_USER_ID =
89          GroupFinder.class.getName() + ".joinByCreatorUserId";
90  
91      public static String JOIN_BY_GROUPS_ORGS =
92          GroupFinder.class.getName() + ".joinByGroupsOrgs";
93  
94      public static String JOIN_BY_GROUPS_ROLES =
95          GroupFinder.class.getName() + ".joinByGroupsRoles";
96  
97      public static String JOIN_BY_GROUPS_USER_GROUPS =
98          GroupFinder.class.getName() + ".joinByGroupsUserGroups";
99  
100     public static String JOIN_BY_LAYOUT_SET =
101         GroupFinder.class.getName() + ".joinByLayoutSet";
102 
103     public static String JOIN_BY_PAGE_COUNT =
104         GroupFinder.class.getName() + ".joinByPageCount";
105 
106     public static String JOIN_BY_ROLE_PERMISSIONS =
107         GroupFinder.class.getName() + ".joinByRolePermissions";
108 
109     public static String JOIN_BY_TYPE =
110         GroupFinder.class.getName() + ".joinByType";
111 
112     public static String JOIN_BY_USER_GROUP_ROLE =
113         GroupFinder.class.getName() + ".joinByUserGroupRole";
114 
115     public static String JOIN_BY_USERS_GROUPS =
116         GroupFinder.class.getName() + ".joinByUsersGroups";
117 
118     public int countByG_U(long groupId, long userId) throws SystemException {
119         String finderSQL = Group.class.getName();
120         boolean[] finderClassNamesCacheEnabled = new boolean[] {
121             GroupModelImpl.CACHE_ENABLED,
122             GroupModelImpl.CACHE_ENABLED_GROUPS_ORGS,
123             GroupModelImpl.CACHE_ENABLED_GROUPS_USERGROUPS,
124             UserModelImpl.CACHE_ENABLED_USERS_GROUPS,
125             UserModelImpl.CACHE_ENABLED_USERS_ORGS,
126             UserModelImpl.CACHE_ENABLED_USERS_USERGROUPS
127         };
128         String[] finderClassNames = new String[] {
129             Group.class.getName(), "Groups_Orgs", "Groups_UserGroups",
130             "Users_Groups", "Users_Orgs", "Users_UserGroups"
131         };
132         String finderMethodName = "customCountByG_U";
133         String finderParams[] = new String[] {
134             Long.class.getName(), Long.class.getName()
135         };
136         Object finderArgs[] = new Object[] {
137             new Long(groupId), new Long(userId)
138         };
139 
140         Object result = null;
141 
142         if (!ArrayUtil.contains(finderClassNamesCacheEnabled, false)) {
143             result = FinderCache.getResult(
144                 finderSQL, finderClassNames, finderMethodName, finderParams,
145                 finderArgs);
146         }
147 
148         if (result == null) {
149             Long userIdObj = new Long(userId);
150 
151             LinkedHashMap params1 = new LinkedHashMap();
152 
153             params1.put("usersGroups", userIdObj);
154 
155             LinkedHashMap params2 = new LinkedHashMap();
156 
157             params2.put("groupsOrgs", userIdObj);
158 
159             LinkedHashMap params3 = new LinkedHashMap();
160 
161             params3.put("groupsUserGroups", userIdObj);
162 
163             Session session = null;
164 
165             try {
166                 session = HibernateUtil.openSession();
167 
168                 int count = countByGroupId(session, groupId, params1);
169                 count += countByGroupId(session, groupId, params2);
170                 count += countByGroupId(session, groupId, params3);
171 
172                 FinderCache.putResult(
173                     finderSQL, finderClassNamesCacheEnabled, finderClassNames,
174                     finderMethodName, finderParams, finderArgs,
175                     new Long(count));
176 
177                 return count;
178             }
179             catch (Exception e) {
180                 throw new SystemException(e);
181             }
182             finally {
183                 HibernateUtil.closeSession(session);
184             }
185         }
186         else {
187             return ((Long)result).intValue();
188         }
189     }
190 
191     public int countByC_N_D(
192             long companyId, String name, String description,
193             LinkedHashMap params)
194         throws SystemException {
195 
196         name = StringUtil.lowerCase(name);
197         description = StringUtil.lowerCase(description);
198 
199         if (params == null) {
200             params = new LinkedHashMap();
201         }
202 
203         Long userId = (Long)params.get("usersGroups");
204 
205         LinkedHashMap params1 = params;
206 
207         LinkedHashMap params2 = new LinkedHashMap();
208 
209         params2.putAll(params1);
210 
211         if (userId != null) {
212             params2.remove("usersGroups");
213             params2.put("groupsOrgs", userId);
214         }
215 
216         LinkedHashMap params3 = new LinkedHashMap();
217 
218         params3.putAll(params1);
219 
220         if (userId != null) {
221             params3.remove("usersGroups");
222             params3.put("groupsUserGroups", userId);
223         }
224 
225         Session session = null;
226 
227         try {
228             session = HibernateUtil.openSession();
229 
230             int count = countByC_N_D(
231                 session, companyId, name, description, params1);
232 
233             if (Validator.isNotNull(userId)) {
234                 count += countByC_N_D(
235                     session, companyId, name, description, params2);
236 
237                 count += countByC_N_D(
238                     session, companyId, name, description, params3);
239             }
240 
241             return count;
242         }
243         catch (Exception e) {
244             throw new SystemException(e);
245         }
246         finally {
247             HibernateUtil.closeSession(session);
248         }
249     }
250 
251     public Group findByC_N(long companyId, String name)
252         throws NoSuchGroupException, SystemException {
253 
254         name = StringUtil.lowerCase(name);
255 
256         boolean finderClassNameCacheEnabled = GroupModelImpl.CACHE_ENABLED;
257         String finderClassName = Group.class.getName();
258         String finderMethodName = "customFindByC_N";
259         String finderParams[] = new String[] {
260             Long.class.getName(), String.class.getName()
261         };
262         Object finderArgs[] = new Object[] {new Long(companyId), name};
263 
264         Object result = FinderCache.getResult(
265             finderClassName, finderMethodName, finderParams, finderArgs);
266 
267         if (result == null) {
268             Session session = null;
269 
270             try {
271                 session = HibernateUtil.openSession();
272 
273                 String sql = CustomSQLUtil.get(FIND_BY_C_N);
274 
275                 SQLQuery q = session.createSQLQuery(sql);
276 
277                 q.addEntity("Group_", GroupImpl.class);
278 
279                 QueryPos qPos = QueryPos.getInstance(q);
280 
281                 qPos.add(companyId);
282                 qPos.add(name);
283 
284                 Iterator itr = q.list().iterator();
285 
286                 if (itr.hasNext()) {
287                     Group group = (Group)itr.next();
288 
289                     FinderCache.putResult(
290                         finderClassNameCacheEnabled, finderClassName,
291                         finderMethodName, finderParams, finderArgs, group);
292 
293                     return group;
294                 }
295             }
296             catch (Exception e) {
297                 throw new SystemException(e);
298             }
299             finally {
300                 HibernateUtil.closeSession(session);
301             }
302 
303             StringMaker sm = new StringMaker();
304 
305             sm.append("No Group exists with the key {companyId=");
306             sm.append(companyId);
307             sm.append(", name=");
308             sm.append(name);
309             sm.append("}");
310 
311             throw new NoSuchGroupException(sm.toString());
312         }
313         else {
314             return (Group)result;
315         }
316     }
317 
318     public List findByC_N_D(
319             long companyId, String name, String description,
320             LinkedHashMap params, int begin, int end, OrderByComparator obc)
321         throws SystemException {
322 
323         name = StringUtil.lowerCase(name);
324         description = StringUtil.lowerCase(description);
325 
326         if (params == null) {
327             params = new LinkedHashMap();
328         }
329 
330         Long userId = (Long)params.get("usersGroups");
331 
332         LinkedHashMap params1 = params;
333 
334         LinkedHashMap params2 = new LinkedHashMap();
335 
336         params2.putAll(params1);
337 
338         if (userId != null) {
339             params2.remove("usersGroups");
340             params2.put("groupsOrgs", userId);
341         }
342 
343         LinkedHashMap params3 = new LinkedHashMap();
344 
345         params3.putAll(params1);
346 
347         if (userId != null) {
348             params3.remove("usersGroups");
349             params3.put("groupsUserGroups", userId);
350         }
351 
352         StringMaker sm = new StringMaker();
353 
354         sm.append("(");
355 
356         sm.append(CustomSQLUtil.get(FIND_BY_C_N_D));
357 
358         String sql = sm.toString();
359 
360         sql = StringUtil.replace(sql, "[$JOIN$]", getJoin(params1));
361         sql = StringUtil.replace(sql, "[$WHERE$]", getWhere(params1));
362 
363         sm = new StringMaker();
364 
365         sm.append(sql);
366 
367         sm.append(")");
368 
369         if (Validator.isNotNull(userId)) {
370             sm.append(" UNION (");
371 
372             sm.append(CustomSQLUtil.get(FIND_BY_C_N_D));
373 
374             sql = sm.toString();
375 
376             sql = StringUtil.replace(sql, "[$JOIN$]", getJoin(params2));
377             sql = StringUtil.replace(sql, "[$WHERE$]", getWhere(params2));
378 
379             sm = new StringMaker();
380 
381             sm.append(sql);
382 
383             sm.append(") UNION (");
384 
385             sm.append(CustomSQLUtil.get(FIND_BY_C_N_D));
386 
387             sql = sm.toString();
388 
389             sql = StringUtil.replace(sql, "[$JOIN$]", getJoin(params3));
390             sql = StringUtil.replace(sql, "[$WHERE$]", getWhere(params3));
391 
392             sm = new StringMaker();
393 
394             sm.append(sql);
395 
396             sm.append(")");
397         }
398 
399         sql = sm.toString();
400         sql = CustomSQLUtil.replaceOrderBy(sql, obc);
401 
402         String finderSQL = sql;
403         boolean[] finderClassNamesCacheEnabled = new boolean[] {
404             GroupModelImpl.CACHE_ENABLED, LayoutSetModelImpl.CACHE_ENABLED,
405             PermissionModelImpl.CACHE_ENABLED, ResourceModelImpl.CACHE_ENABLED,
406             ResourceCodeModelImpl.CACHE_ENABLED,
407             UserGroupRoleModelImpl.CACHE_ENABLED,
408             GroupModelImpl.CACHE_ENABLED_GROUPS_ORGS,
409             GroupModelImpl.CACHE_ENABLED_GROUPS_ROLES,
410             GroupModelImpl.CACHE_ENABLED_GROUPS_USERGROUPS,
411             RoleModelImpl.CACHE_ENABLED_ROLES_PERMISSIONS,
412             UserModelImpl.CACHE_ENABLED_USERS_GROUPS,
413             UserModelImpl.CACHE_ENABLED_USERS_ORGS,
414             UserModelImpl.CACHE_ENABLED_USERS_USERGROUPS
415         };
416         String[] finderClassNames = new String[] {
417             Group.class.getName(), LayoutSet.class.getName(),
418             Permission.class.getName(), Resource.class.getName(),
419             ResourceCode.class.getName(), UserGroupRole.class.getName(),
420             "Groups_Orgs", "Groups_Roles", "Groups_UserGroups",
421             "Roles_Permissions", "Users_Groups", "Users_Orgs",
422             "Users_UserGroups"
423         };
424         String finderMethodName = "customFindByC_N_D";
425         String finderParams[] = new String[] {
426             Long.class.getName(), String.class.getName(),
427             String.class.getName(), LinkedHashMap.class.getName(),
428             String.class.getName(), String.class.getName()
429         };
430         Object finderArgs[] = new Object[] {
431             new Long(companyId), name, description, params.toString(),
432             String.valueOf(begin), String.valueOf(end)
433         };
434 
435         Object result = null;
436 
437         if (!ArrayUtil.contains(finderClassNamesCacheEnabled, false)) {
438             result = FinderCache.getResult(
439                 finderSQL, finderClassNames, finderMethodName, finderParams,
440                 finderArgs);
441         }
442 
443         if (result == null) {
444             Session session = null;
445 
446             try {
447                 session = HibernateUtil.openSession();
448 
449                 SQLQuery q = session.createSQLQuery(sql);
450 
451                 q.addScalar("groupId", Hibernate.STRING);
452 
453                 QueryPos qPos = QueryPos.getInstance(q);
454 
455                 setJoin(qPos, params1);
456                 qPos.add(companyId);
457                 qPos.add(name);
458                 qPos.add(name);
459                 qPos.add(description);
460                 qPos.add(description);
461 
462                 if (Validator.isNotNull(userId)) {
463                     setJoin(qPos, params2);
464                     qPos.add(companyId);
465                     qPos.add(name);
466                     qPos.add(name);
467                     qPos.add(description);
468                     qPos.add(description);
469 
470                     setJoin(qPos, params3);
471                     qPos.add(companyId);
472                     qPos.add(name);
473                     qPos.add(name);
474                     qPos.add(description);
475                     qPos.add(description);
476                 }
477 
478                 List list = new ArrayList();
479 
480                 Iterator itr = QueryUtil.iterate(
481                     q, HibernateUtil.getDialect(), begin, end);
482 
483                 while (itr.hasNext()) {
484                     long groupId = GetterUtil.getLong((String)itr.next());
485 
486                     Group group = GroupUtil.findByPrimaryKey(groupId);
487 
488                     list.add(group);
489                 }
490 
491                 FinderCache.putResult(
492                     finderSQL, finderClassNamesCacheEnabled, finderClassNames,
493                     finderMethodName, finderParams, finderArgs, list);
494 
495                 return list;
496             }
497             catch (Exception e) {
498                 throw new SystemException(e);
499             }
500             finally {
501                 HibernateUtil.closeSession(session);
502             }
503         }
504         else {
505             return (List)result;
506         }
507     }
508 
509     protected int countByGroupId(
510             Session session, long groupId, LinkedHashMap params)
511         throws SystemException {
512 
513         String sql = CustomSQLUtil.get(COUNT_BY_GROUP_ID);
514 
515         sql = StringUtil.replace(sql, "[$JOIN$]", getJoin(params));
516         sql = StringUtil.replace(sql, "[$WHERE$]", getWhere(params));
517 
518         SQLQuery q = session.createSQLQuery(sql);
519 
520         q.addScalar(HibernateUtil.getCountColumnName(), Hibernate.LONG);
521 
522         QueryPos qPos = QueryPos.getInstance(q);
523 
524         setJoin(qPos, params);
525         qPos.add(groupId);
526 
527         Iterator itr = q.list().iterator();
528 
529         if (itr.hasNext()) {
530             Long count = (Long)itr.next();
531 
532             if (count != null) {
533                 return count.intValue();
534             }
535         }
536 
537         return 0;
538     }
539 
540     protected int countByC_N_D(
541             Session session, long companyId, String name, String description,
542             LinkedHashMap params)
543         throws SystemException {
544 
545         String sql = CustomSQLUtil.get(COUNT_BY_C_N_D);
546 
547         sql = StringUtil.replace(sql, "[$JOIN$]", getJoin(params));
548         sql = StringUtil.replace(sql, "[$WHERE$]", getWhere(params));
549 
550         SQLQuery q = session.createSQLQuery(sql);
551 
552         q.addScalar(HibernateUtil.getCountColumnName(), Hibernate.LONG);
553 
554         QueryPos qPos = QueryPos.getInstance(q);
555 
556         setJoin(qPos, params);
557         qPos.add(companyId);
558         qPos.add(name);
559         qPos.add(name);
560         qPos.add(description);
561         qPos.add(description);
562 
563         Iterator itr = q.list().iterator();
564 
565         if (itr.hasNext()) {
566             Long count = (Long)itr.next();
567 
568             if (count != null) {
569                 return count.intValue();
570             }
571         }
572 
573         return 0;
574     }
575 
576     protected String getJoin(LinkedHashMap params) {
577         if (params == null) {
578             return StringPool.BLANK;
579         }
580 
581         StringMaker sm = new StringMaker();
582 
583         Iterator itr = params.entrySet().iterator();
584 
585         while (itr.hasNext()) {
586             Map.Entry entry = (Map.Entry)itr.next();
587 
588             String key = (String)entry.getKey();
589             Object value = entry.getValue();
590 
591             if (Validator.isNotNull(value)) {
592                 sm.append(getJoin(key));
593             }
594         }
595 
596         return sm.toString();
597     }
598 
599     protected String getJoin(String key) {
600         String join = StringPool.BLANK;
601 
602         if (key.equals("groupsOrgs")) {
603             join = CustomSQLUtil.get(JOIN_BY_GROUPS_ORGS);
604         }
605         else if (key.equals("groupsRoles")) {
606             join = CustomSQLUtil.get(JOIN_BY_GROUPS_ROLES);
607         }
608         else if (key.equals("groupsUserGroups")) {
609             join = CustomSQLUtil.get(JOIN_BY_GROUPS_USER_GROUPS);
610         }
611         else if (key.equals("layoutSet")) {
612             join = CustomSQLUtil.get(JOIN_BY_LAYOUT_SET);
613         }
614         else if (key.equals("pageCount")) {
615             join = CustomSQLUtil.get(JOIN_BY_PAGE_COUNT);
616         }
617         else if (key.equals("rolePermissions")) {
618             join = CustomSQLUtil.get(JOIN_BY_ROLE_PERMISSIONS);
619         }
620         else if (key.equals("userGroupRole")) {
621             join = CustomSQLUtil.get(JOIN_BY_USER_GROUP_ROLE);
622         }
623         else if (key.equals("usersGroups")) {
624             join = CustomSQLUtil.get(JOIN_BY_USERS_GROUPS);
625         }
626 
627         if (Validator.isNotNull(join)) {
628             int pos = join.indexOf("WHERE");
629 
630             if (pos != -1) {
631                 join = join.substring(0, pos);
632             }
633         }
634 
635         return join;
636     }
637 
638     protected String getWhere(LinkedHashMap params) {
639         if (params == null) {
640             return StringPool.BLANK;
641         }
642 
643         StringMaker sm = new StringMaker();
644 
645         Iterator itr = params.entrySet().iterator();
646 
647         while (itr.hasNext()) {
648             Map.Entry entry = (Map.Entry)itr.next();
649 
650             String key = (String)entry.getKey();
651             Object value = entry.getValue();
652 
653             if (Validator.isNotNull(value)) {
654                 sm.append(getWhere(key, value));
655             }
656         }
657 
658         return sm.toString();
659     }
660 
661     protected String getWhere(String key, Object value) {
662         String join = StringPool.BLANK;
663 
664         if (key.equals("active")) {
665             join = CustomSQLUtil.get(JOIN_BY_ACTIVE);
666         }
667         else if (key.equals("creatorUserId")) {
668             join = CustomSQLUtil.get(JOIN_BY_CREATOR_USER_ID);
669         }
670         else if (key.equals("groupsOrgs")) {
671             join = CustomSQLUtil.get(JOIN_BY_GROUPS_ORGS);
672         }
673         else if (key.equals("groupsRoles")) {
674             join = CustomSQLUtil.get(JOIN_BY_GROUPS_ROLES);
675         }
676         else if (key.equals("groupsUserGroups")) {
677             join = CustomSQLUtil.get(JOIN_BY_GROUPS_USER_GROUPS);
678         }
679         else if (key.equals("layoutSet")) {
680             join = CustomSQLUtil.get(JOIN_BY_LAYOUT_SET);
681         }
682         else if (key.equals("pageCount")) {
683             join = CustomSQLUtil.get(JOIN_BY_PAGE_COUNT);
684         }
685         else if (key.equals("rolePermissions")) {
686             join = CustomSQLUtil.get(JOIN_BY_ROLE_PERMISSIONS);
687         }
688         else if (key.equals("type")) {
689             join = CustomSQLUtil.get(JOIN_BY_TYPE);
690         }
691         else if (key.equals("types")) {
692             List types = (List)value;
693 
694             StringMaker sm = new StringMaker();
695 
696             sm.append("WHERE (");
697 
698             for (int i = 0; i < types.size(); i++) {
699                 sm.append("(Group_.type_ = ?) ");
700 
701                 if ((i + 1) < types.size()) {
702                     sm.append("OR ");
703                 }
704             }
705 
706             sm.append(")");
707 
708             join = sm.toString();
709         }
710         else if (key.equals("userGroupRole")) {
711             join = CustomSQLUtil.get(JOIN_BY_USER_GROUP_ROLE);
712         }
713         else if (key.equals("usersGroups")) {
714             join = CustomSQLUtil.get(JOIN_BY_USERS_GROUPS);
715         }
716 
717         if (Validator.isNotNull(join)) {
718             int pos = join.indexOf("WHERE");
719 
720             if (pos != -1) {
721                 StringMaker sm = new StringMaker();
722 
723                 sm.append(join.substring(pos + 5, join.length()));
724                 sm.append(" AND ");
725 
726                 join = sm.toString();
727             }
728         }
729 
730         return join;
731     }
732 
733     protected void setJoin(QueryPos qPos, LinkedHashMap params) {
734         if (params != null) {
735             Iterator itr = params.entrySet().iterator();
736 
737             while (itr.hasNext()) {
738                 Map.Entry entry = (Map.Entry)itr.next();
739 
740                 String key = (String)entry.getKey();
741 
742                 if (key.equals("active") || key.equals("layoutSet")) {
743                     Boolean value = (Boolean)entry.getValue();
744 
745                     qPos.add(value);
746                 }
747                 else if (key.equals("pageCount")) {
748                 }
749                 else if (key.equals("rolePermissions")) {
750                     List values = (List)entry.getValue();
751 
752                     for (int i = 0; i < values.size(); i++) {
753                         Object value = values.get(i);
754 
755                         if (value instanceof Integer) {
756                             Integer valueInteger = (Integer)value;
757 
758                             qPos.add(valueInteger);
759                         }
760                         else if (value instanceof Long) {
761                             Long valueLong = (Long)value;
762 
763                             qPos.add(valueLong);
764                         }
765                         else if (value instanceof String) {
766                             String valueString = (String)value;
767 
768                             qPos.add(valueString);
769                         }
770                     }
771                 }
772                 else if (key.equals("types")) {
773                     List values = (List)entry.getValue();
774 
775                     for (int i = 0; i < values.size(); i++) {
776                         Integer value = (Integer)values.get(i);
777 
778                         qPos.add(value);
779                     }
780                 }
781                 else if (key.equals("userGroupRole")) {
782                     List values = (List)entry.getValue();
783 
784                     Long userId = (Long)values.get(0);
785                     Long roleId = (Long)values.get(1);
786 
787                     qPos.add(userId);
788                     qPos.add(roleId);
789                 }
790                 else {
791                     Object value = entry.getValue();
792 
793                     if (value instanceof Long) {
794                         Long valueLong = (Long)value;
795 
796                         if (Validator.isNotNull(valueLong)) {
797                             qPos.add(valueLong);
798                         }
799                     }
800                     else if (value instanceof String) {
801                         String valueString = (String)value;
802 
803                         if (Validator.isNotNull(valueString)) {
804                             qPos.add(valueString);
805                         }
806                     }
807                 }
808             }
809         }
810     }
811 
812 }