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