1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights 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.NoSuchRoleException;
26  import com.liferay.portal.SystemException;
27  import com.liferay.portal.kernel.annotation.BeanReference;
28  import com.liferay.portal.kernel.cache.CacheRegistry;
29  import com.liferay.portal.kernel.dao.jdbc.MappingSqlQuery;
30  import com.liferay.portal.kernel.dao.jdbc.MappingSqlQueryFactoryUtil;
31  import com.liferay.portal.kernel.dao.jdbc.RowMapper;
32  import com.liferay.portal.kernel.dao.jdbc.SqlUpdate;
33  import com.liferay.portal.kernel.dao.jdbc.SqlUpdateFactoryUtil;
34  import com.liferay.portal.kernel.dao.orm.DynamicQuery;
35  import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
36  import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
37  import com.liferay.portal.kernel.dao.orm.FinderPath;
38  import com.liferay.portal.kernel.dao.orm.Query;
39  import com.liferay.portal.kernel.dao.orm.QueryPos;
40  import com.liferay.portal.kernel.dao.orm.QueryUtil;
41  import com.liferay.portal.kernel.dao.orm.SQLQuery;
42  import com.liferay.portal.kernel.dao.orm.Session;
43  import com.liferay.portal.kernel.dao.orm.Type;
44  import com.liferay.portal.kernel.log.Log;
45  import com.liferay.portal.kernel.log.LogFactoryUtil;
46  import com.liferay.portal.kernel.util.GetterUtil;
47  import com.liferay.portal.kernel.util.OrderByComparator;
48  import com.liferay.portal.kernel.util.SetUtil;
49  import com.liferay.portal.kernel.util.StringPool;
50  import com.liferay.portal.kernel.util.StringUtil;
51  import com.liferay.portal.kernel.util.Validator;
52  import com.liferay.portal.model.ModelListener;
53  import com.liferay.portal.model.Role;
54  import com.liferay.portal.model.impl.RoleImpl;
55  import com.liferay.portal.model.impl.RoleModelImpl;
56  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
57  
58  import java.sql.Types;
59  
60  import java.util.ArrayList;
61  import java.util.Collections;
62  import java.util.List;
63  import java.util.Set;
64  
65  /**
66   * <a href="RolePersistenceImpl.java.html"><b><i>View Source</i></b></a>
67   *
68   * <p>
69   * ServiceBuilder generated this class. Modifications in this class will be
70   * overwritten the next time is generated.
71   * </p>
72   *
73   * @author    Brian Wing Shun Chan
74   * @see       RolePersistence
75   * @see       RoleUtil
76   * @generated
77   */
78  public class RolePersistenceImpl extends BasePersistenceImpl
79      implements RolePersistence {
80      public static final String FINDER_CLASS_NAME_ENTITY = RoleImpl.class.getName();
81      public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
82          ".List";
83      public static final FinderPath FINDER_PATH_FIND_BY_COMPANYID = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
84              RoleModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
85              "findByCompanyId", new String[] { Long.class.getName() });
86      public static final FinderPath FINDER_PATH_FIND_BY_OBC_COMPANYID = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
87              RoleModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
88              "findByCompanyId",
89              new String[] {
90                  Long.class.getName(),
91                  
92              "java.lang.Integer", "java.lang.Integer",
93                  "com.liferay.portal.kernel.util.OrderByComparator"
94              });
95      public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
96              RoleModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
97              "countByCompanyId", new String[] { Long.class.getName() });
98      public static final FinderPath FINDER_PATH_FIND_BY_SUBTYPE = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
99              RoleModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
100             "findBySubtype", new String[] { String.class.getName() });
101     public static final FinderPath FINDER_PATH_FIND_BY_OBC_SUBTYPE = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
102             RoleModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
103             "findBySubtype",
104             new String[] {
105                 String.class.getName(),
106                 
107             "java.lang.Integer", "java.lang.Integer",
108                 "com.liferay.portal.kernel.util.OrderByComparator"
109             });
110     public static final FinderPath FINDER_PATH_COUNT_BY_SUBTYPE = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
111             RoleModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
112             "countBySubtype", new String[] { String.class.getName() });
113     public static final FinderPath FINDER_PATH_FETCH_BY_C_N = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
114             RoleModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
115             "fetchByC_N",
116             new String[] { Long.class.getName(), String.class.getName() });
117     public static final FinderPath FINDER_PATH_COUNT_BY_C_N = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
118             RoleModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
119             "countByC_N",
120             new String[] { Long.class.getName(), String.class.getName() });
121     public static final FinderPath FINDER_PATH_FIND_BY_T_S = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
122             RoleModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
123             "findByT_S",
124             new String[] { Integer.class.getName(), String.class.getName() });
125     public static final FinderPath FINDER_PATH_FIND_BY_OBC_T_S = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
126             RoleModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
127             "findByT_S",
128             new String[] {
129                 Integer.class.getName(), String.class.getName(),
130                 
131             "java.lang.Integer", "java.lang.Integer",
132                 "com.liferay.portal.kernel.util.OrderByComparator"
133             });
134     public static final FinderPath FINDER_PATH_COUNT_BY_T_S = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
135             RoleModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
136             "countByT_S",
137             new String[] { Integer.class.getName(), String.class.getName() });
138     public static final FinderPath FINDER_PATH_FETCH_BY_C_C_C = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
139             RoleModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
140             "fetchByC_C_C",
141             new String[] {
142                 Long.class.getName(), Long.class.getName(), Long.class.getName()
143             });
144     public static final FinderPath FINDER_PATH_COUNT_BY_C_C_C = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
145             RoleModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
146             "countByC_C_C",
147             new String[] {
148                 Long.class.getName(), Long.class.getName(), Long.class.getName()
149             });
150     public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
151             RoleModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
152             "findAll", new String[0]);
153     public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
154             RoleModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
155             "countAll", new String[0]);
156 
157     public void cacheResult(Role role) {
158         EntityCacheUtil.putResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
159             RoleImpl.class, role.getPrimaryKey(), role);
160 
161         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
162             new Object[] { new Long(role.getCompanyId()), role.getName() }, role);
163 
164         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_C,
165             new Object[] {
166                 new Long(role.getCompanyId()), new Long(role.getClassNameId()),
167                 new Long(role.getClassPK())
168             }, role);
169     }
170 
171     public void cacheResult(List<Role> roles) {
172         for (Role role : roles) {
173             if (EntityCacheUtil.getResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
174                         RoleImpl.class, role.getPrimaryKey(), this) == null) {
175                 cacheResult(role);
176             }
177         }
178     }
179 
180     public void clearCache() {
181         CacheRegistry.clear(RoleImpl.class.getName());
182         EntityCacheUtil.clearCache(RoleImpl.class.getName());
183         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
184         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
185     }
186 
187     public Role create(long roleId) {
188         Role role = new RoleImpl();
189 
190         role.setNew(true);
191         role.setPrimaryKey(roleId);
192 
193         return role;
194     }
195 
196     public Role remove(long roleId) throws NoSuchRoleException, SystemException {
197         Session session = null;
198 
199         try {
200             session = openSession();
201 
202             Role role = (Role)session.get(RoleImpl.class, new Long(roleId));
203 
204             if (role == null) {
205                 if (_log.isWarnEnabled()) {
206                     _log.warn("No Role exists with the primary key " + roleId);
207                 }
208 
209                 throw new NoSuchRoleException(
210                     "No Role exists with the primary key " + roleId);
211             }
212 
213             return remove(role);
214         }
215         catch (NoSuchRoleException nsee) {
216             throw nsee;
217         }
218         catch (Exception e) {
219             throw processException(e);
220         }
221         finally {
222             closeSession(session);
223         }
224     }
225 
226     public Role remove(Role role) throws SystemException {
227         for (ModelListener<Role> listener : listeners) {
228             listener.onBeforeRemove(role);
229         }
230 
231         role = removeImpl(role);
232 
233         for (ModelListener<Role> listener : listeners) {
234             listener.onAfterRemove(role);
235         }
236 
237         return role;
238     }
239 
240     protected Role removeImpl(Role role) throws SystemException {
241         role = toUnwrappedModel(role);
242 
243         try {
244             clearGroups.clear(role.getPrimaryKey());
245         }
246         catch (Exception e) {
247             throw processException(e);
248         }
249         finally {
250             FinderCacheUtil.clearCache("Groups_Roles");
251         }
252 
253         try {
254             clearPermissions.clear(role.getPrimaryKey());
255         }
256         catch (Exception e) {
257             throw processException(e);
258         }
259         finally {
260             FinderCacheUtil.clearCache("Roles_Permissions");
261         }
262 
263         try {
264             clearUsers.clear(role.getPrimaryKey());
265         }
266         catch (Exception e) {
267             throw processException(e);
268         }
269         finally {
270             FinderCacheUtil.clearCache("Users_Roles");
271         }
272 
273         Session session = null;
274 
275         try {
276             session = openSession();
277 
278             if (role.isCachedModel() || BatchSessionUtil.isEnabled()) {
279                 Object staleObject = session.get(RoleImpl.class,
280                         role.getPrimaryKeyObj());
281 
282                 if (staleObject != null) {
283                     session.evict(staleObject);
284                 }
285             }
286 
287             session.delete(role);
288 
289             session.flush();
290         }
291         catch (Exception e) {
292             throw processException(e);
293         }
294         finally {
295             closeSession(session);
296         }
297 
298         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
299 
300         RoleModelImpl roleModelImpl = (RoleModelImpl)role;
301 
302         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N,
303             new Object[] {
304                 new Long(roleModelImpl.getOriginalCompanyId()),
305                 
306             roleModelImpl.getOriginalName()
307             });
308 
309         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C_C,
310             new Object[] {
311                 new Long(roleModelImpl.getOriginalCompanyId()),
312                 new Long(roleModelImpl.getOriginalClassNameId()),
313                 new Long(roleModelImpl.getOriginalClassPK())
314             });
315 
316         EntityCacheUtil.removeResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
317             RoleImpl.class, role.getPrimaryKey());
318 
319         return role;
320     }
321 
322     /**
323      * @deprecated Use {@link #update(Role, boolean merge)}.
324      */
325     public Role update(Role role) throws SystemException {
326         if (_log.isWarnEnabled()) {
327             _log.warn(
328                 "Using the deprecated update(Role role) method. Use update(Role role, boolean merge) instead.");
329         }
330 
331         return update(role, false);
332     }
333 
334     /**
335      * Add, update, or merge, the entity. This method also calls the model
336      * listeners to trigger the proper events associated with adding, deleting,
337      * or updating an entity.
338      *
339      * @param  role the entity to add, update, or merge
340      * @param  merge boolean value for whether to merge the entity. The default
341      *         value is false. Setting merge to true is more expensive and
342      *         should only be true when role is transient. See
343      *         LEP-5473 for a detailed discussion of this method.
344      * @return the entity that was added, updated, or merged
345      */
346     public Role update(Role role, boolean merge) throws SystemException {
347         boolean isNew = role.isNew();
348 
349         for (ModelListener<Role> listener : listeners) {
350             if (isNew) {
351                 listener.onBeforeCreate(role);
352             }
353             else {
354                 listener.onBeforeUpdate(role);
355             }
356         }
357 
358         role = updateImpl(role, merge);
359 
360         for (ModelListener<Role> listener : listeners) {
361             if (isNew) {
362                 listener.onAfterCreate(role);
363             }
364             else {
365                 listener.onAfterUpdate(role);
366             }
367         }
368 
369         return role;
370     }
371 
372     public Role updateImpl(com.liferay.portal.model.Role role, boolean merge)
373         throws SystemException {
374         role = toUnwrappedModel(role);
375 
376         boolean isNew = role.isNew();
377 
378         RoleModelImpl roleModelImpl = (RoleModelImpl)role;
379 
380         Session session = null;
381 
382         try {
383             session = openSession();
384 
385             BatchSessionUtil.update(session, role, merge);
386 
387             role.setNew(false);
388         }
389         catch (Exception e) {
390             throw processException(e);
391         }
392         finally {
393             closeSession(session);
394         }
395 
396         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
397 
398         EntityCacheUtil.putResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
399             RoleImpl.class, role.getPrimaryKey(), role);
400 
401         if (!isNew &&
402                 ((role.getCompanyId() != roleModelImpl.getOriginalCompanyId()) ||
403                 !Validator.equals(role.getName(),
404                     roleModelImpl.getOriginalName()))) {
405             FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N,
406                 new Object[] {
407                     new Long(roleModelImpl.getOriginalCompanyId()),
408                     
409                 roleModelImpl.getOriginalName()
410                 });
411         }
412 
413         if (isNew ||
414                 ((role.getCompanyId() != roleModelImpl.getOriginalCompanyId()) ||
415                 !Validator.equals(role.getName(),
416                     roleModelImpl.getOriginalName()))) {
417             FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
418                 new Object[] { new Long(role.getCompanyId()), role.getName() },
419                 role);
420         }
421 
422         if (!isNew &&
423                 ((role.getCompanyId() != roleModelImpl.getOriginalCompanyId()) ||
424                 (role.getClassNameId() != roleModelImpl.getOriginalClassNameId()) ||
425                 (role.getClassPK() != roleModelImpl.getOriginalClassPK()))) {
426             FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C_C,
427                 new Object[] {
428                     new Long(roleModelImpl.getOriginalCompanyId()),
429                     new Long(roleModelImpl.getOriginalClassNameId()),
430                     new Long(roleModelImpl.getOriginalClassPK())
431                 });
432         }
433 
434         if (isNew ||
435                 ((role.getCompanyId() != roleModelImpl.getOriginalCompanyId()) ||
436                 (role.getClassNameId() != roleModelImpl.getOriginalClassNameId()) ||
437                 (role.getClassPK() != roleModelImpl.getOriginalClassPK()))) {
438             FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_C,
439                 new Object[] {
440                     new Long(role.getCompanyId()),
441                     new Long(role.getClassNameId()), new Long(role.getClassPK())
442                 }, role);
443         }
444 
445         return role;
446     }
447 
448     protected Role toUnwrappedModel(Role role) {
449         if (role instanceof RoleImpl) {
450             return role;
451         }
452 
453         RoleImpl roleImpl = new RoleImpl();
454 
455         roleImpl.setNew(role.isNew());
456         roleImpl.setPrimaryKey(role.getPrimaryKey());
457 
458         roleImpl.setRoleId(role.getRoleId());
459         roleImpl.setCompanyId(role.getCompanyId());
460         roleImpl.setClassNameId(role.getClassNameId());
461         roleImpl.setClassPK(role.getClassPK());
462         roleImpl.setName(role.getName());
463         roleImpl.setTitle(role.getTitle());
464         roleImpl.setDescription(role.getDescription());
465         roleImpl.setType(role.getType());
466         roleImpl.setSubtype(role.getSubtype());
467 
468         return roleImpl;
469     }
470 
471     public Role findByPrimaryKey(long roleId)
472         throws NoSuchRoleException, SystemException {
473         Role role = fetchByPrimaryKey(roleId);
474 
475         if (role == null) {
476             if (_log.isWarnEnabled()) {
477                 _log.warn("No Role exists with the primary key " + roleId);
478             }
479 
480             throw new NoSuchRoleException(
481                 "No Role exists with the primary key " + roleId);
482         }
483 
484         return role;
485     }
486 
487     public Role fetchByPrimaryKey(long roleId) throws SystemException {
488         Role role = (Role)EntityCacheUtil.getResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
489                 RoleImpl.class, roleId, this);
490 
491         if (role == null) {
492             Session session = null;
493 
494             try {
495                 session = openSession();
496 
497                 role = (Role)session.get(RoleImpl.class, new Long(roleId));
498             }
499             catch (Exception e) {
500                 throw processException(e);
501             }
502             finally {
503                 if (role != null) {
504                     cacheResult(role);
505                 }
506 
507                 closeSession(session);
508             }
509         }
510 
511         return role;
512     }
513 
514     public List<Role> findByCompanyId(long companyId) throws SystemException {
515         Object[] finderArgs = new Object[] { new Long(companyId) };
516 
517         List<Role> list = (List<Role>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_COMPANYID,
518                 finderArgs, this);
519 
520         if (list == null) {
521             Session session = null;
522 
523             try {
524                 session = openSession();
525 
526                 StringBuilder query = new StringBuilder();
527 
528                 query.append("SELECT role FROM Role role WHERE ");
529 
530                 query.append("role.companyId = ?");
531 
532                 query.append(" ");
533 
534                 query.append("ORDER BY ");
535 
536                 query.append("role.name ASC");
537 
538                 Query q = session.createQuery(query.toString());
539 
540                 QueryPos qPos = QueryPos.getInstance(q);
541 
542                 qPos.add(companyId);
543 
544                 list = q.list();
545             }
546             catch (Exception e) {
547                 throw processException(e);
548             }
549             finally {
550                 if (list == null) {
551                     list = new ArrayList<Role>();
552                 }
553 
554                 cacheResult(list);
555 
556                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_COMPANYID,
557                     finderArgs, list);
558 
559                 closeSession(session);
560             }
561         }
562 
563         return list;
564     }
565 
566     public List<Role> findByCompanyId(long companyId, int start, int end)
567         throws SystemException {
568         return findByCompanyId(companyId, start, end, null);
569     }
570 
571     public List<Role> findByCompanyId(long companyId, int start, int end,
572         OrderByComparator obc) throws SystemException {
573         Object[] finderArgs = new Object[] {
574                 new Long(companyId),
575                 
576                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
577             };
578 
579         List<Role> list = (List<Role>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_COMPANYID,
580                 finderArgs, this);
581 
582         if (list == null) {
583             Session session = null;
584 
585             try {
586                 session = openSession();
587 
588                 StringBuilder query = new StringBuilder();
589 
590                 query.append("SELECT role FROM Role role WHERE ");
591 
592                 query.append("role.companyId = ?");
593 
594                 query.append(" ");
595 
596                 if (obc != null) {
597                     query.append("ORDER BY ");
598 
599                     String[] orderByFields = obc.getOrderByFields();
600 
601                     for (int i = 0; i < orderByFields.length; i++) {
602                         query.append("role.");
603                         query.append(orderByFields[i]);
604 
605                         if (obc.isAscending()) {
606                             query.append(" ASC");
607                         }
608                         else {
609                             query.append(" DESC");
610                         }
611 
612                         if ((i + 1) < orderByFields.length) {
613                             query.append(", ");
614                         }
615                     }
616                 }
617 
618                 else {
619                     query.append("ORDER BY ");
620 
621                     query.append("role.name ASC");
622                 }
623 
624                 Query q = session.createQuery(query.toString());
625 
626                 QueryPos qPos = QueryPos.getInstance(q);
627 
628                 qPos.add(companyId);
629 
630                 list = (List<Role>)QueryUtil.list(q, getDialect(), start, end);
631             }
632             catch (Exception e) {
633                 throw processException(e);
634             }
635             finally {
636                 if (list == null) {
637                     list = new ArrayList<Role>();
638                 }
639 
640                 cacheResult(list);
641 
642                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_COMPANYID,
643                     finderArgs, list);
644 
645                 closeSession(session);
646             }
647         }
648 
649         return list;
650     }
651 
652     public Role findByCompanyId_First(long companyId, OrderByComparator obc)
653         throws NoSuchRoleException, SystemException {
654         List<Role> list = findByCompanyId(companyId, 0, 1, obc);
655 
656         if (list.isEmpty()) {
657             StringBuilder msg = new StringBuilder();
658 
659             msg.append("No Role exists with the key {");
660 
661             msg.append("companyId=" + companyId);
662 
663             msg.append(StringPool.CLOSE_CURLY_BRACE);
664 
665             throw new NoSuchRoleException(msg.toString());
666         }
667         else {
668             return list.get(0);
669         }
670     }
671 
672     public Role findByCompanyId_Last(long companyId, OrderByComparator obc)
673         throws NoSuchRoleException, SystemException {
674         int count = countByCompanyId(companyId);
675 
676         List<Role> list = findByCompanyId(companyId, count - 1, count, obc);
677 
678         if (list.isEmpty()) {
679             StringBuilder msg = new StringBuilder();
680 
681             msg.append("No Role exists with the key {");
682 
683             msg.append("companyId=" + companyId);
684 
685             msg.append(StringPool.CLOSE_CURLY_BRACE);
686 
687             throw new NoSuchRoleException(msg.toString());
688         }
689         else {
690             return list.get(0);
691         }
692     }
693 
694     public Role[] findByCompanyId_PrevAndNext(long roleId, long companyId,
695         OrderByComparator obc) throws NoSuchRoleException, SystemException {
696         Role role = findByPrimaryKey(roleId);
697 
698         int count = countByCompanyId(companyId);
699 
700         Session session = null;
701 
702         try {
703             session = openSession();
704 
705             StringBuilder query = new StringBuilder();
706 
707             query.append("SELECT role FROM Role role WHERE ");
708 
709             query.append("role.companyId = ?");
710 
711             query.append(" ");
712 
713             if (obc != null) {
714                 query.append("ORDER BY ");
715 
716                 String[] orderByFields = obc.getOrderByFields();
717 
718                 for (int i = 0; i < orderByFields.length; i++) {
719                     query.append("role.");
720                     query.append(orderByFields[i]);
721 
722                     if (obc.isAscending()) {
723                         query.append(" ASC");
724                     }
725                     else {
726                         query.append(" DESC");
727                     }
728 
729                     if ((i + 1) < orderByFields.length) {
730                         query.append(", ");
731                     }
732                 }
733             }
734 
735             else {
736                 query.append("ORDER BY ");
737 
738                 query.append("role.name ASC");
739             }
740 
741             Query q = session.createQuery(query.toString());
742 
743             QueryPos qPos = QueryPos.getInstance(q);
744 
745             qPos.add(companyId);
746 
747             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, role);
748 
749             Role[] array = new RoleImpl[3];
750 
751             array[0] = (Role)objArray[0];
752             array[1] = (Role)objArray[1];
753             array[2] = (Role)objArray[2];
754 
755             return array;
756         }
757         catch (Exception e) {
758             throw processException(e);
759         }
760         finally {
761             closeSession(session);
762         }
763     }
764 
765     public List<Role> findBySubtype(String subtype) throws SystemException {
766         Object[] finderArgs = new Object[] { subtype };
767 
768         List<Role> list = (List<Role>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_SUBTYPE,
769                 finderArgs, this);
770 
771         if (list == null) {
772             Session session = null;
773 
774             try {
775                 session = openSession();
776 
777                 StringBuilder query = new StringBuilder();
778 
779                 query.append("SELECT role FROM Role role WHERE ");
780 
781                 if (subtype == null) {
782                     query.append("role.subtype IS NULL");
783                 }
784                 else {
785                     query.append("role.subtype = ?");
786                 }
787 
788                 query.append(" ");
789 
790                 query.append("ORDER BY ");
791 
792                 query.append("role.name ASC");
793 
794                 Query q = session.createQuery(query.toString());
795 
796                 QueryPos qPos = QueryPos.getInstance(q);
797 
798                 if (subtype != null) {
799                     qPos.add(subtype);
800                 }
801 
802                 list = q.list();
803             }
804             catch (Exception e) {
805                 throw processException(e);
806             }
807             finally {
808                 if (list == null) {
809                     list = new ArrayList<Role>();
810                 }
811 
812                 cacheResult(list);
813 
814                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_SUBTYPE,
815                     finderArgs, list);
816 
817                 closeSession(session);
818             }
819         }
820 
821         return list;
822     }
823 
824     public List<Role> findBySubtype(String subtype, int start, int end)
825         throws SystemException {
826         return findBySubtype(subtype, start, end, null);
827     }
828 
829     public List<Role> findBySubtype(String subtype, int start, int end,
830         OrderByComparator obc) throws SystemException {
831         Object[] finderArgs = new Object[] {
832                 subtype,
833                 
834                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
835             };
836 
837         List<Role> list = (List<Role>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_SUBTYPE,
838                 finderArgs, this);
839 
840         if (list == null) {
841             Session session = null;
842 
843             try {
844                 session = openSession();
845 
846                 StringBuilder query = new StringBuilder();
847 
848                 query.append("SELECT role FROM Role role WHERE ");
849 
850                 if (subtype == null) {
851                     query.append("role.subtype IS NULL");
852                 }
853                 else {
854                     query.append("role.subtype = ?");
855                 }
856 
857                 query.append(" ");
858 
859                 if (obc != null) {
860                     query.append("ORDER BY ");
861 
862                     String[] orderByFields = obc.getOrderByFields();
863 
864                     for (int i = 0; i < orderByFields.length; i++) {
865                         query.append("role.");
866                         query.append(orderByFields[i]);
867 
868                         if (obc.isAscending()) {
869                             query.append(" ASC");
870                         }
871                         else {
872                             query.append(" DESC");
873                         }
874 
875                         if ((i + 1) < orderByFields.length) {
876                             query.append(", ");
877                         }
878                     }
879                 }
880 
881                 else {
882                     query.append("ORDER BY ");
883 
884                     query.append("role.name ASC");
885                 }
886 
887                 Query q = session.createQuery(query.toString());
888 
889                 QueryPos qPos = QueryPos.getInstance(q);
890 
891                 if (subtype != null) {
892                     qPos.add(subtype);
893                 }
894 
895                 list = (List<Role>)QueryUtil.list(q, getDialect(), start, end);
896             }
897             catch (Exception e) {
898                 throw processException(e);
899             }
900             finally {
901                 if (list == null) {
902                     list = new ArrayList<Role>();
903                 }
904 
905                 cacheResult(list);
906 
907                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_SUBTYPE,
908                     finderArgs, list);
909 
910                 closeSession(session);
911             }
912         }
913 
914         return list;
915     }
916 
917     public Role findBySubtype_First(String subtype, OrderByComparator obc)
918         throws NoSuchRoleException, SystemException {
919         List<Role> list = findBySubtype(subtype, 0, 1, obc);
920 
921         if (list.isEmpty()) {
922             StringBuilder msg = new StringBuilder();
923 
924             msg.append("No Role exists with the key {");
925 
926             msg.append("subtype=" + subtype);
927 
928             msg.append(StringPool.CLOSE_CURLY_BRACE);
929 
930             throw new NoSuchRoleException(msg.toString());
931         }
932         else {
933             return list.get(0);
934         }
935     }
936 
937     public Role findBySubtype_Last(String subtype, OrderByComparator obc)
938         throws NoSuchRoleException, SystemException {
939         int count = countBySubtype(subtype);
940 
941         List<Role> list = findBySubtype(subtype, count - 1, count, obc);
942 
943         if (list.isEmpty()) {
944             StringBuilder msg = new StringBuilder();
945 
946             msg.append("No Role exists with the key {");
947 
948             msg.append("subtype=" + subtype);
949 
950             msg.append(StringPool.CLOSE_CURLY_BRACE);
951 
952             throw new NoSuchRoleException(msg.toString());
953         }
954         else {
955             return list.get(0);
956         }
957     }
958 
959     public Role[] findBySubtype_PrevAndNext(long roleId, String subtype,
960         OrderByComparator obc) throws NoSuchRoleException, SystemException {
961         Role role = findByPrimaryKey(roleId);
962 
963         int count = countBySubtype(subtype);
964 
965         Session session = null;
966 
967         try {
968             session = openSession();
969 
970             StringBuilder query = new StringBuilder();
971 
972             query.append("SELECT role FROM Role role WHERE ");
973 
974             if (subtype == null) {
975                 query.append("role.subtype IS NULL");
976             }
977             else {
978                 query.append("role.subtype = ?");
979             }
980 
981             query.append(" ");
982 
983             if (obc != null) {
984                 query.append("ORDER BY ");
985 
986                 String[] orderByFields = obc.getOrderByFields();
987 
988                 for (int i = 0; i < orderByFields.length; i++) {
989                     query.append("role.");
990                     query.append(orderByFields[i]);
991 
992                     if (obc.isAscending()) {
993                         query.append(" ASC");
994                     }
995                     else {
996                         query.append(" DESC");
997                     }
998 
999                     if ((i + 1) < orderByFields.length) {
1000                        query.append(", ");
1001                    }
1002                }
1003            }
1004
1005            else {
1006                query.append("ORDER BY ");
1007
1008                query.append("role.name ASC");
1009            }
1010
1011            Query q = session.createQuery(query.toString());
1012
1013            QueryPos qPos = QueryPos.getInstance(q);
1014
1015            if (subtype != null) {
1016                qPos.add(subtype);
1017            }
1018
1019            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, role);
1020
1021            Role[] array = new RoleImpl[3];
1022
1023            array[0] = (Role)objArray[0];
1024            array[1] = (Role)objArray[1];
1025            array[2] = (Role)objArray[2];
1026
1027            return array;
1028        }
1029        catch (Exception e) {
1030            throw processException(e);
1031        }
1032        finally {
1033            closeSession(session);
1034        }
1035    }
1036
1037    public Role findByC_N(long companyId, String name)
1038        throws NoSuchRoleException, SystemException {
1039        Role role = fetchByC_N(companyId, name);
1040
1041        if (role == null) {
1042            StringBuilder msg = new StringBuilder();
1043
1044            msg.append("No Role exists with the key {");
1045
1046            msg.append("companyId=" + companyId);
1047
1048            msg.append(", ");
1049            msg.append("name=" + name);
1050
1051            msg.append(StringPool.CLOSE_CURLY_BRACE);
1052
1053            if (_log.isWarnEnabled()) {
1054                _log.warn(msg.toString());
1055            }
1056
1057            throw new NoSuchRoleException(msg.toString());
1058        }
1059
1060        return role;
1061    }
1062
1063    public Role fetchByC_N(long companyId, String name)
1064        throws SystemException {
1065        return fetchByC_N(companyId, name, true);
1066    }
1067
1068    public Role fetchByC_N(long companyId, String name,
1069        boolean retrieveFromCache) throws SystemException {
1070        Object[] finderArgs = new Object[] { new Long(companyId), name };
1071
1072        Object result = null;
1073
1074        if (retrieveFromCache) {
1075            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_N,
1076                    finderArgs, this);
1077        }
1078
1079        if (result == null) {
1080            Session session = null;
1081
1082            try {
1083                session = openSession();
1084
1085                StringBuilder query = new StringBuilder();
1086
1087                query.append("SELECT role FROM Role role WHERE ");
1088
1089                query.append("role.companyId = ?");
1090
1091                query.append(" AND ");
1092
1093                if (name == null) {
1094                    query.append("role.name IS NULL");
1095                }
1096                else {
1097                    query.append("role.name = ?");
1098                }
1099
1100                query.append(" ");
1101
1102                query.append("ORDER BY ");
1103
1104                query.append("role.name ASC");
1105
1106                Query q = session.createQuery(query.toString());
1107
1108                QueryPos qPos = QueryPos.getInstance(q);
1109
1110                qPos.add(companyId);
1111
1112                if (name != null) {
1113                    qPos.add(name);
1114                }
1115
1116                List<Role> list = q.list();
1117
1118                result = list;
1119
1120                Role role = null;
1121
1122                if (list.isEmpty()) {
1123                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
1124                        finderArgs, list);
1125                }
1126                else {
1127                    role = list.get(0);
1128
1129                    cacheResult(role);
1130
1131                    if ((role.getCompanyId() != companyId) ||
1132                            (role.getName() == null) ||
1133                            !role.getName().equals(name)) {
1134                        FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
1135                            finderArgs, role);
1136                    }
1137                }
1138
1139                return role;
1140            }
1141            catch (Exception e) {
1142                throw processException(e);
1143            }
1144            finally {
1145                if (result == null) {
1146                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
1147                        finderArgs, new ArrayList<Role>());
1148                }
1149
1150                closeSession(session);
1151            }
1152        }
1153        else {
1154            if (result instanceof List<?>) {
1155                return null;
1156            }
1157            else {
1158                return (Role)result;
1159            }
1160        }
1161    }
1162
1163    public List<Role> findByT_S(int type, String subtype)
1164        throws SystemException {
1165        Object[] finderArgs = new Object[] { new Integer(type), subtype };
1166
1167        List<Role> list = (List<Role>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_T_S,
1168                finderArgs, this);
1169
1170        if (list == null) {
1171            Session session = null;
1172
1173            try {
1174                session = openSession();
1175
1176                StringBuilder query = new StringBuilder();
1177
1178                query.append("SELECT role FROM Role role WHERE ");
1179
1180                query.append("role.type = ?");
1181
1182                query.append(" AND ");
1183
1184                if (subtype == null) {
1185                    query.append("role.subtype IS NULL");
1186                }
1187                else {
1188                    query.append("role.subtype = ?");
1189                }
1190
1191                query.append(" ");
1192
1193                query.append("ORDER BY ");
1194
1195                query.append("role.name ASC");
1196
1197                Query q = session.createQuery(query.toString());
1198
1199                QueryPos qPos = QueryPos.getInstance(q);
1200
1201                qPos.add(type);
1202
1203                if (subtype != null) {
1204                    qPos.add(subtype);
1205                }
1206
1207                list = q.list();
1208            }
1209            catch (Exception e) {
1210                throw processException(e);
1211            }
1212            finally {
1213                if (list == null) {
1214                    list = new ArrayList<Role>();
1215                }
1216
1217                cacheResult(list);
1218
1219                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_T_S, finderArgs,
1220                    list);
1221
1222                closeSession(session);
1223            }
1224        }
1225
1226        return list;
1227    }
1228
1229    public List<Role> findByT_S(int type, String subtype, int start, int end)
1230        throws SystemException {
1231        return findByT_S(type, subtype, start, end, null);
1232    }
1233
1234    public List<Role> findByT_S(int type, String subtype, int start, int end,
1235        OrderByComparator obc) throws SystemException {
1236        Object[] finderArgs = new Object[] {
1237                new Integer(type),
1238                
1239                subtype,
1240                
1241                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1242            };
1243
1244        List<Role> list = (List<Role>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_T_S,
1245                finderArgs, this);
1246
1247        if (list == null) {
1248            Session session = null;
1249
1250            try {
1251                session = openSession();
1252
1253                StringBuilder query = new StringBuilder();
1254
1255                query.append("SELECT role FROM Role role WHERE ");
1256
1257                query.append("role.type = ?");
1258
1259                query.append(" AND ");
1260
1261                if (subtype == null) {
1262                    query.append("role.subtype IS NULL");
1263                }
1264                else {
1265                    query.append("role.subtype = ?");
1266                }
1267
1268                query.append(" ");
1269
1270                if (obc != null) {
1271                    query.append("ORDER BY ");
1272
1273                    String[] orderByFields = obc.getOrderByFields();
1274
1275                    for (int i = 0; i < orderByFields.length; i++) {
1276                        query.append("role.");
1277                        query.append(orderByFields[i]);
1278
1279                        if (obc.isAscending()) {
1280                            query.append(" ASC");
1281                        }
1282                        else {
1283                            query.append(" DESC");
1284                        }
1285
1286                        if ((i + 1) < orderByFields.length) {
1287                            query.append(", ");
1288                        }
1289                    }
1290                }
1291
1292                else {
1293                    query.append("ORDER BY ");
1294
1295                    query.append("role.name ASC");
1296                }
1297
1298                Query q = session.createQuery(query.toString());
1299
1300                QueryPos qPos = QueryPos.getInstance(q);
1301
1302                qPos.add(type);
1303
1304                if (subtype != null) {
1305                    qPos.add(subtype);
1306                }
1307
1308                list = (List<Role>)QueryUtil.list(q, getDialect(), start, end);
1309            }
1310            catch (Exception e) {
1311                throw processException(e);
1312            }
1313            finally {
1314                if (list == null) {
1315                    list = new ArrayList<Role>();
1316                }
1317
1318                cacheResult(list);
1319
1320                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_T_S,
1321                    finderArgs, list);
1322
1323                closeSession(session);
1324            }
1325        }
1326
1327        return list;
1328    }
1329
1330    public Role findByT_S_First(int type, String subtype, OrderByComparator obc)
1331        throws NoSuchRoleException, SystemException {
1332        List<Role> list = findByT_S(type, subtype, 0, 1, obc);
1333
1334        if (list.isEmpty()) {
1335            StringBuilder msg = new StringBuilder();
1336
1337            msg.append("No Role exists with the key {");
1338
1339            msg.append("type=" + type);
1340
1341            msg.append(", ");
1342            msg.append("subtype=" + subtype);
1343
1344            msg.append(StringPool.CLOSE_CURLY_BRACE);
1345
1346            throw new NoSuchRoleException(msg.toString());
1347        }
1348        else {
1349            return list.get(0);
1350        }
1351    }
1352
1353    public Role findByT_S_Last(int type, String subtype, OrderByComparator obc)
1354        throws NoSuchRoleException, SystemException {
1355        int count = countByT_S(type, subtype);
1356
1357        List<Role> list = findByT_S(type, subtype, count - 1, count, obc);
1358
1359        if (list.isEmpty()) {
1360            StringBuilder msg = new StringBuilder();
1361
1362            msg.append("No Role exists with the key {");
1363
1364            msg.append("type=" + type);
1365
1366            msg.append(", ");
1367            msg.append("subtype=" + subtype);
1368
1369            msg.append(StringPool.CLOSE_CURLY_BRACE);
1370
1371            throw new NoSuchRoleException(msg.toString());
1372        }
1373        else {
1374            return list.get(0);
1375        }
1376    }
1377
1378    public Role[] findByT_S_PrevAndNext(long roleId, int type, String subtype,
1379        OrderByComparator obc) throws NoSuchRoleException, SystemException {
1380        Role role = findByPrimaryKey(roleId);
1381
1382        int count = countByT_S(type, subtype);
1383
1384        Session session = null;
1385
1386        try {
1387            session = openSession();
1388
1389            StringBuilder query = new StringBuilder();
1390
1391            query.append("SELECT role FROM Role role WHERE ");
1392
1393            query.append("role.type = ?");
1394
1395            query.append(" AND ");
1396
1397            if (subtype == null) {
1398                query.append("role.subtype IS NULL");
1399            }
1400            else {
1401                query.append("role.subtype = ?");
1402            }
1403
1404            query.append(" ");
1405
1406            if (obc != null) {
1407                query.append("ORDER BY ");
1408
1409                String[] orderByFields = obc.getOrderByFields();
1410
1411                for (int i = 0; i < orderByFields.length; i++) {
1412                    query.append("role.");
1413                    query.append(orderByFields[i]);
1414
1415                    if (obc.isAscending()) {
1416                        query.append(" ASC");
1417                    }
1418                    else {
1419                        query.append(" DESC");
1420                    }
1421
1422                    if ((i + 1) < orderByFields.length) {
1423                        query.append(", ");
1424                    }
1425                }
1426            }
1427
1428            else {
1429                query.append("ORDER BY ");
1430
1431                query.append("role.name ASC");
1432            }
1433
1434            Query q = session.createQuery(query.toString());
1435
1436            QueryPos qPos = QueryPos.getInstance(q);
1437
1438            qPos.add(type);
1439
1440            if (subtype != null) {
1441                qPos.add(subtype);
1442            }
1443
1444            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, role);
1445
1446            Role[] array = new RoleImpl[3];
1447
1448            array[0] = (Role)objArray[0];
1449            array[1] = (Role)objArray[1];
1450            array[2] = (Role)objArray[2];
1451
1452            return array;
1453        }
1454        catch (Exception e) {
1455            throw processException(e);
1456        }
1457        finally {
1458            closeSession(session);
1459        }
1460    }
1461
1462    public Role findByC_C_C(long companyId, long classNameId, long classPK)
1463        throws NoSuchRoleException, SystemException {
1464        Role role = fetchByC_C_C(companyId, classNameId, classPK);
1465
1466        if (role == null) {
1467            StringBuilder msg = new StringBuilder();
1468
1469            msg.append("No Role exists with the key {");
1470
1471            msg.append("companyId=" + companyId);
1472
1473            msg.append(", ");
1474            msg.append("classNameId=" + classNameId);
1475
1476            msg.append(", ");
1477            msg.append("classPK=" + classPK);
1478
1479            msg.append(StringPool.CLOSE_CURLY_BRACE);
1480
1481            if (_log.isWarnEnabled()) {
1482                _log.warn(msg.toString());
1483            }
1484
1485            throw new NoSuchRoleException(msg.toString());
1486        }
1487
1488        return role;
1489    }
1490
1491    public Role fetchByC_C_C(long companyId, long classNameId, long classPK)
1492        throws SystemException {
1493        return fetchByC_C_C(companyId, classNameId, classPK, true);
1494    }
1495
1496    public Role fetchByC_C_C(long companyId, long classNameId, long classPK,
1497        boolean retrieveFromCache) throws SystemException {
1498        Object[] finderArgs = new Object[] {
1499                new Long(companyId), new Long(classNameId), new Long(classPK)
1500            };
1501
1502        Object result = null;
1503
1504        if (retrieveFromCache) {
1505            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_C_C,
1506                    finderArgs, this);
1507        }
1508
1509        if (result == null) {
1510            Session session = null;
1511
1512            try {
1513                session = openSession();
1514
1515                StringBuilder query = new StringBuilder();
1516
1517                query.append("SELECT role FROM Role role WHERE ");
1518
1519                query.append("role.companyId = ?");
1520
1521                query.append(" AND ");
1522
1523                query.append("role.classNameId = ?");
1524
1525                query.append(" AND ");
1526
1527                query.append("role.classPK = ?");
1528
1529                query.append(" ");
1530
1531                query.append("ORDER BY ");
1532
1533                query.append("role.name ASC");
1534
1535                Query q = session.createQuery(query.toString());
1536
1537                QueryPos qPos = QueryPos.getInstance(q);
1538
1539                qPos.add(companyId);
1540
1541                qPos.add(classNameId);
1542
1543                qPos.add(classPK);
1544
1545                List<Role> list = q.list();
1546
1547                result = list;
1548
1549                Role role = null;
1550
1551                if (list.isEmpty()) {
1552                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_C,
1553                        finderArgs, list);
1554                }
1555                else {
1556                    role = list.get(0);
1557
1558                    cacheResult(role);
1559
1560                    if ((role.getCompanyId() != companyId) ||
1561                            (role.getClassNameId() != classNameId) ||
1562                            (role.getClassPK() != classPK)) {
1563                        FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_C,
1564                            finderArgs, role);
1565                    }
1566                }
1567
1568                return role;
1569            }
1570            catch (Exception e) {
1571                throw processException(e);
1572            }
1573            finally {
1574                if (result == null) {
1575                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_C,
1576                        finderArgs, new ArrayList<Role>());
1577                }
1578
1579                closeSession(session);
1580            }
1581        }
1582        else {
1583            if (result instanceof List<?>) {
1584                return null;
1585            }
1586            else {
1587                return (Role)result;
1588            }
1589        }
1590    }
1591
1592    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
1593        throws SystemException {
1594        Session session = null;
1595
1596        try {
1597            session = openSession();
1598
1599            dynamicQuery.compile(session);
1600
1601            return dynamicQuery.list();
1602        }
1603        catch (Exception e) {
1604            throw processException(e);
1605        }
1606        finally {
1607            closeSession(session);
1608        }
1609    }
1610
1611    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
1612        int start, int end) throws SystemException {
1613        Session session = null;
1614
1615        try {
1616            session = openSession();
1617
1618            dynamicQuery.setLimit(start, end);
1619
1620            dynamicQuery.compile(session);
1621
1622            return dynamicQuery.list();
1623        }
1624        catch (Exception e) {
1625            throw processException(e);
1626        }
1627        finally {
1628            closeSession(session);
1629        }
1630    }
1631
1632    public List<Role> findAll() throws SystemException {
1633        return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1634    }
1635
1636    public List<Role> findAll(int start, int end) throws SystemException {
1637        return findAll(start, end, null);
1638    }
1639
1640    public List<Role> findAll(int start, int end, OrderByComparator obc)
1641        throws SystemException {
1642        Object[] finderArgs = new Object[] {
1643                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1644            };
1645
1646        List<Role> list = (List<Role>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1647                finderArgs, this);
1648
1649        if (list == null) {
1650            Session session = null;
1651
1652            try {
1653                session = openSession();
1654
1655                StringBuilder query = new StringBuilder();
1656
1657                query.append("SELECT role FROM Role role ");
1658
1659                if (obc != null) {
1660                    query.append("ORDER BY ");
1661
1662                    String[] orderByFields = obc.getOrderByFields();
1663
1664                    for (int i = 0; i < orderByFields.length; i++) {
1665                        query.append("role.");
1666                        query.append(orderByFields[i]);
1667
1668                        if (obc.isAscending()) {
1669                            query.append(" ASC");
1670                        }
1671                        else {
1672                            query.append(" DESC");
1673                        }
1674
1675                        if ((i + 1) < orderByFields.length) {
1676                            query.append(", ");
1677                        }
1678                    }
1679                }
1680
1681                else {
1682                    query.append("ORDER BY ");
1683
1684                    query.append("role.name ASC");
1685                }
1686
1687                Query q = session.createQuery(query.toString());
1688
1689                if (obc == null) {
1690                    list = (List<Role>)QueryUtil.list(q, getDialect(), start,
1691                            end, false);
1692
1693                    Collections.sort(list);
1694                }
1695                else {
1696                    list = (List<Role>)QueryUtil.list(q, getDialect(), start,
1697                            end);
1698                }
1699            }
1700            catch (Exception e) {
1701                throw processException(e);
1702            }
1703            finally {
1704                if (list == null) {
1705                    list = new ArrayList<Role>();
1706                }
1707
1708                cacheResult(list);
1709
1710                FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1711
1712                closeSession(session);
1713            }
1714        }
1715
1716        return list;
1717    }
1718
1719    public void removeByCompanyId(long companyId) throws SystemException {
1720        for (Role role : findByCompanyId(companyId)) {
1721            remove(role);
1722        }
1723    }
1724
1725    public void removeBySubtype(String subtype) throws SystemException {
1726        for (Role role : findBySubtype(subtype)) {
1727            remove(role);
1728        }
1729    }
1730
1731    public void removeByC_N(long companyId, String name)
1732        throws NoSuchRoleException, SystemException {
1733        Role role = findByC_N(companyId, name);
1734
1735        remove(role);
1736    }
1737
1738    public void removeByT_S(int type, String subtype) throws SystemException {
1739        for (Role role : findByT_S(type, subtype)) {
1740            remove(role);
1741        }
1742    }
1743
1744    public void removeByC_C_C(long companyId, long classNameId, long classPK)
1745        throws NoSuchRoleException, SystemException {
1746        Role role = findByC_C_C(companyId, classNameId, classPK);
1747
1748        remove(role);
1749    }
1750
1751    public void removeAll() throws SystemException {
1752        for (Role role : findAll()) {
1753            remove(role);
1754        }
1755    }
1756
1757    public int countByCompanyId(long companyId) throws SystemException {
1758        Object[] finderArgs = new Object[] { new Long(companyId) };
1759
1760        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
1761                finderArgs, this);
1762
1763        if (count == null) {
1764            Session session = null;
1765
1766            try {
1767                session = openSession();
1768
1769                StringBuilder query = new StringBuilder();
1770
1771                query.append("SELECT COUNT(role) ");
1772                query.append("FROM Role role WHERE ");
1773
1774                query.append("role.companyId = ?");
1775
1776                query.append(" ");
1777
1778                Query q = session.createQuery(query.toString());
1779
1780                QueryPos qPos = QueryPos.getInstance(q);
1781
1782                qPos.add(companyId);
1783
1784                count = (Long)q.uniqueResult();
1785            }
1786            catch (Exception e) {
1787                throw processException(e);
1788            }
1789            finally {
1790                if (count == null) {
1791                    count = Long.valueOf(0);
1792                }
1793
1794                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
1795                    finderArgs, count);
1796
1797                closeSession(session);
1798            }
1799        }
1800
1801        return count.intValue();
1802    }
1803
1804    public int countBySubtype(String subtype) throws SystemException {
1805        Object[] finderArgs = new Object[] { subtype };
1806
1807        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_SUBTYPE,
1808                finderArgs, this);
1809
1810        if (count == null) {
1811            Session session = null;
1812
1813            try {
1814                session = openSession();
1815
1816                StringBuilder query = new StringBuilder();
1817
1818                query.append("SELECT COUNT(role) ");
1819                query.append("FROM Role role WHERE ");
1820
1821                if (subtype == null) {
1822                    query.append("role.subtype IS NULL");
1823                }
1824                else {
1825                    query.append("role.subtype = ?");
1826                }
1827
1828                query.append(" ");
1829
1830                Query q = session.createQuery(query.toString());
1831
1832                QueryPos qPos = QueryPos.getInstance(q);
1833
1834                if (subtype != null) {
1835                    qPos.add(subtype);
1836                }
1837
1838                count = (Long)q.uniqueResult();
1839            }
1840            catch (Exception e) {
1841                throw processException(e);
1842            }
1843            finally {
1844                if (count == null) {
1845                    count = Long.valueOf(0);
1846                }
1847
1848                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_SUBTYPE,
1849                    finderArgs, count);
1850
1851                closeSession(session);
1852            }
1853        }
1854
1855        return count.intValue();
1856    }
1857
1858    public int countByC_N(long companyId, String name)
1859        throws SystemException {
1860        Object[] finderArgs = new Object[] { new Long(companyId), name };
1861
1862        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_N,
1863                finderArgs, this);
1864
1865        if (count == null) {
1866            Session session = null;
1867
1868            try {
1869                session = openSession();
1870
1871                StringBuilder query = new StringBuilder();
1872
1873                query.append("SELECT COUNT(role) ");
1874                query.append("FROM Role role WHERE ");
1875
1876                query.append("role.companyId = ?");
1877
1878                query.append(" AND ");
1879
1880                if (name == null) {
1881                    query.append("role.name IS NULL");
1882                }
1883                else {
1884                    query.append("role.name = ?");
1885                }
1886
1887                query.append(" ");
1888
1889                Query q = session.createQuery(query.toString());
1890
1891                QueryPos qPos = QueryPos.getInstance(q);
1892
1893                qPos.add(companyId);
1894
1895                if (name != null) {
1896                    qPos.add(name);
1897                }
1898
1899                count = (Long)q.uniqueResult();
1900            }
1901            catch (Exception e) {
1902                throw processException(e);
1903            }
1904            finally {
1905                if (count == null) {
1906                    count = Long.valueOf(0);
1907                }
1908
1909                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_N, finderArgs,
1910                    count);
1911
1912                closeSession(session);
1913            }
1914        }
1915
1916        return count.intValue();
1917    }
1918
1919    public int countByT_S(int type, String subtype) throws SystemException {
1920        Object[] finderArgs = new Object[] { new Integer(type), subtype };
1921
1922        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_T_S,
1923                finderArgs, this);
1924
1925        if (count == null) {
1926            Session session = null;
1927
1928            try {
1929                session = openSession();
1930
1931                StringBuilder query = new StringBuilder();
1932
1933                query.append("SELECT COUNT(role) ");
1934                query.append("FROM Role role WHERE ");
1935
1936                query.append("role.type = ?");
1937
1938                query.append(" AND ");
1939
1940                if (subtype == null) {
1941                    query.append("role.subtype IS NULL");
1942                }
1943                else {
1944                    query.append("role.subtype = ?");
1945                }
1946
1947                query.append(" ");
1948
1949                Query q = session.createQuery(query.toString());
1950
1951                QueryPos qPos = QueryPos.getInstance(q);
1952
1953                qPos.add(type);
1954
1955                if (subtype != null) {
1956                    qPos.add(subtype);
1957                }
1958
1959                count = (Long)q.uniqueResult();
1960            }
1961            catch (Exception e) {
1962                throw processException(e);
1963            }
1964            finally {
1965                if (count == null) {
1966                    count = Long.valueOf(0);
1967                }
1968
1969                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_S, finderArgs,
1970                    count);
1971
1972                closeSession(session);
1973            }
1974        }
1975
1976        return count.intValue();
1977    }
1978
1979    public int countByC_C_C(long companyId, long classNameId, long classPK)
1980        throws SystemException {
1981        Object[] finderArgs = new Object[] {
1982                new Long(companyId), new Long(classNameId), new Long(classPK)
1983            };
1984
1985        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C_C,
1986                finderArgs, this);
1987
1988        if (count == null) {
1989            Session session = null;
1990
1991            try {
1992                session = openSession();
1993
1994                StringBuilder query = new StringBuilder();
1995
1996                query.append("SELECT COUNT(role) ");
1997                query.append("FROM Role role WHERE ");
1998
1999                query.append("role.companyId = ?");
2000
2001                query.append(" AND ");
2002
2003                query.append("role.classNameId = ?");
2004
2005                query.append(" AND ");
2006
2007                query.append("role.classPK = ?");
2008
2009                query.append(" ");
2010
2011                Query q = session.createQuery(query.toString());
2012
2013                QueryPos qPos = QueryPos.getInstance(q);
2014
2015                qPos.add(companyId);
2016
2017                qPos.add(classNameId);
2018
2019                qPos.add(classPK);
2020
2021                count = (Long)q.uniqueResult();
2022            }
2023            catch (Exception e) {
2024                throw processException(e);
2025            }
2026            finally {
2027                if (count == null) {
2028                    count = Long.valueOf(0);
2029                }
2030
2031                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C_C,
2032                    finderArgs, count);
2033
2034                closeSession(session);
2035            }
2036        }
2037
2038        return count.intValue();
2039    }
2040
2041    public int countAll() throws SystemException {
2042        Object[] finderArgs = new Object[0];
2043
2044        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2045                finderArgs, this);
2046
2047        if (count == null) {
2048            Session session = null;
2049
2050            try {
2051                session = openSession();
2052
2053                Query q = session.createQuery(
2054                        "SELECT COUNT(role) FROM Role role");
2055
2056                count = (Long)q.uniqueResult();
2057            }
2058            catch (Exception e) {
2059                throw processException(e);
2060            }
2061            finally {
2062                if (count == null) {
2063                    count = Long.valueOf(0);
2064                }
2065
2066                FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
2067                    count);
2068
2069                closeSession(session);
2070            }
2071        }
2072
2073        return count.intValue();
2074    }
2075
2076    public List<com.liferay.portal.model.Group> getGroups(long pk)
2077        throws SystemException {
2078        return getGroups(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
2079    }
2080
2081    public List<com.liferay.portal.model.Group> getGroups(long pk, int start,
2082        int end) throws SystemException {
2083        return getGroups(pk, start, end, null);
2084    }
2085
2086    public static final FinderPath FINDER_PATH_GET_GROUPS = new FinderPath(com.liferay.portal.model.impl.GroupModelImpl.ENTITY_CACHE_ENABLED,
2087            RoleModelImpl.FINDER_CACHE_ENABLED_GROUPS_ROLES, "Groups_Roles",
2088            "getGroups",
2089            new String[] {
2090                Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
2091                "com.liferay.portal.kernel.util.OrderByComparator"
2092            });
2093
2094    public List<com.liferay.portal.model.Group> getGroups(long pk, int start,
2095        int end, OrderByComparator obc) throws SystemException {
2096        Object[] finderArgs = new Object[] {
2097                new Long(pk), String.valueOf(start), String.valueOf(end),
2098                String.valueOf(obc)
2099            };
2100
2101        List<com.liferay.portal.model.Group> list = (List<com.liferay.portal.model.Group>)FinderCacheUtil.getResult(FINDER_PATH_GET_GROUPS,
2102                finderArgs, this);
2103
2104        if (list == null) {
2105            Session session = null;
2106
2107            try {
2108                session = openSession();
2109
2110                StringBuilder sb = new StringBuilder();
2111
2112                sb.append(_SQL_GETGROUPS);
2113
2114                if (obc != null) {
2115                    sb.append("ORDER BY ");
2116                    sb.append(obc.getOrderBy());
2117                }
2118
2119                else {
2120                    sb.append("ORDER BY ");
2121
2122                    sb.append("Group_.name ASC");
2123                }
2124
2125                String sql = sb.toString();
2126
2127                SQLQuery q = session.createSQLQuery(sql);
2128
2129                q.addEntity("Group_",
2130                    com.liferay.portal.model.impl.GroupImpl.class);
2131
2132                QueryPos qPos = QueryPos.getInstance(q);
2133
2134                qPos.add(pk);
2135
2136                list = (List<com.liferay.portal.model.Group>)QueryUtil.list(q,
2137                        getDialect(), start, end);
2138            }
2139            catch (Exception e) {
2140                throw processException(e);
2141            }
2142            finally {
2143                if (list == null) {
2144                    list = new ArrayList<com.liferay.portal.model.Group>();
2145                }
2146
2147                groupPersistence.cacheResult(list);
2148
2149                FinderCacheUtil.putResult(FINDER_PATH_GET_GROUPS, finderArgs,
2150                    list);
2151
2152                closeSession(session);
2153            }
2154        }
2155
2156        return list;
2157    }
2158
2159    public static final FinderPath FINDER_PATH_GET_GROUPS_SIZE = new FinderPath(com.liferay.portal.model.impl.GroupModelImpl.ENTITY_CACHE_ENABLED,
2160            RoleModelImpl.FINDER_CACHE_ENABLED_GROUPS_ROLES, "Groups_Roles",
2161            "getGroupsSize", new String[] { Long.class.getName() });
2162
2163    public int getGroupsSize(long pk) throws SystemException {
2164        Object[] finderArgs = new Object[] { new Long(pk) };
2165
2166        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_GROUPS_SIZE,
2167                finderArgs, this);
2168
2169        if (count == null) {
2170            Session session = null;
2171
2172            try {
2173                session = openSession();
2174
2175                SQLQuery q = session.createSQLQuery(_SQL_GETGROUPSSIZE);
2176
2177                q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
2178
2179                QueryPos qPos = QueryPos.getInstance(q);
2180
2181                qPos.add(pk);
2182
2183                count = (Long)q.uniqueResult();
2184            }
2185            catch (Exception e) {
2186                throw processException(e);
2187            }
2188            finally {
2189                if (count == null) {
2190                    count = Long.valueOf(0);
2191                }
2192
2193                FinderCacheUtil.putResult(FINDER_PATH_GET_GROUPS_SIZE,
2194                    finderArgs, count);
2195
2196                closeSession(session);
2197            }
2198        }
2199
2200        return count.intValue();
2201    }
2202
2203    public static final FinderPath FINDER_PATH_CONTAINS_GROUP = new FinderPath(com.liferay.portal.model.impl.GroupModelImpl.ENTITY_CACHE_ENABLED,
2204            RoleModelImpl.FINDER_CACHE_ENABLED_GROUPS_ROLES, "Groups_Roles",
2205            "containsGroup",
2206            new String[] { Long.class.getName(), Long.class.getName() });
2207
2208    public boolean containsGroup(long pk, long groupPK)
2209        throws SystemException {
2210        Object[] finderArgs = new Object[] { new Long(pk), new Long(groupPK) };
2211
2212        Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_GROUP,
2213                finderArgs, this);
2214
2215        if (value == null) {
2216            try {
2217                value = Boolean.valueOf(containsGroup.contains(pk, groupPK));
2218            }
2219            catch (Exception e) {
2220                throw processException(e);
2221            }
2222            finally {
2223                if (value == null) {
2224                    value = Boolean.FALSE;
2225                }
2226
2227                FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_GROUP,
2228                    finderArgs, value);
2229            }
2230        }
2231
2232        return value.booleanValue();
2233    }
2234
2235    public boolean containsGroups(long pk) throws SystemException {
2236        if (getGroupsSize(pk) > 0) {
2237            return true;
2238        }
2239        else {
2240            return false;
2241        }
2242    }
2243
2244    public void addGroup(long pk, long groupPK) throws SystemException {
2245        try {
2246            addGroup.add(pk, groupPK);
2247        }
2248        catch (Exception e) {
2249            throw processException(e);
2250        }
2251        finally {
2252            FinderCacheUtil.clearCache("Groups_Roles");
2253        }
2254    }
2255
2256    public void addGroup(long pk, com.liferay.portal.model.Group group)
2257        throws SystemException {
2258        try {
2259            addGroup.add(pk, group.getPrimaryKey());
2260        }
2261        catch (Exception e) {
2262            throw processException(e);
2263        }
2264        finally {
2265            FinderCacheUtil.clearCache("Groups_Roles");
2266        }
2267    }
2268
2269    public void addGroups(long pk, long[] groupPKs) throws SystemException {
2270        try {
2271            for (long groupPK : groupPKs) {
2272                addGroup.add(pk, groupPK);
2273            }
2274        }
2275        catch (Exception e) {
2276            throw processException(e);
2277        }
2278        finally {
2279            FinderCacheUtil.clearCache("Groups_Roles");
2280        }
2281    }
2282
2283    public void addGroups(long pk, List<com.liferay.portal.model.Group> groups)
2284        throws SystemException {
2285        try {
2286            for (com.liferay.portal.model.Group group : groups) {
2287                addGroup.add(pk, group.getPrimaryKey());
2288            }
2289        }
2290        catch (Exception e) {
2291            throw processException(e);
2292        }
2293        finally {
2294            FinderCacheUtil.clearCache("Groups_Roles");
2295        }
2296    }
2297
2298    public void clearGroups(long pk) throws SystemException {
2299        try {
2300            clearGroups.clear(pk);
2301        }
2302        catch (Exception e) {
2303            throw processException(e);
2304        }
2305        finally {
2306            FinderCacheUtil.clearCache("Groups_Roles");
2307        }
2308    }
2309
2310    public void removeGroup(long pk, long groupPK) throws SystemException {
2311        try {
2312            removeGroup.remove(pk, groupPK);
2313        }
2314        catch (Exception e) {
2315            throw processException(e);
2316        }
2317        finally {
2318            FinderCacheUtil.clearCache("Groups_Roles");
2319        }
2320    }
2321
2322    public void removeGroup(long pk, com.liferay.portal.model.Group group)
2323        throws SystemException {
2324        try {
2325            removeGroup.remove(pk, group.getPrimaryKey());
2326        }
2327        catch (Exception e) {
2328            throw processException(e);
2329        }
2330        finally {
2331            FinderCacheUtil.clearCache("Groups_Roles");
2332        }
2333    }
2334
2335    public void removeGroups(long pk, long[] groupPKs)
2336        throws SystemException {
2337        try {
2338            for (long groupPK : groupPKs) {
2339                removeGroup.remove(pk, groupPK);
2340            }
2341        }
2342        catch (Exception e) {
2343            throw processException(e);
2344        }
2345        finally {
2346            FinderCacheUtil.clearCache("Groups_Roles");
2347        }
2348    }
2349
2350    public void removeGroups(long pk,
2351        List<com.liferay.portal.model.Group> groups) throws SystemException {
2352        try {
2353            for (com.liferay.portal.model.Group group : groups) {
2354                removeGroup.remove(pk, group.getPrimaryKey());
2355            }
2356        }
2357        catch (Exception e) {
2358            throw processException(e);
2359        }
2360        finally {
2361            FinderCacheUtil.clearCache("Groups_Roles");
2362        }
2363    }
2364
2365    public void setGroups(long pk, long[] groupPKs) throws SystemException {
2366        try {
2367            Set<Long> groupPKSet = SetUtil.fromArray(groupPKs);
2368
2369            List<com.liferay.portal.model.Group> groups = getGroups(pk);
2370
2371            for (com.liferay.portal.model.Group group : groups) {
2372                if (!groupPKSet.contains(group.getPrimaryKey())) {
2373                    removeGroup.remove(pk, group.getPrimaryKey());
2374                }
2375                else {
2376                    groupPKSet.remove(group.getPrimaryKey());
2377                }
2378            }
2379
2380            for (Long groupPK : groupPKSet) {
2381                addGroup.add(pk, groupPK);
2382            }
2383        }
2384        catch (Exception e) {
2385            throw processException(e);
2386        }
2387        finally {
2388            FinderCacheUtil.clearCache("Groups_Roles");
2389        }
2390    }
2391
2392    public void setGroups(long pk, List<com.liferay.portal.model.Group> groups)
2393        throws SystemException {
2394        try {
2395            long[] groupPKs = new long[groups.size()];
2396
2397            for (int i = 0; i < groups.size(); i++) {
2398                com.liferay.portal.model.Group group = groups.get(i);
2399
2400                groupPKs[i] = group.getPrimaryKey();
2401            }
2402
2403            setGroups(pk, groupPKs);
2404        }
2405        catch (Exception e) {
2406            throw processException(e);
2407        }
2408        finally {
2409            FinderCacheUtil.clearCache("Groups_Roles");
2410        }
2411    }
2412
2413    public List<com.liferay.portal.model.Permission> getPermissions(long pk)
2414        throws SystemException {
2415        return getPermissions(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
2416    }
2417
2418    public List<com.liferay.portal.model.Permission> getPermissions(long pk,
2419        int start, int end) throws SystemException {
2420        return getPermissions(pk, start, end, null);
2421    }
2422
2423    public static final FinderPath FINDER_PATH_GET_PERMISSIONS = new FinderPath(com.liferay.portal.model.impl.PermissionModelImpl.ENTITY_CACHE_ENABLED,
2424            RoleModelImpl.FINDER_CACHE_ENABLED_ROLES_PERMISSIONS,
2425            "Roles_Permissions", "getPermissions",
2426            new String[] {
2427                Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
2428                "com.liferay.portal.kernel.util.OrderByComparator"
2429            });
2430
2431    public List<com.liferay.portal.model.Permission> getPermissions(long pk,
2432        int start, int end, OrderByComparator obc) throws SystemException {
2433        Object[] finderArgs = new Object[] {
2434                new Long(pk), String.valueOf(start), String.valueOf(end),
2435                String.valueOf(obc)
2436            };
2437
2438        List<com.liferay.portal.model.Permission> list = (List<com.liferay.portal.model.Permission>)FinderCacheUtil.getResult(FINDER_PATH_GET_PERMISSIONS,
2439                finderArgs, this);
2440
2441        if (list == null) {
2442            Session session = null;
2443
2444            try {
2445                session = openSession();
2446
2447                StringBuilder sb = new StringBuilder();
2448
2449                sb.append(_SQL_GETPERMISSIONS);
2450
2451                if (obc != null) {
2452                    sb.append("ORDER BY ");
2453                    sb.append(obc.getOrderBy());
2454                }
2455
2456                String sql = sb.toString();
2457
2458                SQLQuery q = session.createSQLQuery(sql);
2459
2460                q.addEntity("Permission_",
2461                    com.liferay.portal.model.impl.PermissionImpl.class);
2462
2463                QueryPos qPos = QueryPos.getInstance(q);
2464
2465                qPos.add(pk);
2466
2467                list = (List<com.liferay.portal.model.Permission>)QueryUtil.list(q,
2468                        getDialect(), start, end);
2469            }
2470            catch (Exception e) {
2471                throw processException(e);
2472            }
2473            finally {
2474                if (list == null) {
2475                    list = new ArrayList<com.liferay.portal.model.Permission>();
2476                }
2477
2478                permissionPersistence.cacheResult(list);
2479
2480                FinderCacheUtil.putResult(FINDER_PATH_GET_PERMISSIONS,
2481                    finderArgs, list);
2482
2483                closeSession(session);
2484            }
2485        }
2486
2487        return list;
2488    }
2489
2490    public static final FinderPath FINDER_PATH_GET_PERMISSIONS_SIZE = new FinderPath(com.liferay.portal.model.impl.PermissionModelImpl.ENTITY_CACHE_ENABLED,
2491            RoleModelImpl.FINDER_CACHE_ENABLED_ROLES_PERMISSIONS,
2492            "Roles_Permissions", "getPermissionsSize",
2493            new String[] { Long.class.getName() });
2494
2495    public int getPermissionsSize(long pk) throws SystemException {
2496        Object[] finderArgs = new Object[] { new Long(pk) };
2497
2498        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_PERMISSIONS_SIZE,
2499                finderArgs, this);
2500
2501        if (count == null) {
2502            Session session = null;
2503
2504            try {
2505                session = openSession();
2506
2507                SQLQuery q = session.createSQLQuery(_SQL_GETPERMISSIONSSIZE);
2508
2509                q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
2510
2511                QueryPos qPos = QueryPos.getInstance(q);
2512
2513                qPos.add(pk);
2514
2515                count = (Long)q.uniqueResult();
2516            }
2517            catch (Exception e) {
2518                throw processException(e);
2519            }
2520            finally {
2521                if (count == null) {
2522                    count = Long.valueOf(0);
2523                }
2524
2525                FinderCacheUtil.putResult(FINDER_PATH_GET_PERMISSIONS_SIZE,
2526                    finderArgs, count);
2527
2528                closeSession(session);
2529            }
2530        }
2531
2532        return count.intValue();
2533    }
2534
2535    public static final FinderPath FINDER_PATH_CONTAINS_PERMISSION = new FinderPath(com.liferay.portal.model.impl.PermissionModelImpl.ENTITY_CACHE_ENABLED,
2536            RoleModelImpl.FINDER_CACHE_ENABLED_ROLES_PERMISSIONS,
2537            "Roles_Permissions", "containsPermission",
2538            new String[] { Long.class.getName(), Long.class.getName() });
2539
2540    public boolean containsPermission(long pk, long permissionPK)
2541        throws SystemException {
2542        Object[] finderArgs = new Object[] { new Long(pk), new Long(permissionPK) };
2543
2544        Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_PERMISSION,
2545                finderArgs, this);
2546
2547        if (value == null) {
2548            try {
2549                value = Boolean.valueOf(containsPermission.contains(pk,
2550                            permissionPK));
2551            }
2552            catch (Exception e) {
2553                throw processException(e);
2554            }
2555            finally {
2556                if (value == null) {
2557                    value = Boolean.FALSE;
2558                }
2559
2560                FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_PERMISSION,
2561                    finderArgs, value);
2562            }
2563        }
2564
2565        return value.booleanValue();
2566    }
2567
2568    public boolean containsPermissions(long pk) throws SystemException {
2569        if (getPermissionsSize(pk) > 0) {
2570            return true;
2571        }
2572        else {
2573            return false;
2574        }
2575    }
2576
2577    public void addPermission(long pk, long permissionPK)
2578        throws SystemException {
2579        try {
2580            addPermission.add(pk, permissionPK);
2581        }
2582        catch (Exception e) {
2583            throw processException(e);
2584        }
2585        finally {
2586            FinderCacheUtil.clearCache("Roles_Permissions");
2587        }
2588    }
2589
2590    public void addPermission(long pk,
2591        com.liferay.portal.model.Permission permission)
2592        throws SystemException {
2593        try {
2594            addPermission.add(pk, permission.getPrimaryKey());
2595        }
2596        catch (Exception e) {
2597            throw processException(e);
2598        }
2599        finally {
2600            FinderCacheUtil.clearCache("Roles_Permissions");
2601        }
2602    }
2603
2604    public void addPermissions(long pk, long[] permissionPKs)
2605        throws SystemException {
2606        try {
2607            for (long permissionPK : permissionPKs) {
2608                addPermission.add(pk, permissionPK);
2609            }
2610        }
2611        catch (Exception e) {
2612            throw processException(e);
2613        }
2614        finally {
2615            FinderCacheUtil.clearCache("Roles_Permissions");
2616        }
2617    }
2618
2619    public void addPermissions(long pk,
2620        List<com.liferay.portal.model.Permission> permissions)
2621        throws SystemException {
2622        try {
2623            for (com.liferay.portal.model.Permission permission : permissions) {
2624                addPermission.add(pk, permission.getPrimaryKey());
2625            }
2626        }
2627        catch (Exception e) {
2628            throw processException(e);
2629        }
2630        finally {
2631            FinderCacheUtil.clearCache("Roles_Permissions");
2632        }
2633    }
2634
2635    public void clearPermissions(long pk) throws SystemException {
2636        try {
2637            clearPermissions.clear(pk);
2638        }
2639        catch (Exception e) {
2640            throw processException(e);
2641        }
2642        finally {
2643            FinderCacheUtil.clearCache("Roles_Permissions");
2644        }
2645    }
2646
2647    public void removePermission(long pk, long permissionPK)
2648        throws SystemException {
2649        try {
2650            removePermission.remove(pk, permissionPK);
2651        }
2652        catch (Exception e) {
2653            throw processException(e);
2654        }
2655        finally {
2656            FinderCacheUtil.clearCache("Roles_Permissions");
2657        }
2658    }
2659
2660    public void removePermission(long pk,
2661        com.liferay.portal.model.Permission permission)
2662        throws SystemException {
2663        try {
2664            removePermission.remove(pk, permission.getPrimaryKey());
2665        }
2666        catch (Exception e) {
2667            throw processException(e);
2668        }
2669        finally {
2670            FinderCacheUtil.clearCache("Roles_Permissions");
2671        }
2672    }
2673
2674    public void removePermissions(long pk, long[] permissionPKs)
2675        throws SystemException {
2676        try {
2677            for (long permissionPK : permissionPKs) {
2678                removePermission.remove(pk, permissionPK);
2679            }
2680        }
2681        catch (Exception e) {
2682            throw processException(e);
2683        }
2684        finally {
2685            FinderCacheUtil.clearCache("Roles_Permissions");
2686        }
2687    }
2688
2689    public void removePermissions(long pk,
2690        List<com.liferay.portal.model.Permission> permissions)
2691        throws SystemException {
2692        try {
2693            for (com.liferay.portal.model.Permission permission : permissions) {
2694                removePermission.remove(pk, permission.getPrimaryKey());
2695            }
2696        }
2697        catch (Exception e) {
2698            throw processException(e);
2699        }
2700        finally {
2701            FinderCacheUtil.clearCache("Roles_Permissions");
2702        }
2703    }
2704
2705    public void setPermissions(long pk, long[] permissionPKs)
2706        throws SystemException {
2707        try {
2708            Set<Long> permissionPKSet = SetUtil.fromArray(permissionPKs);
2709
2710            List<com.liferay.portal.model.Permission> permissions = getPermissions(pk);
2711
2712            for (com.liferay.portal.model.Permission permission : permissions) {
2713                if (!permissionPKSet.contains(permission.getPrimaryKey())) {
2714                    removePermission.remove(pk, permission.getPrimaryKey());
2715                }
2716                else {
2717                    permissionPKSet.remove(permission.getPrimaryKey());
2718                }
2719            }
2720
2721            for (Long permissionPK : permissionPKSet) {
2722                addPermission.add(pk, permissionPK);
2723            }
2724        }
2725        catch (Exception e) {
2726            throw processException(e);
2727        }
2728        finally {
2729            FinderCacheUtil.clearCache("Roles_Permissions");
2730        }
2731    }
2732
2733    public void setPermissions(long pk,
2734        List<com.liferay.portal.model.Permission> permissions)
2735        throws SystemException {
2736        try {
2737            long[] permissionPKs = new long[permissions.size()];
2738
2739            for (int i = 0; i < permissions.size(); i++) {
2740                com.liferay.portal.model.Permission permission = permissions.get(i);
2741
2742                permissionPKs[i] = permission.getPrimaryKey();
2743            }
2744
2745            setPermissions(pk, permissionPKs);
2746        }
2747        catch (Exception e) {
2748            throw processException(e);
2749        }
2750        finally {
2751            FinderCacheUtil.clearCache("Roles_Permissions");
2752        }
2753    }
2754
2755    public List<com.liferay.portal.model.User> getUsers(long pk)
2756        throws SystemException {
2757        return getUsers(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
2758    }
2759
2760    public List<com.liferay.portal.model.User> getUsers(long pk, int start,
2761        int end) throws SystemException {
2762        return getUsers(pk, start, end, null);
2763    }
2764
2765    public static final FinderPath FINDER_PATH_GET_USERS = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
2766            RoleModelImpl.FINDER_CACHE_ENABLED_USERS_ROLES, "Users_Roles",
2767            "getUsers",
2768            new String[] {
2769                Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
2770                "com.liferay.portal.kernel.util.OrderByComparator"
2771            });
2772
2773    public List<com.liferay.portal.model.User> getUsers(long pk, int start,
2774        int end, OrderByComparator obc) throws SystemException {
2775        Object[] finderArgs = new Object[] {
2776                new Long(pk), String.valueOf(start), String.valueOf(end),
2777                String.valueOf(obc)
2778            };
2779
2780        List<com.liferay.portal.model.User> list = (List<com.liferay.portal.model.User>)FinderCacheUtil.getResult(FINDER_PATH_GET_USERS,
2781                finderArgs, this);
2782
2783        if (list == null) {
2784            Session session = null;
2785
2786            try {
2787                session = openSession();
2788
2789                StringBuilder sb = new StringBuilder();
2790
2791                sb.append(_SQL_GETUSERS);
2792
2793                if (obc != null) {
2794                    sb.append("ORDER BY ");
2795                    sb.append(obc.getOrderBy());
2796                }
2797
2798                String sql = sb.toString();
2799
2800                SQLQuery q = session.createSQLQuery(sql);
2801
2802                q.addEntity("User_",
2803                    com.liferay.portal.model.impl.UserImpl.class);
2804
2805                QueryPos qPos = QueryPos.getInstance(q);
2806
2807                qPos.add(pk);
2808
2809                list = (List<com.liferay.portal.model.User>)QueryUtil.list(q,
2810                        getDialect(), start, end);
2811            }
2812            catch (Exception e) {
2813                throw processException(e);
2814            }
2815            finally {
2816                if (list == null) {
2817                    list = new ArrayList<com.liferay.portal.model.User>();
2818                }
2819
2820                userPersistence.cacheResult(list);
2821
2822                FinderCacheUtil.putResult(FINDER_PATH_GET_USERS, finderArgs,
2823                    list);
2824
2825                closeSession(session);
2826            }
2827        }
2828
2829        return list;
2830    }
2831
2832    public static final FinderPath FINDER_PATH_GET_USERS_SIZE = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
2833            RoleModelImpl.FINDER_CACHE_ENABLED_USERS_ROLES, "Users_Roles",
2834            "getUsersSize", new String[] { Long.class.getName() });
2835
2836    public int getUsersSize(long pk) throws SystemException {
2837        Object[] finderArgs = new Object[] { new Long(pk) };
2838
2839        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_USERS_SIZE,
2840                finderArgs, this);
2841
2842        if (count == null) {
2843            Session session = null;
2844
2845            try {
2846                session = openSession();
2847
2848                SQLQuery q = session.createSQLQuery(_SQL_GETUSERSSIZE);
2849
2850                q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
2851
2852                QueryPos qPos = QueryPos.getInstance(q);
2853
2854                qPos.add(pk);
2855
2856                count = (Long)q.uniqueResult();
2857            }
2858            catch (Exception e) {
2859                throw processException(e);
2860            }
2861            finally {
2862                if (count == null) {
2863                    count = Long.valueOf(0);
2864                }
2865
2866                FinderCacheUtil.putResult(FINDER_PATH_GET_USERS_SIZE,
2867                    finderArgs, count);
2868
2869                closeSession(session);
2870            }
2871        }
2872
2873        return count.intValue();
2874    }
2875
2876    public static final FinderPath FINDER_PATH_CONTAINS_USER = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
2877            RoleModelImpl.FINDER_CACHE_ENABLED_USERS_ROLES, "Users_Roles",
2878            "containsUser",
2879            new String[] { Long.class.getName(), Long.class.getName() });
2880
2881    public boolean containsUser(long pk, long userPK) throws SystemException {
2882        Object[] finderArgs = new Object[] { new Long(pk), new Long(userPK) };
2883
2884        Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_USER,
2885                finderArgs, this);
2886
2887        if (value == null) {
2888            try {
2889                value = Boolean.valueOf(containsUser.contains(pk, userPK));
2890            }
2891            catch (Exception e) {
2892                throw processException(e);
2893            }
2894            finally {
2895                if (value == null) {
2896                    value = Boolean.FALSE;
2897                }
2898
2899                FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_USER,
2900                    finderArgs, value);
2901            }
2902        }
2903
2904        return value.booleanValue();
2905    }
2906
2907    public boolean containsUsers(long pk) throws SystemException {
2908        if (getUsersSize(pk) > 0) {
2909            return true;
2910        }
2911        else {
2912            return false;
2913        }
2914    }
2915
2916    public void addUser(long pk, long userPK) throws SystemException {
2917        try {
2918            addUser.add(pk, userPK);
2919        }
2920        catch (Exception e) {
2921            throw processException(e);
2922        }
2923        finally {
2924            FinderCacheUtil.clearCache("Users_Roles");
2925        }
2926    }
2927
2928    public void addUser(long pk, com.liferay.portal.model.User user)
2929        throws SystemException {
2930        try {
2931            addUser.add(pk, user.getPrimaryKey());
2932        }
2933        catch (Exception e) {
2934            throw processException(e);
2935        }
2936        finally {
2937            FinderCacheUtil.clearCache("Users_Roles");
2938        }
2939    }
2940
2941    public void addUsers(long pk, long[] userPKs) throws SystemException {
2942        try {
2943            for (long userPK : userPKs) {
2944                addUser.add(pk, userPK);
2945            }
2946        }
2947        catch (Exception e) {
2948            throw processException(e);
2949        }
2950        finally {
2951            FinderCacheUtil.clearCache("Users_Roles");
2952        }
2953    }
2954
2955    public void addUsers(long pk, List<com.liferay.portal.model.User> users)
2956        throws SystemException {
2957        try {
2958            for (com.liferay.portal.model.User user : users) {
2959                addUser.add(pk, user.getPrimaryKey());
2960            }
2961        }
2962        catch (Exception e) {
2963            throw processException(e);
2964        }
2965        finally {
2966            FinderCacheUtil.clearCache("Users_Roles");
2967        }
2968    }
2969
2970    public void clearUsers(long pk) throws SystemException {
2971        try {
2972            clearUsers.clear(pk);
2973        }
2974        catch (Exception e) {
2975            throw processException(e);
2976        }
2977        finally {
2978            FinderCacheUtil.clearCache("Users_Roles");
2979        }
2980    }
2981
2982    public void removeUser(long pk, long userPK) throws SystemException {
2983        try {
2984            removeUser.remove(pk, userPK);
2985        }
2986        catch (Exception e) {
2987            throw processException(e);
2988        }
2989        finally {
2990            FinderCacheUtil.clearCache("Users_Roles");
2991        }
2992    }
2993
2994    public void removeUser(long pk, com.liferay.portal.model.User user)
2995        throws SystemException {
2996        try {
2997            removeUser.remove(pk, user.getPrimaryKey());
2998        }
2999        catch (Exception e) {
3000            throw processException(e);
3001        }
3002        finally {
3003            FinderCacheUtil.clearCache("Users_Roles");
3004        }
3005    }
3006
3007    public void removeUsers(long pk, long[] userPKs) throws SystemException {
3008        try {
3009            for (long userPK : userPKs) {
3010                removeUser.remove(pk, userPK);
3011            }
3012        }
3013        catch (Exception e) {
3014            throw processException(e);
3015        }
3016        finally {
3017            FinderCacheUtil.clearCache("Users_Roles");
3018        }
3019    }
3020
3021    public void removeUsers(long pk, List<com.liferay.portal.model.User> users)
3022        throws SystemException {
3023        try {
3024            for (com.liferay.portal.model.User user : users) {
3025                removeUser.remove(pk, user.getPrimaryKey());
3026            }
3027        }
3028        catch (Exception e) {
3029            throw processException(e);
3030        }
3031        finally {
3032            FinderCacheUtil.clearCache("Users_Roles");
3033        }
3034    }
3035
3036    public void setUsers(long pk, long[] userPKs) throws SystemException {
3037        try {
3038            Set<Long> userPKSet = SetUtil.fromArray(userPKs);
3039
3040            List<com.liferay.portal.model.User> users = getUsers(pk);
3041
3042            for (com.liferay.portal.model.User user : users) {
3043                if (!userPKSet.contains(user.getPrimaryKey())) {
3044                    removeUser.remove(pk, user.getPrimaryKey());
3045                }
3046                else {
3047                    userPKSet.remove(user.getPrimaryKey());
3048                }
3049            }
3050
3051            for (Long userPK : userPKSet) {
3052                addUser.add(pk, userPK);
3053            }
3054        }
3055        catch (Exception e) {
3056            throw processException(e);
3057        }
3058        finally {
3059            FinderCacheUtil.clearCache("Users_Roles");
3060        }
3061    }
3062
3063    public void setUsers(long pk, List<com.liferay.portal.model.User> users)
3064        throws SystemException {
3065        try {
3066            long[] userPKs = new long[users.size()];
3067
3068            for (int i = 0; i < users.size(); i++) {
3069                com.liferay.portal.model.User user = users.get(i);
3070
3071                userPKs[i] = user.getPrimaryKey();
3072            }
3073
3074            setUsers(pk, userPKs);
3075        }
3076        catch (Exception e) {
3077            throw processException(e);
3078        }
3079        finally {
3080            FinderCacheUtil.clearCache("Users_Roles");
3081        }
3082    }
3083
3084    public void afterPropertiesSet() {
3085        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
3086                    com.liferay.portal.util.PropsUtil.get(
3087                        "value.object.listener.com.liferay.portal.model.Role")));
3088
3089        if (listenerClassNames.length > 0) {
3090            try {
3091                List<ModelListener<Role>> listenersList = new ArrayList<ModelListener<Role>>();
3092
3093                for (String listenerClassName : listenerClassNames) {
3094                    listenersList.add((ModelListener<Role>)Class.forName(
3095                            listenerClassName).newInstance());
3096                }
3097
3098                listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
3099            }
3100            catch (Exception e) {
3101                _log.error(e);
3102            }
3103        }
3104
3105        containsGroup = new ContainsGroup(this);
3106
3107        addGroup = new AddGroup(this);
3108        clearGroups = new ClearGroups(this);
3109        removeGroup = new RemoveGroup(this);
3110
3111        containsPermission = new ContainsPermission(this);
3112
3113        addPermission = new AddPermission(this);
3114        clearPermissions = new ClearPermissions(this);
3115        removePermission = new RemovePermission(this);
3116
3117        containsUser = new ContainsUser(this);
3118
3119        addUser = new AddUser(this);
3120        clearUsers = new ClearUsers(this);
3121        removeUser = new RemoveUser(this);
3122    }
3123
3124    @BeanReference(name = "com.liferay.portal.service.persistence.AccountPersistence.impl")
3125    protected com.liferay.portal.service.persistence.AccountPersistence accountPersistence;
3126    @BeanReference(name = "com.liferay.portal.service.persistence.AddressPersistence.impl")
3127    protected com.liferay.portal.service.persistence.AddressPersistence addressPersistence;
3128    @BeanReference(name = "com.liferay.portal.service.persistence.BrowserTrackerPersistence.impl")
3129    protected com.liferay.portal.service.persistence.BrowserTrackerPersistence browserTrackerPersistence;
3130    @BeanReference(name = "com.liferay.portal.service.persistence.ClassNamePersistence.impl")
3131    protected com.liferay.portal.service.persistence.ClassNamePersistence classNamePersistence;
3132    @BeanReference(name = "com.liferay.portal.service.persistence.CompanyPersistence.impl")
3133    protected com.liferay.portal.service.persistence.CompanyPersistence companyPersistence;
3134    @BeanReference(name = "com.liferay.portal.service.persistence.ContactPersistence.impl")
3135    protected com.liferay.portal.service.persistence.ContactPersistence contactPersistence;
3136    @BeanReference(name = "com.liferay.portal.service.persistence.CountryPersistence.impl")
3137    protected com.liferay.portal.service.persistence.CountryPersistence countryPersistence;
3138    @BeanReference(name = "com.liferay.portal.service.persistence.EmailAddressPersistence.impl")
3139    protected com.liferay.portal.service.persistence.EmailAddressPersistence emailAddressPersistence;
3140    @BeanReference(name = "com.liferay.portal.service.persistence.GroupPersistence.impl")
3141    protected com.liferay.portal.service.persistence.GroupPersistence groupPersistence;
3142    @BeanReference(name = "com.liferay.portal.service.persistence.ImagePersistence.impl")
3143    protected com.liferay.portal.service.persistence.ImagePersistence imagePersistence;
3144    @BeanReference(name = "com.liferay.portal.service.persistence.LayoutPersistence.impl")
3145    protected com.liferay.portal.service.persistence.LayoutPersistence layoutPersistence;
3146    @BeanReference(name = "com.liferay.portal.service.persistence.LayoutSetPersistence.impl")
3147    protected com.liferay.portal.service.persistence.LayoutSetPersistence layoutSetPersistence;
3148    @BeanReference(name = "com.liferay.portal.service.persistence.ListTypePersistence.impl")
3149    protected com.liferay.portal.service.persistence.ListTypePersistence listTypePersistence;
3150    @BeanReference(name = "com.liferay.portal.service.persistence.LockPersistence.impl")
3151    protected com.liferay.portal.service.persistence.LockPersistence lockPersistence;
3152    @BeanReference(name = "com.liferay.portal.service.persistence.MembershipRequestPersistence.impl")
3153    protected com.liferay.portal.service.persistence.MembershipRequestPersistence membershipRequestPersistence;
3154    @BeanReference(name = "com.liferay.portal.service.persistence.OrganizationPersistence.impl")
3155    protected com.liferay.portal.service.persistence.OrganizationPersistence organizationPersistence;
3156    @BeanReference(name = "com.liferay.portal.service.persistence.OrgGroupPermissionPersistence.impl")
3157    protected com.liferay.portal.service.persistence.OrgGroupPermissionPersistence orgGroupPermissionPersistence;
3158    @BeanReference(name = "com.liferay.portal.service.persistence.OrgGroupRolePersistence.impl")
3159    protected com.liferay.portal.service.persistence.OrgGroupRolePersistence orgGroupRolePersistence;
3160    @BeanReference(name = "com.liferay.portal.service.persistence.OrgLaborPersistence.impl")
3161    protected com.liferay.portal.service.persistence.OrgLaborPersistence orgLaborPersistence;
3162    @BeanReference(name = "com.liferay.portal.service.persistence.PasswordPolicyPersistence.impl")
3163    protected com.liferay.portal.service.persistence.PasswordPolicyPersistence passwordPolicyPersistence;
3164    @BeanReference(name = "com.liferay.portal.service.persistence.PasswordPolicyRelPersistence.impl")
3165    protected com.liferay.portal.service.persistence.PasswordPolicyRelPersistence passwordPolicyRelPersistence;
3166    @BeanReference(name = "com.liferay.portal.service.persistence.PasswordTrackerPersistence.impl")
3167    protected com.liferay.portal.service.persistence.PasswordTrackerPersistence passwordTrackerPersistence;
3168    @BeanReference(name = "com.liferay.portal.service.persistence.PermissionPersistence.impl")
3169    protected com.liferay.portal.service.persistence.PermissionPersistence permissionPersistence;
3170    @BeanReference(name = "com.liferay.portal.service.persistence.PhonePersistence.impl")
3171    protected com.liferay.portal.service.persistence.PhonePersistence phonePersistence;
3172    @BeanReference(name = "com.liferay.portal.service.persistence.PluginSettingPersistence.impl")
3173    protected com.liferay.portal.service.persistence.PluginSettingPersistence pluginSettingPersistence;
3174    @BeanReference(name = "com.liferay.portal.service.persistence.PortletPersistence.impl")
3175    protected com.liferay.portal.service.persistence.PortletPersistence portletPersistence;
3176    @BeanReference(name = "com.liferay.portal.service.persistence.PortletItemPersistence.impl")
3177    protected com.liferay.portal.service.persistence.PortletItemPersistence portletItemPersistence;
3178    @BeanReference(name = "com.liferay.portal.service.persistence.PortletPreferencesPersistence.impl")
3179    protected com.liferay.portal.service.persistence.PortletPreferencesPersistence portletPreferencesPersistence;
3180    @BeanReference(name = "com.liferay.portal.service.persistence.RegionPersistence.impl")
3181    protected com.liferay.portal.service.persistence.RegionPersistence regionPersistence;
3182    @BeanReference(name = "com.liferay.portal.service.persistence.ReleasePersistence.impl")
3183    protected com.liferay.portal.service.persistence.ReleasePersistence releasePersistence;
3184    @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePersistence.impl")
3185    protected com.liferay.portal.service.persistence.ResourcePersistence resourcePersistence;
3186    @BeanReference(name = "com.liferay.portal.service.persistence.ResourceActionPersistence.impl")
3187    protected com.liferay.portal.service.persistence.ResourceActionPersistence resourceActionPersistence;
3188    @BeanReference(name = "com.liferay.portal.service.persistence.ResourceCodePersistence.impl")
3189    protected com.liferay.portal.service.persistence.ResourceCodePersistence resourceCodePersistence;
3190    @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePermissionPersistence.impl")
3191    protected com.liferay.portal.service.persistence.ResourcePermissionPersistence resourcePermissionPersistence;
3192    @BeanReference(name = "com.liferay.portal.service.persistence.RolePersistence.impl")
3193    protected com.liferay.portal.service.persistence.RolePersistence rolePersistence;
3194    @BeanReference(name = "com.liferay.portal.service.persistence.ServiceComponentPersistence.impl")
3195    protected com.liferay.portal.service.persistence.ServiceComponentPersistence serviceComponentPersistence;
3196    @BeanReference(name = "com.liferay.portal.service.persistence.ShardPersistence.impl")
3197    protected com.liferay.portal.service.persistence.ShardPersistence shardPersistence;
3198    @BeanReference(name = "com.liferay.portal.service.persistence.SubscriptionPersistence.impl")
3199    protected com.liferay.portal.service.persistence.SubscriptionPersistence subscriptionPersistence;
3200    @BeanReference(name = "com.liferay.portal.service.persistence.UserPersistence.impl")
3201    protected com.liferay.portal.service.persistence.UserPersistence userPersistence;
3202    @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupPersistence.impl")
3203    protected com.liferay.portal.service.persistence.UserGroupPersistence userGroupPersistence;
3204    @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupGroupRolePersistence.impl")
3205    protected com.liferay.portal.service.persistence.UserGroupGroupRolePersistence userGroupGroupRolePersistence;
3206    @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupRolePersistence.impl")
3207    protected com.liferay.portal.service.persistence.UserGroupRolePersistence userGroupRolePersistence;
3208    @BeanReference(name = "com.liferay.portal.service.persistence.UserIdMapperPersistence.impl")
3209    protected com.liferay.portal.service.persistence.UserIdMapperPersistence userIdMapperPersistence;
3210    @BeanReference(name = "com.liferay.portal.service.persistence.UserTrackerPersistence.impl")
3211    protected com.liferay.portal.service.persistence.UserTrackerPersistence userTrackerPersistence;
3212    @BeanReference(name = "com.liferay.portal.service.persistence.UserTrackerPathPersistence.impl")
3213    protected com.liferay.portal.service.persistence.UserTrackerPathPersistence userTrackerPathPersistence;
3214    @BeanReference(name = "com.liferay.portal.service.persistence.WebDAVPropsPersistence.impl")
3215    protected com.liferay.portal.service.persistence.WebDAVPropsPersistence webDAVPropsPersistence;
3216    @BeanReference(name = "com.liferay.portal.service.persistence.WebsitePersistence.impl")
3217    protected com.liferay.portal.service.persistence.WebsitePersistence websitePersistence;
3218    protected ContainsGroup containsGroup;
3219    protected AddGroup addGroup;
3220    protected ClearGroups clearGroups;
3221    protected RemoveGroup removeGroup;
3222    protected ContainsPermission containsPermission;
3223    protected AddPermission addPermission;
3224    protected ClearPermissions clearPermissions;
3225    protected RemovePermission removePermission;
3226    protected ContainsUser containsUser;
3227    protected AddUser addUser;
3228    protected ClearUsers clearUsers;
3229    protected RemoveUser removeUser;
3230
3231    protected class ContainsGroup {
3232        protected ContainsGroup(RolePersistenceImpl persistenceImpl) {
3233            super();
3234
3235            _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
3236                    _SQL_CONTAINSGROUP,
3237                    new int[] { Types.BIGINT, Types.BIGINT }, RowMapper.COUNT);
3238        }
3239
3240        protected boolean contains(long roleId, long groupId) {
3241            List<Integer> results = _mappingSqlQuery.execute(new Object[] {
3242                        new Long(roleId), new Long(groupId)
3243                    });
3244
3245            if (results.size() > 0) {
3246                Integer count = results.get(0);
3247
3248                if (count.intValue() > 0) {
3249                    return true;
3250                }
3251            }
3252
3253            return false;
3254        }
3255
3256        private MappingSqlQuery _mappingSqlQuery;
3257    }
3258
3259    protected class AddGroup {
3260        protected AddGroup(RolePersistenceImpl persistenceImpl) {
3261            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
3262                    "INSERT INTO Groups_Roles (roleId, groupId) VALUES (?, ?)",
3263                    new int[] { Types.BIGINT, Types.BIGINT });
3264            _persistenceImpl = persistenceImpl;
3265        }
3266
3267        protected void add(long roleId, long groupId) throws SystemException {
3268            if (!_persistenceImpl.containsGroup.contains(roleId, groupId)) {
3269                ModelListener<com.liferay.portal.model.Group>[] groupListeners = groupPersistence.getListeners();
3270
3271                for (ModelListener<Role> listener : listeners) {
3272                    listener.onBeforeAddAssociation(roleId,
3273                        com.liferay.portal.model.Group.class.getName(), groupId);
3274                }
3275
3276                for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
3277                    listener.onBeforeAddAssociation(groupId,
3278                        Role.class.getName(), roleId);
3279                }
3280
3281                _sqlUpdate.update(new Object[] {
3282                        new Long(roleId), new Long(groupId)
3283                    });
3284
3285                for (ModelListener<Role> listener : listeners) {
3286                    listener.onAfterAddAssociation(roleId,
3287                        com.liferay.portal.model.Group.class.getName(), groupId);
3288                }
3289
3290                for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
3291                    listener.onAfterAddAssociation(groupId,
3292                        Role.class.getName(), roleId);
3293                }
3294            }
3295        }
3296
3297        private SqlUpdate _sqlUpdate;
3298        private RolePersistenceImpl _persistenceImpl;
3299    }
3300
3301    protected class ClearGroups {
3302        protected ClearGroups(RolePersistenceImpl persistenceImpl) {
3303            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
3304                    "DELETE FROM Groups_Roles WHERE roleId = ?",
3305                    new int[] { Types.BIGINT });
3306        }
3307
3308        protected void clear(long roleId) throws SystemException {
3309            ModelListener<com.liferay.portal.model.Group>[] groupListeners = groupPersistence.getListeners();
3310
3311            List<com.liferay.portal.model.Group> groups = null;
3312
3313            if ((listeners.length > 0) || (groupListeners.length > 0)) {
3314                groups = getGroups(roleId);
3315
3316                for (com.liferay.portal.model.Group group : groups) {
3317                    for (ModelListener<Role> listener : listeners) {
3318                        listener.onBeforeRemoveAssociation(roleId,
3319                            com.liferay.portal.model.Group.class.getName(),
3320                            group.getPrimaryKey());
3321                    }
3322
3323                    for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
3324                        listener.onBeforeRemoveAssociation(group.getPrimaryKey(),
3325                            Role.class.getName(), roleId);
3326                    }
3327                }
3328            }
3329
3330            _sqlUpdate.update(new Object[] { new Long(roleId) });
3331
3332            if ((listeners.length > 0) || (groupListeners.length > 0)) {
3333                for (com.liferay.portal.model.Group group : groups) {
3334                    for (ModelListener<Role> listener : listeners) {
3335                        listener.onAfterRemoveAssociation(roleId,
3336                            com.liferay.portal.model.Group.class.getName(),
3337                            group.getPrimaryKey());
3338                    }
3339
3340                    for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
3341                        listener.onAfterRemoveAssociation(group.getPrimaryKey(),
3342                            Role.class.getName(), roleId);
3343                    }
3344                }
3345            }
3346        }
3347
3348        private SqlUpdate _sqlUpdate;
3349    }
3350
3351    protected class RemoveGroup {
3352        protected RemoveGroup(RolePersistenceImpl persistenceImpl) {
3353            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
3354                    "DELETE FROM Groups_Roles WHERE roleId = ? AND groupId = ?",
3355                    new int[] { Types.BIGINT, Types.BIGINT });
3356            _persistenceImpl = persistenceImpl;
3357        }
3358
3359        protected void remove(long roleId, long groupId)
3360            throws SystemException {
3361            if (_persistenceImpl.containsGroup.contains(roleId, groupId)) {
3362                ModelListener<com.liferay.portal.model.Group>[] groupListeners = groupPersistence.getListeners();
3363
3364                for (ModelListener<Role> listener : listeners) {
3365                    listener.onBeforeRemoveAssociation(roleId,
3366                        com.liferay.portal.model.Group.class.getName(), groupId);
3367                }
3368
3369                for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
3370                    listener.onBeforeRemoveAssociation(groupId,
3371                        Role.class.getName(), roleId);
3372                }
3373
3374                _sqlUpdate.update(new Object[] {
3375                        new Long(roleId), new Long(groupId)
3376                    });
3377
3378                for (ModelListener<Role> listener : listeners) {
3379                    listener.onAfterRemoveAssociation(roleId,
3380                        com.liferay.portal.model.Group.class.getName(), groupId);
3381                }
3382
3383                for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
3384                    listener.onAfterRemoveAssociation(groupId,
3385                        Role.class.getName(), roleId);
3386                }
3387            }
3388        }
3389
3390        private SqlUpdate _sqlUpdate;
3391        private RolePersistenceImpl _persistenceImpl;
3392    }
3393
3394    protected class ContainsPermission {
3395        protected ContainsPermission(RolePersistenceImpl persistenceImpl) {
3396            super();
3397
3398            _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
3399                    _SQL_CONTAINSPERMISSION,
3400                    new int[] { Types.BIGINT, Types.BIGINT }, RowMapper.COUNT);
3401        }
3402
3403        protected boolean contains(long roleId, long permissionId) {
3404            List<Integer> results = _mappingSqlQuery.execute(new Object[] {
3405                        new Long(roleId), new Long(permissionId)
3406                    });
3407
3408            if (results.size() > 0) {
3409                Integer count = results.get(0);
3410
3411                if (count.intValue() > 0) {
3412                    return true;
3413                }
3414            }
3415
3416            return false;
3417        }
3418
3419        private MappingSqlQuery _mappingSqlQuery;
3420    }
3421
3422    protected class AddPermission {
3423        protected AddPermission(RolePersistenceImpl persistenceImpl) {
3424            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
3425                    "INSERT INTO Roles_Permissions (roleId, permissionId) VALUES (?, ?)",
3426                    new int[] { Types.BIGINT, Types.BIGINT });
3427            _persistenceImpl = persistenceImpl;
3428        }
3429
3430        protected void add(long roleId, long permissionId)
3431            throws SystemException {
3432            if (!_persistenceImpl.containsPermission.contains(roleId,
3433                        permissionId)) {
3434                ModelListener<com.liferay.portal.model.Permission>[] permissionListeners =
3435                    permissionPersistence.getListeners();
3436
3437                for (ModelListener<Role> listener : listeners) {
3438                    listener.onBeforeAddAssociation(roleId,
3439                        com.liferay.portal.model.Permission.class.getName(),
3440                        permissionId);
3441                }
3442
3443                for (ModelListener<com.liferay.portal.model.Permission> listener : permissionListeners) {
3444                    listener.onBeforeAddAssociation(permissionId,
3445                        Role.class.getName(), roleId);
3446                }
3447
3448                _sqlUpdate.update(new Object[] {
3449                        new Long(roleId), new Long(permissionId)
3450                    });
3451
3452                for (ModelListener<Role> listener : listeners) {
3453                    listener.onAfterAddAssociation(roleId,
3454                        com.liferay.portal.model.Permission.class.getName(),
3455                        permissionId);
3456                }
3457
3458                for (ModelListener<com.liferay.portal.model.Permission> listener : permissionListeners) {
3459                    listener.onAfterAddAssociation(permissionId,
3460                        Role.class.getName(), roleId);
3461                }
3462            }
3463        }
3464
3465        private SqlUpdate _sqlUpdate;
3466        private RolePersistenceImpl _persistenceImpl;
3467    }
3468
3469    protected class ClearPermissions {
3470        protected ClearPermissions(RolePersistenceImpl persistenceImpl) {
3471            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
3472                    "DELETE FROM Roles_Permissions WHERE roleId = ?",
3473                    new int[] { Types.BIGINT });
3474        }
3475
3476        protected void clear(long roleId) throws SystemException {
3477            ModelListener<com.liferay.portal.model.Permission>[] permissionListeners =
3478                permissionPersistence.getListeners();
3479
3480            List<com.liferay.portal.model.Permission> permissions = null;
3481
3482            if ((listeners.length > 0) || (permissionListeners.length > 0)) {
3483                permissions = getPermissions(roleId);
3484
3485                for (com.liferay.portal.model.Permission permission : permissions) {
3486                    for (ModelListener<Role> listener : listeners) {
3487                        listener.onBeforeRemoveAssociation(roleId,
3488                            com.liferay.portal.model.Permission.class.getName(),
3489                            permission.getPrimaryKey());
3490                    }
3491
3492                    for (ModelListener<com.liferay.portal.model.Permission> listener : permissionListeners) {
3493                        listener.onBeforeRemoveAssociation(permission.getPrimaryKey(),
3494                            Role.class.getName(), roleId);
3495                    }
3496                }
3497            }
3498
3499            _sqlUpdate.update(new Object[] { new Long(roleId) });
3500
3501            if ((listeners.length > 0) || (permissionListeners.length > 0)) {
3502                for (com.liferay.portal.model.Permission permission : permissions) {
3503                    for (ModelListener<Role> listener : listeners) {
3504                        listener.onAfterRemoveAssociation(roleId,
3505                            com.liferay.portal.model.Permission.class.getName(),
3506                            permission.getPrimaryKey());
3507                    }
3508
3509                    for (ModelListener<com.liferay.portal.model.Permission> listener : permissionListeners) {
3510                        listener.onAfterRemoveAssociation(permission.getPrimaryKey(),
3511                            Role.class.getName(), roleId);
3512                    }
3513                }
3514            }
3515        }
3516
3517        private SqlUpdate _sqlUpdate;
3518    }
3519
3520    protected class RemovePermission {
3521        protected RemovePermission(RolePersistenceImpl persistenceImpl) {
3522            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
3523                    "DELETE FROM Roles_Permissions WHERE roleId = ? AND permissionId = ?",
3524                    new int[] { Types.BIGINT, Types.BIGINT });
3525            _persistenceImpl = persistenceImpl;
3526        }
3527
3528        protected void remove(long roleId, long permissionId)
3529            throws SystemException {
3530            if (_persistenceImpl.containsPermission.contains(roleId,
3531                        permissionId)) {
3532                ModelListener<com.liferay.portal.model.Permission>[] permissionListeners =
3533                    permissionPersistence.getListeners();
3534
3535                for (ModelListener<Role> listener : listeners) {
3536                    listener.onBeforeRemoveAssociation(roleId,
3537                        com.liferay.portal.model.Permission.class.getName(),
3538                        permissionId);
3539                }
3540
3541                for (ModelListener<com.liferay.portal.model.Permission> listener : permissionListeners) {
3542                    listener.onBeforeRemoveAssociation(permissionId,
3543                        Role.class.getName(), roleId);
3544                }
3545
3546                _sqlUpdate.update(new Object[] {
3547                        new Long(roleId), new Long(permissionId)
3548                    });
3549
3550                for (ModelListener<Role> listener : listeners) {
3551                    listener.onAfterRemoveAssociation(roleId,
3552                        com.liferay.portal.model.Permission.class.getName(),
3553                        permissionId);
3554                }
3555
3556                for (ModelListener<com.liferay.portal.model.Permission> listener : permissionListeners) {
3557                    listener.onAfterRemoveAssociation(permissionId,
3558                        Role.class.getName(), roleId);
3559                }
3560            }
3561        }
3562
3563        private SqlUpdate _sqlUpdate;
3564        private RolePersistenceImpl _persistenceImpl;
3565    }
3566
3567    protected class ContainsUser {
3568        protected ContainsUser(RolePersistenceImpl persistenceImpl) {
3569            super();
3570
3571            _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
3572                    _SQL_CONTAINSUSER,
3573                    new int[] { Types.BIGINT, Types.BIGINT }, RowMapper.COUNT);
3574        }
3575
3576        protected boolean contains(long roleId, long userId) {
3577            List<Integer> results = _mappingSqlQuery.execute(new Object[] {
3578                        new Long(roleId), new Long(userId)
3579                    });
3580
3581            if (results.size() > 0) {
3582                Integer count = results.get(0);
3583
3584                if (count.intValue() > 0) {
3585                    return true;
3586                }
3587            }
3588
3589            return false;
3590        }
3591
3592        private MappingSqlQuery _mappingSqlQuery;
3593    }
3594
3595    protected class AddUser {
3596        protected AddUser(RolePersistenceImpl persistenceImpl) {
3597            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
3598                    "INSERT INTO Users_Roles (roleId, userId) VALUES (?, ?)",
3599                    new int[] { Types.BIGINT, Types.BIGINT });
3600            _persistenceImpl = persistenceImpl;
3601        }
3602
3603        protected void add(long roleId, long userId) throws SystemException {
3604            if (!_persistenceImpl.containsUser.contains(roleId, userId)) {
3605                ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
3606
3607                for (ModelListener<Role> listener : listeners) {
3608                    listener.onBeforeAddAssociation(roleId,
3609                        com.liferay.portal.model.User.class.getName(), userId);
3610                }
3611
3612                for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
3613                    listener.onBeforeAddAssociation(userId,
3614                        Role.class.getName(), roleId);
3615                }
3616
3617                _sqlUpdate.update(new Object[] {
3618                        new Long(roleId), new Long(userId)
3619                    });
3620
3621                for (ModelListener<Role> listener : listeners) {
3622                    listener.onAfterAddAssociation(roleId,
3623                        com.liferay.portal.model.User.class.getName(), userId);
3624                }
3625
3626                for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
3627                    listener.onAfterAddAssociation(userId,
3628                        Role.class.getName(), roleId);
3629                }
3630            }
3631        }
3632
3633        private SqlUpdate _sqlUpdate;
3634        private RolePersistenceImpl _persistenceImpl;
3635    }
3636
3637    protected class ClearUsers {
3638        protected ClearUsers(RolePersistenceImpl persistenceImpl) {
3639            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
3640                    "DELETE FROM Users_Roles WHERE roleId = ?",
3641                    new int[] { Types.BIGINT });
3642        }
3643
3644        protected void clear(long roleId) throws SystemException {
3645            ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
3646
3647            List<com.liferay.portal.model.User> users = null;
3648
3649            if ((listeners.length > 0) || (userListeners.length > 0)) {
3650                users = getUsers(roleId);
3651
3652                for (com.liferay.portal.model.User user : users) {
3653                    for (ModelListener<Role> listener : listeners) {
3654                        listener.onBeforeRemoveAssociation(roleId,
3655                            com.liferay.portal.model.User.class.getName(),
3656                            user.getPrimaryKey());
3657                    }
3658
3659                    for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
3660                        listener.onBeforeRemoveAssociation(user.getPrimaryKey(),
3661                            Role.class.getName(), roleId);
3662                    }
3663                }
3664            }
3665
3666            _sqlUpdate.update(new Object[] { new Long(roleId) });
3667
3668            if ((listeners.length > 0) || (userListeners.length > 0)) {
3669                for (com.liferay.portal.model.User user : users) {
3670                    for (ModelListener<Role> listener : listeners) {
3671                        listener.onAfterRemoveAssociation(roleId,
3672                            com.liferay.portal.model.User.class.getName(),
3673                            user.getPrimaryKey());
3674                    }
3675
3676                    for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
3677                        listener.onAfterRemoveAssociation(user.getPrimaryKey(),
3678                            Role.class.getName(), roleId);
3679                    }
3680                }
3681            }
3682        }
3683
3684        private SqlUpdate _sqlUpdate;
3685    }
3686
3687    protected class RemoveUser {
3688        protected RemoveUser(RolePersistenceImpl persistenceImpl) {
3689            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
3690                    "DELETE FROM Users_Roles WHERE roleId = ? AND userId = ?",
3691                    new int[] { Types.BIGINT, Types.BIGINT });
3692            _persistenceImpl = persistenceImpl;
3693        }
3694
3695        protected void remove(long roleId, long userId)
3696            throws SystemException {
3697            if (_persistenceImpl.containsUser.contains(roleId, userId)) {
3698                ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
3699
3700                for (ModelListener<Role> listener : listeners) {
3701                    listener.onBeforeRemoveAssociation(roleId,
3702                        com.liferay.portal.model.User.class.getName(), userId);
3703                }
3704
3705                for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
3706                    listener.onBeforeRemoveAssociation(userId,
3707                        Role.class.getName(), roleId);
3708                }
3709
3710                _sqlUpdate.update(new Object[] {
3711                        new Long(roleId), new Long(userId)
3712                    });
3713
3714                for (ModelListener<Role> listener : listeners) {
3715                    listener.onAfterRemoveAssociation(roleId,
3716                        com.liferay.portal.model.User.class.getName(), userId);
3717                }
3718
3719                for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
3720                    listener.onAfterRemoveAssociation(userId,
3721                        Role.class.getName(), roleId);
3722                }
3723            }
3724        }
3725
3726        private SqlUpdate _sqlUpdate;
3727        private RolePersistenceImpl _persistenceImpl;
3728    }
3729
3730    private static final String _SQL_GETGROUPS = "SELECT {Group_.*} FROM Group_ INNER JOIN Groups_Roles ON (Groups_Roles.groupId = Group_.groupId) WHERE (Groups_Roles.roleId = ?)";
3731    private static final String _SQL_GETGROUPSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_Roles WHERE roleId = ?";
3732    private static final String _SQL_CONTAINSGROUP = "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_Roles WHERE roleId = ? AND groupId = ?";
3733    private static final String _SQL_GETPERMISSIONS = "SELECT {Permission_.*} FROM Permission_ INNER JOIN Roles_Permissions ON (Roles_Permissions.permissionId = Permission_.permissionId) WHERE (Roles_Permissions.roleId = ?)";
3734    private static final String _SQL_GETPERMISSIONSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Roles_Permissions WHERE roleId = ?";
3735    private static final String _SQL_CONTAINSPERMISSION = "SELECT COUNT(*) AS COUNT_VALUE FROM Roles_Permissions WHERE roleId = ? AND permissionId = ?";
3736    private static final String _SQL_GETUSERS = "SELECT {User_.*} FROM User_ INNER JOIN Users_Roles ON (Users_Roles.userId = User_.userId) WHERE (Users_Roles.roleId = ?)";
3737    private static final String _SQL_GETUSERSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Roles WHERE roleId = ?";
3738    private static final String _SQL_CONTAINSUSER = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Roles WHERE roleId = ? AND userId = ?";
3739    private static Log _log = LogFactoryUtil.getLog(RolePersistenceImpl.class);
3740}