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 @Override
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 @Override
134 public List<ShoppingItemPrice> findByItemId(long itemId, int start, int end)
135 throws SystemException {
136 return findByItemId(itemId, start, end, null);
137 }
138
139
153 @Override
154 public List<ShoppingItemPrice> findByItemId(long itemId, int start,
155 int end, OrderByComparator orderByComparator) throws SystemException {
156 boolean pagination = true;
157 FinderPath finderPath = null;
158 Object[] finderArgs = null;
159
160 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
161 (orderByComparator == null)) {
162 pagination = false;
163 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ITEMID;
164 finderArgs = new Object[] { itemId };
165 }
166 else {
167 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_ITEMID;
168 finderArgs = new Object[] { itemId, start, end, orderByComparator };
169 }
170
171 List<ShoppingItemPrice> list = (List<ShoppingItemPrice>)FinderCacheUtil.getResult(finderPath,
172 finderArgs, this);
173
174 if ((list != null) && !list.isEmpty()) {
175 for (ShoppingItemPrice shoppingItemPrice : list) {
176 if ((itemId != shoppingItemPrice.getItemId())) {
177 list = null;
178
179 break;
180 }
181 }
182 }
183
184 if (list == null) {
185 StringBundler query = null;
186
187 if (orderByComparator != null) {
188 query = new StringBundler(3 +
189 (orderByComparator.getOrderByFields().length * 3));
190 }
191 else {
192 query = new StringBundler(3);
193 }
194
195 query.append(_SQL_SELECT_SHOPPINGITEMPRICE_WHERE);
196
197 query.append(_FINDER_COLUMN_ITEMID_ITEMID_2);
198
199 if (orderByComparator != null) {
200 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
201 orderByComparator);
202 }
203 else
204 if (pagination) {
205 query.append(ShoppingItemPriceModelImpl.ORDER_BY_JPQL);
206 }
207
208 String sql = query.toString();
209
210 Session session = null;
211
212 try {
213 session = openSession();
214
215 Query q = session.createQuery(sql);
216
217 QueryPos qPos = QueryPos.getInstance(q);
218
219 qPos.add(itemId);
220
221 if (!pagination) {
222 list = (List<ShoppingItemPrice>)QueryUtil.list(q,
223 getDialect(), start, end, false);
224
225 Collections.sort(list);
226
227 list = new UnmodifiableList<ShoppingItemPrice>(list);
228 }
229 else {
230 list = (List<ShoppingItemPrice>)QueryUtil.list(q,
231 getDialect(), start, end);
232 }
233
234 cacheResult(list);
235
236 FinderCacheUtil.putResult(finderPath, finderArgs, list);
237 }
238 catch (Exception e) {
239 FinderCacheUtil.removeResult(finderPath, finderArgs);
240
241 throw processException(e);
242 }
243 finally {
244 closeSession(session);
245 }
246 }
247
248 return list;
249 }
250
251
260 @Override
261 public ShoppingItemPrice findByItemId_First(long itemId,
262 OrderByComparator orderByComparator)
263 throws NoSuchItemPriceException, SystemException {
264 ShoppingItemPrice shoppingItemPrice = fetchByItemId_First(itemId,
265 orderByComparator);
266
267 if (shoppingItemPrice != null) {
268 return shoppingItemPrice;
269 }
270
271 StringBundler msg = new StringBundler(4);
272
273 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
274
275 msg.append("itemId=");
276 msg.append(itemId);
277
278 msg.append(StringPool.CLOSE_CURLY_BRACE);
279
280 throw new NoSuchItemPriceException(msg.toString());
281 }
282
283
291 @Override
292 public ShoppingItemPrice fetchByItemId_First(long itemId,
293 OrderByComparator orderByComparator) throws SystemException {
294 List<ShoppingItemPrice> list = findByItemId(itemId, 0, 1,
295 orderByComparator);
296
297 if (!list.isEmpty()) {
298 return list.get(0);
299 }
300
301 return null;
302 }
303
304
313 @Override
314 public ShoppingItemPrice findByItemId_Last(long itemId,
315 OrderByComparator orderByComparator)
316 throws NoSuchItemPriceException, SystemException {
317 ShoppingItemPrice shoppingItemPrice = fetchByItemId_Last(itemId,
318 orderByComparator);
319
320 if (shoppingItemPrice != null) {
321 return shoppingItemPrice;
322 }
323
324 StringBundler msg = new StringBundler(4);
325
326 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
327
328 msg.append("itemId=");
329 msg.append(itemId);
330
331 msg.append(StringPool.CLOSE_CURLY_BRACE);
332
333 throw new NoSuchItemPriceException(msg.toString());
334 }
335
336
344 @Override
345 public ShoppingItemPrice fetchByItemId_Last(long itemId,
346 OrderByComparator orderByComparator) throws SystemException {
347 int count = countByItemId(itemId);
348
349 if (count == 0) {
350 return null;
351 }
352
353 List<ShoppingItemPrice> list = findByItemId(itemId, count - 1, count,
354 orderByComparator);
355
356 if (!list.isEmpty()) {
357 return list.get(0);
358 }
359
360 return null;
361 }
362
363
373 @Override
374 public ShoppingItemPrice[] findByItemId_PrevAndNext(long itemPriceId,
375 long itemId, OrderByComparator orderByComparator)
376 throws NoSuchItemPriceException, SystemException {
377 ShoppingItemPrice shoppingItemPrice = findByPrimaryKey(itemPriceId);
378
379 Session session = null;
380
381 try {
382 session = openSession();
383
384 ShoppingItemPrice[] array = new ShoppingItemPriceImpl[3];
385
386 array[0] = getByItemId_PrevAndNext(session, shoppingItemPrice,
387 itemId, orderByComparator, true);
388
389 array[1] = shoppingItemPrice;
390
391 array[2] = getByItemId_PrevAndNext(session, shoppingItemPrice,
392 itemId, orderByComparator, false);
393
394 return array;
395 }
396 catch (Exception e) {
397 throw processException(e);
398 }
399 finally {
400 closeSession(session);
401 }
402 }
403
404 protected ShoppingItemPrice getByItemId_PrevAndNext(Session session,
405 ShoppingItemPrice shoppingItemPrice, long itemId,
406 OrderByComparator orderByComparator, boolean previous) {
407 StringBundler query = null;
408
409 if (orderByComparator != null) {
410 query = new StringBundler(6 +
411 (orderByComparator.getOrderByFields().length * 6));
412 }
413 else {
414 query = new StringBundler(3);
415 }
416
417 query.append(_SQL_SELECT_SHOPPINGITEMPRICE_WHERE);
418
419 query.append(_FINDER_COLUMN_ITEMID_ITEMID_2);
420
421 if (orderByComparator != null) {
422 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
423
424 if (orderByConditionFields.length > 0) {
425 query.append(WHERE_AND);
426 }
427
428 for (int i = 0; i < orderByConditionFields.length; i++) {
429 query.append(_ORDER_BY_ENTITY_ALIAS);
430 query.append(orderByConditionFields[i]);
431
432 if ((i + 1) < orderByConditionFields.length) {
433 if (orderByComparator.isAscending() ^ previous) {
434 query.append(WHERE_GREATER_THAN_HAS_NEXT);
435 }
436 else {
437 query.append(WHERE_LESSER_THAN_HAS_NEXT);
438 }
439 }
440 else {
441 if (orderByComparator.isAscending() ^ previous) {
442 query.append(WHERE_GREATER_THAN);
443 }
444 else {
445 query.append(WHERE_LESSER_THAN);
446 }
447 }
448 }
449
450 query.append(ORDER_BY_CLAUSE);
451
452 String[] orderByFields = orderByComparator.getOrderByFields();
453
454 for (int i = 0; i < orderByFields.length; i++) {
455 query.append(_ORDER_BY_ENTITY_ALIAS);
456 query.append(orderByFields[i]);
457
458 if ((i + 1) < orderByFields.length) {
459 if (orderByComparator.isAscending() ^ previous) {
460 query.append(ORDER_BY_ASC_HAS_NEXT);
461 }
462 else {
463 query.append(ORDER_BY_DESC_HAS_NEXT);
464 }
465 }
466 else {
467 if (orderByComparator.isAscending() ^ previous) {
468 query.append(ORDER_BY_ASC);
469 }
470 else {
471 query.append(ORDER_BY_DESC);
472 }
473 }
474 }
475 }
476 else {
477 query.append(ShoppingItemPriceModelImpl.ORDER_BY_JPQL);
478 }
479
480 String sql = query.toString();
481
482 Query q = session.createQuery(sql);
483
484 q.setFirstResult(0);
485 q.setMaxResults(2);
486
487 QueryPos qPos = QueryPos.getInstance(q);
488
489 qPos.add(itemId);
490
491 if (orderByComparator != null) {
492 Object[] values = orderByComparator.getOrderByConditionValues(shoppingItemPrice);
493
494 for (Object value : values) {
495 qPos.add(value);
496 }
497 }
498
499 List<ShoppingItemPrice> list = q.list();
500
501 if (list.size() == 2) {
502 return list.get(1);
503 }
504 else {
505 return null;
506 }
507 }
508
509
515 @Override
516 public void removeByItemId(long itemId) throws SystemException {
517 for (ShoppingItemPrice shoppingItemPrice : findByItemId(itemId,
518 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
519 remove(shoppingItemPrice);
520 }
521 }
522
523
530 @Override
531 public int countByItemId(long itemId) throws SystemException {
532 FinderPath finderPath = FINDER_PATH_COUNT_BY_ITEMID;
533
534 Object[] finderArgs = new Object[] { itemId };
535
536 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
537 this);
538
539 if (count == null) {
540 StringBundler query = new StringBundler(2);
541
542 query.append(_SQL_COUNT_SHOPPINGITEMPRICE_WHERE);
543
544 query.append(_FINDER_COLUMN_ITEMID_ITEMID_2);
545
546 String sql = query.toString();
547
548 Session session = null;
549
550 try {
551 session = openSession();
552
553 Query q = session.createQuery(sql);
554
555 QueryPos qPos = QueryPos.getInstance(q);
556
557 qPos.add(itemId);
558
559 count = (Long)q.uniqueResult();
560
561 FinderCacheUtil.putResult(finderPath, finderArgs, count);
562 }
563 catch (Exception e) {
564 FinderCacheUtil.removeResult(finderPath, finderArgs);
565
566 throw processException(e);
567 }
568 finally {
569 closeSession(session);
570 }
571 }
572
573 return count.intValue();
574 }
575
576 private static final String _FINDER_COLUMN_ITEMID_ITEMID_2 = "shoppingItemPrice.itemId = ?";
577
578
583 @Override
584 public void cacheResult(ShoppingItemPrice shoppingItemPrice) {
585 EntityCacheUtil.putResult(ShoppingItemPriceModelImpl.ENTITY_CACHE_ENABLED,
586 ShoppingItemPriceImpl.class, shoppingItemPrice.getPrimaryKey(),
587 shoppingItemPrice);
588
589 shoppingItemPrice.resetOriginalValues();
590 }
591
592
597 @Override
598 public void cacheResult(List<ShoppingItemPrice> shoppingItemPrices) {
599 for (ShoppingItemPrice shoppingItemPrice : shoppingItemPrices) {
600 if (EntityCacheUtil.getResult(
601 ShoppingItemPriceModelImpl.ENTITY_CACHE_ENABLED,
602 ShoppingItemPriceImpl.class,
603 shoppingItemPrice.getPrimaryKey()) == null) {
604 cacheResult(shoppingItemPrice);
605 }
606 else {
607 shoppingItemPrice.resetOriginalValues();
608 }
609 }
610 }
611
612
619 @Override
620 public void clearCache() {
621 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
622 CacheRegistryUtil.clear(ShoppingItemPriceImpl.class.getName());
623 }
624
625 EntityCacheUtil.clearCache(ShoppingItemPriceImpl.class.getName());
626
627 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
628 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
629 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
630 }
631
632
639 @Override
640 public void clearCache(ShoppingItemPrice shoppingItemPrice) {
641 EntityCacheUtil.removeResult(ShoppingItemPriceModelImpl.ENTITY_CACHE_ENABLED,
642 ShoppingItemPriceImpl.class, shoppingItemPrice.getPrimaryKey());
643
644 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
645 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
646 }
647
648 @Override
649 public void clearCache(List<ShoppingItemPrice> shoppingItemPrices) {
650 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
651 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
652
653 for (ShoppingItemPrice shoppingItemPrice : shoppingItemPrices) {
654 EntityCacheUtil.removeResult(ShoppingItemPriceModelImpl.ENTITY_CACHE_ENABLED,
655 ShoppingItemPriceImpl.class, shoppingItemPrice.getPrimaryKey());
656 }
657 }
658
659
665 @Override
666 public ShoppingItemPrice create(long itemPriceId) {
667 ShoppingItemPrice shoppingItemPrice = new ShoppingItemPriceImpl();
668
669 shoppingItemPrice.setNew(true);
670 shoppingItemPrice.setPrimaryKey(itemPriceId);
671
672 return shoppingItemPrice;
673 }
674
675
683 @Override
684 public ShoppingItemPrice remove(long itemPriceId)
685 throws NoSuchItemPriceException, SystemException {
686 return remove((Serializable)itemPriceId);
687 }
688
689
697 @Override
698 public ShoppingItemPrice remove(Serializable primaryKey)
699 throws NoSuchItemPriceException, SystemException {
700 Session session = null;
701
702 try {
703 session = openSession();
704
705 ShoppingItemPrice shoppingItemPrice = (ShoppingItemPrice)session.get(ShoppingItemPriceImpl.class,
706 primaryKey);
707
708 if (shoppingItemPrice == null) {
709 if (_log.isWarnEnabled()) {
710 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
711 }
712
713 throw new NoSuchItemPriceException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
714 primaryKey);
715 }
716
717 return remove(shoppingItemPrice);
718 }
719 catch (NoSuchItemPriceException nsee) {
720 throw nsee;
721 }
722 catch (Exception e) {
723 throw processException(e);
724 }
725 finally {
726 closeSession(session);
727 }
728 }
729
730 @Override
731 protected ShoppingItemPrice removeImpl(ShoppingItemPrice shoppingItemPrice)
732 throws SystemException {
733 shoppingItemPrice = toUnwrappedModel(shoppingItemPrice);
734
735 Session session = null;
736
737 try {
738 session = openSession();
739
740 if (!session.contains(shoppingItemPrice)) {
741 shoppingItemPrice = (ShoppingItemPrice)session.get(ShoppingItemPriceImpl.class,
742 shoppingItemPrice.getPrimaryKeyObj());
743 }
744
745 if (shoppingItemPrice != null) {
746 session.delete(shoppingItemPrice);
747 }
748 }
749 catch (Exception e) {
750 throw processException(e);
751 }
752 finally {
753 closeSession(session);
754 }
755
756 if (shoppingItemPrice != null) {
757 clearCache(shoppingItemPrice);
758 }
759
760 return shoppingItemPrice;
761 }
762
763 @Override
764 public ShoppingItemPrice updateImpl(
765 com.liferay.portlet.shopping.model.ShoppingItemPrice shoppingItemPrice)
766 throws SystemException {
767 shoppingItemPrice = toUnwrappedModel(shoppingItemPrice);
768
769 boolean isNew = shoppingItemPrice.isNew();
770
771 ShoppingItemPriceModelImpl shoppingItemPriceModelImpl = (ShoppingItemPriceModelImpl)shoppingItemPrice;
772
773 Session session = null;
774
775 try {
776 session = openSession();
777
778 if (shoppingItemPrice.isNew()) {
779 session.save(shoppingItemPrice);
780
781 shoppingItemPrice.setNew(false);
782 }
783 else {
784 session.merge(shoppingItemPrice);
785 }
786 }
787 catch (Exception e) {
788 throw processException(e);
789 }
790 finally {
791 closeSession(session);
792 }
793
794 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
795
796 if (isNew || !ShoppingItemPriceModelImpl.COLUMN_BITMASK_ENABLED) {
797 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
798 }
799
800 else {
801 if ((shoppingItemPriceModelImpl.getColumnBitmask() &
802 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ITEMID.getColumnBitmask()) != 0) {
803 Object[] args = new Object[] {
804 shoppingItemPriceModelImpl.getOriginalItemId()
805 };
806
807 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ITEMID, args);
808 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ITEMID,
809 args);
810
811 args = new Object[] { shoppingItemPriceModelImpl.getItemId() };
812
813 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ITEMID, args);
814 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ITEMID,
815 args);
816 }
817 }
818
819 EntityCacheUtil.putResult(ShoppingItemPriceModelImpl.ENTITY_CACHE_ENABLED,
820 ShoppingItemPriceImpl.class, shoppingItemPrice.getPrimaryKey(),
821 shoppingItemPrice);
822
823 return shoppingItemPrice;
824 }
825
826 protected ShoppingItemPrice toUnwrappedModel(
827 ShoppingItemPrice shoppingItemPrice) {
828 if (shoppingItemPrice instanceof ShoppingItemPriceImpl) {
829 return shoppingItemPrice;
830 }
831
832 ShoppingItemPriceImpl shoppingItemPriceImpl = new ShoppingItemPriceImpl();
833
834 shoppingItemPriceImpl.setNew(shoppingItemPrice.isNew());
835 shoppingItemPriceImpl.setPrimaryKey(shoppingItemPrice.getPrimaryKey());
836
837 shoppingItemPriceImpl.setItemPriceId(shoppingItemPrice.getItemPriceId());
838 shoppingItemPriceImpl.setItemId(shoppingItemPrice.getItemId());
839 shoppingItemPriceImpl.setMinQuantity(shoppingItemPrice.getMinQuantity());
840 shoppingItemPriceImpl.setMaxQuantity(shoppingItemPrice.getMaxQuantity());
841 shoppingItemPriceImpl.setPrice(shoppingItemPrice.getPrice());
842 shoppingItemPriceImpl.setDiscount(shoppingItemPrice.getDiscount());
843 shoppingItemPriceImpl.setTaxable(shoppingItemPrice.isTaxable());
844 shoppingItemPriceImpl.setShipping(shoppingItemPrice.getShipping());
845 shoppingItemPriceImpl.setUseShippingFormula(shoppingItemPrice.isUseShippingFormula());
846 shoppingItemPriceImpl.setStatus(shoppingItemPrice.getStatus());
847
848 return shoppingItemPriceImpl;
849 }
850
851
859 @Override
860 public ShoppingItemPrice findByPrimaryKey(Serializable primaryKey)
861 throws NoSuchItemPriceException, SystemException {
862 ShoppingItemPrice shoppingItemPrice = fetchByPrimaryKey(primaryKey);
863
864 if (shoppingItemPrice == null) {
865 if (_log.isWarnEnabled()) {
866 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
867 }
868
869 throw new NoSuchItemPriceException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
870 primaryKey);
871 }
872
873 return shoppingItemPrice;
874 }
875
876
884 @Override
885 public ShoppingItemPrice findByPrimaryKey(long itemPriceId)
886 throws NoSuchItemPriceException, SystemException {
887 return findByPrimaryKey((Serializable)itemPriceId);
888 }
889
890
897 @Override
898 public ShoppingItemPrice fetchByPrimaryKey(Serializable primaryKey)
899 throws SystemException {
900 ShoppingItemPrice shoppingItemPrice = (ShoppingItemPrice)EntityCacheUtil.getResult(ShoppingItemPriceModelImpl.ENTITY_CACHE_ENABLED,
901 ShoppingItemPriceImpl.class, primaryKey);
902
903 if (shoppingItemPrice == _nullShoppingItemPrice) {
904 return null;
905 }
906
907 if (shoppingItemPrice == null) {
908 Session session = null;
909
910 try {
911 session = openSession();
912
913 shoppingItemPrice = (ShoppingItemPrice)session.get(ShoppingItemPriceImpl.class,
914 primaryKey);
915
916 if (shoppingItemPrice != null) {
917 cacheResult(shoppingItemPrice);
918 }
919 else {
920 EntityCacheUtil.putResult(ShoppingItemPriceModelImpl.ENTITY_CACHE_ENABLED,
921 ShoppingItemPriceImpl.class, primaryKey,
922 _nullShoppingItemPrice);
923 }
924 }
925 catch (Exception e) {
926 EntityCacheUtil.removeResult(ShoppingItemPriceModelImpl.ENTITY_CACHE_ENABLED,
927 ShoppingItemPriceImpl.class, primaryKey);
928
929 throw processException(e);
930 }
931 finally {
932 closeSession(session);
933 }
934 }
935
936 return shoppingItemPrice;
937 }
938
939
946 @Override
947 public ShoppingItemPrice fetchByPrimaryKey(long itemPriceId)
948 throws SystemException {
949 return fetchByPrimaryKey((Serializable)itemPriceId);
950 }
951
952
958 @Override
959 public List<ShoppingItemPrice> findAll() throws SystemException {
960 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
961 }
962
963
975 @Override
976 public List<ShoppingItemPrice> findAll(int start, int end)
977 throws SystemException {
978 return findAll(start, end, null);
979 }
980
981
994 @Override
995 public List<ShoppingItemPrice> findAll(int start, int end,
996 OrderByComparator orderByComparator) throws SystemException {
997 boolean pagination = true;
998 FinderPath finderPath = null;
999 Object[] finderArgs = null;
1000
1001 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1002 (orderByComparator == null)) {
1003 pagination = false;
1004 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1005 finderArgs = FINDER_ARGS_EMPTY;
1006 }
1007 else {
1008 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1009 finderArgs = new Object[] { start, end, orderByComparator };
1010 }
1011
1012 List<ShoppingItemPrice> list = (List<ShoppingItemPrice>)FinderCacheUtil.getResult(finderPath,
1013 finderArgs, this);
1014
1015 if (list == null) {
1016 StringBundler query = null;
1017 String sql = null;
1018
1019 if (orderByComparator != null) {
1020 query = new StringBundler(2 +
1021 (orderByComparator.getOrderByFields().length * 3));
1022
1023 query.append(_SQL_SELECT_SHOPPINGITEMPRICE);
1024
1025 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1026 orderByComparator);
1027
1028 sql = query.toString();
1029 }
1030 else {
1031 sql = _SQL_SELECT_SHOPPINGITEMPRICE;
1032
1033 if (pagination) {
1034 sql = sql.concat(ShoppingItemPriceModelImpl.ORDER_BY_JPQL);
1035 }
1036 }
1037
1038 Session session = null;
1039
1040 try {
1041 session = openSession();
1042
1043 Query q = session.createQuery(sql);
1044
1045 if (!pagination) {
1046 list = (List<ShoppingItemPrice>)QueryUtil.list(q,
1047 getDialect(), start, end, false);
1048
1049 Collections.sort(list);
1050
1051 list = new UnmodifiableList<ShoppingItemPrice>(list);
1052 }
1053 else {
1054 list = (List<ShoppingItemPrice>)QueryUtil.list(q,
1055 getDialect(), start, end);
1056 }
1057
1058 cacheResult(list);
1059
1060 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1061 }
1062 catch (Exception e) {
1063 FinderCacheUtil.removeResult(finderPath, finderArgs);
1064
1065 throw processException(e);
1066 }
1067 finally {
1068 closeSession(session);
1069 }
1070 }
1071
1072 return list;
1073 }
1074
1075
1080 @Override
1081 public void removeAll() throws SystemException {
1082 for (ShoppingItemPrice shoppingItemPrice : findAll()) {
1083 remove(shoppingItemPrice);
1084 }
1085 }
1086
1087
1093 @Override
1094 public int countAll() throws SystemException {
1095 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1096 FINDER_ARGS_EMPTY, this);
1097
1098 if (count == null) {
1099 Session session = null;
1100
1101 try {
1102 session = openSession();
1103
1104 Query q = session.createQuery(_SQL_COUNT_SHOPPINGITEMPRICE);
1105
1106 count = (Long)q.uniqueResult();
1107
1108 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1109 FINDER_ARGS_EMPTY, count);
1110 }
1111 catch (Exception e) {
1112 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
1113 FINDER_ARGS_EMPTY);
1114
1115 throw processException(e);
1116 }
1117 finally {
1118 closeSession(session);
1119 }
1120 }
1121
1122 return count.intValue();
1123 }
1124
1125
1128 public void afterPropertiesSet() {
1129 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1130 com.liferay.portal.util.PropsUtil.get(
1131 "value.object.listener.com.liferay.portlet.shopping.model.ShoppingItemPrice")));
1132
1133 if (listenerClassNames.length > 0) {
1134 try {
1135 List<ModelListener<ShoppingItemPrice>> listenersList = new ArrayList<ModelListener<ShoppingItemPrice>>();
1136
1137 for (String listenerClassName : listenerClassNames) {
1138 listenersList.add((ModelListener<ShoppingItemPrice>)InstanceFactory.newInstance(
1139 getClassLoader(), listenerClassName));
1140 }
1141
1142 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1143 }
1144 catch (Exception e) {
1145 _log.error(e);
1146 }
1147 }
1148 }
1149
1150 public void destroy() {
1151 EntityCacheUtil.removeCache(ShoppingItemPriceImpl.class.getName());
1152 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1153 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1154 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1155 }
1156
1157 private static final String _SQL_SELECT_SHOPPINGITEMPRICE = "SELECT shoppingItemPrice FROM ShoppingItemPrice shoppingItemPrice";
1158 private static final String _SQL_SELECT_SHOPPINGITEMPRICE_WHERE = "SELECT shoppingItemPrice FROM ShoppingItemPrice shoppingItemPrice WHERE ";
1159 private static final String _SQL_COUNT_SHOPPINGITEMPRICE = "SELECT COUNT(shoppingItemPrice) FROM ShoppingItemPrice shoppingItemPrice";
1160 private static final String _SQL_COUNT_SHOPPINGITEMPRICE_WHERE = "SELECT COUNT(shoppingItemPrice) FROM ShoppingItemPrice shoppingItemPrice WHERE ";
1161 private static final String _ORDER_BY_ENTITY_ALIAS = "shoppingItemPrice.";
1162 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ShoppingItemPrice exists with the primary key ";
1163 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ShoppingItemPrice exists with the key {";
1164 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1165 private static Log _log = LogFactoryUtil.getLog(ShoppingItemPricePersistenceImpl.class);
1166 private static ShoppingItemPrice _nullShoppingItemPrice = new ShoppingItemPriceImpl() {
1167 @Override
1168 public Object clone() {
1169 return this;
1170 }
1171
1172 @Override
1173 public CacheModel<ShoppingItemPrice> toCacheModel() {
1174 return _nullShoppingItemPriceCacheModel;
1175 }
1176 };
1177
1178 private static CacheModel<ShoppingItemPrice> _nullShoppingItemPriceCacheModel =
1179 new CacheModel<ShoppingItemPrice>() {
1180 @Override
1181 public ShoppingItemPrice toEntityModel() {
1182 return _nullShoppingItemPrice;
1183 }
1184 };
1185 }