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_WITH_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_WITHOUT_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) && !list.isEmpty()) {
531 for (ShoppingOrderItem shoppingOrderItem : list) {
532 if ((orderId != shoppingOrderItem.getOrderId())) {
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_SHOPPINGORDERITEM_WHERE);
552
553 query.append(_FINDER_COLUMN_ORDERID_ORDERID_2);
554
555 if (orderByComparator != null) {
556 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
557 orderByComparator);
558 }
559
560 else {
561 query.append(ShoppingOrderItemModelImpl.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(orderId);
576
577 list = (List<ShoppingOrderItem>)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 ShoppingOrderItem findByOrderId_First(long orderId,
610 OrderByComparator orderByComparator)
611 throws NoSuchOrderItemException, SystemException {
612 ShoppingOrderItem shoppingOrderItem = fetchByOrderId_First(orderId,
613 orderByComparator);
614
615 if (shoppingOrderItem != null) {
616 return shoppingOrderItem;
617 }
618
619 StringBundler msg = new StringBundler(4);
620
621 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
622
623 msg.append("orderId=");
624 msg.append(orderId);
625
626 msg.append(StringPool.CLOSE_CURLY_BRACE);
627
628 throw new NoSuchOrderItemException(msg.toString());
629 }
630
631
639 public ShoppingOrderItem fetchByOrderId_First(long orderId,
640 OrderByComparator orderByComparator) throws SystemException {
641 List<ShoppingOrderItem> list = findByOrderId(orderId, 0, 1,
642 orderByComparator);
643
644 if (!list.isEmpty()) {
645 return list.get(0);
646 }
647
648 return null;
649 }
650
651
660 public ShoppingOrderItem findByOrderId_Last(long orderId,
661 OrderByComparator orderByComparator)
662 throws NoSuchOrderItemException, SystemException {
663 ShoppingOrderItem shoppingOrderItem = fetchByOrderId_Last(orderId,
664 orderByComparator);
665
666 if (shoppingOrderItem != null) {
667 return shoppingOrderItem;
668 }
669
670 StringBundler msg = new StringBundler(4);
671
672 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
673
674 msg.append("orderId=");
675 msg.append(orderId);
676
677 msg.append(StringPool.CLOSE_CURLY_BRACE);
678
679 throw new NoSuchOrderItemException(msg.toString());
680 }
681
682
690 public ShoppingOrderItem fetchByOrderId_Last(long orderId,
691 OrderByComparator orderByComparator) throws SystemException {
692 int count = countByOrderId(orderId);
693
694 List<ShoppingOrderItem> list = findByOrderId(orderId, 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 ShoppingOrderItem[] findByOrderId_PrevAndNext(long orderItemId,
715 long orderId, OrderByComparator orderByComparator)
716 throws NoSuchOrderItemException, SystemException {
717 ShoppingOrderItem shoppingOrderItem = findByPrimaryKey(orderItemId);
718
719 Session session = null;
720
721 try {
722 session = openSession();
723
724 ShoppingOrderItem[] array = new ShoppingOrderItemImpl[3];
725
726 array[0] = getByOrderId_PrevAndNext(session, shoppingOrderItem,
727 orderId, orderByComparator, true);
728
729 array[1] = shoppingOrderItem;
730
731 array[2] = getByOrderId_PrevAndNext(session, shoppingOrderItem,
732 orderId, 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 ShoppingOrderItem getByOrderId_PrevAndNext(Session session,
745 ShoppingOrderItem shoppingOrderItem, long orderId,
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_SHOPPINGORDERITEM_WHERE);
758
759 query.append(_FINDER_COLUMN_ORDERID_ORDERID_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(ShoppingOrderItemModelImpl.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(orderId);
831
832 if (orderByComparator != null) {
833 Object[] values = orderByComparator.getOrderByConditionValues(shoppingOrderItem);
834
835 for (Object value : values) {
836 qPos.add(value);
837 }
838 }
839
840 List<ShoppingOrderItem> 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<ShoppingOrderItem> findAll() throws SystemException {
857 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
858 }
859
860
872 public List<ShoppingOrderItem> findAll(int start, int end)
873 throws SystemException {
874 return findAll(start, end, null);
875 }
876
877
890 public List<ShoppingOrderItem> 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<ShoppingOrderItem> list = (List<ShoppingOrderItem>)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_SHOPPINGORDERITEM);
917
918 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
919 orderByComparator);
920
921 sql = query.toString();
922 }
923 else {
924 sql = _SQL_SELECT_SHOPPINGORDERITEM.concat(ShoppingOrderItemModelImpl.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<ShoppingOrderItem>)QueryUtil.list(q,
936 getDialect(), start, end, false);
937
938 Collections.sort(list);
939 }
940 else {
941 list = (List<ShoppingOrderItem>)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 removeByOrderId(long orderId) throws SystemException {
972 for (ShoppingOrderItem shoppingOrderItem : findByOrderId(orderId)) {
973 remove(shoppingOrderItem);
974 }
975 }
976
977
982 public void removeAll() throws SystemException {
983 for (ShoppingOrderItem shoppingOrderItem : findAll()) {
984 remove(shoppingOrderItem);
985 }
986 }
987
988
995 public int countByOrderId(long orderId) throws SystemException {
996 Object[] finderArgs = new Object[] { orderId };
997
998 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_ORDERID,
999 finderArgs, this);
1000
1001 if (count == null) {
1002 StringBundler query = new StringBundler(2);
1003
1004 query.append(_SQL_COUNT_SHOPPINGORDERITEM_WHERE);
1005
1006 query.append(_FINDER_COLUMN_ORDERID_ORDERID_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(orderId);
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_ORDERID,
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_SHOPPINGORDERITEM);
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.ShoppingOrderItem")));
1086
1087 if (listenerClassNames.length > 0) {
1088 try {
1089 List<ModelListener<ShoppingOrderItem>> listenersList = new ArrayList<ModelListener<ShoppingOrderItem>>();
1090
1091 for (String listenerClassName : listenerClassNames) {
1092 Class<?> clazz = getClass();
1093
1094 listenersList.add((ModelListener<ShoppingOrderItem>)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(ShoppingOrderItemImpl.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_SHOPPINGORDERITEM = "SELECT shoppingOrderItem FROM ShoppingOrderItem shoppingOrderItem";
1133 private static final String _SQL_SELECT_SHOPPINGORDERITEM_WHERE = "SELECT shoppingOrderItem FROM ShoppingOrderItem shoppingOrderItem WHERE ";
1134 private static final String _SQL_COUNT_SHOPPINGORDERITEM = "SELECT COUNT(shoppingOrderItem) FROM ShoppingOrderItem shoppingOrderItem";
1135 private static final String _SQL_COUNT_SHOPPINGORDERITEM_WHERE = "SELECT COUNT(shoppingOrderItem) FROM ShoppingOrderItem shoppingOrderItem WHERE ";
1136 private static final String _FINDER_COLUMN_ORDERID_ORDERID_2 = "shoppingOrderItem.orderId = ?";
1137 private static final String _ORDER_BY_ENTITY_ALIAS = "shoppingOrderItem.";
1138 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ShoppingOrderItem exists with the primary key ";
1139 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ShoppingOrderItem 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(ShoppingOrderItemPersistenceImpl.class);
1142 private static ShoppingOrderItem _nullShoppingOrderItem = new ShoppingOrderItemImpl() {
1143 @Override
1144 public Object clone() {
1145 return this;
1146 }
1147
1148 @Override
1149 public CacheModel<ShoppingOrderItem> toCacheModel() {
1150 return _nullShoppingOrderItemCacheModel;
1151 }
1152 };
1153
1154 private static CacheModel<ShoppingOrderItem> _nullShoppingOrderItemCacheModel =
1155 new CacheModel<ShoppingOrderItem>() {
1156 public ShoppingOrderItem toEntityModel() {
1157 return _nullShoppingOrderItem;
1158 }
1159 };
1160 }