1
22
23 package com.liferay.portlet.softwarecatalog.service.persistence;
24
25 import com.liferay.portal.SystemException;
26 import com.liferay.portal.kernel.dao.orm.DynamicQuery;
27 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
28 import com.liferay.portal.kernel.dao.orm.Query;
29 import com.liferay.portal.kernel.dao.orm.QueryPos;
30 import com.liferay.portal.kernel.dao.orm.QueryUtil;
31 import com.liferay.portal.kernel.dao.orm.Session;
32 import com.liferay.portal.kernel.util.GetterUtil;
33 import com.liferay.portal.kernel.util.ListUtil;
34 import com.liferay.portal.kernel.util.OrderByComparator;
35 import com.liferay.portal.kernel.util.StringPool;
36 import com.liferay.portal.kernel.util.StringUtil;
37 import com.liferay.portal.model.ModelListener;
38 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
39
40 import com.liferay.portlet.softwarecatalog.NoSuchProductScreenshotException;
41 import com.liferay.portlet.softwarecatalog.model.SCProductScreenshot;
42 import com.liferay.portlet.softwarecatalog.model.impl.SCProductScreenshotImpl;
43 import com.liferay.portlet.softwarecatalog.model.impl.SCProductScreenshotModelImpl;
44
45 import org.apache.commons.logging.Log;
46 import org.apache.commons.logging.LogFactory;
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 SCProductScreenshotPersistenceImpl extends BasePersistenceImpl
60 implements SCProductScreenshotPersistence {
61 public SCProductScreenshot create(long productScreenshotId) {
62 SCProductScreenshot scProductScreenshot = new SCProductScreenshotImpl();
63
64 scProductScreenshot.setNew(true);
65 scProductScreenshot.setPrimaryKey(productScreenshotId);
66
67 return scProductScreenshot;
68 }
69
70 public SCProductScreenshot remove(long productScreenshotId)
71 throws NoSuchProductScreenshotException, SystemException {
72 Session session = null;
73
74 try {
75 session = openSession();
76
77 SCProductScreenshot scProductScreenshot = (SCProductScreenshot)session.get(SCProductScreenshotImpl.class,
78 new Long(productScreenshotId));
79
80 if (scProductScreenshot == null) {
81 if (_log.isWarnEnabled()) {
82 _log.warn(
83 "No SCProductScreenshot exists with the primary key " +
84 productScreenshotId);
85 }
86
87 throw new NoSuchProductScreenshotException(
88 "No SCProductScreenshot exists with the primary key " +
89 productScreenshotId);
90 }
91
92 return remove(scProductScreenshot);
93 }
94 catch (NoSuchProductScreenshotException nsee) {
95 throw nsee;
96 }
97 catch (Exception e) {
98 throw processException(e);
99 }
100 finally {
101 closeSession(session);
102 }
103 }
104
105 public SCProductScreenshot remove(SCProductScreenshot scProductScreenshot)
106 throws SystemException {
107 if (_listeners.length > 0) {
108 for (ModelListener listener : _listeners) {
109 listener.onBeforeRemove(scProductScreenshot);
110 }
111 }
112
113 scProductScreenshot = removeImpl(scProductScreenshot);
114
115 if (_listeners.length > 0) {
116 for (ModelListener listener : _listeners) {
117 listener.onAfterRemove(scProductScreenshot);
118 }
119 }
120
121 return scProductScreenshot;
122 }
123
124 protected SCProductScreenshot removeImpl(
125 SCProductScreenshot scProductScreenshot) throws SystemException {
126 Session session = null;
127
128 try {
129 session = openSession();
130
131 session.delete(scProductScreenshot);
132
133 session.flush();
134
135 return scProductScreenshot;
136 }
137 catch (Exception e) {
138 throw processException(e);
139 }
140 finally {
141 closeSession(session);
142
143 FinderCacheUtil.clearCache(SCProductScreenshot.class.getName());
144 }
145 }
146
147
150 public SCProductScreenshot update(SCProductScreenshot scProductScreenshot)
151 throws SystemException {
152 if (_log.isWarnEnabled()) {
153 _log.warn(
154 "Using the deprecated update(SCProductScreenshot scProductScreenshot) method. Use update(SCProductScreenshot scProductScreenshot, boolean merge) instead.");
155 }
156
157 return update(scProductScreenshot, false);
158 }
159
160
173 public SCProductScreenshot update(SCProductScreenshot scProductScreenshot,
174 boolean merge) throws SystemException {
175 boolean isNew = scProductScreenshot.isNew();
176
177 if (_listeners.length > 0) {
178 for (ModelListener listener : _listeners) {
179 if (isNew) {
180 listener.onBeforeCreate(scProductScreenshot);
181 }
182 else {
183 listener.onBeforeUpdate(scProductScreenshot);
184 }
185 }
186 }
187
188 scProductScreenshot = updateImpl(scProductScreenshot, merge);
189
190 if (_listeners.length > 0) {
191 for (ModelListener listener : _listeners) {
192 if (isNew) {
193 listener.onAfterCreate(scProductScreenshot);
194 }
195 else {
196 listener.onAfterUpdate(scProductScreenshot);
197 }
198 }
199 }
200
201 return scProductScreenshot;
202 }
203
204 public SCProductScreenshot updateImpl(
205 com.liferay.portlet.softwarecatalog.model.SCProductScreenshot scProductScreenshot,
206 boolean merge) throws SystemException {
207 Session session = null;
208
209 try {
210 session = openSession();
211
212 if (merge) {
213 session.merge(scProductScreenshot);
214 }
215 else {
216 if (scProductScreenshot.isNew()) {
217 session.save(scProductScreenshot);
218 }
219 }
220
221 session.flush();
222
223 scProductScreenshot.setNew(false);
224
225 return scProductScreenshot;
226 }
227 catch (Exception e) {
228 throw processException(e);
229 }
230 finally {
231 closeSession(session);
232
233 FinderCacheUtil.clearCache(SCProductScreenshot.class.getName());
234 }
235 }
236
237 public SCProductScreenshot findByPrimaryKey(long productScreenshotId)
238 throws NoSuchProductScreenshotException, SystemException {
239 SCProductScreenshot scProductScreenshot = fetchByPrimaryKey(productScreenshotId);
240
241 if (scProductScreenshot == null) {
242 if (_log.isWarnEnabled()) {
243 _log.warn("No SCProductScreenshot exists with the primary key " +
244 productScreenshotId);
245 }
246
247 throw new NoSuchProductScreenshotException(
248 "No SCProductScreenshot exists with the primary key " +
249 productScreenshotId);
250 }
251
252 return scProductScreenshot;
253 }
254
255 public SCProductScreenshot fetchByPrimaryKey(long productScreenshotId)
256 throws SystemException {
257 Session session = null;
258
259 try {
260 session = openSession();
261
262 return (SCProductScreenshot)session.get(SCProductScreenshotImpl.class,
263 new Long(productScreenshotId));
264 }
265 catch (Exception e) {
266 throw processException(e);
267 }
268 finally {
269 closeSession(session);
270 }
271 }
272
273 public List<SCProductScreenshot> findByProductEntryId(long productEntryId)
274 throws SystemException {
275 boolean finderClassNameCacheEnabled = SCProductScreenshotModelImpl.CACHE_ENABLED;
276 String finderClassName = SCProductScreenshot.class.getName();
277 String finderMethodName = "findByProductEntryId";
278 String[] finderParams = new String[] { Long.class.getName() };
279 Object[] finderArgs = new Object[] { new Long(productEntryId) };
280
281 Object result = null;
282
283 if (finderClassNameCacheEnabled) {
284 result = FinderCacheUtil.getResult(finderClassName,
285 finderMethodName, finderParams, finderArgs, this);
286 }
287
288 if (result == null) {
289 Session session = null;
290
291 try {
292 session = openSession();
293
294 StringBuilder query = new StringBuilder();
295
296 query.append(
297 "FROM com.liferay.portlet.softwarecatalog.model.SCProductScreenshot WHERE ");
298
299 query.append("productEntryId = ?");
300
301 query.append(" ");
302
303 query.append("ORDER BY ");
304
305 query.append("productEntryId ASC, ");
306 query.append("priority ASC");
307
308 Query q = session.createQuery(query.toString());
309
310 QueryPos qPos = QueryPos.getInstance(q);
311
312 qPos.add(productEntryId);
313
314 List<SCProductScreenshot> list = q.list();
315
316 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
317 finderClassName, finderMethodName, finderParams,
318 finderArgs, list);
319
320 return list;
321 }
322 catch (Exception e) {
323 throw processException(e);
324 }
325 finally {
326 closeSession(session);
327 }
328 }
329 else {
330 return (List<SCProductScreenshot>)result;
331 }
332 }
333
334 public List<SCProductScreenshot> findByProductEntryId(long productEntryId,
335 int start, int end) throws SystemException {
336 return findByProductEntryId(productEntryId, start, end, null);
337 }
338
339 public List<SCProductScreenshot> findByProductEntryId(long productEntryId,
340 int start, int end, OrderByComparator obc) throws SystemException {
341 boolean finderClassNameCacheEnabled = SCProductScreenshotModelImpl.CACHE_ENABLED;
342 String finderClassName = SCProductScreenshot.class.getName();
343 String finderMethodName = "findByProductEntryId";
344 String[] finderParams = new String[] {
345 Long.class.getName(),
346
347 "java.lang.Integer", "java.lang.Integer",
348 "com.liferay.portal.kernel.util.OrderByComparator"
349 };
350 Object[] finderArgs = new Object[] {
351 new Long(productEntryId),
352
353 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
354 };
355
356 Object result = null;
357
358 if (finderClassNameCacheEnabled) {
359 result = FinderCacheUtil.getResult(finderClassName,
360 finderMethodName, finderParams, finderArgs, this);
361 }
362
363 if (result == null) {
364 Session session = null;
365
366 try {
367 session = openSession();
368
369 StringBuilder query = new StringBuilder();
370
371 query.append(
372 "FROM com.liferay.portlet.softwarecatalog.model.SCProductScreenshot WHERE ");
373
374 query.append("productEntryId = ?");
375
376 query.append(" ");
377
378 if (obc != null) {
379 query.append("ORDER BY ");
380 query.append(obc.getOrderBy());
381 }
382
383 else {
384 query.append("ORDER BY ");
385
386 query.append("productEntryId ASC, ");
387 query.append("priority ASC");
388 }
389
390 Query q = session.createQuery(query.toString());
391
392 QueryPos qPos = QueryPos.getInstance(q);
393
394 qPos.add(productEntryId);
395
396 List<SCProductScreenshot> list = (List<SCProductScreenshot>)QueryUtil.list(q,
397 getDialect(), start, end);
398
399 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
400 finderClassName, finderMethodName, finderParams,
401 finderArgs, list);
402
403 return list;
404 }
405 catch (Exception e) {
406 throw processException(e);
407 }
408 finally {
409 closeSession(session);
410 }
411 }
412 else {
413 return (List<SCProductScreenshot>)result;
414 }
415 }
416
417 public SCProductScreenshot findByProductEntryId_First(long productEntryId,
418 OrderByComparator obc)
419 throws NoSuchProductScreenshotException, SystemException {
420 List<SCProductScreenshot> list = findByProductEntryId(productEntryId,
421 0, 1, obc);
422
423 if (list.size() == 0) {
424 StringBuilder msg = new StringBuilder();
425
426 msg.append("No SCProductScreenshot exists with the key {");
427
428 msg.append("productEntryId=" + productEntryId);
429
430 msg.append(StringPool.CLOSE_CURLY_BRACE);
431
432 throw new NoSuchProductScreenshotException(msg.toString());
433 }
434 else {
435 return list.get(0);
436 }
437 }
438
439 public SCProductScreenshot findByProductEntryId_Last(long productEntryId,
440 OrderByComparator obc)
441 throws NoSuchProductScreenshotException, SystemException {
442 int count = countByProductEntryId(productEntryId);
443
444 List<SCProductScreenshot> list = findByProductEntryId(productEntryId,
445 count - 1, count, obc);
446
447 if (list.size() == 0) {
448 StringBuilder msg = new StringBuilder();
449
450 msg.append("No SCProductScreenshot exists with the key {");
451
452 msg.append("productEntryId=" + productEntryId);
453
454 msg.append(StringPool.CLOSE_CURLY_BRACE);
455
456 throw new NoSuchProductScreenshotException(msg.toString());
457 }
458 else {
459 return list.get(0);
460 }
461 }
462
463 public SCProductScreenshot[] findByProductEntryId_PrevAndNext(
464 long productScreenshotId, long productEntryId, OrderByComparator obc)
465 throws NoSuchProductScreenshotException, SystemException {
466 SCProductScreenshot scProductScreenshot = findByPrimaryKey(productScreenshotId);
467
468 int count = countByProductEntryId(productEntryId);
469
470 Session session = null;
471
472 try {
473 session = openSession();
474
475 StringBuilder query = new StringBuilder();
476
477 query.append(
478 "FROM com.liferay.portlet.softwarecatalog.model.SCProductScreenshot WHERE ");
479
480 query.append("productEntryId = ?");
481
482 query.append(" ");
483
484 if (obc != null) {
485 query.append("ORDER BY ");
486 query.append(obc.getOrderBy());
487 }
488
489 else {
490 query.append("ORDER BY ");
491
492 query.append("productEntryId ASC, ");
493 query.append("priority ASC");
494 }
495
496 Query q = session.createQuery(query.toString());
497
498 QueryPos qPos = QueryPos.getInstance(q);
499
500 qPos.add(productEntryId);
501
502 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
503 scProductScreenshot);
504
505 SCProductScreenshot[] array = new SCProductScreenshotImpl[3];
506
507 array[0] = (SCProductScreenshot)objArray[0];
508 array[1] = (SCProductScreenshot)objArray[1];
509 array[2] = (SCProductScreenshot)objArray[2];
510
511 return array;
512 }
513 catch (Exception e) {
514 throw processException(e);
515 }
516 finally {
517 closeSession(session);
518 }
519 }
520
521 public SCProductScreenshot findByThumbnailId(long thumbnailId)
522 throws NoSuchProductScreenshotException, SystemException {
523 SCProductScreenshot scProductScreenshot = fetchByThumbnailId(thumbnailId);
524
525 if (scProductScreenshot == null) {
526 StringBuilder msg = new StringBuilder();
527
528 msg.append("No SCProductScreenshot exists with the key {");
529
530 msg.append("thumbnailId=" + thumbnailId);
531
532 msg.append(StringPool.CLOSE_CURLY_BRACE);
533
534 if (_log.isWarnEnabled()) {
535 _log.warn(msg.toString());
536 }
537
538 throw new NoSuchProductScreenshotException(msg.toString());
539 }
540
541 return scProductScreenshot;
542 }
543
544 public SCProductScreenshot fetchByThumbnailId(long thumbnailId)
545 throws SystemException {
546 boolean finderClassNameCacheEnabled = SCProductScreenshotModelImpl.CACHE_ENABLED;
547 String finderClassName = SCProductScreenshot.class.getName();
548 String finderMethodName = "fetchByThumbnailId";
549 String[] finderParams = new String[] { Long.class.getName() };
550 Object[] finderArgs = new Object[] { new Long(thumbnailId) };
551
552 Object result = null;
553
554 if (finderClassNameCacheEnabled) {
555 result = FinderCacheUtil.getResult(finderClassName,
556 finderMethodName, finderParams, finderArgs, this);
557 }
558
559 if (result == null) {
560 Session session = null;
561
562 try {
563 session = openSession();
564
565 StringBuilder query = new StringBuilder();
566
567 query.append(
568 "FROM com.liferay.portlet.softwarecatalog.model.SCProductScreenshot WHERE ");
569
570 query.append("thumbnailId = ?");
571
572 query.append(" ");
573
574 query.append("ORDER BY ");
575
576 query.append("productEntryId ASC, ");
577 query.append("priority ASC");
578
579 Query q = session.createQuery(query.toString());
580
581 QueryPos qPos = QueryPos.getInstance(q);
582
583 qPos.add(thumbnailId);
584
585 List<SCProductScreenshot> list = q.list();
586
587 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
588 finderClassName, finderMethodName, finderParams,
589 finderArgs, list);
590
591 if (list.size() == 0) {
592 return null;
593 }
594 else {
595 return list.get(0);
596 }
597 }
598 catch (Exception e) {
599 throw processException(e);
600 }
601 finally {
602 closeSession(session);
603 }
604 }
605 else {
606 List<SCProductScreenshot> list = (List<SCProductScreenshot>)result;
607
608 if (list.size() == 0) {
609 return null;
610 }
611 else {
612 return list.get(0);
613 }
614 }
615 }
616
617 public SCProductScreenshot findByFullImageId(long fullImageId)
618 throws NoSuchProductScreenshotException, SystemException {
619 SCProductScreenshot scProductScreenshot = fetchByFullImageId(fullImageId);
620
621 if (scProductScreenshot == null) {
622 StringBuilder msg = new StringBuilder();
623
624 msg.append("No SCProductScreenshot exists with the key {");
625
626 msg.append("fullImageId=" + fullImageId);
627
628 msg.append(StringPool.CLOSE_CURLY_BRACE);
629
630 if (_log.isWarnEnabled()) {
631 _log.warn(msg.toString());
632 }
633
634 throw new NoSuchProductScreenshotException(msg.toString());
635 }
636
637 return scProductScreenshot;
638 }
639
640 public SCProductScreenshot fetchByFullImageId(long fullImageId)
641 throws SystemException {
642 boolean finderClassNameCacheEnabled = SCProductScreenshotModelImpl.CACHE_ENABLED;
643 String finderClassName = SCProductScreenshot.class.getName();
644 String finderMethodName = "fetchByFullImageId";
645 String[] finderParams = new String[] { Long.class.getName() };
646 Object[] finderArgs = new Object[] { new Long(fullImageId) };
647
648 Object result = null;
649
650 if (finderClassNameCacheEnabled) {
651 result = FinderCacheUtil.getResult(finderClassName,
652 finderMethodName, finderParams, finderArgs, this);
653 }
654
655 if (result == null) {
656 Session session = null;
657
658 try {
659 session = openSession();
660
661 StringBuilder query = new StringBuilder();
662
663 query.append(
664 "FROM com.liferay.portlet.softwarecatalog.model.SCProductScreenshot WHERE ");
665
666 query.append("fullImageId = ?");
667
668 query.append(" ");
669
670 query.append("ORDER BY ");
671
672 query.append("productEntryId ASC, ");
673 query.append("priority ASC");
674
675 Query q = session.createQuery(query.toString());
676
677 QueryPos qPos = QueryPos.getInstance(q);
678
679 qPos.add(fullImageId);
680
681 List<SCProductScreenshot> list = q.list();
682
683 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
684 finderClassName, finderMethodName, finderParams,
685 finderArgs, list);
686
687 if (list.size() == 0) {
688 return null;
689 }
690 else {
691 return list.get(0);
692 }
693 }
694 catch (Exception e) {
695 throw processException(e);
696 }
697 finally {
698 closeSession(session);
699 }
700 }
701 else {
702 List<SCProductScreenshot> list = (List<SCProductScreenshot>)result;
703
704 if (list.size() == 0) {
705 return null;
706 }
707 else {
708 return list.get(0);
709 }
710 }
711 }
712
713 public SCProductScreenshot findByP_P(long productEntryId, int priority)
714 throws NoSuchProductScreenshotException, SystemException {
715 SCProductScreenshot scProductScreenshot = fetchByP_P(productEntryId,
716 priority);
717
718 if (scProductScreenshot == null) {
719 StringBuilder msg = new StringBuilder();
720
721 msg.append("No SCProductScreenshot exists with the key {");
722
723 msg.append("productEntryId=" + productEntryId);
724
725 msg.append(", ");
726 msg.append("priority=" + priority);
727
728 msg.append(StringPool.CLOSE_CURLY_BRACE);
729
730 if (_log.isWarnEnabled()) {
731 _log.warn(msg.toString());
732 }
733
734 throw new NoSuchProductScreenshotException(msg.toString());
735 }
736
737 return scProductScreenshot;
738 }
739
740 public SCProductScreenshot fetchByP_P(long productEntryId, int priority)
741 throws SystemException {
742 boolean finderClassNameCacheEnabled = SCProductScreenshotModelImpl.CACHE_ENABLED;
743 String finderClassName = SCProductScreenshot.class.getName();
744 String finderMethodName = "fetchByP_P";
745 String[] finderParams = new String[] {
746 Long.class.getName(), Integer.class.getName()
747 };
748 Object[] finderArgs = new Object[] {
749 new Long(productEntryId), new Integer(priority)
750 };
751
752 Object result = null;
753
754 if (finderClassNameCacheEnabled) {
755 result = FinderCacheUtil.getResult(finderClassName,
756 finderMethodName, finderParams, finderArgs, this);
757 }
758
759 if (result == null) {
760 Session session = null;
761
762 try {
763 session = openSession();
764
765 StringBuilder query = new StringBuilder();
766
767 query.append(
768 "FROM com.liferay.portlet.softwarecatalog.model.SCProductScreenshot WHERE ");
769
770 query.append("productEntryId = ?");
771
772 query.append(" AND ");
773
774 query.append("priority = ?");
775
776 query.append(" ");
777
778 query.append("ORDER BY ");
779
780 query.append("productEntryId ASC, ");
781 query.append("priority ASC");
782
783 Query q = session.createQuery(query.toString());
784
785 QueryPos qPos = QueryPos.getInstance(q);
786
787 qPos.add(productEntryId);
788
789 qPos.add(priority);
790
791 List<SCProductScreenshot> list = q.list();
792
793 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
794 finderClassName, finderMethodName, finderParams,
795 finderArgs, list);
796
797 if (list.size() == 0) {
798 return null;
799 }
800 else {
801 return list.get(0);
802 }
803 }
804 catch (Exception e) {
805 throw processException(e);
806 }
807 finally {
808 closeSession(session);
809 }
810 }
811 else {
812 List<SCProductScreenshot> list = (List<SCProductScreenshot>)result;
813
814 if (list.size() == 0) {
815 return null;
816 }
817 else {
818 return list.get(0);
819 }
820 }
821 }
822
823 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
824 throws SystemException {
825 Session session = null;
826
827 try {
828 session = openSession();
829
830 dynamicQuery.compile(session);
831
832 return dynamicQuery.list();
833 }
834 catch (Exception e) {
835 throw processException(e);
836 }
837 finally {
838 closeSession(session);
839 }
840 }
841
842 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
843 int start, int end) throws SystemException {
844 Session session = null;
845
846 try {
847 session = openSession();
848
849 dynamicQuery.setLimit(start, end);
850
851 dynamicQuery.compile(session);
852
853 return dynamicQuery.list();
854 }
855 catch (Exception e) {
856 throw processException(e);
857 }
858 finally {
859 closeSession(session);
860 }
861 }
862
863 public List<SCProductScreenshot> findAll() throws SystemException {
864 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
865 }
866
867 public List<SCProductScreenshot> findAll(int start, int end)
868 throws SystemException {
869 return findAll(start, end, null);
870 }
871
872 public List<SCProductScreenshot> findAll(int start, int end,
873 OrderByComparator obc) throws SystemException {
874 boolean finderClassNameCacheEnabled = SCProductScreenshotModelImpl.CACHE_ENABLED;
875 String finderClassName = SCProductScreenshot.class.getName();
876 String finderMethodName = "findAll";
877 String[] finderParams = new String[] {
878 "java.lang.Integer", "java.lang.Integer",
879 "com.liferay.portal.kernel.util.OrderByComparator"
880 };
881 Object[] finderArgs = new Object[] {
882 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
883 };
884
885 Object result = null;
886
887 if (finderClassNameCacheEnabled) {
888 result = FinderCacheUtil.getResult(finderClassName,
889 finderMethodName, finderParams, finderArgs, this);
890 }
891
892 if (result == null) {
893 Session session = null;
894
895 try {
896 session = openSession();
897
898 StringBuilder query = new StringBuilder();
899
900 query.append(
901 "FROM com.liferay.portlet.softwarecatalog.model.SCProductScreenshot ");
902
903 if (obc != null) {
904 query.append("ORDER BY ");
905 query.append(obc.getOrderBy());
906 }
907
908 else {
909 query.append("ORDER BY ");
910
911 query.append("productEntryId ASC, ");
912 query.append("priority ASC");
913 }
914
915 Query q = session.createQuery(query.toString());
916
917 List<SCProductScreenshot> list = (List<SCProductScreenshot>)QueryUtil.list(q,
918 getDialect(), start, end);
919
920 if (obc == null) {
921 Collections.sort(list);
922 }
923
924 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
925 finderClassName, finderMethodName, finderParams,
926 finderArgs, list);
927
928 return list;
929 }
930 catch (Exception e) {
931 throw processException(e);
932 }
933 finally {
934 closeSession(session);
935 }
936 }
937 else {
938 return (List<SCProductScreenshot>)result;
939 }
940 }
941
942 public void removeByProductEntryId(long productEntryId)
943 throws SystemException {
944 for (SCProductScreenshot scProductScreenshot : findByProductEntryId(
945 productEntryId)) {
946 remove(scProductScreenshot);
947 }
948 }
949
950 public void removeByThumbnailId(long thumbnailId)
951 throws NoSuchProductScreenshotException, SystemException {
952 SCProductScreenshot scProductScreenshot = findByThumbnailId(thumbnailId);
953
954 remove(scProductScreenshot);
955 }
956
957 public void removeByFullImageId(long fullImageId)
958 throws NoSuchProductScreenshotException, SystemException {
959 SCProductScreenshot scProductScreenshot = findByFullImageId(fullImageId);
960
961 remove(scProductScreenshot);
962 }
963
964 public void removeByP_P(long productEntryId, int priority)
965 throws NoSuchProductScreenshotException, SystemException {
966 SCProductScreenshot scProductScreenshot = findByP_P(productEntryId,
967 priority);
968
969 remove(scProductScreenshot);
970 }
971
972 public void removeAll() throws SystemException {
973 for (SCProductScreenshot scProductScreenshot : findAll()) {
974 remove(scProductScreenshot);
975 }
976 }
977
978 public int countByProductEntryId(long productEntryId)
979 throws SystemException {
980 boolean finderClassNameCacheEnabled = SCProductScreenshotModelImpl.CACHE_ENABLED;
981 String finderClassName = SCProductScreenshot.class.getName();
982 String finderMethodName = "countByProductEntryId";
983 String[] finderParams = new String[] { Long.class.getName() };
984 Object[] finderArgs = new Object[] { new Long(productEntryId) };
985
986 Object result = null;
987
988 if (finderClassNameCacheEnabled) {
989 result = FinderCacheUtil.getResult(finderClassName,
990 finderMethodName, finderParams, finderArgs, this);
991 }
992
993 if (result == null) {
994 Session session = null;
995
996 try {
997 session = openSession();
998
999 StringBuilder query = new StringBuilder();
1000
1001 query.append("SELECT COUNT(*) ");
1002 query.append(
1003 "FROM com.liferay.portlet.softwarecatalog.model.SCProductScreenshot WHERE ");
1004
1005 query.append("productEntryId = ?");
1006
1007 query.append(" ");
1008
1009 Query q = session.createQuery(query.toString());
1010
1011 QueryPos qPos = QueryPos.getInstance(q);
1012
1013 qPos.add(productEntryId);
1014
1015 Long count = null;
1016
1017 Iterator<Long> itr = q.list().iterator();
1018
1019 if (itr.hasNext()) {
1020 count = itr.next();
1021 }
1022
1023 if (count == null) {
1024 count = new Long(0);
1025 }
1026
1027 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1028 finderClassName, finderMethodName, finderParams,
1029 finderArgs, count);
1030
1031 return count.intValue();
1032 }
1033 catch (Exception e) {
1034 throw processException(e);
1035 }
1036 finally {
1037 closeSession(session);
1038 }
1039 }
1040 else {
1041 return ((Long)result).intValue();
1042 }
1043 }
1044
1045 public int countByThumbnailId(long thumbnailId) throws SystemException {
1046 boolean finderClassNameCacheEnabled = SCProductScreenshotModelImpl.CACHE_ENABLED;
1047 String finderClassName = SCProductScreenshot.class.getName();
1048 String finderMethodName = "countByThumbnailId";
1049 String[] finderParams = new String[] { Long.class.getName() };
1050 Object[] finderArgs = new Object[] { new Long(thumbnailId) };
1051
1052 Object result = null;
1053
1054 if (finderClassNameCacheEnabled) {
1055 result = FinderCacheUtil.getResult(finderClassName,
1056 finderMethodName, finderParams, finderArgs, this);
1057 }
1058
1059 if (result == null) {
1060 Session session = null;
1061
1062 try {
1063 session = openSession();
1064
1065 StringBuilder query = new StringBuilder();
1066
1067 query.append("SELECT COUNT(*) ");
1068 query.append(
1069 "FROM com.liferay.portlet.softwarecatalog.model.SCProductScreenshot WHERE ");
1070
1071 query.append("thumbnailId = ?");
1072
1073 query.append(" ");
1074
1075 Query q = session.createQuery(query.toString());
1076
1077 QueryPos qPos = QueryPos.getInstance(q);
1078
1079 qPos.add(thumbnailId);
1080
1081 Long count = null;
1082
1083 Iterator<Long> itr = q.list().iterator();
1084
1085 if (itr.hasNext()) {
1086 count = itr.next();
1087 }
1088
1089 if (count == null) {
1090 count = new Long(0);
1091 }
1092
1093 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1094 finderClassName, finderMethodName, finderParams,
1095 finderArgs, count);
1096
1097 return count.intValue();
1098 }
1099 catch (Exception e) {
1100 throw processException(e);
1101 }
1102 finally {
1103 closeSession(session);
1104 }
1105 }
1106 else {
1107 return ((Long)result).intValue();
1108 }
1109 }
1110
1111 public int countByFullImageId(long fullImageId) throws SystemException {
1112 boolean finderClassNameCacheEnabled = SCProductScreenshotModelImpl.CACHE_ENABLED;
1113 String finderClassName = SCProductScreenshot.class.getName();
1114 String finderMethodName = "countByFullImageId";
1115 String[] finderParams = new String[] { Long.class.getName() };
1116 Object[] finderArgs = new Object[] { new Long(fullImageId) };
1117
1118 Object result = null;
1119
1120 if (finderClassNameCacheEnabled) {
1121 result = FinderCacheUtil.getResult(finderClassName,
1122 finderMethodName, finderParams, finderArgs, this);
1123 }
1124
1125 if (result == null) {
1126 Session session = null;
1127
1128 try {
1129 session = openSession();
1130
1131 StringBuilder query = new StringBuilder();
1132
1133 query.append("SELECT COUNT(*) ");
1134 query.append(
1135 "FROM com.liferay.portlet.softwarecatalog.model.SCProductScreenshot WHERE ");
1136
1137 query.append("fullImageId = ?");
1138
1139 query.append(" ");
1140
1141 Query q = session.createQuery(query.toString());
1142
1143 QueryPos qPos = QueryPos.getInstance(q);
1144
1145 qPos.add(fullImageId);
1146
1147 Long count = null;
1148
1149 Iterator<Long> itr = q.list().iterator();
1150
1151 if (itr.hasNext()) {
1152 count = itr.next();
1153 }
1154
1155 if (count == null) {
1156 count = new Long(0);
1157 }
1158
1159 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1160 finderClassName, finderMethodName, finderParams,
1161 finderArgs, count);
1162
1163 return count.intValue();
1164 }
1165 catch (Exception e) {
1166 throw processException(e);
1167 }
1168 finally {
1169 closeSession(session);
1170 }
1171 }
1172 else {
1173 return ((Long)result).intValue();
1174 }
1175 }
1176
1177 public int countByP_P(long productEntryId, int priority)
1178 throws SystemException {
1179 boolean finderClassNameCacheEnabled = SCProductScreenshotModelImpl.CACHE_ENABLED;
1180 String finderClassName = SCProductScreenshot.class.getName();
1181 String finderMethodName = "countByP_P";
1182 String[] finderParams = new String[] {
1183 Long.class.getName(), Integer.class.getName()
1184 };
1185 Object[] finderArgs = new Object[] {
1186 new Long(productEntryId), new Integer(priority)
1187 };
1188
1189 Object result = null;
1190
1191 if (finderClassNameCacheEnabled) {
1192 result = FinderCacheUtil.getResult(finderClassName,
1193 finderMethodName, finderParams, finderArgs, this);
1194 }
1195
1196 if (result == null) {
1197 Session session = null;
1198
1199 try {
1200 session = openSession();
1201
1202 StringBuilder query = new StringBuilder();
1203
1204 query.append("SELECT COUNT(*) ");
1205 query.append(
1206 "FROM com.liferay.portlet.softwarecatalog.model.SCProductScreenshot WHERE ");
1207
1208 query.append("productEntryId = ?");
1209
1210 query.append(" AND ");
1211
1212 query.append("priority = ?");
1213
1214 query.append(" ");
1215
1216 Query q = session.createQuery(query.toString());
1217
1218 QueryPos qPos = QueryPos.getInstance(q);
1219
1220 qPos.add(productEntryId);
1221
1222 qPos.add(priority);
1223
1224 Long count = null;
1225
1226 Iterator<Long> itr = q.list().iterator();
1227
1228 if (itr.hasNext()) {
1229 count = itr.next();
1230 }
1231
1232 if (count == null) {
1233 count = new Long(0);
1234 }
1235
1236 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1237 finderClassName, finderMethodName, finderParams,
1238 finderArgs, count);
1239
1240 return count.intValue();
1241 }
1242 catch (Exception e) {
1243 throw processException(e);
1244 }
1245 finally {
1246 closeSession(session);
1247 }
1248 }
1249 else {
1250 return ((Long)result).intValue();
1251 }
1252 }
1253
1254 public int countAll() throws SystemException {
1255 boolean finderClassNameCacheEnabled = SCProductScreenshotModelImpl.CACHE_ENABLED;
1256 String finderClassName = SCProductScreenshot.class.getName();
1257 String finderMethodName = "countAll";
1258 String[] finderParams = new String[] { };
1259 Object[] finderArgs = new Object[] { };
1260
1261 Object result = null;
1262
1263 if (finderClassNameCacheEnabled) {
1264 result = FinderCacheUtil.getResult(finderClassName,
1265 finderMethodName, finderParams, finderArgs, this);
1266 }
1267
1268 if (result == null) {
1269 Session session = null;
1270
1271 try {
1272 session = openSession();
1273
1274 Query q = session.createQuery(
1275 "SELECT COUNT(*) FROM com.liferay.portlet.softwarecatalog.model.SCProductScreenshot");
1276
1277 Long count = null;
1278
1279 Iterator<Long> itr = q.list().iterator();
1280
1281 if (itr.hasNext()) {
1282 count = itr.next();
1283 }
1284
1285 if (count == null) {
1286 count = new Long(0);
1287 }
1288
1289 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1290 finderClassName, finderMethodName, finderParams,
1291 finderArgs, count);
1292
1293 return count.intValue();
1294 }
1295 catch (Exception e) {
1296 throw processException(e);
1297 }
1298 finally {
1299 closeSession(session);
1300 }
1301 }
1302 else {
1303 return ((Long)result).intValue();
1304 }
1305 }
1306
1307 public void registerListener(ModelListener listener) {
1308 List<ModelListener> listeners = ListUtil.fromArray(_listeners);
1309
1310 listeners.add(listener);
1311
1312 _listeners = listeners.toArray(new ModelListener[listeners.size()]);
1313 }
1314
1315 public void unregisterListener(ModelListener listener) {
1316 List<ModelListener> listeners = ListUtil.fromArray(_listeners);
1317
1318 listeners.remove(listener);
1319
1320 _listeners = listeners.toArray(new ModelListener[listeners.size()]);
1321 }
1322
1323 public void afterPropertiesSet() {
1324 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1325 com.liferay.portal.util.PropsUtil.get(
1326 "value.object.listener.com.liferay.portlet.softwarecatalog.model.SCProductScreenshot")));
1327
1328 if (listenerClassNames.length > 0) {
1329 try {
1330 List<ModelListener> listeners = new ArrayList<ModelListener>();
1331
1332 for (String listenerClassName : listenerClassNames) {
1333 listeners.add((ModelListener)Class.forName(
1334 listenerClassName).newInstance());
1335 }
1336
1337 _listeners = listeners.toArray(new ModelListener[listeners.size()]);
1338 }
1339 catch (Exception e) {
1340 _log.error(e);
1341 }
1342 }
1343 }
1344
1345 private static Log _log = LogFactory.getLog(SCProductScreenshotPersistenceImpl.class);
1346 private ModelListener[] _listeners = new ModelListener[0];
1347}