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