001
014
015 package com.liferay.portlet.shopping.service.persistence;
016
017 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
018 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
019 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
020 import com.liferay.portal.kernel.dao.orm.FinderPath;
021 import com.liferay.portal.kernel.dao.orm.Query;
022 import com.liferay.portal.kernel.dao.orm.QueryPos;
023 import com.liferay.portal.kernel.dao.orm.QueryUtil;
024 import com.liferay.portal.kernel.dao.orm.Session;
025 import com.liferay.portal.kernel.exception.SystemException;
026 import com.liferay.portal.kernel.log.Log;
027 import com.liferay.portal.kernel.log.LogFactoryUtil;
028 import com.liferay.portal.kernel.util.GetterUtil;
029 import com.liferay.portal.kernel.util.InstanceFactory;
030 import com.liferay.portal.kernel.util.OrderByComparator;
031 import com.liferay.portal.kernel.util.StringBundler;
032 import com.liferay.portal.kernel.util.StringPool;
033 import com.liferay.portal.kernel.util.StringUtil;
034 import com.liferay.portal.kernel.util.UnmodifiableList;
035 import com.liferay.portal.model.CacheModel;
036 import com.liferay.portal.model.ModelListener;
037 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
038
039 import com.liferay.portlet.shopping.NoSuchItemPriceException;
040 import com.liferay.portlet.shopping.model.ShoppingItemPrice;
041 import com.liferay.portlet.shopping.model.impl.ShoppingItemPriceImpl;
042 import com.liferay.portlet.shopping.model.impl.ShoppingItemPriceModelImpl;
043
044 import java.io.Serializable;
045
046 import java.util.ArrayList;
047 import java.util.Collections;
048 import java.util.List;
049
050
062 public class ShoppingItemPricePersistenceImpl extends BasePersistenceImpl<ShoppingItemPrice>
063 implements ShoppingItemPricePersistence {
064
069 public static final String FINDER_CLASS_NAME_ENTITY = ShoppingItemPriceImpl.class.getName();
070 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
071 ".List1";
072 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
073 ".List2";
074 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(ShoppingItemPriceModelImpl.ENTITY_CACHE_ENABLED,
075 ShoppingItemPriceModelImpl.FINDER_CACHE_ENABLED,
076 ShoppingItemPriceImpl.class,
077 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
078 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(ShoppingItemPriceModelImpl.ENTITY_CACHE_ENABLED,
079 ShoppingItemPriceModelImpl.FINDER_CACHE_ENABLED,
080 ShoppingItemPriceImpl.class,
081 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
082 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ShoppingItemPriceModelImpl.ENTITY_CACHE_ENABLED,
083 ShoppingItemPriceModelImpl.FINDER_CACHE_ENABLED, Long.class,
084 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
085 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_ITEMID = new FinderPath(ShoppingItemPriceModelImpl.ENTITY_CACHE_ENABLED,
086 ShoppingItemPriceModelImpl.FINDER_CACHE_ENABLED,
087 ShoppingItemPriceImpl.class,
088 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByItemId",
089 new String[] {
090 Long.class.getName(),
091
092 Integer.class.getName(), Integer.class.getName(),
093 OrderByComparator.class.getName()
094 });
095 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ITEMID =
096 new FinderPath(ShoppingItemPriceModelImpl.ENTITY_CACHE_ENABLED,
097 ShoppingItemPriceModelImpl.FINDER_CACHE_ENABLED,
098 ShoppingItemPriceImpl.class,
099 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByItemId",
100 new String[] { Long.class.getName() },
101 ShoppingItemPriceModelImpl.ITEMID_COLUMN_BITMASK);
102 public static final FinderPath FINDER_PATH_COUNT_BY_ITEMID = new FinderPath(ShoppingItemPriceModelImpl.ENTITY_CACHE_ENABLED,
103 ShoppingItemPriceModelImpl.FINDER_CACHE_ENABLED, Long.class,
104 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByItemId",
105 new String[] { Long.class.getName() });
106
107
114 public List<ShoppingItemPrice> findByItemId(long itemId)
115 throws SystemException {
116 return findByItemId(itemId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
117 }
118
119
132 public List<ShoppingItemPrice> findByItemId(long itemId, int start, int end)
133 throws SystemException {
134 return findByItemId(itemId, start, end, null);
135 }
136
137
151 public List<ShoppingItemPrice> findByItemId(long itemId, int start,
152 int end, OrderByComparator orderByComparator) throws SystemException {
153 boolean pagination = true;
154 FinderPath finderPath = null;
155 Object[] finderArgs = null;
156
157 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
158 (orderByComparator == null)) {
159 pagination = false;
160 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ITEMID;
161 finderArgs = new Object[] { itemId };
162 }
163 else {
164 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_ITEMID;
165 finderArgs = new Object[] { itemId, start, end, orderByComparator };
166 }
167
168 List<ShoppingItemPrice> list = (List<ShoppingItemPrice>)FinderCacheUtil.getResult(finderPath,
169 finderArgs, this);
170
171 if ((list != null) && !list.isEmpty()) {
172 for (ShoppingItemPrice shoppingItemPrice : list) {
173 if ((itemId != shoppingItemPrice.getItemId())) {
174 list = null;
175
176 break;
177 }
178 }
179 }
180
181 if (list == null) {
182 StringBundler query = null;
183
184 if (orderByComparator != null) {
185 query = new StringBundler(3 +
186 (orderByComparator.getOrderByFields().length * 3));
187 }
188 else {
189 query = new StringBundler(3);
190 }
191
192 query.append(_SQL_SELECT_SHOPPINGITEMPRICE_WHERE);
193
194 query.append(_FINDER_COLUMN_ITEMID_ITEMID_2);
195
196 if (orderByComparator != null) {
197 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
198 orderByComparator);
199 }
200 else
201 if (pagination) {
202 query.append(ShoppingItemPriceModelImpl.ORDER_BY_JPQL);
203 }
204
205 String sql = query.toString();
206
207 Session session = null;
208
209 try {
210 session = openSession();
211
212 Query q = session.createQuery(sql);
213
214 QueryPos qPos = QueryPos.getInstance(q);
215
216 qPos.add(itemId);
217
218 if (!pagination) {
219 list = (List<ShoppingItemPrice>)QueryUtil.list(q,
220 getDialect(), start, end, false);
221
222 Collections.sort(list);
223
224 list = new UnmodifiableList<ShoppingItemPrice>(list);
225 }
226 else {
227 list = (List<ShoppingItemPrice>)QueryUtil.list(q,
228 getDialect(), start, end);
229 }
230
231 cacheResult(list);
232
233 FinderCacheUtil.putResult(finderPath, finderArgs, list);
234 }
235 catch (Exception e) {
236 FinderCacheUtil.removeResult(finderPath, finderArgs);
237
238 throw processException(e);
239 }
240 finally {
241 closeSession(session);
242 }
243 }
244
245 return list;
246 }
247
248
257 public ShoppingItemPrice findByItemId_First(long itemId,
258 OrderByComparator orderByComparator)
259 throws NoSuchItemPriceException, SystemException {
260 ShoppingItemPrice shoppingItemPrice = fetchByItemId_First(itemId,
261 orderByComparator);
262
263 if (shoppingItemPrice != null) {
264 return shoppingItemPrice;
265 }
266
267 StringBundler msg = new StringBundler(4);
268
269 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
270
271 msg.append("itemId=");
272 msg.append(itemId);
273
274 msg.append(StringPool.CLOSE_CURLY_BRACE);
275
276 throw new NoSuchItemPriceException(msg.toString());
277 }
278
279
287 public ShoppingItemPrice fetchByItemId_First(long itemId,
288 OrderByComparator orderByComparator) throws SystemException {
289 List<ShoppingItemPrice> list = findByItemId(itemId, 0, 1,
290 orderByComparator);
291
292 if (!list.isEmpty()) {
293 return list.get(0);
294 }
295
296 return null;
297 }
298
299
308 public ShoppingItemPrice findByItemId_Last(long itemId,
309 OrderByComparator orderByComparator)
310 throws NoSuchItemPriceException, SystemException {
311 ShoppingItemPrice shoppingItemPrice = fetchByItemId_Last(itemId,
312 orderByComparator);
313
314 if (shoppingItemPrice != null) {
315 return shoppingItemPrice;
316 }
317
318 StringBundler msg = new StringBundler(4);
319
320 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
321
322 msg.append("itemId=");
323 msg.append(itemId);
324
325 msg.append(StringPool.CLOSE_CURLY_BRACE);
326
327 throw new NoSuchItemPriceException(msg.toString());
328 }
329
330
338 public ShoppingItemPrice fetchByItemId_Last(long itemId,
339 OrderByComparator orderByComparator) throws SystemException {
340 int count = countByItemId(itemId);
341
342 List<ShoppingItemPrice> list = findByItemId(itemId, count - 1, count,
343 orderByComparator);
344
345 if (!list.isEmpty()) {
346 return list.get(0);
347 }
348
349 return null;
350 }
351
352
362 public ShoppingItemPrice[] findByItemId_PrevAndNext(long itemPriceId,
363 long itemId, OrderByComparator orderByComparator)
364 throws NoSuchItemPriceException, SystemException {
365 ShoppingItemPrice shoppingItemPrice = findByPrimaryKey(itemPriceId);
366
367 Session session = null;
368
369 try {
370 session = openSession();
371
372 ShoppingItemPrice[] array = new ShoppingItemPriceImpl[3];
373
374 array[0] = getByItemId_PrevAndNext(session, shoppingItemPrice,
375 itemId, orderByComparator, true);
376
377 array[1] = shoppingItemPrice;
378
379 array[2] = getByItemId_PrevAndNext(session, shoppingItemPrice,
380 itemId, orderByComparator, false);
381
382 return array;
383 }
384 catch (Exception e) {
385 throw processException(e);
386 }
387 finally {
388 closeSession(session);
389 }
390 }
391
392 protected ShoppingItemPrice getByItemId_PrevAndNext(Session session,
393 ShoppingItemPrice shoppingItemPrice, long itemId,
394 OrderByComparator orderByComparator, boolean previous) {
395 StringBundler query = null;
396
397 if (orderByComparator != null) {
398 query = new StringBundler(6 +
399 (orderByComparator.getOrderByFields().length * 6));
400 }
401 else {
402 query = new StringBundler(3);
403 }
404
405 query.append(_SQL_SELECT_SHOPPINGITEMPRICE_WHERE);
406
407 query.append(_FINDER_COLUMN_ITEMID_ITEMID_2);
408
409 if (orderByComparator != null) {
410 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
411
412 if (orderByConditionFields.length > 0) {
413 query.append(WHERE_AND);
414 }
415
416 for (int i = 0; i < orderByConditionFields.length; i++) {
417 query.append(_ORDER_BY_ENTITY_ALIAS);
418 query.append(orderByConditionFields[i]);
419
420 if ((i + 1) < orderByConditionFields.length) {
421 if (orderByComparator.isAscending() ^ previous) {
422 query.append(WHERE_GREATER_THAN_HAS_NEXT);
423 }
424 else {
425 query.append(WHERE_LESSER_THAN_HAS_NEXT);
426 }
427 }
428 else {
429 if (orderByComparator.isAscending() ^ previous) {
430 query.append(WHERE_GREATER_THAN);
431 }
432 else {
433 query.append(WHERE_LESSER_THAN);
434 }
435 }
436 }
437
438 query.append(ORDER_BY_CLAUSE);
439
440 String[] orderByFields = orderByComparator.getOrderByFields();
441
442 for (int i = 0; i < orderByFields.length; i++) {
443 query.append(_ORDER_BY_ENTITY_ALIAS);
444 query.append(orderByFields[i]);
445
446 if ((i + 1) < orderByFields.length) {
447 if (orderByComparator.isAscending() ^ previous) {
448 query.append(ORDER_BY_ASC_HAS_NEXT);
449 }
450 else {
451 query.append(ORDER_BY_DESC_HAS_NEXT);
452 }
453 }
454 else {
455 if (orderByComparator.isAscending() ^ previous) {
456 query.append(ORDER_BY_ASC);
457 }
458 else {
459 query.append(ORDER_BY_DESC);
460 }
461 }
462 }
463 }
464 else {
465 query.append(ShoppingItemPriceModelImpl.ORDER_BY_JPQL);
466 }
467
468 String sql = query.toString();
469
470 Query q = session.createQuery(sql);
471
472 q.setFirstResult(0);
473 q.setMaxResults(2);
474
475 QueryPos qPos = QueryPos.getInstance(q);
476
477 qPos.add(itemId);
478
479 if (orderByComparator != null) {
480 Object[] values = orderByComparator.getOrderByConditionValues(shoppingItemPrice);
481
482 for (Object value : values) {
483 qPos.add(value);
484 }
485 }
486
487 List<ShoppingItemPrice> list = q.list();
488
489 if (list.size() == 2) {
490 return list.get(1);
491 }
492 else {
493 return null;
494 }
495 }
496
497
503 public void removeByItemId(long itemId) throws SystemException {
504 for (ShoppingItemPrice shoppingItemPrice : findByItemId(itemId,
505 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
506 remove(shoppingItemPrice);
507 }
508 }
509
510
517 public int countByItemId(long itemId) throws SystemException {
518 FinderPath finderPath = FINDER_PATH_COUNT_BY_ITEMID;
519
520 Object[] finderArgs = new Object[] { itemId };
521
522 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
523 this);
524
525 if (count == null) {
526 StringBundler query = new StringBundler(2);
527
528 query.append(_SQL_COUNT_SHOPPINGITEMPRICE_WHERE);
529
530 query.append(_FINDER_COLUMN_ITEMID_ITEMID_2);
531
532 String sql = query.toString();
533
534 Session session = null;
535
536 try {
537 session = openSession();
538
539 Query q = session.createQuery(sql);
540
541 QueryPos qPos = QueryPos.getInstance(q);
542
543 qPos.add(itemId);
544
545 count = (Long)q.uniqueResult();
546
547 FinderCacheUtil.putResult(finderPath, finderArgs, count);
548 }
549 catch (Exception e) {
550 FinderCacheUtil.removeResult(finderPath, finderArgs);
551
552 throw processException(e);
553 }
554 finally {
555 closeSession(session);
556 }
557 }
558
559 return count.intValue();
560 }
561
562 private static final String _FINDER_COLUMN_ITEMID_ITEMID_2 = "shoppingItemPrice.itemId = ?";
563
564
569 public void cacheResult(ShoppingItemPrice shoppingItemPrice) {
570 EntityCacheUtil.putResult(ShoppingItemPriceModelImpl.ENTITY_CACHE_ENABLED,
571 ShoppingItemPriceImpl.class, shoppingItemPrice.getPrimaryKey(),
572 shoppingItemPrice);
573
574 shoppingItemPrice.resetOriginalValues();
575 }
576
577
582 public void cacheResult(List<ShoppingItemPrice> shoppingItemPrices) {
583 for (ShoppingItemPrice shoppingItemPrice : shoppingItemPrices) {
584 if (EntityCacheUtil.getResult(
585 ShoppingItemPriceModelImpl.ENTITY_CACHE_ENABLED,
586 ShoppingItemPriceImpl.class,
587 shoppingItemPrice.getPrimaryKey()) == null) {
588 cacheResult(shoppingItemPrice);
589 }
590 else {
591 shoppingItemPrice.resetOriginalValues();
592 }
593 }
594 }
595
596
603 @Override
604 public void clearCache() {
605 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
606 CacheRegistryUtil.clear(ShoppingItemPriceImpl.class.getName());
607 }
608
609 EntityCacheUtil.clearCache(ShoppingItemPriceImpl.class.getName());
610
611 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
612 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
613 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
614 }
615
616
623 @Override
624 public void clearCache(ShoppingItemPrice shoppingItemPrice) {
625 EntityCacheUtil.removeResult(ShoppingItemPriceModelImpl.ENTITY_CACHE_ENABLED,
626 ShoppingItemPriceImpl.class, shoppingItemPrice.getPrimaryKey());
627
628 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
629 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
630 }
631
632 @Override
633 public void clearCache(List<ShoppingItemPrice> shoppingItemPrices) {
634 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
635 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
636
637 for (ShoppingItemPrice shoppingItemPrice : shoppingItemPrices) {
638 EntityCacheUtil.removeResult(ShoppingItemPriceModelImpl.ENTITY_CACHE_ENABLED,
639 ShoppingItemPriceImpl.class, shoppingItemPrice.getPrimaryKey());
640 }
641 }
642
643
649 public ShoppingItemPrice create(long itemPriceId) {
650 ShoppingItemPrice shoppingItemPrice = new ShoppingItemPriceImpl();
651
652 shoppingItemPrice.setNew(true);
653 shoppingItemPrice.setPrimaryKey(itemPriceId);
654
655 return shoppingItemPrice;
656 }
657
658
666 public ShoppingItemPrice remove(long itemPriceId)
667 throws NoSuchItemPriceException, SystemException {
668 return remove((Serializable)itemPriceId);
669 }
670
671
679 @Override
680 public ShoppingItemPrice remove(Serializable primaryKey)
681 throws NoSuchItemPriceException, SystemException {
682 Session session = null;
683
684 try {
685 session = openSession();
686
687 ShoppingItemPrice shoppingItemPrice = (ShoppingItemPrice)session.get(ShoppingItemPriceImpl.class,
688 primaryKey);
689
690 if (shoppingItemPrice == null) {
691 if (_log.isWarnEnabled()) {
692 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
693 }
694
695 throw new NoSuchItemPriceException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
696 primaryKey);
697 }
698
699 return remove(shoppingItemPrice);
700 }
701 catch (NoSuchItemPriceException nsee) {
702 throw nsee;
703 }
704 catch (Exception e) {
705 throw processException(e);
706 }
707 finally {
708 closeSession(session);
709 }
710 }
711
712 @Override
713 protected ShoppingItemPrice removeImpl(ShoppingItemPrice shoppingItemPrice)
714 throws SystemException {
715 shoppingItemPrice = toUnwrappedModel(shoppingItemPrice);
716
717 Session session = null;
718
719 try {
720 session = openSession();
721
722 if (!session.contains(shoppingItemPrice)) {
723 shoppingItemPrice = (ShoppingItemPrice)session.get(ShoppingItemPriceImpl.class,
724 shoppingItemPrice.getPrimaryKeyObj());
725 }
726
727 if (shoppingItemPrice != null) {
728 session.delete(shoppingItemPrice);
729 }
730 }
731 catch (Exception e) {
732 throw processException(e);
733 }
734 finally {
735 closeSession(session);
736 }
737
738 if (shoppingItemPrice != null) {
739 clearCache(shoppingItemPrice);
740 }
741
742 return shoppingItemPrice;
743 }
744
745 @Override
746 public ShoppingItemPrice updateImpl(
747 com.liferay.portlet.shopping.model.ShoppingItemPrice shoppingItemPrice)
748 throws SystemException {
749 shoppingItemPrice = toUnwrappedModel(shoppingItemPrice);
750
751 boolean isNew = shoppingItemPrice.isNew();
752
753 ShoppingItemPriceModelImpl shoppingItemPriceModelImpl = (ShoppingItemPriceModelImpl)shoppingItemPrice;
754
755 Session session = null;
756
757 try {
758 session = openSession();
759
760 if (shoppingItemPrice.isNew()) {
761 session.save(shoppingItemPrice);
762
763 shoppingItemPrice.setNew(false);
764 }
765 else {
766 session.merge(shoppingItemPrice);
767 }
768 }
769 catch (Exception e) {
770 throw processException(e);
771 }
772 finally {
773 closeSession(session);
774 }
775
776 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
777
778 if (isNew || !ShoppingItemPriceModelImpl.COLUMN_BITMASK_ENABLED) {
779 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
780 }
781
782 else {
783 if ((shoppingItemPriceModelImpl.getColumnBitmask() &
784 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ITEMID.getColumnBitmask()) != 0) {
785 Object[] args = new Object[] {
786 shoppingItemPriceModelImpl.getOriginalItemId()
787 };
788
789 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ITEMID, args);
790 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ITEMID,
791 args);
792
793 args = new Object[] { shoppingItemPriceModelImpl.getItemId() };
794
795 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ITEMID, args);
796 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ITEMID,
797 args);
798 }
799 }
800
801 EntityCacheUtil.putResult(ShoppingItemPriceModelImpl.ENTITY_CACHE_ENABLED,
802 ShoppingItemPriceImpl.class, shoppingItemPrice.getPrimaryKey(),
803 shoppingItemPrice);
804
805 return shoppingItemPrice;
806 }
807
808 protected ShoppingItemPrice toUnwrappedModel(
809 ShoppingItemPrice shoppingItemPrice) {
810 if (shoppingItemPrice instanceof ShoppingItemPriceImpl) {
811 return shoppingItemPrice;
812 }
813
814 ShoppingItemPriceImpl shoppingItemPriceImpl = new ShoppingItemPriceImpl();
815
816 shoppingItemPriceImpl.setNew(shoppingItemPrice.isNew());
817 shoppingItemPriceImpl.setPrimaryKey(shoppingItemPrice.getPrimaryKey());
818
819 shoppingItemPriceImpl.setItemPriceId(shoppingItemPrice.getItemPriceId());
820 shoppingItemPriceImpl.setItemId(shoppingItemPrice.getItemId());
821 shoppingItemPriceImpl.setMinQuantity(shoppingItemPrice.getMinQuantity());
822 shoppingItemPriceImpl.setMaxQuantity(shoppingItemPrice.getMaxQuantity());
823 shoppingItemPriceImpl.setPrice(shoppingItemPrice.getPrice());
824 shoppingItemPriceImpl.setDiscount(shoppingItemPrice.getDiscount());
825 shoppingItemPriceImpl.setTaxable(shoppingItemPrice.isTaxable());
826 shoppingItemPriceImpl.setShipping(shoppingItemPrice.getShipping());
827 shoppingItemPriceImpl.setUseShippingFormula(shoppingItemPrice.isUseShippingFormula());
828 shoppingItemPriceImpl.setStatus(shoppingItemPrice.getStatus());
829
830 return shoppingItemPriceImpl;
831 }
832
833
841 @Override
842 public ShoppingItemPrice findByPrimaryKey(Serializable primaryKey)
843 throws NoSuchItemPriceException, SystemException {
844 ShoppingItemPrice shoppingItemPrice = fetchByPrimaryKey(primaryKey);
845
846 if (shoppingItemPrice == null) {
847 if (_log.isWarnEnabled()) {
848 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
849 }
850
851 throw new NoSuchItemPriceException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
852 primaryKey);
853 }
854
855 return shoppingItemPrice;
856 }
857
858
866 public ShoppingItemPrice findByPrimaryKey(long itemPriceId)
867 throws NoSuchItemPriceException, SystemException {
868 return findByPrimaryKey((Serializable)itemPriceId);
869 }
870
871
878 @Override
879 public ShoppingItemPrice fetchByPrimaryKey(Serializable primaryKey)
880 throws SystemException {
881 ShoppingItemPrice shoppingItemPrice = (ShoppingItemPrice)EntityCacheUtil.getResult(ShoppingItemPriceModelImpl.ENTITY_CACHE_ENABLED,
882 ShoppingItemPriceImpl.class, primaryKey);
883
884 if (shoppingItemPrice == _nullShoppingItemPrice) {
885 return null;
886 }
887
888 if (shoppingItemPrice == null) {
889 Session session = null;
890
891 try {
892 session = openSession();
893
894 shoppingItemPrice = (ShoppingItemPrice)session.get(ShoppingItemPriceImpl.class,
895 primaryKey);
896
897 if (shoppingItemPrice != null) {
898 cacheResult(shoppingItemPrice);
899 }
900 else {
901 EntityCacheUtil.putResult(ShoppingItemPriceModelImpl.ENTITY_CACHE_ENABLED,
902 ShoppingItemPriceImpl.class, primaryKey,
903 _nullShoppingItemPrice);
904 }
905 }
906 catch (Exception e) {
907 EntityCacheUtil.removeResult(ShoppingItemPriceModelImpl.ENTITY_CACHE_ENABLED,
908 ShoppingItemPriceImpl.class, primaryKey);
909
910 throw processException(e);
911 }
912 finally {
913 closeSession(session);
914 }
915 }
916
917 return shoppingItemPrice;
918 }
919
920
927 public ShoppingItemPrice fetchByPrimaryKey(long itemPriceId)
928 throws SystemException {
929 return fetchByPrimaryKey((Serializable)itemPriceId);
930 }
931
932
938 public List<ShoppingItemPrice> findAll() throws SystemException {
939 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
940 }
941
942
954 public List<ShoppingItemPrice> findAll(int start, int end)
955 throws SystemException {
956 return findAll(start, end, null);
957 }
958
959
972 public List<ShoppingItemPrice> findAll(int start, int end,
973 OrderByComparator orderByComparator) throws SystemException {
974 boolean pagination = true;
975 FinderPath finderPath = null;
976 Object[] finderArgs = null;
977
978 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
979 (orderByComparator == null)) {
980 pagination = false;
981 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
982 finderArgs = FINDER_ARGS_EMPTY;
983 }
984 else {
985 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
986 finderArgs = new Object[] { start, end, orderByComparator };
987 }
988
989 List<ShoppingItemPrice> list = (List<ShoppingItemPrice>)FinderCacheUtil.getResult(finderPath,
990 finderArgs, this);
991
992 if (list == null) {
993 StringBundler query = null;
994 String sql = null;
995
996 if (orderByComparator != null) {
997 query = new StringBundler(2 +
998 (orderByComparator.getOrderByFields().length * 3));
999
1000 query.append(_SQL_SELECT_SHOPPINGITEMPRICE);
1001
1002 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1003 orderByComparator);
1004
1005 sql = query.toString();
1006 }
1007 else {
1008 sql = _SQL_SELECT_SHOPPINGITEMPRICE;
1009
1010 if (pagination) {
1011 sql = sql.concat(ShoppingItemPriceModelImpl.ORDER_BY_JPQL);
1012 }
1013 }
1014
1015 Session session = null;
1016
1017 try {
1018 session = openSession();
1019
1020 Query q = session.createQuery(sql);
1021
1022 if (!pagination) {
1023 list = (List<ShoppingItemPrice>)QueryUtil.list(q,
1024 getDialect(), start, end, false);
1025
1026 Collections.sort(list);
1027
1028 list = new UnmodifiableList<ShoppingItemPrice>(list);
1029 }
1030 else {
1031 list = (List<ShoppingItemPrice>)QueryUtil.list(q,
1032 getDialect(), start, end);
1033 }
1034
1035 cacheResult(list);
1036
1037 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1038 }
1039 catch (Exception e) {
1040 FinderCacheUtil.removeResult(finderPath, finderArgs);
1041
1042 throw processException(e);
1043 }
1044 finally {
1045 closeSession(session);
1046 }
1047 }
1048
1049 return list;
1050 }
1051
1052
1057 public void removeAll() throws SystemException {
1058 for (ShoppingItemPrice shoppingItemPrice : findAll()) {
1059 remove(shoppingItemPrice);
1060 }
1061 }
1062
1063
1069 public int countAll() throws SystemException {
1070 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1071 FINDER_ARGS_EMPTY, this);
1072
1073 if (count == null) {
1074 Session session = null;
1075
1076 try {
1077 session = openSession();
1078
1079 Query q = session.createQuery(_SQL_COUNT_SHOPPINGITEMPRICE);
1080
1081 count = (Long)q.uniqueResult();
1082
1083 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1084 FINDER_ARGS_EMPTY, count);
1085 }
1086 catch (Exception e) {
1087 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
1088 FINDER_ARGS_EMPTY);
1089
1090 throw processException(e);
1091 }
1092 finally {
1093 closeSession(session);
1094 }
1095 }
1096
1097 return count.intValue();
1098 }
1099
1100
1103 public void afterPropertiesSet() {
1104 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1105 com.liferay.portal.util.PropsUtil.get(
1106 "value.object.listener.com.liferay.portlet.shopping.model.ShoppingItemPrice")));
1107
1108 if (listenerClassNames.length > 0) {
1109 try {
1110 List<ModelListener<ShoppingItemPrice>> listenersList = new ArrayList<ModelListener<ShoppingItemPrice>>();
1111
1112 for (String listenerClassName : listenerClassNames) {
1113 listenersList.add((ModelListener<ShoppingItemPrice>)InstanceFactory.newInstance(
1114 getClassLoader(), listenerClassName));
1115 }
1116
1117 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1118 }
1119 catch (Exception e) {
1120 _log.error(e);
1121 }
1122 }
1123 }
1124
1125 public void destroy() {
1126 EntityCacheUtil.removeCache(ShoppingItemPriceImpl.class.getName());
1127 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1128 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1129 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1130 }
1131
1132 private static final String _SQL_SELECT_SHOPPINGITEMPRICE = "SELECT shoppingItemPrice FROM ShoppingItemPrice shoppingItemPrice";
1133 private static final String _SQL_SELECT_SHOPPINGITEMPRICE_WHERE = "SELECT shoppingItemPrice FROM ShoppingItemPrice shoppingItemPrice WHERE ";
1134 private static final String _SQL_COUNT_SHOPPINGITEMPRICE = "SELECT COUNT(shoppingItemPrice) FROM ShoppingItemPrice shoppingItemPrice";
1135 private static final String _SQL_COUNT_SHOPPINGITEMPRICE_WHERE = "SELECT COUNT(shoppingItemPrice) FROM ShoppingItemPrice shoppingItemPrice WHERE ";
1136 private static final String _ORDER_BY_ENTITY_ALIAS = "shoppingItemPrice.";
1137 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ShoppingItemPrice exists with the primary key ";
1138 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ShoppingItemPrice exists with the key {";
1139 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1140 private static Log _log = LogFactoryUtil.getLog(ShoppingItemPricePersistenceImpl.class);
1141 private static ShoppingItemPrice _nullShoppingItemPrice = new ShoppingItemPriceImpl() {
1142 @Override
1143 public Object clone() {
1144 return this;
1145 }
1146
1147 @Override
1148 public CacheModel<ShoppingItemPrice> toCacheModel() {
1149 return _nullShoppingItemPriceCacheModel;
1150 }
1151 };
1152
1153 private static CacheModel<ShoppingItemPrice> _nullShoppingItemPriceCacheModel =
1154 new CacheModel<ShoppingItemPrice>() {
1155 public ShoppingItemPrice toEntityModel() {
1156 return _nullShoppingItemPrice;
1157 }
1158 };
1159 }