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