1
22
23 package com.liferay.portlet.softwarecatalog.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.softwarecatalog.NoSuchProductScreenshotException;
36 import com.liferay.portlet.softwarecatalog.model.SCProductScreenshot;
37 import com.liferay.portlet.softwarecatalog.model.impl.SCProductScreenshotImpl;
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 SCProductScreenshotPersistenceImpl extends BasePersistence
58 implements SCProductScreenshotPersistence {
59 public SCProductScreenshot create(long productScreenshotId) {
60 SCProductScreenshot scProductScreenshot = new SCProductScreenshotImpl();
61 scProductScreenshot.setNew(true);
62 scProductScreenshot.setPrimaryKey(productScreenshotId);
63
64 return scProductScreenshot;
65 }
66
67 public SCProductScreenshot remove(long productScreenshotId)
68 throws NoSuchProductScreenshotException, SystemException {
69 Session session = null;
70
71 try {
72 session = openSession();
73
74 SCProductScreenshot scProductScreenshot = (SCProductScreenshot)session.get(SCProductScreenshotImpl.class,
75 new Long(productScreenshotId));
76
77 if (scProductScreenshot == null) {
78 if (_log.isWarnEnabled()) {
79 _log.warn(
80 "No SCProductScreenshot exists with the primary key " +
81 productScreenshotId);
82 }
83
84 throw new NoSuchProductScreenshotException(
85 "No SCProductScreenshot exists with the primary key " +
86 productScreenshotId);
87 }
88
89 return remove(scProductScreenshot);
90 }
91 catch (NoSuchProductScreenshotException 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 SCProductScreenshot remove(SCProductScreenshot scProductScreenshot)
103 throws SystemException {
104 Session session = null;
105
106 try {
107 session = openSession();
108 session.delete(scProductScreenshot);
109 session.flush();
110
111 return scProductScreenshot;
112 }
113 catch (Exception e) {
114 throw HibernateUtil.processException(e);
115 }
116 finally {
117 closeSession(session);
118 FinderCache.clearCache(SCProductScreenshot.class.getName());
119 }
120 }
121
122 public SCProductScreenshot update(
123 com.liferay.portlet.softwarecatalog.model.SCProductScreenshot scProductScreenshot)
124 throws SystemException {
125 return update(scProductScreenshot, false);
126 }
127
128 public SCProductScreenshot update(
129 com.liferay.portlet.softwarecatalog.model.SCProductScreenshot scProductScreenshot,
130 boolean merge) throws SystemException {
131 Session session = null;
132
133 try {
134 session = openSession();
135
136 if (merge) {
137 session.merge(scProductScreenshot);
138 }
139 else {
140 if (scProductScreenshot.isNew()) {
141 session.save(scProductScreenshot);
142 }
143 }
144
145 session.flush();
146 scProductScreenshot.setNew(false);
147
148 return scProductScreenshot;
149 }
150 catch (Exception e) {
151 throw HibernateUtil.processException(e);
152 }
153 finally {
154 closeSession(session);
155 FinderCache.clearCache(SCProductScreenshot.class.getName());
156 }
157 }
158
159 public SCProductScreenshot findByPrimaryKey(long productScreenshotId)
160 throws NoSuchProductScreenshotException, SystemException {
161 SCProductScreenshot scProductScreenshot = fetchByPrimaryKey(productScreenshotId);
162
163 if (scProductScreenshot == null) {
164 if (_log.isWarnEnabled()) {
165 _log.warn("No SCProductScreenshot exists with the primary key " +
166 productScreenshotId);
167 }
168
169 throw new NoSuchProductScreenshotException(
170 "No SCProductScreenshot exists with the primary key " +
171 productScreenshotId);
172 }
173
174 return scProductScreenshot;
175 }
176
177 public SCProductScreenshot fetchByPrimaryKey(long productScreenshotId)
178 throws SystemException {
179 Session session = null;
180
181 try {
182 session = openSession();
183
184 return (SCProductScreenshot)session.get(SCProductScreenshotImpl.class,
185 new Long(productScreenshotId));
186 }
187 catch (Exception e) {
188 throw HibernateUtil.processException(e);
189 }
190 finally {
191 closeSession(session);
192 }
193 }
194
195 public List findByProductEntryId(long productEntryId)
196 throws SystemException {
197 String finderClassName = SCProductScreenshot.class.getName();
198 String finderMethodName = "findByProductEntryId";
199 String[] finderParams = new String[] { Long.class.getName() };
200 Object[] finderArgs = new Object[] { new Long(productEntryId) };
201 Object result = FinderCache.getResult(finderClassName,
202 finderMethodName, finderParams, finderArgs, getSessionFactory());
203
204 if (result == null) {
205 Session session = null;
206
207 try {
208 session = openSession();
209
210 StringMaker query = new StringMaker();
211 query.append(
212 "FROM com.liferay.portlet.softwarecatalog.model.SCProductScreenshot WHERE ");
213 query.append("productEntryId = ?");
214 query.append(" ");
215 query.append("ORDER BY ");
216 query.append("productEntryId ASC").append(", ");
217 query.append("priority ASC");
218
219 Query q = session.createQuery(query.toString());
220 int queryPos = 0;
221 q.setLong(queryPos++, productEntryId);
222
223 List list = q.list();
224 FinderCache.putResult(finderClassName, finderMethodName,
225 finderParams, finderArgs, list);
226
227 return list;
228 }
229 catch (Exception e) {
230 throw HibernateUtil.processException(e);
231 }
232 finally {
233 closeSession(session);
234 }
235 }
236 else {
237 return (List)result;
238 }
239 }
240
241 public List findByProductEntryId(long productEntryId, int begin, int end)
242 throws SystemException {
243 return findByProductEntryId(productEntryId, begin, end, null);
244 }
245
246 public List findByProductEntryId(long productEntryId, int begin, int end,
247 OrderByComparator obc) throws SystemException {
248 String finderClassName = SCProductScreenshot.class.getName();
249 String finderMethodName = "findByProductEntryId";
250 String[] finderParams = new String[] {
251 Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
252 "com.liferay.portal.kernel.util.OrderByComparator"
253 };
254 Object[] finderArgs = new Object[] {
255 new Long(productEntryId), String.valueOf(begin),
256 String.valueOf(end), String.valueOf(obc)
257 };
258 Object result = FinderCache.getResult(finderClassName,
259 finderMethodName, finderParams, finderArgs, getSessionFactory());
260
261 if (result == null) {
262 Session session = null;
263
264 try {
265 session = openSession();
266
267 StringMaker query = new StringMaker();
268 query.append(
269 "FROM com.liferay.portlet.softwarecatalog.model.SCProductScreenshot WHERE ");
270 query.append("productEntryId = ?");
271 query.append(" ");
272
273 if (obc != null) {
274 query.append("ORDER BY ");
275 query.append(obc.getOrderBy());
276 }
277 else {
278 query.append("ORDER BY ");
279 query.append("productEntryId ASC").append(", ");
280 query.append("priority ASC");
281 }
282
283 Query q = session.createQuery(query.toString());
284 int queryPos = 0;
285 q.setLong(queryPos++, productEntryId);
286
287 List list = QueryUtil.list(q, getDialect(), begin, end);
288 FinderCache.putResult(finderClassName, finderMethodName,
289 finderParams, finderArgs, list);
290
291 return list;
292 }
293 catch (Exception e) {
294 throw HibernateUtil.processException(e);
295 }
296 finally {
297 closeSession(session);
298 }
299 }
300 else {
301 return (List)result;
302 }
303 }
304
305 public SCProductScreenshot findByProductEntryId_First(long productEntryId,
306 OrderByComparator obc)
307 throws NoSuchProductScreenshotException, SystemException {
308 List list = findByProductEntryId(productEntryId, 0, 1, obc);
309
310 if (list.size() == 0) {
311 StringMaker msg = new StringMaker();
312 msg.append("No SCProductScreenshot exists with the key ");
313 msg.append(StringPool.OPEN_CURLY_BRACE);
314 msg.append("productEntryId=");
315 msg.append(productEntryId);
316 msg.append(StringPool.CLOSE_CURLY_BRACE);
317 throw new NoSuchProductScreenshotException(msg.toString());
318 }
319 else {
320 return (SCProductScreenshot)list.get(0);
321 }
322 }
323
324 public SCProductScreenshot findByProductEntryId_Last(long productEntryId,
325 OrderByComparator obc)
326 throws NoSuchProductScreenshotException, SystemException {
327 int count = countByProductEntryId(productEntryId);
328 List list = findByProductEntryId(productEntryId, count - 1, count, obc);
329
330 if (list.size() == 0) {
331 StringMaker msg = new StringMaker();
332 msg.append("No SCProductScreenshot exists with the key ");
333 msg.append(StringPool.OPEN_CURLY_BRACE);
334 msg.append("productEntryId=");
335 msg.append(productEntryId);
336 msg.append(StringPool.CLOSE_CURLY_BRACE);
337 throw new NoSuchProductScreenshotException(msg.toString());
338 }
339 else {
340 return (SCProductScreenshot)list.get(0);
341 }
342 }
343
344 public SCProductScreenshot[] findByProductEntryId_PrevAndNext(
345 long productScreenshotId, long productEntryId, OrderByComparator obc)
346 throws NoSuchProductScreenshotException, SystemException {
347 SCProductScreenshot scProductScreenshot = findByPrimaryKey(productScreenshotId);
348 int count = countByProductEntryId(productEntryId);
349 Session session = null;
350
351 try {
352 session = openSession();
353
354 StringMaker query = new StringMaker();
355 query.append(
356 "FROM com.liferay.portlet.softwarecatalog.model.SCProductScreenshot WHERE ");
357 query.append("productEntryId = ?");
358 query.append(" ");
359
360 if (obc != null) {
361 query.append("ORDER BY ");
362 query.append(obc.getOrderBy());
363 }
364 else {
365 query.append("ORDER BY ");
366 query.append("productEntryId ASC").append(", ");
367 query.append("priority ASC");
368 }
369
370 Query q = session.createQuery(query.toString());
371 int queryPos = 0;
372 q.setLong(queryPos++, productEntryId);
373
374 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
375 scProductScreenshot);
376 SCProductScreenshot[] array = new SCProductScreenshotImpl[3];
377 array[0] = (SCProductScreenshot)objArray[0];
378 array[1] = (SCProductScreenshot)objArray[1];
379 array[2] = (SCProductScreenshot)objArray[2];
380
381 return array;
382 }
383 catch (Exception e) {
384 throw HibernateUtil.processException(e);
385 }
386 finally {
387 closeSession(session);
388 }
389 }
390
391 public SCProductScreenshot findByP_P(long productEntryId, int priority)
392 throws NoSuchProductScreenshotException, SystemException {
393 SCProductScreenshot scProductScreenshot = fetchByP_P(productEntryId,
394 priority);
395
396 if (scProductScreenshot == null) {
397 StringMaker msg = new StringMaker();
398 msg.append("No SCProductScreenshot exists with the key ");
399 msg.append(StringPool.OPEN_CURLY_BRACE);
400 msg.append("productEntryId=");
401 msg.append(productEntryId);
402 msg.append(", ");
403 msg.append("priority=");
404 msg.append(priority);
405 msg.append(StringPool.CLOSE_CURLY_BRACE);
406
407 if (_log.isWarnEnabled()) {
408 _log.warn(msg.toString());
409 }
410
411 throw new NoSuchProductScreenshotException(msg.toString());
412 }
413
414 return scProductScreenshot;
415 }
416
417 public SCProductScreenshot fetchByP_P(long productEntryId, int priority)
418 throws SystemException {
419 String finderClassName = SCProductScreenshot.class.getName();
420 String finderMethodName = "fetchByP_P";
421 String[] finderParams = new String[] {
422 Long.class.getName(), Integer.class.getName()
423 };
424 Object[] finderArgs = new Object[] {
425 new Long(productEntryId), new Integer(priority)
426 };
427 Object result = FinderCache.getResult(finderClassName,
428 finderMethodName, finderParams, finderArgs, getSessionFactory());
429
430 if (result == null) {
431 Session session = null;
432
433 try {
434 session = openSession();
435
436 StringMaker query = new StringMaker();
437 query.append(
438 "FROM com.liferay.portlet.softwarecatalog.model.SCProductScreenshot WHERE ");
439 query.append("productEntryId = ?");
440 query.append(" AND ");
441 query.append("priority = ?");
442 query.append(" ");
443 query.append("ORDER BY ");
444 query.append("productEntryId ASC").append(", ");
445 query.append("priority ASC");
446
447 Query q = session.createQuery(query.toString());
448 int queryPos = 0;
449 q.setLong(queryPos++, productEntryId);
450 q.setInteger(queryPos++, priority);
451
452 List list = q.list();
453 FinderCache.putResult(finderClassName, finderMethodName,
454 finderParams, finderArgs, list);
455
456 if (list.size() == 0) {
457 return null;
458 }
459 else {
460 return (SCProductScreenshot)list.get(0);
461 }
462 }
463 catch (Exception e) {
464 throw HibernateUtil.processException(e);
465 }
466 finally {
467 closeSession(session);
468 }
469 }
470 else {
471 List list = (List)result;
472
473 if (list.size() == 0) {
474 return null;
475 }
476 else {
477 return (SCProductScreenshot)list.get(0);
478 }
479 }
480 }
481
482 public List findWithDynamicQuery(DynamicQueryInitializer queryInitializer)
483 throws SystemException {
484 Session session = null;
485
486 try {
487 session = openSession();
488
489 DynamicQuery query = queryInitializer.initialize(session);
490
491 return query.list();
492 }
493 catch (Exception e) {
494 throw HibernateUtil.processException(e);
495 }
496 finally {
497 closeSession(session);
498 }
499 }
500
501 public List findWithDynamicQuery(DynamicQueryInitializer queryInitializer,
502 int begin, int end) throws SystemException {
503 Session session = null;
504
505 try {
506 session = openSession();
507
508 DynamicQuery query = queryInitializer.initialize(session);
509 query.setLimit(begin, end);
510
511 return query.list();
512 }
513 catch (Exception e) {
514 throw HibernateUtil.processException(e);
515 }
516 finally {
517 closeSession(session);
518 }
519 }
520
521 public List findAll() throws SystemException {
522 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
523 }
524
525 public List findAll(int begin, int end) throws SystemException {
526 return findAll(begin, end, null);
527 }
528
529 public List findAll(int begin, int end, OrderByComparator obc)
530 throws SystemException {
531 String finderClassName = SCProductScreenshot.class.getName();
532 String finderMethodName = "findAll";
533 String[] finderParams = new String[] {
534 "java.lang.Integer", "java.lang.Integer",
535 "com.liferay.portal.kernel.util.OrderByComparator"
536 };
537 Object[] finderArgs = new Object[] {
538 String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
539 };
540 Object result = FinderCache.getResult(finderClassName,
541 finderMethodName, finderParams, finderArgs, getSessionFactory());
542
543 if (result == null) {
544 Session session = null;
545
546 try {
547 session = openSession();
548
549 StringMaker query = new StringMaker();
550 query.append(
551 "FROM com.liferay.portlet.softwarecatalog.model.SCProductScreenshot ");
552
553 if (obc != null) {
554 query.append("ORDER BY ");
555 query.append(obc.getOrderBy());
556 }
557 else {
558 query.append("ORDER BY ");
559 query.append("productEntryId ASC").append(", ");
560 query.append("priority ASC");
561 }
562
563 Query q = session.createQuery(query.toString());
564 List list = QueryUtil.list(q, getDialect(), begin, end);
565
566 if (obc == null) {
567 Collections.sort(list);
568 }
569
570 FinderCache.putResult(finderClassName, finderMethodName,
571 finderParams, finderArgs, list);
572
573 return list;
574 }
575 catch (Exception e) {
576 throw HibernateUtil.processException(e);
577 }
578 finally {
579 closeSession(session);
580 }
581 }
582 else {
583 return (List)result;
584 }
585 }
586
587 public void removeByProductEntryId(long productEntryId)
588 throws SystemException {
589 Iterator itr = findByProductEntryId(productEntryId).iterator();
590
591 while (itr.hasNext()) {
592 SCProductScreenshot scProductScreenshot = (SCProductScreenshot)itr.next();
593 remove(scProductScreenshot);
594 }
595 }
596
597 public void removeByP_P(long productEntryId, int priority)
598 throws NoSuchProductScreenshotException, SystemException {
599 SCProductScreenshot scProductScreenshot = findByP_P(productEntryId,
600 priority);
601 remove(scProductScreenshot);
602 }
603
604 public void removeAll() throws SystemException {
605 Iterator itr = findAll().iterator();
606
607 while (itr.hasNext()) {
608 remove((SCProductScreenshot)itr.next());
609 }
610 }
611
612 public int countByProductEntryId(long productEntryId)
613 throws SystemException {
614 String finderClassName = SCProductScreenshot.class.getName();
615 String finderMethodName = "countByProductEntryId";
616 String[] finderParams = new String[] { Long.class.getName() };
617 Object[] finderArgs = new Object[] { new Long(productEntryId) };
618 Object result = FinderCache.getResult(finderClassName,
619 finderMethodName, finderParams, finderArgs, getSessionFactory());
620
621 if (result == null) {
622 Session session = null;
623
624 try {
625 session = openSession();
626
627 StringMaker query = new StringMaker();
628 query.append("SELECT COUNT(*) ");
629 query.append(
630 "FROM com.liferay.portlet.softwarecatalog.model.SCProductScreenshot WHERE ");
631 query.append("productEntryId = ?");
632 query.append(" ");
633
634 Query q = session.createQuery(query.toString());
635 int queryPos = 0;
636 q.setLong(queryPos++, productEntryId);
637
638 Long count = null;
639 Iterator itr = q.list().iterator();
640
641 if (itr.hasNext()) {
642 count = (Long)itr.next();
643 }
644
645 if (count == null) {
646 count = new Long(0);
647 }
648
649 FinderCache.putResult(finderClassName, finderMethodName,
650 finderParams, finderArgs, count);
651
652 return count.intValue();
653 }
654 catch (Exception e) {
655 throw HibernateUtil.processException(e);
656 }
657 finally {
658 closeSession(session);
659 }
660 }
661 else {
662 return ((Long)result).intValue();
663 }
664 }
665
666 public int countByP_P(long productEntryId, int priority)
667 throws SystemException {
668 String finderClassName = SCProductScreenshot.class.getName();
669 String finderMethodName = "countByP_P";
670 String[] finderParams = new String[] {
671 Long.class.getName(), Integer.class.getName()
672 };
673 Object[] finderArgs = new Object[] {
674 new Long(productEntryId), new Integer(priority)
675 };
676 Object result = FinderCache.getResult(finderClassName,
677 finderMethodName, finderParams, finderArgs, getSessionFactory());
678
679 if (result == null) {
680 Session session = null;
681
682 try {
683 session = openSession();
684
685 StringMaker query = new StringMaker();
686 query.append("SELECT COUNT(*) ");
687 query.append(
688 "FROM com.liferay.portlet.softwarecatalog.model.SCProductScreenshot WHERE ");
689 query.append("productEntryId = ?");
690 query.append(" AND ");
691 query.append("priority = ?");
692 query.append(" ");
693
694 Query q = session.createQuery(query.toString());
695 int queryPos = 0;
696 q.setLong(queryPos++, productEntryId);
697 q.setInteger(queryPos++, priority);
698
699 Long count = null;
700 Iterator itr = q.list().iterator();
701
702 if (itr.hasNext()) {
703 count = (Long)itr.next();
704 }
705
706 if (count == null) {
707 count = new Long(0);
708 }
709
710 FinderCache.putResult(finderClassName, finderMethodName,
711 finderParams, finderArgs, count);
712
713 return count.intValue();
714 }
715 catch (Exception e) {
716 throw HibernateUtil.processException(e);
717 }
718 finally {
719 closeSession(session);
720 }
721 }
722 else {
723 return ((Long)result).intValue();
724 }
725 }
726
727 public int countAll() throws SystemException {
728 String finderClassName = SCProductScreenshot.class.getName();
729 String finderMethodName = "countAll";
730 String[] finderParams = new String[] { };
731 Object[] finderArgs = new Object[] { };
732 Object result = FinderCache.getResult(finderClassName,
733 finderMethodName, finderParams, finderArgs, getSessionFactory());
734
735 if (result == null) {
736 Session session = null;
737
738 try {
739 session = openSession();
740
741 StringMaker query = new StringMaker();
742 query.append("SELECT COUNT(*) ");
743 query.append(
744 "FROM com.liferay.portlet.softwarecatalog.model.SCProductScreenshot");
745
746 Query q = session.createQuery(query.toString());
747 Long count = null;
748 Iterator itr = q.list().iterator();
749
750 if (itr.hasNext()) {
751 count = (Long)itr.next();
752 }
753
754 if (count == null) {
755 count = new Long(0);
756 }
757
758 FinderCache.putResult(finderClassName, finderMethodName,
759 finderParams, finderArgs, count);
760
761 return count.intValue();
762 }
763 catch (Exception e) {
764 throw HibernateUtil.processException(e);
765 }
766 finally {
767 closeSession(session);
768 }
769 }
770 else {
771 return ((Long)result).intValue();
772 }
773 }
774
775 protected void initDao() {
776 }
777
778 private static Log _log = LogFactory.getLog(SCProductScreenshotPersistenceImpl.class);
779 }