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