Source Code Cross Referenced for PortletPersistenceImpl.java in  » Portal » liferay-portal-4.4.2 » com » liferay » portal » service » persistence » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Portal » liferay portal 4.4.2 » com.liferay.portal.service.persistence 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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