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