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