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 @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) {
531 StringBundler query = null;
532
533 if (orderByComparator != null) {
534 query = new StringBundler(3 +
535 (orderByComparator.getOrderByFields().length * 3));
536 }
537 else {
538 query = new StringBundler(3);
539 }
540
541 query.append(_SQL_SELECT_SHOPPINGITEMPRICE_WHERE);
542
543 query.append(_FINDER_COLUMN_ITEMID_ITEMID_2);
544
545 if (orderByComparator != null) {
546 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
547 orderByComparator);
548 }
549
550 else {
551 query.append(ShoppingItemPriceModelImpl.ORDER_BY_JPQL);
552 }
553
554 String sql = query.toString();
555
556 Session session = null;
557
558 try {
559 session = openSession();
560
561 Query q = session.createQuery(sql);
562
563 QueryPos qPos = QueryPos.getInstance(q);
564
565 qPos.add(itemId);
566
567 list = (List<ShoppingItemPrice>)QueryUtil.list(q, getDialect(),
568 start, end);
569 }
570 catch (Exception e) {
571 throw processException(e);
572 }
573 finally {
574 if (list == null) {
575 FinderCacheUtil.removeResult(finderPath, finderArgs);
576 }
577 else {
578 cacheResult(list);
579
580 FinderCacheUtil.putResult(finderPath, finderArgs, list);
581 }
582
583 closeSession(session);
584 }
585 }
586
587 return list;
588 }
589
590
603 public ShoppingItemPrice findByItemId_First(long itemId,
604 OrderByComparator orderByComparator)
605 throws NoSuchItemPriceException, SystemException {
606 List<ShoppingItemPrice> list = findByItemId(itemId, 0, 1,
607 orderByComparator);
608
609 if (list.isEmpty()) {
610 StringBundler msg = new StringBundler(4);
611
612 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
613
614 msg.append("itemId=");
615 msg.append(itemId);
616
617 msg.append(StringPool.CLOSE_CURLY_BRACE);
618
619 throw new NoSuchItemPriceException(msg.toString());
620 }
621 else {
622 return list.get(0);
623 }
624 }
625
626
639 public ShoppingItemPrice findByItemId_Last(long itemId,
640 OrderByComparator orderByComparator)
641 throws NoSuchItemPriceException, SystemException {
642 int count = countByItemId(itemId);
643
644 List<ShoppingItemPrice> list = findByItemId(itemId, count - 1, count,
645 orderByComparator);
646
647 if (list.isEmpty()) {
648 StringBundler msg = new StringBundler(4);
649
650 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
651
652 msg.append("itemId=");
653 msg.append(itemId);
654
655 msg.append(StringPool.CLOSE_CURLY_BRACE);
656
657 throw new NoSuchItemPriceException(msg.toString());
658 }
659 else {
660 return list.get(0);
661 }
662 }
663
664
678 public ShoppingItemPrice[] findByItemId_PrevAndNext(long itemPriceId,
679 long itemId, OrderByComparator orderByComparator)
680 throws NoSuchItemPriceException, SystemException {
681 ShoppingItemPrice shoppingItemPrice = findByPrimaryKey(itemPriceId);
682
683 Session session = null;
684
685 try {
686 session = openSession();
687
688 ShoppingItemPrice[] array = new ShoppingItemPriceImpl[3];
689
690 array[0] = getByItemId_PrevAndNext(session, shoppingItemPrice,
691 itemId, orderByComparator, true);
692
693 array[1] = shoppingItemPrice;
694
695 array[2] = getByItemId_PrevAndNext(session, shoppingItemPrice,
696 itemId, orderByComparator, false);
697
698 return array;
699 }
700 catch (Exception e) {
701 throw processException(e);
702 }
703 finally {
704 closeSession(session);
705 }
706 }
707
708 protected ShoppingItemPrice getByItemId_PrevAndNext(Session session,
709 ShoppingItemPrice shoppingItemPrice, long itemId,
710 OrderByComparator orderByComparator, boolean previous) {
711 StringBundler query = null;
712
713 if (orderByComparator != null) {
714 query = new StringBundler(6 +
715 (orderByComparator.getOrderByFields().length * 6));
716 }
717 else {
718 query = new StringBundler(3);
719 }
720
721 query.append(_SQL_SELECT_SHOPPINGITEMPRICE_WHERE);
722
723 query.append(_FINDER_COLUMN_ITEMID_ITEMID_2);
724
725 if (orderByComparator != null) {
726 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
727
728 if (orderByConditionFields.length > 0) {
729 query.append(WHERE_AND);
730 }
731
732 for (int i = 0; i < orderByConditionFields.length; i++) {
733 query.append(_ORDER_BY_ENTITY_ALIAS);
734 query.append(orderByConditionFields[i]);
735
736 if ((i + 1) < orderByConditionFields.length) {
737 if (orderByComparator.isAscending() ^ previous) {
738 query.append(WHERE_GREATER_THAN_HAS_NEXT);
739 }
740 else {
741 query.append(WHERE_LESSER_THAN_HAS_NEXT);
742 }
743 }
744 else {
745 if (orderByComparator.isAscending() ^ previous) {
746 query.append(WHERE_GREATER_THAN);
747 }
748 else {
749 query.append(WHERE_LESSER_THAN);
750 }
751 }
752 }
753
754 query.append(ORDER_BY_CLAUSE);
755
756 String[] orderByFields = orderByComparator.getOrderByFields();
757
758 for (int i = 0; i < orderByFields.length; i++) {
759 query.append(_ORDER_BY_ENTITY_ALIAS);
760 query.append(orderByFields[i]);
761
762 if ((i + 1) < orderByFields.length) {
763 if (orderByComparator.isAscending() ^ previous) {
764 query.append(ORDER_BY_ASC_HAS_NEXT);
765 }
766 else {
767 query.append(ORDER_BY_DESC_HAS_NEXT);
768 }
769 }
770 else {
771 if (orderByComparator.isAscending() ^ previous) {
772 query.append(ORDER_BY_ASC);
773 }
774 else {
775 query.append(ORDER_BY_DESC);
776 }
777 }
778 }
779 }
780
781 else {
782 query.append(ShoppingItemPriceModelImpl.ORDER_BY_JPQL);
783 }
784
785 String sql = query.toString();
786
787 Query q = session.createQuery(sql);
788
789 q.setFirstResult(0);
790 q.setMaxResults(2);
791
792 QueryPos qPos = QueryPos.getInstance(q);
793
794 qPos.add(itemId);
795
796 if (orderByComparator != null) {
797 Object[] values = orderByComparator.getOrderByConditionValues(shoppingItemPrice);
798
799 for (Object value : values) {
800 qPos.add(value);
801 }
802 }
803
804 List<ShoppingItemPrice> list = q.list();
805
806 if (list.size() == 2) {
807 return list.get(1);
808 }
809 else {
810 return null;
811 }
812 }
813
814
820 public List<ShoppingItemPrice> findAll() throws SystemException {
821 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
822 }
823
824
836 public List<ShoppingItemPrice> findAll(int start, int end)
837 throws SystemException {
838 return findAll(start, end, null);
839 }
840
841
854 public List<ShoppingItemPrice> findAll(int start, int end,
855 OrderByComparator orderByComparator) throws SystemException {
856 FinderPath finderPath = null;
857 Object[] finderArgs = new Object[] { start, end, orderByComparator };
858
859 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
860 (orderByComparator == null)) {
861 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
862 finderArgs = FINDER_ARGS_EMPTY;
863 }
864 else {
865 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
866 finderArgs = new Object[] { start, end, orderByComparator };
867 }
868
869 List<ShoppingItemPrice> list = (List<ShoppingItemPrice>)FinderCacheUtil.getResult(finderPath,
870 finderArgs, this);
871
872 if (list == null) {
873 StringBundler query = null;
874 String sql = null;
875
876 if (orderByComparator != null) {
877 query = new StringBundler(2 +
878 (orderByComparator.getOrderByFields().length * 3));
879
880 query.append(_SQL_SELECT_SHOPPINGITEMPRICE);
881
882 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
883 orderByComparator);
884
885 sql = query.toString();
886 }
887 else {
888 sql = _SQL_SELECT_SHOPPINGITEMPRICE.concat(ShoppingItemPriceModelImpl.ORDER_BY_JPQL);
889 }
890
891 Session session = null;
892
893 try {
894 session = openSession();
895
896 Query q = session.createQuery(sql);
897
898 if (orderByComparator == null) {
899 list = (List<ShoppingItemPrice>)QueryUtil.list(q,
900 getDialect(), start, end, false);
901
902 Collections.sort(list);
903 }
904 else {
905 list = (List<ShoppingItemPrice>)QueryUtil.list(q,
906 getDialect(), start, end);
907 }
908 }
909 catch (Exception e) {
910 throw processException(e);
911 }
912 finally {
913 if (list == null) {
914 FinderCacheUtil.removeResult(finderPath, finderArgs);
915 }
916 else {
917 cacheResult(list);
918
919 FinderCacheUtil.putResult(finderPath, finderArgs, list);
920 }
921
922 closeSession(session);
923 }
924 }
925
926 return list;
927 }
928
929
935 public void removeByItemId(long itemId) throws SystemException {
936 for (ShoppingItemPrice shoppingItemPrice : findByItemId(itemId)) {
937 remove(shoppingItemPrice);
938 }
939 }
940
941
946 public void removeAll() throws SystemException {
947 for (ShoppingItemPrice shoppingItemPrice : findAll()) {
948 remove(shoppingItemPrice);
949 }
950 }
951
952
959 public int countByItemId(long itemId) throws SystemException {
960 Object[] finderArgs = new Object[] { itemId };
961
962 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_ITEMID,
963 finderArgs, this);
964
965 if (count == null) {
966 StringBundler query = new StringBundler(2);
967
968 query.append(_SQL_COUNT_SHOPPINGITEMPRICE_WHERE);
969
970 query.append(_FINDER_COLUMN_ITEMID_ITEMID_2);
971
972 String sql = query.toString();
973
974 Session session = null;
975
976 try {
977 session = openSession();
978
979 Query q = session.createQuery(sql);
980
981 QueryPos qPos = QueryPos.getInstance(q);
982
983 qPos.add(itemId);
984
985 count = (Long)q.uniqueResult();
986 }
987 catch (Exception e) {
988 throw processException(e);
989 }
990 finally {
991 if (count == null) {
992 count = Long.valueOf(0);
993 }
994
995 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_ITEMID,
996 finderArgs, count);
997
998 closeSession(session);
999 }
1000 }
1001
1002 return count.intValue();
1003 }
1004
1005
1011 public int countAll() throws SystemException {
1012 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1013 FINDER_ARGS_EMPTY, this);
1014
1015 if (count == null) {
1016 Session session = null;
1017
1018 try {
1019 session = openSession();
1020
1021 Query q = session.createQuery(_SQL_COUNT_SHOPPINGITEMPRICE);
1022
1023 count = (Long)q.uniqueResult();
1024 }
1025 catch (Exception e) {
1026 throw processException(e);
1027 }
1028 finally {
1029 if (count == null) {
1030 count = Long.valueOf(0);
1031 }
1032
1033 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1034 FINDER_ARGS_EMPTY, count);
1035
1036 closeSession(session);
1037 }
1038 }
1039
1040 return count.intValue();
1041 }
1042
1043
1046 public void afterPropertiesSet() {
1047 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1048 com.liferay.portal.util.PropsUtil.get(
1049 "value.object.listener.com.liferay.portlet.shopping.model.ShoppingItemPrice")));
1050
1051 if (listenerClassNames.length > 0) {
1052 try {
1053 List<ModelListener<ShoppingItemPrice>> listenersList = new ArrayList<ModelListener<ShoppingItemPrice>>();
1054
1055 for (String listenerClassName : listenerClassNames) {
1056 listenersList.add((ModelListener<ShoppingItemPrice>)InstanceFactory.newInstance(
1057 listenerClassName));
1058 }
1059
1060 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1061 }
1062 catch (Exception e) {
1063 _log.error(e);
1064 }
1065 }
1066 }
1067
1068 public void destroy() {
1069 EntityCacheUtil.removeCache(ShoppingItemPriceImpl.class.getName());
1070 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1071 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1072 }
1073
1074 @BeanReference(type = ShoppingCartPersistence.class)
1075 protected ShoppingCartPersistence shoppingCartPersistence;
1076 @BeanReference(type = ShoppingCategoryPersistence.class)
1077 protected ShoppingCategoryPersistence shoppingCategoryPersistence;
1078 @BeanReference(type = ShoppingCouponPersistence.class)
1079 protected ShoppingCouponPersistence shoppingCouponPersistence;
1080 @BeanReference(type = ShoppingItemPersistence.class)
1081 protected ShoppingItemPersistence shoppingItemPersistence;
1082 @BeanReference(type = ShoppingItemFieldPersistence.class)
1083 protected ShoppingItemFieldPersistence shoppingItemFieldPersistence;
1084 @BeanReference(type = ShoppingItemPricePersistence.class)
1085 protected ShoppingItemPricePersistence shoppingItemPricePersistence;
1086 @BeanReference(type = ShoppingOrderPersistence.class)
1087 protected ShoppingOrderPersistence shoppingOrderPersistence;
1088 @BeanReference(type = ShoppingOrderItemPersistence.class)
1089 protected ShoppingOrderItemPersistence shoppingOrderItemPersistence;
1090 @BeanReference(type = ResourcePersistence.class)
1091 protected ResourcePersistence resourcePersistence;
1092 @BeanReference(type = UserPersistence.class)
1093 protected UserPersistence userPersistence;
1094 private static final String _SQL_SELECT_SHOPPINGITEMPRICE = "SELECT shoppingItemPrice FROM ShoppingItemPrice shoppingItemPrice";
1095 private static final String _SQL_SELECT_SHOPPINGITEMPRICE_WHERE = "SELECT shoppingItemPrice FROM ShoppingItemPrice shoppingItemPrice WHERE ";
1096 private static final String _SQL_COUNT_SHOPPINGITEMPRICE = "SELECT COUNT(shoppingItemPrice) FROM ShoppingItemPrice shoppingItemPrice";
1097 private static final String _SQL_COUNT_SHOPPINGITEMPRICE_WHERE = "SELECT COUNT(shoppingItemPrice) FROM ShoppingItemPrice shoppingItemPrice WHERE ";
1098 private static final String _FINDER_COLUMN_ITEMID_ITEMID_2 = "shoppingItemPrice.itemId = ?";
1099 private static final String _ORDER_BY_ENTITY_ALIAS = "shoppingItemPrice.";
1100 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ShoppingItemPrice exists with the primary key ";
1101 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ShoppingItemPrice exists with the key {";
1102 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1103 private static Log _log = LogFactoryUtil.getLog(ShoppingItemPricePersistenceImpl.class);
1104 private static ShoppingItemPrice _nullShoppingItemPrice = new ShoppingItemPriceImpl() {
1105 @Override
1106 public Object clone() {
1107 return this;
1108 }
1109
1110 @Override
1111 public CacheModel<ShoppingItemPrice> toCacheModel() {
1112 return _nullShoppingItemPriceCacheModel;
1113 }
1114 };
1115
1116 private static CacheModel<ShoppingItemPrice> _nullShoppingItemPriceCacheModel =
1117 new CacheModel<ShoppingItemPrice>() {
1118 public ShoppingItemPrice toEntityModel() {
1119 return _nullShoppingItemPrice;
1120 }
1121 };
1122 }