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