001
014
015 package com.liferay.portlet.shopping.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
018 import com.liferay.portal.kernel.bean.BeanReference;
019 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderPath;
023 import com.liferay.portal.kernel.dao.orm.Query;
024 import com.liferay.portal.kernel.dao.orm.QueryPos;
025 import com.liferay.portal.kernel.dao.orm.QueryUtil;
026 import com.liferay.portal.kernel.dao.orm.Session;
027 import com.liferay.portal.kernel.exception.SystemException;
028 import com.liferay.portal.kernel.log.Log;
029 import com.liferay.portal.kernel.log.LogFactoryUtil;
030 import com.liferay.portal.kernel.util.GetterUtil;
031 import com.liferay.portal.kernel.util.InstanceFactory;
032 import com.liferay.portal.kernel.util.OrderByComparator;
033 import com.liferay.portal.kernel.util.StringBundler;
034 import com.liferay.portal.kernel.util.StringPool;
035 import com.liferay.portal.kernel.util.StringUtil;
036 import com.liferay.portal.kernel.util.Validator;
037 import com.liferay.portal.model.CacheModel;
038 import com.liferay.portal.model.ModelListener;
039 import com.liferay.portal.service.persistence.BatchSessionUtil;
040 import com.liferay.portal.service.persistence.ResourcePersistence;
041 import com.liferay.portal.service.persistence.UserPersistence;
042 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
043
044 import com.liferay.portlet.shopping.NoSuchCouponException;
045 import com.liferay.portlet.shopping.model.ShoppingCoupon;
046 import com.liferay.portlet.shopping.model.impl.ShoppingCouponImpl;
047 import com.liferay.portlet.shopping.model.impl.ShoppingCouponModelImpl;
048
049 import java.io.Serializable;
050
051 import java.util.ArrayList;
052 import java.util.Collections;
053 import java.util.List;
054
055
067 public class ShoppingCouponPersistenceImpl extends BasePersistenceImpl<ShoppingCoupon>
068 implements ShoppingCouponPersistence {
069
074 public static final String FINDER_CLASS_NAME_ENTITY = ShoppingCouponImpl.class.getName();
075 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
076 ".List1";
077 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
078 ".List2";
079 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(ShoppingCouponModelImpl.ENTITY_CACHE_ENABLED,
080 ShoppingCouponModelImpl.FINDER_CACHE_ENABLED,
081 ShoppingCouponImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
082 "findByGroupId",
083 new String[] {
084 Long.class.getName(),
085
086 "java.lang.Integer", "java.lang.Integer",
087 "com.liferay.portal.kernel.util.OrderByComparator"
088 });
089 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
090 new FinderPath(ShoppingCouponModelImpl.ENTITY_CACHE_ENABLED,
091 ShoppingCouponModelImpl.FINDER_CACHE_ENABLED,
092 ShoppingCouponImpl.class,
093 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
094 new String[] { Long.class.getName() },
095 ShoppingCouponModelImpl.GROUPID_COLUMN_BITMASK);
096 public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(ShoppingCouponModelImpl.ENTITY_CACHE_ENABLED,
097 ShoppingCouponModelImpl.FINDER_CACHE_ENABLED, Long.class,
098 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
099 new String[] { Long.class.getName() });
100 public static final FinderPath FINDER_PATH_FETCH_BY_CODE = new FinderPath(ShoppingCouponModelImpl.ENTITY_CACHE_ENABLED,
101 ShoppingCouponModelImpl.FINDER_CACHE_ENABLED,
102 ShoppingCouponImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByCode",
103 new String[] { String.class.getName() },
104 ShoppingCouponModelImpl.CODE_COLUMN_BITMASK);
105 public static final FinderPath FINDER_PATH_COUNT_BY_CODE = new FinderPath(ShoppingCouponModelImpl.ENTITY_CACHE_ENABLED,
106 ShoppingCouponModelImpl.FINDER_CACHE_ENABLED, Long.class,
107 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCode",
108 new String[] { String.class.getName() });
109 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(ShoppingCouponModelImpl.ENTITY_CACHE_ENABLED,
110 ShoppingCouponModelImpl.FINDER_CACHE_ENABLED,
111 ShoppingCouponImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
112 "findAll", new String[0]);
113 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(ShoppingCouponModelImpl.ENTITY_CACHE_ENABLED,
114 ShoppingCouponModelImpl.FINDER_CACHE_ENABLED,
115 ShoppingCouponImpl.class,
116 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
117 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ShoppingCouponModelImpl.ENTITY_CACHE_ENABLED,
118 ShoppingCouponModelImpl.FINDER_CACHE_ENABLED, Long.class,
119 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
120
121
126 public void cacheResult(ShoppingCoupon shoppingCoupon) {
127 EntityCacheUtil.putResult(ShoppingCouponModelImpl.ENTITY_CACHE_ENABLED,
128 ShoppingCouponImpl.class, shoppingCoupon.getPrimaryKey(),
129 shoppingCoupon);
130
131 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_CODE,
132 new Object[] { shoppingCoupon.getCode() }, shoppingCoupon);
133
134 shoppingCoupon.resetOriginalValues();
135 }
136
137
142 public void cacheResult(List<ShoppingCoupon> shoppingCoupons) {
143 for (ShoppingCoupon shoppingCoupon : shoppingCoupons) {
144 if (EntityCacheUtil.getResult(
145 ShoppingCouponModelImpl.ENTITY_CACHE_ENABLED,
146 ShoppingCouponImpl.class, shoppingCoupon.getPrimaryKey()) == null) {
147 cacheResult(shoppingCoupon);
148 }
149 else {
150 shoppingCoupon.resetOriginalValues();
151 }
152 }
153 }
154
155
162 @Override
163 public void clearCache() {
164 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
165 CacheRegistryUtil.clear(ShoppingCouponImpl.class.getName());
166 }
167
168 EntityCacheUtil.clearCache(ShoppingCouponImpl.class.getName());
169
170 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
171 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
172 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
173 }
174
175
182 @Override
183 public void clearCache(ShoppingCoupon shoppingCoupon) {
184 EntityCacheUtil.removeResult(ShoppingCouponModelImpl.ENTITY_CACHE_ENABLED,
185 ShoppingCouponImpl.class, shoppingCoupon.getPrimaryKey());
186
187 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
188 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
189
190 clearUniqueFindersCache(shoppingCoupon);
191 }
192
193 @Override
194 public void clearCache(List<ShoppingCoupon> shoppingCoupons) {
195 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
196 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
197
198 for (ShoppingCoupon shoppingCoupon : shoppingCoupons) {
199 EntityCacheUtil.removeResult(ShoppingCouponModelImpl.ENTITY_CACHE_ENABLED,
200 ShoppingCouponImpl.class, shoppingCoupon.getPrimaryKey());
201
202 clearUniqueFindersCache(shoppingCoupon);
203 }
204 }
205
206 protected void cacheUniqueFindersCache(ShoppingCoupon shoppingCoupon) {
207 if (shoppingCoupon.isNew()) {
208 Object[] args = new Object[] { shoppingCoupon.getCode() };
209
210 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_CODE, args,
211 Long.valueOf(1));
212 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_CODE, args,
213 shoppingCoupon);
214 }
215 else {
216 ShoppingCouponModelImpl shoppingCouponModelImpl = (ShoppingCouponModelImpl)shoppingCoupon;
217
218 if ((shoppingCouponModelImpl.getColumnBitmask() &
219 FINDER_PATH_FETCH_BY_CODE.getColumnBitmask()) != 0) {
220 Object[] args = new Object[] { shoppingCoupon.getCode() };
221
222 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_CODE, args,
223 Long.valueOf(1));
224 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_CODE, args,
225 shoppingCoupon);
226 }
227 }
228 }
229
230 protected void clearUniqueFindersCache(ShoppingCoupon shoppingCoupon) {
231 ShoppingCouponModelImpl shoppingCouponModelImpl = (ShoppingCouponModelImpl)shoppingCoupon;
232
233 Object[] args = new Object[] { shoppingCoupon.getCode() };
234
235 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_CODE, args);
236 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_CODE, args);
237
238 if ((shoppingCouponModelImpl.getColumnBitmask() &
239 FINDER_PATH_FETCH_BY_CODE.getColumnBitmask()) != 0) {
240 args = new Object[] { shoppingCouponModelImpl.getOriginalCode() };
241
242 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_CODE, args);
243 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_CODE, args);
244 }
245 }
246
247
253 public ShoppingCoupon create(long couponId) {
254 ShoppingCoupon shoppingCoupon = new ShoppingCouponImpl();
255
256 shoppingCoupon.setNew(true);
257 shoppingCoupon.setPrimaryKey(couponId);
258
259 return shoppingCoupon;
260 }
261
262
270 public ShoppingCoupon remove(long couponId)
271 throws NoSuchCouponException, SystemException {
272 return remove(Long.valueOf(couponId));
273 }
274
275
283 @Override
284 public ShoppingCoupon remove(Serializable primaryKey)
285 throws NoSuchCouponException, SystemException {
286 Session session = null;
287
288 try {
289 session = openSession();
290
291 ShoppingCoupon shoppingCoupon = (ShoppingCoupon)session.get(ShoppingCouponImpl.class,
292 primaryKey);
293
294 if (shoppingCoupon == null) {
295 if (_log.isWarnEnabled()) {
296 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
297 }
298
299 throw new NoSuchCouponException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
300 primaryKey);
301 }
302
303 return remove(shoppingCoupon);
304 }
305 catch (NoSuchCouponException nsee) {
306 throw nsee;
307 }
308 catch (Exception e) {
309 throw processException(e);
310 }
311 finally {
312 closeSession(session);
313 }
314 }
315
316 @Override
317 protected ShoppingCoupon removeImpl(ShoppingCoupon shoppingCoupon)
318 throws SystemException {
319 shoppingCoupon = toUnwrappedModel(shoppingCoupon);
320
321 Session session = null;
322
323 try {
324 session = openSession();
325
326 BatchSessionUtil.delete(session, shoppingCoupon);
327 }
328 catch (Exception e) {
329 throw processException(e);
330 }
331 finally {
332 closeSession(session);
333 }
334
335 clearCache(shoppingCoupon);
336
337 return shoppingCoupon;
338 }
339
340 @Override
341 public ShoppingCoupon updateImpl(
342 com.liferay.portlet.shopping.model.ShoppingCoupon shoppingCoupon,
343 boolean merge) throws SystemException {
344 shoppingCoupon = toUnwrappedModel(shoppingCoupon);
345
346 boolean isNew = shoppingCoupon.isNew();
347
348 ShoppingCouponModelImpl shoppingCouponModelImpl = (ShoppingCouponModelImpl)shoppingCoupon;
349
350 Session session = null;
351
352 try {
353 session = openSession();
354
355 BatchSessionUtil.update(session, shoppingCoupon, merge);
356
357 shoppingCoupon.setNew(false);
358 }
359 catch (Exception e) {
360 throw processException(e);
361 }
362 finally {
363 closeSession(session);
364 }
365
366 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
367
368 if (isNew || !ShoppingCouponModelImpl.COLUMN_BITMASK_ENABLED) {
369 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
370 }
371
372 else {
373 if ((shoppingCouponModelImpl.getColumnBitmask() &
374 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
375 Object[] args = new Object[] {
376 Long.valueOf(shoppingCouponModelImpl.getOriginalGroupId())
377 };
378
379 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
380 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
381 args);
382
383 args = new Object[] {
384 Long.valueOf(shoppingCouponModelImpl.getGroupId())
385 };
386
387 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
388 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
389 args);
390 }
391 }
392
393 EntityCacheUtil.putResult(ShoppingCouponModelImpl.ENTITY_CACHE_ENABLED,
394 ShoppingCouponImpl.class, shoppingCoupon.getPrimaryKey(),
395 shoppingCoupon);
396
397 clearUniqueFindersCache(shoppingCoupon);
398 cacheUniqueFindersCache(shoppingCoupon);
399
400 return shoppingCoupon;
401 }
402
403 protected ShoppingCoupon toUnwrappedModel(ShoppingCoupon shoppingCoupon) {
404 if (shoppingCoupon instanceof ShoppingCouponImpl) {
405 return shoppingCoupon;
406 }
407
408 ShoppingCouponImpl shoppingCouponImpl = new ShoppingCouponImpl();
409
410 shoppingCouponImpl.setNew(shoppingCoupon.isNew());
411 shoppingCouponImpl.setPrimaryKey(shoppingCoupon.getPrimaryKey());
412
413 shoppingCouponImpl.setCouponId(shoppingCoupon.getCouponId());
414 shoppingCouponImpl.setGroupId(shoppingCoupon.getGroupId());
415 shoppingCouponImpl.setCompanyId(shoppingCoupon.getCompanyId());
416 shoppingCouponImpl.setUserId(shoppingCoupon.getUserId());
417 shoppingCouponImpl.setUserName(shoppingCoupon.getUserName());
418 shoppingCouponImpl.setCreateDate(shoppingCoupon.getCreateDate());
419 shoppingCouponImpl.setModifiedDate(shoppingCoupon.getModifiedDate());
420 shoppingCouponImpl.setCode(shoppingCoupon.getCode());
421 shoppingCouponImpl.setName(shoppingCoupon.getName());
422 shoppingCouponImpl.setDescription(shoppingCoupon.getDescription());
423 shoppingCouponImpl.setStartDate(shoppingCoupon.getStartDate());
424 shoppingCouponImpl.setEndDate(shoppingCoupon.getEndDate());
425 shoppingCouponImpl.setActive(shoppingCoupon.isActive());
426 shoppingCouponImpl.setLimitCategories(shoppingCoupon.getLimitCategories());
427 shoppingCouponImpl.setLimitSkus(shoppingCoupon.getLimitSkus());
428 shoppingCouponImpl.setMinOrder(shoppingCoupon.getMinOrder());
429 shoppingCouponImpl.setDiscount(shoppingCoupon.getDiscount());
430 shoppingCouponImpl.setDiscountType(shoppingCoupon.getDiscountType());
431
432 return shoppingCouponImpl;
433 }
434
435
443 @Override
444 public ShoppingCoupon findByPrimaryKey(Serializable primaryKey)
445 throws NoSuchModelException, SystemException {
446 return findByPrimaryKey(((Long)primaryKey).longValue());
447 }
448
449
457 public ShoppingCoupon findByPrimaryKey(long couponId)
458 throws NoSuchCouponException, SystemException {
459 ShoppingCoupon shoppingCoupon = fetchByPrimaryKey(couponId);
460
461 if (shoppingCoupon == null) {
462 if (_log.isWarnEnabled()) {
463 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + couponId);
464 }
465
466 throw new NoSuchCouponException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
467 couponId);
468 }
469
470 return shoppingCoupon;
471 }
472
473
480 @Override
481 public ShoppingCoupon fetchByPrimaryKey(Serializable primaryKey)
482 throws SystemException {
483 return fetchByPrimaryKey(((Long)primaryKey).longValue());
484 }
485
486
493 public ShoppingCoupon fetchByPrimaryKey(long couponId)
494 throws SystemException {
495 ShoppingCoupon shoppingCoupon = (ShoppingCoupon)EntityCacheUtil.getResult(ShoppingCouponModelImpl.ENTITY_CACHE_ENABLED,
496 ShoppingCouponImpl.class, couponId);
497
498 if (shoppingCoupon == _nullShoppingCoupon) {
499 return null;
500 }
501
502 if (shoppingCoupon == null) {
503 Session session = null;
504
505 boolean hasException = false;
506
507 try {
508 session = openSession();
509
510 shoppingCoupon = (ShoppingCoupon)session.get(ShoppingCouponImpl.class,
511 Long.valueOf(couponId));
512 }
513 catch (Exception e) {
514 hasException = true;
515
516 throw processException(e);
517 }
518 finally {
519 if (shoppingCoupon != null) {
520 cacheResult(shoppingCoupon);
521 }
522 else if (!hasException) {
523 EntityCacheUtil.putResult(ShoppingCouponModelImpl.ENTITY_CACHE_ENABLED,
524 ShoppingCouponImpl.class, couponId, _nullShoppingCoupon);
525 }
526
527 closeSession(session);
528 }
529 }
530
531 return shoppingCoupon;
532 }
533
534
541 public List<ShoppingCoupon> findByGroupId(long groupId)
542 throws SystemException {
543 return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
544 }
545
546
559 public List<ShoppingCoupon> findByGroupId(long groupId, int start, int end)
560 throws SystemException {
561 return findByGroupId(groupId, start, end, null);
562 }
563
564
578 public List<ShoppingCoupon> findByGroupId(long groupId, int start, int end,
579 OrderByComparator orderByComparator) throws SystemException {
580 FinderPath finderPath = null;
581 Object[] finderArgs = null;
582
583 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
584 (orderByComparator == null)) {
585 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
586 finderArgs = new Object[] { groupId };
587 }
588 else {
589 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
590 finderArgs = new Object[] { groupId, start, end, orderByComparator };
591 }
592
593 List<ShoppingCoupon> list = (List<ShoppingCoupon>)FinderCacheUtil.getResult(finderPath,
594 finderArgs, this);
595
596 if ((list != null) && !list.isEmpty()) {
597 for (ShoppingCoupon shoppingCoupon : list) {
598 if ((groupId != shoppingCoupon.getGroupId())) {
599 list = null;
600
601 break;
602 }
603 }
604 }
605
606 if (list == null) {
607 StringBundler query = null;
608
609 if (orderByComparator != null) {
610 query = new StringBundler(3 +
611 (orderByComparator.getOrderByFields().length * 3));
612 }
613 else {
614 query = new StringBundler(3);
615 }
616
617 query.append(_SQL_SELECT_SHOPPINGCOUPON_WHERE);
618
619 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
620
621 if (orderByComparator != null) {
622 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
623 orderByComparator);
624 }
625
626 else {
627 query.append(ShoppingCouponModelImpl.ORDER_BY_JPQL);
628 }
629
630 String sql = query.toString();
631
632 Session session = null;
633
634 try {
635 session = openSession();
636
637 Query q = session.createQuery(sql);
638
639 QueryPos qPos = QueryPos.getInstance(q);
640
641 qPos.add(groupId);
642
643 list = (List<ShoppingCoupon>)QueryUtil.list(q, getDialect(),
644 start, end);
645 }
646 catch (Exception e) {
647 throw processException(e);
648 }
649 finally {
650 if (list == null) {
651 FinderCacheUtil.removeResult(finderPath, finderArgs);
652 }
653 else {
654 cacheResult(list);
655
656 FinderCacheUtil.putResult(finderPath, finderArgs, list);
657 }
658
659 closeSession(session);
660 }
661 }
662
663 return list;
664 }
665
666
675 public ShoppingCoupon findByGroupId_First(long groupId,
676 OrderByComparator orderByComparator)
677 throws NoSuchCouponException, SystemException {
678 ShoppingCoupon shoppingCoupon = fetchByGroupId_First(groupId,
679 orderByComparator);
680
681 if (shoppingCoupon != null) {
682 return shoppingCoupon;
683 }
684
685 StringBundler msg = new StringBundler(4);
686
687 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
688
689 msg.append("groupId=");
690 msg.append(groupId);
691
692 msg.append(StringPool.CLOSE_CURLY_BRACE);
693
694 throw new NoSuchCouponException(msg.toString());
695 }
696
697
705 public ShoppingCoupon fetchByGroupId_First(long groupId,
706 OrderByComparator orderByComparator) throws SystemException {
707 List<ShoppingCoupon> list = findByGroupId(groupId, 0, 1,
708 orderByComparator);
709
710 if (!list.isEmpty()) {
711 return list.get(0);
712 }
713
714 return null;
715 }
716
717
726 public ShoppingCoupon findByGroupId_Last(long groupId,
727 OrderByComparator orderByComparator)
728 throws NoSuchCouponException, SystemException {
729 ShoppingCoupon shoppingCoupon = fetchByGroupId_Last(groupId,
730 orderByComparator);
731
732 if (shoppingCoupon != null) {
733 return shoppingCoupon;
734 }
735
736 StringBundler msg = new StringBundler(4);
737
738 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
739
740 msg.append("groupId=");
741 msg.append(groupId);
742
743 msg.append(StringPool.CLOSE_CURLY_BRACE);
744
745 throw new NoSuchCouponException(msg.toString());
746 }
747
748
756 public ShoppingCoupon fetchByGroupId_Last(long groupId,
757 OrderByComparator orderByComparator) throws SystemException {
758 int count = countByGroupId(groupId);
759
760 List<ShoppingCoupon> list = findByGroupId(groupId, count - 1, count,
761 orderByComparator);
762
763 if (!list.isEmpty()) {
764 return list.get(0);
765 }
766
767 return null;
768 }
769
770
780 public ShoppingCoupon[] findByGroupId_PrevAndNext(long couponId,
781 long groupId, OrderByComparator orderByComparator)
782 throws NoSuchCouponException, SystemException {
783 ShoppingCoupon shoppingCoupon = findByPrimaryKey(couponId);
784
785 Session session = null;
786
787 try {
788 session = openSession();
789
790 ShoppingCoupon[] array = new ShoppingCouponImpl[3];
791
792 array[0] = getByGroupId_PrevAndNext(session, shoppingCoupon,
793 groupId, orderByComparator, true);
794
795 array[1] = shoppingCoupon;
796
797 array[2] = getByGroupId_PrevAndNext(session, shoppingCoupon,
798 groupId, orderByComparator, false);
799
800 return array;
801 }
802 catch (Exception e) {
803 throw processException(e);
804 }
805 finally {
806 closeSession(session);
807 }
808 }
809
810 protected ShoppingCoupon getByGroupId_PrevAndNext(Session session,
811 ShoppingCoupon shoppingCoupon, long groupId,
812 OrderByComparator orderByComparator, boolean previous) {
813 StringBundler query = null;
814
815 if (orderByComparator != null) {
816 query = new StringBundler(6 +
817 (orderByComparator.getOrderByFields().length * 6));
818 }
819 else {
820 query = new StringBundler(3);
821 }
822
823 query.append(_SQL_SELECT_SHOPPINGCOUPON_WHERE);
824
825 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
826
827 if (orderByComparator != null) {
828 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
829
830 if (orderByConditionFields.length > 0) {
831 query.append(WHERE_AND);
832 }
833
834 for (int i = 0; i < orderByConditionFields.length; i++) {
835 query.append(_ORDER_BY_ENTITY_ALIAS);
836 query.append(orderByConditionFields[i]);
837
838 if ((i + 1) < orderByConditionFields.length) {
839 if (orderByComparator.isAscending() ^ previous) {
840 query.append(WHERE_GREATER_THAN_HAS_NEXT);
841 }
842 else {
843 query.append(WHERE_LESSER_THAN_HAS_NEXT);
844 }
845 }
846 else {
847 if (orderByComparator.isAscending() ^ previous) {
848 query.append(WHERE_GREATER_THAN);
849 }
850 else {
851 query.append(WHERE_LESSER_THAN);
852 }
853 }
854 }
855
856 query.append(ORDER_BY_CLAUSE);
857
858 String[] orderByFields = orderByComparator.getOrderByFields();
859
860 for (int i = 0; i < orderByFields.length; i++) {
861 query.append(_ORDER_BY_ENTITY_ALIAS);
862 query.append(orderByFields[i]);
863
864 if ((i + 1) < orderByFields.length) {
865 if (orderByComparator.isAscending() ^ previous) {
866 query.append(ORDER_BY_ASC_HAS_NEXT);
867 }
868 else {
869 query.append(ORDER_BY_DESC_HAS_NEXT);
870 }
871 }
872 else {
873 if (orderByComparator.isAscending() ^ previous) {
874 query.append(ORDER_BY_ASC);
875 }
876 else {
877 query.append(ORDER_BY_DESC);
878 }
879 }
880 }
881 }
882
883 else {
884 query.append(ShoppingCouponModelImpl.ORDER_BY_JPQL);
885 }
886
887 String sql = query.toString();
888
889 Query q = session.createQuery(sql);
890
891 q.setFirstResult(0);
892 q.setMaxResults(2);
893
894 QueryPos qPos = QueryPos.getInstance(q);
895
896 qPos.add(groupId);
897
898 if (orderByComparator != null) {
899 Object[] values = orderByComparator.getOrderByConditionValues(shoppingCoupon);
900
901 for (Object value : values) {
902 qPos.add(value);
903 }
904 }
905
906 List<ShoppingCoupon> list = q.list();
907
908 if (list.size() == 2) {
909 return list.get(1);
910 }
911 else {
912 return null;
913 }
914 }
915
916
924 public ShoppingCoupon findByCode(String code)
925 throws NoSuchCouponException, SystemException {
926 ShoppingCoupon shoppingCoupon = fetchByCode(code);
927
928 if (shoppingCoupon == null) {
929 StringBundler msg = new StringBundler(4);
930
931 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
932
933 msg.append("code=");
934 msg.append(code);
935
936 msg.append(StringPool.CLOSE_CURLY_BRACE);
937
938 if (_log.isWarnEnabled()) {
939 _log.warn(msg.toString());
940 }
941
942 throw new NoSuchCouponException(msg.toString());
943 }
944
945 return shoppingCoupon;
946 }
947
948
955 public ShoppingCoupon fetchByCode(String code) throws SystemException {
956 return fetchByCode(code, true);
957 }
958
959
967 public ShoppingCoupon fetchByCode(String code, boolean retrieveFromCache)
968 throws SystemException {
969 Object[] finderArgs = new Object[] { code };
970
971 Object result = null;
972
973 if (retrieveFromCache) {
974 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_CODE,
975 finderArgs, this);
976 }
977
978 if (result instanceof ShoppingCoupon) {
979 ShoppingCoupon shoppingCoupon = (ShoppingCoupon)result;
980
981 if (!Validator.equals(code, shoppingCoupon.getCode())) {
982 result = null;
983 }
984 }
985
986 if (result == null) {
987 StringBundler query = new StringBundler(3);
988
989 query.append(_SQL_SELECT_SHOPPINGCOUPON_WHERE);
990
991 if (code == null) {
992 query.append(_FINDER_COLUMN_CODE_CODE_1);
993 }
994 else {
995 if (code.equals(StringPool.BLANK)) {
996 query.append(_FINDER_COLUMN_CODE_CODE_3);
997 }
998 else {
999 query.append(_FINDER_COLUMN_CODE_CODE_2);
1000 }
1001 }
1002
1003 query.append(ShoppingCouponModelImpl.ORDER_BY_JPQL);
1004
1005 String sql = query.toString();
1006
1007 Session session = null;
1008
1009 try {
1010 session = openSession();
1011
1012 Query q = session.createQuery(sql);
1013
1014 QueryPos qPos = QueryPos.getInstance(q);
1015
1016 if (code != null) {
1017 qPos.add(code);
1018 }
1019
1020 List<ShoppingCoupon> list = q.list();
1021
1022 result = list;
1023
1024 ShoppingCoupon shoppingCoupon = null;
1025
1026 if (list.isEmpty()) {
1027 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_CODE,
1028 finderArgs, list);
1029 }
1030 else {
1031 shoppingCoupon = list.get(0);
1032
1033 cacheResult(shoppingCoupon);
1034
1035 if ((shoppingCoupon.getCode() == null) ||
1036 !shoppingCoupon.getCode().equals(code)) {
1037 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_CODE,
1038 finderArgs, shoppingCoupon);
1039 }
1040 }
1041
1042 return shoppingCoupon;
1043 }
1044 catch (Exception e) {
1045 throw processException(e);
1046 }
1047 finally {
1048 if (result == null) {
1049 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_CODE,
1050 finderArgs);
1051 }
1052
1053 closeSession(session);
1054 }
1055 }
1056 else {
1057 if (result instanceof List<?>) {
1058 return null;
1059 }
1060 else {
1061 return (ShoppingCoupon)result;
1062 }
1063 }
1064 }
1065
1066
1072 public List<ShoppingCoupon> findAll() throws SystemException {
1073 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1074 }
1075
1076
1088 public List<ShoppingCoupon> findAll(int start, int end)
1089 throws SystemException {
1090 return findAll(start, end, null);
1091 }
1092
1093
1106 public List<ShoppingCoupon> findAll(int start, int end,
1107 OrderByComparator orderByComparator) throws SystemException {
1108 FinderPath finderPath = null;
1109 Object[] finderArgs = new Object[] { start, end, orderByComparator };
1110
1111 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1112 (orderByComparator == null)) {
1113 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1114 finderArgs = FINDER_ARGS_EMPTY;
1115 }
1116 else {
1117 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1118 finderArgs = new Object[] { start, end, orderByComparator };
1119 }
1120
1121 List<ShoppingCoupon> list = (List<ShoppingCoupon>)FinderCacheUtil.getResult(finderPath,
1122 finderArgs, this);
1123
1124 if (list == null) {
1125 StringBundler query = null;
1126 String sql = null;
1127
1128 if (orderByComparator != null) {
1129 query = new StringBundler(2 +
1130 (orderByComparator.getOrderByFields().length * 3));
1131
1132 query.append(_SQL_SELECT_SHOPPINGCOUPON);
1133
1134 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1135 orderByComparator);
1136
1137 sql = query.toString();
1138 }
1139 else {
1140 sql = _SQL_SELECT_SHOPPINGCOUPON.concat(ShoppingCouponModelImpl.ORDER_BY_JPQL);
1141 }
1142
1143 Session session = null;
1144
1145 try {
1146 session = openSession();
1147
1148 Query q = session.createQuery(sql);
1149
1150 if (orderByComparator == null) {
1151 list = (List<ShoppingCoupon>)QueryUtil.list(q,
1152 getDialect(), start, end, false);
1153
1154 Collections.sort(list);
1155 }
1156 else {
1157 list = (List<ShoppingCoupon>)QueryUtil.list(q,
1158 getDialect(), start, end);
1159 }
1160 }
1161 catch (Exception e) {
1162 throw processException(e);
1163 }
1164 finally {
1165 if (list == null) {
1166 FinderCacheUtil.removeResult(finderPath, finderArgs);
1167 }
1168 else {
1169 cacheResult(list);
1170
1171 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1172 }
1173
1174 closeSession(session);
1175 }
1176 }
1177
1178 return list;
1179 }
1180
1181
1187 public void removeByGroupId(long groupId) throws SystemException {
1188 for (ShoppingCoupon shoppingCoupon : findByGroupId(groupId)) {
1189 remove(shoppingCoupon);
1190 }
1191 }
1192
1193
1200 public ShoppingCoupon removeByCode(String code)
1201 throws NoSuchCouponException, SystemException {
1202 ShoppingCoupon shoppingCoupon = findByCode(code);
1203
1204 return remove(shoppingCoupon);
1205 }
1206
1207
1212 public void removeAll() throws SystemException {
1213 for (ShoppingCoupon shoppingCoupon : findAll()) {
1214 remove(shoppingCoupon);
1215 }
1216 }
1217
1218
1225 public int countByGroupId(long groupId) throws SystemException {
1226 Object[] finderArgs = new Object[] { groupId };
1227
1228 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
1229 finderArgs, this);
1230
1231 if (count == null) {
1232 StringBundler query = new StringBundler(2);
1233
1234 query.append(_SQL_COUNT_SHOPPINGCOUPON_WHERE);
1235
1236 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1237
1238 String sql = query.toString();
1239
1240 Session session = null;
1241
1242 try {
1243 session = openSession();
1244
1245 Query q = session.createQuery(sql);
1246
1247 QueryPos qPos = QueryPos.getInstance(q);
1248
1249 qPos.add(groupId);
1250
1251 count = (Long)q.uniqueResult();
1252 }
1253 catch (Exception e) {
1254 throw processException(e);
1255 }
1256 finally {
1257 if (count == null) {
1258 count = Long.valueOf(0);
1259 }
1260
1261 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
1262 finderArgs, count);
1263
1264 closeSession(session);
1265 }
1266 }
1267
1268 return count.intValue();
1269 }
1270
1271
1278 public int countByCode(String code) throws SystemException {
1279 Object[] finderArgs = new Object[] { code };
1280
1281 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_CODE,
1282 finderArgs, this);
1283
1284 if (count == null) {
1285 StringBundler query = new StringBundler(2);
1286
1287 query.append(_SQL_COUNT_SHOPPINGCOUPON_WHERE);
1288
1289 if (code == null) {
1290 query.append(_FINDER_COLUMN_CODE_CODE_1);
1291 }
1292 else {
1293 if (code.equals(StringPool.BLANK)) {
1294 query.append(_FINDER_COLUMN_CODE_CODE_3);
1295 }
1296 else {
1297 query.append(_FINDER_COLUMN_CODE_CODE_2);
1298 }
1299 }
1300
1301 String sql = query.toString();
1302
1303 Session session = null;
1304
1305 try {
1306 session = openSession();
1307
1308 Query q = session.createQuery(sql);
1309
1310 QueryPos qPos = QueryPos.getInstance(q);
1311
1312 if (code != null) {
1313 qPos.add(code);
1314 }
1315
1316 count = (Long)q.uniqueResult();
1317 }
1318 catch (Exception e) {
1319 throw processException(e);
1320 }
1321 finally {
1322 if (count == null) {
1323 count = Long.valueOf(0);
1324 }
1325
1326 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_CODE,
1327 finderArgs, count);
1328
1329 closeSession(session);
1330 }
1331 }
1332
1333 return count.intValue();
1334 }
1335
1336
1342 public int countAll() throws SystemException {
1343 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1344 FINDER_ARGS_EMPTY, this);
1345
1346 if (count == null) {
1347 Session session = null;
1348
1349 try {
1350 session = openSession();
1351
1352 Query q = session.createQuery(_SQL_COUNT_SHOPPINGCOUPON);
1353
1354 count = (Long)q.uniqueResult();
1355 }
1356 catch (Exception e) {
1357 throw processException(e);
1358 }
1359 finally {
1360 if (count == null) {
1361 count = Long.valueOf(0);
1362 }
1363
1364 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1365 FINDER_ARGS_EMPTY, count);
1366
1367 closeSession(session);
1368 }
1369 }
1370
1371 return count.intValue();
1372 }
1373
1374
1377 public void afterPropertiesSet() {
1378 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1379 com.liferay.portal.util.PropsUtil.get(
1380 "value.object.listener.com.liferay.portlet.shopping.model.ShoppingCoupon")));
1381
1382 if (listenerClassNames.length > 0) {
1383 try {
1384 List<ModelListener<ShoppingCoupon>> listenersList = new ArrayList<ModelListener<ShoppingCoupon>>();
1385
1386 for (String listenerClassName : listenerClassNames) {
1387 Class<?> clazz = getClass();
1388
1389 listenersList.add((ModelListener<ShoppingCoupon>)InstanceFactory.newInstance(
1390 clazz.getClassLoader(), listenerClassName));
1391 }
1392
1393 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1394 }
1395 catch (Exception e) {
1396 _log.error(e);
1397 }
1398 }
1399 }
1400
1401 public void destroy() {
1402 EntityCacheUtil.removeCache(ShoppingCouponImpl.class.getName());
1403 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1404 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1405 }
1406
1407 @BeanReference(type = ShoppingCartPersistence.class)
1408 protected ShoppingCartPersistence shoppingCartPersistence;
1409 @BeanReference(type = ShoppingCategoryPersistence.class)
1410 protected ShoppingCategoryPersistence shoppingCategoryPersistence;
1411 @BeanReference(type = ShoppingCouponPersistence.class)
1412 protected ShoppingCouponPersistence shoppingCouponPersistence;
1413 @BeanReference(type = ShoppingItemPersistence.class)
1414 protected ShoppingItemPersistence shoppingItemPersistence;
1415 @BeanReference(type = ShoppingItemFieldPersistence.class)
1416 protected ShoppingItemFieldPersistence shoppingItemFieldPersistence;
1417 @BeanReference(type = ShoppingItemPricePersistence.class)
1418 protected ShoppingItemPricePersistence shoppingItemPricePersistence;
1419 @BeanReference(type = ShoppingOrderPersistence.class)
1420 protected ShoppingOrderPersistence shoppingOrderPersistence;
1421 @BeanReference(type = ShoppingOrderItemPersistence.class)
1422 protected ShoppingOrderItemPersistence shoppingOrderItemPersistence;
1423 @BeanReference(type = ResourcePersistence.class)
1424 protected ResourcePersistence resourcePersistence;
1425 @BeanReference(type = UserPersistence.class)
1426 protected UserPersistence userPersistence;
1427 private static final String _SQL_SELECT_SHOPPINGCOUPON = "SELECT shoppingCoupon FROM ShoppingCoupon shoppingCoupon";
1428 private static final String _SQL_SELECT_SHOPPINGCOUPON_WHERE = "SELECT shoppingCoupon FROM ShoppingCoupon shoppingCoupon WHERE ";
1429 private static final String _SQL_COUNT_SHOPPINGCOUPON = "SELECT COUNT(shoppingCoupon) FROM ShoppingCoupon shoppingCoupon";
1430 private static final String _SQL_COUNT_SHOPPINGCOUPON_WHERE = "SELECT COUNT(shoppingCoupon) FROM ShoppingCoupon shoppingCoupon WHERE ";
1431 private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "shoppingCoupon.groupId = ?";
1432 private static final String _FINDER_COLUMN_CODE_CODE_1 = "shoppingCoupon.code IS NULL";
1433 private static final String _FINDER_COLUMN_CODE_CODE_2 = "shoppingCoupon.code = ?";
1434 private static final String _FINDER_COLUMN_CODE_CODE_3 = "(shoppingCoupon.code IS NULL OR shoppingCoupon.code = ?)";
1435 private static final String _ORDER_BY_ENTITY_ALIAS = "shoppingCoupon.";
1436 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ShoppingCoupon exists with the primary key ";
1437 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ShoppingCoupon exists with the key {";
1438 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1439 private static Log _log = LogFactoryUtil.getLog(ShoppingCouponPersistenceImpl.class);
1440 private static ShoppingCoupon _nullShoppingCoupon = new ShoppingCouponImpl() {
1441 @Override
1442 public Object clone() {
1443 return this;
1444 }
1445
1446 @Override
1447 public CacheModel<ShoppingCoupon> toCacheModel() {
1448 return _nullShoppingCouponCacheModel;
1449 }
1450 };
1451
1452 private static CacheModel<ShoppingCoupon> _nullShoppingCouponCacheModel = new CacheModel<ShoppingCoupon>() {
1453 public ShoppingCoupon toEntityModel() {
1454 return _nullShoppingCoupon;
1455 }
1456 };
1457 }