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
315 else {
316 if ((shoppingItemFieldModelImpl.getColumnBitmask() &
317 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ITEMID.getColumnBitmask()) != 0) {
318 Object[] args = new Object[] {
319 Long.valueOf(shoppingItemFieldModelImpl.getOriginalItemId())
320 };
321
322 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ITEMID, args);
323 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ITEMID,
324 args);
325
326 args = new Object[] {
327 Long.valueOf(shoppingItemFieldModelImpl.getItemId())
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 }
335
336 EntityCacheUtil.putResult(ShoppingItemFieldModelImpl.ENTITY_CACHE_ENABLED,
337 ShoppingItemFieldImpl.class, shoppingItemField.getPrimaryKey(),
338 shoppingItemField);
339
340 return shoppingItemField;
341 }
342
343 protected ShoppingItemField toUnwrappedModel(
344 ShoppingItemField shoppingItemField) {
345 if (shoppingItemField instanceof ShoppingItemFieldImpl) {
346 return shoppingItemField;
347 }
348
349 ShoppingItemFieldImpl shoppingItemFieldImpl = new ShoppingItemFieldImpl();
350
351 shoppingItemFieldImpl.setNew(shoppingItemField.isNew());
352 shoppingItemFieldImpl.setPrimaryKey(shoppingItemField.getPrimaryKey());
353
354 shoppingItemFieldImpl.setItemFieldId(shoppingItemField.getItemFieldId());
355 shoppingItemFieldImpl.setItemId(shoppingItemField.getItemId());
356 shoppingItemFieldImpl.setName(shoppingItemField.getName());
357 shoppingItemFieldImpl.setValues(shoppingItemField.getValues());
358 shoppingItemFieldImpl.setDescription(shoppingItemField.getDescription());
359
360 return shoppingItemFieldImpl;
361 }
362
363
371 @Override
372 public ShoppingItemField findByPrimaryKey(Serializable primaryKey)
373 throws NoSuchModelException, SystemException {
374 return findByPrimaryKey(((Long)primaryKey).longValue());
375 }
376
377
385 public ShoppingItemField findByPrimaryKey(long itemFieldId)
386 throws NoSuchItemFieldException, SystemException {
387 ShoppingItemField shoppingItemField = fetchByPrimaryKey(itemFieldId);
388
389 if (shoppingItemField == null) {
390 if (_log.isWarnEnabled()) {
391 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + itemFieldId);
392 }
393
394 throw new NoSuchItemFieldException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
395 itemFieldId);
396 }
397
398 return shoppingItemField;
399 }
400
401
408 @Override
409 public ShoppingItemField fetchByPrimaryKey(Serializable primaryKey)
410 throws SystemException {
411 return fetchByPrimaryKey(((Long)primaryKey).longValue());
412 }
413
414
421 public ShoppingItemField fetchByPrimaryKey(long itemFieldId)
422 throws SystemException {
423 ShoppingItemField shoppingItemField = (ShoppingItemField)EntityCacheUtil.getResult(ShoppingItemFieldModelImpl.ENTITY_CACHE_ENABLED,
424 ShoppingItemFieldImpl.class, itemFieldId);
425
426 if (shoppingItemField == _nullShoppingItemField) {
427 return null;
428 }
429
430 if (shoppingItemField == null) {
431 Session session = null;
432
433 boolean hasException = false;
434
435 try {
436 session = openSession();
437
438 shoppingItemField = (ShoppingItemField)session.get(ShoppingItemFieldImpl.class,
439 Long.valueOf(itemFieldId));
440 }
441 catch (Exception e) {
442 hasException = true;
443
444 throw processException(e);
445 }
446 finally {
447 if (shoppingItemField != null) {
448 cacheResult(shoppingItemField);
449 }
450 else if (!hasException) {
451 EntityCacheUtil.putResult(ShoppingItemFieldModelImpl.ENTITY_CACHE_ENABLED,
452 ShoppingItemFieldImpl.class, itemFieldId,
453 _nullShoppingItemField);
454 }
455
456 closeSession(session);
457 }
458 }
459
460 return shoppingItemField;
461 }
462
463
470 public List<ShoppingItemField> findByItemId(long itemId)
471 throws SystemException {
472 return findByItemId(itemId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
473 }
474
475
488 public List<ShoppingItemField> findByItemId(long itemId, int start, int end)
489 throws SystemException {
490 return findByItemId(itemId, start, end, null);
491 }
492
493
507 public List<ShoppingItemField> findByItemId(long itemId, int start,
508 int end, OrderByComparator orderByComparator) throws SystemException {
509 FinderPath finderPath = null;
510 Object[] finderArgs = null;
511
512 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
513 (orderByComparator == null)) {
514 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ITEMID;
515 finderArgs = new Object[] { itemId };
516 }
517 else {
518 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_ITEMID;
519 finderArgs = new Object[] { itemId, start, end, orderByComparator };
520 }
521
522 List<ShoppingItemField> list = (List<ShoppingItemField>)FinderCacheUtil.getResult(finderPath,
523 finderArgs, this);
524
525 if ((list != null) && !list.isEmpty()) {
526 for (ShoppingItemField shoppingItemField : list) {
527 if ((itemId != shoppingItemField.getItemId())) {
528 list = null;
529
530 break;
531 }
532 }
533 }
534
535 if (list == null) {
536 StringBundler query = null;
537
538 if (orderByComparator != null) {
539 query = new StringBundler(3 +
540 (orderByComparator.getOrderByFields().length * 3));
541 }
542 else {
543 query = new StringBundler(3);
544 }
545
546 query.append(_SQL_SELECT_SHOPPINGITEMFIELD_WHERE);
547
548 query.append(_FINDER_COLUMN_ITEMID_ITEMID_2);
549
550 if (orderByComparator != null) {
551 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
552 orderByComparator);
553 }
554
555 else {
556 query.append(ShoppingItemFieldModelImpl.ORDER_BY_JPQL);
557 }
558
559 String sql = query.toString();
560
561 Session session = null;
562
563 try {
564 session = openSession();
565
566 Query q = session.createQuery(sql);
567
568 QueryPos qPos = QueryPos.getInstance(q);
569
570 qPos.add(itemId);
571
572 list = (List<ShoppingItemField>)QueryUtil.list(q, getDialect(),
573 start, end);
574 }
575 catch (Exception e) {
576 throw processException(e);
577 }
578 finally {
579 if (list == null) {
580 FinderCacheUtil.removeResult(finderPath, finderArgs);
581 }
582 else {
583 cacheResult(list);
584
585 FinderCacheUtil.putResult(finderPath, finderArgs, list);
586 }
587
588 closeSession(session);
589 }
590 }
591
592 return list;
593 }
594
595
604 public ShoppingItemField findByItemId_First(long itemId,
605 OrderByComparator orderByComparator)
606 throws NoSuchItemFieldException, SystemException {
607 ShoppingItemField shoppingItemField = fetchByItemId_First(itemId,
608 orderByComparator);
609
610 if (shoppingItemField != null) {
611 return shoppingItemField;
612 }
613
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
626
634 public ShoppingItemField fetchByItemId_First(long itemId,
635 OrderByComparator orderByComparator) throws SystemException {
636 List<ShoppingItemField> list = findByItemId(itemId, 0, 1,
637 orderByComparator);
638
639 if (!list.isEmpty()) {
640 return list.get(0);
641 }
642
643 return null;
644 }
645
646
655 public ShoppingItemField findByItemId_Last(long itemId,
656 OrderByComparator orderByComparator)
657 throws NoSuchItemFieldException, SystemException {
658 ShoppingItemField shoppingItemField = fetchByItemId_Last(itemId,
659 orderByComparator);
660
661 if (shoppingItemField != null) {
662 return shoppingItemField;
663 }
664
665 StringBundler msg = new StringBundler(4);
666
667 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
668
669 msg.append("itemId=");
670 msg.append(itemId);
671
672 msg.append(StringPool.CLOSE_CURLY_BRACE);
673
674 throw new NoSuchItemFieldException(msg.toString());
675 }
676
677
685 public ShoppingItemField fetchByItemId_Last(long itemId,
686 OrderByComparator orderByComparator) throws SystemException {
687 int count = countByItemId(itemId);
688
689 List<ShoppingItemField> list = findByItemId(itemId, count - 1, count,
690 orderByComparator);
691
692 if (!list.isEmpty()) {
693 return list.get(0);
694 }
695
696 return null;
697 }
698
699
709 public ShoppingItemField[] findByItemId_PrevAndNext(long itemFieldId,
710 long itemId, OrderByComparator orderByComparator)
711 throws NoSuchItemFieldException, SystemException {
712 ShoppingItemField shoppingItemField = findByPrimaryKey(itemFieldId);
713
714 Session session = null;
715
716 try {
717 session = openSession();
718
719 ShoppingItemField[] array = new ShoppingItemFieldImpl[3];
720
721 array[0] = getByItemId_PrevAndNext(session, shoppingItemField,
722 itemId, orderByComparator, true);
723
724 array[1] = shoppingItemField;
725
726 array[2] = getByItemId_PrevAndNext(session, shoppingItemField,
727 itemId, orderByComparator, false);
728
729 return array;
730 }
731 catch (Exception e) {
732 throw processException(e);
733 }
734 finally {
735 closeSession(session);
736 }
737 }
738
739 protected ShoppingItemField getByItemId_PrevAndNext(Session session,
740 ShoppingItemField shoppingItemField, long itemId,
741 OrderByComparator orderByComparator, boolean previous) {
742 StringBundler query = null;
743
744 if (orderByComparator != null) {
745 query = new StringBundler(6 +
746 (orderByComparator.getOrderByFields().length * 6));
747 }
748 else {
749 query = new StringBundler(3);
750 }
751
752 query.append(_SQL_SELECT_SHOPPINGITEMFIELD_WHERE);
753
754 query.append(_FINDER_COLUMN_ITEMID_ITEMID_2);
755
756 if (orderByComparator != null) {
757 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
758
759 if (orderByConditionFields.length > 0) {
760 query.append(WHERE_AND);
761 }
762
763 for (int i = 0; i < orderByConditionFields.length; i++) {
764 query.append(_ORDER_BY_ENTITY_ALIAS);
765 query.append(orderByConditionFields[i]);
766
767 if ((i + 1) < orderByConditionFields.length) {
768 if (orderByComparator.isAscending() ^ previous) {
769 query.append(WHERE_GREATER_THAN_HAS_NEXT);
770 }
771 else {
772 query.append(WHERE_LESSER_THAN_HAS_NEXT);
773 }
774 }
775 else {
776 if (orderByComparator.isAscending() ^ previous) {
777 query.append(WHERE_GREATER_THAN);
778 }
779 else {
780 query.append(WHERE_LESSER_THAN);
781 }
782 }
783 }
784
785 query.append(ORDER_BY_CLAUSE);
786
787 String[] orderByFields = orderByComparator.getOrderByFields();
788
789 for (int i = 0; i < orderByFields.length; i++) {
790 query.append(_ORDER_BY_ENTITY_ALIAS);
791 query.append(orderByFields[i]);
792
793 if ((i + 1) < orderByFields.length) {
794 if (orderByComparator.isAscending() ^ previous) {
795 query.append(ORDER_BY_ASC_HAS_NEXT);
796 }
797 else {
798 query.append(ORDER_BY_DESC_HAS_NEXT);
799 }
800 }
801 else {
802 if (orderByComparator.isAscending() ^ previous) {
803 query.append(ORDER_BY_ASC);
804 }
805 else {
806 query.append(ORDER_BY_DESC);
807 }
808 }
809 }
810 }
811
812 else {
813 query.append(ShoppingItemFieldModelImpl.ORDER_BY_JPQL);
814 }
815
816 String sql = query.toString();
817
818 Query q = session.createQuery(sql);
819
820 q.setFirstResult(0);
821 q.setMaxResults(2);
822
823 QueryPos qPos = QueryPos.getInstance(q);
824
825 qPos.add(itemId);
826
827 if (orderByComparator != null) {
828 Object[] values = orderByComparator.getOrderByConditionValues(shoppingItemField);
829
830 for (Object value : values) {
831 qPos.add(value);
832 }
833 }
834
835 List<ShoppingItemField> list = q.list();
836
837 if (list.size() == 2) {
838 return list.get(1);
839 }
840 else {
841 return null;
842 }
843 }
844
845
851 public List<ShoppingItemField> findAll() throws SystemException {
852 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
853 }
854
855
867 public List<ShoppingItemField> findAll(int start, int end)
868 throws SystemException {
869 return findAll(start, end, null);
870 }
871
872
885 public List<ShoppingItemField> findAll(int start, int end,
886 OrderByComparator orderByComparator) throws SystemException {
887 FinderPath finderPath = null;
888 Object[] finderArgs = new Object[] { start, end, orderByComparator };
889
890 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
891 (orderByComparator == null)) {
892 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
893 finderArgs = FINDER_ARGS_EMPTY;
894 }
895 else {
896 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
897 finderArgs = new Object[] { start, end, orderByComparator };
898 }
899
900 List<ShoppingItemField> list = (List<ShoppingItemField>)FinderCacheUtil.getResult(finderPath,
901 finderArgs, this);
902
903 if (list == null) {
904 StringBundler query = null;
905 String sql = null;
906
907 if (orderByComparator != null) {
908 query = new StringBundler(2 +
909 (orderByComparator.getOrderByFields().length * 3));
910
911 query.append(_SQL_SELECT_SHOPPINGITEMFIELD);
912
913 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
914 orderByComparator);
915
916 sql = query.toString();
917 }
918 else {
919 sql = _SQL_SELECT_SHOPPINGITEMFIELD.concat(ShoppingItemFieldModelImpl.ORDER_BY_JPQL);
920 }
921
922 Session session = null;
923
924 try {
925 session = openSession();
926
927 Query q = session.createQuery(sql);
928
929 if (orderByComparator == null) {
930 list = (List<ShoppingItemField>)QueryUtil.list(q,
931 getDialect(), start, end, false);
932
933 Collections.sort(list);
934 }
935 else {
936 list = (List<ShoppingItemField>)QueryUtil.list(q,
937 getDialect(), start, end);
938 }
939 }
940 catch (Exception e) {
941 throw processException(e);
942 }
943 finally {
944 if (list == null) {
945 FinderCacheUtil.removeResult(finderPath, finderArgs);
946 }
947 else {
948 cacheResult(list);
949
950 FinderCacheUtil.putResult(finderPath, finderArgs, list);
951 }
952
953 closeSession(session);
954 }
955 }
956
957 return list;
958 }
959
960
966 public void removeByItemId(long itemId) throws SystemException {
967 for (ShoppingItemField shoppingItemField : findByItemId(itemId)) {
968 remove(shoppingItemField);
969 }
970 }
971
972
977 public void removeAll() throws SystemException {
978 for (ShoppingItemField shoppingItemField : findAll()) {
979 remove(shoppingItemField);
980 }
981 }
982
983
990 public int countByItemId(long itemId) throws SystemException {
991 Object[] finderArgs = new Object[] { itemId };
992
993 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_ITEMID,
994 finderArgs, this);
995
996 if (count == null) {
997 StringBundler query = new StringBundler(2);
998
999 query.append(_SQL_COUNT_SHOPPINGITEMFIELD_WHERE);
1000
1001 query.append(_FINDER_COLUMN_ITEMID_ITEMID_2);
1002
1003 String sql = query.toString();
1004
1005 Session session = null;
1006
1007 try {
1008 session = openSession();
1009
1010 Query q = session.createQuery(sql);
1011
1012 QueryPos qPos = QueryPos.getInstance(q);
1013
1014 qPos.add(itemId);
1015
1016 count = (Long)q.uniqueResult();
1017 }
1018 catch (Exception e) {
1019 throw processException(e);
1020 }
1021 finally {
1022 if (count == null) {
1023 count = Long.valueOf(0);
1024 }
1025
1026 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_ITEMID,
1027 finderArgs, count);
1028
1029 closeSession(session);
1030 }
1031 }
1032
1033 return count.intValue();
1034 }
1035
1036
1042 public int countAll() throws SystemException {
1043 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1044 FINDER_ARGS_EMPTY, this);
1045
1046 if (count == null) {
1047 Session session = null;
1048
1049 try {
1050 session = openSession();
1051
1052 Query q = session.createQuery(_SQL_COUNT_SHOPPINGITEMFIELD);
1053
1054 count = (Long)q.uniqueResult();
1055 }
1056 catch (Exception e) {
1057 throw processException(e);
1058 }
1059 finally {
1060 if (count == null) {
1061 count = Long.valueOf(0);
1062 }
1063
1064 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1065 FINDER_ARGS_EMPTY, count);
1066
1067 closeSession(session);
1068 }
1069 }
1070
1071 return count.intValue();
1072 }
1073
1074
1077 public void afterPropertiesSet() {
1078 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1079 com.liferay.portal.util.PropsUtil.get(
1080 "value.object.listener.com.liferay.portlet.shopping.model.ShoppingItemField")));
1081
1082 if (listenerClassNames.length > 0) {
1083 try {
1084 List<ModelListener<ShoppingItemField>> listenersList = new ArrayList<ModelListener<ShoppingItemField>>();
1085
1086 for (String listenerClassName : listenerClassNames) {
1087 Class<?> clazz = getClass();
1088
1089 listenersList.add((ModelListener<ShoppingItemField>)InstanceFactory.newInstance(
1090 clazz.getClassLoader(), listenerClassName));
1091 }
1092
1093 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1094 }
1095 catch (Exception e) {
1096 _log.error(e);
1097 }
1098 }
1099 }
1100
1101 public void destroy() {
1102 EntityCacheUtil.removeCache(ShoppingItemFieldImpl.class.getName());
1103 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1104 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1105 }
1106
1107 @BeanReference(type = ShoppingCartPersistence.class)
1108 protected ShoppingCartPersistence shoppingCartPersistence;
1109 @BeanReference(type = ShoppingCategoryPersistence.class)
1110 protected ShoppingCategoryPersistence shoppingCategoryPersistence;
1111 @BeanReference(type = ShoppingCouponPersistence.class)
1112 protected ShoppingCouponPersistence shoppingCouponPersistence;
1113 @BeanReference(type = ShoppingItemPersistence.class)
1114 protected ShoppingItemPersistence shoppingItemPersistence;
1115 @BeanReference(type = ShoppingItemFieldPersistence.class)
1116 protected ShoppingItemFieldPersistence shoppingItemFieldPersistence;
1117 @BeanReference(type = ShoppingItemPricePersistence.class)
1118 protected ShoppingItemPricePersistence shoppingItemPricePersistence;
1119 @BeanReference(type = ShoppingOrderPersistence.class)
1120 protected ShoppingOrderPersistence shoppingOrderPersistence;
1121 @BeanReference(type = ShoppingOrderItemPersistence.class)
1122 protected ShoppingOrderItemPersistence shoppingOrderItemPersistence;
1123 @BeanReference(type = ResourcePersistence.class)
1124 protected ResourcePersistence resourcePersistence;
1125 @BeanReference(type = UserPersistence.class)
1126 protected UserPersistence userPersistence;
1127 private static final String _SQL_SELECT_SHOPPINGITEMFIELD = "SELECT shoppingItemField FROM ShoppingItemField shoppingItemField";
1128 private static final String _SQL_SELECT_SHOPPINGITEMFIELD_WHERE = "SELECT shoppingItemField FROM ShoppingItemField shoppingItemField WHERE ";
1129 private static final String _SQL_COUNT_SHOPPINGITEMFIELD = "SELECT COUNT(shoppingItemField) FROM ShoppingItemField shoppingItemField";
1130 private static final String _SQL_COUNT_SHOPPINGITEMFIELD_WHERE = "SELECT COUNT(shoppingItemField) FROM ShoppingItemField shoppingItemField WHERE ";
1131 private static final String _FINDER_COLUMN_ITEMID_ITEMID_2 = "shoppingItemField.itemId = ?";
1132 private static final String _ORDER_BY_ENTITY_ALIAS = "shoppingItemField.";
1133 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ShoppingItemField exists with the primary key ";
1134 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ShoppingItemField exists with the key {";
1135 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1136 private static Log _log = LogFactoryUtil.getLog(ShoppingItemFieldPersistenceImpl.class);
1137 private static ShoppingItemField _nullShoppingItemField = new ShoppingItemFieldImpl() {
1138 @Override
1139 public Object clone() {
1140 return this;
1141 }
1142
1143 @Override
1144 public CacheModel<ShoppingItemField> toCacheModel() {
1145 return _nullShoppingItemFieldCacheModel;
1146 }
1147 };
1148
1149 private static CacheModel<ShoppingItemField> _nullShoppingItemFieldCacheModel =
1150 new CacheModel<ShoppingItemField>() {
1151 public ShoppingItemField toEntityModel() {
1152 return _nullShoppingItemField;
1153 }
1154 };
1155 }