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