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.UserPersistence;
039 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
040
041 import com.liferay.portlet.shopping.NoSuchItemFieldException;
042 import com.liferay.portlet.shopping.model.ShoppingItemField;
043 import com.liferay.portlet.shopping.model.impl.ShoppingItemFieldImpl;
044 import com.liferay.portlet.shopping.model.impl.ShoppingItemFieldModelImpl;
045
046 import java.io.Serializable;
047
048 import java.util.ArrayList;
049 import java.util.Collections;
050 import java.util.List;
051
052
064 public class ShoppingItemFieldPersistenceImpl extends BasePersistenceImpl<ShoppingItemField>
065 implements ShoppingItemFieldPersistence {
066
071 public static final String FINDER_CLASS_NAME_ENTITY = ShoppingItemFieldImpl.class.getName();
072 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
073 ".List1";
074 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
075 ".List2";
076 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_ITEMID = new FinderPath(ShoppingItemFieldModelImpl.ENTITY_CACHE_ENABLED,
077 ShoppingItemFieldModelImpl.FINDER_CACHE_ENABLED,
078 ShoppingItemFieldImpl.class,
079 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByItemId",
080 new String[] {
081 Long.class.getName(),
082
083 "java.lang.Integer", "java.lang.Integer",
084 "com.liferay.portal.kernel.util.OrderByComparator"
085 });
086 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ITEMID =
087 new FinderPath(ShoppingItemFieldModelImpl.ENTITY_CACHE_ENABLED,
088 ShoppingItemFieldModelImpl.FINDER_CACHE_ENABLED,
089 ShoppingItemFieldImpl.class,
090 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByItemId",
091 new String[] { Long.class.getName() },
092 ShoppingItemFieldModelImpl.ITEMID_COLUMN_BITMASK);
093 public static final FinderPath FINDER_PATH_COUNT_BY_ITEMID = new FinderPath(ShoppingItemFieldModelImpl.ENTITY_CACHE_ENABLED,
094 ShoppingItemFieldModelImpl.FINDER_CACHE_ENABLED, Long.class,
095 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByItemId",
096 new String[] { Long.class.getName() });
097 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(ShoppingItemFieldModelImpl.ENTITY_CACHE_ENABLED,
098 ShoppingItemFieldModelImpl.FINDER_CACHE_ENABLED,
099 ShoppingItemFieldImpl.class,
100 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
101 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(ShoppingItemFieldModelImpl.ENTITY_CACHE_ENABLED,
102 ShoppingItemFieldModelImpl.FINDER_CACHE_ENABLED,
103 ShoppingItemFieldImpl.class,
104 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
105 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ShoppingItemFieldModelImpl.ENTITY_CACHE_ENABLED,
106 ShoppingItemFieldModelImpl.FINDER_CACHE_ENABLED, Long.class,
107 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
108
109
114 public void cacheResult(ShoppingItemField shoppingItemField) {
115 EntityCacheUtil.putResult(ShoppingItemFieldModelImpl.ENTITY_CACHE_ENABLED,
116 ShoppingItemFieldImpl.class, shoppingItemField.getPrimaryKey(),
117 shoppingItemField);
118
119 shoppingItemField.resetOriginalValues();
120 }
121
122
127 public void cacheResult(List<ShoppingItemField> shoppingItemFields) {
128 for (ShoppingItemField shoppingItemField : shoppingItemFields) {
129 if (EntityCacheUtil.getResult(
130 ShoppingItemFieldModelImpl.ENTITY_CACHE_ENABLED,
131 ShoppingItemFieldImpl.class,
132 shoppingItemField.getPrimaryKey()) == null) {
133 cacheResult(shoppingItemField);
134 }
135 else {
136 shoppingItemField.resetOriginalValues();
137 }
138 }
139 }
140
141
148 @Override
149 public void clearCache() {
150 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
151 CacheRegistryUtil.clear(ShoppingItemFieldImpl.class.getName());
152 }
153
154 EntityCacheUtil.clearCache(ShoppingItemFieldImpl.class.getName());
155
156 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
157 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
158 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
159 }
160
161
168 @Override
169 public void clearCache(ShoppingItemField shoppingItemField) {
170 EntityCacheUtil.removeResult(ShoppingItemFieldModelImpl.ENTITY_CACHE_ENABLED,
171 ShoppingItemFieldImpl.class, shoppingItemField.getPrimaryKey());
172
173 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
174 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
175 }
176
177 @Override
178 public void clearCache(List<ShoppingItemField> shoppingItemFields) {
179 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
180 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
181
182 for (ShoppingItemField shoppingItemField : shoppingItemFields) {
183 EntityCacheUtil.removeResult(ShoppingItemFieldModelImpl.ENTITY_CACHE_ENABLED,
184 ShoppingItemFieldImpl.class, shoppingItemField.getPrimaryKey());
185 }
186 }
187
188
194 public ShoppingItemField create(long itemFieldId) {
195 ShoppingItemField shoppingItemField = new ShoppingItemFieldImpl();
196
197 shoppingItemField.setNew(true);
198 shoppingItemField.setPrimaryKey(itemFieldId);
199
200 return shoppingItemField;
201 }
202
203
211 public ShoppingItemField remove(long itemFieldId)
212 throws NoSuchItemFieldException, SystemException {
213 return remove(Long.valueOf(itemFieldId));
214 }
215
216
224 @Override
225 public ShoppingItemField remove(Serializable primaryKey)
226 throws NoSuchItemFieldException, SystemException {
227 Session session = null;
228
229 try {
230 session = openSession();
231
232 ShoppingItemField shoppingItemField = (ShoppingItemField)session.get(ShoppingItemFieldImpl.class,
233 primaryKey);
234
235 if (shoppingItemField == null) {
236 if (_log.isWarnEnabled()) {
237 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
238 }
239
240 throw new NoSuchItemFieldException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
241 primaryKey);
242 }
243
244 return remove(shoppingItemField);
245 }
246 catch (NoSuchItemFieldException nsee) {
247 throw nsee;
248 }
249 catch (Exception e) {
250 throw processException(e);
251 }
252 finally {
253 closeSession(session);
254 }
255 }
256
257 @Override
258 protected ShoppingItemField removeImpl(ShoppingItemField shoppingItemField)
259 throws SystemException {
260 shoppingItemField = toUnwrappedModel(shoppingItemField);
261
262 Session session = null;
263
264 try {
265 session = openSession();
266
267 if (shoppingItemField.isCachedModel()) {
268 shoppingItemField = (ShoppingItemField)session.get(ShoppingItemFieldImpl.class,
269 shoppingItemField.getPrimaryKeyObj());
270 }
271
272 session.delete(shoppingItemField);
273 }
274 catch (Exception e) {
275 throw processException(e);
276 }
277 finally {
278 closeSession(session);
279 }
280
281 clearCache(shoppingItemField);
282
283 return shoppingItemField;
284 }
285
286 @Override
287 public ShoppingItemField updateImpl(
288 com.liferay.portlet.shopping.model.ShoppingItemField shoppingItemField)
289 throws SystemException {
290 shoppingItemField = toUnwrappedModel(shoppingItemField);
291
292 boolean isNew = shoppingItemField.isNew();
293
294 ShoppingItemFieldModelImpl shoppingItemFieldModelImpl = (ShoppingItemFieldModelImpl)shoppingItemField;
295
296 Session session = null;
297
298 try {
299 session = openSession();
300
301 if (shoppingItemField.isNew()) {
302 session.save(shoppingItemField);
303
304 shoppingItemField.setNew(false);
305 }
306 else {
307 session.merge(shoppingItemField);
308 }
309 }
310 catch (Exception e) {
311 throw processException(e);
312 }
313 finally {
314 closeSession(session);
315 }
316
317 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
318
319 if (isNew || !ShoppingItemFieldModelImpl.COLUMN_BITMASK_ENABLED) {
320 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
321 }
322
323 else {
324 if ((shoppingItemFieldModelImpl.getColumnBitmask() &
325 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ITEMID.getColumnBitmask()) != 0) {
326 Object[] args = new Object[] {
327 Long.valueOf(shoppingItemFieldModelImpl.getOriginalItemId())
328 };
329
330 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ITEMID, args);
331 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ITEMID,
332 args);
333
334 args = new Object[] {
335 Long.valueOf(shoppingItemFieldModelImpl.getItemId())
336 };
337
338 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ITEMID, args);
339 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ITEMID,
340 args);
341 }
342 }
343
344 EntityCacheUtil.putResult(ShoppingItemFieldModelImpl.ENTITY_CACHE_ENABLED,
345 ShoppingItemFieldImpl.class, shoppingItemField.getPrimaryKey(),
346 shoppingItemField);
347
348 return shoppingItemField;
349 }
350
351 protected ShoppingItemField toUnwrappedModel(
352 ShoppingItemField shoppingItemField) {
353 if (shoppingItemField instanceof ShoppingItemFieldImpl) {
354 return shoppingItemField;
355 }
356
357 ShoppingItemFieldImpl shoppingItemFieldImpl = new ShoppingItemFieldImpl();
358
359 shoppingItemFieldImpl.setNew(shoppingItemField.isNew());
360 shoppingItemFieldImpl.setPrimaryKey(shoppingItemField.getPrimaryKey());
361
362 shoppingItemFieldImpl.setItemFieldId(shoppingItemField.getItemFieldId());
363 shoppingItemFieldImpl.setItemId(shoppingItemField.getItemId());
364 shoppingItemFieldImpl.setName(shoppingItemField.getName());
365 shoppingItemFieldImpl.setValues(shoppingItemField.getValues());
366 shoppingItemFieldImpl.setDescription(shoppingItemField.getDescription());
367
368 return shoppingItemFieldImpl;
369 }
370
371
379 @Override
380 public ShoppingItemField findByPrimaryKey(Serializable primaryKey)
381 throws NoSuchModelException, SystemException {
382 return findByPrimaryKey(((Long)primaryKey).longValue());
383 }
384
385
393 public ShoppingItemField findByPrimaryKey(long itemFieldId)
394 throws NoSuchItemFieldException, SystemException {
395 ShoppingItemField shoppingItemField = fetchByPrimaryKey(itemFieldId);
396
397 if (shoppingItemField == null) {
398 if (_log.isWarnEnabled()) {
399 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + itemFieldId);
400 }
401
402 throw new NoSuchItemFieldException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
403 itemFieldId);
404 }
405
406 return shoppingItemField;
407 }
408
409
416 @Override
417 public ShoppingItemField fetchByPrimaryKey(Serializable primaryKey)
418 throws SystemException {
419 return fetchByPrimaryKey(((Long)primaryKey).longValue());
420 }
421
422
429 public ShoppingItemField fetchByPrimaryKey(long itemFieldId)
430 throws SystemException {
431 ShoppingItemField shoppingItemField = (ShoppingItemField)EntityCacheUtil.getResult(ShoppingItemFieldModelImpl.ENTITY_CACHE_ENABLED,
432 ShoppingItemFieldImpl.class, itemFieldId);
433
434 if (shoppingItemField == _nullShoppingItemField) {
435 return null;
436 }
437
438 if (shoppingItemField == null) {
439 Session session = null;
440
441 boolean hasException = false;
442
443 try {
444 session = openSession();
445
446 shoppingItemField = (ShoppingItemField)session.get(ShoppingItemFieldImpl.class,
447 Long.valueOf(itemFieldId));
448 }
449 catch (Exception e) {
450 hasException = true;
451
452 throw processException(e);
453 }
454 finally {
455 if (shoppingItemField != null) {
456 cacheResult(shoppingItemField);
457 }
458 else if (!hasException) {
459 EntityCacheUtil.putResult(ShoppingItemFieldModelImpl.ENTITY_CACHE_ENABLED,
460 ShoppingItemFieldImpl.class, itemFieldId,
461 _nullShoppingItemField);
462 }
463
464 closeSession(session);
465 }
466 }
467
468 return shoppingItemField;
469 }
470
471
478 public List<ShoppingItemField> findByItemId(long itemId)
479 throws SystemException {
480 return findByItemId(itemId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
481 }
482
483
496 public List<ShoppingItemField> findByItemId(long itemId, int start, int end)
497 throws SystemException {
498 return findByItemId(itemId, start, end, null);
499 }
500
501
515 public List<ShoppingItemField> findByItemId(long itemId, int start,
516 int end, OrderByComparator orderByComparator) throws SystemException {
517 FinderPath finderPath = null;
518 Object[] finderArgs = null;
519
520 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
521 (orderByComparator == null)) {
522 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ITEMID;
523 finderArgs = new Object[] { itemId };
524 }
525 else {
526 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_ITEMID;
527 finderArgs = new Object[] { itemId, start, end, orderByComparator };
528 }
529
530 List<ShoppingItemField> list = (List<ShoppingItemField>)FinderCacheUtil.getResult(finderPath,
531 finderArgs, this);
532
533 if ((list != null) && !list.isEmpty()) {
534 for (ShoppingItemField shoppingItemField : list) {
535 if ((itemId != shoppingItemField.getItemId())) {
536 list = null;
537
538 break;
539 }
540 }
541 }
542
543 if (list == null) {
544 StringBundler query = null;
545
546 if (orderByComparator != null) {
547 query = new StringBundler(3 +
548 (orderByComparator.getOrderByFields().length * 3));
549 }
550 else {
551 query = new StringBundler(3);
552 }
553
554 query.append(_SQL_SELECT_SHOPPINGITEMFIELD_WHERE);
555
556 query.append(_FINDER_COLUMN_ITEMID_ITEMID_2);
557
558 if (orderByComparator != null) {
559 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
560 orderByComparator);
561 }
562
563 else {
564 query.append(ShoppingItemFieldModelImpl.ORDER_BY_JPQL);
565 }
566
567 String sql = query.toString();
568
569 Session session = null;
570
571 try {
572 session = openSession();
573
574 Query q = session.createQuery(sql);
575
576 QueryPos qPos = QueryPos.getInstance(q);
577
578 qPos.add(itemId);
579
580 list = (List<ShoppingItemField>)QueryUtil.list(q, getDialect(),
581 start, end);
582 }
583 catch (Exception e) {
584 throw processException(e);
585 }
586 finally {
587 if (list == null) {
588 FinderCacheUtil.removeResult(finderPath, finderArgs);
589 }
590 else {
591 cacheResult(list);
592
593 FinderCacheUtil.putResult(finderPath, finderArgs, list);
594 }
595
596 closeSession(session);
597 }
598 }
599
600 return list;
601 }
602
603
612 public ShoppingItemField findByItemId_First(long itemId,
613 OrderByComparator orderByComparator)
614 throws NoSuchItemFieldException, SystemException {
615 ShoppingItemField shoppingItemField = fetchByItemId_First(itemId,
616 orderByComparator);
617
618 if (shoppingItemField != null) {
619 return shoppingItemField;
620 }
621
622 StringBundler msg = new StringBundler(4);
623
624 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
625
626 msg.append("itemId=");
627 msg.append(itemId);
628
629 msg.append(StringPool.CLOSE_CURLY_BRACE);
630
631 throw new NoSuchItemFieldException(msg.toString());
632 }
633
634
642 public ShoppingItemField fetchByItemId_First(long itemId,
643 OrderByComparator orderByComparator) throws SystemException {
644 List<ShoppingItemField> list = findByItemId(itemId, 0, 1,
645 orderByComparator);
646
647 if (!list.isEmpty()) {
648 return list.get(0);
649 }
650
651 return null;
652 }
653
654
663 public ShoppingItemField findByItemId_Last(long itemId,
664 OrderByComparator orderByComparator)
665 throws NoSuchItemFieldException, SystemException {
666 ShoppingItemField shoppingItemField = fetchByItemId_Last(itemId,
667 orderByComparator);
668
669 if (shoppingItemField != null) {
670 return shoppingItemField;
671 }
672
673 StringBundler msg = new StringBundler(4);
674
675 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
676
677 msg.append("itemId=");
678 msg.append(itemId);
679
680 msg.append(StringPool.CLOSE_CURLY_BRACE);
681
682 throw new NoSuchItemFieldException(msg.toString());
683 }
684
685
693 public ShoppingItemField fetchByItemId_Last(long itemId,
694 OrderByComparator orderByComparator) throws SystemException {
695 int count = countByItemId(itemId);
696
697 List<ShoppingItemField> list = findByItemId(itemId, count - 1, count,
698 orderByComparator);
699
700 if (!list.isEmpty()) {
701 return list.get(0);
702 }
703
704 return null;
705 }
706
707
717 public ShoppingItemField[] findByItemId_PrevAndNext(long itemFieldId,
718 long itemId, OrderByComparator orderByComparator)
719 throws NoSuchItemFieldException, SystemException {
720 ShoppingItemField shoppingItemField = findByPrimaryKey(itemFieldId);
721
722 Session session = null;
723
724 try {
725 session = openSession();
726
727 ShoppingItemField[] array = new ShoppingItemFieldImpl[3];
728
729 array[0] = getByItemId_PrevAndNext(session, shoppingItemField,
730 itemId, orderByComparator, true);
731
732 array[1] = shoppingItemField;
733
734 array[2] = getByItemId_PrevAndNext(session, shoppingItemField,
735 itemId, orderByComparator, false);
736
737 return array;
738 }
739 catch (Exception e) {
740 throw processException(e);
741 }
742 finally {
743 closeSession(session);
744 }
745 }
746
747 protected ShoppingItemField getByItemId_PrevAndNext(Session session,
748 ShoppingItemField shoppingItemField, long itemId,
749 OrderByComparator orderByComparator, boolean previous) {
750 StringBundler query = null;
751
752 if (orderByComparator != null) {
753 query = new StringBundler(6 +
754 (orderByComparator.getOrderByFields().length * 6));
755 }
756 else {
757 query = new StringBundler(3);
758 }
759
760 query.append(_SQL_SELECT_SHOPPINGITEMFIELD_WHERE);
761
762 query.append(_FINDER_COLUMN_ITEMID_ITEMID_2);
763
764 if (orderByComparator != null) {
765 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
766
767 if (orderByConditionFields.length > 0) {
768 query.append(WHERE_AND);
769 }
770
771 for (int i = 0; i < orderByConditionFields.length; i++) {
772 query.append(_ORDER_BY_ENTITY_ALIAS);
773 query.append(orderByConditionFields[i]);
774
775 if ((i + 1) < orderByConditionFields.length) {
776 if (orderByComparator.isAscending() ^ previous) {
777 query.append(WHERE_GREATER_THAN_HAS_NEXT);
778 }
779 else {
780 query.append(WHERE_LESSER_THAN_HAS_NEXT);
781 }
782 }
783 else {
784 if (orderByComparator.isAscending() ^ previous) {
785 query.append(WHERE_GREATER_THAN);
786 }
787 else {
788 query.append(WHERE_LESSER_THAN);
789 }
790 }
791 }
792
793 query.append(ORDER_BY_CLAUSE);
794
795 String[] orderByFields = orderByComparator.getOrderByFields();
796
797 for (int i = 0; i < orderByFields.length; i++) {
798 query.append(_ORDER_BY_ENTITY_ALIAS);
799 query.append(orderByFields[i]);
800
801 if ((i + 1) < orderByFields.length) {
802 if (orderByComparator.isAscending() ^ previous) {
803 query.append(ORDER_BY_ASC_HAS_NEXT);
804 }
805 else {
806 query.append(ORDER_BY_DESC_HAS_NEXT);
807 }
808 }
809 else {
810 if (orderByComparator.isAscending() ^ previous) {
811 query.append(ORDER_BY_ASC);
812 }
813 else {
814 query.append(ORDER_BY_DESC);
815 }
816 }
817 }
818 }
819
820 else {
821 query.append(ShoppingItemFieldModelImpl.ORDER_BY_JPQL);
822 }
823
824 String sql = query.toString();
825
826 Query q = session.createQuery(sql);
827
828 q.setFirstResult(0);
829 q.setMaxResults(2);
830
831 QueryPos qPos = QueryPos.getInstance(q);
832
833 qPos.add(itemId);
834
835 if (orderByComparator != null) {
836 Object[] values = orderByComparator.getOrderByConditionValues(shoppingItemField);
837
838 for (Object value : values) {
839 qPos.add(value);
840 }
841 }
842
843 List<ShoppingItemField> list = q.list();
844
845 if (list.size() == 2) {
846 return list.get(1);
847 }
848 else {
849 return null;
850 }
851 }
852
853
859 public List<ShoppingItemField> findAll() throws SystemException {
860 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
861 }
862
863
875 public List<ShoppingItemField> findAll(int start, int end)
876 throws SystemException {
877 return findAll(start, end, null);
878 }
879
880
893 public List<ShoppingItemField> findAll(int start, int end,
894 OrderByComparator orderByComparator) throws SystemException {
895 FinderPath finderPath = null;
896 Object[] finderArgs = new Object[] { start, end, orderByComparator };
897
898 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
899 (orderByComparator == null)) {
900 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
901 finderArgs = FINDER_ARGS_EMPTY;
902 }
903 else {
904 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
905 finderArgs = new Object[] { start, end, orderByComparator };
906 }
907
908 List<ShoppingItemField> list = (List<ShoppingItemField>)FinderCacheUtil.getResult(finderPath,
909 finderArgs, this);
910
911 if (list == null) {
912 StringBundler query = null;
913 String sql = null;
914
915 if (orderByComparator != null) {
916 query = new StringBundler(2 +
917 (orderByComparator.getOrderByFields().length * 3));
918
919 query.append(_SQL_SELECT_SHOPPINGITEMFIELD);
920
921 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
922 orderByComparator);
923
924 sql = query.toString();
925 }
926 else {
927 sql = _SQL_SELECT_SHOPPINGITEMFIELD.concat(ShoppingItemFieldModelImpl.ORDER_BY_JPQL);
928 }
929
930 Session session = null;
931
932 try {
933 session = openSession();
934
935 Query q = session.createQuery(sql);
936
937 if (orderByComparator == null) {
938 list = (List<ShoppingItemField>)QueryUtil.list(q,
939 getDialect(), start, end, false);
940
941 Collections.sort(list);
942 }
943 else {
944 list = (List<ShoppingItemField>)QueryUtil.list(q,
945 getDialect(), start, end);
946 }
947 }
948 catch (Exception e) {
949 throw processException(e);
950 }
951 finally {
952 if (list == null) {
953 FinderCacheUtil.removeResult(finderPath, finderArgs);
954 }
955 else {
956 cacheResult(list);
957
958 FinderCacheUtil.putResult(finderPath, finderArgs, list);
959 }
960
961 closeSession(session);
962 }
963 }
964
965 return list;
966 }
967
968
974 public void removeByItemId(long itemId) throws SystemException {
975 for (ShoppingItemField shoppingItemField : findByItemId(itemId)) {
976 remove(shoppingItemField);
977 }
978 }
979
980
985 public void removeAll() throws SystemException {
986 for (ShoppingItemField shoppingItemField : findAll()) {
987 remove(shoppingItemField);
988 }
989 }
990
991
998 public int countByItemId(long itemId) throws SystemException {
999 Object[] finderArgs = new Object[] { itemId };
1000
1001 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_ITEMID,
1002 finderArgs, this);
1003
1004 if (count == null) {
1005 StringBundler query = new StringBundler(2);
1006
1007 query.append(_SQL_COUNT_SHOPPINGITEMFIELD_WHERE);
1008
1009 query.append(_FINDER_COLUMN_ITEMID_ITEMID_2);
1010
1011 String sql = query.toString();
1012
1013 Session session = null;
1014
1015 try {
1016 session = openSession();
1017
1018 Query q = session.createQuery(sql);
1019
1020 QueryPos qPos = QueryPos.getInstance(q);
1021
1022 qPos.add(itemId);
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_BY_ITEMID,
1035 finderArgs, count);
1036
1037 closeSession(session);
1038 }
1039 }
1040
1041 return count.intValue();
1042 }
1043
1044
1050 public int countAll() throws SystemException {
1051 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1052 FINDER_ARGS_EMPTY, this);
1053
1054 if (count == null) {
1055 Session session = null;
1056
1057 try {
1058 session = openSession();
1059
1060 Query q = session.createQuery(_SQL_COUNT_SHOPPINGITEMFIELD);
1061
1062 count = (Long)q.uniqueResult();
1063 }
1064 catch (Exception e) {
1065 throw processException(e);
1066 }
1067 finally {
1068 if (count == null) {
1069 count = Long.valueOf(0);
1070 }
1071
1072 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1073 FINDER_ARGS_EMPTY, count);
1074
1075 closeSession(session);
1076 }
1077 }
1078
1079 return count.intValue();
1080 }
1081
1082
1085 public void afterPropertiesSet() {
1086 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1087 com.liferay.portal.util.PropsUtil.get(
1088 "value.object.listener.com.liferay.portlet.shopping.model.ShoppingItemField")));
1089
1090 if (listenerClassNames.length > 0) {
1091 try {
1092 List<ModelListener<ShoppingItemField>> listenersList = new ArrayList<ModelListener<ShoppingItemField>>();
1093
1094 for (String listenerClassName : listenerClassNames) {
1095 listenersList.add((ModelListener<ShoppingItemField>)InstanceFactory.newInstance(
1096 listenerClassName));
1097 }
1098
1099 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1100 }
1101 catch (Exception e) {
1102 _log.error(e);
1103 }
1104 }
1105 }
1106
1107 public void destroy() {
1108 EntityCacheUtil.removeCache(ShoppingItemFieldImpl.class.getName());
1109 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1110 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1111 }
1112
1113 @BeanReference(type = ShoppingCartPersistence.class)
1114 protected ShoppingCartPersistence shoppingCartPersistence;
1115 @BeanReference(type = ShoppingCategoryPersistence.class)
1116 protected ShoppingCategoryPersistence shoppingCategoryPersistence;
1117 @BeanReference(type = ShoppingCouponPersistence.class)
1118 protected ShoppingCouponPersistence shoppingCouponPersistence;
1119 @BeanReference(type = ShoppingItemPersistence.class)
1120 protected ShoppingItemPersistence shoppingItemPersistence;
1121 @BeanReference(type = ShoppingItemFieldPersistence.class)
1122 protected ShoppingItemFieldPersistence shoppingItemFieldPersistence;
1123 @BeanReference(type = ShoppingItemPricePersistence.class)
1124 protected ShoppingItemPricePersistence shoppingItemPricePersistence;
1125 @BeanReference(type = ShoppingOrderPersistence.class)
1126 protected ShoppingOrderPersistence shoppingOrderPersistence;
1127 @BeanReference(type = ShoppingOrderItemPersistence.class)
1128 protected ShoppingOrderItemPersistence shoppingOrderItemPersistence;
1129 @BeanReference(type = UserPersistence.class)
1130 protected UserPersistence userPersistence;
1131 private static final String _SQL_SELECT_SHOPPINGITEMFIELD = "SELECT shoppingItemField FROM ShoppingItemField shoppingItemField";
1132 private static final String _SQL_SELECT_SHOPPINGITEMFIELD_WHERE = "SELECT shoppingItemField FROM ShoppingItemField shoppingItemField WHERE ";
1133 private static final String _SQL_COUNT_SHOPPINGITEMFIELD = "SELECT COUNT(shoppingItemField) FROM ShoppingItemField shoppingItemField";
1134 private static final String _SQL_COUNT_SHOPPINGITEMFIELD_WHERE = "SELECT COUNT(shoppingItemField) FROM ShoppingItemField shoppingItemField WHERE ";
1135 private static final String _FINDER_COLUMN_ITEMID_ITEMID_2 = "shoppingItemField.itemId = ?";
1136 private static final String _ORDER_BY_ENTITY_ALIAS = "shoppingItemField.";
1137 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ShoppingItemField exists with the primary key ";
1138 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ShoppingItemField exists with the key {";
1139 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1140 private static Log _log = LogFactoryUtil.getLog(ShoppingItemFieldPersistenceImpl.class);
1141 private static ShoppingItemField _nullShoppingItemField = new ShoppingItemFieldImpl() {
1142 @Override
1143 public Object clone() {
1144 return this;
1145 }
1146
1147 @Override
1148 public CacheModel<ShoppingItemField> toCacheModel() {
1149 return _nullShoppingItemFieldCacheModel;
1150 }
1151 };
1152
1153 private static CacheModel<ShoppingItemField> _nullShoppingItemFieldCacheModel =
1154 new CacheModel<ShoppingItemField>() {
1155 public ShoppingItemField toEntityModel() {
1156 return _nullShoppingItemField;
1157 }
1158 };
1159 }