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
315 else {
316 if ((shoppingItemPriceModelImpl.getColumnBitmask() &
317 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ITEMID.getColumnBitmask()) != 0) {
318 Object[] args = new Object[] {
319 Long.valueOf(shoppingItemPriceModelImpl.getOriginalItemId())
320 };
321
322 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ITEMID, args);
323 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ITEMID,
324 args);
325
326 args = new Object[] {
327 Long.valueOf(shoppingItemPriceModelImpl.getItemId())
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 }
335
336 EntityCacheUtil.putResult(ShoppingItemPriceModelImpl.ENTITY_CACHE_ENABLED,
337 ShoppingItemPriceImpl.class, shoppingItemPrice.getPrimaryKey(),
338 shoppingItemPrice);
339
340 return shoppingItemPrice;
341 }
342
343 protected ShoppingItemPrice toUnwrappedModel(
344 ShoppingItemPrice shoppingItemPrice) {
345 if (shoppingItemPrice instanceof ShoppingItemPriceImpl) {
346 return shoppingItemPrice;
347 }
348
349 ShoppingItemPriceImpl shoppingItemPriceImpl = new ShoppingItemPriceImpl();
350
351 shoppingItemPriceImpl.setNew(shoppingItemPrice.isNew());
352 shoppingItemPriceImpl.setPrimaryKey(shoppingItemPrice.getPrimaryKey());
353
354 shoppingItemPriceImpl.setItemPriceId(shoppingItemPrice.getItemPriceId());
355 shoppingItemPriceImpl.setItemId(shoppingItemPrice.getItemId());
356 shoppingItemPriceImpl.setMinQuantity(shoppingItemPrice.getMinQuantity());
357 shoppingItemPriceImpl.setMaxQuantity(shoppingItemPrice.getMaxQuantity());
358 shoppingItemPriceImpl.setPrice(shoppingItemPrice.getPrice());
359 shoppingItemPriceImpl.setDiscount(shoppingItemPrice.getDiscount());
360 shoppingItemPriceImpl.setTaxable(shoppingItemPrice.isTaxable());
361 shoppingItemPriceImpl.setShipping(shoppingItemPrice.getShipping());
362 shoppingItemPriceImpl.setUseShippingFormula(shoppingItemPrice.isUseShippingFormula());
363 shoppingItemPriceImpl.setStatus(shoppingItemPrice.getStatus());
364
365 return shoppingItemPriceImpl;
366 }
367
368
376 @Override
377 public ShoppingItemPrice findByPrimaryKey(Serializable primaryKey)
378 throws NoSuchModelException, SystemException {
379 return findByPrimaryKey(((Long)primaryKey).longValue());
380 }
381
382
390 public ShoppingItemPrice findByPrimaryKey(long itemPriceId)
391 throws NoSuchItemPriceException, SystemException {
392 ShoppingItemPrice shoppingItemPrice = fetchByPrimaryKey(itemPriceId);
393
394 if (shoppingItemPrice == null) {
395 if (_log.isWarnEnabled()) {
396 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + itemPriceId);
397 }
398
399 throw new NoSuchItemPriceException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
400 itemPriceId);
401 }
402
403 return shoppingItemPrice;
404 }
405
406
413 @Override
414 public ShoppingItemPrice fetchByPrimaryKey(Serializable primaryKey)
415 throws SystemException {
416 return fetchByPrimaryKey(((Long)primaryKey).longValue());
417 }
418
419
426 public ShoppingItemPrice fetchByPrimaryKey(long itemPriceId)
427 throws SystemException {
428 ShoppingItemPrice shoppingItemPrice = (ShoppingItemPrice)EntityCacheUtil.getResult(ShoppingItemPriceModelImpl.ENTITY_CACHE_ENABLED,
429 ShoppingItemPriceImpl.class, itemPriceId);
430
431 if (shoppingItemPrice == _nullShoppingItemPrice) {
432 return null;
433 }
434
435 if (shoppingItemPrice == null) {
436 Session session = null;
437
438 boolean hasException = false;
439
440 try {
441 session = openSession();
442
443 shoppingItemPrice = (ShoppingItemPrice)session.get(ShoppingItemPriceImpl.class,
444 Long.valueOf(itemPriceId));
445 }
446 catch (Exception e) {
447 hasException = true;
448
449 throw processException(e);
450 }
451 finally {
452 if (shoppingItemPrice != null) {
453 cacheResult(shoppingItemPrice);
454 }
455 else if (!hasException) {
456 EntityCacheUtil.putResult(ShoppingItemPriceModelImpl.ENTITY_CACHE_ENABLED,
457 ShoppingItemPriceImpl.class, itemPriceId,
458 _nullShoppingItemPrice);
459 }
460
461 closeSession(session);
462 }
463 }
464
465 return shoppingItemPrice;
466 }
467
468
475 public List<ShoppingItemPrice> findByItemId(long itemId)
476 throws SystemException {
477 return findByItemId(itemId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
478 }
479
480
493 public List<ShoppingItemPrice> findByItemId(long itemId, int start, int end)
494 throws SystemException {
495 return findByItemId(itemId, start, end, null);
496 }
497
498
512 public List<ShoppingItemPrice> findByItemId(long itemId, int start,
513 int end, OrderByComparator orderByComparator) throws SystemException {
514 FinderPath finderPath = null;
515 Object[] finderArgs = null;
516
517 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
518 (orderByComparator == null)) {
519 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ITEMID;
520 finderArgs = new Object[] { itemId };
521 }
522 else {
523 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_ITEMID;
524 finderArgs = new Object[] { itemId, start, end, orderByComparator };
525 }
526
527 List<ShoppingItemPrice> list = (List<ShoppingItemPrice>)FinderCacheUtil.getResult(finderPath,
528 finderArgs, this);
529
530 if ((list != null) && !list.isEmpty()) {
531 for (ShoppingItemPrice shoppingItemPrice : list) {
532 if ((itemId != shoppingItemPrice.getItemId())) {
533 list = null;
534
535 break;
536 }
537 }
538 }
539
540 if (list == null) {
541 StringBundler query = null;
542
543 if (orderByComparator != null) {
544 query = new StringBundler(3 +
545 (orderByComparator.getOrderByFields().length * 3));
546 }
547 else {
548 query = new StringBundler(3);
549 }
550
551 query.append(_SQL_SELECT_SHOPPINGITEMPRICE_WHERE);
552
553 query.append(_FINDER_COLUMN_ITEMID_ITEMID_2);
554
555 if (orderByComparator != null) {
556 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
557 orderByComparator);
558 }
559
560 else {
561 query.append(ShoppingItemPriceModelImpl.ORDER_BY_JPQL);
562 }
563
564 String sql = query.toString();
565
566 Session session = null;
567
568 try {
569 session = openSession();
570
571 Query q = session.createQuery(sql);
572
573 QueryPos qPos = QueryPos.getInstance(q);
574
575 qPos.add(itemId);
576
577 list = (List<ShoppingItemPrice>)QueryUtil.list(q, getDialect(),
578 start, end);
579 }
580 catch (Exception e) {
581 throw processException(e);
582 }
583 finally {
584 if (list == null) {
585 FinderCacheUtil.removeResult(finderPath, finderArgs);
586 }
587 else {
588 cacheResult(list);
589
590 FinderCacheUtil.putResult(finderPath, finderArgs, list);
591 }
592
593 closeSession(session);
594 }
595 }
596
597 return list;
598 }
599
600
609 public ShoppingItemPrice findByItemId_First(long itemId,
610 OrderByComparator orderByComparator)
611 throws NoSuchItemPriceException, SystemException {
612 ShoppingItemPrice shoppingItemPrice = fetchByItemId_First(itemId,
613 orderByComparator);
614
615 if (shoppingItemPrice != null) {
616 return shoppingItemPrice;
617 }
618
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
631
639 public ShoppingItemPrice fetchByItemId_First(long itemId,
640 OrderByComparator orderByComparator) throws SystemException {
641 List<ShoppingItemPrice> list = findByItemId(itemId, 0, 1,
642 orderByComparator);
643
644 if (!list.isEmpty()) {
645 return list.get(0);
646 }
647
648 return null;
649 }
650
651
660 public ShoppingItemPrice findByItemId_Last(long itemId,
661 OrderByComparator orderByComparator)
662 throws NoSuchItemPriceException, SystemException {
663 ShoppingItemPrice shoppingItemPrice = fetchByItemId_Last(itemId,
664 orderByComparator);
665
666 if (shoppingItemPrice != null) {
667 return shoppingItemPrice;
668 }
669
670 StringBundler msg = new StringBundler(4);
671
672 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
673
674 msg.append("itemId=");
675 msg.append(itemId);
676
677 msg.append(StringPool.CLOSE_CURLY_BRACE);
678
679 throw new NoSuchItemPriceException(msg.toString());
680 }
681
682
690 public ShoppingItemPrice fetchByItemId_Last(long itemId,
691 OrderByComparator orderByComparator) throws SystemException {
692 int count = countByItemId(itemId);
693
694 List<ShoppingItemPrice> list = findByItemId(itemId, count - 1, count,
695 orderByComparator);
696
697 if (!list.isEmpty()) {
698 return list.get(0);
699 }
700
701 return null;
702 }
703
704
714 public ShoppingItemPrice[] findByItemId_PrevAndNext(long itemPriceId,
715 long itemId, OrderByComparator orderByComparator)
716 throws NoSuchItemPriceException, SystemException {
717 ShoppingItemPrice shoppingItemPrice = findByPrimaryKey(itemPriceId);
718
719 Session session = null;
720
721 try {
722 session = openSession();
723
724 ShoppingItemPrice[] array = new ShoppingItemPriceImpl[3];
725
726 array[0] = getByItemId_PrevAndNext(session, shoppingItemPrice,
727 itemId, orderByComparator, true);
728
729 array[1] = shoppingItemPrice;
730
731 array[2] = getByItemId_PrevAndNext(session, shoppingItemPrice,
732 itemId, orderByComparator, false);
733
734 return array;
735 }
736 catch (Exception e) {
737 throw processException(e);
738 }
739 finally {
740 closeSession(session);
741 }
742 }
743
744 protected ShoppingItemPrice getByItemId_PrevAndNext(Session session,
745 ShoppingItemPrice shoppingItemPrice, long itemId,
746 OrderByComparator orderByComparator, boolean previous) {
747 StringBundler query = null;
748
749 if (orderByComparator != null) {
750 query = new StringBundler(6 +
751 (orderByComparator.getOrderByFields().length * 6));
752 }
753 else {
754 query = new StringBundler(3);
755 }
756
757 query.append(_SQL_SELECT_SHOPPINGITEMPRICE_WHERE);
758
759 query.append(_FINDER_COLUMN_ITEMID_ITEMID_2);
760
761 if (orderByComparator != null) {
762 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
763
764 if (orderByConditionFields.length > 0) {
765 query.append(WHERE_AND);
766 }
767
768 for (int i = 0; i < orderByConditionFields.length; i++) {
769 query.append(_ORDER_BY_ENTITY_ALIAS);
770 query.append(orderByConditionFields[i]);
771
772 if ((i + 1) < orderByConditionFields.length) {
773 if (orderByComparator.isAscending() ^ previous) {
774 query.append(WHERE_GREATER_THAN_HAS_NEXT);
775 }
776 else {
777 query.append(WHERE_LESSER_THAN_HAS_NEXT);
778 }
779 }
780 else {
781 if (orderByComparator.isAscending() ^ previous) {
782 query.append(WHERE_GREATER_THAN);
783 }
784 else {
785 query.append(WHERE_LESSER_THAN);
786 }
787 }
788 }
789
790 query.append(ORDER_BY_CLAUSE);
791
792 String[] orderByFields = orderByComparator.getOrderByFields();
793
794 for (int i = 0; i < orderByFields.length; i++) {
795 query.append(_ORDER_BY_ENTITY_ALIAS);
796 query.append(orderByFields[i]);
797
798 if ((i + 1) < orderByFields.length) {
799 if (orderByComparator.isAscending() ^ previous) {
800 query.append(ORDER_BY_ASC_HAS_NEXT);
801 }
802 else {
803 query.append(ORDER_BY_DESC_HAS_NEXT);
804 }
805 }
806 else {
807 if (orderByComparator.isAscending() ^ previous) {
808 query.append(ORDER_BY_ASC);
809 }
810 else {
811 query.append(ORDER_BY_DESC);
812 }
813 }
814 }
815 }
816
817 else {
818 query.append(ShoppingItemPriceModelImpl.ORDER_BY_JPQL);
819 }
820
821 String sql = query.toString();
822
823 Query q = session.createQuery(sql);
824
825 q.setFirstResult(0);
826 q.setMaxResults(2);
827
828 QueryPos qPos = QueryPos.getInstance(q);
829
830 qPos.add(itemId);
831
832 if (orderByComparator != null) {
833 Object[] values = orderByComparator.getOrderByConditionValues(shoppingItemPrice);
834
835 for (Object value : values) {
836 qPos.add(value);
837 }
838 }
839
840 List<ShoppingItemPrice> list = q.list();
841
842 if (list.size() == 2) {
843 return list.get(1);
844 }
845 else {
846 return null;
847 }
848 }
849
850
856 public List<ShoppingItemPrice> findAll() throws SystemException {
857 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
858 }
859
860
872 public List<ShoppingItemPrice> findAll(int start, int end)
873 throws SystemException {
874 return findAll(start, end, null);
875 }
876
877
890 public List<ShoppingItemPrice> findAll(int start, int end,
891 OrderByComparator orderByComparator) throws SystemException {
892 FinderPath finderPath = null;
893 Object[] finderArgs = new Object[] { start, end, orderByComparator };
894
895 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
896 (orderByComparator == null)) {
897 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
898 finderArgs = FINDER_ARGS_EMPTY;
899 }
900 else {
901 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
902 finderArgs = new Object[] { start, end, orderByComparator };
903 }
904
905 List<ShoppingItemPrice> list = (List<ShoppingItemPrice>)FinderCacheUtil.getResult(finderPath,
906 finderArgs, this);
907
908 if (list == null) {
909 StringBundler query = null;
910 String sql = null;
911
912 if (orderByComparator != null) {
913 query = new StringBundler(2 +
914 (orderByComparator.getOrderByFields().length * 3));
915
916 query.append(_SQL_SELECT_SHOPPINGITEMPRICE);
917
918 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
919 orderByComparator);
920
921 sql = query.toString();
922 }
923 else {
924 sql = _SQL_SELECT_SHOPPINGITEMPRICE.concat(ShoppingItemPriceModelImpl.ORDER_BY_JPQL);
925 }
926
927 Session session = null;
928
929 try {
930 session = openSession();
931
932 Query q = session.createQuery(sql);
933
934 if (orderByComparator == null) {
935 list = (List<ShoppingItemPrice>)QueryUtil.list(q,
936 getDialect(), start, end, false);
937
938 Collections.sort(list);
939 }
940 else {
941 list = (List<ShoppingItemPrice>)QueryUtil.list(q,
942 getDialect(), start, end);
943 }
944 }
945 catch (Exception e) {
946 throw processException(e);
947 }
948 finally {
949 if (list == null) {
950 FinderCacheUtil.removeResult(finderPath, finderArgs);
951 }
952 else {
953 cacheResult(list);
954
955 FinderCacheUtil.putResult(finderPath, finderArgs, list);
956 }
957
958 closeSession(session);
959 }
960 }
961
962 return list;
963 }
964
965
971 public void removeByItemId(long itemId) throws SystemException {
972 for (ShoppingItemPrice shoppingItemPrice : findByItemId(itemId)) {
973 remove(shoppingItemPrice);
974 }
975 }
976
977
982 public void removeAll() throws SystemException {
983 for (ShoppingItemPrice shoppingItemPrice : findAll()) {
984 remove(shoppingItemPrice);
985 }
986 }
987
988
995 public int countByItemId(long itemId) throws SystemException {
996 Object[] finderArgs = new Object[] { itemId };
997
998 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_ITEMID,
999 finderArgs, this);
1000
1001 if (count == null) {
1002 StringBundler query = new StringBundler(2);
1003
1004 query.append(_SQL_COUNT_SHOPPINGITEMPRICE_WHERE);
1005
1006 query.append(_FINDER_COLUMN_ITEMID_ITEMID_2);
1007
1008 String sql = query.toString();
1009
1010 Session session = null;
1011
1012 try {
1013 session = openSession();
1014
1015 Query q = session.createQuery(sql);
1016
1017 QueryPos qPos = QueryPos.getInstance(q);
1018
1019 qPos.add(itemId);
1020
1021 count = (Long)q.uniqueResult();
1022 }
1023 catch (Exception e) {
1024 throw processException(e);
1025 }
1026 finally {
1027 if (count == null) {
1028 count = Long.valueOf(0);
1029 }
1030
1031 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_ITEMID,
1032 finderArgs, count);
1033
1034 closeSession(session);
1035 }
1036 }
1037
1038 return count.intValue();
1039 }
1040
1041
1047 public int countAll() throws SystemException {
1048 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1049 FINDER_ARGS_EMPTY, this);
1050
1051 if (count == null) {
1052 Session session = null;
1053
1054 try {
1055 session = openSession();
1056
1057 Query q = session.createQuery(_SQL_COUNT_SHOPPINGITEMPRICE);
1058
1059 count = (Long)q.uniqueResult();
1060 }
1061 catch (Exception e) {
1062 throw processException(e);
1063 }
1064 finally {
1065 if (count == null) {
1066 count = Long.valueOf(0);
1067 }
1068
1069 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1070 FINDER_ARGS_EMPTY, count);
1071
1072 closeSession(session);
1073 }
1074 }
1075
1076 return count.intValue();
1077 }
1078
1079
1082 public void afterPropertiesSet() {
1083 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1084 com.liferay.portal.util.PropsUtil.get(
1085 "value.object.listener.com.liferay.portlet.shopping.model.ShoppingItemPrice")));
1086
1087 if (listenerClassNames.length > 0) {
1088 try {
1089 List<ModelListener<ShoppingItemPrice>> listenersList = new ArrayList<ModelListener<ShoppingItemPrice>>();
1090
1091 for (String listenerClassName : listenerClassNames) {
1092 Class<?> clazz = getClass();
1093
1094 listenersList.add((ModelListener<ShoppingItemPrice>)InstanceFactory.newInstance(
1095 clazz.getClassLoader(), listenerClassName));
1096 }
1097
1098 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1099 }
1100 catch (Exception e) {
1101 _log.error(e);
1102 }
1103 }
1104 }
1105
1106 public void destroy() {
1107 EntityCacheUtil.removeCache(ShoppingItemPriceImpl.class.getName());
1108 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1109 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1110 }
1111
1112 @BeanReference(type = ShoppingCartPersistence.class)
1113 protected ShoppingCartPersistence shoppingCartPersistence;
1114 @BeanReference(type = ShoppingCategoryPersistence.class)
1115 protected ShoppingCategoryPersistence shoppingCategoryPersistence;
1116 @BeanReference(type = ShoppingCouponPersistence.class)
1117 protected ShoppingCouponPersistence shoppingCouponPersistence;
1118 @BeanReference(type = ShoppingItemPersistence.class)
1119 protected ShoppingItemPersistence shoppingItemPersistence;
1120 @BeanReference(type = ShoppingItemFieldPersistence.class)
1121 protected ShoppingItemFieldPersistence shoppingItemFieldPersistence;
1122 @BeanReference(type = ShoppingItemPricePersistence.class)
1123 protected ShoppingItemPricePersistence shoppingItemPricePersistence;
1124 @BeanReference(type = ShoppingOrderPersistence.class)
1125 protected ShoppingOrderPersistence shoppingOrderPersistence;
1126 @BeanReference(type = ShoppingOrderItemPersistence.class)
1127 protected ShoppingOrderItemPersistence shoppingOrderItemPersistence;
1128 @BeanReference(type = ResourcePersistence.class)
1129 protected ResourcePersistence resourcePersistence;
1130 @BeanReference(type = UserPersistence.class)
1131 protected UserPersistence userPersistence;
1132 private static final String _SQL_SELECT_SHOPPINGITEMPRICE = "SELECT shoppingItemPrice FROM ShoppingItemPrice shoppingItemPrice";
1133 private static final String _SQL_SELECT_SHOPPINGITEMPRICE_WHERE = "SELECT shoppingItemPrice FROM ShoppingItemPrice shoppingItemPrice WHERE ";
1134 private static final String _SQL_COUNT_SHOPPINGITEMPRICE = "SELECT COUNT(shoppingItemPrice) FROM ShoppingItemPrice shoppingItemPrice";
1135 private static final String _SQL_COUNT_SHOPPINGITEMPRICE_WHERE = "SELECT COUNT(shoppingItemPrice) FROM ShoppingItemPrice shoppingItemPrice WHERE ";
1136 private static final String _FINDER_COLUMN_ITEMID_ITEMID_2 = "shoppingItemPrice.itemId = ?";
1137 private static final String _ORDER_BY_ENTITY_ALIAS = "shoppingItemPrice.";
1138 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ShoppingItemPrice exists with the primary key ";
1139 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ShoppingItemPrice exists with the key {";
1140 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1141 private static Log _log = LogFactoryUtil.getLog(ShoppingItemPricePersistenceImpl.class);
1142 private static ShoppingItemPrice _nullShoppingItemPrice = new ShoppingItemPriceImpl() {
1143 @Override
1144 public Object clone() {
1145 return this;
1146 }
1147
1148 @Override
1149 public CacheModel<ShoppingItemPrice> toCacheModel() {
1150 return _nullShoppingItemPriceCacheModel;
1151 }
1152 };
1153
1154 private static CacheModel<ShoppingItemPrice> _nullShoppingItemPriceCacheModel =
1155 new CacheModel<ShoppingItemPrice>() {
1156 public ShoppingItemPrice toEntityModel() {
1157 return _nullShoppingItemPrice;
1158 }
1159 };
1160 }