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