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.GetterUtil;
29 import com.liferay.portal.kernel.util.OrderByComparator;
30 import com.liferay.portal.kernel.util.StringMaker;
31 import com.liferay.portal.kernel.util.StringPool;
32 import com.liferay.portal.kernel.util.StringUtil;
33 import com.liferay.portal.model.ModelListener;
34 import com.liferay.portal.service.persistence.BasePersistence;
35 import com.liferay.portal.spring.hibernate.FinderCache;
36 import com.liferay.portal.spring.hibernate.HibernateUtil;
37 import com.liferay.portal.util.PropsUtil;
38
39 import com.liferay.portlet.shopping.NoSuchCategoryException;
40 import com.liferay.portlet.shopping.model.ShoppingCategory;
41 import com.liferay.portlet.shopping.model.impl.ShoppingCategoryImpl;
42 import com.liferay.portlet.shopping.model.impl.ShoppingCategoryModelImpl;
43
44 import com.liferay.util.dao.hibernate.QueryUtil;
45
46 import org.apache.commons.logging.Log;
47 import org.apache.commons.logging.LogFactory;
48
49 import org.hibernate.Query;
50 import org.hibernate.Session;
51
52 import java.util.ArrayList;
53 import java.util.Collections;
54 import java.util.Iterator;
55 import java.util.List;
56
57
63 public class ShoppingCategoryPersistenceImpl extends BasePersistence
64 implements ShoppingCategoryPersistence {
65 public ShoppingCategory create(long categoryId) {
66 ShoppingCategory shoppingCategory = new ShoppingCategoryImpl();
67
68 shoppingCategory.setNew(true);
69 shoppingCategory.setPrimaryKey(categoryId);
70
71 return shoppingCategory;
72 }
73
74 public ShoppingCategory remove(long categoryId)
75 throws NoSuchCategoryException, SystemException {
76 Session session = null;
77
78 try {
79 session = openSession();
80
81 ShoppingCategory shoppingCategory = (ShoppingCategory)session.get(ShoppingCategoryImpl.class,
82 new Long(categoryId));
83
84 if (shoppingCategory == null) {
85 if (_log.isWarnEnabled()) {
86 _log.warn(
87 "No ShoppingCategory exists with the primary key " +
88 categoryId);
89 }
90
91 throw new NoSuchCategoryException(
92 "No ShoppingCategory exists with the primary key " +
93 categoryId);
94 }
95
96 return remove(shoppingCategory);
97 }
98 catch (NoSuchCategoryException nsee) {
99 throw nsee;
100 }
101 catch (Exception e) {
102 throw HibernateUtil.processException(e);
103 }
104 finally {
105 closeSession(session);
106 }
107 }
108
109 public ShoppingCategory remove(ShoppingCategory shoppingCategory)
110 throws SystemException {
111 if (_listeners != null) {
112 for (ModelListener listener : _listeners) {
113 listener.onBeforeRemove(shoppingCategory);
114 }
115 }
116
117 shoppingCategory = removeImpl(shoppingCategory);
118
119 if (_listeners != null) {
120 for (ModelListener listener : _listeners) {
121 listener.onAfterRemove(shoppingCategory);
122 }
123 }
124
125 return shoppingCategory;
126 }
127
128 protected ShoppingCategory removeImpl(ShoppingCategory shoppingCategory)
129 throws SystemException {
130 Session session = null;
131
132 try {
133 session = openSession();
134
135 session.delete(shoppingCategory);
136
137 session.flush();
138
139 return shoppingCategory;
140 }
141 catch (Exception e) {
142 throw HibernateUtil.processException(e);
143 }
144 finally {
145 closeSession(session);
146
147 FinderCache.clearCache(ShoppingCategory.class.getName());
148 }
149 }
150
151
154 public ShoppingCategory update(ShoppingCategory shoppingCategory)
155 throws SystemException {
156 if (_log.isWarnEnabled()) {
157 _log.warn(
158 "Using the deprecated update(ShoppingCategory shoppingCategory) method. Use update(ShoppingCategory shoppingCategory, boolean merge) instead.");
159 }
160
161 return update(shoppingCategory, false);
162 }
163
164
177 public ShoppingCategory update(ShoppingCategory shoppingCategory,
178 boolean merge) throws SystemException {
179 boolean isNew = shoppingCategory.isNew();
180
181 if (_listeners != null) {
182 for (ModelListener listener : _listeners) {
183 if (isNew) {
184 listener.onBeforeCreate(shoppingCategory);
185 }
186 else {
187 listener.onBeforeUpdate(shoppingCategory);
188 }
189 }
190 }
191
192 shoppingCategory = updateImpl(shoppingCategory, merge);
193
194 if (_listeners != null) {
195 for (ModelListener listener : _listeners) {
196 if (isNew) {
197 listener.onAfterCreate(shoppingCategory);
198 }
199 else {
200 listener.onAfterUpdate(shoppingCategory);
201 }
202 }
203 }
204
205 return shoppingCategory;
206 }
207
208 public ShoppingCategory updateImpl(
209 com.liferay.portlet.shopping.model.ShoppingCategory shoppingCategory,
210 boolean merge) throws SystemException {
211 Session session = null;
212
213 try {
214 session = openSession();
215
216 if (merge) {
217 session.merge(shoppingCategory);
218 }
219 else {
220 if (shoppingCategory.isNew()) {
221 session.save(shoppingCategory);
222 }
223 }
224
225 session.flush();
226
227 shoppingCategory.setNew(false);
228
229 return shoppingCategory;
230 }
231 catch (Exception e) {
232 throw HibernateUtil.processException(e);
233 }
234 finally {
235 closeSession(session);
236
237 FinderCache.clearCache(ShoppingCategory.class.getName());
238 }
239 }
240
241 public ShoppingCategory findByPrimaryKey(long categoryId)
242 throws NoSuchCategoryException, SystemException {
243 ShoppingCategory shoppingCategory = fetchByPrimaryKey(categoryId);
244
245 if (shoppingCategory == null) {
246 if (_log.isWarnEnabled()) {
247 _log.warn("No ShoppingCategory exists with the primary key " +
248 categoryId);
249 }
250
251 throw new NoSuchCategoryException(
252 "No ShoppingCategory exists with the primary key " +
253 categoryId);
254 }
255
256 return shoppingCategory;
257 }
258
259 public ShoppingCategory fetchByPrimaryKey(long categoryId)
260 throws SystemException {
261 Session session = null;
262
263 try {
264 session = openSession();
265
266 return (ShoppingCategory)session.get(ShoppingCategoryImpl.class,
267 new Long(categoryId));
268 }
269 catch (Exception e) {
270 throw HibernateUtil.processException(e);
271 }
272 finally {
273 closeSession(session);
274 }
275 }
276
277 public List<ShoppingCategory> findByGroupId(long groupId)
278 throws SystemException {
279 boolean finderClassNameCacheEnabled = ShoppingCategoryModelImpl.CACHE_ENABLED;
280 String finderClassName = ShoppingCategory.class.getName();
281 String finderMethodName = "findByGroupId";
282 String[] finderParams = new String[] { Long.class.getName() };
283 Object[] finderArgs = new Object[] { new Long(groupId) };
284
285 Object result = null;
286
287 if (finderClassNameCacheEnabled) {
288 result = FinderCache.getResult(finderClassName, finderMethodName,
289 finderParams, finderArgs, getSessionFactory());
290 }
291
292 if (result == null) {
293 Session session = null;
294
295 try {
296 session = openSession();
297
298 StringMaker query = new StringMaker();
299
300 query.append(
301 "FROM com.liferay.portlet.shopping.model.ShoppingCategory WHERE ");
302
303 query.append("groupId = ?");
304
305 query.append(" ");
306
307 query.append("ORDER BY ");
308
309 query.append("parentCategoryId ASC, ");
310 query.append("name ASC");
311
312 Query q = session.createQuery(query.toString());
313
314 int queryPos = 0;
315
316 q.setLong(queryPos++, groupId);
317
318 List<ShoppingCategory> list = q.list();
319
320 FinderCache.putResult(finderClassNameCacheEnabled,
321 finderClassName, finderMethodName, finderParams,
322 finderArgs, list);
323
324 return list;
325 }
326 catch (Exception e) {
327 throw HibernateUtil.processException(e);
328 }
329 finally {
330 closeSession(session);
331 }
332 }
333 else {
334 return (List<ShoppingCategory>)result;
335 }
336 }
337
338 public List<ShoppingCategory> findByGroupId(long groupId, int begin, int end)
339 throws SystemException {
340 return findByGroupId(groupId, begin, end, null);
341 }
342
343 public List<ShoppingCategory> findByGroupId(long groupId, int begin,
344 int end, OrderByComparator obc) throws SystemException {
345 boolean finderClassNameCacheEnabled = ShoppingCategoryModelImpl.CACHE_ENABLED;
346 String finderClassName = ShoppingCategory.class.getName();
347 String finderMethodName = "findByGroupId";
348 String[] finderParams = new String[] {
349 Long.class.getName(),
350
351 "java.lang.Integer", "java.lang.Integer",
352 "com.liferay.portal.kernel.util.OrderByComparator"
353 };
354 Object[] finderArgs = new Object[] {
355 new Long(groupId),
356
357 String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
358 };
359
360 Object result = null;
361
362 if (finderClassNameCacheEnabled) {
363 result = FinderCache.getResult(finderClassName, finderMethodName,
364 finderParams, finderArgs, getSessionFactory());
365 }
366
367 if (result == null) {
368 Session session = null;
369
370 try {
371 session = openSession();
372
373 StringMaker query = new StringMaker();
374
375 query.append(
376 "FROM com.liferay.portlet.shopping.model.ShoppingCategory WHERE ");
377
378 query.append("groupId = ?");
379
380 query.append(" ");
381
382 if (obc != null) {
383 query.append("ORDER BY ");
384 query.append(obc.getOrderBy());
385 }
386
387 else {
388 query.append("ORDER BY ");
389
390 query.append("parentCategoryId ASC, ");
391 query.append("name ASC");
392 }
393
394 Query q = session.createQuery(query.toString());
395
396 int queryPos = 0;
397
398 q.setLong(queryPos++, groupId);
399
400 List<ShoppingCategory> list = (List<ShoppingCategory>)QueryUtil.list(q,
401 getDialect(), begin, end);
402
403 FinderCache.putResult(finderClassNameCacheEnabled,
404 finderClassName, finderMethodName, finderParams,
405 finderArgs, list);
406
407 return list;
408 }
409 catch (Exception e) {
410 throw HibernateUtil.processException(e);
411 }
412 finally {
413 closeSession(session);
414 }
415 }
416 else {
417 return (List<ShoppingCategory>)result;
418 }
419 }
420
421 public ShoppingCategory findByGroupId_First(long groupId,
422 OrderByComparator obc) throws NoSuchCategoryException, SystemException {
423 List<ShoppingCategory> list = findByGroupId(groupId, 0, 1, obc);
424
425 if (list.size() == 0) {
426 StringMaker msg = new StringMaker();
427
428 msg.append("No ShoppingCategory exists with the key {");
429
430 msg.append("groupId=" + groupId);
431
432 msg.append(StringPool.CLOSE_CURLY_BRACE);
433
434 throw new NoSuchCategoryException(msg.toString());
435 }
436 else {
437 return list.get(0);
438 }
439 }
440
441 public ShoppingCategory findByGroupId_Last(long groupId,
442 OrderByComparator obc) throws NoSuchCategoryException, SystemException {
443 int count = countByGroupId(groupId);
444
445 List<ShoppingCategory> list = findByGroupId(groupId, count - 1, count,
446 obc);
447
448 if (list.size() == 0) {
449 StringMaker msg = new StringMaker();
450
451 msg.append("No ShoppingCategory exists with the key {");
452
453 msg.append("groupId=" + groupId);
454
455 msg.append(StringPool.CLOSE_CURLY_BRACE);
456
457 throw new NoSuchCategoryException(msg.toString());
458 }
459 else {
460 return list.get(0);
461 }
462 }
463
464 public ShoppingCategory[] findByGroupId_PrevAndNext(long categoryId,
465 long groupId, OrderByComparator obc)
466 throws NoSuchCategoryException, SystemException {
467 ShoppingCategory shoppingCategory = findByPrimaryKey(categoryId);
468
469 int count = countByGroupId(groupId);
470
471 Session session = null;
472
473 try {
474 session = openSession();
475
476 StringMaker query = new StringMaker();
477
478 query.append(
479 "FROM com.liferay.portlet.shopping.model.ShoppingCategory WHERE ");
480
481 query.append("groupId = ?");
482
483 query.append(" ");
484
485 if (obc != null) {
486 query.append("ORDER BY ");
487 query.append(obc.getOrderBy());
488 }
489
490 else {
491 query.append("ORDER BY ");
492
493 query.append("parentCategoryId ASC, ");
494 query.append("name ASC");
495 }
496
497 Query q = session.createQuery(query.toString());
498
499 int queryPos = 0;
500
501 q.setLong(queryPos++, groupId);
502
503 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
504 shoppingCategory);
505
506 ShoppingCategory[] array = new ShoppingCategoryImpl[3];
507
508 array[0] = (ShoppingCategory)objArray[0];
509 array[1] = (ShoppingCategory)objArray[1];
510 array[2] = (ShoppingCategory)objArray[2];
511
512 return array;
513 }
514 catch (Exception e) {
515 throw HibernateUtil.processException(e);
516 }
517 finally {
518 closeSession(session);
519 }
520 }
521
522 public List<ShoppingCategory> findByG_P(long groupId, long parentCategoryId)
523 throws SystemException {
524 boolean finderClassNameCacheEnabled = ShoppingCategoryModelImpl.CACHE_ENABLED;
525 String finderClassName = ShoppingCategory.class.getName();
526 String finderMethodName = "findByG_P";
527 String[] finderParams = new String[] {
528 Long.class.getName(), Long.class.getName()
529 };
530 Object[] finderArgs = new Object[] {
531 new Long(groupId), new Long(parentCategoryId)
532 };
533
534 Object result = null;
535
536 if (finderClassNameCacheEnabled) {
537 result = FinderCache.getResult(finderClassName, finderMethodName,
538 finderParams, finderArgs, getSessionFactory());
539 }
540
541 if (result == null) {
542 Session session = null;
543
544 try {
545 session = openSession();
546
547 StringMaker query = new StringMaker();
548
549 query.append(
550 "FROM com.liferay.portlet.shopping.model.ShoppingCategory WHERE ");
551
552 query.append("groupId = ?");
553
554 query.append(" AND ");
555
556 query.append("parentCategoryId = ?");
557
558 query.append(" ");
559
560 query.append("ORDER BY ");
561
562 query.append("parentCategoryId ASC, ");
563 query.append("name ASC");
564
565 Query q = session.createQuery(query.toString());
566
567 int queryPos = 0;
568
569 q.setLong(queryPos++, groupId);
570
571 q.setLong(queryPos++, parentCategoryId);
572
573 List<ShoppingCategory> list = q.list();
574
575 FinderCache.putResult(finderClassNameCacheEnabled,
576 finderClassName, finderMethodName, finderParams,
577 finderArgs, list);
578
579 return list;
580 }
581 catch (Exception e) {
582 throw HibernateUtil.processException(e);
583 }
584 finally {
585 closeSession(session);
586 }
587 }
588 else {
589 return (List<ShoppingCategory>)result;
590 }
591 }
592
593 public List<ShoppingCategory> findByG_P(long groupId,
594 long parentCategoryId, int begin, int end) throws SystemException {
595 return findByG_P(groupId, parentCategoryId, begin, end, null);
596 }
597
598 public List<ShoppingCategory> findByG_P(long groupId,
599 long parentCategoryId, int begin, int end, OrderByComparator obc)
600 throws SystemException {
601 boolean finderClassNameCacheEnabled = ShoppingCategoryModelImpl.CACHE_ENABLED;
602 String finderClassName = ShoppingCategory.class.getName();
603 String finderMethodName = "findByG_P";
604 String[] finderParams = new String[] {
605 Long.class.getName(), Long.class.getName(),
606
607 "java.lang.Integer", "java.lang.Integer",
608 "com.liferay.portal.kernel.util.OrderByComparator"
609 };
610 Object[] finderArgs = new Object[] {
611 new Long(groupId), new Long(parentCategoryId),
612
613 String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
614 };
615
616 Object result = null;
617
618 if (finderClassNameCacheEnabled) {
619 result = FinderCache.getResult(finderClassName, finderMethodName,
620 finderParams, finderArgs, getSessionFactory());
621 }
622
623 if (result == null) {
624 Session session = null;
625
626 try {
627 session = openSession();
628
629 StringMaker query = new StringMaker();
630
631 query.append(
632 "FROM com.liferay.portlet.shopping.model.ShoppingCategory WHERE ");
633
634 query.append("groupId = ?");
635
636 query.append(" AND ");
637
638 query.append("parentCategoryId = ?");
639
640 query.append(" ");
641
642 if (obc != null) {
643 query.append("ORDER BY ");
644 query.append(obc.getOrderBy());
645 }
646
647 else {
648 query.append("ORDER BY ");
649
650 query.append("parentCategoryId ASC, ");
651 query.append("name ASC");
652 }
653
654 Query q = session.createQuery(query.toString());
655
656 int queryPos = 0;
657
658 q.setLong(queryPos++, groupId);
659
660 q.setLong(queryPos++, parentCategoryId);
661
662 List<ShoppingCategory> list = (List<ShoppingCategory>)QueryUtil.list(q,
663 getDialect(), begin, end);
664
665 FinderCache.putResult(finderClassNameCacheEnabled,
666 finderClassName, finderMethodName, finderParams,
667 finderArgs, list);
668
669 return list;
670 }
671 catch (Exception e) {
672 throw HibernateUtil.processException(e);
673 }
674 finally {
675 closeSession(session);
676 }
677 }
678 else {
679 return (List<ShoppingCategory>)result;
680 }
681 }
682
683 public ShoppingCategory findByG_P_First(long groupId,
684 long parentCategoryId, OrderByComparator obc)
685 throws NoSuchCategoryException, SystemException {
686 List<ShoppingCategory> list = findByG_P(groupId, parentCategoryId, 0,
687 1, obc);
688
689 if (list.size() == 0) {
690 StringMaker msg = new StringMaker();
691
692 msg.append("No ShoppingCategory exists with the key {");
693
694 msg.append("groupId=" + groupId);
695
696 msg.append(", ");
697 msg.append("parentCategoryId=" + parentCategoryId);
698
699 msg.append(StringPool.CLOSE_CURLY_BRACE);
700
701 throw new NoSuchCategoryException(msg.toString());
702 }
703 else {
704 return list.get(0);
705 }
706 }
707
708 public ShoppingCategory findByG_P_Last(long groupId, long parentCategoryId,
709 OrderByComparator obc) throws NoSuchCategoryException, SystemException {
710 int count = countByG_P(groupId, parentCategoryId);
711
712 List<ShoppingCategory> list = findByG_P(groupId, parentCategoryId,
713 count - 1, count, obc);
714
715 if (list.size() == 0) {
716 StringMaker msg = new StringMaker();
717
718 msg.append("No ShoppingCategory exists with the key {");
719
720 msg.append("groupId=" + groupId);
721
722 msg.append(", ");
723 msg.append("parentCategoryId=" + parentCategoryId);
724
725 msg.append(StringPool.CLOSE_CURLY_BRACE);
726
727 throw new NoSuchCategoryException(msg.toString());
728 }
729 else {
730 return list.get(0);
731 }
732 }
733
734 public ShoppingCategory[] findByG_P_PrevAndNext(long categoryId,
735 long groupId, long parentCategoryId, OrderByComparator obc)
736 throws NoSuchCategoryException, SystemException {
737 ShoppingCategory shoppingCategory = findByPrimaryKey(categoryId);
738
739 int count = countByG_P(groupId, parentCategoryId);
740
741 Session session = null;
742
743 try {
744 session = openSession();
745
746 StringMaker query = new StringMaker();
747
748 query.append(
749 "FROM com.liferay.portlet.shopping.model.ShoppingCategory WHERE ");
750
751 query.append("groupId = ?");
752
753 query.append(" AND ");
754
755 query.append("parentCategoryId = ?");
756
757 query.append(" ");
758
759 if (obc != null) {
760 query.append("ORDER BY ");
761 query.append(obc.getOrderBy());
762 }
763
764 else {
765 query.append("ORDER BY ");
766
767 query.append("parentCategoryId ASC, ");
768 query.append("name ASC");
769 }
770
771 Query q = session.createQuery(query.toString());
772
773 int queryPos = 0;
774
775 q.setLong(queryPos++, groupId);
776
777 q.setLong(queryPos++, parentCategoryId);
778
779 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
780 shoppingCategory);
781
782 ShoppingCategory[] array = new ShoppingCategoryImpl[3];
783
784 array[0] = (ShoppingCategory)objArray[0];
785 array[1] = (ShoppingCategory)objArray[1];
786 array[2] = (ShoppingCategory)objArray[2];
787
788 return array;
789 }
790 catch (Exception e) {
791 throw HibernateUtil.processException(e);
792 }
793 finally {
794 closeSession(session);
795 }
796 }
797
798 public List<ShoppingCategory> findWithDynamicQuery(
799 DynamicQueryInitializer queryInitializer) throws SystemException {
800 Session session = null;
801
802 try {
803 session = openSession();
804
805 DynamicQuery query = queryInitializer.initialize(session);
806
807 return query.list();
808 }
809 catch (Exception e) {
810 throw HibernateUtil.processException(e);
811 }
812 finally {
813 closeSession(session);
814 }
815 }
816
817 public List<ShoppingCategory> findWithDynamicQuery(
818 DynamicQueryInitializer queryInitializer, int begin, int end)
819 throws SystemException {
820 Session session = null;
821
822 try {
823 session = openSession();
824
825 DynamicQuery query = queryInitializer.initialize(session);
826
827 query.setLimit(begin, end);
828
829 return query.list();
830 }
831 catch (Exception e) {
832 throw HibernateUtil.processException(e);
833 }
834 finally {
835 closeSession(session);
836 }
837 }
838
839 public List<ShoppingCategory> findAll() throws SystemException {
840 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
841 }
842
843 public List<ShoppingCategory> findAll(int begin, int end)
844 throws SystemException {
845 return findAll(begin, end, null);
846 }
847
848 public List<ShoppingCategory> findAll(int begin, int end,
849 OrderByComparator obc) throws SystemException {
850 boolean finderClassNameCacheEnabled = ShoppingCategoryModelImpl.CACHE_ENABLED;
851 String finderClassName = ShoppingCategory.class.getName();
852 String finderMethodName = "findAll";
853 String[] finderParams = new String[] {
854 "java.lang.Integer", "java.lang.Integer",
855 "com.liferay.portal.kernel.util.OrderByComparator"
856 };
857 Object[] finderArgs = new Object[] {
858 String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
859 };
860
861 Object result = null;
862
863 if (finderClassNameCacheEnabled) {
864 result = FinderCache.getResult(finderClassName, finderMethodName,
865 finderParams, finderArgs, getSessionFactory());
866 }
867
868 if (result == null) {
869 Session session = null;
870
871 try {
872 session = openSession();
873
874 StringMaker query = new StringMaker();
875
876 query.append(
877 "FROM com.liferay.portlet.shopping.model.ShoppingCategory ");
878
879 if (obc != null) {
880 query.append("ORDER BY ");
881 query.append(obc.getOrderBy());
882 }
883
884 else {
885 query.append("ORDER BY ");
886
887 query.append("parentCategoryId ASC, ");
888 query.append("name ASC");
889 }
890
891 Query q = session.createQuery(query.toString());
892
893 List<ShoppingCategory> list = (List<ShoppingCategory>)QueryUtil.list(q,
894 getDialect(), begin, end);
895
896 if (obc == null) {
897 Collections.sort(list);
898 }
899
900 FinderCache.putResult(finderClassNameCacheEnabled,
901 finderClassName, finderMethodName, finderParams,
902 finderArgs, list);
903
904 return list;
905 }
906 catch (Exception e) {
907 throw HibernateUtil.processException(e);
908 }
909 finally {
910 closeSession(session);
911 }
912 }
913 else {
914 return (List<ShoppingCategory>)result;
915 }
916 }
917
918 public void removeByGroupId(long groupId) throws SystemException {
919 for (ShoppingCategory shoppingCategory : findByGroupId(groupId)) {
920 remove(shoppingCategory);
921 }
922 }
923
924 public void removeByG_P(long groupId, long parentCategoryId)
925 throws SystemException {
926 for (ShoppingCategory shoppingCategory : findByG_P(groupId,
927 parentCategoryId)) {
928 remove(shoppingCategory);
929 }
930 }
931
932 public void removeAll() throws SystemException {
933 for (ShoppingCategory shoppingCategory : findAll()) {
934 remove(shoppingCategory);
935 }
936 }
937
938 public int countByGroupId(long groupId) throws SystemException {
939 boolean finderClassNameCacheEnabled = ShoppingCategoryModelImpl.CACHE_ENABLED;
940 String finderClassName = ShoppingCategory.class.getName();
941 String finderMethodName = "countByGroupId";
942 String[] finderParams = new String[] { Long.class.getName() };
943 Object[] finderArgs = new Object[] { new Long(groupId) };
944
945 Object result = null;
946
947 if (finderClassNameCacheEnabled) {
948 result = FinderCache.getResult(finderClassName, finderMethodName,
949 finderParams, finderArgs, getSessionFactory());
950 }
951
952 if (result == null) {
953 Session session = null;
954
955 try {
956 session = openSession();
957
958 StringMaker query = new StringMaker();
959
960 query.append("SELECT COUNT(*) ");
961 query.append(
962 "FROM com.liferay.portlet.shopping.model.ShoppingCategory WHERE ");
963
964 query.append("groupId = ?");
965
966 query.append(" ");
967
968 Query q = session.createQuery(query.toString());
969
970 int queryPos = 0;
971
972 q.setLong(queryPos++, groupId);
973
974 Long count = null;
975
976 Iterator<Long> itr = q.list().iterator();
977
978 if (itr.hasNext()) {
979 count = itr.next();
980 }
981
982 if (count == null) {
983 count = new Long(0);
984 }
985
986 FinderCache.putResult(finderClassNameCacheEnabled,
987 finderClassName, finderMethodName, finderParams,
988 finderArgs, count);
989
990 return count.intValue();
991 }
992 catch (Exception e) {
993 throw HibernateUtil.processException(e);
994 }
995 finally {
996 closeSession(session);
997 }
998 }
999 else {
1000 return ((Long)result).intValue();
1001 }
1002 }
1003
1004 public int countByG_P(long groupId, long parentCategoryId)
1005 throws SystemException {
1006 boolean finderClassNameCacheEnabled = ShoppingCategoryModelImpl.CACHE_ENABLED;
1007 String finderClassName = ShoppingCategory.class.getName();
1008 String finderMethodName = "countByG_P";
1009 String[] finderParams = new String[] {
1010 Long.class.getName(), Long.class.getName()
1011 };
1012 Object[] finderArgs = new Object[] {
1013 new Long(groupId), new Long(parentCategoryId)
1014 };
1015
1016 Object result = null;
1017
1018 if (finderClassNameCacheEnabled) {
1019 result = FinderCache.getResult(finderClassName, finderMethodName,
1020 finderParams, finderArgs, getSessionFactory());
1021 }
1022
1023 if (result == null) {
1024 Session session = null;
1025
1026 try {
1027 session = openSession();
1028
1029 StringMaker query = new StringMaker();
1030
1031 query.append("SELECT COUNT(*) ");
1032 query.append(
1033 "FROM com.liferay.portlet.shopping.model.ShoppingCategory WHERE ");
1034
1035 query.append("groupId = ?");
1036
1037 query.append(" AND ");
1038
1039 query.append("parentCategoryId = ?");
1040
1041 query.append(" ");
1042
1043 Query q = session.createQuery(query.toString());
1044
1045 int queryPos = 0;
1046
1047 q.setLong(queryPos++, groupId);
1048
1049 q.setLong(queryPos++, parentCategoryId);
1050
1051 Long count = null;
1052
1053 Iterator<Long> itr = q.list().iterator();
1054
1055 if (itr.hasNext()) {
1056 count = itr.next();
1057 }
1058
1059 if (count == null) {
1060 count = new Long(0);
1061 }
1062
1063 FinderCache.putResult(finderClassNameCacheEnabled,
1064 finderClassName, finderMethodName, finderParams,
1065 finderArgs, count);
1066
1067 return count.intValue();
1068 }
1069 catch (Exception e) {
1070 throw HibernateUtil.processException(e);
1071 }
1072 finally {
1073 closeSession(session);
1074 }
1075 }
1076 else {
1077 return ((Long)result).intValue();
1078 }
1079 }
1080
1081 public int countAll() throws SystemException {
1082 boolean finderClassNameCacheEnabled = ShoppingCategoryModelImpl.CACHE_ENABLED;
1083 String finderClassName = ShoppingCategory.class.getName();
1084 String finderMethodName = "countAll";
1085 String[] finderParams = new String[] { };
1086 Object[] finderArgs = new Object[] { };
1087
1088 Object result = null;
1089
1090 if (finderClassNameCacheEnabled) {
1091 result = FinderCache.getResult(finderClassName, finderMethodName,
1092 finderParams, finderArgs, getSessionFactory());
1093 }
1094
1095 if (result == null) {
1096 Session session = null;
1097
1098 try {
1099 session = openSession();
1100
1101 Query q = session.createQuery(
1102 "SELECT COUNT(*) FROM com.liferay.portlet.shopping.model.ShoppingCategory");
1103
1104 Long count = null;
1105
1106 Iterator<Long> itr = q.list().iterator();
1107
1108 if (itr.hasNext()) {
1109 count = itr.next();
1110 }
1111
1112 if (count == null) {
1113 count = new Long(0);
1114 }
1115
1116 FinderCache.putResult(finderClassNameCacheEnabled,
1117 finderClassName, finderMethodName, finderParams,
1118 finderArgs, count);
1119
1120 return count.intValue();
1121 }
1122 catch (Exception e) {
1123 throw HibernateUtil.processException(e);
1124 }
1125 finally {
1126 closeSession(session);
1127 }
1128 }
1129 else {
1130 return ((Long)result).intValue();
1131 }
1132 }
1133
1134 protected void initDao() {
1135 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1136 PropsUtil.get(
1137 "value.object.listener.com.liferay.portlet.shopping.model.ShoppingCategory")));
1138
1139 if (listenerClassNames.length > 0) {
1140 try {
1141 List<ModelListener> listeners = new ArrayList<ModelListener>();
1142
1143 for (String listenerClassName : listenerClassNames) {
1144 listeners.add((ModelListener)Class.forName(
1145 listenerClassName).newInstance());
1146 }
1147
1148 _listeners = listeners.toArray(new ModelListener[listeners.size()]);
1149 }
1150 catch (Exception e) {
1151 _log.error(e);
1152 }
1153 }
1154 }
1155
1156 private static Log _log = LogFactory.getLog(ShoppingCategoryPersistenceImpl.class);
1157 private ModelListener[] _listeners;
1158}