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.NoSuchItemFieldException;
044 import com.liferay.portlet.shopping.model.ShoppingItemField;
045 import com.liferay.portlet.shopping.model.impl.ShoppingItemFieldImpl;
046 import com.liferay.portlet.shopping.model.impl.ShoppingItemFieldModelImpl;
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 ShoppingItemFieldPersistenceImpl extends BasePersistenceImpl<ShoppingItemField>
067 implements ShoppingItemFieldPersistence {
068
073 public static final String FINDER_CLASS_NAME_ENTITY = ShoppingItemFieldImpl.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(ShoppingItemFieldModelImpl.ENTITY_CACHE_ENABLED,
079 ShoppingItemFieldModelImpl.FINDER_CACHE_ENABLED,
080 ShoppingItemFieldImpl.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(ShoppingItemFieldModelImpl.ENTITY_CACHE_ENABLED,
090 ShoppingItemFieldModelImpl.FINDER_CACHE_ENABLED,
091 ShoppingItemFieldImpl.class,
092 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByItemId",
093 new String[] { Long.class.getName() },
094 ShoppingItemFieldModelImpl.ITEMID_COLUMN_BITMASK);
095 public static final FinderPath FINDER_PATH_COUNT_BY_ITEMID = new FinderPath(ShoppingItemFieldModelImpl.ENTITY_CACHE_ENABLED,
096 ShoppingItemFieldModelImpl.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(ShoppingItemFieldModelImpl.ENTITY_CACHE_ENABLED,
100 ShoppingItemFieldModelImpl.FINDER_CACHE_ENABLED,
101 ShoppingItemFieldImpl.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(ShoppingItemFieldModelImpl.ENTITY_CACHE_ENABLED,
104 ShoppingItemFieldModelImpl.FINDER_CACHE_ENABLED,
105 ShoppingItemFieldImpl.class,
106 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
107 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ShoppingItemFieldModelImpl.ENTITY_CACHE_ENABLED,
108 ShoppingItemFieldModelImpl.FINDER_CACHE_ENABLED, Long.class,
109 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
110
111
116 public void cacheResult(ShoppingItemField shoppingItemField) {
117 EntityCacheUtil.putResult(ShoppingItemFieldModelImpl.ENTITY_CACHE_ENABLED,
118 ShoppingItemFieldImpl.class, shoppingItemField.getPrimaryKey(),
119 shoppingItemField);
120
121 shoppingItemField.resetOriginalValues();
122 }
123
124
129 public void cacheResult(List<ShoppingItemField> shoppingItemFields) {
130 for (ShoppingItemField shoppingItemField : shoppingItemFields) {
131 if (EntityCacheUtil.getResult(
132 ShoppingItemFieldModelImpl.ENTITY_CACHE_ENABLED,
133 ShoppingItemFieldImpl.class,
134 shoppingItemField.getPrimaryKey()) == null) {
135 cacheResult(shoppingItemField);
136 }
137 else {
138 shoppingItemField.resetOriginalValues();
139 }
140 }
141 }
142
143
150 @Override
151 public void clearCache() {
152 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
153 CacheRegistryUtil.clear(ShoppingItemFieldImpl.class.getName());
154 }
155
156 EntityCacheUtil.clearCache(ShoppingItemFieldImpl.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(ShoppingItemField shoppingItemField) {
172 EntityCacheUtil.removeResult(ShoppingItemFieldModelImpl.ENTITY_CACHE_ENABLED,
173 ShoppingItemFieldImpl.class, shoppingItemField.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 ShoppingItemField create(long itemFieldId) {
186 ShoppingItemField shoppingItemField = new ShoppingItemFieldImpl();
187
188 shoppingItemField.setNew(true);
189 shoppingItemField.setPrimaryKey(itemFieldId);
190
191 return shoppingItemField;
192 }
193
194
202 @Override
203 public ShoppingItemField remove(Serializable primaryKey)
204 throws NoSuchModelException, SystemException {
205 return remove(((Long)primaryKey).longValue());
206 }
207
208
216 public ShoppingItemField remove(long itemFieldId)
217 throws NoSuchItemFieldException, SystemException {
218 Session session = null;
219
220 try {
221 session = openSession();
222
223 ShoppingItemField shoppingItemField = (ShoppingItemField)session.get(ShoppingItemFieldImpl.class,
224 Long.valueOf(itemFieldId));
225
226 if (shoppingItemField == null) {
227 if (_log.isWarnEnabled()) {
228 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + itemFieldId);
229 }
230
231 throw new NoSuchItemFieldException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
232 itemFieldId);
233 }
234
235 return shoppingItemFieldPersistence.remove(shoppingItemField);
236 }
237 catch (NoSuchItemFieldException 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 ShoppingItemField remove(ShoppingItemField shoppingItemField)
257 throws SystemException {
258 return super.remove(shoppingItemField);
259 }
260
261 @Override
262 protected ShoppingItemField removeImpl(ShoppingItemField shoppingItemField)
263 throws SystemException {
264 shoppingItemField = toUnwrappedModel(shoppingItemField);
265
266 Session session = null;
267
268 try {
269 session = openSession();
270
271 BatchSessionUtil.delete(session, shoppingItemField);
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(ShoppingItemFieldModelImpl.ENTITY_CACHE_ENABLED,
284 ShoppingItemFieldImpl.class, shoppingItemField.getPrimaryKey());
285
286 return shoppingItemField;
287 }
288
289 @Override
290 public ShoppingItemField updateImpl(
291 com.liferay.portlet.shopping.model.ShoppingItemField shoppingItemField,
292 boolean merge) throws SystemException {
293 shoppingItemField = toUnwrappedModel(shoppingItemField);
294
295 boolean isNew = shoppingItemField.isNew();
296
297 ShoppingItemFieldModelImpl shoppingItemFieldModelImpl = (ShoppingItemFieldModelImpl)shoppingItemField;
298
299 Session session = null;
300
301 try {
302 session = openSession();
303
304 BatchSessionUtil.update(session, shoppingItemField, merge);
305
306 shoppingItemField.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 || !ShoppingItemFieldModelImpl.COLUMN_BITMASK_ENABLED) {
318 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
319 }
320
321 else {
322 if ((shoppingItemFieldModelImpl.getColumnBitmask() &
323 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ITEMID.getColumnBitmask()) != 0) {
324 Object[] args = new Object[] {
325 Long.valueOf(shoppingItemFieldModelImpl.getOriginalItemId())
326 };
327
328 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ITEMID, args);
329 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ITEMID,
330 args);
331
332 args = new Object[] {
333 Long.valueOf(shoppingItemFieldModelImpl.getItemId())
334 };
335
336 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ITEMID, args);
337 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ITEMID,
338 args);
339 }
340 }
341
342 EntityCacheUtil.putResult(ShoppingItemFieldModelImpl.ENTITY_CACHE_ENABLED,
343 ShoppingItemFieldImpl.class, shoppingItemField.getPrimaryKey(),
344 shoppingItemField);
345
346 return shoppingItemField;
347 }
348
349 protected ShoppingItemField toUnwrappedModel(
350 ShoppingItemField shoppingItemField) {
351 if (shoppingItemField instanceof ShoppingItemFieldImpl) {
352 return shoppingItemField;
353 }
354
355 ShoppingItemFieldImpl shoppingItemFieldImpl = new ShoppingItemFieldImpl();
356
357 shoppingItemFieldImpl.setNew(shoppingItemField.isNew());
358 shoppingItemFieldImpl.setPrimaryKey(shoppingItemField.getPrimaryKey());
359
360 shoppingItemFieldImpl.setItemFieldId(shoppingItemField.getItemFieldId());
361 shoppingItemFieldImpl.setItemId(shoppingItemField.getItemId());
362 shoppingItemFieldImpl.setName(shoppingItemField.getName());
363 shoppingItemFieldImpl.setValues(shoppingItemField.getValues());
364 shoppingItemFieldImpl.setDescription(shoppingItemField.getDescription());
365
366 return shoppingItemFieldImpl;
367 }
368
369
377 @Override
378 public ShoppingItemField findByPrimaryKey(Serializable primaryKey)
379 throws NoSuchModelException, SystemException {
380 return findByPrimaryKey(((Long)primaryKey).longValue());
381 }
382
383
391 public ShoppingItemField findByPrimaryKey(long itemFieldId)
392 throws NoSuchItemFieldException, SystemException {
393 ShoppingItemField shoppingItemField = fetchByPrimaryKey(itemFieldId);
394
395 if (shoppingItemField == null) {
396 if (_log.isWarnEnabled()) {
397 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + itemFieldId);
398 }
399
400 throw new NoSuchItemFieldException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
401 itemFieldId);
402 }
403
404 return shoppingItemField;
405 }
406
407
414 @Override
415 public ShoppingItemField fetchByPrimaryKey(Serializable primaryKey)
416 throws SystemException {
417 return fetchByPrimaryKey(((Long)primaryKey).longValue());
418 }
419
420
427 public ShoppingItemField fetchByPrimaryKey(long itemFieldId)
428 throws SystemException {
429 ShoppingItemField shoppingItemField = (ShoppingItemField)EntityCacheUtil.getResult(ShoppingItemFieldModelImpl.ENTITY_CACHE_ENABLED,
430 ShoppingItemFieldImpl.class, itemFieldId);
431
432 if (shoppingItemField == _nullShoppingItemField) {
433 return null;
434 }
435
436 if (shoppingItemField == null) {
437 Session session = null;
438
439 boolean hasException = false;
440
441 try {
442 session = openSession();
443
444 shoppingItemField = (ShoppingItemField)session.get(ShoppingItemFieldImpl.class,
445 Long.valueOf(itemFieldId));
446 }
447 catch (Exception e) {
448 hasException = true;
449
450 throw processException(e);
451 }
452 finally {
453 if (shoppingItemField != null) {
454 cacheResult(shoppingItemField);
455 }
456 else if (!hasException) {
457 EntityCacheUtil.putResult(ShoppingItemFieldModelImpl.ENTITY_CACHE_ENABLED,
458 ShoppingItemFieldImpl.class, itemFieldId,
459 _nullShoppingItemField);
460 }
461
462 closeSession(session);
463 }
464 }
465
466 return shoppingItemField;
467 }
468
469
476 public List<ShoppingItemField> findByItemId(long itemId)
477 throws SystemException {
478 return findByItemId(itemId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
479 }
480
481
494 public List<ShoppingItemField> findByItemId(long itemId, int start, int end)
495 throws SystemException {
496 return findByItemId(itemId, start, end, null);
497 }
498
499
513 public List<ShoppingItemField> findByItemId(long itemId, int start,
514 int end, OrderByComparator orderByComparator) throws SystemException {
515 FinderPath finderPath = null;
516 Object[] finderArgs = null;
517
518 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
519 (orderByComparator == null)) {
520 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ITEMID;
521 finderArgs = new Object[] { itemId };
522 }
523 else {
524 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_ITEMID;
525 finderArgs = new Object[] { itemId, start, end, orderByComparator };
526 }
527
528 List<ShoppingItemField> list = (List<ShoppingItemField>)FinderCacheUtil.getResult(finderPath,
529 finderArgs, this);
530
531 if (list == null) {
532 StringBundler query = null;
533
534 if (orderByComparator != null) {
535 query = new StringBundler(3 +
536 (orderByComparator.getOrderByFields().length * 3));
537 }
538 else {
539 query = new StringBundler(3);
540 }
541
542 query.append(_SQL_SELECT_SHOPPINGITEMFIELD_WHERE);
543
544 query.append(_FINDER_COLUMN_ITEMID_ITEMID_2);
545
546 if (orderByComparator != null) {
547 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
548 orderByComparator);
549 }
550
551 else {
552 query.append(ShoppingItemFieldModelImpl.ORDER_BY_JPQL);
553 }
554
555 String sql = query.toString();
556
557 Session session = null;
558
559 try {
560 session = openSession();
561
562 Query q = session.createQuery(sql);
563
564 QueryPos qPos = QueryPos.getInstance(q);
565
566 qPos.add(itemId);
567
568 list = (List<ShoppingItemField>)QueryUtil.list(q, getDialect(),
569 start, end);
570 }
571 catch (Exception e) {
572 throw processException(e);
573 }
574 finally {
575 if (list == null) {
576 FinderCacheUtil.removeResult(finderPath, finderArgs);
577 }
578 else {
579 cacheResult(list);
580
581 FinderCacheUtil.putResult(finderPath, finderArgs, list);
582 }
583
584 closeSession(session);
585 }
586 }
587
588 return list;
589 }
590
591
604 public ShoppingItemField findByItemId_First(long itemId,
605 OrderByComparator orderByComparator)
606 throws NoSuchItemFieldException, SystemException {
607 List<ShoppingItemField> list = findByItemId(itemId, 0, 1,
608 orderByComparator);
609
610 if (list.isEmpty()) {
611 StringBundler msg = new StringBundler(4);
612
613 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
614
615 msg.append("itemId=");
616 msg.append(itemId);
617
618 msg.append(StringPool.CLOSE_CURLY_BRACE);
619
620 throw new NoSuchItemFieldException(msg.toString());
621 }
622 else {
623 return list.get(0);
624 }
625 }
626
627
640 public ShoppingItemField findByItemId_Last(long itemId,
641 OrderByComparator orderByComparator)
642 throws NoSuchItemFieldException, SystemException {
643 int count = countByItemId(itemId);
644
645 List<ShoppingItemField> list = findByItemId(itemId, count - 1, count,
646 orderByComparator);
647
648 if (list.isEmpty()) {
649 StringBundler msg = new StringBundler(4);
650
651 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
652
653 msg.append("itemId=");
654 msg.append(itemId);
655
656 msg.append(StringPool.CLOSE_CURLY_BRACE);
657
658 throw new NoSuchItemFieldException(msg.toString());
659 }
660 else {
661 return list.get(0);
662 }
663 }
664
665
679 public ShoppingItemField[] findByItemId_PrevAndNext(long itemFieldId,
680 long itemId, OrderByComparator orderByComparator)
681 throws NoSuchItemFieldException, SystemException {
682 ShoppingItemField shoppingItemField = findByPrimaryKey(itemFieldId);
683
684 Session session = null;
685
686 try {
687 session = openSession();
688
689 ShoppingItemField[] array = new ShoppingItemFieldImpl[3];
690
691 array[0] = getByItemId_PrevAndNext(session, shoppingItemField,
692 itemId, orderByComparator, true);
693
694 array[1] = shoppingItemField;
695
696 array[2] = getByItemId_PrevAndNext(session, shoppingItemField,
697 itemId, orderByComparator, false);
698
699 return array;
700 }
701 catch (Exception e) {
702 throw processException(e);
703 }
704 finally {
705 closeSession(session);
706 }
707 }
708
709 protected ShoppingItemField getByItemId_PrevAndNext(Session session,
710 ShoppingItemField shoppingItemField, long itemId,
711 OrderByComparator orderByComparator, boolean previous) {
712 StringBundler query = null;
713
714 if (orderByComparator != null) {
715 query = new StringBundler(6 +
716 (orderByComparator.getOrderByFields().length * 6));
717 }
718 else {
719 query = new StringBundler(3);
720 }
721
722 query.append(_SQL_SELECT_SHOPPINGITEMFIELD_WHERE);
723
724 query.append(_FINDER_COLUMN_ITEMID_ITEMID_2);
725
726 if (orderByComparator != null) {
727 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
728
729 if (orderByConditionFields.length > 0) {
730 query.append(WHERE_AND);
731 }
732
733 for (int i = 0; i < orderByConditionFields.length; i++) {
734 query.append(_ORDER_BY_ENTITY_ALIAS);
735 query.append(orderByConditionFields[i]);
736
737 if ((i + 1) < orderByConditionFields.length) {
738 if (orderByComparator.isAscending() ^ previous) {
739 query.append(WHERE_GREATER_THAN_HAS_NEXT);
740 }
741 else {
742 query.append(WHERE_LESSER_THAN_HAS_NEXT);
743 }
744 }
745 else {
746 if (orderByComparator.isAscending() ^ previous) {
747 query.append(WHERE_GREATER_THAN);
748 }
749 else {
750 query.append(WHERE_LESSER_THAN);
751 }
752 }
753 }
754
755 query.append(ORDER_BY_CLAUSE);
756
757 String[] orderByFields = orderByComparator.getOrderByFields();
758
759 for (int i = 0; i < orderByFields.length; i++) {
760 query.append(_ORDER_BY_ENTITY_ALIAS);
761 query.append(orderByFields[i]);
762
763 if ((i + 1) < orderByFields.length) {
764 if (orderByComparator.isAscending() ^ previous) {
765 query.append(ORDER_BY_ASC_HAS_NEXT);
766 }
767 else {
768 query.append(ORDER_BY_DESC_HAS_NEXT);
769 }
770 }
771 else {
772 if (orderByComparator.isAscending() ^ previous) {
773 query.append(ORDER_BY_ASC);
774 }
775 else {
776 query.append(ORDER_BY_DESC);
777 }
778 }
779 }
780 }
781
782 else {
783 query.append(ShoppingItemFieldModelImpl.ORDER_BY_JPQL);
784 }
785
786 String sql = query.toString();
787
788 Query q = session.createQuery(sql);
789
790 q.setFirstResult(0);
791 q.setMaxResults(2);
792
793 QueryPos qPos = QueryPos.getInstance(q);
794
795 qPos.add(itemId);
796
797 if (orderByComparator != null) {
798 Object[] values = orderByComparator.getOrderByConditionValues(shoppingItemField);
799
800 for (Object value : values) {
801 qPos.add(value);
802 }
803 }
804
805 List<ShoppingItemField> list = q.list();
806
807 if (list.size() == 2) {
808 return list.get(1);
809 }
810 else {
811 return null;
812 }
813 }
814
815
821 public List<ShoppingItemField> findAll() throws SystemException {
822 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
823 }
824
825
837 public List<ShoppingItemField> findAll(int start, int end)
838 throws SystemException {
839 return findAll(start, end, null);
840 }
841
842
855 public List<ShoppingItemField> findAll(int start, int end,
856 OrderByComparator orderByComparator) throws SystemException {
857 FinderPath finderPath = null;
858 Object[] finderArgs = new Object[] { start, end, orderByComparator };
859
860 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
861 (orderByComparator == null)) {
862 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
863 finderArgs = FINDER_ARGS_EMPTY;
864 }
865 else {
866 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
867 finderArgs = new Object[] { start, end, orderByComparator };
868 }
869
870 List<ShoppingItemField> list = (List<ShoppingItemField>)FinderCacheUtil.getResult(finderPath,
871 finderArgs, this);
872
873 if (list == null) {
874 StringBundler query = null;
875 String sql = null;
876
877 if (orderByComparator != null) {
878 query = new StringBundler(2 +
879 (orderByComparator.getOrderByFields().length * 3));
880
881 query.append(_SQL_SELECT_SHOPPINGITEMFIELD);
882
883 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
884 orderByComparator);
885
886 sql = query.toString();
887 }
888 else {
889 sql = _SQL_SELECT_SHOPPINGITEMFIELD.concat(ShoppingItemFieldModelImpl.ORDER_BY_JPQL);
890 }
891
892 Session session = null;
893
894 try {
895 session = openSession();
896
897 Query q = session.createQuery(sql);
898
899 if (orderByComparator == null) {
900 list = (List<ShoppingItemField>)QueryUtil.list(q,
901 getDialect(), start, end, false);
902
903 Collections.sort(list);
904 }
905 else {
906 list = (List<ShoppingItemField>)QueryUtil.list(q,
907 getDialect(), start, end);
908 }
909 }
910 catch (Exception e) {
911 throw processException(e);
912 }
913 finally {
914 if (list == null) {
915 FinderCacheUtil.removeResult(finderPath, finderArgs);
916 }
917 else {
918 cacheResult(list);
919
920 FinderCacheUtil.putResult(finderPath, finderArgs, list);
921 }
922
923 closeSession(session);
924 }
925 }
926
927 return list;
928 }
929
930
936 public void removeByItemId(long itemId) throws SystemException {
937 for (ShoppingItemField shoppingItemField : findByItemId(itemId)) {
938 shoppingItemFieldPersistence.remove(shoppingItemField);
939 }
940 }
941
942
947 public void removeAll() throws SystemException {
948 for (ShoppingItemField shoppingItemField : findAll()) {
949 shoppingItemFieldPersistence.remove(shoppingItemField);
950 }
951 }
952
953
960 public int countByItemId(long itemId) throws SystemException {
961 Object[] finderArgs = new Object[] { itemId };
962
963 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_ITEMID,
964 finderArgs, this);
965
966 if (count == null) {
967 StringBundler query = new StringBundler(2);
968
969 query.append(_SQL_COUNT_SHOPPINGITEMFIELD_WHERE);
970
971 query.append(_FINDER_COLUMN_ITEMID_ITEMID_2);
972
973 String sql = query.toString();
974
975 Session session = null;
976
977 try {
978 session = openSession();
979
980 Query q = session.createQuery(sql);
981
982 QueryPos qPos = QueryPos.getInstance(q);
983
984 qPos.add(itemId);
985
986 count = (Long)q.uniqueResult();
987 }
988 catch (Exception e) {
989 throw processException(e);
990 }
991 finally {
992 if (count == null) {
993 count = Long.valueOf(0);
994 }
995
996 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_ITEMID,
997 finderArgs, count);
998
999 closeSession(session);
1000 }
1001 }
1002
1003 return count.intValue();
1004 }
1005
1006
1012 public int countAll() throws SystemException {
1013 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1014 FINDER_ARGS_EMPTY, this);
1015
1016 if (count == null) {
1017 Session session = null;
1018
1019 try {
1020 session = openSession();
1021
1022 Query q = session.createQuery(_SQL_COUNT_SHOPPINGITEMFIELD);
1023
1024 count = (Long)q.uniqueResult();
1025 }
1026 catch (Exception e) {
1027 throw processException(e);
1028 }
1029 finally {
1030 if (count == null) {
1031 count = Long.valueOf(0);
1032 }
1033
1034 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1035 FINDER_ARGS_EMPTY, count);
1036
1037 closeSession(session);
1038 }
1039 }
1040
1041 return count.intValue();
1042 }
1043
1044
1047 public void afterPropertiesSet() {
1048 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1049 com.liferay.portal.util.PropsUtil.get(
1050 "value.object.listener.com.liferay.portlet.shopping.model.ShoppingItemField")));
1051
1052 if (listenerClassNames.length > 0) {
1053 try {
1054 List<ModelListener<ShoppingItemField>> listenersList = new ArrayList<ModelListener<ShoppingItemField>>();
1055
1056 for (String listenerClassName : listenerClassNames) {
1057 listenersList.add((ModelListener<ShoppingItemField>)InstanceFactory.newInstance(
1058 listenerClassName));
1059 }
1060
1061 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1062 }
1063 catch (Exception e) {
1064 _log.error(e);
1065 }
1066 }
1067 }
1068
1069 public void destroy() {
1070 EntityCacheUtil.removeCache(ShoppingItemFieldImpl.class.getName());
1071 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1072 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1073 }
1074
1075 @BeanReference(type = ShoppingCartPersistence.class)
1076 protected ShoppingCartPersistence shoppingCartPersistence;
1077 @BeanReference(type = ShoppingCategoryPersistence.class)
1078 protected ShoppingCategoryPersistence shoppingCategoryPersistence;
1079 @BeanReference(type = ShoppingCouponPersistence.class)
1080 protected ShoppingCouponPersistence shoppingCouponPersistence;
1081 @BeanReference(type = ShoppingItemPersistence.class)
1082 protected ShoppingItemPersistence shoppingItemPersistence;
1083 @BeanReference(type = ShoppingItemFieldPersistence.class)
1084 protected ShoppingItemFieldPersistence shoppingItemFieldPersistence;
1085 @BeanReference(type = ShoppingItemPricePersistence.class)
1086 protected ShoppingItemPricePersistence shoppingItemPricePersistence;
1087 @BeanReference(type = ShoppingOrderPersistence.class)
1088 protected ShoppingOrderPersistence shoppingOrderPersistence;
1089 @BeanReference(type = ShoppingOrderItemPersistence.class)
1090 protected ShoppingOrderItemPersistence shoppingOrderItemPersistence;
1091 @BeanReference(type = ResourcePersistence.class)
1092 protected ResourcePersistence resourcePersistence;
1093 @BeanReference(type = UserPersistence.class)
1094 protected UserPersistence userPersistence;
1095 private static final String _SQL_SELECT_SHOPPINGITEMFIELD = "SELECT shoppingItemField FROM ShoppingItemField shoppingItemField";
1096 private static final String _SQL_SELECT_SHOPPINGITEMFIELD_WHERE = "SELECT shoppingItemField FROM ShoppingItemField shoppingItemField WHERE ";
1097 private static final String _SQL_COUNT_SHOPPINGITEMFIELD = "SELECT COUNT(shoppingItemField) FROM ShoppingItemField shoppingItemField";
1098 private static final String _SQL_COUNT_SHOPPINGITEMFIELD_WHERE = "SELECT COUNT(shoppingItemField) FROM ShoppingItemField shoppingItemField WHERE ";
1099 private static final String _FINDER_COLUMN_ITEMID_ITEMID_2 = "shoppingItemField.itemId = ?";
1100 private static final String _ORDER_BY_ENTITY_ALIAS = "shoppingItemField.";
1101 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ShoppingItemField exists with the primary key ";
1102 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ShoppingItemField exists with the key {";
1103 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1104 private static Log _log = LogFactoryUtil.getLog(ShoppingItemFieldPersistenceImpl.class);
1105 private static ShoppingItemField _nullShoppingItemField = new ShoppingItemFieldImpl() {
1106 @Override
1107 public Object clone() {
1108 return this;
1109 }
1110
1111 @Override
1112 public CacheModel<ShoppingItemField> toCacheModel() {
1113 return _nullShoppingItemFieldCacheModel;
1114 }
1115 };
1116
1117 private static CacheModel<ShoppingItemField> _nullShoppingItemFieldCacheModel =
1118 new CacheModel<ShoppingItemField>() {
1119 public ShoppingItemField toEntityModel() {
1120 return _nullShoppingItemField;
1121 }
1122 };
1123 }