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