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