1
22
23 package com.liferay.portlet.shopping.service.persistence;
24
25 import com.liferay.portal.SystemException;
26 import com.liferay.portal.kernel.annotation.BeanReference;
27 import com.liferay.portal.kernel.dao.orm.DynamicQuery;
28 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
29 import com.liferay.portal.kernel.dao.orm.Query;
30 import com.liferay.portal.kernel.dao.orm.QueryPos;
31 import com.liferay.portal.kernel.dao.orm.QueryUtil;
32 import com.liferay.portal.kernel.dao.orm.Session;
33 import com.liferay.portal.kernel.log.Log;
34 import com.liferay.portal.kernel.log.LogFactoryUtil;
35 import com.liferay.portal.kernel.util.GetterUtil;
36 import com.liferay.portal.kernel.util.OrderByComparator;
37 import com.liferay.portal.kernel.util.StringPool;
38 import com.liferay.portal.kernel.util.StringUtil;
39 import com.liferay.portal.model.ModelListener;
40 import com.liferay.portal.service.persistence.BatchSessionUtil;
41 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
42
43 import com.liferay.portlet.shopping.NoSuchItemFieldException;
44 import com.liferay.portlet.shopping.model.ShoppingItemField;
45 import com.liferay.portlet.shopping.model.impl.ShoppingItemFieldImpl;
46 import com.liferay.portlet.shopping.model.impl.ShoppingItemFieldModelImpl;
47
48 import java.util.ArrayList;
49 import java.util.Collections;
50 import java.util.Iterator;
51 import java.util.List;
52
53
59 public class ShoppingItemFieldPersistenceImpl extends BasePersistenceImpl
60 implements ShoppingItemFieldPersistence {
61 public ShoppingItemField create(long itemFieldId) {
62 ShoppingItemField shoppingItemField = new ShoppingItemFieldImpl();
63
64 shoppingItemField.setNew(true);
65 shoppingItemField.setPrimaryKey(itemFieldId);
66
67 return shoppingItemField;
68 }
69
70 public ShoppingItemField remove(long itemFieldId)
71 throws NoSuchItemFieldException, SystemException {
72 Session session = null;
73
74 try {
75 session = openSession();
76
77 ShoppingItemField shoppingItemField = (ShoppingItemField)session.get(ShoppingItemFieldImpl.class,
78 new Long(itemFieldId));
79
80 if (shoppingItemField == null) {
81 if (_log.isWarnEnabled()) {
82 _log.warn(
83 "No ShoppingItemField exists with the primary key " +
84 itemFieldId);
85 }
86
87 throw new NoSuchItemFieldException(
88 "No ShoppingItemField exists with the primary key " +
89 itemFieldId);
90 }
91
92 return remove(shoppingItemField);
93 }
94 catch (NoSuchItemFieldException nsee) {
95 throw nsee;
96 }
97 catch (Exception e) {
98 throw processException(e);
99 }
100 finally {
101 closeSession(session);
102 }
103 }
104
105 public ShoppingItemField remove(ShoppingItemField shoppingItemField)
106 throws SystemException {
107 for (ModelListener listener : listeners) {
108 listener.onBeforeRemove(shoppingItemField);
109 }
110
111 shoppingItemField = removeImpl(shoppingItemField);
112
113 for (ModelListener listener : listeners) {
114 listener.onAfterRemove(shoppingItemField);
115 }
116
117 return shoppingItemField;
118 }
119
120 protected ShoppingItemField removeImpl(ShoppingItemField shoppingItemField)
121 throws SystemException {
122 Session session = null;
123
124 try {
125 session = openSession();
126
127 if (BatchSessionUtil.isEnabled()) {
128 Object staleObject = session.get(ShoppingItemFieldImpl.class,
129 shoppingItemField.getPrimaryKeyObj());
130
131 if (staleObject != null) {
132 session.evict(staleObject);
133 }
134 }
135
136 session.delete(shoppingItemField);
137
138 session.flush();
139
140 return shoppingItemField;
141 }
142 catch (Exception e) {
143 throw processException(e);
144 }
145 finally {
146 closeSession(session);
147
148 FinderCacheUtil.clearCache(ShoppingItemField.class.getName());
149 }
150 }
151
152
155 public ShoppingItemField update(ShoppingItemField shoppingItemField)
156 throws SystemException {
157 if (_log.isWarnEnabled()) {
158 _log.warn(
159 "Using the deprecated update(ShoppingItemField shoppingItemField) method. Use update(ShoppingItemField shoppingItemField, boolean merge) instead.");
160 }
161
162 return update(shoppingItemField, false);
163 }
164
165
178 public ShoppingItemField update(ShoppingItemField shoppingItemField,
179 boolean merge) throws SystemException {
180 boolean isNew = shoppingItemField.isNew();
181
182 for (ModelListener listener : listeners) {
183 if (isNew) {
184 listener.onBeforeCreate(shoppingItemField);
185 }
186 else {
187 listener.onBeforeUpdate(shoppingItemField);
188 }
189 }
190
191 shoppingItemField = updateImpl(shoppingItemField, merge);
192
193 for (ModelListener listener : listeners) {
194 if (isNew) {
195 listener.onAfterCreate(shoppingItemField);
196 }
197 else {
198 listener.onAfterUpdate(shoppingItemField);
199 }
200 }
201
202 return shoppingItemField;
203 }
204
205 public ShoppingItemField updateImpl(
206 com.liferay.portlet.shopping.model.ShoppingItemField shoppingItemField,
207 boolean merge) throws SystemException {
208 Session session = null;
209
210 try {
211 session = openSession();
212
213 BatchSessionUtil.update(session, shoppingItemField, merge);
214
215 shoppingItemField.setNew(false);
216
217 return shoppingItemField;
218 }
219 catch (Exception e) {
220 throw processException(e);
221 }
222 finally {
223 closeSession(session);
224
225 FinderCacheUtil.clearCache(ShoppingItemField.class.getName());
226 }
227 }
228
229 public ShoppingItemField findByPrimaryKey(long itemFieldId)
230 throws NoSuchItemFieldException, SystemException {
231 ShoppingItemField shoppingItemField = fetchByPrimaryKey(itemFieldId);
232
233 if (shoppingItemField == null) {
234 if (_log.isWarnEnabled()) {
235 _log.warn("No ShoppingItemField exists with the primary key " +
236 itemFieldId);
237 }
238
239 throw new NoSuchItemFieldException(
240 "No ShoppingItemField exists with the primary key " +
241 itemFieldId);
242 }
243
244 return shoppingItemField;
245 }
246
247 public ShoppingItemField fetchByPrimaryKey(long itemFieldId)
248 throws SystemException {
249 Session session = null;
250
251 try {
252 session = openSession();
253
254 return (ShoppingItemField)session.get(ShoppingItemFieldImpl.class,
255 new Long(itemFieldId));
256 }
257 catch (Exception e) {
258 throw processException(e);
259 }
260 finally {
261 closeSession(session);
262 }
263 }
264
265 public List<ShoppingItemField> findByItemId(long itemId)
266 throws SystemException {
267 boolean finderClassNameCacheEnabled = ShoppingItemFieldModelImpl.CACHE_ENABLED;
268 String finderClassName = ShoppingItemField.class.getName();
269 String finderMethodName = "findByItemId";
270 String[] finderParams = new String[] { Long.class.getName() };
271 Object[] finderArgs = new Object[] { new Long(itemId) };
272
273 Object result = null;
274
275 if (finderClassNameCacheEnabled) {
276 result = FinderCacheUtil.getResult(finderClassName,
277 finderMethodName, finderParams, finderArgs, this);
278 }
279
280 if (result == null) {
281 Session session = null;
282
283 try {
284 session = openSession();
285
286 StringBuilder query = new StringBuilder();
287
288 query.append(
289 "FROM com.liferay.portlet.shopping.model.ShoppingItemField WHERE ");
290
291 query.append("itemId = ?");
292
293 query.append(" ");
294
295 query.append("ORDER BY ");
296
297 query.append("itemId ASC, ");
298 query.append("name ASC");
299
300 Query q = session.createQuery(query.toString());
301
302 QueryPos qPos = QueryPos.getInstance(q);
303
304 qPos.add(itemId);
305
306 List<ShoppingItemField> list = q.list();
307
308 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
309 finderClassName, finderMethodName, finderParams,
310 finderArgs, list);
311
312 return list;
313 }
314 catch (Exception e) {
315 throw processException(e);
316 }
317 finally {
318 closeSession(session);
319 }
320 }
321 else {
322 return (List<ShoppingItemField>)result;
323 }
324 }
325
326 public List<ShoppingItemField> findByItemId(long itemId, int start, int end)
327 throws SystemException {
328 return findByItemId(itemId, start, end, null);
329 }
330
331 public List<ShoppingItemField> findByItemId(long itemId, int start,
332 int end, OrderByComparator obc) throws SystemException {
333 boolean finderClassNameCacheEnabled = ShoppingItemFieldModelImpl.CACHE_ENABLED;
334 String finderClassName = ShoppingItemField.class.getName();
335 String finderMethodName = "findByItemId";
336 String[] finderParams = new String[] {
337 Long.class.getName(),
338
339 "java.lang.Integer", "java.lang.Integer",
340 "com.liferay.portal.kernel.util.OrderByComparator"
341 };
342 Object[] finderArgs = new Object[] {
343 new Long(itemId),
344
345 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
346 };
347
348 Object result = null;
349
350 if (finderClassNameCacheEnabled) {
351 result = FinderCacheUtil.getResult(finderClassName,
352 finderMethodName, finderParams, finderArgs, this);
353 }
354
355 if (result == null) {
356 Session session = null;
357
358 try {
359 session = openSession();
360
361 StringBuilder query = new StringBuilder();
362
363 query.append(
364 "FROM com.liferay.portlet.shopping.model.ShoppingItemField WHERE ");
365
366 query.append("itemId = ?");
367
368 query.append(" ");
369
370 if (obc != null) {
371 query.append("ORDER BY ");
372 query.append(obc.getOrderBy());
373 }
374
375 else {
376 query.append("ORDER BY ");
377
378 query.append("itemId ASC, ");
379 query.append("name ASC");
380 }
381
382 Query q = session.createQuery(query.toString());
383
384 QueryPos qPos = QueryPos.getInstance(q);
385
386 qPos.add(itemId);
387
388 List<ShoppingItemField> list = (List<ShoppingItemField>)QueryUtil.list(q,
389 getDialect(), start, end);
390
391 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
392 finderClassName, finderMethodName, finderParams,
393 finderArgs, list);
394
395 return list;
396 }
397 catch (Exception e) {
398 throw processException(e);
399 }
400 finally {
401 closeSession(session);
402 }
403 }
404 else {
405 return (List<ShoppingItemField>)result;
406 }
407 }
408
409 public ShoppingItemField findByItemId_First(long itemId,
410 OrderByComparator obc) throws NoSuchItemFieldException, SystemException {
411 List<ShoppingItemField> list = findByItemId(itemId, 0, 1, obc);
412
413 if (list.size() == 0) {
414 StringBuilder msg = new StringBuilder();
415
416 msg.append("No ShoppingItemField exists with the key {");
417
418 msg.append("itemId=" + itemId);
419
420 msg.append(StringPool.CLOSE_CURLY_BRACE);
421
422 throw new NoSuchItemFieldException(msg.toString());
423 }
424 else {
425 return list.get(0);
426 }
427 }
428
429 public ShoppingItemField findByItemId_Last(long itemId,
430 OrderByComparator obc) throws NoSuchItemFieldException, SystemException {
431 int count = countByItemId(itemId);
432
433 List<ShoppingItemField> list = findByItemId(itemId, count - 1, count,
434 obc);
435
436 if (list.size() == 0) {
437 StringBuilder msg = new StringBuilder();
438
439 msg.append("No ShoppingItemField exists with the key {");
440
441 msg.append("itemId=" + itemId);
442
443 msg.append(StringPool.CLOSE_CURLY_BRACE);
444
445 throw new NoSuchItemFieldException(msg.toString());
446 }
447 else {
448 return list.get(0);
449 }
450 }
451
452 public ShoppingItemField[] findByItemId_PrevAndNext(long itemFieldId,
453 long itemId, OrderByComparator obc)
454 throws NoSuchItemFieldException, SystemException {
455 ShoppingItemField shoppingItemField = findByPrimaryKey(itemFieldId);
456
457 int count = countByItemId(itemId);
458
459 Session session = null;
460
461 try {
462 session = openSession();
463
464 StringBuilder query = new StringBuilder();
465
466 query.append(
467 "FROM com.liferay.portlet.shopping.model.ShoppingItemField WHERE ");
468
469 query.append("itemId = ?");
470
471 query.append(" ");
472
473 if (obc != null) {
474 query.append("ORDER BY ");
475 query.append(obc.getOrderBy());
476 }
477
478 else {
479 query.append("ORDER BY ");
480
481 query.append("itemId ASC, ");
482 query.append("name ASC");
483 }
484
485 Query q = session.createQuery(query.toString());
486
487 QueryPos qPos = QueryPos.getInstance(q);
488
489 qPos.add(itemId);
490
491 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
492 shoppingItemField);
493
494 ShoppingItemField[] array = new ShoppingItemFieldImpl[3];
495
496 array[0] = (ShoppingItemField)objArray[0];
497 array[1] = (ShoppingItemField)objArray[1];
498 array[2] = (ShoppingItemField)objArray[2];
499
500 return array;
501 }
502 catch (Exception e) {
503 throw processException(e);
504 }
505 finally {
506 closeSession(session);
507 }
508 }
509
510 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
511 throws SystemException {
512 Session session = null;
513
514 try {
515 session = openSession();
516
517 dynamicQuery.compile(session);
518
519 return dynamicQuery.list();
520 }
521 catch (Exception e) {
522 throw processException(e);
523 }
524 finally {
525 closeSession(session);
526 }
527 }
528
529 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
530 int start, int end) throws SystemException {
531 Session session = null;
532
533 try {
534 session = openSession();
535
536 dynamicQuery.setLimit(start, end);
537
538 dynamicQuery.compile(session);
539
540 return dynamicQuery.list();
541 }
542 catch (Exception e) {
543 throw processException(e);
544 }
545 finally {
546 closeSession(session);
547 }
548 }
549
550 public List<ShoppingItemField> findAll() throws SystemException {
551 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
552 }
553
554 public List<ShoppingItemField> findAll(int start, int end)
555 throws SystemException {
556 return findAll(start, end, null);
557 }
558
559 public List<ShoppingItemField> findAll(int start, int end,
560 OrderByComparator obc) throws SystemException {
561 boolean finderClassNameCacheEnabled = ShoppingItemFieldModelImpl.CACHE_ENABLED;
562 String finderClassName = ShoppingItemField.class.getName();
563 String finderMethodName = "findAll";
564 String[] finderParams = new String[] {
565 "java.lang.Integer", "java.lang.Integer",
566 "com.liferay.portal.kernel.util.OrderByComparator"
567 };
568 Object[] finderArgs = new Object[] {
569 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
570 };
571
572 Object result = null;
573
574 if (finderClassNameCacheEnabled) {
575 result = FinderCacheUtil.getResult(finderClassName,
576 finderMethodName, finderParams, finderArgs, this);
577 }
578
579 if (result == null) {
580 Session session = null;
581
582 try {
583 session = openSession();
584
585 StringBuilder query = new StringBuilder();
586
587 query.append(
588 "FROM com.liferay.portlet.shopping.model.ShoppingItemField ");
589
590 if (obc != null) {
591 query.append("ORDER BY ");
592 query.append(obc.getOrderBy());
593 }
594
595 else {
596 query.append("ORDER BY ");
597
598 query.append("itemId ASC, ");
599 query.append("name ASC");
600 }
601
602 Query q = session.createQuery(query.toString());
603
604 List<ShoppingItemField> list = null;
605
606 if (obc == null) {
607 list = (List<ShoppingItemField>)QueryUtil.list(q,
608 getDialect(), start, end, false);
609
610 Collections.sort(list);
611 }
612 else {
613 list = (List<ShoppingItemField>)QueryUtil.list(q,
614 getDialect(), start, end);
615 }
616
617 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
618 finderClassName, finderMethodName, finderParams,
619 finderArgs, list);
620
621 return list;
622 }
623 catch (Exception e) {
624 throw processException(e);
625 }
626 finally {
627 closeSession(session);
628 }
629 }
630 else {
631 return (List<ShoppingItemField>)result;
632 }
633 }
634
635 public void removeByItemId(long itemId) throws SystemException {
636 for (ShoppingItemField shoppingItemField : findByItemId(itemId)) {
637 remove(shoppingItemField);
638 }
639 }
640
641 public void removeAll() throws SystemException {
642 for (ShoppingItemField shoppingItemField : findAll()) {
643 remove(shoppingItemField);
644 }
645 }
646
647 public int countByItemId(long itemId) throws SystemException {
648 boolean finderClassNameCacheEnabled = ShoppingItemFieldModelImpl.CACHE_ENABLED;
649 String finderClassName = ShoppingItemField.class.getName();
650 String finderMethodName = "countByItemId";
651 String[] finderParams = new String[] { Long.class.getName() };
652 Object[] finderArgs = new Object[] { new Long(itemId) };
653
654 Object result = null;
655
656 if (finderClassNameCacheEnabled) {
657 result = FinderCacheUtil.getResult(finderClassName,
658 finderMethodName, finderParams, finderArgs, this);
659 }
660
661 if (result == null) {
662 Session session = null;
663
664 try {
665 session = openSession();
666
667 StringBuilder query = new StringBuilder();
668
669 query.append("SELECT COUNT(*) ");
670 query.append(
671 "FROM com.liferay.portlet.shopping.model.ShoppingItemField WHERE ");
672
673 query.append("itemId = ?");
674
675 query.append(" ");
676
677 Query q = session.createQuery(query.toString());
678
679 QueryPos qPos = QueryPos.getInstance(q);
680
681 qPos.add(itemId);
682
683 Long count = null;
684
685 Iterator<Long> itr = q.list().iterator();
686
687 if (itr.hasNext()) {
688 count = itr.next();
689 }
690
691 if (count == null) {
692 count = new Long(0);
693 }
694
695 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
696 finderClassName, finderMethodName, finderParams,
697 finderArgs, count);
698
699 return count.intValue();
700 }
701 catch (Exception e) {
702 throw processException(e);
703 }
704 finally {
705 closeSession(session);
706 }
707 }
708 else {
709 return ((Long)result).intValue();
710 }
711 }
712
713 public int countAll() throws SystemException {
714 boolean finderClassNameCacheEnabled = ShoppingItemFieldModelImpl.CACHE_ENABLED;
715 String finderClassName = ShoppingItemField.class.getName();
716 String finderMethodName = "countAll";
717 String[] finderParams = new String[] { };
718 Object[] finderArgs = new Object[] { };
719
720 Object result = null;
721
722 if (finderClassNameCacheEnabled) {
723 result = FinderCacheUtil.getResult(finderClassName,
724 finderMethodName, finderParams, finderArgs, this);
725 }
726
727 if (result == null) {
728 Session session = null;
729
730 try {
731 session = openSession();
732
733 Query q = session.createQuery(
734 "SELECT COUNT(*) FROM com.liferay.portlet.shopping.model.ShoppingItemField");
735
736 Long count = null;
737
738 Iterator<Long> itr = q.list().iterator();
739
740 if (itr.hasNext()) {
741 count = itr.next();
742 }
743
744 if (count == null) {
745 count = new Long(0);
746 }
747
748 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
749 finderClassName, finderMethodName, finderParams,
750 finderArgs, count);
751
752 return count.intValue();
753 }
754 catch (Exception e) {
755 throw processException(e);
756 }
757 finally {
758 closeSession(session);
759 }
760 }
761 else {
762 return ((Long)result).intValue();
763 }
764 }
765
766 public void afterPropertiesSet() {
767 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
768 com.liferay.portal.util.PropsUtil.get(
769 "value.object.listener.com.liferay.portlet.shopping.model.ShoppingItemField")));
770
771 if (listenerClassNames.length > 0) {
772 try {
773 List<ModelListener> listenersList = new ArrayList<ModelListener>();
774
775 for (String listenerClassName : listenerClassNames) {
776 listenersList.add((ModelListener)Class.forName(
777 listenerClassName).newInstance());
778 }
779
780 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
781 }
782 catch (Exception e) {
783 _log.error(e);
784 }
785 }
786 }
787
788 @BeanReference(name = "com.liferay.portlet.shopping.service.persistence.ShoppingCartPersistence.impl")
789 protected com.liferay.portlet.shopping.service.persistence.ShoppingCartPersistence shoppingCartPersistence;
790 @BeanReference(name = "com.liferay.portlet.shopping.service.persistence.ShoppingCategoryPersistence.impl")
791 protected com.liferay.portlet.shopping.service.persistence.ShoppingCategoryPersistence shoppingCategoryPersistence;
792 @BeanReference(name = "com.liferay.portlet.shopping.service.persistence.ShoppingCouponPersistence.impl")
793 protected com.liferay.portlet.shopping.service.persistence.ShoppingCouponPersistence shoppingCouponPersistence;
794 @BeanReference(name = "com.liferay.portlet.shopping.service.persistence.ShoppingItemPersistence.impl")
795 protected com.liferay.portlet.shopping.service.persistence.ShoppingItemPersistence shoppingItemPersistence;
796 @BeanReference(name = "com.liferay.portlet.shopping.service.persistence.ShoppingItemFieldPersistence.impl")
797 protected com.liferay.portlet.shopping.service.persistence.ShoppingItemFieldPersistence shoppingItemFieldPersistence;
798 @BeanReference(name = "com.liferay.portlet.shopping.service.persistence.ShoppingItemPricePersistence.impl")
799 protected com.liferay.portlet.shopping.service.persistence.ShoppingItemPricePersistence shoppingItemPricePersistence;
800 @BeanReference(name = "com.liferay.portlet.shopping.service.persistence.ShoppingOrderPersistence.impl")
801 protected com.liferay.portlet.shopping.service.persistence.ShoppingOrderPersistence shoppingOrderPersistence;
802 @BeanReference(name = "com.liferay.portlet.shopping.service.persistence.ShoppingOrderItemPersistence.impl")
803 protected com.liferay.portlet.shopping.service.persistence.ShoppingOrderItemPersistence shoppingOrderItemPersistence;
804 private static Log _log = LogFactoryUtil.getLog(ShoppingItemFieldPersistenceImpl.class);
805 }