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_WITH_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_WITHOUT_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 @Override
180 public void clearCache(List<ShoppingItemField> shoppingItemFields) {
181 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
182 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
183
184 for (ShoppingItemField shoppingItemField : shoppingItemFields) {
185 EntityCacheUtil.removeResult(ShoppingItemFieldModelImpl.ENTITY_CACHE_ENABLED,
186 ShoppingItemFieldImpl.class, shoppingItemField.getPrimaryKey());
187 }
188 }
189
190
196 public ShoppingItemField create(long itemFieldId) {
197 ShoppingItemField shoppingItemField = new ShoppingItemFieldImpl();
198
199 shoppingItemField.setNew(true);
200 shoppingItemField.setPrimaryKey(itemFieldId);
201
202 return shoppingItemField;
203 }
204
205
213 public ShoppingItemField remove(long itemFieldId)
214 throws NoSuchItemFieldException, SystemException {
215 return remove(Long.valueOf(itemFieldId));
216 }
217
218
226 @Override
227 public ShoppingItemField remove(Serializable primaryKey)
228 throws NoSuchItemFieldException, SystemException {
229 Session session = null;
230
231 try {
232 session = openSession();
233
234 ShoppingItemField shoppingItemField = (ShoppingItemField)session.get(ShoppingItemFieldImpl.class,
235 primaryKey);
236
237 if (shoppingItemField == null) {
238 if (_log.isWarnEnabled()) {
239 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
240 }
241
242 throw new NoSuchItemFieldException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
243 primaryKey);
244 }
245
246 return remove(shoppingItemField);
247 }
248 catch (NoSuchItemFieldException 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 ShoppingItemField removeImpl(ShoppingItemField shoppingItemField)
261 throws SystemException {
262 shoppingItemField = toUnwrappedModel(shoppingItemField);
263
264 Session session = null;
265
266 try {
267 session = openSession();
268
269 BatchSessionUtil.delete(session, shoppingItemField);
270 }
271 catch (Exception e) {
272 throw processException(e);
273 }
274 finally {
275 closeSession(session);
276 }
277
278 clearCache(shoppingItemField);
279
280 return shoppingItemField;
281 }
282
283 @Override
284 public ShoppingItemField updateImpl(
285 com.liferay.portlet.shopping.model.ShoppingItemField shoppingItemField,
286 boolean merge) throws SystemException {
287 shoppingItemField = toUnwrappedModel(shoppingItemField);
288
289 boolean isNew = shoppingItemField.isNew();
290
291 ShoppingItemFieldModelImpl shoppingItemFieldModelImpl = (ShoppingItemFieldModelImpl)shoppingItemField;
292
293 Session session = null;
294
295 try {
296 session = openSession();
297
298 BatchSessionUtil.update(session, shoppingItemField, merge);
299
300 shoppingItemField.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 || !ShoppingItemFieldModelImpl.COLUMN_BITMASK_ENABLED) {
312 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
313 }
314 else {
315 if ((shoppingItemFieldModelImpl.getColumnBitmask() &
316 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ITEMID.getColumnBitmask()) != 0) {
317 Object[] args = new Object[] {
318 Long.valueOf(shoppingItemFieldModelImpl.getOriginalItemId())
319 };
320
321 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ITEMID, args);
322 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ITEMID,
323 args);
324
325 args = new Object[] {
326 Long.valueOf(shoppingItemFieldModelImpl.getItemId())
327 };
328
329 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ITEMID, args);
330 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ITEMID,
331 args);
332 }
333 }
334
335 EntityCacheUtil.putResult(ShoppingItemFieldModelImpl.ENTITY_CACHE_ENABLED,
336 ShoppingItemFieldImpl.class, shoppingItemField.getPrimaryKey(),
337 shoppingItemField);
338
339 return shoppingItemField;
340 }
341
342 protected ShoppingItemField toUnwrappedModel(
343 ShoppingItemField shoppingItemField) {
344 if (shoppingItemField instanceof ShoppingItemFieldImpl) {
345 return shoppingItemField;
346 }
347
348 ShoppingItemFieldImpl shoppingItemFieldImpl = new ShoppingItemFieldImpl();
349
350 shoppingItemFieldImpl.setNew(shoppingItemField.isNew());
351 shoppingItemFieldImpl.setPrimaryKey(shoppingItemField.getPrimaryKey());
352
353 shoppingItemFieldImpl.setItemFieldId(shoppingItemField.getItemFieldId());
354 shoppingItemFieldImpl.setItemId(shoppingItemField.getItemId());
355 shoppingItemFieldImpl.setName(shoppingItemField.getName());
356 shoppingItemFieldImpl.setValues(shoppingItemField.getValues());
357 shoppingItemFieldImpl.setDescription(shoppingItemField.getDescription());
358
359 return shoppingItemFieldImpl;
360 }
361
362
370 @Override
371 public ShoppingItemField findByPrimaryKey(Serializable primaryKey)
372 throws NoSuchModelException, SystemException {
373 return findByPrimaryKey(((Long)primaryKey).longValue());
374 }
375
376
384 public ShoppingItemField findByPrimaryKey(long itemFieldId)
385 throws NoSuchItemFieldException, SystemException {
386 ShoppingItemField shoppingItemField = fetchByPrimaryKey(itemFieldId);
387
388 if (shoppingItemField == null) {
389 if (_log.isWarnEnabled()) {
390 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + itemFieldId);
391 }
392
393 throw new NoSuchItemFieldException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
394 itemFieldId);
395 }
396
397 return shoppingItemField;
398 }
399
400
407 @Override
408 public ShoppingItemField fetchByPrimaryKey(Serializable primaryKey)
409 throws SystemException {
410 return fetchByPrimaryKey(((Long)primaryKey).longValue());
411 }
412
413
420 public ShoppingItemField fetchByPrimaryKey(long itemFieldId)
421 throws SystemException {
422 ShoppingItemField shoppingItemField = (ShoppingItemField)EntityCacheUtil.getResult(ShoppingItemFieldModelImpl.ENTITY_CACHE_ENABLED,
423 ShoppingItemFieldImpl.class, itemFieldId);
424
425 if (shoppingItemField == _nullShoppingItemField) {
426 return null;
427 }
428
429 if (shoppingItemField == null) {
430 Session session = null;
431
432 boolean hasException = false;
433
434 try {
435 session = openSession();
436
437 shoppingItemField = (ShoppingItemField)session.get(ShoppingItemFieldImpl.class,
438 Long.valueOf(itemFieldId));
439 }
440 catch (Exception e) {
441 hasException = true;
442
443 throw processException(e);
444 }
445 finally {
446 if (shoppingItemField != null) {
447 cacheResult(shoppingItemField);
448 }
449 else if (!hasException) {
450 EntityCacheUtil.putResult(ShoppingItemFieldModelImpl.ENTITY_CACHE_ENABLED,
451 ShoppingItemFieldImpl.class, itemFieldId,
452 _nullShoppingItemField);
453 }
454
455 closeSession(session);
456 }
457 }
458
459 return shoppingItemField;
460 }
461
462
469 public List<ShoppingItemField> findByItemId(long itemId)
470 throws SystemException {
471 return findByItemId(itemId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
472 }
473
474
487 public List<ShoppingItemField> findByItemId(long itemId, int start, int end)
488 throws SystemException {
489 return findByItemId(itemId, start, end, null);
490 }
491
492
506 public List<ShoppingItemField> findByItemId(long itemId, int start,
507 int end, OrderByComparator orderByComparator) throws SystemException {
508 FinderPath finderPath = null;
509 Object[] finderArgs = null;
510
511 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
512 (orderByComparator == null)) {
513 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ITEMID;
514 finderArgs = new Object[] { itemId };
515 }
516 else {
517 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_ITEMID;
518 finderArgs = new Object[] { itemId, start, end, orderByComparator };
519 }
520
521 List<ShoppingItemField> list = (List<ShoppingItemField>)FinderCacheUtil.getResult(finderPath,
522 finderArgs, this);
523
524 if ((list != null) && !list.isEmpty()) {
525 for (ShoppingItemField shoppingItemField : list) {
526 if ((itemId != shoppingItemField.getItemId())) {
527 list = null;
528
529 break;
530 }
531 }
532 }
533
534 if (list == null) {
535 StringBundler query = null;
536
537 if (orderByComparator != null) {
538 query = new StringBundler(3 +
539 (orderByComparator.getOrderByFields().length * 3));
540 }
541 else {
542 query = new StringBundler(3);
543 }
544
545 query.append(_SQL_SELECT_SHOPPINGITEMFIELD_WHERE);
546
547 query.append(_FINDER_COLUMN_ITEMID_ITEMID_2);
548
549 if (orderByComparator != null) {
550 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
551 orderByComparator);
552 }
553
554 else {
555 query.append(ShoppingItemFieldModelImpl.ORDER_BY_JPQL);
556 }
557
558 String sql = query.toString();
559
560 Session session = null;
561
562 try {
563 session = openSession();
564
565 Query q = session.createQuery(sql);
566
567 QueryPos qPos = QueryPos.getInstance(q);
568
569 qPos.add(itemId);
570
571 list = (List<ShoppingItemField>)QueryUtil.list(q, getDialect(),
572 start, end);
573 }
574 catch (Exception e) {
575 throw processException(e);
576 }
577 finally {
578 if (list == null) {
579 FinderCacheUtil.removeResult(finderPath, finderArgs);
580 }
581 else {
582 cacheResult(list);
583
584 FinderCacheUtil.putResult(finderPath, finderArgs, list);
585 }
586
587 closeSession(session);
588 }
589 }
590
591 return list;
592 }
593
594
607 public ShoppingItemField findByItemId_First(long itemId,
608 OrderByComparator orderByComparator)
609 throws NoSuchItemFieldException, SystemException {
610 List<ShoppingItemField> list = findByItemId(itemId, 0, 1,
611 orderByComparator);
612
613 if (list.isEmpty()) {
614 StringBundler msg = new StringBundler(4);
615
616 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
617
618 msg.append("itemId=");
619 msg.append(itemId);
620
621 msg.append(StringPool.CLOSE_CURLY_BRACE);
622
623 throw new NoSuchItemFieldException(msg.toString());
624 }
625 else {
626 return list.get(0);
627 }
628 }
629
630
643 public ShoppingItemField findByItemId_Last(long itemId,
644 OrderByComparator orderByComparator)
645 throws NoSuchItemFieldException, SystemException {
646 int count = countByItemId(itemId);
647
648 List<ShoppingItemField> list = findByItemId(itemId, count - 1, count,
649 orderByComparator);
650
651 if (list.isEmpty()) {
652 StringBundler msg = new StringBundler(4);
653
654 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
655
656 msg.append("itemId=");
657 msg.append(itemId);
658
659 msg.append(StringPool.CLOSE_CURLY_BRACE);
660
661 throw new NoSuchItemFieldException(msg.toString());
662 }
663 else {
664 return list.get(0);
665 }
666 }
667
668
682 public ShoppingItemField[] findByItemId_PrevAndNext(long itemFieldId,
683 long itemId, OrderByComparator orderByComparator)
684 throws NoSuchItemFieldException, SystemException {
685 ShoppingItemField shoppingItemField = findByPrimaryKey(itemFieldId);
686
687 Session session = null;
688
689 try {
690 session = openSession();
691
692 ShoppingItemField[] array = new ShoppingItemFieldImpl[3];
693
694 array[0] = getByItemId_PrevAndNext(session, shoppingItemField,
695 itemId, orderByComparator, true);
696
697 array[1] = shoppingItemField;
698
699 array[2] = getByItemId_PrevAndNext(session, shoppingItemField,
700 itemId, orderByComparator, false);
701
702 return array;
703 }
704 catch (Exception e) {
705 throw processException(e);
706 }
707 finally {
708 closeSession(session);
709 }
710 }
711
712 protected ShoppingItemField getByItemId_PrevAndNext(Session session,
713 ShoppingItemField shoppingItemField, long itemId,
714 OrderByComparator orderByComparator, boolean previous) {
715 StringBundler query = null;
716
717 if (orderByComparator != null) {
718 query = new StringBundler(6 +
719 (orderByComparator.getOrderByFields().length * 6));
720 }
721 else {
722 query = new StringBundler(3);
723 }
724
725 query.append(_SQL_SELECT_SHOPPINGITEMFIELD_WHERE);
726
727 query.append(_FINDER_COLUMN_ITEMID_ITEMID_2);
728
729 if (orderByComparator != null) {
730 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
731
732 if (orderByConditionFields.length > 0) {
733 query.append(WHERE_AND);
734 }
735
736 for (int i = 0; i < orderByConditionFields.length; i++) {
737 query.append(_ORDER_BY_ENTITY_ALIAS);
738 query.append(orderByConditionFields[i]);
739
740 if ((i + 1) < orderByConditionFields.length) {
741 if (orderByComparator.isAscending() ^ previous) {
742 query.append(WHERE_GREATER_THAN_HAS_NEXT);
743 }
744 else {
745 query.append(WHERE_LESSER_THAN_HAS_NEXT);
746 }
747 }
748 else {
749 if (orderByComparator.isAscending() ^ previous) {
750 query.append(WHERE_GREATER_THAN);
751 }
752 else {
753 query.append(WHERE_LESSER_THAN);
754 }
755 }
756 }
757
758 query.append(ORDER_BY_CLAUSE);
759
760 String[] orderByFields = orderByComparator.getOrderByFields();
761
762 for (int i = 0; i < orderByFields.length; i++) {
763 query.append(_ORDER_BY_ENTITY_ALIAS);
764 query.append(orderByFields[i]);
765
766 if ((i + 1) < orderByFields.length) {
767 if (orderByComparator.isAscending() ^ previous) {
768 query.append(ORDER_BY_ASC_HAS_NEXT);
769 }
770 else {
771 query.append(ORDER_BY_DESC_HAS_NEXT);
772 }
773 }
774 else {
775 if (orderByComparator.isAscending() ^ previous) {
776 query.append(ORDER_BY_ASC);
777 }
778 else {
779 query.append(ORDER_BY_DESC);
780 }
781 }
782 }
783 }
784
785 else {
786 query.append(ShoppingItemFieldModelImpl.ORDER_BY_JPQL);
787 }
788
789 String sql = query.toString();
790
791 Query q = session.createQuery(sql);
792
793 q.setFirstResult(0);
794 q.setMaxResults(2);
795
796 QueryPos qPos = QueryPos.getInstance(q);
797
798 qPos.add(itemId);
799
800 if (orderByComparator != null) {
801 Object[] values = orderByComparator.getOrderByConditionValues(shoppingItemField);
802
803 for (Object value : values) {
804 qPos.add(value);
805 }
806 }
807
808 List<ShoppingItemField> list = q.list();
809
810 if (list.size() == 2) {
811 return list.get(1);
812 }
813 else {
814 return null;
815 }
816 }
817
818
824 public List<ShoppingItemField> findAll() throws SystemException {
825 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
826 }
827
828
840 public List<ShoppingItemField> findAll(int start, int end)
841 throws SystemException {
842 return findAll(start, end, null);
843 }
844
845
858 public List<ShoppingItemField> findAll(int start, int end,
859 OrderByComparator orderByComparator) throws SystemException {
860 FinderPath finderPath = null;
861 Object[] finderArgs = new Object[] { start, end, orderByComparator };
862
863 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
864 (orderByComparator == null)) {
865 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
866 finderArgs = FINDER_ARGS_EMPTY;
867 }
868 else {
869 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
870 finderArgs = new Object[] { start, end, orderByComparator };
871 }
872
873 List<ShoppingItemField> list = (List<ShoppingItemField>)FinderCacheUtil.getResult(finderPath,
874 finderArgs, this);
875
876 if (list == null) {
877 StringBundler query = null;
878 String sql = null;
879
880 if (orderByComparator != null) {
881 query = new StringBundler(2 +
882 (orderByComparator.getOrderByFields().length * 3));
883
884 query.append(_SQL_SELECT_SHOPPINGITEMFIELD);
885
886 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
887 orderByComparator);
888
889 sql = query.toString();
890 }
891 else {
892 sql = _SQL_SELECT_SHOPPINGITEMFIELD.concat(ShoppingItemFieldModelImpl.ORDER_BY_JPQL);
893 }
894
895 Session session = null;
896
897 try {
898 session = openSession();
899
900 Query q = session.createQuery(sql);
901
902 if (orderByComparator == null) {
903 list = (List<ShoppingItemField>)QueryUtil.list(q,
904 getDialect(), start, end, false);
905
906 Collections.sort(list);
907 }
908 else {
909 list = (List<ShoppingItemField>)QueryUtil.list(q,
910 getDialect(), start, end);
911 }
912 }
913 catch (Exception e) {
914 throw processException(e);
915 }
916 finally {
917 if (list == null) {
918 FinderCacheUtil.removeResult(finderPath, finderArgs);
919 }
920 else {
921 cacheResult(list);
922
923 FinderCacheUtil.putResult(finderPath, finderArgs, list);
924 }
925
926 closeSession(session);
927 }
928 }
929
930 return list;
931 }
932
933
939 public void removeByItemId(long itemId) throws SystemException {
940 for (ShoppingItemField shoppingItemField : findByItemId(itemId)) {
941 remove(shoppingItemField);
942 }
943 }
944
945
950 public void removeAll() throws SystemException {
951 for (ShoppingItemField shoppingItemField : findAll()) {
952 remove(shoppingItemField);
953 }
954 }
955
956
963 public int countByItemId(long itemId) throws SystemException {
964 Object[] finderArgs = new Object[] { itemId };
965
966 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_ITEMID,
967 finderArgs, this);
968
969 if (count == null) {
970 StringBundler query = new StringBundler(2);
971
972 query.append(_SQL_COUNT_SHOPPINGITEMFIELD_WHERE);
973
974 query.append(_FINDER_COLUMN_ITEMID_ITEMID_2);
975
976 String sql = query.toString();
977
978 Session session = null;
979
980 try {
981 session = openSession();
982
983 Query q = session.createQuery(sql);
984
985 QueryPos qPos = QueryPos.getInstance(q);
986
987 qPos.add(itemId);
988
989 count = (Long)q.uniqueResult();
990 }
991 catch (Exception e) {
992 throw processException(e);
993 }
994 finally {
995 if (count == null) {
996 count = Long.valueOf(0);
997 }
998
999 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_ITEMID,
1000 finderArgs, count);
1001
1002 closeSession(session);
1003 }
1004 }
1005
1006 return count.intValue();
1007 }
1008
1009
1015 public int countAll() throws SystemException {
1016 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1017 FINDER_ARGS_EMPTY, this);
1018
1019 if (count == null) {
1020 Session session = null;
1021
1022 try {
1023 session = openSession();
1024
1025 Query q = session.createQuery(_SQL_COUNT_SHOPPINGITEMFIELD);
1026
1027 count = (Long)q.uniqueResult();
1028 }
1029 catch (Exception e) {
1030 throw processException(e);
1031 }
1032 finally {
1033 if (count == null) {
1034 count = Long.valueOf(0);
1035 }
1036
1037 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1038 FINDER_ARGS_EMPTY, count);
1039
1040 closeSession(session);
1041 }
1042 }
1043
1044 return count.intValue();
1045 }
1046
1047
1050 public void afterPropertiesSet() {
1051 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1052 com.liferay.portal.util.PropsUtil.get(
1053 "value.object.listener.com.liferay.portlet.shopping.model.ShoppingItemField")));
1054
1055 if (listenerClassNames.length > 0) {
1056 try {
1057 List<ModelListener<ShoppingItemField>> listenersList = new ArrayList<ModelListener<ShoppingItemField>>();
1058
1059 for (String listenerClassName : listenerClassNames) {
1060 listenersList.add((ModelListener<ShoppingItemField>)InstanceFactory.newInstance(
1061 listenerClassName));
1062 }
1063
1064 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1065 }
1066 catch (Exception e) {
1067 _log.error(e);
1068 }
1069 }
1070 }
1071
1072 public void destroy() {
1073 EntityCacheUtil.removeCache(ShoppingItemFieldImpl.class.getName());
1074 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1075 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1076 }
1077
1078 @BeanReference(type = ShoppingCartPersistence.class)
1079 protected ShoppingCartPersistence shoppingCartPersistence;
1080 @BeanReference(type = ShoppingCategoryPersistence.class)
1081 protected ShoppingCategoryPersistence shoppingCategoryPersistence;
1082 @BeanReference(type = ShoppingCouponPersistence.class)
1083 protected ShoppingCouponPersistence shoppingCouponPersistence;
1084 @BeanReference(type = ShoppingItemPersistence.class)
1085 protected ShoppingItemPersistence shoppingItemPersistence;
1086 @BeanReference(type = ShoppingItemFieldPersistence.class)
1087 protected ShoppingItemFieldPersistence shoppingItemFieldPersistence;
1088 @BeanReference(type = ShoppingItemPricePersistence.class)
1089 protected ShoppingItemPricePersistence shoppingItemPricePersistence;
1090 @BeanReference(type = ShoppingOrderPersistence.class)
1091 protected ShoppingOrderPersistence shoppingOrderPersistence;
1092 @BeanReference(type = ShoppingOrderItemPersistence.class)
1093 protected ShoppingOrderItemPersistence shoppingOrderItemPersistence;
1094 @BeanReference(type = ResourcePersistence.class)
1095 protected ResourcePersistence resourcePersistence;
1096 @BeanReference(type = UserPersistence.class)
1097 protected UserPersistence userPersistence;
1098 private static final String _SQL_SELECT_SHOPPINGITEMFIELD = "SELECT shoppingItemField FROM ShoppingItemField shoppingItemField";
1099 private static final String _SQL_SELECT_SHOPPINGITEMFIELD_WHERE = "SELECT shoppingItemField FROM ShoppingItemField shoppingItemField WHERE ";
1100 private static final String _SQL_COUNT_SHOPPINGITEMFIELD = "SELECT COUNT(shoppingItemField) FROM ShoppingItemField shoppingItemField";
1101 private static final String _SQL_COUNT_SHOPPINGITEMFIELD_WHERE = "SELECT COUNT(shoppingItemField) FROM ShoppingItemField shoppingItemField WHERE ";
1102 private static final String _FINDER_COLUMN_ITEMID_ITEMID_2 = "shoppingItemField.itemId = ?";
1103 private static final String _ORDER_BY_ENTITY_ALIAS = "shoppingItemField.";
1104 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ShoppingItemField exists with the primary key ";
1105 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ShoppingItemField exists with the key {";
1106 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1107 private static Log _log = LogFactoryUtil.getLog(ShoppingItemFieldPersistenceImpl.class);
1108 private static ShoppingItemField _nullShoppingItemField = new ShoppingItemFieldImpl() {
1109 @Override
1110 public Object clone() {
1111 return this;
1112 }
1113
1114 @Override
1115 public CacheModel<ShoppingItemField> toCacheModel() {
1116 return _nullShoppingItemFieldCacheModel;
1117 }
1118 };
1119
1120 private static CacheModel<ShoppingItemField> _nullShoppingItemFieldCacheModel =
1121 new CacheModel<ShoppingItemField>() {
1122 public ShoppingItemField toEntityModel() {
1123 return _nullShoppingItemField;
1124 }
1125 };
1126 }