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