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.model.CacheModel;
037 import com.liferay.portal.model.ModelListener;
038 import com.liferay.portal.service.persistence.BatchSessionUtil;
039 import com.liferay.portal.service.persistence.ResourcePersistence;
040 import com.liferay.portal.service.persistence.UserPersistence;
041 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
042
043 import com.liferay.portlet.shopping.NoSuchItemPriceException;
044 import com.liferay.portlet.shopping.model.ShoppingItemPrice;
045 import com.liferay.portlet.shopping.model.impl.ShoppingItemPriceImpl;
046 import com.liferay.portlet.shopping.model.impl.ShoppingItemPriceModelImpl;
047
048 import java.io.Serializable;
049
050 import java.util.ArrayList;
051 import java.util.Collections;
052 import java.util.List;
053
054
066 public class ShoppingItemPricePersistenceImpl extends BasePersistenceImpl<ShoppingItemPrice>
067 implements ShoppingItemPricePersistence {
068
073 public static final String FINDER_CLASS_NAME_ENTITY = ShoppingItemPriceImpl.class.getName();
074 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
075 ".List1";
076 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
077 ".List2";
078 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_ITEMID = new FinderPath(ShoppingItemPriceModelImpl.ENTITY_CACHE_ENABLED,
079 ShoppingItemPriceModelImpl.FINDER_CACHE_ENABLED,
080 ShoppingItemPriceImpl.class,
081 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByItemId",
082 new String[] {
083 Long.class.getName(),
084
085 "java.lang.Integer", "java.lang.Integer",
086 "com.liferay.portal.kernel.util.OrderByComparator"
087 });
088 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ITEMID =
089 new FinderPath(ShoppingItemPriceModelImpl.ENTITY_CACHE_ENABLED,
090 ShoppingItemPriceModelImpl.FINDER_CACHE_ENABLED,
091 ShoppingItemPriceImpl.class,
092 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByItemId",
093 new String[] { Long.class.getName() },
094 ShoppingItemPriceModelImpl.ITEMID_COLUMN_BITMASK);
095 public static final FinderPath FINDER_PATH_COUNT_BY_ITEMID = new FinderPath(ShoppingItemPriceModelImpl.ENTITY_CACHE_ENABLED,
096 ShoppingItemPriceModelImpl.FINDER_CACHE_ENABLED, Long.class,
097 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByItemId",
098 new String[] { Long.class.getName() });
099 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(ShoppingItemPriceModelImpl.ENTITY_CACHE_ENABLED,
100 ShoppingItemPriceModelImpl.FINDER_CACHE_ENABLED,
101 ShoppingItemPriceImpl.class,
102 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
103 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(ShoppingItemPriceModelImpl.ENTITY_CACHE_ENABLED,
104 ShoppingItemPriceModelImpl.FINDER_CACHE_ENABLED,
105 ShoppingItemPriceImpl.class,
106 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
107 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ShoppingItemPriceModelImpl.ENTITY_CACHE_ENABLED,
108 ShoppingItemPriceModelImpl.FINDER_CACHE_ENABLED, Long.class,
109 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
110
111
116 public void cacheResult(ShoppingItemPrice shoppingItemPrice) {
117 EntityCacheUtil.putResult(ShoppingItemPriceModelImpl.ENTITY_CACHE_ENABLED,
118 ShoppingItemPriceImpl.class, shoppingItemPrice.getPrimaryKey(),
119 shoppingItemPrice);
120
121 shoppingItemPrice.resetOriginalValues();
122 }
123
124
129 public void cacheResult(List<ShoppingItemPrice> shoppingItemPrices) {
130 for (ShoppingItemPrice shoppingItemPrice : shoppingItemPrices) {
131 if (EntityCacheUtil.getResult(
132 ShoppingItemPriceModelImpl.ENTITY_CACHE_ENABLED,
133 ShoppingItemPriceImpl.class,
134 shoppingItemPrice.getPrimaryKey()) == null) {
135 cacheResult(shoppingItemPrice);
136 }
137 else {
138 shoppingItemPrice.resetOriginalValues();
139 }
140 }
141 }
142
143
150 @Override
151 public void clearCache() {
152 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
153 CacheRegistryUtil.clear(ShoppingItemPriceImpl.class.getName());
154 }
155
156 EntityCacheUtil.clearCache(ShoppingItemPriceImpl.class.getName());
157
158 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
159 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
160 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
161 }
162
163
170 @Override
171 public void clearCache(ShoppingItemPrice shoppingItemPrice) {
172 EntityCacheUtil.removeResult(ShoppingItemPriceModelImpl.ENTITY_CACHE_ENABLED,
173 ShoppingItemPriceImpl.class, shoppingItemPrice.getPrimaryKey());
174
175 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
176 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
177 }
178
179
185 public ShoppingItemPrice create(long itemPriceId) {
186 ShoppingItemPrice shoppingItemPrice = new ShoppingItemPriceImpl();
187
188 shoppingItemPrice.setNew(true);
189 shoppingItemPrice.setPrimaryKey(itemPriceId);
190
191 return shoppingItemPrice;
192 }
193
194
202 @Override
203 public ShoppingItemPrice remove(Serializable primaryKey)
204 throws NoSuchModelException, SystemException {
205 return remove(((Long)primaryKey).longValue());
206 }
207
208
216 public ShoppingItemPrice remove(long itemPriceId)
217 throws NoSuchItemPriceException, SystemException {
218 Session session = null;
219
220 try {
221 session = openSession();
222
223 ShoppingItemPrice shoppingItemPrice = (ShoppingItemPrice)session.get(ShoppingItemPriceImpl.class,
224 Long.valueOf(itemPriceId));
225
226 if (shoppingItemPrice == null) {
227 if (_log.isWarnEnabled()) {
228 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + itemPriceId);
229 }
230
231 throw new NoSuchItemPriceException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
232 itemPriceId);
233 }
234
235 return shoppingItemPricePersistence.remove(shoppingItemPrice);
236 }
237 catch (NoSuchItemPriceException nsee) {
238 throw nsee;
239 }
240 catch (Exception e) {
241 throw processException(e);
242 }
243 finally {
244 closeSession(session);
245 }
246 }
247
248
255 @Override
256 public ShoppingItemPrice remove(ShoppingItemPrice shoppingItemPrice)
257 throws SystemException {
258 return super.remove(shoppingItemPrice);
259 }
260
261 @Override
262 protected ShoppingItemPrice removeImpl(ShoppingItemPrice shoppingItemPrice)
263 throws SystemException {
264 shoppingItemPrice = toUnwrappedModel(shoppingItemPrice);
265
266 Session session = null;
267
268 try {
269 session = openSession();
270
271 BatchSessionUtil.delete(session, shoppingItemPrice);
272 }
273 catch (Exception e) {
274 throw processException(e);
275 }
276 finally {
277 closeSession(session);
278 }
279
280 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
281 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
282
283 EntityCacheUtil.removeResult(ShoppingItemPriceModelImpl.ENTITY_CACHE_ENABLED,
284 ShoppingItemPriceImpl.class, shoppingItemPrice.getPrimaryKey());
285
286 return shoppingItemPrice;
287 }
288
289 @Override
290 public ShoppingItemPrice updateImpl(
291 com.liferay.portlet.shopping.model.ShoppingItemPrice shoppingItemPrice,
292 boolean merge) throws SystemException {
293 shoppingItemPrice = toUnwrappedModel(shoppingItemPrice);
294
295 boolean isNew = shoppingItemPrice.isNew();
296
297 ShoppingItemPriceModelImpl shoppingItemPriceModelImpl = (ShoppingItemPriceModelImpl)shoppingItemPrice;
298
299 Session session = null;
300
301 try {
302 session = openSession();
303
304 BatchSessionUtil.update(session, shoppingItemPrice, merge);
305
306 shoppingItemPrice.setNew(false);
307 }
308 catch (Exception e) {
309 throw processException(e);
310 }
311 finally {
312 closeSession(session);
313 }
314
315 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
316
317 if (isNew || !ShoppingItemPriceModelImpl.COLUMN_BITMASK_ENABLED) {
318 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
319 }
320
321 else {
322 if ((shoppingItemPriceModelImpl.getColumnBitmask() &
323 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ITEMID.getColumnBitmask()) != 0) {
324 Object[] args = new Object[] {
325 Long.valueOf(shoppingItemPriceModelImpl.getOriginalItemId())
326 };
327
328 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ITEMID, args);
329 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ITEMID,
330 args);
331
332 args = new Object[] {
333 Long.valueOf(shoppingItemPriceModelImpl.getItemId())
334 };
335
336 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ITEMID, args);
337 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ITEMID,
338 args);
339 }
340 }
341
342 EntityCacheUtil.putResult(ShoppingItemPriceModelImpl.ENTITY_CACHE_ENABLED,
343 ShoppingItemPriceImpl.class, shoppingItemPrice.getPrimaryKey(),
344 shoppingItemPrice);
345
346 return shoppingItemPrice;
347 }
348
349 protected ShoppingItemPrice toUnwrappedModel(
350 ShoppingItemPrice shoppingItemPrice) {
351 if (shoppingItemPrice instanceof ShoppingItemPriceImpl) {
352 return shoppingItemPrice;
353 }
354
355 ShoppingItemPriceImpl shoppingItemPriceImpl = new ShoppingItemPriceImpl();
356
357 shoppingItemPriceImpl.setNew(shoppingItemPrice.isNew());
358 shoppingItemPriceImpl.setPrimaryKey(shoppingItemPrice.getPrimaryKey());
359
360 shoppingItemPriceImpl.setItemPriceId(shoppingItemPrice.getItemPriceId());
361 shoppingItemPriceImpl.setItemId(shoppingItemPrice.getItemId());
362 shoppingItemPriceImpl.setMinQuantity(shoppingItemPrice.getMinQuantity());
363 shoppingItemPriceImpl.setMaxQuantity(shoppingItemPrice.getMaxQuantity());
364 shoppingItemPriceImpl.setPrice(shoppingItemPrice.getPrice());
365 shoppingItemPriceImpl.setDiscount(shoppingItemPrice.getDiscount());
366 shoppingItemPriceImpl.setTaxable(shoppingItemPrice.isTaxable());
367 shoppingItemPriceImpl.setShipping(shoppingItemPrice.getShipping());
368 shoppingItemPriceImpl.setUseShippingFormula(shoppingItemPrice.isUseShippingFormula());
369 shoppingItemPriceImpl.setStatus(shoppingItemPrice.getStatus());
370
371 return shoppingItemPriceImpl;
372 }
373
374
382 @Override
383 public ShoppingItemPrice findByPrimaryKey(Serializable primaryKey)
384 throws NoSuchModelException, SystemException {
385 return findByPrimaryKey(((Long)primaryKey).longValue());
386 }
387
388
396 public ShoppingItemPrice findByPrimaryKey(long itemPriceId)
397 throws NoSuchItemPriceException, SystemException {
398 ShoppingItemPrice shoppingItemPrice = fetchByPrimaryKey(itemPriceId);
399
400 if (shoppingItemPrice == null) {
401 if (_log.isWarnEnabled()) {
402 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + itemPriceId);
403 }
404
405 throw new NoSuchItemPriceException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
406 itemPriceId);
407 }
408
409 return shoppingItemPrice;
410 }
411
412
419 @Override
420 public ShoppingItemPrice fetchByPrimaryKey(Serializable primaryKey)
421 throws SystemException {
422 return fetchByPrimaryKey(((Long)primaryKey).longValue());
423 }
424
425
432 public ShoppingItemPrice fetchByPrimaryKey(long itemPriceId)
433 throws SystemException {
434 ShoppingItemPrice shoppingItemPrice = (ShoppingItemPrice)EntityCacheUtil.getResult(ShoppingItemPriceModelImpl.ENTITY_CACHE_ENABLED,
435 ShoppingItemPriceImpl.class, itemPriceId);
436
437 if (shoppingItemPrice == _nullShoppingItemPrice) {
438 return null;
439 }
440
441 if (shoppingItemPrice == null) {
442 Session session = null;
443
444 boolean hasException = false;
445
446 try {
447 session = openSession();
448
449 shoppingItemPrice = (ShoppingItemPrice)session.get(ShoppingItemPriceImpl.class,
450 Long.valueOf(itemPriceId));
451 }
452 catch (Exception e) {
453 hasException = true;
454
455 throw processException(e);
456 }
457 finally {
458 if (shoppingItemPrice != null) {
459 cacheResult(shoppingItemPrice);
460 }
461 else if (!hasException) {
462 EntityCacheUtil.putResult(ShoppingItemPriceModelImpl.ENTITY_CACHE_ENABLED,
463 ShoppingItemPriceImpl.class, itemPriceId,
464 _nullShoppingItemPrice);
465 }
466
467 closeSession(session);
468 }
469 }
470
471 return shoppingItemPrice;
472 }
473
474
481 public List<ShoppingItemPrice> findByItemId(long itemId)
482 throws SystemException {
483 return findByItemId(itemId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
484 }
485
486
499 public List<ShoppingItemPrice> findByItemId(long itemId, int start, int end)
500 throws SystemException {
501 return findByItemId(itemId, start, end, null);
502 }
503
504
518 public List<ShoppingItemPrice> findByItemId(long itemId, int start,
519 int end, OrderByComparator orderByComparator) throws SystemException {
520 FinderPath finderPath = null;
521 Object[] finderArgs = null;
522
523 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
524 (orderByComparator == null)) {
525 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ITEMID;
526 finderArgs = new Object[] { itemId };
527 }
528 else {
529 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_ITEMID;
530 finderArgs = new Object[] { itemId, start, end, orderByComparator };
531 }
532
533 List<ShoppingItemPrice> list = (List<ShoppingItemPrice>)FinderCacheUtil.getResult(finderPath,
534 finderArgs, this);
535
536 if (list == null) {
537 StringBundler query = null;
538
539 if (orderByComparator != null) {
540 query = new StringBundler(3 +
541 (orderByComparator.getOrderByFields().length * 3));
542 }
543 else {
544 query = new StringBundler(3);
545 }
546
547 query.append(_SQL_SELECT_SHOPPINGITEMPRICE_WHERE);
548
549 query.append(_FINDER_COLUMN_ITEMID_ITEMID_2);
550
551 if (orderByComparator != null) {
552 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
553 orderByComparator);
554 }
555
556 else {
557 query.append(ShoppingItemPriceModelImpl.ORDER_BY_JPQL);
558 }
559
560 String sql = query.toString();
561
562 Session session = null;
563
564 try {
565 session = openSession();
566
567 Query q = session.createQuery(sql);
568
569 QueryPos qPos = QueryPos.getInstance(q);
570
571 qPos.add(itemId);
572
573 list = (List<ShoppingItemPrice>)QueryUtil.list(q, getDialect(),
574 start, end);
575 }
576 catch (Exception e) {
577 throw processException(e);
578 }
579 finally {
580 if (list == null) {
581 FinderCacheUtil.removeResult(finderPath, finderArgs);
582 }
583 else {
584 cacheResult(list);
585
586 FinderCacheUtil.putResult(finderPath, finderArgs, list);
587 }
588
589 closeSession(session);
590 }
591 }
592
593 return list;
594 }
595
596
609 public ShoppingItemPrice findByItemId_First(long itemId,
610 OrderByComparator orderByComparator)
611 throws NoSuchItemPriceException, SystemException {
612 List<ShoppingItemPrice> list = findByItemId(itemId, 0, 1,
613 orderByComparator);
614
615 if (list.isEmpty()) {
616 StringBundler msg = new StringBundler(4);
617
618 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
619
620 msg.append("itemId=");
621 msg.append(itemId);
622
623 msg.append(StringPool.CLOSE_CURLY_BRACE);
624
625 throw new NoSuchItemPriceException(msg.toString());
626 }
627 else {
628 return list.get(0);
629 }
630 }
631
632
645 public ShoppingItemPrice findByItemId_Last(long itemId,
646 OrderByComparator orderByComparator)
647 throws NoSuchItemPriceException, SystemException {
648 int count = countByItemId(itemId);
649
650 List<ShoppingItemPrice> list = findByItemId(itemId, count - 1, count,
651 orderByComparator);
652
653 if (list.isEmpty()) {
654 StringBundler msg = new StringBundler(4);
655
656 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
657
658 msg.append("itemId=");
659 msg.append(itemId);
660
661 msg.append(StringPool.CLOSE_CURLY_BRACE);
662
663 throw new NoSuchItemPriceException(msg.toString());
664 }
665 else {
666 return list.get(0);
667 }
668 }
669
670
684 public ShoppingItemPrice[] findByItemId_PrevAndNext(long itemPriceId,
685 long itemId, OrderByComparator orderByComparator)
686 throws NoSuchItemPriceException, SystemException {
687 ShoppingItemPrice shoppingItemPrice = findByPrimaryKey(itemPriceId);
688
689 Session session = null;
690
691 try {
692 session = openSession();
693
694 ShoppingItemPrice[] array = new ShoppingItemPriceImpl[3];
695
696 array[0] = getByItemId_PrevAndNext(session, shoppingItemPrice,
697 itemId, orderByComparator, true);
698
699 array[1] = shoppingItemPrice;
700
701 array[2] = getByItemId_PrevAndNext(session, shoppingItemPrice,
702 itemId, orderByComparator, false);
703
704 return array;
705 }
706 catch (Exception e) {
707 throw processException(e);
708 }
709 finally {
710 closeSession(session);
711 }
712 }
713
714 protected ShoppingItemPrice getByItemId_PrevAndNext(Session session,
715 ShoppingItemPrice shoppingItemPrice, long itemId,
716 OrderByComparator orderByComparator, boolean previous) {
717 StringBundler query = null;
718
719 if (orderByComparator != null) {
720 query = new StringBundler(6 +
721 (orderByComparator.getOrderByFields().length * 6));
722 }
723 else {
724 query = new StringBundler(3);
725 }
726
727 query.append(_SQL_SELECT_SHOPPINGITEMPRICE_WHERE);
728
729 query.append(_FINDER_COLUMN_ITEMID_ITEMID_2);
730
731 if (orderByComparator != null) {
732 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
733
734 if (orderByConditionFields.length > 0) {
735 query.append(WHERE_AND);
736 }
737
738 for (int i = 0; i < orderByConditionFields.length; i++) {
739 query.append(_ORDER_BY_ENTITY_ALIAS);
740 query.append(orderByConditionFields[i]);
741
742 if ((i + 1) < orderByConditionFields.length) {
743 if (orderByComparator.isAscending() ^ previous) {
744 query.append(WHERE_GREATER_THAN_HAS_NEXT);
745 }
746 else {
747 query.append(WHERE_LESSER_THAN_HAS_NEXT);
748 }
749 }
750 else {
751 if (orderByComparator.isAscending() ^ previous) {
752 query.append(WHERE_GREATER_THAN);
753 }
754 else {
755 query.append(WHERE_LESSER_THAN);
756 }
757 }
758 }
759
760 query.append(ORDER_BY_CLAUSE);
761
762 String[] orderByFields = orderByComparator.getOrderByFields();
763
764 for (int i = 0; i < orderByFields.length; i++) {
765 query.append(_ORDER_BY_ENTITY_ALIAS);
766 query.append(orderByFields[i]);
767
768 if ((i + 1) < orderByFields.length) {
769 if (orderByComparator.isAscending() ^ previous) {
770 query.append(ORDER_BY_ASC_HAS_NEXT);
771 }
772 else {
773 query.append(ORDER_BY_DESC_HAS_NEXT);
774 }
775 }
776 else {
777 if (orderByComparator.isAscending() ^ previous) {
778 query.append(ORDER_BY_ASC);
779 }
780 else {
781 query.append(ORDER_BY_DESC);
782 }
783 }
784 }
785 }
786
787 else {
788 query.append(ShoppingItemPriceModelImpl.ORDER_BY_JPQL);
789 }
790
791 String sql = query.toString();
792
793 Query q = session.createQuery(sql);
794
795 q.setFirstResult(0);
796 q.setMaxResults(2);
797
798 QueryPos qPos = QueryPos.getInstance(q);
799
800 qPos.add(itemId);
801
802 if (orderByComparator != null) {
803 Object[] values = orderByComparator.getOrderByConditionValues(shoppingItemPrice);
804
805 for (Object value : values) {
806 qPos.add(value);
807 }
808 }
809
810 List<ShoppingItemPrice> list = q.list();
811
812 if (list.size() == 2) {
813 return list.get(1);
814 }
815 else {
816 return null;
817 }
818 }
819
820
826 public List<ShoppingItemPrice> findAll() throws SystemException {
827 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
828 }
829
830
842 public List<ShoppingItemPrice> findAll(int start, int end)
843 throws SystemException {
844 return findAll(start, end, null);
845 }
846
847
860 public List<ShoppingItemPrice> findAll(int start, int end,
861 OrderByComparator orderByComparator) throws SystemException {
862 FinderPath finderPath = null;
863 Object[] finderArgs = new Object[] { start, end, orderByComparator };
864
865 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
866 (orderByComparator == null)) {
867 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
868 finderArgs = FINDER_ARGS_EMPTY;
869 }
870 else {
871 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
872 finderArgs = new Object[] { start, end, orderByComparator };
873 }
874
875 List<ShoppingItemPrice> list = (List<ShoppingItemPrice>)FinderCacheUtil.getResult(finderPath,
876 finderArgs, this);
877
878 if (list == null) {
879 StringBundler query = null;
880 String sql = null;
881
882 if (orderByComparator != null) {
883 query = new StringBundler(2 +
884 (orderByComparator.getOrderByFields().length * 3));
885
886 query.append(_SQL_SELECT_SHOPPINGITEMPRICE);
887
888 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
889 orderByComparator);
890
891 sql = query.toString();
892 }
893 else {
894 sql = _SQL_SELECT_SHOPPINGITEMPRICE.concat(ShoppingItemPriceModelImpl.ORDER_BY_JPQL);
895 }
896
897 Session session = null;
898
899 try {
900 session = openSession();
901
902 Query q = session.createQuery(sql);
903
904 if (orderByComparator == null) {
905 list = (List<ShoppingItemPrice>)QueryUtil.list(q,
906 getDialect(), start, end, false);
907
908 Collections.sort(list);
909 }
910 else {
911 list = (List<ShoppingItemPrice>)QueryUtil.list(q,
912 getDialect(), start, end);
913 }
914 }
915 catch (Exception e) {
916 throw processException(e);
917 }
918 finally {
919 if (list == null) {
920 FinderCacheUtil.removeResult(finderPath, finderArgs);
921 }
922 else {
923 cacheResult(list);
924
925 FinderCacheUtil.putResult(finderPath, finderArgs, list);
926 }
927
928 closeSession(session);
929 }
930 }
931
932 return list;
933 }
934
935
941 public void removeByItemId(long itemId) throws SystemException {
942 for (ShoppingItemPrice shoppingItemPrice : findByItemId(itemId)) {
943 shoppingItemPricePersistence.remove(shoppingItemPrice);
944 }
945 }
946
947
952 public void removeAll() throws SystemException {
953 for (ShoppingItemPrice shoppingItemPrice : findAll()) {
954 shoppingItemPricePersistence.remove(shoppingItemPrice);
955 }
956 }
957
958
965 public int countByItemId(long itemId) throws SystemException {
966 Object[] finderArgs = new Object[] { itemId };
967
968 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_ITEMID,
969 finderArgs, this);
970
971 if (count == null) {
972 StringBundler query = new StringBundler(2);
973
974 query.append(_SQL_COUNT_SHOPPINGITEMPRICE_WHERE);
975
976 query.append(_FINDER_COLUMN_ITEMID_ITEMID_2);
977
978 String sql = query.toString();
979
980 Session session = null;
981
982 try {
983 session = openSession();
984
985 Query q = session.createQuery(sql);
986
987 QueryPos qPos = QueryPos.getInstance(q);
988
989 qPos.add(itemId);
990
991 count = (Long)q.uniqueResult();
992 }
993 catch (Exception e) {
994 throw processException(e);
995 }
996 finally {
997 if (count == null) {
998 count = Long.valueOf(0);
999 }
1000
1001 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_ITEMID,
1002 finderArgs, count);
1003
1004 closeSession(session);
1005 }
1006 }
1007
1008 return count.intValue();
1009 }
1010
1011
1017 public int countAll() throws SystemException {
1018 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1019 FINDER_ARGS_EMPTY, this);
1020
1021 if (count == null) {
1022 Session session = null;
1023
1024 try {
1025 session = openSession();
1026
1027 Query q = session.createQuery(_SQL_COUNT_SHOPPINGITEMPRICE);
1028
1029 count = (Long)q.uniqueResult();
1030 }
1031 catch (Exception e) {
1032 throw processException(e);
1033 }
1034 finally {
1035 if (count == null) {
1036 count = Long.valueOf(0);
1037 }
1038
1039 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1040 FINDER_ARGS_EMPTY, count);
1041
1042 closeSession(session);
1043 }
1044 }
1045
1046 return count.intValue();
1047 }
1048
1049
1052 public void afterPropertiesSet() {
1053 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1054 com.liferay.portal.util.PropsUtil.get(
1055 "value.object.listener.com.liferay.portlet.shopping.model.ShoppingItemPrice")));
1056
1057 if (listenerClassNames.length > 0) {
1058 try {
1059 List<ModelListener<ShoppingItemPrice>> listenersList = new ArrayList<ModelListener<ShoppingItemPrice>>();
1060
1061 for (String listenerClassName : listenerClassNames) {
1062 listenersList.add((ModelListener<ShoppingItemPrice>)InstanceFactory.newInstance(
1063 listenerClassName));
1064 }
1065
1066 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1067 }
1068 catch (Exception e) {
1069 _log.error(e);
1070 }
1071 }
1072 }
1073
1074 public void destroy() {
1075 EntityCacheUtil.removeCache(ShoppingItemPriceImpl.class.getName());
1076 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1077 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1078 }
1079
1080 @BeanReference(type = ShoppingCartPersistence.class)
1081 protected ShoppingCartPersistence shoppingCartPersistence;
1082 @BeanReference(type = ShoppingCategoryPersistence.class)
1083 protected ShoppingCategoryPersistence shoppingCategoryPersistence;
1084 @BeanReference(type = ShoppingCouponPersistence.class)
1085 protected ShoppingCouponPersistence shoppingCouponPersistence;
1086 @BeanReference(type = ShoppingItemPersistence.class)
1087 protected ShoppingItemPersistence shoppingItemPersistence;
1088 @BeanReference(type = ShoppingItemFieldPersistence.class)
1089 protected ShoppingItemFieldPersistence shoppingItemFieldPersistence;
1090 @BeanReference(type = ShoppingItemPricePersistence.class)
1091 protected ShoppingItemPricePersistence shoppingItemPricePersistence;
1092 @BeanReference(type = ShoppingOrderPersistence.class)
1093 protected ShoppingOrderPersistence shoppingOrderPersistence;
1094 @BeanReference(type = ShoppingOrderItemPersistence.class)
1095 protected ShoppingOrderItemPersistence shoppingOrderItemPersistence;
1096 @BeanReference(type = ResourcePersistence.class)
1097 protected ResourcePersistence resourcePersistence;
1098 @BeanReference(type = UserPersistence.class)
1099 protected UserPersistence userPersistence;
1100 private static final String _SQL_SELECT_SHOPPINGITEMPRICE = "SELECT shoppingItemPrice FROM ShoppingItemPrice shoppingItemPrice";
1101 private static final String _SQL_SELECT_SHOPPINGITEMPRICE_WHERE = "SELECT shoppingItemPrice FROM ShoppingItemPrice shoppingItemPrice WHERE ";
1102 private static final String _SQL_COUNT_SHOPPINGITEMPRICE = "SELECT COUNT(shoppingItemPrice) FROM ShoppingItemPrice shoppingItemPrice";
1103 private static final String _SQL_COUNT_SHOPPINGITEMPRICE_WHERE = "SELECT COUNT(shoppingItemPrice) FROM ShoppingItemPrice shoppingItemPrice WHERE ";
1104 private static final String _FINDER_COLUMN_ITEMID_ITEMID_2 = "shoppingItemPrice.itemId = ?";
1105 private static final String _ORDER_BY_ENTITY_ALIAS = "shoppingItemPrice.";
1106 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ShoppingItemPrice exists with the primary key ";
1107 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ShoppingItemPrice exists with the key {";
1108 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1109 private static Log _log = LogFactoryUtil.getLog(ShoppingItemPricePersistenceImpl.class);
1110 private static ShoppingItemPrice _nullShoppingItemPrice = new ShoppingItemPriceImpl() {
1111 @Override
1112 public Object clone() {
1113 return this;
1114 }
1115
1116 @Override
1117 public CacheModel<ShoppingItemPrice> toCacheModel() {
1118 return _nullShoppingItemPriceCacheModel;
1119 }
1120 };
1121
1122 private static CacheModel<ShoppingItemPrice> _nullShoppingItemPriceCacheModel =
1123 new CacheModel<ShoppingItemPrice>() {
1124 public ShoppingItemPrice toEntityModel() {
1125 return _nullShoppingItemPrice;
1126 }
1127 };
1128 }