001
014
015 package com.liferay.portlet.shopping.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
018 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
019 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
020 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderPath;
022 import com.liferay.portal.kernel.dao.orm.Query;
023 import com.liferay.portal.kernel.dao.orm.QueryPos;
024 import com.liferay.portal.kernel.dao.orm.QueryUtil;
025 import com.liferay.portal.kernel.dao.orm.Session;
026 import com.liferay.portal.kernel.exception.SystemException;
027 import com.liferay.portal.kernel.log.Log;
028 import com.liferay.portal.kernel.log.LogFactoryUtil;
029 import com.liferay.portal.kernel.util.GetterUtil;
030 import com.liferay.portal.kernel.util.InstanceFactory;
031 import com.liferay.portal.kernel.util.OrderByComparator;
032 import com.liferay.portal.kernel.util.StringBundler;
033 import com.liferay.portal.kernel.util.StringPool;
034 import com.liferay.portal.kernel.util.StringUtil;
035 import com.liferay.portal.kernel.util.UnmodifiableList;
036 import com.liferay.portal.model.CacheModel;
037 import com.liferay.portal.model.ModelListener;
038 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
039
040 import com.liferay.portlet.shopping.NoSuchItemFieldException;
041 import com.liferay.portlet.shopping.model.ShoppingItemField;
042 import com.liferay.portlet.shopping.model.impl.ShoppingItemFieldImpl;
043 import com.liferay.portlet.shopping.model.impl.ShoppingItemFieldModelImpl;
044
045 import java.io.Serializable;
046
047 import java.util.ArrayList;
048 import java.util.Collections;
049 import java.util.List;
050
051
063 public class ShoppingItemFieldPersistenceImpl extends BasePersistenceImpl<ShoppingItemField>
064 implements ShoppingItemFieldPersistence {
065
070 public static final String FINDER_CLASS_NAME_ENTITY = ShoppingItemFieldImpl.class.getName();
071 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
072 ".List1";
073 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
074 ".List2";
075 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(ShoppingItemFieldModelImpl.ENTITY_CACHE_ENABLED,
076 ShoppingItemFieldModelImpl.FINDER_CACHE_ENABLED,
077 ShoppingItemFieldImpl.class,
078 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
079 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(ShoppingItemFieldModelImpl.ENTITY_CACHE_ENABLED,
080 ShoppingItemFieldModelImpl.FINDER_CACHE_ENABLED,
081 ShoppingItemFieldImpl.class,
082 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
083 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ShoppingItemFieldModelImpl.ENTITY_CACHE_ENABLED,
084 ShoppingItemFieldModelImpl.FINDER_CACHE_ENABLED, Long.class,
085 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
086 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_ITEMID = new FinderPath(ShoppingItemFieldModelImpl.ENTITY_CACHE_ENABLED,
087 ShoppingItemFieldModelImpl.FINDER_CACHE_ENABLED,
088 ShoppingItemFieldImpl.class,
089 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByItemId",
090 new String[] {
091 Long.class.getName(),
092
093 Integer.class.getName(), Integer.class.getName(),
094 OrderByComparator.class.getName()
095 });
096 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ITEMID =
097 new FinderPath(ShoppingItemFieldModelImpl.ENTITY_CACHE_ENABLED,
098 ShoppingItemFieldModelImpl.FINDER_CACHE_ENABLED,
099 ShoppingItemFieldImpl.class,
100 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByItemId",
101 new String[] { Long.class.getName() },
102 ShoppingItemFieldModelImpl.ITEMID_COLUMN_BITMASK |
103 ShoppingItemFieldModelImpl.NAME_COLUMN_BITMASK);
104 public static final FinderPath FINDER_PATH_COUNT_BY_ITEMID = new FinderPath(ShoppingItemFieldModelImpl.ENTITY_CACHE_ENABLED,
105 ShoppingItemFieldModelImpl.FINDER_CACHE_ENABLED, Long.class,
106 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByItemId",
107 new String[] { Long.class.getName() });
108
109
116 public List<ShoppingItemField> findByItemId(long itemId)
117 throws SystemException {
118 return findByItemId(itemId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
119 }
120
121
134 public List<ShoppingItemField> findByItemId(long itemId, int start, int end)
135 throws SystemException {
136 return findByItemId(itemId, start, end, null);
137 }
138
139
153 public List<ShoppingItemField> findByItemId(long itemId, int start,
154 int end, OrderByComparator orderByComparator) throws SystemException {
155 boolean pagination = true;
156 FinderPath finderPath = null;
157 Object[] finderArgs = null;
158
159 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
160 (orderByComparator == null)) {
161 pagination = false;
162 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ITEMID;
163 finderArgs = new Object[] { itemId };
164 }
165 else {
166 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_ITEMID;
167 finderArgs = new Object[] { itemId, start, end, orderByComparator };
168 }
169
170 List<ShoppingItemField> list = (List<ShoppingItemField>)FinderCacheUtil.getResult(finderPath,
171 finderArgs, this);
172
173 if ((list != null) && !list.isEmpty()) {
174 for (ShoppingItemField shoppingItemField : list) {
175 if ((itemId != shoppingItemField.getItemId())) {
176 list = null;
177
178 break;
179 }
180 }
181 }
182
183 if (list == null) {
184 StringBundler query = null;
185
186 if (orderByComparator != null) {
187 query = new StringBundler(3 +
188 (orderByComparator.getOrderByFields().length * 3));
189 }
190 else {
191 query = new StringBundler(3);
192 }
193
194 query.append(_SQL_SELECT_SHOPPINGITEMFIELD_WHERE);
195
196 query.append(_FINDER_COLUMN_ITEMID_ITEMID_2);
197
198 if (orderByComparator != null) {
199 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
200 orderByComparator);
201 }
202 else
203 if (pagination) {
204 query.append(ShoppingItemFieldModelImpl.ORDER_BY_JPQL);
205 }
206
207 String sql = query.toString();
208
209 Session session = null;
210
211 try {
212 session = openSession();
213
214 Query q = session.createQuery(sql);
215
216 QueryPos qPos = QueryPos.getInstance(q);
217
218 qPos.add(itemId);
219
220 if (!pagination) {
221 list = (List<ShoppingItemField>)QueryUtil.list(q,
222 getDialect(), start, end, false);
223
224 Collections.sort(list);
225
226 list = new UnmodifiableList<ShoppingItemField>(list);
227 }
228 else {
229 list = (List<ShoppingItemField>)QueryUtil.list(q,
230 getDialect(), start, end);
231 }
232
233 cacheResult(list);
234
235 FinderCacheUtil.putResult(finderPath, finderArgs, list);
236 }
237 catch (Exception e) {
238 FinderCacheUtil.removeResult(finderPath, finderArgs);
239
240 throw processException(e);
241 }
242 finally {
243 closeSession(session);
244 }
245 }
246
247 return list;
248 }
249
250
259 public ShoppingItemField findByItemId_First(long itemId,
260 OrderByComparator orderByComparator)
261 throws NoSuchItemFieldException, SystemException {
262 ShoppingItemField shoppingItemField = fetchByItemId_First(itemId,
263 orderByComparator);
264
265 if (shoppingItemField != null) {
266 return shoppingItemField;
267 }
268
269 StringBundler msg = new StringBundler(4);
270
271 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
272
273 msg.append("itemId=");
274 msg.append(itemId);
275
276 msg.append(StringPool.CLOSE_CURLY_BRACE);
277
278 throw new NoSuchItemFieldException(msg.toString());
279 }
280
281
289 public ShoppingItemField fetchByItemId_First(long itemId,
290 OrderByComparator orderByComparator) throws SystemException {
291 List<ShoppingItemField> list = findByItemId(itemId, 0, 1,
292 orderByComparator);
293
294 if (!list.isEmpty()) {
295 return list.get(0);
296 }
297
298 return null;
299 }
300
301
310 public ShoppingItemField findByItemId_Last(long itemId,
311 OrderByComparator orderByComparator)
312 throws NoSuchItemFieldException, SystemException {
313 ShoppingItemField shoppingItemField = fetchByItemId_Last(itemId,
314 orderByComparator);
315
316 if (shoppingItemField != null) {
317 return shoppingItemField;
318 }
319
320 StringBundler msg = new StringBundler(4);
321
322 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
323
324 msg.append("itemId=");
325 msg.append(itemId);
326
327 msg.append(StringPool.CLOSE_CURLY_BRACE);
328
329 throw new NoSuchItemFieldException(msg.toString());
330 }
331
332
340 public ShoppingItemField fetchByItemId_Last(long itemId,
341 OrderByComparator orderByComparator) throws SystemException {
342 int count = countByItemId(itemId);
343
344 List<ShoppingItemField> list = findByItemId(itemId, count - 1, count,
345 orderByComparator);
346
347 if (!list.isEmpty()) {
348 return list.get(0);
349 }
350
351 return null;
352 }
353
354
364 public ShoppingItemField[] findByItemId_PrevAndNext(long itemFieldId,
365 long itemId, OrderByComparator orderByComparator)
366 throws NoSuchItemFieldException, SystemException {
367 ShoppingItemField shoppingItemField = findByPrimaryKey(itemFieldId);
368
369 Session session = null;
370
371 try {
372 session = openSession();
373
374 ShoppingItemField[] array = new ShoppingItemFieldImpl[3];
375
376 array[0] = getByItemId_PrevAndNext(session, shoppingItemField,
377 itemId, orderByComparator, true);
378
379 array[1] = shoppingItemField;
380
381 array[2] = getByItemId_PrevAndNext(session, shoppingItemField,
382 itemId, orderByComparator, false);
383
384 return array;
385 }
386 catch (Exception e) {
387 throw processException(e);
388 }
389 finally {
390 closeSession(session);
391 }
392 }
393
394 protected ShoppingItemField getByItemId_PrevAndNext(Session session,
395 ShoppingItemField shoppingItemField, long itemId,
396 OrderByComparator orderByComparator, boolean previous) {
397 StringBundler query = null;
398
399 if (orderByComparator != null) {
400 query = new StringBundler(6 +
401 (orderByComparator.getOrderByFields().length * 6));
402 }
403 else {
404 query = new StringBundler(3);
405 }
406
407 query.append(_SQL_SELECT_SHOPPINGITEMFIELD_WHERE);
408
409 query.append(_FINDER_COLUMN_ITEMID_ITEMID_2);
410
411 if (orderByComparator != null) {
412 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
413
414 if (orderByConditionFields.length > 0) {
415 query.append(WHERE_AND);
416 }
417
418 for (int i = 0; i < orderByConditionFields.length; i++) {
419 query.append(_ORDER_BY_ENTITY_ALIAS);
420 query.append(orderByConditionFields[i]);
421
422 if ((i + 1) < orderByConditionFields.length) {
423 if (orderByComparator.isAscending() ^ previous) {
424 query.append(WHERE_GREATER_THAN_HAS_NEXT);
425 }
426 else {
427 query.append(WHERE_LESSER_THAN_HAS_NEXT);
428 }
429 }
430 else {
431 if (orderByComparator.isAscending() ^ previous) {
432 query.append(WHERE_GREATER_THAN);
433 }
434 else {
435 query.append(WHERE_LESSER_THAN);
436 }
437 }
438 }
439
440 query.append(ORDER_BY_CLAUSE);
441
442 String[] orderByFields = orderByComparator.getOrderByFields();
443
444 for (int i = 0; i < orderByFields.length; i++) {
445 query.append(_ORDER_BY_ENTITY_ALIAS);
446 query.append(orderByFields[i]);
447
448 if ((i + 1) < orderByFields.length) {
449 if (orderByComparator.isAscending() ^ previous) {
450 query.append(ORDER_BY_ASC_HAS_NEXT);
451 }
452 else {
453 query.append(ORDER_BY_DESC_HAS_NEXT);
454 }
455 }
456 else {
457 if (orderByComparator.isAscending() ^ previous) {
458 query.append(ORDER_BY_ASC);
459 }
460 else {
461 query.append(ORDER_BY_DESC);
462 }
463 }
464 }
465 }
466 else {
467 query.append(ShoppingItemFieldModelImpl.ORDER_BY_JPQL);
468 }
469
470 String sql = query.toString();
471
472 Query q = session.createQuery(sql);
473
474 q.setFirstResult(0);
475 q.setMaxResults(2);
476
477 QueryPos qPos = QueryPos.getInstance(q);
478
479 qPos.add(itemId);
480
481 if (orderByComparator != null) {
482 Object[] values = orderByComparator.getOrderByConditionValues(shoppingItemField);
483
484 for (Object value : values) {
485 qPos.add(value);
486 }
487 }
488
489 List<ShoppingItemField> list = q.list();
490
491 if (list.size() == 2) {
492 return list.get(1);
493 }
494 else {
495 return null;
496 }
497 }
498
499
505 public void removeByItemId(long itemId) throws SystemException {
506 for (ShoppingItemField shoppingItemField : findByItemId(itemId,
507 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
508 remove(shoppingItemField);
509 }
510 }
511
512
519 public int countByItemId(long itemId) throws SystemException {
520 FinderPath finderPath = FINDER_PATH_COUNT_BY_ITEMID;
521
522 Object[] finderArgs = new Object[] { itemId };
523
524 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
525 this);
526
527 if (count == null) {
528 StringBundler query = new StringBundler(2);
529
530 query.append(_SQL_COUNT_SHOPPINGITEMFIELD_WHERE);
531
532 query.append(_FINDER_COLUMN_ITEMID_ITEMID_2);
533
534 String sql = query.toString();
535
536 Session session = null;
537
538 try {
539 session = openSession();
540
541 Query q = session.createQuery(sql);
542
543 QueryPos qPos = QueryPos.getInstance(q);
544
545 qPos.add(itemId);
546
547 count = (Long)q.uniqueResult();
548
549 FinderCacheUtil.putResult(finderPath, finderArgs, count);
550 }
551 catch (Exception e) {
552 FinderCacheUtil.removeResult(finderPath, finderArgs);
553
554 throw processException(e);
555 }
556 finally {
557 closeSession(session);
558 }
559 }
560
561 return count.intValue();
562 }
563
564 private static final String _FINDER_COLUMN_ITEMID_ITEMID_2 = "shoppingItemField.itemId = ?";
565
566
571 public void cacheResult(ShoppingItemField shoppingItemField) {
572 EntityCacheUtil.putResult(ShoppingItemFieldModelImpl.ENTITY_CACHE_ENABLED,
573 ShoppingItemFieldImpl.class, shoppingItemField.getPrimaryKey(),
574 shoppingItemField);
575
576 shoppingItemField.resetOriginalValues();
577 }
578
579
584 public void cacheResult(List<ShoppingItemField> shoppingItemFields) {
585 for (ShoppingItemField shoppingItemField : shoppingItemFields) {
586 if (EntityCacheUtil.getResult(
587 ShoppingItemFieldModelImpl.ENTITY_CACHE_ENABLED,
588 ShoppingItemFieldImpl.class,
589 shoppingItemField.getPrimaryKey()) == null) {
590 cacheResult(shoppingItemField);
591 }
592 else {
593 shoppingItemField.resetOriginalValues();
594 }
595 }
596 }
597
598
605 @Override
606 public void clearCache() {
607 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
608 CacheRegistryUtil.clear(ShoppingItemFieldImpl.class.getName());
609 }
610
611 EntityCacheUtil.clearCache(ShoppingItemFieldImpl.class.getName());
612
613 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
614 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
615 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
616 }
617
618
625 @Override
626 public void clearCache(ShoppingItemField shoppingItemField) {
627 EntityCacheUtil.removeResult(ShoppingItemFieldModelImpl.ENTITY_CACHE_ENABLED,
628 ShoppingItemFieldImpl.class, shoppingItemField.getPrimaryKey());
629
630 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
631 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
632 }
633
634 @Override
635 public void clearCache(List<ShoppingItemField> shoppingItemFields) {
636 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
637 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
638
639 for (ShoppingItemField shoppingItemField : shoppingItemFields) {
640 EntityCacheUtil.removeResult(ShoppingItemFieldModelImpl.ENTITY_CACHE_ENABLED,
641 ShoppingItemFieldImpl.class, shoppingItemField.getPrimaryKey());
642 }
643 }
644
645
651 public ShoppingItemField create(long itemFieldId) {
652 ShoppingItemField shoppingItemField = new ShoppingItemFieldImpl();
653
654 shoppingItemField.setNew(true);
655 shoppingItemField.setPrimaryKey(itemFieldId);
656
657 return shoppingItemField;
658 }
659
660
668 public ShoppingItemField remove(long itemFieldId)
669 throws NoSuchItemFieldException, SystemException {
670 return remove(Long.valueOf(itemFieldId));
671 }
672
673
681 @Override
682 public ShoppingItemField remove(Serializable primaryKey)
683 throws NoSuchItemFieldException, SystemException {
684 Session session = null;
685
686 try {
687 session = openSession();
688
689 ShoppingItemField shoppingItemField = (ShoppingItemField)session.get(ShoppingItemFieldImpl.class,
690 primaryKey);
691
692 if (shoppingItemField == null) {
693 if (_log.isWarnEnabled()) {
694 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
695 }
696
697 throw new NoSuchItemFieldException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
698 primaryKey);
699 }
700
701 return remove(shoppingItemField);
702 }
703 catch (NoSuchItemFieldException nsee) {
704 throw nsee;
705 }
706 catch (Exception e) {
707 throw processException(e);
708 }
709 finally {
710 closeSession(session);
711 }
712 }
713
714 @Override
715 protected ShoppingItemField removeImpl(ShoppingItemField shoppingItemField)
716 throws SystemException {
717 shoppingItemField = toUnwrappedModel(shoppingItemField);
718
719 Session session = null;
720
721 try {
722 session = openSession();
723
724 if (!session.contains(shoppingItemField)) {
725 shoppingItemField = (ShoppingItemField)session.get(ShoppingItemFieldImpl.class,
726 shoppingItemField.getPrimaryKeyObj());
727 }
728
729 if (shoppingItemField != null) {
730 session.delete(shoppingItemField);
731 }
732 }
733 catch (Exception e) {
734 throw processException(e);
735 }
736 finally {
737 closeSession(session);
738 }
739
740 if (shoppingItemField != null) {
741 clearCache(shoppingItemField);
742 }
743
744 return shoppingItemField;
745 }
746
747 @Override
748 public ShoppingItemField updateImpl(
749 com.liferay.portlet.shopping.model.ShoppingItemField shoppingItemField)
750 throws SystemException {
751 shoppingItemField = toUnwrappedModel(shoppingItemField);
752
753 boolean isNew = shoppingItemField.isNew();
754
755 ShoppingItemFieldModelImpl shoppingItemFieldModelImpl = (ShoppingItemFieldModelImpl)shoppingItemField;
756
757 Session session = null;
758
759 try {
760 session = openSession();
761
762 if (shoppingItemField.isNew()) {
763 session.save(shoppingItemField);
764
765 shoppingItemField.setNew(false);
766 }
767 else {
768 session.merge(shoppingItemField);
769 }
770 }
771 catch (Exception e) {
772 throw processException(e);
773 }
774 finally {
775 closeSession(session);
776 }
777
778 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
779
780 if (isNew || !ShoppingItemFieldModelImpl.COLUMN_BITMASK_ENABLED) {
781 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
782 }
783
784 else {
785 if ((shoppingItemFieldModelImpl.getColumnBitmask() &
786 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ITEMID.getColumnBitmask()) != 0) {
787 Object[] args = new Object[] {
788 Long.valueOf(shoppingItemFieldModelImpl.getOriginalItemId())
789 };
790
791 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ITEMID, args);
792 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ITEMID,
793 args);
794
795 args = new Object[] {
796 Long.valueOf(shoppingItemFieldModelImpl.getItemId())
797 };
798
799 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ITEMID, args);
800 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ITEMID,
801 args);
802 }
803 }
804
805 EntityCacheUtil.putResult(ShoppingItemFieldModelImpl.ENTITY_CACHE_ENABLED,
806 ShoppingItemFieldImpl.class, shoppingItemField.getPrimaryKey(),
807 shoppingItemField);
808
809 return shoppingItemField;
810 }
811
812 protected ShoppingItemField toUnwrappedModel(
813 ShoppingItemField shoppingItemField) {
814 if (shoppingItemField instanceof ShoppingItemFieldImpl) {
815 return shoppingItemField;
816 }
817
818 ShoppingItemFieldImpl shoppingItemFieldImpl = new ShoppingItemFieldImpl();
819
820 shoppingItemFieldImpl.setNew(shoppingItemField.isNew());
821 shoppingItemFieldImpl.setPrimaryKey(shoppingItemField.getPrimaryKey());
822
823 shoppingItemFieldImpl.setItemFieldId(shoppingItemField.getItemFieldId());
824 shoppingItemFieldImpl.setItemId(shoppingItemField.getItemId());
825 shoppingItemFieldImpl.setName(shoppingItemField.getName());
826 shoppingItemFieldImpl.setValues(shoppingItemField.getValues());
827 shoppingItemFieldImpl.setDescription(shoppingItemField.getDescription());
828
829 return shoppingItemFieldImpl;
830 }
831
832
840 @Override
841 public ShoppingItemField findByPrimaryKey(Serializable primaryKey)
842 throws NoSuchModelException, SystemException {
843 return findByPrimaryKey(((Long)primaryKey).longValue());
844 }
845
846
854 public ShoppingItemField findByPrimaryKey(long itemFieldId)
855 throws NoSuchItemFieldException, SystemException {
856 ShoppingItemField shoppingItemField = fetchByPrimaryKey(itemFieldId);
857
858 if (shoppingItemField == null) {
859 if (_log.isWarnEnabled()) {
860 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + itemFieldId);
861 }
862
863 throw new NoSuchItemFieldException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
864 itemFieldId);
865 }
866
867 return shoppingItemField;
868 }
869
870
877 @Override
878 public ShoppingItemField fetchByPrimaryKey(Serializable primaryKey)
879 throws SystemException {
880 return fetchByPrimaryKey(((Long)primaryKey).longValue());
881 }
882
883
890 public ShoppingItemField fetchByPrimaryKey(long itemFieldId)
891 throws SystemException {
892 ShoppingItemField shoppingItemField = (ShoppingItemField)EntityCacheUtil.getResult(ShoppingItemFieldModelImpl.ENTITY_CACHE_ENABLED,
893 ShoppingItemFieldImpl.class, itemFieldId);
894
895 if (shoppingItemField == _nullShoppingItemField) {
896 return null;
897 }
898
899 if (shoppingItemField == null) {
900 Session session = null;
901
902 try {
903 session = openSession();
904
905 shoppingItemField = (ShoppingItemField)session.get(ShoppingItemFieldImpl.class,
906 Long.valueOf(itemFieldId));
907
908 if (shoppingItemField != null) {
909 cacheResult(shoppingItemField);
910 }
911 else {
912 EntityCacheUtil.putResult(ShoppingItemFieldModelImpl.ENTITY_CACHE_ENABLED,
913 ShoppingItemFieldImpl.class, itemFieldId,
914 _nullShoppingItemField);
915 }
916 }
917 catch (Exception e) {
918 EntityCacheUtil.removeResult(ShoppingItemFieldModelImpl.ENTITY_CACHE_ENABLED,
919 ShoppingItemFieldImpl.class, itemFieldId);
920
921 throw processException(e);
922 }
923 finally {
924 closeSession(session);
925 }
926 }
927
928 return shoppingItemField;
929 }
930
931
937 public List<ShoppingItemField> findAll() throws SystemException {
938 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
939 }
940
941
953 public List<ShoppingItemField> findAll(int start, int end)
954 throws SystemException {
955 return findAll(start, end, null);
956 }
957
958
971 public List<ShoppingItemField> findAll(int start, int end,
972 OrderByComparator orderByComparator) throws SystemException {
973 boolean pagination = true;
974 FinderPath finderPath = null;
975 Object[] finderArgs = null;
976
977 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
978 (orderByComparator == null)) {
979 pagination = false;
980 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
981 finderArgs = FINDER_ARGS_EMPTY;
982 }
983 else {
984 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
985 finderArgs = new Object[] { start, end, orderByComparator };
986 }
987
988 List<ShoppingItemField> list = (List<ShoppingItemField>)FinderCacheUtil.getResult(finderPath,
989 finderArgs, this);
990
991 if (list == null) {
992 StringBundler query = null;
993 String sql = null;
994
995 if (orderByComparator != null) {
996 query = new StringBundler(2 +
997 (orderByComparator.getOrderByFields().length * 3));
998
999 query.append(_SQL_SELECT_SHOPPINGITEMFIELD);
1000
1001 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1002 orderByComparator);
1003
1004 sql = query.toString();
1005 }
1006 else {
1007 sql = _SQL_SELECT_SHOPPINGITEMFIELD;
1008
1009 if (pagination) {
1010 sql = sql.concat(ShoppingItemFieldModelImpl.ORDER_BY_JPQL);
1011 }
1012 }
1013
1014 Session session = null;
1015
1016 try {
1017 session = openSession();
1018
1019 Query q = session.createQuery(sql);
1020
1021 if (!pagination) {
1022 list = (List<ShoppingItemField>)QueryUtil.list(q,
1023 getDialect(), start, end, false);
1024
1025 Collections.sort(list);
1026
1027 list = new UnmodifiableList<ShoppingItemField>(list);
1028 }
1029 else {
1030 list = (List<ShoppingItemField>)QueryUtil.list(q,
1031 getDialect(), start, end);
1032 }
1033
1034 cacheResult(list);
1035
1036 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1037 }
1038 catch (Exception e) {
1039 FinderCacheUtil.removeResult(finderPath, finderArgs);
1040
1041 throw processException(e);
1042 }
1043 finally {
1044 closeSession(session);
1045 }
1046 }
1047
1048 return list;
1049 }
1050
1051
1056 public void removeAll() throws SystemException {
1057 for (ShoppingItemField shoppingItemField : findAll()) {
1058 remove(shoppingItemField);
1059 }
1060 }
1061
1062
1068 public int countAll() throws SystemException {
1069 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1070 FINDER_ARGS_EMPTY, this);
1071
1072 if (count == null) {
1073 Session session = null;
1074
1075 try {
1076 session = openSession();
1077
1078 Query q = session.createQuery(_SQL_COUNT_SHOPPINGITEMFIELD);
1079
1080 count = (Long)q.uniqueResult();
1081
1082 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1083 FINDER_ARGS_EMPTY, count);
1084 }
1085 catch (Exception e) {
1086 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
1087 FINDER_ARGS_EMPTY);
1088
1089 throw processException(e);
1090 }
1091 finally {
1092 closeSession(session);
1093 }
1094 }
1095
1096 return count.intValue();
1097 }
1098
1099
1102 public void afterPropertiesSet() {
1103 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1104 com.liferay.portal.util.PropsUtil.get(
1105 "value.object.listener.com.liferay.portlet.shopping.model.ShoppingItemField")));
1106
1107 if (listenerClassNames.length > 0) {
1108 try {
1109 List<ModelListener<ShoppingItemField>> listenersList = new ArrayList<ModelListener<ShoppingItemField>>();
1110
1111 for (String listenerClassName : listenerClassNames) {
1112 listenersList.add((ModelListener<ShoppingItemField>)InstanceFactory.newInstance(
1113 listenerClassName));
1114 }
1115
1116 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1117 }
1118 catch (Exception e) {
1119 _log.error(e);
1120 }
1121 }
1122 }
1123
1124 public void destroy() {
1125 EntityCacheUtil.removeCache(ShoppingItemFieldImpl.class.getName());
1126 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1127 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1128 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1129 }
1130
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 _ORDER_BY_ENTITY_ALIAS = "shoppingItemField.";
1136 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ShoppingItemField exists with the primary key ";
1137 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ShoppingItemField exists with the key {";
1138 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1139 private static Log _log = LogFactoryUtil.getLog(ShoppingItemFieldPersistenceImpl.class);
1140 private static ShoppingItemField _nullShoppingItemField = new ShoppingItemFieldImpl() {
1141 @Override
1142 public Object clone() {
1143 return this;
1144 }
1145
1146 @Override
1147 public CacheModel<ShoppingItemField> toCacheModel() {
1148 return _nullShoppingItemFieldCacheModel;
1149 }
1150 };
1151
1152 private static CacheModel<ShoppingItemField> _nullShoppingItemFieldCacheModel =
1153 new CacheModel<ShoppingItemField>() {
1154 public ShoppingItemField toEntityModel() {
1155 return _nullShoppingItemField;
1156 }
1157 };
1158 }