Source Code Cross Referenced for RatingsEntryPersistenceImpl.java in  » Portal » liferay-portal-4.4.2 » com » liferay » portlet » ratings » 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.ratings.service.persistence 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003:         *
004:         * Permission is hereby granted, free of charge, to any person obtaining a copy
005:         * of this software and associated documentation files (the "Software"), to deal
006:         * in the Software without restriction, including without limitation the rights
007:         * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008:         * copies of the Software, and to permit persons to whom the Software is
009:         * furnished to do so, subject to the following conditions:
010:         *
011:         * The above copyright notice and this permission notice shall be included in
012:         * all copies or substantial portions of the Software.
013:         *
014:         * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015:         * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016:         * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017:         * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018:         * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019:         * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020:         * SOFTWARE.
021:         */package com.liferay.portlet.ratings.service.persistence;
022:
023:        import com.liferay.portal.SystemException;
024:        import com.liferay.portal.kernel.dao.DynamicQuery;
025:        import com.liferay.portal.kernel.dao.DynamicQueryInitializer;
026:        import com.liferay.portal.kernel.util.GetterUtil;
027:        import com.liferay.portal.kernel.util.OrderByComparator;
028:        import com.liferay.portal.kernel.util.StringMaker;
029:        import com.liferay.portal.kernel.util.StringPool;
030:        import com.liferay.portal.kernel.util.Validator;
031:        import com.liferay.portal.model.ModelListener;
032:        import com.liferay.portal.service.persistence.BasePersistence;
033:        import com.liferay.portal.spring.hibernate.FinderCache;
034:        import com.liferay.portal.spring.hibernate.HibernateUtil;
035:        import com.liferay.portal.util.PropsUtil;
036:
037:        import com.liferay.portlet.ratings.NoSuchEntryException;
038:        import com.liferay.portlet.ratings.model.RatingsEntry;
039:        import com.liferay.portlet.ratings.model.impl.RatingsEntryImpl;
040:        import com.liferay.portlet.ratings.model.impl.RatingsEntryModelImpl;
041:
042:        import com.liferay.util.dao.hibernate.QueryUtil;
043:
044:        import org.apache.commons.logging.Log;
045:        import org.apache.commons.logging.LogFactory;
046:
047:        import org.hibernate.Query;
048:        import org.hibernate.Session;
049:
050:        import java.util.Collections;
051:        import java.util.Iterator;
052:        import java.util.List;
053:
054:        /**
055:         * <a href="RatingsEntryPersistenceImpl.java.html"><b><i>View Source</i></b></a>
056:         *
057:         * @author Brian Wing Shun Chan
058:         *
059:         */
060:        public class RatingsEntryPersistenceImpl extends BasePersistence
061:                implements  RatingsEntryPersistence {
062:            public RatingsEntry create(long entryId) {
063:                RatingsEntry ratingsEntry = new RatingsEntryImpl();
064:
065:                ratingsEntry.setNew(true);
066:                ratingsEntry.setPrimaryKey(entryId);
067:
068:                return ratingsEntry;
069:            }
070:
071:            public RatingsEntry remove(long entryId)
072:                    throws NoSuchEntryException, SystemException {
073:                Session session = null;
074:
075:                try {
076:                    session = openSession();
077:
078:                    RatingsEntry ratingsEntry = (RatingsEntry) session.get(
079:                            RatingsEntryImpl.class, new Long(entryId));
080:
081:                    if (ratingsEntry == null) {
082:                        if (_log.isWarnEnabled()) {
083:                            _log
084:                                    .warn("No RatingsEntry exists with the primary key "
085:                                            + entryId);
086:                        }
087:
088:                        throw new NoSuchEntryException(
089:                                "No RatingsEntry exists with the primary key "
090:                                        + entryId);
091:                    }
092:
093:                    return remove(ratingsEntry);
094:                } catch (NoSuchEntryException nsee) {
095:                    throw nsee;
096:                } catch (Exception e) {
097:                    throw HibernateUtil.processException(e);
098:                } finally {
099:                    closeSession(session);
100:                }
101:            }
102:
103:            public RatingsEntry remove(RatingsEntry ratingsEntry)
104:                    throws SystemException {
105:                ModelListener listener = _getListener();
106:
107:                if (listener != null) {
108:                    listener.onBeforeRemove(ratingsEntry);
109:                }
110:
111:                ratingsEntry = removeImpl(ratingsEntry);
112:
113:                if (listener != null) {
114:                    listener.onAfterRemove(ratingsEntry);
115:                }
116:
117:                return ratingsEntry;
118:            }
119:
120:            protected RatingsEntry removeImpl(RatingsEntry ratingsEntry)
121:                    throws SystemException {
122:                Session session = null;
123:
124:                try {
125:                    session = openSession();
126:
127:                    session.delete(ratingsEntry);
128:
129:                    session.flush();
130:
131:                    return ratingsEntry;
132:                } catch (Exception e) {
133:                    throw HibernateUtil.processException(e);
134:                } finally {
135:                    closeSession(session);
136:
137:                    FinderCache.clearCache(RatingsEntry.class.getName());
138:                }
139:            }
140:
141:            public RatingsEntry update(RatingsEntry ratingsEntry)
142:                    throws SystemException {
143:                return update(ratingsEntry, false);
144:            }
145:
146:            public RatingsEntry update(RatingsEntry ratingsEntry, boolean merge)
147:                    throws SystemException {
148:                ModelListener listener = _getListener();
149:
150:                boolean isNew = ratingsEntry.isNew();
151:
152:                if (listener != null) {
153:                    if (isNew) {
154:                        listener.onBeforeCreate(ratingsEntry);
155:                    } else {
156:                        listener.onBeforeUpdate(ratingsEntry);
157:                    }
158:                }
159:
160:                ratingsEntry = updateImpl(ratingsEntry, merge);
161:
162:                if (listener != null) {
163:                    if (isNew) {
164:                        listener.onAfterCreate(ratingsEntry);
165:                    } else {
166:                        listener.onAfterUpdate(ratingsEntry);
167:                    }
168:                }
169:
170:                return ratingsEntry;
171:            }
172:
173:            public RatingsEntry updateImpl(
174:                    com.liferay.portlet.ratings.model.RatingsEntry ratingsEntry,
175:                    boolean merge) throws SystemException {
176:                Session session = null;
177:
178:                try {
179:                    session = openSession();
180:
181:                    if (merge) {
182:                        session.merge(ratingsEntry);
183:                    } else {
184:                        if (ratingsEntry.isNew()) {
185:                            session.save(ratingsEntry);
186:                        }
187:                    }
188:
189:                    session.flush();
190:
191:                    ratingsEntry.setNew(false);
192:
193:                    return ratingsEntry;
194:                } catch (Exception e) {
195:                    throw HibernateUtil.processException(e);
196:                } finally {
197:                    closeSession(session);
198:
199:                    FinderCache.clearCache(RatingsEntry.class.getName());
200:                }
201:            }
202:
203:            public RatingsEntry findByPrimaryKey(long entryId)
204:                    throws NoSuchEntryException, SystemException {
205:                RatingsEntry ratingsEntry = fetchByPrimaryKey(entryId);
206:
207:                if (ratingsEntry == null) {
208:                    if (_log.isWarnEnabled()) {
209:                        _log
210:                                .warn("No RatingsEntry exists with the primary key "
211:                                        + entryId);
212:                    }
213:
214:                    throw new NoSuchEntryException(
215:                            "No RatingsEntry exists with the primary key "
216:                                    + entryId);
217:                }
218:
219:                return ratingsEntry;
220:            }
221:
222:            public RatingsEntry fetchByPrimaryKey(long entryId)
223:                    throws SystemException {
224:                Session session = null;
225:
226:                try {
227:                    session = openSession();
228:
229:                    return (RatingsEntry) session.get(RatingsEntryImpl.class,
230:                            new Long(entryId));
231:                } catch (Exception e) {
232:                    throw HibernateUtil.processException(e);
233:                } finally {
234:                    closeSession(session);
235:                }
236:            }
237:
238:            public List findByC_C(long classNameId, long classPK)
239:                    throws SystemException {
240:                boolean finderClassNameCacheEnabled = RatingsEntryModelImpl.CACHE_ENABLED;
241:                String finderClassName = RatingsEntry.class.getName();
242:                String finderMethodName = "findByC_C";
243:                String[] finderParams = new String[] { Long.class.getName(),
244:                        Long.class.getName() };
245:                Object[] finderArgs = new Object[] { new Long(classNameId),
246:                        new Long(classPK) };
247:
248:                Object result = null;
249:
250:                if (finderClassNameCacheEnabled) {
251:                    result = FinderCache.getResult(finderClassName,
252:                            finderMethodName, finderParams, finderArgs,
253:                            getSessionFactory());
254:                }
255:
256:                if (result == null) {
257:                    Session session = null;
258:
259:                    try {
260:                        session = openSession();
261:
262:                        StringMaker query = new StringMaker();
263:
264:                        query
265:                                .append("FROM com.liferay.portlet.ratings.model.RatingsEntry WHERE ");
266:
267:                        query.append("classNameId = ?");
268:
269:                        query.append(" AND ");
270:
271:                        query.append("classPK = ?");
272:
273:                        query.append(" ");
274:
275:                        Query q = session.createQuery(query.toString());
276:
277:                        int queryPos = 0;
278:
279:                        q.setLong(queryPos++, classNameId);
280:
281:                        q.setLong(queryPos++, classPK);
282:
283:                        List list = q.list();
284:
285:                        FinderCache.putResult(finderClassNameCacheEnabled,
286:                                finderClassName, finderMethodName,
287:                                finderParams, finderArgs, list);
288:
289:                        return list;
290:                    } catch (Exception e) {
291:                        throw HibernateUtil.processException(e);
292:                    } finally {
293:                        closeSession(session);
294:                    }
295:                } else {
296:                    return (List) result;
297:                }
298:            }
299:
300:            public List findByC_C(long classNameId, long classPK, int begin,
301:                    int end) throws SystemException {
302:                return findByC_C(classNameId, classPK, begin, end, null);
303:            }
304:
305:            public List findByC_C(long classNameId, long classPK, int begin,
306:                    int end, OrderByComparator obc) throws SystemException {
307:                boolean finderClassNameCacheEnabled = RatingsEntryModelImpl.CACHE_ENABLED;
308:                String finderClassName = RatingsEntry.class.getName();
309:                String finderMethodName = "findByC_C";
310:                String[] finderParams = new String[] { Long.class.getName(),
311:                        Long.class.getName(),
312:
313:                        "java.lang.Integer", "java.lang.Integer",
314:                        "com.liferay.portal.kernel.util.OrderByComparator" };
315:                Object[] finderArgs = new Object[] { new Long(classNameId),
316:                        new Long(classPK),
317:
318:                        String.valueOf(begin), String.valueOf(end),
319:                        String.valueOf(obc) };
320:
321:                Object result = null;
322:
323:                if (finderClassNameCacheEnabled) {
324:                    result = FinderCache.getResult(finderClassName,
325:                            finderMethodName, finderParams, finderArgs,
326:                            getSessionFactory());
327:                }
328:
329:                if (result == null) {
330:                    Session session = null;
331:
332:                    try {
333:                        session = openSession();
334:
335:                        StringMaker query = new StringMaker();
336:
337:                        query
338:                                .append("FROM com.liferay.portlet.ratings.model.RatingsEntry WHERE ");
339:
340:                        query.append("classNameId = ?");
341:
342:                        query.append(" AND ");
343:
344:                        query.append("classPK = ?");
345:
346:                        query.append(" ");
347:
348:                        if (obc != null) {
349:                            query.append("ORDER BY ");
350:                            query.append(obc.getOrderBy());
351:                        }
352:
353:                        Query q = session.createQuery(query.toString());
354:
355:                        int queryPos = 0;
356:
357:                        q.setLong(queryPos++, classNameId);
358:
359:                        q.setLong(queryPos++, classPK);
360:
361:                        List list = QueryUtil.list(q, getDialect(), begin, end);
362:
363:                        FinderCache.putResult(finderClassNameCacheEnabled,
364:                                finderClassName, finderMethodName,
365:                                finderParams, finderArgs, list);
366:
367:                        return list;
368:                    } catch (Exception e) {
369:                        throw HibernateUtil.processException(e);
370:                    } finally {
371:                        closeSession(session);
372:                    }
373:                } else {
374:                    return (List) result;
375:                }
376:            }
377:
378:            public RatingsEntry findByC_C_First(long classNameId, long classPK,
379:                    OrderByComparator obc) throws NoSuchEntryException,
380:                    SystemException {
381:                List list = findByC_C(classNameId, classPK, 0, 1, obc);
382:
383:                if (list.size() == 0) {
384:                    StringMaker msg = new StringMaker();
385:
386:                    msg.append("No RatingsEntry exists with the key {");
387:
388:                    msg.append("classNameId=" + classNameId);
389:
390:                    msg.append(", ");
391:                    msg.append("classPK=" + classPK);
392:
393:                    msg.append(StringPool.CLOSE_CURLY_BRACE);
394:
395:                    throw new NoSuchEntryException(msg.toString());
396:                } else {
397:                    return (RatingsEntry) list.get(0);
398:                }
399:            }
400:
401:            public RatingsEntry findByC_C_Last(long classNameId, long classPK,
402:                    OrderByComparator obc) throws NoSuchEntryException,
403:                    SystemException {
404:                int count = countByC_C(classNameId, classPK);
405:
406:                List list = findByC_C(classNameId, classPK, count - 1, count,
407:                        obc);
408:
409:                if (list.size() == 0) {
410:                    StringMaker msg = new StringMaker();
411:
412:                    msg.append("No RatingsEntry exists with the key {");
413:
414:                    msg.append("classNameId=" + classNameId);
415:
416:                    msg.append(", ");
417:                    msg.append("classPK=" + classPK);
418:
419:                    msg.append(StringPool.CLOSE_CURLY_BRACE);
420:
421:                    throw new NoSuchEntryException(msg.toString());
422:                } else {
423:                    return (RatingsEntry) list.get(0);
424:                }
425:            }
426:
427:            public RatingsEntry[] findByC_C_PrevAndNext(long entryId,
428:                    long classNameId, long classPK, OrderByComparator obc)
429:                    throws NoSuchEntryException, SystemException {
430:                RatingsEntry ratingsEntry = findByPrimaryKey(entryId);
431:
432:                int count = countByC_C(classNameId, classPK);
433:
434:                Session session = null;
435:
436:                try {
437:                    session = openSession();
438:
439:                    StringMaker query = new StringMaker();
440:
441:                    query
442:                            .append("FROM com.liferay.portlet.ratings.model.RatingsEntry WHERE ");
443:
444:                    query.append("classNameId = ?");
445:
446:                    query.append(" AND ");
447:
448:                    query.append("classPK = ?");
449:
450:                    query.append(" ");
451:
452:                    if (obc != null) {
453:                        query.append("ORDER BY ");
454:                        query.append(obc.getOrderBy());
455:                    }
456:
457:                    Query q = session.createQuery(query.toString());
458:
459:                    int queryPos = 0;
460:
461:                    q.setLong(queryPos++, classNameId);
462:
463:                    q.setLong(queryPos++, classPK);
464:
465:                    Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
466:                            ratingsEntry);
467:
468:                    RatingsEntry[] array = new RatingsEntryImpl[3];
469:
470:                    array[0] = (RatingsEntry) objArray[0];
471:                    array[1] = (RatingsEntry) objArray[1];
472:                    array[2] = (RatingsEntry) objArray[2];
473:
474:                    return array;
475:                } catch (Exception e) {
476:                    throw HibernateUtil.processException(e);
477:                } finally {
478:                    closeSession(session);
479:                }
480:            }
481:
482:            public RatingsEntry findByU_C_C(long userId, long classNameId,
483:                    long classPK) throws NoSuchEntryException, SystemException {
484:                RatingsEntry ratingsEntry = fetchByU_C_C(userId, classNameId,
485:                        classPK);
486:
487:                if (ratingsEntry == null) {
488:                    StringMaker msg = new StringMaker();
489:
490:                    msg.append("No RatingsEntry exists with the key {");
491:
492:                    msg.append("userId=" + userId);
493:
494:                    msg.append(", ");
495:                    msg.append("classNameId=" + classNameId);
496:
497:                    msg.append(", ");
498:                    msg.append("classPK=" + classPK);
499:
500:                    msg.append(StringPool.CLOSE_CURLY_BRACE);
501:
502:                    if (_log.isWarnEnabled()) {
503:                        _log.warn(msg.toString());
504:                    }
505:
506:                    throw new NoSuchEntryException(msg.toString());
507:                }
508:
509:                return ratingsEntry;
510:            }
511:
512:            public RatingsEntry fetchByU_C_C(long userId, long classNameId,
513:                    long classPK) throws SystemException {
514:                boolean finderClassNameCacheEnabled = RatingsEntryModelImpl.CACHE_ENABLED;
515:                String finderClassName = RatingsEntry.class.getName();
516:                String finderMethodName = "fetchByU_C_C";
517:                String[] finderParams = new String[] { Long.class.getName(),
518:                        Long.class.getName(), Long.class.getName() };
519:                Object[] finderArgs = new Object[] { new Long(userId),
520:                        new Long(classNameId), new Long(classPK) };
521:
522:                Object result = null;
523:
524:                if (finderClassNameCacheEnabled) {
525:                    result = FinderCache.getResult(finderClassName,
526:                            finderMethodName, finderParams, finderArgs,
527:                            getSessionFactory());
528:                }
529:
530:                if (result == null) {
531:                    Session session = null;
532:
533:                    try {
534:                        session = openSession();
535:
536:                        StringMaker query = new StringMaker();
537:
538:                        query
539:                                .append("FROM com.liferay.portlet.ratings.model.RatingsEntry WHERE ");
540:
541:                        query.append("userId = ?");
542:
543:                        query.append(" AND ");
544:
545:                        query.append("classNameId = ?");
546:
547:                        query.append(" AND ");
548:
549:                        query.append("classPK = ?");
550:
551:                        query.append(" ");
552:
553:                        Query q = session.createQuery(query.toString());
554:
555:                        int queryPos = 0;
556:
557:                        q.setLong(queryPos++, userId);
558:
559:                        q.setLong(queryPos++, classNameId);
560:
561:                        q.setLong(queryPos++, classPK);
562:
563:                        List list = q.list();
564:
565:                        FinderCache.putResult(finderClassNameCacheEnabled,
566:                                finderClassName, finderMethodName,
567:                                finderParams, finderArgs, list);
568:
569:                        if (list.size() == 0) {
570:                            return null;
571:                        } else {
572:                            return (RatingsEntry) list.get(0);
573:                        }
574:                    } catch (Exception e) {
575:                        throw HibernateUtil.processException(e);
576:                    } finally {
577:                        closeSession(session);
578:                    }
579:                } else {
580:                    List list = (List) result;
581:
582:                    if (list.size() == 0) {
583:                        return null;
584:                    } else {
585:                        return (RatingsEntry) list.get(0);
586:                    }
587:                }
588:            }
589:
590:            public List findWithDynamicQuery(
591:                    DynamicQueryInitializer queryInitializer)
592:                    throws SystemException {
593:                Session session = null;
594:
595:                try {
596:                    session = openSession();
597:
598:                    DynamicQuery query = queryInitializer.initialize(session);
599:
600:                    return query.list();
601:                } catch (Exception e) {
602:                    throw HibernateUtil.processException(e);
603:                } finally {
604:                    closeSession(session);
605:                }
606:            }
607:
608:            public List findWithDynamicQuery(
609:                    DynamicQueryInitializer queryInitializer, int begin, int end)
610:                    throws SystemException {
611:                Session session = null;
612:
613:                try {
614:                    session = openSession();
615:
616:                    DynamicQuery query = queryInitializer.initialize(session);
617:
618:                    query.setLimit(begin, end);
619:
620:                    return query.list();
621:                } catch (Exception e) {
622:                    throw HibernateUtil.processException(e);
623:                } finally {
624:                    closeSession(session);
625:                }
626:            }
627:
628:            public List findAll() throws SystemException {
629:                return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
630:            }
631:
632:            public List findAll(int begin, int end) throws SystemException {
633:                return findAll(begin, end, null);
634:            }
635:
636:            public List findAll(int begin, int end, OrderByComparator obc)
637:                    throws SystemException {
638:                boolean finderClassNameCacheEnabled = RatingsEntryModelImpl.CACHE_ENABLED;
639:                String finderClassName = RatingsEntry.class.getName();
640:                String finderMethodName = "findAll";
641:                String[] finderParams = new String[] { "java.lang.Integer",
642:                        "java.lang.Integer",
643:                        "com.liferay.portal.kernel.util.OrderByComparator" };
644:                Object[] finderArgs = new Object[] { String.valueOf(begin),
645:                        String.valueOf(end), String.valueOf(obc) };
646:
647:                Object result = null;
648:
649:                if (finderClassNameCacheEnabled) {
650:                    result = FinderCache.getResult(finderClassName,
651:                            finderMethodName, finderParams, finderArgs,
652:                            getSessionFactory());
653:                }
654:
655:                if (result == null) {
656:                    Session session = null;
657:
658:                    try {
659:                        session = openSession();
660:
661:                        StringMaker query = new StringMaker();
662:
663:                        query
664:                                .append("FROM com.liferay.portlet.ratings.model.RatingsEntry ");
665:
666:                        if (obc != null) {
667:                            query.append("ORDER BY ");
668:                            query.append(obc.getOrderBy());
669:                        }
670:
671:                        Query q = session.createQuery(query.toString());
672:
673:                        List list = QueryUtil.list(q, getDialect(), begin, end);
674:
675:                        if (obc == null) {
676:                            Collections.sort(list);
677:                        }
678:
679:                        FinderCache.putResult(finderClassNameCacheEnabled,
680:                                finderClassName, finderMethodName,
681:                                finderParams, finderArgs, list);
682:
683:                        return list;
684:                    } catch (Exception e) {
685:                        throw HibernateUtil.processException(e);
686:                    } finally {
687:                        closeSession(session);
688:                    }
689:                } else {
690:                    return (List) result;
691:                }
692:            }
693:
694:            public void removeByC_C(long classNameId, long classPK)
695:                    throws SystemException {
696:                Iterator itr = findByC_C(classNameId, classPK).iterator();
697:
698:                while (itr.hasNext()) {
699:                    RatingsEntry ratingsEntry = (RatingsEntry) itr.next();
700:
701:                    remove(ratingsEntry);
702:                }
703:            }
704:
705:            public void removeByU_C_C(long userId, long classNameId,
706:                    long classPK) throws NoSuchEntryException, SystemException {
707:                RatingsEntry ratingsEntry = findByU_C_C(userId, classNameId,
708:                        classPK);
709:
710:                remove(ratingsEntry);
711:            }
712:
713:            public void removeAll() throws SystemException {
714:                Iterator itr = findAll().iterator();
715:
716:                while (itr.hasNext()) {
717:                    remove((RatingsEntry) itr.next());
718:                }
719:            }
720:
721:            public int countByC_C(long classNameId, long classPK)
722:                    throws SystemException {
723:                boolean finderClassNameCacheEnabled = RatingsEntryModelImpl.CACHE_ENABLED;
724:                String finderClassName = RatingsEntry.class.getName();
725:                String finderMethodName = "countByC_C";
726:                String[] finderParams = new String[] { Long.class.getName(),
727:                        Long.class.getName() };
728:                Object[] finderArgs = new Object[] { new Long(classNameId),
729:                        new Long(classPK) };
730:
731:                Object result = null;
732:
733:                if (finderClassNameCacheEnabled) {
734:                    result = FinderCache.getResult(finderClassName,
735:                            finderMethodName, finderParams, finderArgs,
736:                            getSessionFactory());
737:                }
738:
739:                if (result == null) {
740:                    Session session = null;
741:
742:                    try {
743:                        session = openSession();
744:
745:                        StringMaker query = new StringMaker();
746:
747:                        query.append("SELECT COUNT(*) ");
748:                        query
749:                                .append("FROM com.liferay.portlet.ratings.model.RatingsEntry WHERE ");
750:
751:                        query.append("classNameId = ?");
752:
753:                        query.append(" AND ");
754:
755:                        query.append("classPK = ?");
756:
757:                        query.append(" ");
758:
759:                        Query q = session.createQuery(query.toString());
760:
761:                        int queryPos = 0;
762:
763:                        q.setLong(queryPos++, classNameId);
764:
765:                        q.setLong(queryPos++, classPK);
766:
767:                        Long count = null;
768:
769:                        Iterator itr = q.list().iterator();
770:
771:                        if (itr.hasNext()) {
772:                            count = (Long) itr.next();
773:                        }
774:
775:                        if (count == null) {
776:                            count = new Long(0);
777:                        }
778:
779:                        FinderCache.putResult(finderClassNameCacheEnabled,
780:                                finderClassName, finderMethodName,
781:                                finderParams, finderArgs, count);
782:
783:                        return count.intValue();
784:                    } catch (Exception e) {
785:                        throw HibernateUtil.processException(e);
786:                    } finally {
787:                        closeSession(session);
788:                    }
789:                } else {
790:                    return ((Long) result).intValue();
791:                }
792:            }
793:
794:            public int countByU_C_C(long userId, long classNameId, long classPK)
795:                    throws SystemException {
796:                boolean finderClassNameCacheEnabled = RatingsEntryModelImpl.CACHE_ENABLED;
797:                String finderClassName = RatingsEntry.class.getName();
798:                String finderMethodName = "countByU_C_C";
799:                String[] finderParams = new String[] { Long.class.getName(),
800:                        Long.class.getName(), Long.class.getName() };
801:                Object[] finderArgs = new Object[] { new Long(userId),
802:                        new Long(classNameId), new Long(classPK) };
803:
804:                Object result = null;
805:
806:                if (finderClassNameCacheEnabled) {
807:                    result = FinderCache.getResult(finderClassName,
808:                            finderMethodName, finderParams, finderArgs,
809:                            getSessionFactory());
810:                }
811:
812:                if (result == null) {
813:                    Session session = null;
814:
815:                    try {
816:                        session = openSession();
817:
818:                        StringMaker query = new StringMaker();
819:
820:                        query.append("SELECT COUNT(*) ");
821:                        query
822:                                .append("FROM com.liferay.portlet.ratings.model.RatingsEntry WHERE ");
823:
824:                        query.append("userId = ?");
825:
826:                        query.append(" AND ");
827:
828:                        query.append("classNameId = ?");
829:
830:                        query.append(" AND ");
831:
832:                        query.append("classPK = ?");
833:
834:                        query.append(" ");
835:
836:                        Query q = session.createQuery(query.toString());
837:
838:                        int queryPos = 0;
839:
840:                        q.setLong(queryPos++, userId);
841:
842:                        q.setLong(queryPos++, classNameId);
843:
844:                        q.setLong(queryPos++, classPK);
845:
846:                        Long count = null;
847:
848:                        Iterator itr = q.list().iterator();
849:
850:                        if (itr.hasNext()) {
851:                            count = (Long) itr.next();
852:                        }
853:
854:                        if (count == null) {
855:                            count = new Long(0);
856:                        }
857:
858:                        FinderCache.putResult(finderClassNameCacheEnabled,
859:                                finderClassName, finderMethodName,
860:                                finderParams, finderArgs, count);
861:
862:                        return count.intValue();
863:                    } catch (Exception e) {
864:                        throw HibernateUtil.processException(e);
865:                    } finally {
866:                        closeSession(session);
867:                    }
868:                } else {
869:                    return ((Long) result).intValue();
870:                }
871:            }
872:
873:            public int countAll() throws SystemException {
874:                boolean finderClassNameCacheEnabled = RatingsEntryModelImpl.CACHE_ENABLED;
875:                String finderClassName = RatingsEntry.class.getName();
876:                String finderMethodName = "countAll";
877:                String[] finderParams = new String[] {};
878:                Object[] finderArgs = new Object[] {};
879:
880:                Object result = null;
881:
882:                if (finderClassNameCacheEnabled) {
883:                    result = FinderCache.getResult(finderClassName,
884:                            finderMethodName, finderParams, finderArgs,
885:                            getSessionFactory());
886:                }
887:
888:                if (result == null) {
889:                    Session session = null;
890:
891:                    try {
892:                        session = openSession();
893:
894:                        Query q = session
895:                                .createQuery("SELECT COUNT(*) FROM com.liferay.portlet.ratings.model.RatingsEntry");
896:
897:                        Long count = null;
898:
899:                        Iterator itr = q.list().iterator();
900:
901:                        if (itr.hasNext()) {
902:                            count = (Long) itr.next();
903:                        }
904:
905:                        if (count == null) {
906:                            count = new Long(0);
907:                        }
908:
909:                        FinderCache.putResult(finderClassNameCacheEnabled,
910:                                finderClassName, finderMethodName,
911:                                finderParams, finderArgs, count);
912:
913:                        return count.intValue();
914:                    } catch (Exception e) {
915:                        throw HibernateUtil.processException(e);
916:                    } finally {
917:                        closeSession(session);
918:                    }
919:                } else {
920:                    return ((Long) result).intValue();
921:                }
922:            }
923:
924:            protected void initDao() {
925:            }
926:
927:            private static ModelListener _getListener() {
928:                if (Validator.isNotNull(_LISTENER)) {
929:                    try {
930:                        return (ModelListener) Class.forName(_LISTENER)
931:                                .newInstance();
932:                    } catch (Exception e) {
933:                        _log.error(e);
934:                    }
935:                }
936:
937:                return null;
938:            }
939:
940:            private static final String _LISTENER = GetterUtil
941:                    .getString(PropsUtil
942:                            .get("value.object.listener.com.liferay.portlet.ratings.model.RatingsEntry"));
943:            private static Log _log = LogFactory
944:                    .getLog(RatingsEntryPersistenceImpl.class);
945:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.