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 @Override
180 public void clearCache(List<ShoppingOrderItem> shoppingOrderItems) {
181 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
182 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
183
184 for (ShoppingOrderItem shoppingOrderItem : shoppingOrderItems) {
185 EntityCacheUtil.removeResult(ShoppingOrderItemModelImpl.ENTITY_CACHE_ENABLED,
186 ShoppingOrderItemImpl.class, shoppingOrderItem.getPrimaryKey());
187 }
188 }
189
190
196 public ShoppingOrderItem create(long orderItemId) {
197 ShoppingOrderItem shoppingOrderItem = new ShoppingOrderItemImpl();
198
199 shoppingOrderItem.setNew(true);
200 shoppingOrderItem.setPrimaryKey(orderItemId);
201
202 return shoppingOrderItem;
203 }
204
205
213 public ShoppingOrderItem remove(long orderItemId)
214 throws NoSuchOrderItemException, SystemException {
215 return remove(Long.valueOf(orderItemId));
216 }
217
218
226 @Override
227 public ShoppingOrderItem remove(Serializable primaryKey)
228 throws NoSuchOrderItemException, SystemException {
229 Session session = null;
230
231 try {
232 session = openSession();
233
234 ShoppingOrderItem shoppingOrderItem = (ShoppingOrderItem)session.get(ShoppingOrderItemImpl.class,
235 primaryKey);
236
237 if (shoppingOrderItem == null) {
238 if (_log.isWarnEnabled()) {
239 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
240 }
241
242 throw new NoSuchOrderItemException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
243 primaryKey);
244 }
245
246 return remove(shoppingOrderItem);
247 }
248 catch (NoSuchOrderItemException 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 ShoppingOrderItem removeImpl(ShoppingOrderItem shoppingOrderItem)
261 throws SystemException {
262 shoppingOrderItem = toUnwrappedModel(shoppingOrderItem);
263
264 Session session = null;
265
266 try {
267 session = openSession();
268
269 BatchSessionUtil.delete(session, shoppingOrderItem);
270 }
271 catch (Exception e) {
272 throw processException(e);
273 }
274 finally {
275 closeSession(session);
276 }
277
278 clearCache(shoppingOrderItem);
279
280 return shoppingOrderItem;
281 }
282
283 @Override
284 public ShoppingOrderItem updateImpl(
285 com.liferay.portlet.shopping.model.ShoppingOrderItem shoppingOrderItem,
286 boolean merge) throws SystemException {
287 shoppingOrderItem = toUnwrappedModel(shoppingOrderItem);
288
289 boolean isNew = shoppingOrderItem.isNew();
290
291 ShoppingOrderItemModelImpl shoppingOrderItemModelImpl = (ShoppingOrderItemModelImpl)shoppingOrderItem;
292
293 Session session = null;
294
295 try {
296 session = openSession();
297
298 BatchSessionUtil.update(session, shoppingOrderItem, merge);
299
300 shoppingOrderItem.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 || !ShoppingOrderItemModelImpl.COLUMN_BITMASK_ENABLED) {
312 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
313 }
314
315 else {
316 if ((shoppingOrderItemModelImpl.getColumnBitmask() &
317 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ORDERID.getColumnBitmask()) != 0) {
318 Object[] args = new Object[] {
319 Long.valueOf(shoppingOrderItemModelImpl.getOriginalOrderId())
320 };
321
322 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ORDERID, args);
323 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ORDERID,
324 args);
325
326 args = new Object[] {
327 Long.valueOf(shoppingOrderItemModelImpl.getOrderId())
328 };
329
330 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ORDERID, args);
331 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ORDERID,
332 args);
333 }
334 }
335
336 EntityCacheUtil.putResult(ShoppingOrderItemModelImpl.ENTITY_CACHE_ENABLED,
337 ShoppingOrderItemImpl.class, shoppingOrderItem.getPrimaryKey(),
338 shoppingOrderItem);
339
340 return shoppingOrderItem;
341 }
342
343 protected ShoppingOrderItem toUnwrappedModel(
344 ShoppingOrderItem shoppingOrderItem) {
345 if (shoppingOrderItem instanceof ShoppingOrderItemImpl) {
346 return shoppingOrderItem;
347 }
348
349 ShoppingOrderItemImpl shoppingOrderItemImpl = new ShoppingOrderItemImpl();
350
351 shoppingOrderItemImpl.setNew(shoppingOrderItem.isNew());
352 shoppingOrderItemImpl.setPrimaryKey(shoppingOrderItem.getPrimaryKey());
353
354 shoppingOrderItemImpl.setOrderItemId(shoppingOrderItem.getOrderItemId());
355 shoppingOrderItemImpl.setOrderId(shoppingOrderItem.getOrderId());
356 shoppingOrderItemImpl.setItemId(shoppingOrderItem.getItemId());
357 shoppingOrderItemImpl.setSku(shoppingOrderItem.getSku());
358 shoppingOrderItemImpl.setName(shoppingOrderItem.getName());
359 shoppingOrderItemImpl.setDescription(shoppingOrderItem.getDescription());
360 shoppingOrderItemImpl.setProperties(shoppingOrderItem.getProperties());
361 shoppingOrderItemImpl.setPrice(shoppingOrderItem.getPrice());
362 shoppingOrderItemImpl.setQuantity(shoppingOrderItem.getQuantity());
363 shoppingOrderItemImpl.setShippedDate(shoppingOrderItem.getShippedDate());
364
365 return shoppingOrderItemImpl;
366 }
367
368
376 @Override
377 public ShoppingOrderItem findByPrimaryKey(Serializable primaryKey)
378 throws NoSuchModelException, SystemException {
379 return findByPrimaryKey(((Long)primaryKey).longValue());
380 }
381
382
390 public ShoppingOrderItem findByPrimaryKey(long orderItemId)
391 throws NoSuchOrderItemException, SystemException {
392 ShoppingOrderItem shoppingOrderItem = fetchByPrimaryKey(orderItemId);
393
394 if (shoppingOrderItem == null) {
395 if (_log.isWarnEnabled()) {
396 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + orderItemId);
397 }
398
399 throw new NoSuchOrderItemException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
400 orderItemId);
401 }
402
403 return shoppingOrderItem;
404 }
405
406
413 @Override
414 public ShoppingOrderItem fetchByPrimaryKey(Serializable primaryKey)
415 throws SystemException {
416 return fetchByPrimaryKey(((Long)primaryKey).longValue());
417 }
418
419
426 public ShoppingOrderItem fetchByPrimaryKey(long orderItemId)
427 throws SystemException {
428 ShoppingOrderItem shoppingOrderItem = (ShoppingOrderItem)EntityCacheUtil.getResult(ShoppingOrderItemModelImpl.ENTITY_CACHE_ENABLED,
429 ShoppingOrderItemImpl.class, orderItemId);
430
431 if (shoppingOrderItem == _nullShoppingOrderItem) {
432 return null;
433 }
434
435 if (shoppingOrderItem == null) {
436 Session session = null;
437
438 boolean hasException = false;
439
440 try {
441 session = openSession();
442
443 shoppingOrderItem = (ShoppingOrderItem)session.get(ShoppingOrderItemImpl.class,
444 Long.valueOf(orderItemId));
445 }
446 catch (Exception e) {
447 hasException = true;
448
449 throw processException(e);
450 }
451 finally {
452 if (shoppingOrderItem != null) {
453 cacheResult(shoppingOrderItem);
454 }
455 else if (!hasException) {
456 EntityCacheUtil.putResult(ShoppingOrderItemModelImpl.ENTITY_CACHE_ENABLED,
457 ShoppingOrderItemImpl.class, orderItemId,
458 _nullShoppingOrderItem);
459 }
460
461 closeSession(session);
462 }
463 }
464
465 return shoppingOrderItem;
466 }
467
468
475 public List<ShoppingOrderItem> findByOrderId(long orderId)
476 throws SystemException {
477 return findByOrderId(orderId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
478 }
479
480
493 public List<ShoppingOrderItem> findByOrderId(long orderId, int start,
494 int end) throws SystemException {
495 return findByOrderId(orderId, start, end, null);
496 }
497
498
512 public List<ShoppingOrderItem> findByOrderId(long orderId, 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_ORDERID;
520 finderArgs = new Object[] { orderId };
521 }
522 else {
523 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_ORDERID;
524 finderArgs = new Object[] { orderId, start, end, orderByComparator };
525 }
526
527 List<ShoppingOrderItem> list = (List<ShoppingOrderItem>)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_SHOPPINGORDERITEM_WHERE);
542
543 query.append(_FINDER_COLUMN_ORDERID_ORDERID_2);
544
545 if (orderByComparator != null) {
546 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
547 orderByComparator);
548 }
549
550 else {
551 query.append(ShoppingOrderItemModelImpl.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(orderId);
566
567 list = (List<ShoppingOrderItem>)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 ShoppingOrderItem findByOrderId_First(long orderId,
604 OrderByComparator orderByComparator)
605 throws NoSuchOrderItemException, SystemException {
606 List<ShoppingOrderItem> list = findByOrderId(orderId, 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("orderId=");
615 msg.append(orderId);
616
617 msg.append(StringPool.CLOSE_CURLY_BRACE);
618
619 throw new NoSuchOrderItemException(msg.toString());
620 }
621 else {
622 return list.get(0);
623 }
624 }
625
626
639 public ShoppingOrderItem findByOrderId_Last(long orderId,
640 OrderByComparator orderByComparator)
641 throws NoSuchOrderItemException, SystemException {
642 int count = countByOrderId(orderId);
643
644 List<ShoppingOrderItem> list = findByOrderId(orderId, 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("orderId=");
653 msg.append(orderId);
654
655 msg.append(StringPool.CLOSE_CURLY_BRACE);
656
657 throw new NoSuchOrderItemException(msg.toString());
658 }
659 else {
660 return list.get(0);
661 }
662 }
663
664
678 public ShoppingOrderItem[] findByOrderId_PrevAndNext(long orderItemId,
679 long orderId, OrderByComparator orderByComparator)
680 throws NoSuchOrderItemException, SystemException {
681 ShoppingOrderItem shoppingOrderItem = findByPrimaryKey(orderItemId);
682
683 Session session = null;
684
685 try {
686 session = openSession();
687
688 ShoppingOrderItem[] array = new ShoppingOrderItemImpl[3];
689
690 array[0] = getByOrderId_PrevAndNext(session, shoppingOrderItem,
691 orderId, orderByComparator, true);
692
693 array[1] = shoppingOrderItem;
694
695 array[2] = getByOrderId_PrevAndNext(session, shoppingOrderItem,
696 orderId, 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 ShoppingOrderItem getByOrderId_PrevAndNext(Session session,
709 ShoppingOrderItem shoppingOrderItem, long orderId,
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_SHOPPINGORDERITEM_WHERE);
722
723 query.append(_FINDER_COLUMN_ORDERID_ORDERID_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(ShoppingOrderItemModelImpl.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(orderId);
795
796 if (orderByComparator != null) {
797 Object[] values = orderByComparator.getOrderByConditionValues(shoppingOrderItem);
798
799 for (Object value : values) {
800 qPos.add(value);
801 }
802 }
803
804 List<ShoppingOrderItem> 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<ShoppingOrderItem> findAll() throws SystemException {
821 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
822 }
823
824
836 public List<ShoppingOrderItem> findAll(int start, int end)
837 throws SystemException {
838 return findAll(start, end, null);
839 }
840
841
854 public List<ShoppingOrderItem> 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<ShoppingOrderItem> list = (List<ShoppingOrderItem>)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_SHOPPINGORDERITEM);
881
882 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
883 orderByComparator);
884
885 sql = query.toString();
886 }
887 else {
888 sql = _SQL_SELECT_SHOPPINGORDERITEM.concat(ShoppingOrderItemModelImpl.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<ShoppingOrderItem>)QueryUtil.list(q,
900 getDialect(), start, end, false);
901
902 Collections.sort(list);
903 }
904 else {
905 list = (List<ShoppingOrderItem>)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 removeByOrderId(long orderId) throws SystemException {
936 for (ShoppingOrderItem shoppingOrderItem : findByOrderId(orderId)) {
937 remove(shoppingOrderItem);
938 }
939 }
940
941
946 public void removeAll() throws SystemException {
947 for (ShoppingOrderItem shoppingOrderItem : findAll()) {
948 remove(shoppingOrderItem);
949 }
950 }
951
952
959 public int countByOrderId(long orderId) throws SystemException {
960 Object[] finderArgs = new Object[] { orderId };
961
962 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_ORDERID,
963 finderArgs, this);
964
965 if (count == null) {
966 StringBundler query = new StringBundler(2);
967
968 query.append(_SQL_COUNT_SHOPPINGORDERITEM_WHERE);
969
970 query.append(_FINDER_COLUMN_ORDERID_ORDERID_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(orderId);
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_ORDERID,
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_SHOPPINGORDERITEM);
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.ShoppingOrderItem")));
1050
1051 if (listenerClassNames.length > 0) {
1052 try {
1053 List<ModelListener<ShoppingOrderItem>> listenersList = new ArrayList<ModelListener<ShoppingOrderItem>>();
1054
1055 for (String listenerClassName : listenerClassNames) {
1056 listenersList.add((ModelListener<ShoppingOrderItem>)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(ShoppingOrderItemImpl.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_SHOPPINGORDERITEM = "SELECT shoppingOrderItem FROM ShoppingOrderItem shoppingOrderItem";
1095 private static final String _SQL_SELECT_SHOPPINGORDERITEM_WHERE = "SELECT shoppingOrderItem FROM ShoppingOrderItem shoppingOrderItem WHERE ";
1096 private static final String _SQL_COUNT_SHOPPINGORDERITEM = "SELECT COUNT(shoppingOrderItem) FROM ShoppingOrderItem shoppingOrderItem";
1097 private static final String _SQL_COUNT_SHOPPINGORDERITEM_WHERE = "SELECT COUNT(shoppingOrderItem) FROM ShoppingOrderItem shoppingOrderItem WHERE ";
1098 private static final String _FINDER_COLUMN_ORDERID_ORDERID_2 = "shoppingOrderItem.orderId = ?";
1099 private static final String _ORDER_BY_ENTITY_ALIAS = "shoppingOrderItem.";
1100 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ShoppingOrderItem exists with the primary key ";
1101 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ShoppingOrderItem 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(ShoppingOrderItemPersistenceImpl.class);
1104 private static ShoppingOrderItem _nullShoppingOrderItem = new ShoppingOrderItemImpl() {
1105 @Override
1106 public Object clone() {
1107 return this;
1108 }
1109
1110 @Override
1111 public CacheModel<ShoppingOrderItem> toCacheModel() {
1112 return _nullShoppingOrderItemCacheModel;
1113 }
1114 };
1115
1116 private static CacheModel<ShoppingOrderItem> _nullShoppingOrderItemCacheModel =
1117 new CacheModel<ShoppingOrderItem>() {
1118 public ShoppingOrderItem toEntityModel() {
1119 return _nullShoppingOrderItem;
1120 }
1121 };
1122 }