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