1
22
23 package com.liferay.portlet.shopping.service.persistence;
24
25 import com.liferay.portal.SystemException;
26 import com.liferay.portal.kernel.dao.DynamicQuery;
27 import com.liferay.portal.kernel.dao.DynamicQueryInitializer;
28 import com.liferay.portal.kernel.util.OrderByComparator;
29 import com.liferay.portal.kernel.util.StringMaker;
30 import com.liferay.portal.kernel.util.StringPool;
31 import com.liferay.portal.service.persistence.BasePersistence;
32 import com.liferay.portal.spring.hibernate.FinderCache;
33 import com.liferay.portal.spring.hibernate.HibernateUtil;
34
35 import com.liferay.portlet.shopping.NoSuchItemPriceException;
36 import com.liferay.portlet.shopping.model.ShoppingItemPrice;
37 import com.liferay.portlet.shopping.model.impl.ShoppingItemPriceImpl;
38
39 import com.liferay.util.dao.hibernate.QueryUtil;
40
41 import org.apache.commons.logging.Log;
42 import org.apache.commons.logging.LogFactory;
43
44 import org.hibernate.Query;
45 import org.hibernate.Session;
46
47 import java.util.Collections;
48 import java.util.Iterator;
49 import java.util.List;
50
51
57 public class ShoppingItemPricePersistenceImpl extends BasePersistence
58 implements ShoppingItemPricePersistence {
59 public ShoppingItemPrice create(long itemPriceId) {
60 ShoppingItemPrice shoppingItemPrice = new ShoppingItemPriceImpl();
61 shoppingItemPrice.setNew(true);
62 shoppingItemPrice.setPrimaryKey(itemPriceId);
63
64 return shoppingItemPrice;
65 }
66
67 public ShoppingItemPrice remove(long itemPriceId)
68 throws NoSuchItemPriceException, SystemException {
69 Session session = null;
70
71 try {
72 session = openSession();
73
74 ShoppingItemPrice shoppingItemPrice = (ShoppingItemPrice)session.get(ShoppingItemPriceImpl.class,
75 new Long(itemPriceId));
76
77 if (shoppingItemPrice == null) {
78 if (_log.isWarnEnabled()) {
79 _log.warn(
80 "No ShoppingItemPrice exists with the primary key " +
81 itemPriceId);
82 }
83
84 throw new NoSuchItemPriceException(
85 "No ShoppingItemPrice exists with the primary key " +
86 itemPriceId);
87 }
88
89 return remove(shoppingItemPrice);
90 }
91 catch (NoSuchItemPriceException nsee) {
92 throw nsee;
93 }
94 catch (Exception e) {
95 throw HibernateUtil.processException(e);
96 }
97 finally {
98 closeSession(session);
99 }
100 }
101
102 public ShoppingItemPrice remove(ShoppingItemPrice shoppingItemPrice)
103 throws SystemException {
104 Session session = null;
105
106 try {
107 session = openSession();
108 session.delete(shoppingItemPrice);
109 session.flush();
110
111 return shoppingItemPrice;
112 }
113 catch (Exception e) {
114 throw HibernateUtil.processException(e);
115 }
116 finally {
117 closeSession(session);
118 FinderCache.clearCache(ShoppingItemPrice.class.getName());
119 }
120 }
121
122 public ShoppingItemPrice update(
123 com.liferay.portlet.shopping.model.ShoppingItemPrice shoppingItemPrice)
124 throws SystemException {
125 return update(shoppingItemPrice, false);
126 }
127
128 public ShoppingItemPrice update(
129 com.liferay.portlet.shopping.model.ShoppingItemPrice shoppingItemPrice,
130 boolean merge) throws SystemException {
131 Session session = null;
132
133 try {
134 session = openSession();
135
136 if (merge) {
137 session.merge(shoppingItemPrice);
138 }
139 else {
140 if (shoppingItemPrice.isNew()) {
141 session.save(shoppingItemPrice);
142 }
143 }
144
145 session.flush();
146 shoppingItemPrice.setNew(false);
147
148 return shoppingItemPrice;
149 }
150 catch (Exception e) {
151 throw HibernateUtil.processException(e);
152 }
153 finally {
154 closeSession(session);
155 FinderCache.clearCache(ShoppingItemPrice.class.getName());
156 }
157 }
158
159 public ShoppingItemPrice findByPrimaryKey(long itemPriceId)
160 throws NoSuchItemPriceException, SystemException {
161 ShoppingItemPrice shoppingItemPrice = fetchByPrimaryKey(itemPriceId);
162
163 if (shoppingItemPrice == null) {
164 if (_log.isWarnEnabled()) {
165 _log.warn("No ShoppingItemPrice exists with the primary key " +
166 itemPriceId);
167 }
168
169 throw new NoSuchItemPriceException(
170 "No ShoppingItemPrice exists with the primary key " +
171 itemPriceId);
172 }
173
174 return shoppingItemPrice;
175 }
176
177 public ShoppingItemPrice fetchByPrimaryKey(long itemPriceId)
178 throws SystemException {
179 Session session = null;
180
181 try {
182 session = openSession();
183
184 return (ShoppingItemPrice)session.get(ShoppingItemPriceImpl.class,
185 new Long(itemPriceId));
186 }
187 catch (Exception e) {
188 throw HibernateUtil.processException(e);
189 }
190 finally {
191 closeSession(session);
192 }
193 }
194
195 public List findByItemId(long itemId) throws SystemException {
196 String finderClassName = ShoppingItemPrice.class.getName();
197 String finderMethodName = "findByItemId";
198 String[] finderParams = new String[] { Long.class.getName() };
199 Object[] finderArgs = new Object[] { new Long(itemId) };
200 Object result = FinderCache.getResult(finderClassName,
201 finderMethodName, finderParams, finderArgs, getSessionFactory());
202
203 if (result == null) {
204 Session session = null;
205
206 try {
207 session = openSession();
208
209 StringMaker query = new StringMaker();
210 query.append(
211 "FROM com.liferay.portlet.shopping.model.ShoppingItemPrice WHERE ");
212 query.append("itemId = ?");
213 query.append(" ");
214 query.append("ORDER BY ");
215 query.append("itemId ASC").append(", ");
216 query.append("itemPriceId ASC");
217
218 Query q = session.createQuery(query.toString());
219 int queryPos = 0;
220 q.setLong(queryPos++, itemId);
221
222 List list = q.list();
223 FinderCache.putResult(finderClassName, finderMethodName,
224 finderParams, finderArgs, list);
225
226 return list;
227 }
228 catch (Exception e) {
229 throw HibernateUtil.processException(e);
230 }
231 finally {
232 closeSession(session);
233 }
234 }
235 else {
236 return (List)result;
237 }
238 }
239
240 public List findByItemId(long itemId, int begin, int end)
241 throws SystemException {
242 return findByItemId(itemId, begin, end, null);
243 }
244
245 public List findByItemId(long itemId, int begin, int end,
246 OrderByComparator obc) throws SystemException {
247 String finderClassName = ShoppingItemPrice.class.getName();
248 String finderMethodName = "findByItemId";
249 String[] finderParams = new String[] {
250 Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
251 "com.liferay.portal.kernel.util.OrderByComparator"
252 };
253 Object[] finderArgs = new Object[] {
254 new Long(itemId), String.valueOf(begin), String.valueOf(end),
255 String.valueOf(obc)
256 };
257 Object result = FinderCache.getResult(finderClassName,
258 finderMethodName, finderParams, finderArgs, getSessionFactory());
259
260 if (result == null) {
261 Session session = null;
262
263 try {
264 session = openSession();
265
266 StringMaker query = new StringMaker();
267 query.append(
268 "FROM com.liferay.portlet.shopping.model.ShoppingItemPrice WHERE ");
269 query.append("itemId = ?");
270 query.append(" ");
271
272 if (obc != null) {
273 query.append("ORDER BY ");
274 query.append(obc.getOrderBy());
275 }
276 else {
277 query.append("ORDER BY ");
278 query.append("itemId ASC").append(", ");
279 query.append("itemPriceId ASC");
280 }
281
282 Query q = session.createQuery(query.toString());
283 int queryPos = 0;
284 q.setLong(queryPos++, itemId);
285
286 List list = QueryUtil.list(q, getDialect(), begin, end);
287 FinderCache.putResult(finderClassName, finderMethodName,
288 finderParams, finderArgs, list);
289
290 return list;
291 }
292 catch (Exception e) {
293 throw HibernateUtil.processException(e);
294 }
295 finally {
296 closeSession(session);
297 }
298 }
299 else {
300 return (List)result;
301 }
302 }
303
304 public ShoppingItemPrice findByItemId_First(long itemId,
305 OrderByComparator obc) throws NoSuchItemPriceException, SystemException {
306 List list = findByItemId(itemId, 0, 1, obc);
307
308 if (list.size() == 0) {
309 StringMaker msg = new StringMaker();
310 msg.append("No ShoppingItemPrice exists with the key ");
311 msg.append(StringPool.OPEN_CURLY_BRACE);
312 msg.append("itemId=");
313 msg.append(itemId);
314 msg.append(StringPool.CLOSE_CURLY_BRACE);
315 throw new NoSuchItemPriceException(msg.toString());
316 }
317 else {
318 return (ShoppingItemPrice)list.get(0);
319 }
320 }
321
322 public ShoppingItemPrice findByItemId_Last(long itemId,
323 OrderByComparator obc) throws NoSuchItemPriceException, SystemException {
324 int count = countByItemId(itemId);
325 List list = findByItemId(itemId, count - 1, count, obc);
326
327 if (list.size() == 0) {
328 StringMaker msg = new StringMaker();
329 msg.append("No ShoppingItemPrice exists with the key ");
330 msg.append(StringPool.OPEN_CURLY_BRACE);
331 msg.append("itemId=");
332 msg.append(itemId);
333 msg.append(StringPool.CLOSE_CURLY_BRACE);
334 throw new NoSuchItemPriceException(msg.toString());
335 }
336 else {
337 return (ShoppingItemPrice)list.get(0);
338 }
339 }
340
341 public ShoppingItemPrice[] findByItemId_PrevAndNext(long itemPriceId,
342 long itemId, OrderByComparator obc)
343 throws NoSuchItemPriceException, SystemException {
344 ShoppingItemPrice shoppingItemPrice = findByPrimaryKey(itemPriceId);
345 int count = countByItemId(itemId);
346 Session session = null;
347
348 try {
349 session = openSession();
350
351 StringMaker query = new StringMaker();
352 query.append(
353 "FROM com.liferay.portlet.shopping.model.ShoppingItemPrice WHERE ");
354 query.append("itemId = ?");
355 query.append(" ");
356
357 if (obc != null) {
358 query.append("ORDER BY ");
359 query.append(obc.getOrderBy());
360 }
361 else {
362 query.append("ORDER BY ");
363 query.append("itemId ASC").append(", ");
364 query.append("itemPriceId ASC");
365 }
366
367 Query q = session.createQuery(query.toString());
368 int queryPos = 0;
369 q.setLong(queryPos++, itemId);
370
371 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
372 shoppingItemPrice);
373 ShoppingItemPrice[] array = new ShoppingItemPriceImpl[3];
374 array[0] = (ShoppingItemPrice)objArray[0];
375 array[1] = (ShoppingItemPrice)objArray[1];
376 array[2] = (ShoppingItemPrice)objArray[2];
377
378 return array;
379 }
380 catch (Exception e) {
381 throw HibernateUtil.processException(e);
382 }
383 finally {
384 closeSession(session);
385 }
386 }
387
388 public List findWithDynamicQuery(DynamicQueryInitializer queryInitializer)
389 throws SystemException {
390 Session session = null;
391
392 try {
393 session = openSession();
394
395 DynamicQuery query = queryInitializer.initialize(session);
396
397 return query.list();
398 }
399 catch (Exception e) {
400 throw HibernateUtil.processException(e);
401 }
402 finally {
403 closeSession(session);
404 }
405 }
406
407 public List findWithDynamicQuery(DynamicQueryInitializer queryInitializer,
408 int begin, int end) throws SystemException {
409 Session session = null;
410
411 try {
412 session = openSession();
413
414 DynamicQuery query = queryInitializer.initialize(session);
415 query.setLimit(begin, end);
416
417 return query.list();
418 }
419 catch (Exception e) {
420 throw HibernateUtil.processException(e);
421 }
422 finally {
423 closeSession(session);
424 }
425 }
426
427 public List findAll() throws SystemException {
428 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
429 }
430
431 public List findAll(int begin, int end) throws SystemException {
432 return findAll(begin, end, null);
433 }
434
435 public List findAll(int begin, int end, OrderByComparator obc)
436 throws SystemException {
437 String finderClassName = ShoppingItemPrice.class.getName();
438 String finderMethodName = "findAll";
439 String[] finderParams = new String[] {
440 "java.lang.Integer", "java.lang.Integer",
441 "com.liferay.portal.kernel.util.OrderByComparator"
442 };
443 Object[] finderArgs = new Object[] {
444 String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
445 };
446 Object result = FinderCache.getResult(finderClassName,
447 finderMethodName, finderParams, finderArgs, getSessionFactory());
448
449 if (result == null) {
450 Session session = null;
451
452 try {
453 session = openSession();
454
455 StringMaker query = new StringMaker();
456 query.append(
457 "FROM com.liferay.portlet.shopping.model.ShoppingItemPrice ");
458
459 if (obc != null) {
460 query.append("ORDER BY ");
461 query.append(obc.getOrderBy());
462 }
463 else {
464 query.append("ORDER BY ");
465 query.append("itemId ASC").append(", ");
466 query.append("itemPriceId ASC");
467 }
468
469 Query q = session.createQuery(query.toString());
470 List list = QueryUtil.list(q, getDialect(), begin, end);
471
472 if (obc == null) {
473 Collections.sort(list);
474 }
475
476 FinderCache.putResult(finderClassName, finderMethodName,
477 finderParams, finderArgs, list);
478
479 return list;
480 }
481 catch (Exception e) {
482 throw HibernateUtil.processException(e);
483 }
484 finally {
485 closeSession(session);
486 }
487 }
488 else {
489 return (List)result;
490 }
491 }
492
493 public void removeByItemId(long itemId) throws SystemException {
494 Iterator itr = findByItemId(itemId).iterator();
495
496 while (itr.hasNext()) {
497 ShoppingItemPrice shoppingItemPrice = (ShoppingItemPrice)itr.next();
498 remove(shoppingItemPrice);
499 }
500 }
501
502 public void removeAll() throws SystemException {
503 Iterator itr = findAll().iterator();
504
505 while (itr.hasNext()) {
506 remove((ShoppingItemPrice)itr.next());
507 }
508 }
509
510 public int countByItemId(long itemId) throws SystemException {
511 String finderClassName = ShoppingItemPrice.class.getName();
512 String finderMethodName = "countByItemId";
513 String[] finderParams = new String[] { Long.class.getName() };
514 Object[] finderArgs = new Object[] { new Long(itemId) };
515 Object result = FinderCache.getResult(finderClassName,
516 finderMethodName, finderParams, finderArgs, getSessionFactory());
517
518 if (result == null) {
519 Session session = null;
520
521 try {
522 session = openSession();
523
524 StringMaker query = new StringMaker();
525 query.append("SELECT COUNT(*) ");
526 query.append(
527 "FROM com.liferay.portlet.shopping.model.ShoppingItemPrice WHERE ");
528 query.append("itemId = ?");
529 query.append(" ");
530
531 Query q = session.createQuery(query.toString());
532 int queryPos = 0;
533 q.setLong(queryPos++, itemId);
534
535 Long count = null;
536 Iterator itr = q.list().iterator();
537
538 if (itr.hasNext()) {
539 count = (Long)itr.next();
540 }
541
542 if (count == null) {
543 count = new Long(0);
544 }
545
546 FinderCache.putResult(finderClassName, finderMethodName,
547 finderParams, finderArgs, count);
548
549 return count.intValue();
550 }
551 catch (Exception e) {
552 throw HibernateUtil.processException(e);
553 }
554 finally {
555 closeSession(session);
556 }
557 }
558 else {
559 return ((Long)result).intValue();
560 }
561 }
562
563 public int countAll() throws SystemException {
564 String finderClassName = ShoppingItemPrice.class.getName();
565 String finderMethodName = "countAll";
566 String[] finderParams = new String[] { };
567 Object[] finderArgs = new Object[] { };
568 Object result = FinderCache.getResult(finderClassName,
569 finderMethodName, finderParams, finderArgs, getSessionFactory());
570
571 if (result == null) {
572 Session session = null;
573
574 try {
575 session = openSession();
576
577 StringMaker query = new StringMaker();
578 query.append("SELECT COUNT(*) ");
579 query.append(
580 "FROM com.liferay.portlet.shopping.model.ShoppingItemPrice");
581
582 Query q = session.createQuery(query.toString());
583 Long count = null;
584 Iterator itr = q.list().iterator();
585
586 if (itr.hasNext()) {
587 count = (Long)itr.next();
588 }
589
590 if (count == null) {
591 count = new Long(0);
592 }
593
594 FinderCache.putResult(finderClassName, finderMethodName,
595 finderParams, finderArgs, count);
596
597 return count.intValue();
598 }
599 catch (Exception e) {
600 throw HibernateUtil.processException(e);
601 }
602 finally {
603 closeSession(session);
604 }
605 }
606 else {
607 return ((Long)result).intValue();
608 }
609 }
610
611 protected void initDao() {
612 }
613
614 private static Log _log = LogFactory.getLog(ShoppingItemPricePersistenceImpl.class);
615 }