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