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.UserPersistence;
039 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
040
041 import com.liferay.portlet.shopping.NoSuchItemPriceException;
042 import com.liferay.portlet.shopping.model.ShoppingItemPrice;
043 import com.liferay.portlet.shopping.model.impl.ShoppingItemPriceImpl;
044 import com.liferay.portlet.shopping.model.impl.ShoppingItemPriceModelImpl;
045
046 import java.io.Serializable;
047
048 import java.util.ArrayList;
049 import java.util.Collections;
050 import java.util.List;
051
052
064 public class ShoppingItemPricePersistenceImpl extends BasePersistenceImpl<ShoppingItemPrice>
065 implements ShoppingItemPricePersistence {
066
071 public static final String FINDER_CLASS_NAME_ENTITY = ShoppingItemPriceImpl.class.getName();
072 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
073 ".List1";
074 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
075 ".List2";
076 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_ITEMID = new FinderPath(ShoppingItemPriceModelImpl.ENTITY_CACHE_ENABLED,
077 ShoppingItemPriceModelImpl.FINDER_CACHE_ENABLED,
078 ShoppingItemPriceImpl.class,
079 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByItemId",
080 new String[] {
081 Long.class.getName(),
082
083 "java.lang.Integer", "java.lang.Integer",
084 "com.liferay.portal.kernel.util.OrderByComparator"
085 });
086 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ITEMID =
087 new FinderPath(ShoppingItemPriceModelImpl.ENTITY_CACHE_ENABLED,
088 ShoppingItemPriceModelImpl.FINDER_CACHE_ENABLED,
089 ShoppingItemPriceImpl.class,
090 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByItemId",
091 new String[] { Long.class.getName() },
092 ShoppingItemPriceModelImpl.ITEMID_COLUMN_BITMASK);
093 public static final FinderPath FINDER_PATH_COUNT_BY_ITEMID = new FinderPath(ShoppingItemPriceModelImpl.ENTITY_CACHE_ENABLED,
094 ShoppingItemPriceModelImpl.FINDER_CACHE_ENABLED, Long.class,
095 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByItemId",
096 new String[] { Long.class.getName() });
097 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(ShoppingItemPriceModelImpl.ENTITY_CACHE_ENABLED,
098 ShoppingItemPriceModelImpl.FINDER_CACHE_ENABLED,
099 ShoppingItemPriceImpl.class,
100 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
101 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(ShoppingItemPriceModelImpl.ENTITY_CACHE_ENABLED,
102 ShoppingItemPriceModelImpl.FINDER_CACHE_ENABLED,
103 ShoppingItemPriceImpl.class,
104 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
105 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ShoppingItemPriceModelImpl.ENTITY_CACHE_ENABLED,
106 ShoppingItemPriceModelImpl.FINDER_CACHE_ENABLED, Long.class,
107 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
108
109
114 public void cacheResult(ShoppingItemPrice shoppingItemPrice) {
115 EntityCacheUtil.putResult(ShoppingItemPriceModelImpl.ENTITY_CACHE_ENABLED,
116 ShoppingItemPriceImpl.class, shoppingItemPrice.getPrimaryKey(),
117 shoppingItemPrice);
118
119 shoppingItemPrice.resetOriginalValues();
120 }
121
122
127 public void cacheResult(List<ShoppingItemPrice> shoppingItemPrices) {
128 for (ShoppingItemPrice shoppingItemPrice : shoppingItemPrices) {
129 if (EntityCacheUtil.getResult(
130 ShoppingItemPriceModelImpl.ENTITY_CACHE_ENABLED,
131 ShoppingItemPriceImpl.class,
132 shoppingItemPrice.getPrimaryKey()) == null) {
133 cacheResult(shoppingItemPrice);
134 }
135 else {
136 shoppingItemPrice.resetOriginalValues();
137 }
138 }
139 }
140
141
148 @Override
149 public void clearCache() {
150 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
151 CacheRegistryUtil.clear(ShoppingItemPriceImpl.class.getName());
152 }
153
154 EntityCacheUtil.clearCache(ShoppingItemPriceImpl.class.getName());
155
156 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
157 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
158 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
159 }
160
161
168 @Override
169 public void clearCache(ShoppingItemPrice shoppingItemPrice) {
170 EntityCacheUtil.removeResult(ShoppingItemPriceModelImpl.ENTITY_CACHE_ENABLED,
171 ShoppingItemPriceImpl.class, shoppingItemPrice.getPrimaryKey());
172
173 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
174 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
175 }
176
177 @Override
178 public void clearCache(List<ShoppingItemPrice> shoppingItemPrices) {
179 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
180 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
181
182 for (ShoppingItemPrice shoppingItemPrice : shoppingItemPrices) {
183 EntityCacheUtil.removeResult(ShoppingItemPriceModelImpl.ENTITY_CACHE_ENABLED,
184 ShoppingItemPriceImpl.class, shoppingItemPrice.getPrimaryKey());
185 }
186 }
187
188
194 public ShoppingItemPrice create(long itemPriceId) {
195 ShoppingItemPrice shoppingItemPrice = new ShoppingItemPriceImpl();
196
197 shoppingItemPrice.setNew(true);
198 shoppingItemPrice.setPrimaryKey(itemPriceId);
199
200 return shoppingItemPrice;
201 }
202
203
211 public ShoppingItemPrice remove(long itemPriceId)
212 throws NoSuchItemPriceException, SystemException {
213 return remove(Long.valueOf(itemPriceId));
214 }
215
216
224 @Override
225 public ShoppingItemPrice remove(Serializable primaryKey)
226 throws NoSuchItemPriceException, SystemException {
227 Session session = null;
228
229 try {
230 session = openSession();
231
232 ShoppingItemPrice shoppingItemPrice = (ShoppingItemPrice)session.get(ShoppingItemPriceImpl.class,
233 primaryKey);
234
235 if (shoppingItemPrice == null) {
236 if (_log.isWarnEnabled()) {
237 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
238 }
239
240 throw new NoSuchItemPriceException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
241 primaryKey);
242 }
243
244 return remove(shoppingItemPrice);
245 }
246 catch (NoSuchItemPriceException nsee) {
247 throw nsee;
248 }
249 catch (Exception e) {
250 throw processException(e);
251 }
252 finally {
253 closeSession(session);
254 }
255 }
256
257 @Override
258 protected ShoppingItemPrice removeImpl(ShoppingItemPrice shoppingItemPrice)
259 throws SystemException {
260 shoppingItemPrice = toUnwrappedModel(shoppingItemPrice);
261
262 Session session = null;
263
264 try {
265 session = openSession();
266
267 if (shoppingItemPrice.isCachedModel()) {
268 shoppingItemPrice = (ShoppingItemPrice)session.get(ShoppingItemPriceImpl.class,
269 shoppingItemPrice.getPrimaryKeyObj());
270 }
271
272 session.delete(shoppingItemPrice);
273 }
274 catch (Exception e) {
275 throw processException(e);
276 }
277 finally {
278 closeSession(session);
279 }
280
281 clearCache(shoppingItemPrice);
282
283 return shoppingItemPrice;
284 }
285
286 @Override
287 public ShoppingItemPrice updateImpl(
288 com.liferay.portlet.shopping.model.ShoppingItemPrice shoppingItemPrice)
289 throws SystemException {
290 shoppingItemPrice = toUnwrappedModel(shoppingItemPrice);
291
292 boolean isNew = shoppingItemPrice.isNew();
293
294 ShoppingItemPriceModelImpl shoppingItemPriceModelImpl = (ShoppingItemPriceModelImpl)shoppingItemPrice;
295
296 Session session = null;
297
298 try {
299 session = openSession();
300
301 if (shoppingItemPrice.isNew()) {
302 session.save(shoppingItemPrice);
303
304 shoppingItemPrice.setNew(false);
305 }
306 else {
307 session.merge(shoppingItemPrice);
308 }
309 }
310 catch (Exception e) {
311 throw processException(e);
312 }
313 finally {
314 closeSession(session);
315 }
316
317 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
318
319 if (isNew || !ShoppingItemPriceModelImpl.COLUMN_BITMASK_ENABLED) {
320 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
321 }
322
323 else {
324 if ((shoppingItemPriceModelImpl.getColumnBitmask() &
325 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ITEMID.getColumnBitmask()) != 0) {
326 Object[] args = new Object[] {
327 Long.valueOf(shoppingItemPriceModelImpl.getOriginalItemId())
328 };
329
330 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ITEMID, args);
331 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ITEMID,
332 args);
333
334 args = new Object[] {
335 Long.valueOf(shoppingItemPriceModelImpl.getItemId())
336 };
337
338 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ITEMID, args);
339 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ITEMID,
340 args);
341 }
342 }
343
344 EntityCacheUtil.putResult(ShoppingItemPriceModelImpl.ENTITY_CACHE_ENABLED,
345 ShoppingItemPriceImpl.class, shoppingItemPrice.getPrimaryKey(),
346 shoppingItemPrice);
347
348 return shoppingItemPrice;
349 }
350
351 protected ShoppingItemPrice toUnwrappedModel(
352 ShoppingItemPrice shoppingItemPrice) {
353 if (shoppingItemPrice instanceof ShoppingItemPriceImpl) {
354 return shoppingItemPrice;
355 }
356
357 ShoppingItemPriceImpl shoppingItemPriceImpl = new ShoppingItemPriceImpl();
358
359 shoppingItemPriceImpl.setNew(shoppingItemPrice.isNew());
360 shoppingItemPriceImpl.setPrimaryKey(shoppingItemPrice.getPrimaryKey());
361
362 shoppingItemPriceImpl.setItemPriceId(shoppingItemPrice.getItemPriceId());
363 shoppingItemPriceImpl.setItemId(shoppingItemPrice.getItemId());
364 shoppingItemPriceImpl.setMinQuantity(shoppingItemPrice.getMinQuantity());
365 shoppingItemPriceImpl.setMaxQuantity(shoppingItemPrice.getMaxQuantity());
366 shoppingItemPriceImpl.setPrice(shoppingItemPrice.getPrice());
367 shoppingItemPriceImpl.setDiscount(shoppingItemPrice.getDiscount());
368 shoppingItemPriceImpl.setTaxable(shoppingItemPrice.isTaxable());
369 shoppingItemPriceImpl.setShipping(shoppingItemPrice.getShipping());
370 shoppingItemPriceImpl.setUseShippingFormula(shoppingItemPrice.isUseShippingFormula());
371 shoppingItemPriceImpl.setStatus(shoppingItemPrice.getStatus());
372
373 return shoppingItemPriceImpl;
374 }
375
376
384 @Override
385 public ShoppingItemPrice findByPrimaryKey(Serializable primaryKey)
386 throws NoSuchModelException, SystemException {
387 return findByPrimaryKey(((Long)primaryKey).longValue());
388 }
389
390
398 public ShoppingItemPrice findByPrimaryKey(long itemPriceId)
399 throws NoSuchItemPriceException, SystemException {
400 ShoppingItemPrice shoppingItemPrice = fetchByPrimaryKey(itemPriceId);
401
402 if (shoppingItemPrice == null) {
403 if (_log.isWarnEnabled()) {
404 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + itemPriceId);
405 }
406
407 throw new NoSuchItemPriceException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
408 itemPriceId);
409 }
410
411 return shoppingItemPrice;
412 }
413
414
421 @Override
422 public ShoppingItemPrice fetchByPrimaryKey(Serializable primaryKey)
423 throws SystemException {
424 return fetchByPrimaryKey(((Long)primaryKey).longValue());
425 }
426
427
434 public ShoppingItemPrice fetchByPrimaryKey(long itemPriceId)
435 throws SystemException {
436 ShoppingItemPrice shoppingItemPrice = (ShoppingItemPrice)EntityCacheUtil.getResult(ShoppingItemPriceModelImpl.ENTITY_CACHE_ENABLED,
437 ShoppingItemPriceImpl.class, itemPriceId);
438
439 if (shoppingItemPrice == _nullShoppingItemPrice) {
440 return null;
441 }
442
443 if (shoppingItemPrice == null) {
444 Session session = null;
445
446 boolean hasException = false;
447
448 try {
449 session = openSession();
450
451 shoppingItemPrice = (ShoppingItemPrice)session.get(ShoppingItemPriceImpl.class,
452 Long.valueOf(itemPriceId));
453 }
454 catch (Exception e) {
455 hasException = true;
456
457 throw processException(e);
458 }
459 finally {
460 if (shoppingItemPrice != null) {
461 cacheResult(shoppingItemPrice);
462 }
463 else if (!hasException) {
464 EntityCacheUtil.putResult(ShoppingItemPriceModelImpl.ENTITY_CACHE_ENABLED,
465 ShoppingItemPriceImpl.class, itemPriceId,
466 _nullShoppingItemPrice);
467 }
468
469 closeSession(session);
470 }
471 }
472
473 return shoppingItemPrice;
474 }
475
476
483 public List<ShoppingItemPrice> findByItemId(long itemId)
484 throws SystemException {
485 return findByItemId(itemId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
486 }
487
488
501 public List<ShoppingItemPrice> findByItemId(long itemId, int start, int end)
502 throws SystemException {
503 return findByItemId(itemId, start, end, null);
504 }
505
506
520 public List<ShoppingItemPrice> findByItemId(long itemId, int start,
521 int end, OrderByComparator orderByComparator) throws SystemException {
522 FinderPath finderPath = null;
523 Object[] finderArgs = null;
524
525 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
526 (orderByComparator == null)) {
527 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ITEMID;
528 finderArgs = new Object[] { itemId };
529 }
530 else {
531 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_ITEMID;
532 finderArgs = new Object[] { itemId, start, end, orderByComparator };
533 }
534
535 List<ShoppingItemPrice> list = (List<ShoppingItemPrice>)FinderCacheUtil.getResult(finderPath,
536 finderArgs, this);
537
538 if ((list != null) && !list.isEmpty()) {
539 for (ShoppingItemPrice shoppingItemPrice : list) {
540 if ((itemId != shoppingItemPrice.getItemId())) {
541 list = null;
542
543 break;
544 }
545 }
546 }
547
548 if (list == null) {
549 StringBundler query = null;
550
551 if (orderByComparator != null) {
552 query = new StringBundler(3 +
553 (orderByComparator.getOrderByFields().length * 3));
554 }
555 else {
556 query = new StringBundler(3);
557 }
558
559 query.append(_SQL_SELECT_SHOPPINGITEMPRICE_WHERE);
560
561 query.append(_FINDER_COLUMN_ITEMID_ITEMID_2);
562
563 if (orderByComparator != null) {
564 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
565 orderByComparator);
566 }
567
568 else {
569 query.append(ShoppingItemPriceModelImpl.ORDER_BY_JPQL);
570 }
571
572 String sql = query.toString();
573
574 Session session = null;
575
576 try {
577 session = openSession();
578
579 Query q = session.createQuery(sql);
580
581 QueryPos qPos = QueryPos.getInstance(q);
582
583 qPos.add(itemId);
584
585 list = (List<ShoppingItemPrice>)QueryUtil.list(q, getDialect(),
586 start, end);
587 }
588 catch (Exception e) {
589 throw processException(e);
590 }
591 finally {
592 if (list == null) {
593 FinderCacheUtil.removeResult(finderPath, finderArgs);
594 }
595 else {
596 cacheResult(list);
597
598 FinderCacheUtil.putResult(finderPath, finderArgs, list);
599 }
600
601 closeSession(session);
602 }
603 }
604
605 return list;
606 }
607
608
617 public ShoppingItemPrice findByItemId_First(long itemId,
618 OrderByComparator orderByComparator)
619 throws NoSuchItemPriceException, SystemException {
620 ShoppingItemPrice shoppingItemPrice = fetchByItemId_First(itemId,
621 orderByComparator);
622
623 if (shoppingItemPrice != null) {
624 return shoppingItemPrice;
625 }
626
627 StringBundler msg = new StringBundler(4);
628
629 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
630
631 msg.append("itemId=");
632 msg.append(itemId);
633
634 msg.append(StringPool.CLOSE_CURLY_BRACE);
635
636 throw new NoSuchItemPriceException(msg.toString());
637 }
638
639
647 public ShoppingItemPrice fetchByItemId_First(long itemId,
648 OrderByComparator orderByComparator) throws SystemException {
649 List<ShoppingItemPrice> list = findByItemId(itemId, 0, 1,
650 orderByComparator);
651
652 if (!list.isEmpty()) {
653 return list.get(0);
654 }
655
656 return null;
657 }
658
659
668 public ShoppingItemPrice findByItemId_Last(long itemId,
669 OrderByComparator orderByComparator)
670 throws NoSuchItemPriceException, SystemException {
671 ShoppingItemPrice shoppingItemPrice = fetchByItemId_Last(itemId,
672 orderByComparator);
673
674 if (shoppingItemPrice != null) {
675 return shoppingItemPrice;
676 }
677
678 StringBundler msg = new StringBundler(4);
679
680 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
681
682 msg.append("itemId=");
683 msg.append(itemId);
684
685 msg.append(StringPool.CLOSE_CURLY_BRACE);
686
687 throw new NoSuchItemPriceException(msg.toString());
688 }
689
690
698 public ShoppingItemPrice fetchByItemId_Last(long itemId,
699 OrderByComparator orderByComparator) throws SystemException {
700 int count = countByItemId(itemId);
701
702 List<ShoppingItemPrice> list = findByItemId(itemId, count - 1, count,
703 orderByComparator);
704
705 if (!list.isEmpty()) {
706 return list.get(0);
707 }
708
709 return null;
710 }
711
712
722 public ShoppingItemPrice[] findByItemId_PrevAndNext(long itemPriceId,
723 long itemId, OrderByComparator orderByComparator)
724 throws NoSuchItemPriceException, SystemException {
725 ShoppingItemPrice shoppingItemPrice = findByPrimaryKey(itemPriceId);
726
727 Session session = null;
728
729 try {
730 session = openSession();
731
732 ShoppingItemPrice[] array = new ShoppingItemPriceImpl[3];
733
734 array[0] = getByItemId_PrevAndNext(session, shoppingItemPrice,
735 itemId, orderByComparator, true);
736
737 array[1] = shoppingItemPrice;
738
739 array[2] = getByItemId_PrevAndNext(session, shoppingItemPrice,
740 itemId, orderByComparator, false);
741
742 return array;
743 }
744 catch (Exception e) {
745 throw processException(e);
746 }
747 finally {
748 closeSession(session);
749 }
750 }
751
752 protected ShoppingItemPrice getByItemId_PrevAndNext(Session session,
753 ShoppingItemPrice shoppingItemPrice, long itemId,
754 OrderByComparator orderByComparator, boolean previous) {
755 StringBundler query = null;
756
757 if (orderByComparator != null) {
758 query = new StringBundler(6 +
759 (orderByComparator.getOrderByFields().length * 6));
760 }
761 else {
762 query = new StringBundler(3);
763 }
764
765 query.append(_SQL_SELECT_SHOPPINGITEMPRICE_WHERE);
766
767 query.append(_FINDER_COLUMN_ITEMID_ITEMID_2);
768
769 if (orderByComparator != null) {
770 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
771
772 if (orderByConditionFields.length > 0) {
773 query.append(WHERE_AND);
774 }
775
776 for (int i = 0; i < orderByConditionFields.length; i++) {
777 query.append(_ORDER_BY_ENTITY_ALIAS);
778 query.append(orderByConditionFields[i]);
779
780 if ((i + 1) < orderByConditionFields.length) {
781 if (orderByComparator.isAscending() ^ previous) {
782 query.append(WHERE_GREATER_THAN_HAS_NEXT);
783 }
784 else {
785 query.append(WHERE_LESSER_THAN_HAS_NEXT);
786 }
787 }
788 else {
789 if (orderByComparator.isAscending() ^ previous) {
790 query.append(WHERE_GREATER_THAN);
791 }
792 else {
793 query.append(WHERE_LESSER_THAN);
794 }
795 }
796 }
797
798 query.append(ORDER_BY_CLAUSE);
799
800 String[] orderByFields = orderByComparator.getOrderByFields();
801
802 for (int i = 0; i < orderByFields.length; i++) {
803 query.append(_ORDER_BY_ENTITY_ALIAS);
804 query.append(orderByFields[i]);
805
806 if ((i + 1) < orderByFields.length) {
807 if (orderByComparator.isAscending() ^ previous) {
808 query.append(ORDER_BY_ASC_HAS_NEXT);
809 }
810 else {
811 query.append(ORDER_BY_DESC_HAS_NEXT);
812 }
813 }
814 else {
815 if (orderByComparator.isAscending() ^ previous) {
816 query.append(ORDER_BY_ASC);
817 }
818 else {
819 query.append(ORDER_BY_DESC);
820 }
821 }
822 }
823 }
824
825 else {
826 query.append(ShoppingItemPriceModelImpl.ORDER_BY_JPQL);
827 }
828
829 String sql = query.toString();
830
831 Query q = session.createQuery(sql);
832
833 q.setFirstResult(0);
834 q.setMaxResults(2);
835
836 QueryPos qPos = QueryPos.getInstance(q);
837
838 qPos.add(itemId);
839
840 if (orderByComparator != null) {
841 Object[] values = orderByComparator.getOrderByConditionValues(shoppingItemPrice);
842
843 for (Object value : values) {
844 qPos.add(value);
845 }
846 }
847
848 List<ShoppingItemPrice> list = q.list();
849
850 if (list.size() == 2) {
851 return list.get(1);
852 }
853 else {
854 return null;
855 }
856 }
857
858
864 public List<ShoppingItemPrice> findAll() throws SystemException {
865 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
866 }
867
868
880 public List<ShoppingItemPrice> findAll(int start, int end)
881 throws SystemException {
882 return findAll(start, end, null);
883 }
884
885
898 public List<ShoppingItemPrice> findAll(int start, int end,
899 OrderByComparator orderByComparator) throws SystemException {
900 FinderPath finderPath = null;
901 Object[] finderArgs = new Object[] { start, end, orderByComparator };
902
903 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
904 (orderByComparator == null)) {
905 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
906 finderArgs = FINDER_ARGS_EMPTY;
907 }
908 else {
909 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
910 finderArgs = new Object[] { start, end, orderByComparator };
911 }
912
913 List<ShoppingItemPrice> list = (List<ShoppingItemPrice>)FinderCacheUtil.getResult(finderPath,
914 finderArgs, this);
915
916 if (list == null) {
917 StringBundler query = null;
918 String sql = null;
919
920 if (orderByComparator != null) {
921 query = new StringBundler(2 +
922 (orderByComparator.getOrderByFields().length * 3));
923
924 query.append(_SQL_SELECT_SHOPPINGITEMPRICE);
925
926 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
927 orderByComparator);
928
929 sql = query.toString();
930 }
931 else {
932 sql = _SQL_SELECT_SHOPPINGITEMPRICE.concat(ShoppingItemPriceModelImpl.ORDER_BY_JPQL);
933 }
934
935 Session session = null;
936
937 try {
938 session = openSession();
939
940 Query q = session.createQuery(sql);
941
942 if (orderByComparator == null) {
943 list = (List<ShoppingItemPrice>)QueryUtil.list(q,
944 getDialect(), start, end, false);
945
946 Collections.sort(list);
947 }
948 else {
949 list = (List<ShoppingItemPrice>)QueryUtil.list(q,
950 getDialect(), start, end);
951 }
952 }
953 catch (Exception e) {
954 throw processException(e);
955 }
956 finally {
957 if (list == null) {
958 FinderCacheUtil.removeResult(finderPath, finderArgs);
959 }
960 else {
961 cacheResult(list);
962
963 FinderCacheUtil.putResult(finderPath, finderArgs, list);
964 }
965
966 closeSession(session);
967 }
968 }
969
970 return list;
971 }
972
973
979 public void removeByItemId(long itemId) throws SystemException {
980 for (ShoppingItemPrice shoppingItemPrice : findByItemId(itemId)) {
981 remove(shoppingItemPrice);
982 }
983 }
984
985
990 public void removeAll() throws SystemException {
991 for (ShoppingItemPrice shoppingItemPrice : findAll()) {
992 remove(shoppingItemPrice);
993 }
994 }
995
996
1003 public int countByItemId(long itemId) throws SystemException {
1004 Object[] finderArgs = new Object[] { itemId };
1005
1006 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_ITEMID,
1007 finderArgs, this);
1008
1009 if (count == null) {
1010 StringBundler query = new StringBundler(2);
1011
1012 query.append(_SQL_COUNT_SHOPPINGITEMPRICE_WHERE);
1013
1014 query.append(_FINDER_COLUMN_ITEMID_ITEMID_2);
1015
1016 String sql = query.toString();
1017
1018 Session session = null;
1019
1020 try {
1021 session = openSession();
1022
1023 Query q = session.createQuery(sql);
1024
1025 QueryPos qPos = QueryPos.getInstance(q);
1026
1027 qPos.add(itemId);
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_BY_ITEMID,
1040 finderArgs, count);
1041
1042 closeSession(session);
1043 }
1044 }
1045
1046 return count.intValue();
1047 }
1048
1049
1055 public int countAll() throws SystemException {
1056 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1057 FINDER_ARGS_EMPTY, this);
1058
1059 if (count == null) {
1060 Session session = null;
1061
1062 try {
1063 session = openSession();
1064
1065 Query q = session.createQuery(_SQL_COUNT_SHOPPINGITEMPRICE);
1066
1067 count = (Long)q.uniqueResult();
1068 }
1069 catch (Exception e) {
1070 throw processException(e);
1071 }
1072 finally {
1073 if (count == null) {
1074 count = Long.valueOf(0);
1075 }
1076
1077 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1078 FINDER_ARGS_EMPTY, count);
1079
1080 closeSession(session);
1081 }
1082 }
1083
1084 return count.intValue();
1085 }
1086
1087
1090 public void afterPropertiesSet() {
1091 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1092 com.liferay.portal.util.PropsUtil.get(
1093 "value.object.listener.com.liferay.portlet.shopping.model.ShoppingItemPrice")));
1094
1095 if (listenerClassNames.length > 0) {
1096 try {
1097 List<ModelListener<ShoppingItemPrice>> listenersList = new ArrayList<ModelListener<ShoppingItemPrice>>();
1098
1099 for (String listenerClassName : listenerClassNames) {
1100 listenersList.add((ModelListener<ShoppingItemPrice>)InstanceFactory.newInstance(
1101 listenerClassName));
1102 }
1103
1104 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1105 }
1106 catch (Exception e) {
1107 _log.error(e);
1108 }
1109 }
1110 }
1111
1112 public void destroy() {
1113 EntityCacheUtil.removeCache(ShoppingItemPriceImpl.class.getName());
1114 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1115 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1116 }
1117
1118 @BeanReference(type = ShoppingCartPersistence.class)
1119 protected ShoppingCartPersistence shoppingCartPersistence;
1120 @BeanReference(type = ShoppingCategoryPersistence.class)
1121 protected ShoppingCategoryPersistence shoppingCategoryPersistence;
1122 @BeanReference(type = ShoppingCouponPersistence.class)
1123 protected ShoppingCouponPersistence shoppingCouponPersistence;
1124 @BeanReference(type = ShoppingItemPersistence.class)
1125 protected ShoppingItemPersistence shoppingItemPersistence;
1126 @BeanReference(type = ShoppingItemFieldPersistence.class)
1127 protected ShoppingItemFieldPersistence shoppingItemFieldPersistence;
1128 @BeanReference(type = ShoppingItemPricePersistence.class)
1129 protected ShoppingItemPricePersistence shoppingItemPricePersistence;
1130 @BeanReference(type = ShoppingOrderPersistence.class)
1131 protected ShoppingOrderPersistence shoppingOrderPersistence;
1132 @BeanReference(type = ShoppingOrderItemPersistence.class)
1133 protected ShoppingOrderItemPersistence shoppingOrderItemPersistence;
1134 @BeanReference(type = UserPersistence.class)
1135 protected UserPersistence userPersistence;
1136 private static final String _SQL_SELECT_SHOPPINGITEMPRICE = "SELECT shoppingItemPrice FROM ShoppingItemPrice shoppingItemPrice";
1137 private static final String _SQL_SELECT_SHOPPINGITEMPRICE_WHERE = "SELECT shoppingItemPrice FROM ShoppingItemPrice shoppingItemPrice WHERE ";
1138 private static final String _SQL_COUNT_SHOPPINGITEMPRICE = "SELECT COUNT(shoppingItemPrice) FROM ShoppingItemPrice shoppingItemPrice";
1139 private static final String _SQL_COUNT_SHOPPINGITEMPRICE_WHERE = "SELECT COUNT(shoppingItemPrice) FROM ShoppingItemPrice shoppingItemPrice WHERE ";
1140 private static final String _FINDER_COLUMN_ITEMID_ITEMID_2 = "shoppingItemPrice.itemId = ?";
1141 private static final String _ORDER_BY_ENTITY_ALIAS = "shoppingItemPrice.";
1142 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ShoppingItemPrice exists with the primary key ";
1143 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ShoppingItemPrice exists with the key {";
1144 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1145 private static Log _log = LogFactoryUtil.getLog(ShoppingItemPricePersistenceImpl.class);
1146 private static ShoppingItemPrice _nullShoppingItemPrice = new ShoppingItemPriceImpl() {
1147 @Override
1148 public Object clone() {
1149 return this;
1150 }
1151
1152 @Override
1153 public CacheModel<ShoppingItemPrice> toCacheModel() {
1154 return _nullShoppingItemPriceCacheModel;
1155 }
1156 };
1157
1158 private static CacheModel<ShoppingItemPrice> _nullShoppingItemPriceCacheModel =
1159 new CacheModel<ShoppingItemPrice>() {
1160 public ShoppingItemPrice toEntityModel() {
1161 return _nullShoppingItemPrice;
1162 }
1163 };
1164 }