Source Code Cross Referenced for ResourceCodePersistenceImpl.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.NoSuchResourceCodeException;
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.ResourceCode;
0034:        import com.liferay.portal.model.impl.ResourceCodeImpl;
0035:        import com.liferay.portal.model.impl.ResourceCodeModelImpl;
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.QueryUtil;
0041:
0042:        import org.apache.commons.logging.Log;
0043:        import org.apache.commons.logging.LogFactory;
0044:
0045:        import org.hibernate.Query;
0046:        import org.hibernate.Session;
0047:
0048:        import java.util.Collections;
0049:        import java.util.Iterator;
0050:        import java.util.List;
0051:
0052:        /**
0053:         * <a href="ResourceCodePersistenceImpl.java.html"><b><i>View Source</i></b></a>
0054:         *
0055:         * @author Brian Wing Shun Chan
0056:         *
0057:         */
0058:        public class ResourceCodePersistenceImpl extends BasePersistence
0059:                implements  ResourceCodePersistence {
0060:            public ResourceCode create(long codeId) {
0061:                ResourceCode resourceCode = new ResourceCodeImpl();
0062:
0063:                resourceCode.setNew(true);
0064:                resourceCode.setPrimaryKey(codeId);
0065:
0066:                return resourceCode;
0067:            }
0068:
0069:            public ResourceCode remove(long codeId)
0070:                    throws NoSuchResourceCodeException, SystemException {
0071:                Session session = null;
0072:
0073:                try {
0074:                    session = openSession();
0075:
0076:                    ResourceCode resourceCode = (ResourceCode) session.get(
0077:                            ResourceCodeImpl.class, new Long(codeId));
0078:
0079:                    if (resourceCode == null) {
0080:                        if (_log.isWarnEnabled()) {
0081:                            _log
0082:                                    .warn("No ResourceCode exists with the primary key "
0083:                                            + codeId);
0084:                        }
0085:
0086:                        throw new NoSuchResourceCodeException(
0087:                                "No ResourceCode exists with the primary key "
0088:                                        + codeId);
0089:                    }
0090:
0091:                    return remove(resourceCode);
0092:                } catch (NoSuchResourceCodeException nsee) {
0093:                    throw nsee;
0094:                } catch (Exception e) {
0095:                    throw HibernateUtil.processException(e);
0096:                } finally {
0097:                    closeSession(session);
0098:                }
0099:            }
0100:
0101:            public ResourceCode remove(ResourceCode resourceCode)
0102:                    throws SystemException {
0103:                ModelListener listener = _getListener();
0104:
0105:                if (listener != null) {
0106:                    listener.onBeforeRemove(resourceCode);
0107:                }
0108:
0109:                resourceCode = removeImpl(resourceCode);
0110:
0111:                if (listener != null) {
0112:                    listener.onAfterRemove(resourceCode);
0113:                }
0114:
0115:                return resourceCode;
0116:            }
0117:
0118:            protected ResourceCode removeImpl(ResourceCode resourceCode)
0119:                    throws SystemException {
0120:                Session session = null;
0121:
0122:                try {
0123:                    session = openSession();
0124:
0125:                    session.delete(resourceCode);
0126:
0127:                    session.flush();
0128:
0129:                    return resourceCode;
0130:                } catch (Exception e) {
0131:                    throw HibernateUtil.processException(e);
0132:                } finally {
0133:                    closeSession(session);
0134:
0135:                    FinderCache.clearCache(ResourceCode.class.getName());
0136:                }
0137:            }
0138:
0139:            public ResourceCode update(ResourceCode resourceCode)
0140:                    throws SystemException {
0141:                return update(resourceCode, false);
0142:            }
0143:
0144:            public ResourceCode update(ResourceCode resourceCode, boolean merge)
0145:                    throws SystemException {
0146:                ModelListener listener = _getListener();
0147:
0148:                boolean isNew = resourceCode.isNew();
0149:
0150:                if (listener != null) {
0151:                    if (isNew) {
0152:                        listener.onBeforeCreate(resourceCode);
0153:                    } else {
0154:                        listener.onBeforeUpdate(resourceCode);
0155:                    }
0156:                }
0157:
0158:                resourceCode = updateImpl(resourceCode, merge);
0159:
0160:                if (listener != null) {
0161:                    if (isNew) {
0162:                        listener.onAfterCreate(resourceCode);
0163:                    } else {
0164:                        listener.onAfterUpdate(resourceCode);
0165:                    }
0166:                }
0167:
0168:                return resourceCode;
0169:            }
0170:
0171:            public ResourceCode updateImpl(
0172:                    com.liferay.portal.model.ResourceCode resourceCode,
0173:                    boolean merge) throws SystemException {
0174:                Session session = null;
0175:
0176:                try {
0177:                    session = openSession();
0178:
0179:                    if (merge) {
0180:                        session.merge(resourceCode);
0181:                    } else {
0182:                        if (resourceCode.isNew()) {
0183:                            session.save(resourceCode);
0184:                        }
0185:                    }
0186:
0187:                    session.flush();
0188:
0189:                    resourceCode.setNew(false);
0190:
0191:                    return resourceCode;
0192:                } catch (Exception e) {
0193:                    throw HibernateUtil.processException(e);
0194:                } finally {
0195:                    closeSession(session);
0196:
0197:                    FinderCache.clearCache(ResourceCode.class.getName());
0198:                }
0199:            }
0200:
0201:            public ResourceCode findByPrimaryKey(long codeId)
0202:                    throws NoSuchResourceCodeException, SystemException {
0203:                ResourceCode resourceCode = fetchByPrimaryKey(codeId);
0204:
0205:                if (resourceCode == null) {
0206:                    if (_log.isWarnEnabled()) {
0207:                        _log
0208:                                .warn("No ResourceCode exists with the primary key "
0209:                                        + codeId);
0210:                    }
0211:
0212:                    throw new NoSuchResourceCodeException(
0213:                            "No ResourceCode exists with the primary key "
0214:                                    + codeId);
0215:                }
0216:
0217:                return resourceCode;
0218:            }
0219:
0220:            public ResourceCode fetchByPrimaryKey(long codeId)
0221:                    throws SystemException {
0222:                Session session = null;
0223:
0224:                try {
0225:                    session = openSession();
0226:
0227:                    return (ResourceCode) session.get(ResourceCodeImpl.class,
0228:                            new Long(codeId));
0229:                } catch (Exception e) {
0230:                    throw HibernateUtil.processException(e);
0231:                } finally {
0232:                    closeSession(session);
0233:                }
0234:            }
0235:
0236:            public List findByCompanyId(long companyId) throws SystemException {
0237:                boolean finderClassNameCacheEnabled = ResourceCodeModelImpl.CACHE_ENABLED;
0238:                String finderClassName = ResourceCode.class.getName();
0239:                String finderMethodName = "findByCompanyId";
0240:                String[] finderParams = new String[] { Long.class.getName() };
0241:                Object[] finderArgs = new Object[] { new Long(companyId) };
0242:
0243:                Object result = null;
0244:
0245:                if (finderClassNameCacheEnabled) {
0246:                    result = FinderCache.getResult(finderClassName,
0247:                            finderMethodName, finderParams, finderArgs,
0248:                            getSessionFactory());
0249:                }
0250:
0251:                if (result == null) {
0252:                    Session session = null;
0253:
0254:                    try {
0255:                        session = openSession();
0256:
0257:                        StringMaker query = new StringMaker();
0258:
0259:                        query
0260:                                .append("FROM com.liferay.portal.model.ResourceCode WHERE ");
0261:
0262:                        query.append("companyId = ?");
0263:
0264:                        query.append(" ");
0265:
0266:                        Query q = session.createQuery(query.toString());
0267:
0268:                        int queryPos = 0;
0269:
0270:                        q.setLong(queryPos++, companyId);
0271:
0272:                        List list = q.list();
0273:
0274:                        FinderCache.putResult(finderClassNameCacheEnabled,
0275:                                finderClassName, finderMethodName,
0276:                                finderParams, finderArgs, list);
0277:
0278:                        return list;
0279:                    } catch (Exception e) {
0280:                        throw HibernateUtil.processException(e);
0281:                    } finally {
0282:                        closeSession(session);
0283:                    }
0284:                } else {
0285:                    return (List) result;
0286:                }
0287:            }
0288:
0289:            public List findByCompanyId(long companyId, int begin, int end)
0290:                    throws SystemException {
0291:                return findByCompanyId(companyId, begin, end, null);
0292:            }
0293:
0294:            public List findByCompanyId(long companyId, int begin, int end,
0295:                    OrderByComparator obc) throws SystemException {
0296:                boolean finderClassNameCacheEnabled = ResourceCodeModelImpl.CACHE_ENABLED;
0297:                String finderClassName = ResourceCode.class.getName();
0298:                String finderMethodName = "findByCompanyId";
0299:                String[] finderParams = new String[] { Long.class.getName(),
0300:
0301:                "java.lang.Integer", "java.lang.Integer",
0302:                        "com.liferay.portal.kernel.util.OrderByComparator" };
0303:                Object[] finderArgs = new Object[] { new Long(companyId),
0304:
0305:                String.valueOf(begin), String.valueOf(end), String.valueOf(obc) };
0306:
0307:                Object result = null;
0308:
0309:                if (finderClassNameCacheEnabled) {
0310:                    result = FinderCache.getResult(finderClassName,
0311:                            finderMethodName, finderParams, finderArgs,
0312:                            getSessionFactory());
0313:                }
0314:
0315:                if (result == null) {
0316:                    Session session = null;
0317:
0318:                    try {
0319:                        session = openSession();
0320:
0321:                        StringMaker query = new StringMaker();
0322:
0323:                        query
0324:                                .append("FROM com.liferay.portal.model.ResourceCode WHERE ");
0325:
0326:                        query.append("companyId = ?");
0327:
0328:                        query.append(" ");
0329:
0330:                        if (obc != null) {
0331:                            query.append("ORDER BY ");
0332:                            query.append(obc.getOrderBy());
0333:                        }
0334:
0335:                        Query q = session.createQuery(query.toString());
0336:
0337:                        int queryPos = 0;
0338:
0339:                        q.setLong(queryPos++, companyId);
0340:
0341:                        List list = QueryUtil.list(q, getDialect(), begin, end);
0342:
0343:                        FinderCache.putResult(finderClassNameCacheEnabled,
0344:                                finderClassName, finderMethodName,
0345:                                finderParams, finderArgs, list);
0346:
0347:                        return list;
0348:                    } catch (Exception e) {
0349:                        throw HibernateUtil.processException(e);
0350:                    } finally {
0351:                        closeSession(session);
0352:                    }
0353:                } else {
0354:                    return (List) result;
0355:                }
0356:            }
0357:
0358:            public ResourceCode findByCompanyId_First(long companyId,
0359:                    OrderByComparator obc) throws NoSuchResourceCodeException,
0360:                    SystemException {
0361:                List list = findByCompanyId(companyId, 0, 1, obc);
0362:
0363:                if (list.size() == 0) {
0364:                    StringMaker msg = new StringMaker();
0365:
0366:                    msg.append("No ResourceCode exists with the key {");
0367:
0368:                    msg.append("companyId=" + companyId);
0369:
0370:                    msg.append(StringPool.CLOSE_CURLY_BRACE);
0371:
0372:                    throw new NoSuchResourceCodeException(msg.toString());
0373:                } else {
0374:                    return (ResourceCode) list.get(0);
0375:                }
0376:            }
0377:
0378:            public ResourceCode findByCompanyId_Last(long companyId,
0379:                    OrderByComparator obc) throws NoSuchResourceCodeException,
0380:                    SystemException {
0381:                int count = countByCompanyId(companyId);
0382:
0383:                List list = findByCompanyId(companyId, count - 1, count, obc);
0384:
0385:                if (list.size() == 0) {
0386:                    StringMaker msg = new StringMaker();
0387:
0388:                    msg.append("No ResourceCode exists with the key {");
0389:
0390:                    msg.append("companyId=" + companyId);
0391:
0392:                    msg.append(StringPool.CLOSE_CURLY_BRACE);
0393:
0394:                    throw new NoSuchResourceCodeException(msg.toString());
0395:                } else {
0396:                    return (ResourceCode) list.get(0);
0397:                }
0398:            }
0399:
0400:            public ResourceCode[] findByCompanyId_PrevAndNext(long codeId,
0401:                    long companyId, OrderByComparator obc)
0402:                    throws NoSuchResourceCodeException, SystemException {
0403:                ResourceCode resourceCode = findByPrimaryKey(codeId);
0404:
0405:                int count = countByCompanyId(companyId);
0406:
0407:                Session session = null;
0408:
0409:                try {
0410:                    session = openSession();
0411:
0412:                    StringMaker query = new StringMaker();
0413:
0414:                    query
0415:                            .append("FROM com.liferay.portal.model.ResourceCode WHERE ");
0416:
0417:                    query.append("companyId = ?");
0418:
0419:                    query.append(" ");
0420:
0421:                    if (obc != null) {
0422:                        query.append("ORDER BY ");
0423:                        query.append(obc.getOrderBy());
0424:                    }
0425:
0426:                    Query q = session.createQuery(query.toString());
0427:
0428:                    int queryPos = 0;
0429:
0430:                    q.setLong(queryPos++, companyId);
0431:
0432:                    Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
0433:                            resourceCode);
0434:
0435:                    ResourceCode[] array = new ResourceCodeImpl[3];
0436:
0437:                    array[0] = (ResourceCode) objArray[0];
0438:                    array[1] = (ResourceCode) objArray[1];
0439:                    array[2] = (ResourceCode) objArray[2];
0440:
0441:                    return array;
0442:                } catch (Exception e) {
0443:                    throw HibernateUtil.processException(e);
0444:                } finally {
0445:                    closeSession(session);
0446:                }
0447:            }
0448:
0449:            public List findByName(String name) throws SystemException {
0450:                boolean finderClassNameCacheEnabled = ResourceCodeModelImpl.CACHE_ENABLED;
0451:                String finderClassName = ResourceCode.class.getName();
0452:                String finderMethodName = "findByName";
0453:                String[] finderParams = new String[] { String.class.getName() };
0454:                Object[] finderArgs = new Object[] { name };
0455:
0456:                Object result = null;
0457:
0458:                if (finderClassNameCacheEnabled) {
0459:                    result = FinderCache.getResult(finderClassName,
0460:                            finderMethodName, finderParams, finderArgs,
0461:                            getSessionFactory());
0462:                }
0463:
0464:                if (result == null) {
0465:                    Session session = null;
0466:
0467:                    try {
0468:                        session = openSession();
0469:
0470:                        StringMaker query = new StringMaker();
0471:
0472:                        query
0473:                                .append("FROM com.liferay.portal.model.ResourceCode WHERE ");
0474:
0475:                        if (name == null) {
0476:                            query.append("name IS NULL");
0477:                        } else {
0478:                            query.append("name = ?");
0479:                        }
0480:
0481:                        query.append(" ");
0482:
0483:                        Query q = session.createQuery(query.toString());
0484:
0485:                        int queryPos = 0;
0486:
0487:                        if (name != null) {
0488:                            q.setString(queryPos++, name);
0489:                        }
0490:
0491:                        List list = q.list();
0492:
0493:                        FinderCache.putResult(finderClassNameCacheEnabled,
0494:                                finderClassName, finderMethodName,
0495:                                finderParams, finderArgs, list);
0496:
0497:                        return list;
0498:                    } catch (Exception e) {
0499:                        throw HibernateUtil.processException(e);
0500:                    } finally {
0501:                        closeSession(session);
0502:                    }
0503:                } else {
0504:                    return (List) result;
0505:                }
0506:            }
0507:
0508:            public List findByName(String name, int begin, int end)
0509:                    throws SystemException {
0510:                return findByName(name, begin, end, null);
0511:            }
0512:
0513:            public List findByName(String name, int begin, int end,
0514:                    OrderByComparator obc) throws SystemException {
0515:                boolean finderClassNameCacheEnabled = ResourceCodeModelImpl.CACHE_ENABLED;
0516:                String finderClassName = ResourceCode.class.getName();
0517:                String finderMethodName = "findByName";
0518:                String[] finderParams = new String[] { String.class.getName(),
0519:
0520:                "java.lang.Integer", "java.lang.Integer",
0521:                        "com.liferay.portal.kernel.util.OrderByComparator" };
0522:                Object[] finderArgs = new Object[] { name,
0523:
0524:                String.valueOf(begin), String.valueOf(end), String.valueOf(obc) };
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.ResourceCode WHERE ");
0544:
0545:                        if (name == null) {
0546:                            query.append("name IS NULL");
0547:                        } else {
0548:                            query.append("name = ?");
0549:                        }
0550:
0551:                        query.append(" ");
0552:
0553:                        if (obc != null) {
0554:                            query.append("ORDER BY ");
0555:                            query.append(obc.getOrderBy());
0556:                        }
0557:
0558:                        Query q = session.createQuery(query.toString());
0559:
0560:                        int queryPos = 0;
0561:
0562:                        if (name != null) {
0563:                            q.setString(queryPos++, name);
0564:                        }
0565:
0566:                        List list = QueryUtil.list(q, getDialect(), begin, end);
0567:
0568:                        FinderCache.putResult(finderClassNameCacheEnabled,
0569:                                finderClassName, finderMethodName,
0570:                                finderParams, finderArgs, list);
0571:
0572:                        return list;
0573:                    } catch (Exception e) {
0574:                        throw HibernateUtil.processException(e);
0575:                    } finally {
0576:                        closeSession(session);
0577:                    }
0578:                } else {
0579:                    return (List) result;
0580:                }
0581:            }
0582:
0583:            public ResourceCode findByName_First(String name,
0584:                    OrderByComparator obc) throws NoSuchResourceCodeException,
0585:                    SystemException {
0586:                List list = findByName(name, 0, 1, obc);
0587:
0588:                if (list.size() == 0) {
0589:                    StringMaker msg = new StringMaker();
0590:
0591:                    msg.append("No ResourceCode exists with the key {");
0592:
0593:                    msg.append("name=" + name);
0594:
0595:                    msg.append(StringPool.CLOSE_CURLY_BRACE);
0596:
0597:                    throw new NoSuchResourceCodeException(msg.toString());
0598:                } else {
0599:                    return (ResourceCode) list.get(0);
0600:                }
0601:            }
0602:
0603:            public ResourceCode findByName_Last(String name,
0604:                    OrderByComparator obc) throws NoSuchResourceCodeException,
0605:                    SystemException {
0606:                int count = countByName(name);
0607:
0608:                List list = findByName(name, count - 1, count, obc);
0609:
0610:                if (list.size() == 0) {
0611:                    StringMaker msg = new StringMaker();
0612:
0613:                    msg.append("No ResourceCode exists with the key {");
0614:
0615:                    msg.append("name=" + name);
0616:
0617:                    msg.append(StringPool.CLOSE_CURLY_BRACE);
0618:
0619:                    throw new NoSuchResourceCodeException(msg.toString());
0620:                } else {
0621:                    return (ResourceCode) list.get(0);
0622:                }
0623:            }
0624:
0625:            public ResourceCode[] findByName_PrevAndNext(long codeId,
0626:                    String name, OrderByComparator obc)
0627:                    throws NoSuchResourceCodeException, SystemException {
0628:                ResourceCode resourceCode = findByPrimaryKey(codeId);
0629:
0630:                int count = countByName(name);
0631:
0632:                Session session = null;
0633:
0634:                try {
0635:                    session = openSession();
0636:
0637:                    StringMaker query = new StringMaker();
0638:
0639:                    query
0640:                            .append("FROM com.liferay.portal.model.ResourceCode WHERE ");
0641:
0642:                    if (name == null) {
0643:                        query.append("name IS NULL");
0644:                    } else {
0645:                        query.append("name = ?");
0646:                    }
0647:
0648:                    query.append(" ");
0649:
0650:                    if (obc != null) {
0651:                        query.append("ORDER BY ");
0652:                        query.append(obc.getOrderBy());
0653:                    }
0654:
0655:                    Query q = session.createQuery(query.toString());
0656:
0657:                    int queryPos = 0;
0658:
0659:                    if (name != null) {
0660:                        q.setString(queryPos++, name);
0661:                    }
0662:
0663:                    Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
0664:                            resourceCode);
0665:
0666:                    ResourceCode[] array = new ResourceCodeImpl[3];
0667:
0668:                    array[0] = (ResourceCode) objArray[0];
0669:                    array[1] = (ResourceCode) objArray[1];
0670:                    array[2] = (ResourceCode) objArray[2];
0671:
0672:                    return array;
0673:                } catch (Exception e) {
0674:                    throw HibernateUtil.processException(e);
0675:                } finally {
0676:                    closeSession(session);
0677:                }
0678:            }
0679:
0680:            public ResourceCode findByC_N_S(long companyId, String name,
0681:                    int scope) throws NoSuchResourceCodeException,
0682:                    SystemException {
0683:                ResourceCode resourceCode = fetchByC_N_S(companyId, name, scope);
0684:
0685:                if (resourceCode == null) {
0686:                    StringMaker msg = new StringMaker();
0687:
0688:                    msg.append("No ResourceCode exists with the key {");
0689:
0690:                    msg.append("companyId=" + companyId);
0691:
0692:                    msg.append(", ");
0693:                    msg.append("name=" + name);
0694:
0695:                    msg.append(", ");
0696:                    msg.append("scope=" + scope);
0697:
0698:                    msg.append(StringPool.CLOSE_CURLY_BRACE);
0699:
0700:                    if (_log.isWarnEnabled()) {
0701:                        _log.warn(msg.toString());
0702:                    }
0703:
0704:                    throw new NoSuchResourceCodeException(msg.toString());
0705:                }
0706:
0707:                return resourceCode;
0708:            }
0709:
0710:            public ResourceCode fetchByC_N_S(long companyId, String name,
0711:                    int scope) throws SystemException {
0712:                boolean finderClassNameCacheEnabled = ResourceCodeModelImpl.CACHE_ENABLED;
0713:                String finderClassName = ResourceCode.class.getName();
0714:                String finderMethodName = "fetchByC_N_S";
0715:                String[] finderParams = new String[] { Long.class.getName(),
0716:                        String.class.getName(), Integer.class.getName() };
0717:                Object[] finderArgs = new Object[] { new Long(companyId),
0718:
0719:                name, new Integer(scope) };
0720:
0721:                Object result = null;
0722:
0723:                if (finderClassNameCacheEnabled) {
0724:                    result = FinderCache.getResult(finderClassName,
0725:                            finderMethodName, finderParams, finderArgs,
0726:                            getSessionFactory());
0727:                }
0728:
0729:                if (result == null) {
0730:                    Session session = null;
0731:
0732:                    try {
0733:                        session = openSession();
0734:
0735:                        StringMaker query = new StringMaker();
0736:
0737:                        query
0738:                                .append("FROM com.liferay.portal.model.ResourceCode WHERE ");
0739:
0740:                        query.append("companyId = ?");
0741:
0742:                        query.append(" AND ");
0743:
0744:                        if (name == null) {
0745:                            query.append("name IS NULL");
0746:                        } else {
0747:                            query.append("name = ?");
0748:                        }
0749:
0750:                        query.append(" AND ");
0751:
0752:                        query.append("scope = ?");
0753:
0754:                        query.append(" ");
0755:
0756:                        Query q = session.createQuery(query.toString());
0757:
0758:                        int queryPos = 0;
0759:
0760:                        q.setLong(queryPos++, companyId);
0761:
0762:                        if (name != null) {
0763:                            q.setString(queryPos++, name);
0764:                        }
0765:
0766:                        q.setInteger(queryPos++, scope);
0767:
0768:                        List list = q.list();
0769:
0770:                        FinderCache.putResult(finderClassNameCacheEnabled,
0771:                                finderClassName, finderMethodName,
0772:                                finderParams, finderArgs, list);
0773:
0774:                        if (list.size() == 0) {
0775:                            return null;
0776:                        } else {
0777:                            return (ResourceCode) list.get(0);
0778:                        }
0779:                    } catch (Exception e) {
0780:                        throw HibernateUtil.processException(e);
0781:                    } finally {
0782:                        closeSession(session);
0783:                    }
0784:                } else {
0785:                    List list = (List) result;
0786:
0787:                    if (list.size() == 0) {
0788:                        return null;
0789:                    } else {
0790:                        return (ResourceCode) list.get(0);
0791:                    }
0792:                }
0793:            }
0794:
0795:            public List findWithDynamicQuery(
0796:                    DynamicQueryInitializer queryInitializer)
0797:                    throws SystemException {
0798:                Session session = null;
0799:
0800:                try {
0801:                    session = openSession();
0802:
0803:                    DynamicQuery query = queryInitializer.initialize(session);
0804:
0805:                    return query.list();
0806:                } catch (Exception e) {
0807:                    throw HibernateUtil.processException(e);
0808:                } finally {
0809:                    closeSession(session);
0810:                }
0811:            }
0812:
0813:            public List findWithDynamicQuery(
0814:                    DynamicQueryInitializer queryInitializer, int begin, int end)
0815:                    throws SystemException {
0816:                Session session = null;
0817:
0818:                try {
0819:                    session = openSession();
0820:
0821:                    DynamicQuery query = queryInitializer.initialize(session);
0822:
0823:                    query.setLimit(begin, end);
0824:
0825:                    return query.list();
0826:                } catch (Exception e) {
0827:                    throw HibernateUtil.processException(e);
0828:                } finally {
0829:                    closeSession(session);
0830:                }
0831:            }
0832:
0833:            public List findAll() throws SystemException {
0834:                return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
0835:            }
0836:
0837:            public List findAll(int begin, int end) throws SystemException {
0838:                return findAll(begin, end, null);
0839:            }
0840:
0841:            public List findAll(int begin, int end, OrderByComparator obc)
0842:                    throws SystemException {
0843:                boolean finderClassNameCacheEnabled = ResourceCodeModelImpl.CACHE_ENABLED;
0844:                String finderClassName = ResourceCode.class.getName();
0845:                String finderMethodName = "findAll";
0846:                String[] finderParams = new String[] { "java.lang.Integer",
0847:                        "java.lang.Integer",
0848:                        "com.liferay.portal.kernel.util.OrderByComparator" };
0849:                Object[] finderArgs = new Object[] { String.valueOf(begin),
0850:                        String.valueOf(end), String.valueOf(obc) };
0851:
0852:                Object result = null;
0853:
0854:                if (finderClassNameCacheEnabled) {
0855:                    result = FinderCache.getResult(finderClassName,
0856:                            finderMethodName, finderParams, finderArgs,
0857:                            getSessionFactory());
0858:                }
0859:
0860:                if (result == null) {
0861:                    Session session = null;
0862:
0863:                    try {
0864:                        session = openSession();
0865:
0866:                        StringMaker query = new StringMaker();
0867:
0868:                        query
0869:                                .append("FROM com.liferay.portal.model.ResourceCode ");
0870:
0871:                        if (obc != null) {
0872:                            query.append("ORDER BY ");
0873:                            query.append(obc.getOrderBy());
0874:                        }
0875:
0876:                        Query q = session.createQuery(query.toString());
0877:
0878:                        List list = QueryUtil.list(q, getDialect(), begin, end);
0879:
0880:                        if (obc == null) {
0881:                            Collections.sort(list);
0882:                        }
0883:
0884:                        FinderCache.putResult(finderClassNameCacheEnabled,
0885:                                finderClassName, finderMethodName,
0886:                                finderParams, finderArgs, list);
0887:
0888:                        return list;
0889:                    } catch (Exception e) {
0890:                        throw HibernateUtil.processException(e);
0891:                    } finally {
0892:                        closeSession(session);
0893:                    }
0894:                } else {
0895:                    return (List) result;
0896:                }
0897:            }
0898:
0899:            public void removeByCompanyId(long companyId)
0900:                    throws SystemException {
0901:                Iterator itr = findByCompanyId(companyId).iterator();
0902:
0903:                while (itr.hasNext()) {
0904:                    ResourceCode resourceCode = (ResourceCode) itr.next();
0905:
0906:                    remove(resourceCode);
0907:                }
0908:            }
0909:
0910:            public void removeByName(String name) throws SystemException {
0911:                Iterator itr = findByName(name).iterator();
0912:
0913:                while (itr.hasNext()) {
0914:                    ResourceCode resourceCode = (ResourceCode) itr.next();
0915:
0916:                    remove(resourceCode);
0917:                }
0918:            }
0919:
0920:            public void removeByC_N_S(long companyId, String name, int scope)
0921:                    throws NoSuchResourceCodeException, SystemException {
0922:                ResourceCode resourceCode = findByC_N_S(companyId, name, scope);
0923:
0924:                remove(resourceCode);
0925:            }
0926:
0927:            public void removeAll() throws SystemException {
0928:                Iterator itr = findAll().iterator();
0929:
0930:                while (itr.hasNext()) {
0931:                    remove((ResourceCode) itr.next());
0932:                }
0933:            }
0934:
0935:            public int countByCompanyId(long companyId) throws SystemException {
0936:                boolean finderClassNameCacheEnabled = ResourceCodeModelImpl.CACHE_ENABLED;
0937:                String finderClassName = ResourceCode.class.getName();
0938:                String finderMethodName = "countByCompanyId";
0939:                String[] finderParams = new String[] { Long.class.getName() };
0940:                Object[] finderArgs = new Object[] { new Long(companyId) };
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 = openSession();
0955:
0956:                        StringMaker query = new StringMaker();
0957:
0958:                        query.append("SELECT COUNT(*) ");
0959:                        query
0960:                                .append("FROM com.liferay.portal.model.ResourceCode WHERE ");
0961:
0962:                        query.append("companyId = ?");
0963:
0964:                        query.append(" ");
0965:
0966:                        Query q = session.createQuery(query.toString());
0967:
0968:                        int queryPos = 0;
0969:
0970:                        q.setLong(queryPos++, companyId);
0971:
0972:                        Long count = null;
0973:
0974:                        Iterator itr = q.list().iterator();
0975:
0976:                        if (itr.hasNext()) {
0977:                            count = (Long) itr.next();
0978:                        }
0979:
0980:                        if (count == null) {
0981:                            count = new Long(0);
0982:                        }
0983:
0984:                        FinderCache.putResult(finderClassNameCacheEnabled,
0985:                                finderClassName, finderMethodName,
0986:                                finderParams, finderArgs, count);
0987:
0988:                        return count.intValue();
0989:                    } catch (Exception e) {
0990:                        throw HibernateUtil.processException(e);
0991:                    } finally {
0992:                        closeSession(session);
0993:                    }
0994:                } else {
0995:                    return ((Long) result).intValue();
0996:                }
0997:            }
0998:
0999:            public int countByName(String name) throws SystemException {
1000:                boolean finderClassNameCacheEnabled = ResourceCodeModelImpl.CACHE_ENABLED;
1001:                String finderClassName = ResourceCode.class.getName();
1002:                String finderMethodName = "countByName";
1003:                String[] finderParams = new String[] { String.class.getName() };
1004:                Object[] finderArgs = new Object[] { name };
1005:
1006:                Object result = null;
1007:
1008:                if (finderClassNameCacheEnabled) {
1009:                    result = FinderCache.getResult(finderClassName,
1010:                            finderMethodName, finderParams, finderArgs,
1011:                            getSessionFactory());
1012:                }
1013:
1014:                if (result == null) {
1015:                    Session session = null;
1016:
1017:                    try {
1018:                        session = openSession();
1019:
1020:                        StringMaker query = new StringMaker();
1021:
1022:                        query.append("SELECT COUNT(*) ");
1023:                        query
1024:                                .append("FROM com.liferay.portal.model.ResourceCode WHERE ");
1025:
1026:                        if (name == null) {
1027:                            query.append("name IS NULL");
1028:                        } else {
1029:                            query.append("name = ?");
1030:                        }
1031:
1032:                        query.append(" ");
1033:
1034:                        Query q = session.createQuery(query.toString());
1035:
1036:                        int queryPos = 0;
1037:
1038:                        if (name != null) {
1039:                            q.setString(queryPos++, name);
1040:                        }
1041:
1042:                        Long count = null;
1043:
1044:                        Iterator itr = q.list().iterator();
1045:
1046:                        if (itr.hasNext()) {
1047:                            count = (Long) itr.next();
1048:                        }
1049:
1050:                        if (count == null) {
1051:                            count = new Long(0);
1052:                        }
1053:
1054:                        FinderCache.putResult(finderClassNameCacheEnabled,
1055:                                finderClassName, finderMethodName,
1056:                                finderParams, finderArgs, count);
1057:
1058:                        return count.intValue();
1059:                    } catch (Exception e) {
1060:                        throw HibernateUtil.processException(e);
1061:                    } finally {
1062:                        closeSession(session);
1063:                    }
1064:                } else {
1065:                    return ((Long) result).intValue();
1066:                }
1067:            }
1068:
1069:            public int countByC_N_S(long companyId, String name, int scope)
1070:                    throws SystemException {
1071:                boolean finderClassNameCacheEnabled = ResourceCodeModelImpl.CACHE_ENABLED;
1072:                String finderClassName = ResourceCode.class.getName();
1073:                String finderMethodName = "countByC_N_S";
1074:                String[] finderParams = new String[] { Long.class.getName(),
1075:                        String.class.getName(), Integer.class.getName() };
1076:                Object[] finderArgs = new Object[] { new Long(companyId),
1077:
1078:                name, new Integer(scope) };
1079:
1080:                Object result = null;
1081:
1082:                if (finderClassNameCacheEnabled) {
1083:                    result = FinderCache.getResult(finderClassName,
1084:                            finderMethodName, finderParams, finderArgs,
1085:                            getSessionFactory());
1086:                }
1087:
1088:                if (result == null) {
1089:                    Session session = null;
1090:
1091:                    try {
1092:                        session = openSession();
1093:
1094:                        StringMaker query = new StringMaker();
1095:
1096:                        query.append("SELECT COUNT(*) ");
1097:                        query
1098:                                .append("FROM com.liferay.portal.model.ResourceCode WHERE ");
1099:
1100:                        query.append("companyId = ?");
1101:
1102:                        query.append(" AND ");
1103:
1104:                        if (name == null) {
1105:                            query.append("name IS NULL");
1106:                        } else {
1107:                            query.append("name = ?");
1108:                        }
1109:
1110:                        query.append(" AND ");
1111:
1112:                        query.append("scope = ?");
1113:
1114:                        query.append(" ");
1115:
1116:                        Query q = session.createQuery(query.toString());
1117:
1118:                        int queryPos = 0;
1119:
1120:                        q.setLong(queryPos++, companyId);
1121:
1122:                        if (name != null) {
1123:                            q.setString(queryPos++, name);
1124:                        }
1125:
1126:                        q.setInteger(queryPos++, scope);
1127:
1128:                        Long count = null;
1129:
1130:                        Iterator itr = q.list().iterator();
1131:
1132:                        if (itr.hasNext()) {
1133:                            count = (Long) itr.next();
1134:                        }
1135:
1136:                        if (count == null) {
1137:                            count = new Long(0);
1138:                        }
1139:
1140:                        FinderCache.putResult(finderClassNameCacheEnabled,
1141:                                finderClassName, finderMethodName,
1142:                                finderParams, finderArgs, count);
1143:
1144:                        return count.intValue();
1145:                    } catch (Exception e) {
1146:                        throw HibernateUtil.processException(e);
1147:                    } finally {
1148:                        closeSession(session);
1149:                    }
1150:                } else {
1151:                    return ((Long) result).intValue();
1152:                }
1153:            }
1154:
1155:            public int countAll() throws SystemException {
1156:                boolean finderClassNameCacheEnabled = ResourceCodeModelImpl.CACHE_ENABLED;
1157:                String finderClassName = ResourceCode.class.getName();
1158:                String finderMethodName = "countAll";
1159:                String[] finderParams = new String[] {};
1160:                Object[] finderArgs = new Object[] {};
1161:
1162:                Object result = null;
1163:
1164:                if (finderClassNameCacheEnabled) {
1165:                    result = FinderCache.getResult(finderClassName,
1166:                            finderMethodName, finderParams, finderArgs,
1167:                            getSessionFactory());
1168:                }
1169:
1170:                if (result == null) {
1171:                    Session session = null;
1172:
1173:                    try {
1174:                        session = openSession();
1175:
1176:                        Query q = session
1177:                                .createQuery("SELECT COUNT(*) FROM com.liferay.portal.model.ResourceCode");
1178:
1179:                        Long count = null;
1180:
1181:                        Iterator itr = q.list().iterator();
1182:
1183:                        if (itr.hasNext()) {
1184:                            count = (Long) itr.next();
1185:                        }
1186:
1187:                        if (count == null) {
1188:                            count = new Long(0);
1189:                        }
1190:
1191:                        FinderCache.putResult(finderClassNameCacheEnabled,
1192:                                finderClassName, finderMethodName,
1193:                                finderParams, finderArgs, count);
1194:
1195:                        return count.intValue();
1196:                    } catch (Exception e) {
1197:                        throw HibernateUtil.processException(e);
1198:                    } finally {
1199:                        closeSession(session);
1200:                    }
1201:                } else {
1202:                    return ((Long) result).intValue();
1203:                }
1204:            }
1205:
1206:            protected void initDao() {
1207:            }
1208:
1209:            private static ModelListener _getListener() {
1210:                if (Validator.isNotNull(_LISTENER)) {
1211:                    try {
1212:                        return (ModelListener) Class.forName(_LISTENER)
1213:                                .newInstance();
1214:                    } catch (Exception e) {
1215:                        _log.error(e);
1216:                    }
1217:                }
1218:
1219:                return null;
1220:            }
1221:
1222:            private static final String _LISTENER = GetterUtil
1223:                    .getString(PropsUtil
1224:                            .get("value.object.listener.com.liferay.portal.model.ResourceCode"));
1225:            private static Log _log = LogFactory
1226:                    .getLog(ResourceCodePersistenceImpl.class);
1227:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.