Source Code Cross Referenced for RolePersistenceImpl.java in  » Portal » liferay-portal-4.4.2 » com » liferay » portal » service » persistence » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Portal » liferay portal 4.4.2 » com.liferay.portal.service.persistence 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /**
0002:         * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
0003:         *
0004:         * Permission is hereby granted, free of charge, to any person obtaining a copy
0005:         * of this software and associated documentation files (the "Software"), to deal
0006:         * in the Software without restriction, including without limitation the rights
0007:         * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
0008:         * copies of the Software, and to permit persons to whom the Software is
0009:         * furnished to do so, subject to the following conditions:
0010:         *
0011:         * The above copyright notice and this permission notice shall be included in
0012:         * all copies or substantial portions of the Software.
0013:         *
0014:         * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0015:         * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0016:         * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
0017:         * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
0018:         * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
0019:         * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
0020:         * SOFTWARE.
0021:         */package com.liferay.portal.service.persistence;
0022:
0023:        import com.liferay.portal.NoSuchRoleException;
0024:        import com.liferay.portal.SystemException;
0025:        import com.liferay.portal.kernel.dao.DynamicQuery;
0026:        import com.liferay.portal.kernel.dao.DynamicQueryInitializer;
0027:        import com.liferay.portal.kernel.util.GetterUtil;
0028:        import com.liferay.portal.kernel.util.OrderByComparator;
0029:        import com.liferay.portal.kernel.util.StringMaker;
0030:        import com.liferay.portal.kernel.util.StringPool;
0031:        import com.liferay.portal.kernel.util.Validator;
0032:        import com.liferay.portal.model.ModelListener;
0033:        import com.liferay.portal.model.Role;
0034:        import com.liferay.portal.model.impl.RoleImpl;
0035:        import com.liferay.portal.model.impl.RoleModelImpl;
0036:        import com.liferay.portal.spring.hibernate.FinderCache;
0037:        import com.liferay.portal.spring.hibernate.HibernateUtil;
0038:        import com.liferay.portal.util.PropsUtil;
0039:
0040:        import com.liferay.util.dao.hibernate.QueryPos;
0041:        import com.liferay.util.dao.hibernate.QueryUtil;
0042:
0043:        import org.apache.commons.logging.Log;
0044:        import org.apache.commons.logging.LogFactory;
0045:
0046:        import org.hibernate.Hibernate;
0047:        import org.hibernate.Query;
0048:        import org.hibernate.SQLQuery;
0049:        import org.hibernate.Session;
0050:
0051:        import org.springframework.dao.DataAccessException;
0052:
0053:        import org.springframework.jdbc.core.SqlParameter;
0054:        import org.springframework.jdbc.object.MappingSqlQuery;
0055:        import org.springframework.jdbc.object.SqlUpdate;
0056:
0057:        import java.sql.ResultSet;
0058:        import java.sql.SQLException;
0059:        import java.sql.Types;
0060:
0061:        import java.util.Collections;
0062:        import java.util.Iterator;
0063:        import java.util.List;
0064:
0065:        /**
0066:         * <a href="RolePersistenceImpl.java.html"><b><i>View Source</i></b></a>
0067:         *
0068:         * @author Brian Wing Shun Chan
0069:         *
0070:         */
0071:        public class RolePersistenceImpl extends BasePersistence implements 
0072:                RolePersistence {
0073:            public Role create(long roleId) {
0074:                Role role = new RoleImpl();
0075:
0076:                role.setNew(true);
0077:                role.setPrimaryKey(roleId);
0078:
0079:                return role;
0080:            }
0081:
0082:            public Role remove(long roleId) throws NoSuchRoleException,
0083:                    SystemException {
0084:                Session session = null;
0085:
0086:                try {
0087:                    session = openSession();
0088:
0089:                    Role role = (Role) session.get(RoleImpl.class, new Long(
0090:                            roleId));
0091:
0092:                    if (role == null) {
0093:                        if (_log.isWarnEnabled()) {
0094:                            _log.warn("No Role exists with the primary key "
0095:                                    + roleId);
0096:                        }
0097:
0098:                        throw new NoSuchRoleException(
0099:                                "No Role exists with the primary key " + roleId);
0100:                    }
0101:
0102:                    return remove(role);
0103:                } catch (NoSuchRoleException nsee) {
0104:                    throw nsee;
0105:                } catch (Exception e) {
0106:                    throw HibernateUtil.processException(e);
0107:                } finally {
0108:                    closeSession(session);
0109:                }
0110:            }
0111:
0112:            public Role remove(Role role) throws SystemException {
0113:                ModelListener listener = _getListener();
0114:
0115:                if (listener != null) {
0116:                    listener.onBeforeRemove(role);
0117:                }
0118:
0119:                role = removeImpl(role);
0120:
0121:                if (listener != null) {
0122:                    listener.onAfterRemove(role);
0123:                }
0124:
0125:                return role;
0126:            }
0127:
0128:            protected Role removeImpl(Role role) throws SystemException {
0129:                try {
0130:                    clearGroups.clear(role.getPrimaryKey());
0131:                } catch (Exception e) {
0132:                    throw HibernateUtil.processException(e);
0133:                } finally {
0134:                    FinderCache.clearCache("Groups_Roles");
0135:                }
0136:
0137:                try {
0138:                    clearPermissions.clear(role.getPrimaryKey());
0139:                } catch (Exception e) {
0140:                    throw HibernateUtil.processException(e);
0141:                } finally {
0142:                    FinderCache.clearCache("Roles_Permissions");
0143:                }
0144:
0145:                try {
0146:                    clearUsers.clear(role.getPrimaryKey());
0147:                } catch (Exception e) {
0148:                    throw HibernateUtil.processException(e);
0149:                } finally {
0150:                    FinderCache.clearCache("Users_Roles");
0151:                }
0152:
0153:                Session session = null;
0154:
0155:                try {
0156:                    session = openSession();
0157:
0158:                    session.delete(role);
0159:
0160:                    session.flush();
0161:
0162:                    return role;
0163:                } catch (Exception e) {
0164:                    throw HibernateUtil.processException(e);
0165:                } finally {
0166:                    closeSession(session);
0167:
0168:                    FinderCache.clearCache(Role.class.getName());
0169:                }
0170:            }
0171:
0172:            public Role update(Role role) throws SystemException {
0173:                return update(role, false);
0174:            }
0175:
0176:            public Role update(Role role, boolean merge) throws SystemException {
0177:                ModelListener listener = _getListener();
0178:
0179:                boolean isNew = role.isNew();
0180:
0181:                if (listener != null) {
0182:                    if (isNew) {
0183:                        listener.onBeforeCreate(role);
0184:                    } else {
0185:                        listener.onBeforeUpdate(role);
0186:                    }
0187:                }
0188:
0189:                role = updateImpl(role, merge);
0190:
0191:                if (listener != null) {
0192:                    if (isNew) {
0193:                        listener.onAfterCreate(role);
0194:                    } else {
0195:                        listener.onAfterUpdate(role);
0196:                    }
0197:                }
0198:
0199:                return role;
0200:            }
0201:
0202:            public Role updateImpl(com.liferay.portal.model.Role role,
0203:                    boolean merge) throws SystemException {
0204:                FinderCache.clearCache("Groups_Roles");
0205:                FinderCache.clearCache("Roles_Permissions");
0206:                FinderCache.clearCache("Users_Roles");
0207:
0208:                Session session = null;
0209:
0210:                try {
0211:                    session = openSession();
0212:
0213:                    if (merge) {
0214:                        session.merge(role);
0215:                    } else {
0216:                        if (role.isNew()) {
0217:                            session.save(role);
0218:                        }
0219:                    }
0220:
0221:                    session.flush();
0222:
0223:                    role.setNew(false);
0224:
0225:                    return role;
0226:                } catch (Exception e) {
0227:                    throw HibernateUtil.processException(e);
0228:                } finally {
0229:                    closeSession(session);
0230:
0231:                    FinderCache.clearCache(Role.class.getName());
0232:                }
0233:            }
0234:
0235:            public Role findByPrimaryKey(long roleId)
0236:                    throws NoSuchRoleException, SystemException {
0237:                Role role = fetchByPrimaryKey(roleId);
0238:
0239:                if (role == null) {
0240:                    if (_log.isWarnEnabled()) {
0241:                        _log.warn("No Role exists with the primary key "
0242:                                + roleId);
0243:                    }
0244:
0245:                    throw new NoSuchRoleException(
0246:                            "No Role exists with the primary key " + roleId);
0247:                }
0248:
0249:                return role;
0250:            }
0251:
0252:            public Role fetchByPrimaryKey(long roleId) throws SystemException {
0253:                Session session = null;
0254:
0255:                try {
0256:                    session = openSession();
0257:
0258:                    return (Role) session.get(RoleImpl.class, new Long(roleId));
0259:                } catch (Exception e) {
0260:                    throw HibernateUtil.processException(e);
0261:                } finally {
0262:                    closeSession(session);
0263:                }
0264:            }
0265:
0266:            public List findByCompanyId(long companyId) throws SystemException {
0267:                boolean finderClassNameCacheEnabled = RoleModelImpl.CACHE_ENABLED;
0268:                String finderClassName = Role.class.getName();
0269:                String finderMethodName = "findByCompanyId";
0270:                String[] finderParams = new String[] { Long.class.getName() };
0271:                Object[] finderArgs = new Object[] { new Long(companyId) };
0272:
0273:                Object result = null;
0274:
0275:                if (finderClassNameCacheEnabled) {
0276:                    result = FinderCache.getResult(finderClassName,
0277:                            finderMethodName, finderParams, finderArgs,
0278:                            getSessionFactory());
0279:                }
0280:
0281:                if (result == null) {
0282:                    Session session = null;
0283:
0284:                    try {
0285:                        session = openSession();
0286:
0287:                        StringMaker query = new StringMaker();
0288:
0289:                        query
0290:                                .append("FROM com.liferay.portal.model.Role WHERE ");
0291:
0292:                        query.append("companyId = ?");
0293:
0294:                        query.append(" ");
0295:
0296:                        query.append("ORDER BY ");
0297:
0298:                        query.append("name ASC");
0299:
0300:                        Query q = session.createQuery(query.toString());
0301:
0302:                        int queryPos = 0;
0303:
0304:                        q.setLong(queryPos++, companyId);
0305:
0306:                        List list = q.list();
0307:
0308:                        FinderCache.putResult(finderClassNameCacheEnabled,
0309:                                finderClassName, finderMethodName,
0310:                                finderParams, finderArgs, list);
0311:
0312:                        return list;
0313:                    } catch (Exception e) {
0314:                        throw HibernateUtil.processException(e);
0315:                    } finally {
0316:                        closeSession(session);
0317:                    }
0318:                } else {
0319:                    return (List) result;
0320:                }
0321:            }
0322:
0323:            public List findByCompanyId(long companyId, int begin, int end)
0324:                    throws SystemException {
0325:                return findByCompanyId(companyId, begin, end, null);
0326:            }
0327:
0328:            public List findByCompanyId(long companyId, int begin, int end,
0329:                    OrderByComparator obc) throws SystemException {
0330:                boolean finderClassNameCacheEnabled = RoleModelImpl.CACHE_ENABLED;
0331:                String finderClassName = Role.class.getName();
0332:                String finderMethodName = "findByCompanyId";
0333:                String[] finderParams = new String[] { Long.class.getName(),
0334:
0335:                "java.lang.Integer", "java.lang.Integer",
0336:                        "com.liferay.portal.kernel.util.OrderByComparator" };
0337:                Object[] finderArgs = new Object[] { new Long(companyId),
0338:
0339:                String.valueOf(begin), String.valueOf(end), String.valueOf(obc) };
0340:
0341:                Object result = null;
0342:
0343:                if (finderClassNameCacheEnabled) {
0344:                    result = FinderCache.getResult(finderClassName,
0345:                            finderMethodName, finderParams, finderArgs,
0346:                            getSessionFactory());
0347:                }
0348:
0349:                if (result == null) {
0350:                    Session session = null;
0351:
0352:                    try {
0353:                        session = openSession();
0354:
0355:                        StringMaker query = new StringMaker();
0356:
0357:                        query
0358:                                .append("FROM com.liferay.portal.model.Role WHERE ");
0359:
0360:                        query.append("companyId = ?");
0361:
0362:                        query.append(" ");
0363:
0364:                        if (obc != null) {
0365:                            query.append("ORDER BY ");
0366:                            query.append(obc.getOrderBy());
0367:                        }
0368:
0369:                        else {
0370:                            query.append("ORDER BY ");
0371:
0372:                            query.append("name ASC");
0373:                        }
0374:
0375:                        Query q = session.createQuery(query.toString());
0376:
0377:                        int queryPos = 0;
0378:
0379:                        q.setLong(queryPos++, companyId);
0380:
0381:                        List list = QueryUtil.list(q, getDialect(), begin, end);
0382:
0383:                        FinderCache.putResult(finderClassNameCacheEnabled,
0384:                                finderClassName, finderMethodName,
0385:                                finderParams, finderArgs, list);
0386:
0387:                        return list;
0388:                    } catch (Exception e) {
0389:                        throw HibernateUtil.processException(e);
0390:                    } finally {
0391:                        closeSession(session);
0392:                    }
0393:                } else {
0394:                    return (List) result;
0395:                }
0396:            }
0397:
0398:            public Role findByCompanyId_First(long companyId,
0399:                    OrderByComparator obc) throws NoSuchRoleException,
0400:                    SystemException {
0401:                List list = findByCompanyId(companyId, 0, 1, obc);
0402:
0403:                if (list.size() == 0) {
0404:                    StringMaker msg = new StringMaker();
0405:
0406:                    msg.append("No Role exists with the key {");
0407:
0408:                    msg.append("companyId=" + companyId);
0409:
0410:                    msg.append(StringPool.CLOSE_CURLY_BRACE);
0411:
0412:                    throw new NoSuchRoleException(msg.toString());
0413:                } else {
0414:                    return (Role) list.get(0);
0415:                }
0416:            }
0417:
0418:            public Role findByCompanyId_Last(long companyId,
0419:                    OrderByComparator obc) throws NoSuchRoleException,
0420:                    SystemException {
0421:                int count = countByCompanyId(companyId);
0422:
0423:                List list = findByCompanyId(companyId, count - 1, count, obc);
0424:
0425:                if (list.size() == 0) {
0426:                    StringMaker msg = new StringMaker();
0427:
0428:                    msg.append("No Role exists with the key {");
0429:
0430:                    msg.append("companyId=" + companyId);
0431:
0432:                    msg.append(StringPool.CLOSE_CURLY_BRACE);
0433:
0434:                    throw new NoSuchRoleException(msg.toString());
0435:                } else {
0436:                    return (Role) list.get(0);
0437:                }
0438:            }
0439:
0440:            public Role[] findByCompanyId_PrevAndNext(long roleId,
0441:                    long companyId, OrderByComparator obc)
0442:                    throws NoSuchRoleException, SystemException {
0443:                Role role = findByPrimaryKey(roleId);
0444:
0445:                int count = countByCompanyId(companyId);
0446:
0447:                Session session = null;
0448:
0449:                try {
0450:                    session = openSession();
0451:
0452:                    StringMaker query = new StringMaker();
0453:
0454:                    query.append("FROM com.liferay.portal.model.Role WHERE ");
0455:
0456:                    query.append("companyId = ?");
0457:
0458:                    query.append(" ");
0459:
0460:                    if (obc != null) {
0461:                        query.append("ORDER BY ");
0462:                        query.append(obc.getOrderBy());
0463:                    }
0464:
0465:                    else {
0466:                        query.append("ORDER BY ");
0467:
0468:                        query.append("name ASC");
0469:                    }
0470:
0471:                    Query q = session.createQuery(query.toString());
0472:
0473:                    int queryPos = 0;
0474:
0475:                    q.setLong(queryPos++, companyId);
0476:
0477:                    Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
0478:                            role);
0479:
0480:                    Role[] array = new RoleImpl[3];
0481:
0482:                    array[0] = (Role) objArray[0];
0483:                    array[1] = (Role) objArray[1];
0484:                    array[2] = (Role) objArray[2];
0485:
0486:                    return array;
0487:                } catch (Exception e) {
0488:                    throw HibernateUtil.processException(e);
0489:                } finally {
0490:                    closeSession(session);
0491:                }
0492:            }
0493:
0494:            public Role findByC_N(long companyId, String name)
0495:                    throws NoSuchRoleException, SystemException {
0496:                Role role = fetchByC_N(companyId, name);
0497:
0498:                if (role == null) {
0499:                    StringMaker msg = new StringMaker();
0500:
0501:                    msg.append("No Role exists with the key {");
0502:
0503:                    msg.append("companyId=" + companyId);
0504:
0505:                    msg.append(", ");
0506:                    msg.append("name=" + name);
0507:
0508:                    msg.append(StringPool.CLOSE_CURLY_BRACE);
0509:
0510:                    if (_log.isWarnEnabled()) {
0511:                        _log.warn(msg.toString());
0512:                    }
0513:
0514:                    throw new NoSuchRoleException(msg.toString());
0515:                }
0516:
0517:                return role;
0518:            }
0519:
0520:            public Role fetchByC_N(long companyId, String name)
0521:                    throws SystemException {
0522:                boolean finderClassNameCacheEnabled = RoleModelImpl.CACHE_ENABLED;
0523:                String finderClassName = Role.class.getName();
0524:                String finderMethodName = "fetchByC_N";
0525:                String[] finderParams = new String[] { Long.class.getName(),
0526:                        String.class.getName() };
0527:                Object[] finderArgs = new Object[] { new Long(companyId), name };
0528:
0529:                Object result = null;
0530:
0531:                if (finderClassNameCacheEnabled) {
0532:                    result = FinderCache.getResult(finderClassName,
0533:                            finderMethodName, finderParams, finderArgs,
0534:                            getSessionFactory());
0535:                }
0536:
0537:                if (result == null) {
0538:                    Session session = null;
0539:
0540:                    try {
0541:                        session = openSession();
0542:
0543:                        StringMaker query = new StringMaker();
0544:
0545:                        query
0546:                                .append("FROM com.liferay.portal.model.Role WHERE ");
0547:
0548:                        query.append("companyId = ?");
0549:
0550:                        query.append(" AND ");
0551:
0552:                        if (name == null) {
0553:                            query.append("name IS NULL");
0554:                        } else {
0555:                            query.append("name = ?");
0556:                        }
0557:
0558:                        query.append(" ");
0559:
0560:                        query.append("ORDER BY ");
0561:
0562:                        query.append("name ASC");
0563:
0564:                        Query q = session.createQuery(query.toString());
0565:
0566:                        int queryPos = 0;
0567:
0568:                        q.setLong(queryPos++, companyId);
0569:
0570:                        if (name != null) {
0571:                            q.setString(queryPos++, name);
0572:                        }
0573:
0574:                        List list = q.list();
0575:
0576:                        FinderCache.putResult(finderClassNameCacheEnabled,
0577:                                finderClassName, finderMethodName,
0578:                                finderParams, finderArgs, list);
0579:
0580:                        if (list.size() == 0) {
0581:                            return null;
0582:                        } else {
0583:                            return (Role) list.get(0);
0584:                        }
0585:                    } catch (Exception e) {
0586:                        throw HibernateUtil.processException(e);
0587:                    } finally {
0588:                        closeSession(session);
0589:                    }
0590:                } else {
0591:                    List list = (List) result;
0592:
0593:                    if (list.size() == 0) {
0594:                        return null;
0595:                    } else {
0596:                        return (Role) list.get(0);
0597:                    }
0598:                }
0599:            }
0600:
0601:            public Role findByC_C_C(long companyId, long classNameId,
0602:                    long classPK) throws NoSuchRoleException, SystemException {
0603:                Role role = fetchByC_C_C(companyId, classNameId, classPK);
0604:
0605:                if (role == null) {
0606:                    StringMaker msg = new StringMaker();
0607:
0608:                    msg.append("No Role exists with the key {");
0609:
0610:                    msg.append("companyId=" + companyId);
0611:
0612:                    msg.append(", ");
0613:                    msg.append("classNameId=" + classNameId);
0614:
0615:                    msg.append(", ");
0616:                    msg.append("classPK=" + classPK);
0617:
0618:                    msg.append(StringPool.CLOSE_CURLY_BRACE);
0619:
0620:                    if (_log.isWarnEnabled()) {
0621:                        _log.warn(msg.toString());
0622:                    }
0623:
0624:                    throw new NoSuchRoleException(msg.toString());
0625:                }
0626:
0627:                return role;
0628:            }
0629:
0630:            public Role fetchByC_C_C(long companyId, long classNameId,
0631:                    long classPK) throws SystemException {
0632:                boolean finderClassNameCacheEnabled = RoleModelImpl.CACHE_ENABLED;
0633:                String finderClassName = Role.class.getName();
0634:                String finderMethodName = "fetchByC_C_C";
0635:                String[] finderParams = new String[] { Long.class.getName(),
0636:                        Long.class.getName(), Long.class.getName() };
0637:                Object[] finderArgs = new Object[] { new Long(companyId),
0638:                        new Long(classNameId), new Long(classPK) };
0639:
0640:                Object result = null;
0641:
0642:                if (finderClassNameCacheEnabled) {
0643:                    result = FinderCache.getResult(finderClassName,
0644:                            finderMethodName, finderParams, finderArgs,
0645:                            getSessionFactory());
0646:                }
0647:
0648:                if (result == null) {
0649:                    Session session = null;
0650:
0651:                    try {
0652:                        session = openSession();
0653:
0654:                        StringMaker query = new StringMaker();
0655:
0656:                        query
0657:                                .append("FROM com.liferay.portal.model.Role WHERE ");
0658:
0659:                        query.append("companyId = ?");
0660:
0661:                        query.append(" AND ");
0662:
0663:                        query.append("classNameId = ?");
0664:
0665:                        query.append(" AND ");
0666:
0667:                        query.append("classPK = ?");
0668:
0669:                        query.append(" ");
0670:
0671:                        query.append("ORDER BY ");
0672:
0673:                        query.append("name ASC");
0674:
0675:                        Query q = session.createQuery(query.toString());
0676:
0677:                        int queryPos = 0;
0678:
0679:                        q.setLong(queryPos++, companyId);
0680:
0681:                        q.setLong(queryPos++, classNameId);
0682:
0683:                        q.setLong(queryPos++, classPK);
0684:
0685:                        List list = q.list();
0686:
0687:                        FinderCache.putResult(finderClassNameCacheEnabled,
0688:                                finderClassName, finderMethodName,
0689:                                finderParams, finderArgs, list);
0690:
0691:                        if (list.size() == 0) {
0692:                            return null;
0693:                        } else {
0694:                            return (Role) list.get(0);
0695:                        }
0696:                    } catch (Exception e) {
0697:                        throw HibernateUtil.processException(e);
0698:                    } finally {
0699:                        closeSession(session);
0700:                    }
0701:                } else {
0702:                    List list = (List) result;
0703:
0704:                    if (list.size() == 0) {
0705:                        return null;
0706:                    } else {
0707:                        return (Role) list.get(0);
0708:                    }
0709:                }
0710:            }
0711:
0712:            public List findWithDynamicQuery(
0713:                    DynamicQueryInitializer queryInitializer)
0714:                    throws SystemException {
0715:                Session session = null;
0716:
0717:                try {
0718:                    session = openSession();
0719:
0720:                    DynamicQuery query = queryInitializer.initialize(session);
0721:
0722:                    return query.list();
0723:                } catch (Exception e) {
0724:                    throw HibernateUtil.processException(e);
0725:                } finally {
0726:                    closeSession(session);
0727:                }
0728:            }
0729:
0730:            public List findWithDynamicQuery(
0731:                    DynamicQueryInitializer queryInitializer, int begin, int end)
0732:                    throws SystemException {
0733:                Session session = null;
0734:
0735:                try {
0736:                    session = openSession();
0737:
0738:                    DynamicQuery query = queryInitializer.initialize(session);
0739:
0740:                    query.setLimit(begin, end);
0741:
0742:                    return query.list();
0743:                } catch (Exception e) {
0744:                    throw HibernateUtil.processException(e);
0745:                } finally {
0746:                    closeSession(session);
0747:                }
0748:            }
0749:
0750:            public List findAll() throws SystemException {
0751:                return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
0752:            }
0753:
0754:            public List findAll(int begin, int end) throws SystemException {
0755:                return findAll(begin, end, null);
0756:            }
0757:
0758:            public List findAll(int begin, int end, OrderByComparator obc)
0759:                    throws SystemException {
0760:                boolean finderClassNameCacheEnabled = RoleModelImpl.CACHE_ENABLED;
0761:                String finderClassName = Role.class.getName();
0762:                String finderMethodName = "findAll";
0763:                String[] finderParams = new String[] { "java.lang.Integer",
0764:                        "java.lang.Integer",
0765:                        "com.liferay.portal.kernel.util.OrderByComparator" };
0766:                Object[] finderArgs = new Object[] { String.valueOf(begin),
0767:                        String.valueOf(end), String.valueOf(obc) };
0768:
0769:                Object result = null;
0770:
0771:                if (finderClassNameCacheEnabled) {
0772:                    result = FinderCache.getResult(finderClassName,
0773:                            finderMethodName, finderParams, finderArgs,
0774:                            getSessionFactory());
0775:                }
0776:
0777:                if (result == null) {
0778:                    Session session = null;
0779:
0780:                    try {
0781:                        session = openSession();
0782:
0783:                        StringMaker query = new StringMaker();
0784:
0785:                        query.append("FROM com.liferay.portal.model.Role ");
0786:
0787:                        if (obc != null) {
0788:                            query.append("ORDER BY ");
0789:                            query.append(obc.getOrderBy());
0790:                        }
0791:
0792:                        else {
0793:                            query.append("ORDER BY ");
0794:
0795:                            query.append("name ASC");
0796:                        }
0797:
0798:                        Query q = session.createQuery(query.toString());
0799:
0800:                        List list = QueryUtil.list(q, getDialect(), begin, end);
0801:
0802:                        if (obc == null) {
0803:                            Collections.sort(list);
0804:                        }
0805:
0806:                        FinderCache.putResult(finderClassNameCacheEnabled,
0807:                                finderClassName, finderMethodName,
0808:                                finderParams, finderArgs, list);
0809:
0810:                        return list;
0811:                    } catch (Exception e) {
0812:                        throw HibernateUtil.processException(e);
0813:                    } finally {
0814:                        closeSession(session);
0815:                    }
0816:                } else {
0817:                    return (List) result;
0818:                }
0819:            }
0820:
0821:            public void removeByCompanyId(long companyId)
0822:                    throws SystemException {
0823:                Iterator itr = findByCompanyId(companyId).iterator();
0824:
0825:                while (itr.hasNext()) {
0826:                    Role role = (Role) itr.next();
0827:
0828:                    remove(role);
0829:                }
0830:            }
0831:
0832:            public void removeByC_N(long companyId, String name)
0833:                    throws NoSuchRoleException, SystemException {
0834:                Role role = findByC_N(companyId, name);
0835:
0836:                remove(role);
0837:            }
0838:
0839:            public void removeByC_C_C(long companyId, long classNameId,
0840:                    long classPK) throws NoSuchRoleException, SystemException {
0841:                Role role = findByC_C_C(companyId, classNameId, classPK);
0842:
0843:                remove(role);
0844:            }
0845:
0846:            public void removeAll() throws SystemException {
0847:                Iterator itr = findAll().iterator();
0848:
0849:                while (itr.hasNext()) {
0850:                    remove((Role) itr.next());
0851:                }
0852:            }
0853:
0854:            public int countByCompanyId(long companyId) throws SystemException {
0855:                boolean finderClassNameCacheEnabled = RoleModelImpl.CACHE_ENABLED;
0856:                String finderClassName = Role.class.getName();
0857:                String finderMethodName = "countByCompanyId";
0858:                String[] finderParams = new String[] { Long.class.getName() };
0859:                Object[] finderArgs = new Object[] { new Long(companyId) };
0860:
0861:                Object result = null;
0862:
0863:                if (finderClassNameCacheEnabled) {
0864:                    result = FinderCache.getResult(finderClassName,
0865:                            finderMethodName, finderParams, finderArgs,
0866:                            getSessionFactory());
0867:                }
0868:
0869:                if (result == null) {
0870:                    Session session = null;
0871:
0872:                    try {
0873:                        session = openSession();
0874:
0875:                        StringMaker query = new StringMaker();
0876:
0877:                        query.append("SELECT COUNT(*) ");
0878:                        query
0879:                                .append("FROM com.liferay.portal.model.Role WHERE ");
0880:
0881:                        query.append("companyId = ?");
0882:
0883:                        query.append(" ");
0884:
0885:                        Query q = session.createQuery(query.toString());
0886:
0887:                        int queryPos = 0;
0888:
0889:                        q.setLong(queryPos++, companyId);
0890:
0891:                        Long count = null;
0892:
0893:                        Iterator itr = q.list().iterator();
0894:
0895:                        if (itr.hasNext()) {
0896:                            count = (Long) itr.next();
0897:                        }
0898:
0899:                        if (count == null) {
0900:                            count = new Long(0);
0901:                        }
0902:
0903:                        FinderCache.putResult(finderClassNameCacheEnabled,
0904:                                finderClassName, finderMethodName,
0905:                                finderParams, finderArgs, count);
0906:
0907:                        return count.intValue();
0908:                    } catch (Exception e) {
0909:                        throw HibernateUtil.processException(e);
0910:                    } finally {
0911:                        closeSession(session);
0912:                    }
0913:                } else {
0914:                    return ((Long) result).intValue();
0915:                }
0916:            }
0917:
0918:            public int countByC_N(long companyId, String name)
0919:                    throws SystemException {
0920:                boolean finderClassNameCacheEnabled = RoleModelImpl.CACHE_ENABLED;
0921:                String finderClassName = Role.class.getName();
0922:                String finderMethodName = "countByC_N";
0923:                String[] finderParams = new String[] { Long.class.getName(),
0924:                        String.class.getName() };
0925:                Object[] finderArgs = new Object[] { new Long(companyId), name };
0926:
0927:                Object result = null;
0928:
0929:                if (finderClassNameCacheEnabled) {
0930:                    result = FinderCache.getResult(finderClassName,
0931:                            finderMethodName, finderParams, finderArgs,
0932:                            getSessionFactory());
0933:                }
0934:
0935:                if (result == null) {
0936:                    Session session = null;
0937:
0938:                    try {
0939:                        session = openSession();
0940:
0941:                        StringMaker query = new StringMaker();
0942:
0943:                        query.append("SELECT COUNT(*) ");
0944:                        query
0945:                                .append("FROM com.liferay.portal.model.Role WHERE ");
0946:
0947:                        query.append("companyId = ?");
0948:
0949:                        query.append(" AND ");
0950:
0951:                        if (name == null) {
0952:                            query.append("name IS NULL");
0953:                        } else {
0954:                            query.append("name = ?");
0955:                        }
0956:
0957:                        query.append(" ");
0958:
0959:                        Query q = session.createQuery(query.toString());
0960:
0961:                        int queryPos = 0;
0962:
0963:                        q.setLong(queryPos++, companyId);
0964:
0965:                        if (name != null) {
0966:                            q.setString(queryPos++, name);
0967:                        }
0968:
0969:                        Long count = null;
0970:
0971:                        Iterator itr = q.list().iterator();
0972:
0973:                        if (itr.hasNext()) {
0974:                            count = (Long) itr.next();
0975:                        }
0976:
0977:                        if (count == null) {
0978:                            count = new Long(0);
0979:                        }
0980:
0981:                        FinderCache.putResult(finderClassNameCacheEnabled,
0982:                                finderClassName, finderMethodName,
0983:                                finderParams, finderArgs, count);
0984:
0985:                        return count.intValue();
0986:                    } catch (Exception e) {
0987:                        throw HibernateUtil.processException(e);
0988:                    } finally {
0989:                        closeSession(session);
0990:                    }
0991:                } else {
0992:                    return ((Long) result).intValue();
0993:                }
0994:            }
0995:
0996:            public int countByC_C_C(long companyId, long classNameId,
0997:                    long classPK) throws SystemException {
0998:                boolean finderClassNameCacheEnabled = RoleModelImpl.CACHE_ENABLED;
0999:                String finderClassName = Role.class.getName();
1000:                String finderMethodName = "countByC_C_C";
1001:                String[] finderParams = new String[] { Long.class.getName(),
1002:                        Long.class.getName(), Long.class.getName() };
1003:                Object[] finderArgs = new Object[] { new Long(companyId),
1004:                        new Long(classNameId), new Long(classPK) };
1005:
1006:                Object result = null;
1007:
1008:                if (finderClassNameCacheEnabled) {
1009:                    result = FinderCache.getResult(finderClassName,
1010:                            finderMethodName, finderParams, finderArgs,
1011:                            getSessionFactory());
1012:                }
1013:
1014:                if (result == null) {
1015:                    Session session = null;
1016:
1017:                    try {
1018:                        session = openSession();
1019:
1020:                        StringMaker query = new StringMaker();
1021:
1022:                        query.append("SELECT COUNT(*) ");
1023:                        query
1024:                                .append("FROM com.liferay.portal.model.Role WHERE ");
1025:
1026:                        query.append("companyId = ?");
1027:
1028:                        query.append(" AND ");
1029:
1030:                        query.append("classNameId = ?");
1031:
1032:                        query.append(" AND ");
1033:
1034:                        query.append("classPK = ?");
1035:
1036:                        query.append(" ");
1037:
1038:                        Query q = session.createQuery(query.toString());
1039:
1040:                        int queryPos = 0;
1041:
1042:                        q.setLong(queryPos++, companyId);
1043:
1044:                        q.setLong(queryPos++, classNameId);
1045:
1046:                        q.setLong(queryPos++, classPK);
1047:
1048:                        Long count = null;
1049:
1050:                        Iterator itr = q.list().iterator();
1051:
1052:                        if (itr.hasNext()) {
1053:                            count = (Long) itr.next();
1054:                        }
1055:
1056:                        if (count == null) {
1057:                            count = new Long(0);
1058:                        }
1059:
1060:                        FinderCache.putResult(finderClassNameCacheEnabled,
1061:                                finderClassName, finderMethodName,
1062:                                finderParams, finderArgs, count);
1063:
1064:                        return count.intValue();
1065:                    } catch (Exception e) {
1066:                        throw HibernateUtil.processException(e);
1067:                    } finally {
1068:                        closeSession(session);
1069:                    }
1070:                } else {
1071:                    return ((Long) result).intValue();
1072:                }
1073:            }
1074:
1075:            public int countAll() throws SystemException {
1076:                boolean finderClassNameCacheEnabled = RoleModelImpl.CACHE_ENABLED;
1077:                String finderClassName = Role.class.getName();
1078:                String finderMethodName = "countAll";
1079:                String[] finderParams = new String[] {};
1080:                Object[] finderArgs = new Object[] {};
1081:
1082:                Object result = null;
1083:
1084:                if (finderClassNameCacheEnabled) {
1085:                    result = FinderCache.getResult(finderClassName,
1086:                            finderMethodName, finderParams, finderArgs,
1087:                            getSessionFactory());
1088:                }
1089:
1090:                if (result == null) {
1091:                    Session session = null;
1092:
1093:                    try {
1094:                        session = openSession();
1095:
1096:                        Query q = session
1097:                                .createQuery("SELECT COUNT(*) FROM com.liferay.portal.model.Role");
1098:
1099:                        Long count = null;
1100:
1101:                        Iterator itr = q.list().iterator();
1102:
1103:                        if (itr.hasNext()) {
1104:                            count = (Long) itr.next();
1105:                        }
1106:
1107:                        if (count == null) {
1108:                            count = new Long(0);
1109:                        }
1110:
1111:                        FinderCache.putResult(finderClassNameCacheEnabled,
1112:                                finderClassName, finderMethodName,
1113:                                finderParams, finderArgs, count);
1114:
1115:                        return count.intValue();
1116:                    } catch (Exception e) {
1117:                        throw HibernateUtil.processException(e);
1118:                    } finally {
1119:                        closeSession(session);
1120:                    }
1121:                } else {
1122:                    return ((Long) result).intValue();
1123:                }
1124:            }
1125:
1126:            public List getGroups(long pk) throws NoSuchRoleException,
1127:                    SystemException {
1128:                return getGroups(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
1129:            }
1130:
1131:            public List getGroups(long pk, int begin, int end)
1132:                    throws NoSuchRoleException, SystemException {
1133:                return getGroups(pk, begin, end, null);
1134:            }
1135:
1136:            public List getGroups(long pk, int begin, int end,
1137:                    OrderByComparator obc) throws NoSuchRoleException,
1138:                    SystemException {
1139:                boolean finderClassNameCacheEnabled = RoleModelImpl.CACHE_ENABLED_GROUPS_ROLES;
1140:                String finderClassName = "Groups_Roles";
1141:                String finderMethodName = "getGroups";
1142:                String[] finderParams = new String[] { Long.class.getName(),
1143:                        "java.lang.Integer", "java.lang.Integer",
1144:                        "com.liferay.portal.kernel.util.OrderByComparator" };
1145:                Object[] finderArgs = new Object[] { new Long(pk),
1146:                        String.valueOf(begin), String.valueOf(end),
1147:                        String.valueOf(obc) };
1148:
1149:                Object result = null;
1150:
1151:                if (finderClassNameCacheEnabled) {
1152:                    result = FinderCache.getResult(finderClassName,
1153:                            finderMethodName, finderParams, finderArgs,
1154:                            getSessionFactory());
1155:                }
1156:
1157:                if (result == null) {
1158:                    Session session = null;
1159:
1160:                    try {
1161:                        session = HibernateUtil.openSession();
1162:
1163:                        StringMaker sm = new StringMaker();
1164:
1165:                        sm.append(_SQL_GETGROUPS);
1166:
1167:                        if (obc != null) {
1168:                            sm.append("ORDER BY ");
1169:                            sm.append(obc.getOrderBy());
1170:                        }
1171:
1172:                        else {
1173:                            sm.append("ORDER BY ");
1174:
1175:                            sm.append("Group_.name ASC");
1176:                        }
1177:
1178:                        String sql = sm.toString();
1179:
1180:                        SQLQuery q = session.createSQLQuery(sql);
1181:
1182:                        q.addEntity("Group_",
1183:                                com.liferay.portal.model.impl.GroupImpl.class);
1184:
1185:                        QueryPos qPos = QueryPos.getInstance(q);
1186:
1187:                        qPos.add(pk);
1188:
1189:                        List list = QueryUtil.list(q, getDialect(), begin, end);
1190:
1191:                        FinderCache.putResult(finderClassNameCacheEnabled,
1192:                                finderClassName, finderMethodName,
1193:                                finderParams, finderArgs, list);
1194:
1195:                        return list;
1196:                    } catch (Exception e) {
1197:                        throw new SystemException(e);
1198:                    } finally {
1199:                        closeSession(session);
1200:                    }
1201:                } else {
1202:                    return (List) result;
1203:                }
1204:            }
1205:
1206:            public int getGroupsSize(long pk) throws SystemException {
1207:                boolean finderClassNameCacheEnabled = RoleModelImpl.CACHE_ENABLED_GROUPS_ROLES;
1208:                String finderClassName = "Groups_Roles";
1209:                String finderMethodName = "getGroupsSize";
1210:                String[] finderParams = new String[] { Long.class.getName() };
1211:                Object[] finderArgs = new Object[] { new Long(pk) };
1212:
1213:                Object result = null;
1214:
1215:                if (finderClassNameCacheEnabled) {
1216:                    result = FinderCache.getResult(finderClassName,
1217:                            finderMethodName, finderParams, finderArgs,
1218:                            getSessionFactory());
1219:                }
1220:
1221:                if (result == null) {
1222:                    Session session = null;
1223:
1224:                    try {
1225:                        session = openSession();
1226:
1227:                        SQLQuery q = session.createSQLQuery(_SQL_GETGROUPSSIZE);
1228:
1229:                        q.addScalar(HibernateUtil.getCountColumnName(),
1230:                                Hibernate.LONG);
1231:
1232:                        QueryPos qPos = QueryPos.getInstance(q);
1233:
1234:                        qPos.add(pk);
1235:
1236:                        Long count = null;
1237:
1238:                        Iterator itr = q.list().iterator();
1239:
1240:                        if (itr.hasNext()) {
1241:                            count = (Long) itr.next();
1242:                        }
1243:
1244:                        if (count == null) {
1245:                            count = new Long(0);
1246:                        }
1247:
1248:                        FinderCache.putResult(finderClassNameCacheEnabled,
1249:                                finderClassName, finderMethodName,
1250:                                finderParams, finderArgs, count);
1251:
1252:                        return count.intValue();
1253:                    } catch (Exception e) {
1254:                        throw HibernateUtil.processException(e);
1255:                    } finally {
1256:                        closeSession(session);
1257:                    }
1258:                } else {
1259:                    return ((Long) result).intValue();
1260:                }
1261:            }
1262:
1263:            public boolean containsGroup(long pk, long groupPK)
1264:                    throws SystemException {
1265:                boolean finderClassNameCacheEnabled = RoleModelImpl.CACHE_ENABLED_GROUPS_ROLES;
1266:                String finderClassName = "Groups_Roles";
1267:                String finderMethodName = "containsGroups";
1268:                String[] finderParams = new String[] { Long.class.getName(),
1269:
1270:                Long.class.getName() };
1271:                Object[] finderArgs = new Object[] { new Long(pk),
1272:                        new Long(groupPK) };
1273:
1274:                Object result = null;
1275:
1276:                if (finderClassNameCacheEnabled) {
1277:                    result = FinderCache.getResult(finderClassName,
1278:                            finderMethodName, finderParams, finderArgs,
1279:                            getSessionFactory());
1280:                }
1281:
1282:                if (result == null) {
1283:                    try {
1284:                        Boolean value = Boolean.valueOf(containsGroup.contains(
1285:                                pk, groupPK));
1286:
1287:                        FinderCache.putResult(finderClassNameCacheEnabled,
1288:                                finderClassName, finderMethodName,
1289:                                finderParams, finderArgs, value);
1290:
1291:                        return value.booleanValue();
1292:                    } catch (DataAccessException dae) {
1293:                        throw new SystemException(dae);
1294:                    }
1295:                } else {
1296:                    return ((Boolean) result).booleanValue();
1297:                }
1298:            }
1299:
1300:            public boolean containsGroups(long pk) throws SystemException {
1301:                if (getGroupsSize(pk) > 0) {
1302:                    return true;
1303:                } else {
1304:                    return false;
1305:                }
1306:            }
1307:
1308:            public void addGroup(long pk, long groupPK)
1309:                    throws NoSuchRoleException,
1310:                    com.liferay.portal.NoSuchGroupException, SystemException {
1311:                try {
1312:                    addGroup.add(pk, groupPK);
1313:                } catch (DataAccessException dae) {
1314:                    throw new SystemException(dae);
1315:                } finally {
1316:                    FinderCache.clearCache("Groups_Roles");
1317:                }
1318:            }
1319:
1320:            public void addGroup(long pk, com.liferay.portal.model.Group group)
1321:                    throws NoSuchRoleException,
1322:                    com.liferay.portal.NoSuchGroupException, SystemException {
1323:                try {
1324:                    addGroup.add(pk, group.getPrimaryKey());
1325:                } catch (DataAccessException dae) {
1326:                    throw new SystemException(dae);
1327:                } finally {
1328:                    FinderCache.clearCache("Groups_Roles");
1329:                }
1330:            }
1331:
1332:            public void addGroups(long pk, long[] groupPKs)
1333:                    throws NoSuchRoleException,
1334:                    com.liferay.portal.NoSuchGroupException, SystemException {
1335:                try {
1336:                    for (int i = 0; i < groupPKs.length; i++) {
1337:                        addGroup.add(pk, groupPKs[i]);
1338:                    }
1339:                } catch (DataAccessException dae) {
1340:                    throw new SystemException(dae);
1341:                } finally {
1342:                    FinderCache.clearCache("Groups_Roles");
1343:                }
1344:            }
1345:
1346:            public void addGroups(long pk, List groups)
1347:                    throws NoSuchRoleException,
1348:                    com.liferay.portal.NoSuchGroupException, SystemException {
1349:                try {
1350:                    for (int i = 0; i < groups.size(); i++) {
1351:                        com.liferay.portal.model.Group group = (com.liferay.portal.model.Group) groups
1352:                                .get(i);
1353:
1354:                        addGroup.add(pk, group.getPrimaryKey());
1355:                    }
1356:                } catch (DataAccessException dae) {
1357:                    throw new SystemException(dae);
1358:                } finally {
1359:                    FinderCache.clearCache("Groups_Roles");
1360:                }
1361:            }
1362:
1363:            public void clearGroups(long pk) throws NoSuchRoleException,
1364:                    SystemException {
1365:                try {
1366:                    clearGroups.clear(pk);
1367:                } catch (DataAccessException dae) {
1368:                    throw new SystemException(dae);
1369:                } finally {
1370:                    FinderCache.clearCache("Groups_Roles");
1371:                }
1372:            }
1373:
1374:            public void removeGroup(long pk, long groupPK)
1375:                    throws NoSuchRoleException,
1376:                    com.liferay.portal.NoSuchGroupException, SystemException {
1377:                try {
1378:                    removeGroup.remove(pk, groupPK);
1379:                } catch (DataAccessException dae) {
1380:                    throw new SystemException(dae);
1381:                } finally {
1382:                    FinderCache.clearCache("Groups_Roles");
1383:                }
1384:            }
1385:
1386:            public void removeGroup(long pk,
1387:                    com.liferay.portal.model.Group group)
1388:                    throws NoSuchRoleException,
1389:                    com.liferay.portal.NoSuchGroupException, SystemException {
1390:                try {
1391:                    removeGroup.remove(pk, group.getPrimaryKey());
1392:                } catch (DataAccessException dae) {
1393:                    throw new SystemException(dae);
1394:                } finally {
1395:                    FinderCache.clearCache("Groups_Roles");
1396:                }
1397:            }
1398:
1399:            public void removeGroups(long pk, long[] groupPKs)
1400:                    throws NoSuchRoleException,
1401:                    com.liferay.portal.NoSuchGroupException, SystemException {
1402:                try {
1403:                    for (int i = 0; i < groupPKs.length; i++) {
1404:                        removeGroup.remove(pk, groupPKs[i]);
1405:                    }
1406:                } catch (DataAccessException dae) {
1407:                    throw new SystemException(dae);
1408:                } finally {
1409:                    FinderCache.clearCache("Groups_Roles");
1410:                }
1411:            }
1412:
1413:            public void removeGroups(long pk, List groups)
1414:                    throws NoSuchRoleException,
1415:                    com.liferay.portal.NoSuchGroupException, SystemException {
1416:                try {
1417:                    for (int i = 0; i < groups.size(); i++) {
1418:                        com.liferay.portal.model.Group group = (com.liferay.portal.model.Group) groups
1419:                                .get(i);
1420:
1421:                        removeGroup.remove(pk, group.getPrimaryKey());
1422:                    }
1423:                } catch (DataAccessException dae) {
1424:                    throw new SystemException(dae);
1425:                } finally {
1426:                    FinderCache.clearCache("Groups_Roles");
1427:                }
1428:            }
1429:
1430:            public void setGroups(long pk, long[] groupPKs)
1431:                    throws NoSuchRoleException,
1432:                    com.liferay.portal.NoSuchGroupException, SystemException {
1433:                try {
1434:                    clearGroups.clear(pk);
1435:
1436:                    for (int i = 0; i < groupPKs.length; i++) {
1437:                        addGroup.add(pk, groupPKs[i]);
1438:                    }
1439:                } catch (DataAccessException dae) {
1440:                    throw new SystemException(dae);
1441:                } finally {
1442:                    FinderCache.clearCache("Groups_Roles");
1443:                }
1444:            }
1445:
1446:            public void setGroups(long pk, List groups)
1447:                    throws NoSuchRoleException,
1448:                    com.liferay.portal.NoSuchGroupException, SystemException {
1449:                try {
1450:                    clearGroups.clear(pk);
1451:
1452:                    for (int i = 0; i < groups.size(); i++) {
1453:                        com.liferay.portal.model.Group group = (com.liferay.portal.model.Group) groups
1454:                                .get(i);
1455:
1456:                        addGroup.add(pk, group.getPrimaryKey());
1457:                    }
1458:                } catch (DataAccessException dae) {
1459:                    throw new SystemException(dae);
1460:                } finally {
1461:                    FinderCache.clearCache("Groups_Roles");
1462:                }
1463:            }
1464:
1465:            public List getPermissions(long pk) throws NoSuchRoleException,
1466:                    SystemException {
1467:                return getPermissions(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
1468:            }
1469:
1470:            public List getPermissions(long pk, int begin, int end)
1471:                    throws NoSuchRoleException, SystemException {
1472:                return getPermissions(pk, begin, end, null);
1473:            }
1474:
1475:            public List getPermissions(long pk, int begin, int end,
1476:                    OrderByComparator obc) throws NoSuchRoleException,
1477:                    SystemException {
1478:                boolean finderClassNameCacheEnabled = RoleModelImpl.CACHE_ENABLED_ROLES_PERMISSIONS;
1479:                String finderClassName = "Roles_Permissions";
1480:                String finderMethodName = "getPermissions";
1481:                String[] finderParams = new String[] { Long.class.getName(),
1482:                        "java.lang.Integer", "java.lang.Integer",
1483:                        "com.liferay.portal.kernel.util.OrderByComparator" };
1484:                Object[] finderArgs = new Object[] { new Long(pk),
1485:                        String.valueOf(begin), String.valueOf(end),
1486:                        String.valueOf(obc) };
1487:
1488:                Object result = null;
1489:
1490:                if (finderClassNameCacheEnabled) {
1491:                    result = FinderCache.getResult(finderClassName,
1492:                            finderMethodName, finderParams, finderArgs,
1493:                            getSessionFactory());
1494:                }
1495:
1496:                if (result == null) {
1497:                    Session session = null;
1498:
1499:                    try {
1500:                        session = HibernateUtil.openSession();
1501:
1502:                        StringMaker sm = new StringMaker();
1503:
1504:                        sm.append(_SQL_GETPERMISSIONS);
1505:
1506:                        if (obc != null) {
1507:                            sm.append("ORDER BY ");
1508:                            sm.append(obc.getOrderBy());
1509:                        }
1510:
1511:                        String sql = sm.toString();
1512:
1513:                        SQLQuery q = session.createSQLQuery(sql);
1514:
1515:                        q
1516:                                .addEntity(
1517:                                        "Permission_",
1518:                                        com.liferay.portal.model.impl.PermissionImpl.class);
1519:
1520:                        QueryPos qPos = QueryPos.getInstance(q);
1521:
1522:                        qPos.add(pk);
1523:
1524:                        List list = QueryUtil.list(q, getDialect(), begin, end);
1525:
1526:                        FinderCache.putResult(finderClassNameCacheEnabled,
1527:                                finderClassName, finderMethodName,
1528:                                finderParams, finderArgs, list);
1529:
1530:                        return list;
1531:                    } catch (Exception e) {
1532:                        throw new SystemException(e);
1533:                    } finally {
1534:                        closeSession(session);
1535:                    }
1536:                } else {
1537:                    return (List) result;
1538:                }
1539:            }
1540:
1541:            public int getPermissionsSize(long pk) throws SystemException {
1542:                boolean finderClassNameCacheEnabled = RoleModelImpl.CACHE_ENABLED_ROLES_PERMISSIONS;
1543:                String finderClassName = "Roles_Permissions";
1544:                String finderMethodName = "getPermissionsSize";
1545:                String[] finderParams = new String[] { Long.class.getName() };
1546:                Object[] finderArgs = new Object[] { new Long(pk) };
1547:
1548:                Object result = null;
1549:
1550:                if (finderClassNameCacheEnabled) {
1551:                    result = FinderCache.getResult(finderClassName,
1552:                            finderMethodName, finderParams, finderArgs,
1553:                            getSessionFactory());
1554:                }
1555:
1556:                if (result == null) {
1557:                    Session session = null;
1558:
1559:                    try {
1560:                        session = openSession();
1561:
1562:                        SQLQuery q = session
1563:                                .createSQLQuery(_SQL_GETPERMISSIONSSIZE);
1564:
1565:                        q.addScalar(HibernateUtil.getCountColumnName(),
1566:                                Hibernate.LONG);
1567:
1568:                        QueryPos qPos = QueryPos.getInstance(q);
1569:
1570:                        qPos.add(pk);
1571:
1572:                        Long count = null;
1573:
1574:                        Iterator itr = q.list().iterator();
1575:
1576:                        if (itr.hasNext()) {
1577:                            count = (Long) itr.next();
1578:                        }
1579:
1580:                        if (count == null) {
1581:                            count = new Long(0);
1582:                        }
1583:
1584:                        FinderCache.putResult(finderClassNameCacheEnabled,
1585:                                finderClassName, finderMethodName,
1586:                                finderParams, finderArgs, count);
1587:
1588:                        return count.intValue();
1589:                    } catch (Exception e) {
1590:                        throw HibernateUtil.processException(e);
1591:                    } finally {
1592:                        closeSession(session);
1593:                    }
1594:                } else {
1595:                    return ((Long) result).intValue();
1596:                }
1597:            }
1598:
1599:            public boolean containsPermission(long pk, long permissionPK)
1600:                    throws SystemException {
1601:                boolean finderClassNameCacheEnabled = RoleModelImpl.CACHE_ENABLED_ROLES_PERMISSIONS;
1602:                String finderClassName = "Roles_Permissions";
1603:                String finderMethodName = "containsPermissions";
1604:                String[] finderParams = new String[] { Long.class.getName(),
1605:
1606:                Long.class.getName() };
1607:                Object[] finderArgs = new Object[] { new Long(pk),
1608:                        new Long(permissionPK) };
1609:
1610:                Object result = null;
1611:
1612:                if (finderClassNameCacheEnabled) {
1613:                    result = FinderCache.getResult(finderClassName,
1614:                            finderMethodName, finderParams, finderArgs,
1615:                            getSessionFactory());
1616:                }
1617:
1618:                if (result == null) {
1619:                    try {
1620:                        Boolean value = Boolean.valueOf(containsPermission
1621:                                .contains(pk, permissionPK));
1622:
1623:                        FinderCache.putResult(finderClassNameCacheEnabled,
1624:                                finderClassName, finderMethodName,
1625:                                finderParams, finderArgs, value);
1626:
1627:                        return value.booleanValue();
1628:                    } catch (DataAccessException dae) {
1629:                        throw new SystemException(dae);
1630:                    }
1631:                } else {
1632:                    return ((Boolean) result).booleanValue();
1633:                }
1634:            }
1635:
1636:            public boolean containsPermissions(long pk) throws SystemException {
1637:                if (getPermissionsSize(pk) > 0) {
1638:                    return true;
1639:                } else {
1640:                    return false;
1641:                }
1642:            }
1643:
1644:            public void addPermission(long pk, long permissionPK)
1645:                    throws NoSuchRoleException,
1646:                    com.liferay.portal.NoSuchPermissionException,
1647:                    SystemException {
1648:                try {
1649:                    addPermission.add(pk, permissionPK);
1650:                } catch (DataAccessException dae) {
1651:                    throw new SystemException(dae);
1652:                } finally {
1653:                    FinderCache.clearCache("Roles_Permissions");
1654:                }
1655:            }
1656:
1657:            public void addPermission(long pk,
1658:                    com.liferay.portal.model.Permission permission)
1659:                    throws NoSuchRoleException,
1660:                    com.liferay.portal.NoSuchPermissionException,
1661:                    SystemException {
1662:                try {
1663:                    addPermission.add(pk, permission.getPrimaryKey());
1664:                } catch (DataAccessException dae) {
1665:                    throw new SystemException(dae);
1666:                } finally {
1667:                    FinderCache.clearCache("Roles_Permissions");
1668:                }
1669:            }
1670:
1671:            public void addPermissions(long pk, long[] permissionPKs)
1672:                    throws NoSuchRoleException,
1673:                    com.liferay.portal.NoSuchPermissionException,
1674:                    SystemException {
1675:                try {
1676:                    for (int i = 0; i < permissionPKs.length; i++) {
1677:                        addPermission.add(pk, permissionPKs[i]);
1678:                    }
1679:                } catch (DataAccessException dae) {
1680:                    throw new SystemException(dae);
1681:                } finally {
1682:                    FinderCache.clearCache("Roles_Permissions");
1683:                }
1684:            }
1685:
1686:            public void addPermissions(long pk, List permissions)
1687:                    throws NoSuchRoleException,
1688:                    com.liferay.portal.NoSuchPermissionException,
1689:                    SystemException {
1690:                try {
1691:                    for (int i = 0; i < permissions.size(); i++) {
1692:                        com.liferay.portal.model.Permission permission = (com.liferay.portal.model.Permission) permissions
1693:                                .get(i);
1694:
1695:                        addPermission.add(pk, permission.getPrimaryKey());
1696:                    }
1697:                } catch (DataAccessException dae) {
1698:                    throw new SystemException(dae);
1699:                } finally {
1700:                    FinderCache.clearCache("Roles_Permissions");
1701:                }
1702:            }
1703:
1704:            public void clearPermissions(long pk) throws NoSuchRoleException,
1705:                    SystemException {
1706:                try {
1707:                    clearPermissions.clear(pk);
1708:                } catch (DataAccessException dae) {
1709:                    throw new SystemException(dae);
1710:                } finally {
1711:                    FinderCache.clearCache("Roles_Permissions");
1712:                }
1713:            }
1714:
1715:            public void removePermission(long pk, long permissionPK)
1716:                    throws NoSuchRoleException,
1717:                    com.liferay.portal.NoSuchPermissionException,
1718:                    SystemException {
1719:                try {
1720:                    removePermission.remove(pk, permissionPK);
1721:                } catch (DataAccessException dae) {
1722:                    throw new SystemException(dae);
1723:                } finally {
1724:                    FinderCache.clearCache("Roles_Permissions");
1725:                }
1726:            }
1727:
1728:            public void removePermission(long pk,
1729:                    com.liferay.portal.model.Permission permission)
1730:                    throws NoSuchRoleException,
1731:                    com.liferay.portal.NoSuchPermissionException,
1732:                    SystemException {
1733:                try {
1734:                    removePermission.remove(pk, permission.getPrimaryKey());
1735:                } catch (DataAccessException dae) {
1736:                    throw new SystemException(dae);
1737:                } finally {
1738:                    FinderCache.clearCache("Roles_Permissions");
1739:                }
1740:            }
1741:
1742:            public void removePermissions(long pk, long[] permissionPKs)
1743:                    throws NoSuchRoleException,
1744:                    com.liferay.portal.NoSuchPermissionException,
1745:                    SystemException {
1746:                try {
1747:                    for (int i = 0; i < permissionPKs.length; i++) {
1748:                        removePermission.remove(pk, permissionPKs[i]);
1749:                    }
1750:                } catch (DataAccessException dae) {
1751:                    throw new SystemException(dae);
1752:                } finally {
1753:                    FinderCache.clearCache("Roles_Permissions");
1754:                }
1755:            }
1756:
1757:            public void removePermissions(long pk, List permissions)
1758:                    throws NoSuchRoleException,
1759:                    com.liferay.portal.NoSuchPermissionException,
1760:                    SystemException {
1761:                try {
1762:                    for (int i = 0; i < permissions.size(); i++) {
1763:                        com.liferay.portal.model.Permission permission = (com.liferay.portal.model.Permission) permissions
1764:                                .get(i);
1765:
1766:                        removePermission.remove(pk, permission.getPrimaryKey());
1767:                    }
1768:                } catch (DataAccessException dae) {
1769:                    throw new SystemException(dae);
1770:                } finally {
1771:                    FinderCache.clearCache("Roles_Permissions");
1772:                }
1773:            }
1774:
1775:            public void setPermissions(long pk, long[] permissionPKs)
1776:                    throws NoSuchRoleException,
1777:                    com.liferay.portal.NoSuchPermissionException,
1778:                    SystemException {
1779:                try {
1780:                    clearPermissions.clear(pk);
1781:
1782:                    for (int i = 0; i < permissionPKs.length; i++) {
1783:                        addPermission.add(pk, permissionPKs[i]);
1784:                    }
1785:                } catch (DataAccessException dae) {
1786:                    throw new SystemException(dae);
1787:                } finally {
1788:                    FinderCache.clearCache("Roles_Permissions");
1789:                }
1790:            }
1791:
1792:            public void setPermissions(long pk, List permissions)
1793:                    throws NoSuchRoleException,
1794:                    com.liferay.portal.NoSuchPermissionException,
1795:                    SystemException {
1796:                try {
1797:                    clearPermissions.clear(pk);
1798:
1799:                    for (int i = 0; i < permissions.size(); i++) {
1800:                        com.liferay.portal.model.Permission permission = (com.liferay.portal.model.Permission) permissions
1801:                                .get(i);
1802:
1803:                        addPermission.add(pk, permission.getPrimaryKey());
1804:                    }
1805:                } catch (DataAccessException dae) {
1806:                    throw new SystemException(dae);
1807:                } finally {
1808:                    FinderCache.clearCache("Roles_Permissions");
1809:                }
1810:            }
1811:
1812:            public List getUsers(long pk) throws NoSuchRoleException,
1813:                    SystemException {
1814:                return getUsers(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
1815:            }
1816:
1817:            public List getUsers(long pk, int begin, int end)
1818:                    throws NoSuchRoleException, SystemException {
1819:                return getUsers(pk, begin, end, null);
1820:            }
1821:
1822:            public List getUsers(long pk, int begin, int end,
1823:                    OrderByComparator obc) throws NoSuchRoleException,
1824:                    SystemException {
1825:                boolean finderClassNameCacheEnabled = RoleModelImpl.CACHE_ENABLED_USERS_ROLES;
1826:                String finderClassName = "Users_Roles";
1827:                String finderMethodName = "getUsers";
1828:                String[] finderParams = new String[] { Long.class.getName(),
1829:                        "java.lang.Integer", "java.lang.Integer",
1830:                        "com.liferay.portal.kernel.util.OrderByComparator" };
1831:                Object[] finderArgs = new Object[] { new Long(pk),
1832:                        String.valueOf(begin), String.valueOf(end),
1833:                        String.valueOf(obc) };
1834:
1835:                Object result = null;
1836:
1837:                if (finderClassNameCacheEnabled) {
1838:                    result = FinderCache.getResult(finderClassName,
1839:                            finderMethodName, finderParams, finderArgs,
1840:                            getSessionFactory());
1841:                }
1842:
1843:                if (result == null) {
1844:                    Session session = null;
1845:
1846:                    try {
1847:                        session = HibernateUtil.openSession();
1848:
1849:                        StringMaker sm = new StringMaker();
1850:
1851:                        sm.append(_SQL_GETUSERS);
1852:
1853:                        if (obc != null) {
1854:                            sm.append("ORDER BY ");
1855:                            sm.append(obc.getOrderBy());
1856:                        }
1857:
1858:                        String sql = sm.toString();
1859:
1860:                        SQLQuery q = session.createSQLQuery(sql);
1861:
1862:                        q.addEntity("User_",
1863:                                com.liferay.portal.model.impl.UserImpl.class);
1864:
1865:                        QueryPos qPos = QueryPos.getInstance(q);
1866:
1867:                        qPos.add(pk);
1868:
1869:                        List list = QueryUtil.list(q, getDialect(), begin, end);
1870:
1871:                        FinderCache.putResult(finderClassNameCacheEnabled,
1872:                                finderClassName, finderMethodName,
1873:                                finderParams, finderArgs, list);
1874:
1875:                        return list;
1876:                    } catch (Exception e) {
1877:                        throw new SystemException(e);
1878:                    } finally {
1879:                        closeSession(session);
1880:                    }
1881:                } else {
1882:                    return (List) result;
1883:                }
1884:            }
1885:
1886:            public int getUsersSize(long pk) throws SystemException {
1887:                boolean finderClassNameCacheEnabled = RoleModelImpl.CACHE_ENABLED_USERS_ROLES;
1888:                String finderClassName = "Users_Roles";
1889:                String finderMethodName = "getUsersSize";
1890:                String[] finderParams = new String[] { Long.class.getName() };
1891:                Object[] finderArgs = new Object[] { new Long(pk) };
1892:
1893:                Object result = null;
1894:
1895:                if (finderClassNameCacheEnabled) {
1896:                    result = FinderCache.getResult(finderClassName,
1897:                            finderMethodName, finderParams, finderArgs,
1898:                            getSessionFactory());
1899:                }
1900:
1901:                if (result == null) {
1902:                    Session session = null;
1903:
1904:                    try {
1905:                        session = openSession();
1906:
1907:                        SQLQuery q = session.createSQLQuery(_SQL_GETUSERSSIZE);
1908:
1909:                        q.addScalar(HibernateUtil.getCountColumnName(),
1910:                                Hibernate.LONG);
1911:
1912:                        QueryPos qPos = QueryPos.getInstance(q);
1913:
1914:                        qPos.add(pk);
1915:
1916:                        Long count = null;
1917:
1918:                        Iterator itr = q.list().iterator();
1919:
1920:                        if (itr.hasNext()) {
1921:                            count = (Long) itr.next();
1922:                        }
1923:
1924:                        if (count == null) {
1925:                            count = new Long(0);
1926:                        }
1927:
1928:                        FinderCache.putResult(finderClassNameCacheEnabled,
1929:                                finderClassName, finderMethodName,
1930:                                finderParams, finderArgs, count);
1931:
1932:                        return count.intValue();
1933:                    } catch (Exception e) {
1934:                        throw HibernateUtil.processException(e);
1935:                    } finally {
1936:                        closeSession(session);
1937:                    }
1938:                } else {
1939:                    return ((Long) result).intValue();
1940:                }
1941:            }
1942:
1943:            public boolean containsUser(long pk, long userPK)
1944:                    throws SystemException {
1945:                boolean finderClassNameCacheEnabled = RoleModelImpl.CACHE_ENABLED_USERS_ROLES;
1946:                String finderClassName = "Users_Roles";
1947:                String finderMethodName = "containsUsers";
1948:                String[] finderParams = new String[] { Long.class.getName(),
1949:
1950:                Long.class.getName() };
1951:                Object[] finderArgs = new Object[] { new Long(pk),
1952:                        new Long(userPK) };
1953:
1954:                Object result = null;
1955:
1956:                if (finderClassNameCacheEnabled) {
1957:                    result = FinderCache.getResult(finderClassName,
1958:                            finderMethodName, finderParams, finderArgs,
1959:                            getSessionFactory());
1960:                }
1961:
1962:                if (result == null) {
1963:                    try {
1964:                        Boolean value = Boolean.valueOf(containsUser.contains(
1965:                                pk, userPK));
1966:
1967:                        FinderCache.putResult(finderClassNameCacheEnabled,
1968:                                finderClassName, finderMethodName,
1969:                                finderParams, finderArgs, value);
1970:
1971:                        return value.booleanValue();
1972:                    } catch (DataAccessException dae) {
1973:                        throw new SystemException(dae);
1974:                    }
1975:                } else {
1976:                    return ((Boolean) result).booleanValue();
1977:                }
1978:            }
1979:
1980:            public boolean containsUsers(long pk) throws SystemException {
1981:                if (getUsersSize(pk) > 0) {
1982:                    return true;
1983:                } else {
1984:                    return false;
1985:                }
1986:            }
1987:
1988:            public void addUser(long pk, long userPK)
1989:                    throws NoSuchRoleException,
1990:                    com.liferay.portal.NoSuchUserException, SystemException {
1991:                try {
1992:                    addUser.add(pk, userPK);
1993:                } catch (DataAccessException dae) {
1994:                    throw new SystemException(dae);
1995:                } finally {
1996:                    FinderCache.clearCache("Users_Roles");
1997:                }
1998:            }
1999:
2000:            public void addUser(long pk, com.liferay.portal.model.User user)
2001:                    throws NoSuchRoleException,
2002:                    com.liferay.portal.NoSuchUserException, SystemException {
2003:                try {
2004:                    addUser.add(pk, user.getPrimaryKey());
2005:                } catch (DataAccessException dae) {
2006:                    throw new SystemException(dae);
2007:                } finally {
2008:                    FinderCache.clearCache("Users_Roles");
2009:                }
2010:            }
2011:
2012:            public void addUsers(long pk, long[] userPKs)
2013:                    throws NoSuchRoleException,
2014:                    com.liferay.portal.NoSuchUserException, SystemException {
2015:                try {
2016:                    for (int i = 0; i < userPKs.length; i++) {
2017:                        addUser.add(pk, userPKs[i]);
2018:                    }
2019:                } catch (DataAccessException dae) {
2020:                    throw new SystemException(dae);
2021:                } finally {
2022:                    FinderCache.clearCache("Users_Roles");
2023:                }
2024:            }
2025:
2026:            public void addUsers(long pk, List users)
2027:                    throws NoSuchRoleException,
2028:                    com.liferay.portal.NoSuchUserException, SystemException {
2029:                try {
2030:                    for (int i = 0; i < users.size(); i++) {
2031:                        com.liferay.portal.model.User user = (com.liferay.portal.model.User) users
2032:                                .get(i);
2033:
2034:                        addUser.add(pk, user.getPrimaryKey());
2035:                    }
2036:                } catch (DataAccessException dae) {
2037:                    throw new SystemException(dae);
2038:                } finally {
2039:                    FinderCache.clearCache("Users_Roles");
2040:                }
2041:            }
2042:
2043:            public void clearUsers(long pk) throws NoSuchRoleException,
2044:                    SystemException {
2045:                try {
2046:                    clearUsers.clear(pk);
2047:                } catch (DataAccessException dae) {
2048:                    throw new SystemException(dae);
2049:                } finally {
2050:                    FinderCache.clearCache("Users_Roles");
2051:                }
2052:            }
2053:
2054:            public void removeUser(long pk, long userPK)
2055:                    throws NoSuchRoleException,
2056:                    com.liferay.portal.NoSuchUserException, SystemException {
2057:                try {
2058:                    removeUser.remove(pk, userPK);
2059:                } catch (DataAccessException dae) {
2060:                    throw new SystemException(dae);
2061:                } finally {
2062:                    FinderCache.clearCache("Users_Roles");
2063:                }
2064:            }
2065:
2066:            public void removeUser(long pk, com.liferay.portal.model.User user)
2067:                    throws NoSuchRoleException,
2068:                    com.liferay.portal.NoSuchUserException, SystemException {
2069:                try {
2070:                    removeUser.remove(pk, user.getPrimaryKey());
2071:                } catch (DataAccessException dae) {
2072:                    throw new SystemException(dae);
2073:                } finally {
2074:                    FinderCache.clearCache("Users_Roles");
2075:                }
2076:            }
2077:
2078:            public void removeUsers(long pk, long[] userPKs)
2079:                    throws NoSuchRoleException,
2080:                    com.liferay.portal.NoSuchUserException, SystemException {
2081:                try {
2082:                    for (int i = 0; i < userPKs.length; i++) {
2083:                        removeUser.remove(pk, userPKs[i]);
2084:                    }
2085:                } catch (DataAccessException dae) {
2086:                    throw new SystemException(dae);
2087:                } finally {
2088:                    FinderCache.clearCache("Users_Roles");
2089:                }
2090:            }
2091:
2092:            public void removeUsers(long pk, List users)
2093:                    throws NoSuchRoleException,
2094:                    com.liferay.portal.NoSuchUserException, SystemException {
2095:                try {
2096:                    for (int i = 0; i < users.size(); i++) {
2097:                        com.liferay.portal.model.User user = (com.liferay.portal.model.User) users
2098:                                .get(i);
2099:
2100:                        removeUser.remove(pk, user.getPrimaryKey());
2101:                    }
2102:                } catch (DataAccessException dae) {
2103:                    throw new SystemException(dae);
2104:                } finally {
2105:                    FinderCache.clearCache("Users_Roles");
2106:                }
2107:            }
2108:
2109:            public void setUsers(long pk, long[] userPKs)
2110:                    throws NoSuchRoleException,
2111:                    com.liferay.portal.NoSuchUserException, SystemException {
2112:                try {
2113:                    clearUsers.clear(pk);
2114:
2115:                    for (int i = 0; i < userPKs.length; i++) {
2116:                        addUser.add(pk, userPKs[i]);
2117:                    }
2118:                } catch (DataAccessException dae) {
2119:                    throw new SystemException(dae);
2120:                } finally {
2121:                    FinderCache.clearCache("Users_Roles");
2122:                }
2123:            }
2124:
2125:            public void setUsers(long pk, List users)
2126:                    throws NoSuchRoleException,
2127:                    com.liferay.portal.NoSuchUserException, SystemException {
2128:                try {
2129:                    clearUsers.clear(pk);
2130:
2131:                    for (int i = 0; i < users.size(); i++) {
2132:                        com.liferay.portal.model.User user = (com.liferay.portal.model.User) users
2133:                                .get(i);
2134:
2135:                        addUser.add(pk, user.getPrimaryKey());
2136:                    }
2137:                } catch (DataAccessException dae) {
2138:                    throw new SystemException(dae);
2139:                } finally {
2140:                    FinderCache.clearCache("Users_Roles");
2141:                }
2142:            }
2143:
2144:            protected void initDao() {
2145:                containsGroup = new ContainsGroup(this );
2146:
2147:                addGroup = new AddGroup(this );
2148:                clearGroups = new ClearGroups(this );
2149:                removeGroup = new RemoveGroup(this );
2150:
2151:                containsPermission = new ContainsPermission(this );
2152:
2153:                addPermission = new AddPermission(this );
2154:                clearPermissions = new ClearPermissions(this );
2155:                removePermission = new RemovePermission(this );
2156:
2157:                containsUser = new ContainsUser(this );
2158:
2159:                addUser = new AddUser(this );
2160:                clearUsers = new ClearUsers(this );
2161:                removeUser = new RemoveUser(this );
2162:            }
2163:
2164:            protected ContainsGroup containsGroup;
2165:            protected AddGroup addGroup;
2166:            protected ClearGroups clearGroups;
2167:            protected RemoveGroup removeGroup;
2168:            protected ContainsPermission containsPermission;
2169:            protected AddPermission addPermission;
2170:            protected ClearPermissions clearPermissions;
2171:            protected RemovePermission removePermission;
2172:            protected ContainsUser containsUser;
2173:            protected AddUser addUser;
2174:            protected ClearUsers clearUsers;
2175:            protected RemoveUser removeUser;
2176:
2177:            protected class ContainsGroup extends MappingSqlQuery {
2178:                protected ContainsGroup(RolePersistenceImpl persistenceImpl) {
2179:                    super (persistenceImpl.getDataSource(), _SQL_CONTAINSGROUP);
2180:
2181:                    declareParameter(new SqlParameter(Types.BIGINT));
2182:                    declareParameter(new SqlParameter(Types.BIGINT));
2183:
2184:                    compile();
2185:                }
2186:
2187:                protected Object mapRow(ResultSet rs, int rowNumber)
2188:                        throws SQLException {
2189:                    return new Integer(rs.getInt("COUNT_VALUE"));
2190:                }
2191:
2192:                protected boolean contains(long roleId, long groupId) {
2193:                    List results = execute(new Object[] { new Long(roleId),
2194:                            new Long(groupId) });
2195:
2196:                    if (results.size() > 0) {
2197:                        Integer count = (Integer) results.get(0);
2198:
2199:                        if (count.intValue() > 0) {
2200:                            return true;
2201:                        }
2202:                    }
2203:
2204:                    return false;
2205:                }
2206:            }
2207:
2208:            protected class AddGroup extends SqlUpdate {
2209:                protected AddGroup(RolePersistenceImpl persistenceImpl) {
2210:                    super (persistenceImpl.getDataSource(),
2211:                            "INSERT INTO Groups_Roles (roleId, groupId) VALUES (?, ?)");
2212:
2213:                    _persistenceImpl = persistenceImpl;
2214:
2215:                    declareParameter(new SqlParameter(Types.BIGINT));
2216:                    declareParameter(new SqlParameter(Types.BIGINT));
2217:
2218:                    compile();
2219:                }
2220:
2221:                protected void add(long roleId, long groupId) {
2222:                    if (!_persistenceImpl.containsGroup.contains(roleId,
2223:                            groupId)) {
2224:                        update(new Object[] { new Long(roleId),
2225:                                new Long(groupId) });
2226:                    }
2227:                }
2228:
2229:                private RolePersistenceImpl _persistenceImpl;
2230:            }
2231:
2232:            protected class ClearGroups extends SqlUpdate {
2233:                protected ClearGroups(RolePersistenceImpl persistenceImpl) {
2234:                    super (persistenceImpl.getDataSource(),
2235:                            "DELETE FROM Groups_Roles WHERE roleId = ?");
2236:
2237:                    declareParameter(new SqlParameter(Types.BIGINT));
2238:
2239:                    compile();
2240:                }
2241:
2242:                protected void clear(long roleId) {
2243:                    update(new Object[] { new Long(roleId) });
2244:                }
2245:            }
2246:
2247:            protected class RemoveGroup extends SqlUpdate {
2248:                protected RemoveGroup(RolePersistenceImpl persistenceImpl) {
2249:                    super (persistenceImpl.getDataSource(),
2250:                            "DELETE FROM Groups_Roles WHERE roleId = ? AND groupId = ?");
2251:
2252:                    declareParameter(new SqlParameter(Types.BIGINT));
2253:                    declareParameter(new SqlParameter(Types.BIGINT));
2254:
2255:                    compile();
2256:                }
2257:
2258:                protected void remove(long roleId, long groupId) {
2259:                    update(new Object[] { new Long(roleId), new Long(groupId) });
2260:                }
2261:            }
2262:
2263:            protected class ContainsPermission extends MappingSqlQuery {
2264:                protected ContainsPermission(RolePersistenceImpl persistenceImpl) {
2265:                    super (persistenceImpl.getDataSource(),
2266:                            _SQL_CONTAINSPERMISSION);
2267:
2268:                    declareParameter(new SqlParameter(Types.BIGINT));
2269:                    declareParameter(new SqlParameter(Types.BIGINT));
2270:
2271:                    compile();
2272:                }
2273:
2274:                protected Object mapRow(ResultSet rs, int rowNumber)
2275:                        throws SQLException {
2276:                    return new Integer(rs.getInt("COUNT_VALUE"));
2277:                }
2278:
2279:                protected boolean contains(long roleId, long permissionId) {
2280:                    List results = execute(new Object[] { new Long(roleId),
2281:                            new Long(permissionId) });
2282:
2283:                    if (results.size() > 0) {
2284:                        Integer count = (Integer) results.get(0);
2285:
2286:                        if (count.intValue() > 0) {
2287:                            return true;
2288:                        }
2289:                    }
2290:
2291:                    return false;
2292:                }
2293:            }
2294:
2295:            protected class AddPermission extends SqlUpdate {
2296:                protected AddPermission(RolePersistenceImpl persistenceImpl) {
2297:                    super (persistenceImpl.getDataSource(),
2298:                            "INSERT INTO Roles_Permissions (roleId, permissionId) VALUES (?, ?)");
2299:
2300:                    _persistenceImpl = persistenceImpl;
2301:
2302:                    declareParameter(new SqlParameter(Types.BIGINT));
2303:                    declareParameter(new SqlParameter(Types.BIGINT));
2304:
2305:                    compile();
2306:                }
2307:
2308:                protected void add(long roleId, long permissionId) {
2309:                    if (!_persistenceImpl.containsPermission.contains(roleId,
2310:                            permissionId)) {
2311:                        update(new Object[] { new Long(roleId),
2312:                                new Long(permissionId) });
2313:                    }
2314:                }
2315:
2316:                private RolePersistenceImpl _persistenceImpl;
2317:            }
2318:
2319:            protected class ClearPermissions extends SqlUpdate {
2320:                protected ClearPermissions(RolePersistenceImpl persistenceImpl) {
2321:                    super (persistenceImpl.getDataSource(),
2322:                            "DELETE FROM Roles_Permissions WHERE roleId = ?");
2323:
2324:                    declareParameter(new SqlParameter(Types.BIGINT));
2325:
2326:                    compile();
2327:                }
2328:
2329:                protected void clear(long roleId) {
2330:                    update(new Object[] { new Long(roleId) });
2331:                }
2332:            }
2333:
2334:            protected class RemovePermission extends SqlUpdate {
2335:                protected RemovePermission(RolePersistenceImpl persistenceImpl) {
2336:                    super (persistenceImpl.getDataSource(),
2337:                            "DELETE FROM Roles_Permissions WHERE roleId = ? AND permissionId = ?");
2338:
2339:                    declareParameter(new SqlParameter(Types.BIGINT));
2340:                    declareParameter(new SqlParameter(Types.BIGINT));
2341:
2342:                    compile();
2343:                }
2344:
2345:                protected void remove(long roleId, long permissionId) {
2346:                    update(new Object[] { new Long(roleId),
2347:                            new Long(permissionId) });
2348:                }
2349:            }
2350:
2351:            protected class ContainsUser extends MappingSqlQuery {
2352:                protected ContainsUser(RolePersistenceImpl persistenceImpl) {
2353:                    super (persistenceImpl.getDataSource(), _SQL_CONTAINSUSER);
2354:
2355:                    declareParameter(new SqlParameter(Types.BIGINT));
2356:                    declareParameter(new SqlParameter(Types.BIGINT));
2357:
2358:                    compile();
2359:                }
2360:
2361:                protected Object mapRow(ResultSet rs, int rowNumber)
2362:                        throws SQLException {
2363:                    return new Integer(rs.getInt("COUNT_VALUE"));
2364:                }
2365:
2366:                protected boolean contains(long roleId, long userId) {
2367:                    List results = execute(new Object[] { new Long(roleId),
2368:                            new Long(userId) });
2369:
2370:                    if (results.size() > 0) {
2371:                        Integer count = (Integer) results.get(0);
2372:
2373:                        if (count.intValue() > 0) {
2374:                            return true;
2375:                        }
2376:                    }
2377:
2378:                    return false;
2379:                }
2380:            }
2381:
2382:            protected class AddUser extends SqlUpdate {
2383:                protected AddUser(RolePersistenceImpl persistenceImpl) {
2384:                    super (persistenceImpl.getDataSource(),
2385:                            "INSERT INTO Users_Roles (roleId, userId) VALUES (?, ?)");
2386:
2387:                    _persistenceImpl = persistenceImpl;
2388:
2389:                    declareParameter(new SqlParameter(Types.BIGINT));
2390:                    declareParameter(new SqlParameter(Types.BIGINT));
2391:
2392:                    compile();
2393:                }
2394:
2395:                protected void add(long roleId, long userId) {
2396:                    if (!_persistenceImpl.containsUser.contains(roleId, userId)) {
2397:                        update(new Object[] { new Long(roleId),
2398:                                new Long(userId) });
2399:                    }
2400:                }
2401:
2402:                private RolePersistenceImpl _persistenceImpl;
2403:            }
2404:
2405:            protected class ClearUsers extends SqlUpdate {
2406:                protected ClearUsers(RolePersistenceImpl persistenceImpl) {
2407:                    super (persistenceImpl.getDataSource(),
2408:                            "DELETE FROM Users_Roles WHERE roleId = ?");
2409:
2410:                    declareParameter(new SqlParameter(Types.BIGINT));
2411:
2412:                    compile();
2413:                }
2414:
2415:                protected void clear(long roleId) {
2416:                    update(new Object[] { new Long(roleId) });
2417:                }
2418:            }
2419:
2420:            protected class RemoveUser extends SqlUpdate {
2421:                protected RemoveUser(RolePersistenceImpl persistenceImpl) {
2422:                    super (persistenceImpl.getDataSource(),
2423:                            "DELETE FROM Users_Roles WHERE roleId = ? AND userId = ?");
2424:
2425:                    declareParameter(new SqlParameter(Types.BIGINT));
2426:                    declareParameter(new SqlParameter(Types.BIGINT));
2427:
2428:                    compile();
2429:                }
2430:
2431:                protected void remove(long roleId, long userId) {
2432:                    update(new Object[] { new Long(roleId), new Long(userId) });
2433:                }
2434:            }
2435:
2436:            private static ModelListener _getListener() {
2437:                if (Validator.isNotNull(_LISTENER)) {
2438:                    try {
2439:                        return (ModelListener) Class.forName(_LISTENER)
2440:                                .newInstance();
2441:                    } catch (Exception e) {
2442:                        _log.error(e);
2443:                    }
2444:                }
2445:
2446:                return null;
2447:            }
2448:
2449:            private static final String _SQL_GETGROUPS = "SELECT {Group_.*} FROM Group_ INNER JOIN Groups_Roles ON (Groups_Roles.groupId = Group_.groupId) WHERE (Groups_Roles.roleId = ?)";
2450:            private static final String _SQL_GETGROUPSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_Roles WHERE roleId = ?";
2451:            private static final String _SQL_CONTAINSGROUP = "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_Roles WHERE roleId = ? AND groupId = ?";
2452:            private static final String _SQL_GETPERMISSIONS = "SELECT {Permission_.*} FROM Permission_ INNER JOIN Roles_Permissions ON (Roles_Permissions.permissionId = Permission_.permissionId) WHERE (Roles_Permissions.roleId = ?)";
2453:            private static final String _SQL_GETPERMISSIONSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Roles_Permissions WHERE roleId = ?";
2454:            private static final String _SQL_CONTAINSPERMISSION = "SELECT COUNT(*) AS COUNT_VALUE FROM Roles_Permissions WHERE roleId = ? AND permissionId = ?";
2455:            private static final String _SQL_GETUSERS = "SELECT {User_.*} FROM User_ INNER JOIN Users_Roles ON (Users_Roles.userId = User_.userId) WHERE (Users_Roles.roleId = ?)";
2456:            private static final String _SQL_GETUSERSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Roles WHERE roleId = ?";
2457:            private static final String _SQL_CONTAINSUSER = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Roles WHERE roleId = ? AND userId = ?";
2458:            private static final String _LISTENER = GetterUtil
2459:                    .getString(PropsUtil
2460:                            .get("value.object.listener.com.liferay.portal.model.Role"));
2461:            private static Log _log = LogFactory
2462:                    .getLog(RolePersistenceImpl.class);
2463:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.