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