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