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_WITH_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_WITHOUT_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 @Override
180 public void clearCache(List<ShoppingItemPrice> shoppingItemPrices) {
181 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
182 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
183
184 for (ShoppingItemPrice shoppingItemPrice : shoppingItemPrices) {
185 EntityCacheUtil.removeResult(ShoppingItemPriceModelImpl.ENTITY_CACHE_ENABLED,
186 ShoppingItemPriceImpl.class, shoppingItemPrice.getPrimaryKey());
187 }
188 }
189
190
196 public ShoppingItemPrice create(long itemPriceId) {
197 ShoppingItemPrice shoppingItemPrice = new ShoppingItemPriceImpl();
198
199 shoppingItemPrice.setNew(true);
200 shoppingItemPrice.setPrimaryKey(itemPriceId);
201
202 return shoppingItemPrice;
203 }
204
205
213 public ShoppingItemPrice remove(long itemPriceId)
214 throws NoSuchItemPriceException, SystemException {
215 return remove(Long.valueOf(itemPriceId));
216 }
217
218
226 @Override
227 public ShoppingItemPrice remove(Serializable primaryKey)
228 throws NoSuchItemPriceException, SystemException {
229 Session session = null;
230
231 try {
232 session = openSession();
233
234 ShoppingItemPrice shoppingItemPrice = (ShoppingItemPrice)session.get(ShoppingItemPriceImpl.class,
235 primaryKey);
236
237 if (shoppingItemPrice == null) {
238 if (_log.isWarnEnabled()) {
239 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
240 }
241
242 throw new NoSuchItemPriceException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
243 primaryKey);
244 }
245
246 return remove(shoppingItemPrice);
247 }
248 catch (NoSuchItemPriceException nsee) {
249 throw nsee;
250 }
251 catch (Exception e) {
252 throw processException(e);
253 }
254 finally {
255 closeSession(session);
256 }
257 }
258
259 @Override
260 protected ShoppingItemPrice removeImpl(ShoppingItemPrice shoppingItemPrice)
261 throws SystemException {
262 shoppingItemPrice = toUnwrappedModel(shoppingItemPrice);
263
264 Session session = null;
265
266 try {
267 session = openSession();
268
269 BatchSessionUtil.delete(session, shoppingItemPrice);
270 }
271 catch (Exception e) {
272 throw processException(e);
273 }
274 finally {
275 closeSession(session);
276 }
277
278 clearCache(shoppingItemPrice);
279
280 return shoppingItemPrice;
281 }
282
283 @Override
284 public ShoppingItemPrice updateImpl(
285 com.liferay.portlet.shopping.model.ShoppingItemPrice shoppingItemPrice,
286 boolean merge) throws SystemException {
287 shoppingItemPrice = toUnwrappedModel(shoppingItemPrice);
288
289 boolean isNew = shoppingItemPrice.isNew();
290
291 ShoppingItemPriceModelImpl shoppingItemPriceModelImpl = (ShoppingItemPriceModelImpl)shoppingItemPrice;
292
293 Session session = null;
294
295 try {
296 session = openSession();
297
298 BatchSessionUtil.update(session, shoppingItemPrice, merge);
299
300 shoppingItemPrice.setNew(false);
301 }
302 catch (Exception e) {
303 throw processException(e);
304 }
305 finally {
306 closeSession(session);
307 }
308
309 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
310
311 if (isNew || !ShoppingItemPriceModelImpl.COLUMN_BITMASK_ENABLED) {
312 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
313 }
314 else {
315 if ((shoppingItemPriceModelImpl.getColumnBitmask() &
316 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ITEMID.getColumnBitmask()) != 0) {
317 Object[] args = new Object[] {
318 Long.valueOf(shoppingItemPriceModelImpl.getOriginalItemId())
319 };
320
321 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ITEMID, args);
322 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ITEMID,
323 args);
324
325 args = new Object[] {
326 Long.valueOf(shoppingItemPriceModelImpl.getItemId())
327 };
328
329 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ITEMID, args);
330 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ITEMID,
331 args);
332 }
333 }
334
335 EntityCacheUtil.putResult(ShoppingItemPriceModelImpl.ENTITY_CACHE_ENABLED,
336 ShoppingItemPriceImpl.class, shoppingItemPrice.getPrimaryKey(),
337 shoppingItemPrice);
338
339 return shoppingItemPrice;
340 }
341
342 protected ShoppingItemPrice toUnwrappedModel(
343 ShoppingItemPrice shoppingItemPrice) {
344 if (shoppingItemPrice instanceof ShoppingItemPriceImpl) {
345 return shoppingItemPrice;
346 }
347
348 ShoppingItemPriceImpl shoppingItemPriceImpl = new ShoppingItemPriceImpl();
349
350 shoppingItemPriceImpl.setNew(shoppingItemPrice.isNew());
351 shoppingItemPriceImpl.setPrimaryKey(shoppingItemPrice.getPrimaryKey());
352
353 shoppingItemPriceImpl.setItemPriceId(shoppingItemPrice.getItemPriceId());
354 shoppingItemPriceImpl.setItemId(shoppingItemPrice.getItemId());
355 shoppingItemPriceImpl.setMinQuantity(shoppingItemPrice.getMinQuantity());
356 shoppingItemPriceImpl.setMaxQuantity(shoppingItemPrice.getMaxQuantity());
357 shoppingItemPriceImpl.setPrice(shoppingItemPrice.getPrice());
358 shoppingItemPriceImpl.setDiscount(shoppingItemPrice.getDiscount());
359 shoppingItemPriceImpl.setTaxable(shoppingItemPrice.isTaxable());
360 shoppingItemPriceImpl.setShipping(shoppingItemPrice.getShipping());
361 shoppingItemPriceImpl.setUseShippingFormula(shoppingItemPrice.isUseShippingFormula());
362 shoppingItemPriceImpl.setStatus(shoppingItemPrice.getStatus());
363
364 return shoppingItemPriceImpl;
365 }
366
367
375 @Override
376 public ShoppingItemPrice findByPrimaryKey(Serializable primaryKey)
377 throws NoSuchModelException, SystemException {
378 return findByPrimaryKey(((Long)primaryKey).longValue());
379 }
380
381
389 public ShoppingItemPrice findByPrimaryKey(long itemPriceId)
390 throws NoSuchItemPriceException, SystemException {
391 ShoppingItemPrice shoppingItemPrice = fetchByPrimaryKey(itemPriceId);
392
393 if (shoppingItemPrice == null) {
394 if (_log.isWarnEnabled()) {
395 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + itemPriceId);
396 }
397
398 throw new NoSuchItemPriceException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
399 itemPriceId);
400 }
401
402 return shoppingItemPrice;
403 }
404
405
412 @Override
413 public ShoppingItemPrice fetchByPrimaryKey(Serializable primaryKey)
414 throws SystemException {
415 return fetchByPrimaryKey(((Long)primaryKey).longValue());
416 }
417
418
425 public ShoppingItemPrice fetchByPrimaryKey(long itemPriceId)
426 throws SystemException {
427 ShoppingItemPrice shoppingItemPrice = (ShoppingItemPrice)EntityCacheUtil.getResult(ShoppingItemPriceModelImpl.ENTITY_CACHE_ENABLED,
428 ShoppingItemPriceImpl.class, itemPriceId);
429
430 if (shoppingItemPrice == _nullShoppingItemPrice) {
431 return null;
432 }
433
434 if (shoppingItemPrice == null) {
435 Session session = null;
436
437 boolean hasException = false;
438
439 try {
440 session = openSession();
441
442 shoppingItemPrice = (ShoppingItemPrice)session.get(ShoppingItemPriceImpl.class,
443 Long.valueOf(itemPriceId));
444 }
445 catch (Exception e) {
446 hasException = true;
447
448 throw processException(e);
449 }
450 finally {
451 if (shoppingItemPrice != null) {
452 cacheResult(shoppingItemPrice);
453 }
454 else if (!hasException) {
455 EntityCacheUtil.putResult(ShoppingItemPriceModelImpl.ENTITY_CACHE_ENABLED,
456 ShoppingItemPriceImpl.class, itemPriceId,
457 _nullShoppingItemPrice);
458 }
459
460 closeSession(session);
461 }
462 }
463
464 return shoppingItemPrice;
465 }
466
467
474 public List<ShoppingItemPrice> findByItemId(long itemId)
475 throws SystemException {
476 return findByItemId(itemId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
477 }
478
479
492 public List<ShoppingItemPrice> findByItemId(long itemId, int start, int end)
493 throws SystemException {
494 return findByItemId(itemId, start, end, null);
495 }
496
497
511 public List<ShoppingItemPrice> findByItemId(long itemId, int start,
512 int end, OrderByComparator orderByComparator) throws SystemException {
513 FinderPath finderPath = null;
514 Object[] finderArgs = null;
515
516 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
517 (orderByComparator == null)) {
518 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ITEMID;
519 finderArgs = new Object[] { itemId };
520 }
521 else {
522 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_ITEMID;
523 finderArgs = new Object[] { itemId, start, end, orderByComparator };
524 }
525
526 List<ShoppingItemPrice> list = (List<ShoppingItemPrice>)FinderCacheUtil.getResult(finderPath,
527 finderArgs, this);
528
529 if ((list != null) && !list.isEmpty()) {
530 for (ShoppingItemPrice shoppingItemPrice : list) {
531 if ((itemId != shoppingItemPrice.getItemId())) {
532 list = null;
533
534 break;
535 }
536 }
537 }
538
539 if (list == null) {
540 StringBundler query = null;
541
542 if (orderByComparator != null) {
543 query = new StringBundler(3 +
544 (orderByComparator.getOrderByFields().length * 3));
545 }
546 else {
547 query = new StringBundler(3);
548 }
549
550 query.append(_SQL_SELECT_SHOPPINGITEMPRICE_WHERE);
551
552 query.append(_FINDER_COLUMN_ITEMID_ITEMID_2);
553
554 if (orderByComparator != null) {
555 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
556 orderByComparator);
557 }
558
559 else {
560 query.append(ShoppingItemPriceModelImpl.ORDER_BY_JPQL);
561 }
562
563 String sql = query.toString();
564
565 Session session = null;
566
567 try {
568 session = openSession();
569
570 Query q = session.createQuery(sql);
571
572 QueryPos qPos = QueryPos.getInstance(q);
573
574 qPos.add(itemId);
575
576 list = (List<ShoppingItemPrice>)QueryUtil.list(q, getDialect(),
577 start, end);
578 }
579 catch (Exception e) {
580 throw processException(e);
581 }
582 finally {
583 if (list == null) {
584 FinderCacheUtil.removeResult(finderPath, finderArgs);
585 }
586 else {
587 cacheResult(list);
588
589 FinderCacheUtil.putResult(finderPath, finderArgs, list);
590 }
591
592 closeSession(session);
593 }
594 }
595
596 return list;
597 }
598
599
612 public ShoppingItemPrice findByItemId_First(long itemId,
613 OrderByComparator orderByComparator)
614 throws NoSuchItemPriceException, SystemException {
615 List<ShoppingItemPrice> list = findByItemId(itemId, 0, 1,
616 orderByComparator);
617
618 if (list.isEmpty()) {
619 StringBundler msg = new StringBundler(4);
620
621 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
622
623 msg.append("itemId=");
624 msg.append(itemId);
625
626 msg.append(StringPool.CLOSE_CURLY_BRACE);
627
628 throw new NoSuchItemPriceException(msg.toString());
629 }
630 else {
631 return list.get(0);
632 }
633 }
634
635
648 public ShoppingItemPrice findByItemId_Last(long itemId,
649 OrderByComparator orderByComparator)
650 throws NoSuchItemPriceException, SystemException {
651 int count = countByItemId(itemId);
652
653 List<ShoppingItemPrice> list = findByItemId(itemId, count - 1, count,
654 orderByComparator);
655
656 if (list.isEmpty()) {
657 StringBundler msg = new StringBundler(4);
658
659 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
660
661 msg.append("itemId=");
662 msg.append(itemId);
663
664 msg.append(StringPool.CLOSE_CURLY_BRACE);
665
666 throw new NoSuchItemPriceException(msg.toString());
667 }
668 else {
669 return list.get(0);
670 }
671 }
672
673
687 public ShoppingItemPrice[] findByItemId_PrevAndNext(long itemPriceId,
688 long itemId, OrderByComparator orderByComparator)
689 throws NoSuchItemPriceException, SystemException {
690 ShoppingItemPrice shoppingItemPrice = findByPrimaryKey(itemPriceId);
691
692 Session session = null;
693
694 try {
695 session = openSession();
696
697 ShoppingItemPrice[] array = new ShoppingItemPriceImpl[3];
698
699 array[0] = getByItemId_PrevAndNext(session, shoppingItemPrice,
700 itemId, orderByComparator, true);
701
702 array[1] = shoppingItemPrice;
703
704 array[2] = getByItemId_PrevAndNext(session, shoppingItemPrice,
705 itemId, orderByComparator, false);
706
707 return array;
708 }
709 catch (Exception e) {
710 throw processException(e);
711 }
712 finally {
713 closeSession(session);
714 }
715 }
716
717 protected ShoppingItemPrice getByItemId_PrevAndNext(Session session,
718 ShoppingItemPrice shoppingItemPrice, long itemId,
719 OrderByComparator orderByComparator, boolean previous) {
720 StringBundler query = null;
721
722 if (orderByComparator != null) {
723 query = new StringBundler(6 +
724 (orderByComparator.getOrderByFields().length * 6));
725 }
726 else {
727 query = new StringBundler(3);
728 }
729
730 query.append(_SQL_SELECT_SHOPPINGITEMPRICE_WHERE);
731
732 query.append(_FINDER_COLUMN_ITEMID_ITEMID_2);
733
734 if (orderByComparator != null) {
735 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
736
737 if (orderByConditionFields.length > 0) {
738 query.append(WHERE_AND);
739 }
740
741 for (int i = 0; i < orderByConditionFields.length; i++) {
742 query.append(_ORDER_BY_ENTITY_ALIAS);
743 query.append(orderByConditionFields[i]);
744
745 if ((i + 1) < orderByConditionFields.length) {
746 if (orderByComparator.isAscending() ^ previous) {
747 query.append(WHERE_GREATER_THAN_HAS_NEXT);
748 }
749 else {
750 query.append(WHERE_LESSER_THAN_HAS_NEXT);
751 }
752 }
753 else {
754 if (orderByComparator.isAscending() ^ previous) {
755 query.append(WHERE_GREATER_THAN);
756 }
757 else {
758 query.append(WHERE_LESSER_THAN);
759 }
760 }
761 }
762
763 query.append(ORDER_BY_CLAUSE);
764
765 String[] orderByFields = orderByComparator.getOrderByFields();
766
767 for (int i = 0; i < orderByFields.length; i++) {
768 query.append(_ORDER_BY_ENTITY_ALIAS);
769 query.append(orderByFields[i]);
770
771 if ((i + 1) < orderByFields.length) {
772 if (orderByComparator.isAscending() ^ previous) {
773 query.append(ORDER_BY_ASC_HAS_NEXT);
774 }
775 else {
776 query.append(ORDER_BY_DESC_HAS_NEXT);
777 }
778 }
779 else {
780 if (orderByComparator.isAscending() ^ previous) {
781 query.append(ORDER_BY_ASC);
782 }
783 else {
784 query.append(ORDER_BY_DESC);
785 }
786 }
787 }
788 }
789
790 else {
791 query.append(ShoppingItemPriceModelImpl.ORDER_BY_JPQL);
792 }
793
794 String sql = query.toString();
795
796 Query q = session.createQuery(sql);
797
798 q.setFirstResult(0);
799 q.setMaxResults(2);
800
801 QueryPos qPos = QueryPos.getInstance(q);
802
803 qPos.add(itemId);
804
805 if (orderByComparator != null) {
806 Object[] values = orderByComparator.getOrderByConditionValues(shoppingItemPrice);
807
808 for (Object value : values) {
809 qPos.add(value);
810 }
811 }
812
813 List<ShoppingItemPrice> list = q.list();
814
815 if (list.size() == 2) {
816 return list.get(1);
817 }
818 else {
819 return null;
820 }
821 }
822
823
829 public List<ShoppingItemPrice> findAll() throws SystemException {
830 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
831 }
832
833
845 public List<ShoppingItemPrice> findAll(int start, int end)
846 throws SystemException {
847 return findAll(start, end, null);
848 }
849
850
863 public List<ShoppingItemPrice> findAll(int start, int end,
864 OrderByComparator orderByComparator) throws SystemException {
865 FinderPath finderPath = null;
866 Object[] finderArgs = new Object[] { start, end, orderByComparator };
867
868 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
869 (orderByComparator == null)) {
870 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
871 finderArgs = FINDER_ARGS_EMPTY;
872 }
873 else {
874 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
875 finderArgs = new Object[] { start, end, orderByComparator };
876 }
877
878 List<ShoppingItemPrice> list = (List<ShoppingItemPrice>)FinderCacheUtil.getResult(finderPath,
879 finderArgs, this);
880
881 if (list == null) {
882 StringBundler query = null;
883 String sql = null;
884
885 if (orderByComparator != null) {
886 query = new StringBundler(2 +
887 (orderByComparator.getOrderByFields().length * 3));
888
889 query.append(_SQL_SELECT_SHOPPINGITEMPRICE);
890
891 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
892 orderByComparator);
893
894 sql = query.toString();
895 }
896 else {
897 sql = _SQL_SELECT_SHOPPINGITEMPRICE.concat(ShoppingItemPriceModelImpl.ORDER_BY_JPQL);
898 }
899
900 Session session = null;
901
902 try {
903 session = openSession();
904
905 Query q = session.createQuery(sql);
906
907 if (orderByComparator == null) {
908 list = (List<ShoppingItemPrice>)QueryUtil.list(q,
909 getDialect(), start, end, false);
910
911 Collections.sort(list);
912 }
913 else {
914 list = (List<ShoppingItemPrice>)QueryUtil.list(q,
915 getDialect(), start, end);
916 }
917 }
918 catch (Exception e) {
919 throw processException(e);
920 }
921 finally {
922 if (list == null) {
923 FinderCacheUtil.removeResult(finderPath, finderArgs);
924 }
925 else {
926 cacheResult(list);
927
928 FinderCacheUtil.putResult(finderPath, finderArgs, list);
929 }
930
931 closeSession(session);
932 }
933 }
934
935 return list;
936 }
937
938
944 public void removeByItemId(long itemId) throws SystemException {
945 for (ShoppingItemPrice shoppingItemPrice : findByItemId(itemId)) {
946 remove(shoppingItemPrice);
947 }
948 }
949
950
955 public void removeAll() throws SystemException {
956 for (ShoppingItemPrice shoppingItemPrice : findAll()) {
957 remove(shoppingItemPrice);
958 }
959 }
960
961
968 public int countByItemId(long itemId) throws SystemException {
969 Object[] finderArgs = new Object[] { itemId };
970
971 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_ITEMID,
972 finderArgs, this);
973
974 if (count == null) {
975 StringBundler query = new StringBundler(2);
976
977 query.append(_SQL_COUNT_SHOPPINGITEMPRICE_WHERE);
978
979 query.append(_FINDER_COLUMN_ITEMID_ITEMID_2);
980
981 String sql = query.toString();
982
983 Session session = null;
984
985 try {
986 session = openSession();
987
988 Query q = session.createQuery(sql);
989
990 QueryPos qPos = QueryPos.getInstance(q);
991
992 qPos.add(itemId);
993
994 count = (Long)q.uniqueResult();
995 }
996 catch (Exception e) {
997 throw processException(e);
998 }
999 finally {
1000 if (count == null) {
1001 count = Long.valueOf(0);
1002 }
1003
1004 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_ITEMID,
1005 finderArgs, count);
1006
1007 closeSession(session);
1008 }
1009 }
1010
1011 return count.intValue();
1012 }
1013
1014
1020 public int countAll() throws SystemException {
1021 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1022 FINDER_ARGS_EMPTY, this);
1023
1024 if (count == null) {
1025 Session session = null;
1026
1027 try {
1028 session = openSession();
1029
1030 Query q = session.createQuery(_SQL_COUNT_SHOPPINGITEMPRICE);
1031
1032 count = (Long)q.uniqueResult();
1033 }
1034 catch (Exception e) {
1035 throw processException(e);
1036 }
1037 finally {
1038 if (count == null) {
1039 count = Long.valueOf(0);
1040 }
1041
1042 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1043 FINDER_ARGS_EMPTY, count);
1044
1045 closeSession(session);
1046 }
1047 }
1048
1049 return count.intValue();
1050 }
1051
1052
1055 public void afterPropertiesSet() {
1056 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1057 com.liferay.portal.util.PropsUtil.get(
1058 "value.object.listener.com.liferay.portlet.shopping.model.ShoppingItemPrice")));
1059
1060 if (listenerClassNames.length > 0) {
1061 try {
1062 List<ModelListener<ShoppingItemPrice>> listenersList = new ArrayList<ModelListener<ShoppingItemPrice>>();
1063
1064 for (String listenerClassName : listenerClassNames) {
1065 listenersList.add((ModelListener<ShoppingItemPrice>)InstanceFactory.newInstance(
1066 listenerClassName));
1067 }
1068
1069 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1070 }
1071 catch (Exception e) {
1072 _log.error(e);
1073 }
1074 }
1075 }
1076
1077 public void destroy() {
1078 EntityCacheUtil.removeCache(ShoppingItemPriceImpl.class.getName());
1079 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1080 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1081 }
1082
1083 @BeanReference(type = ShoppingCartPersistence.class)
1084 protected ShoppingCartPersistence shoppingCartPersistence;
1085 @BeanReference(type = ShoppingCategoryPersistence.class)
1086 protected ShoppingCategoryPersistence shoppingCategoryPersistence;
1087 @BeanReference(type = ShoppingCouponPersistence.class)
1088 protected ShoppingCouponPersistence shoppingCouponPersistence;
1089 @BeanReference(type = ShoppingItemPersistence.class)
1090 protected ShoppingItemPersistence shoppingItemPersistence;
1091 @BeanReference(type = ShoppingItemFieldPersistence.class)
1092 protected ShoppingItemFieldPersistence shoppingItemFieldPersistence;
1093 @BeanReference(type = ShoppingItemPricePersistence.class)
1094 protected ShoppingItemPricePersistence shoppingItemPricePersistence;
1095 @BeanReference(type = ShoppingOrderPersistence.class)
1096 protected ShoppingOrderPersistence shoppingOrderPersistence;
1097 @BeanReference(type = ShoppingOrderItemPersistence.class)
1098 protected ShoppingOrderItemPersistence shoppingOrderItemPersistence;
1099 @BeanReference(type = ResourcePersistence.class)
1100 protected ResourcePersistence resourcePersistence;
1101 @BeanReference(type = UserPersistence.class)
1102 protected UserPersistence userPersistence;
1103 private static final String _SQL_SELECT_SHOPPINGITEMPRICE = "SELECT shoppingItemPrice FROM ShoppingItemPrice shoppingItemPrice";
1104 private static final String _SQL_SELECT_SHOPPINGITEMPRICE_WHERE = "SELECT shoppingItemPrice FROM ShoppingItemPrice shoppingItemPrice WHERE ";
1105 private static final String _SQL_COUNT_SHOPPINGITEMPRICE = "SELECT COUNT(shoppingItemPrice) FROM ShoppingItemPrice shoppingItemPrice";
1106 private static final String _SQL_COUNT_SHOPPINGITEMPRICE_WHERE = "SELECT COUNT(shoppingItemPrice) FROM ShoppingItemPrice shoppingItemPrice WHERE ";
1107 private static final String _FINDER_COLUMN_ITEMID_ITEMID_2 = "shoppingItemPrice.itemId = ?";
1108 private static final String _ORDER_BY_ENTITY_ALIAS = "shoppingItemPrice.";
1109 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ShoppingItemPrice exists with the primary key ";
1110 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ShoppingItemPrice exists with the key {";
1111 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1112 private static Log _log = LogFactoryUtil.getLog(ShoppingItemPricePersistenceImpl.class);
1113 private static ShoppingItemPrice _nullShoppingItemPrice = new ShoppingItemPriceImpl() {
1114 @Override
1115 public Object clone() {
1116 return this;
1117 }
1118
1119 @Override
1120 public CacheModel<ShoppingItemPrice> toCacheModel() {
1121 return _nullShoppingItemPriceCacheModel;
1122 }
1123 };
1124
1125 private static CacheModel<ShoppingItemPrice> _nullShoppingItemPriceCacheModel =
1126 new CacheModel<ShoppingItemPrice>() {
1127 public ShoppingItemPrice toEntityModel() {
1128 return _nullShoppingItemPrice;
1129 }
1130 };
1131 }