1
22
23 package com.liferay.portlet.imagegallery.service.persistence;
24
25 import com.liferay.portal.SystemException;
26 import com.liferay.portal.kernel.bean.InitializingBean;
27 import com.liferay.portal.kernel.dao.orm.DynamicQuery;
28 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
29 import com.liferay.portal.kernel.dao.orm.Query;
30 import com.liferay.portal.kernel.dao.orm.QueryPos;
31 import com.liferay.portal.kernel.dao.orm.QueryUtil;
32 import com.liferay.portal.kernel.dao.orm.Session;
33 import com.liferay.portal.kernel.util.GetterUtil;
34 import com.liferay.portal.kernel.util.ListUtil;
35 import com.liferay.portal.kernel.util.OrderByComparator;
36 import com.liferay.portal.kernel.util.StringPool;
37 import com.liferay.portal.kernel.util.StringUtil;
38 import com.liferay.portal.kernel.util.Validator;
39 import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
40 import com.liferay.portal.model.ModelListener;
41 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
42
43 import com.liferay.portlet.imagegallery.NoSuchImageException;
44 import com.liferay.portlet.imagegallery.model.IGImage;
45 import com.liferay.portlet.imagegallery.model.impl.IGImageImpl;
46 import com.liferay.portlet.imagegallery.model.impl.IGImageModelImpl;
47
48 import org.apache.commons.logging.Log;
49 import org.apache.commons.logging.LogFactory;
50
51 import java.util.ArrayList;
52 import java.util.Collections;
53 import java.util.Iterator;
54 import java.util.List;
55
56
62 public class IGImagePersistenceImpl extends BasePersistenceImpl
63 implements IGImagePersistence, InitializingBean {
64 public IGImage create(long imageId) {
65 IGImage igImage = new IGImageImpl();
66
67 igImage.setNew(true);
68 igImage.setPrimaryKey(imageId);
69
70 String uuid = PortalUUIDUtil.generate();
71
72 igImage.setUuid(uuid);
73
74 return igImage;
75 }
76
77 public IGImage remove(long imageId)
78 throws NoSuchImageException, SystemException {
79 Session session = null;
80
81 try {
82 session = openSession();
83
84 IGImage igImage = (IGImage)session.get(IGImageImpl.class,
85 new Long(imageId));
86
87 if (igImage == null) {
88 if (_log.isWarnEnabled()) {
89 _log.warn("No IGImage exists with the primary key " +
90 imageId);
91 }
92
93 throw new NoSuchImageException(
94 "No IGImage exists with the primary key " + imageId);
95 }
96
97 return remove(igImage);
98 }
99 catch (NoSuchImageException nsee) {
100 throw nsee;
101 }
102 catch (Exception e) {
103 throw processException(e);
104 }
105 finally {
106 closeSession(session);
107 }
108 }
109
110 public IGImage remove(IGImage igImage) throws SystemException {
111 if (_listeners.length > 0) {
112 for (ModelListener listener : _listeners) {
113 listener.onBeforeRemove(igImage);
114 }
115 }
116
117 igImage = removeImpl(igImage);
118
119 if (_listeners.length > 0) {
120 for (ModelListener listener : _listeners) {
121 listener.onAfterRemove(igImage);
122 }
123 }
124
125 return igImage;
126 }
127
128 protected IGImage removeImpl(IGImage igImage) throws SystemException {
129 Session session = null;
130
131 try {
132 session = openSession();
133
134 session.delete(igImage);
135
136 session.flush();
137
138 return igImage;
139 }
140 catch (Exception e) {
141 throw processException(e);
142 }
143 finally {
144 closeSession(session);
145
146 FinderCacheUtil.clearCache(IGImage.class.getName());
147 }
148 }
149
150
153 public IGImage update(IGImage igImage) throws SystemException {
154 if (_log.isWarnEnabled()) {
155 _log.warn(
156 "Using the deprecated update(IGImage igImage) method. Use update(IGImage igImage, boolean merge) instead.");
157 }
158
159 return update(igImage, false);
160 }
161
162
175 public IGImage update(IGImage igImage, boolean merge)
176 throws SystemException {
177 boolean isNew = igImage.isNew();
178
179 if (_listeners.length > 0) {
180 for (ModelListener listener : _listeners) {
181 if (isNew) {
182 listener.onBeforeCreate(igImage);
183 }
184 else {
185 listener.onBeforeUpdate(igImage);
186 }
187 }
188 }
189
190 igImage = updateImpl(igImage, merge);
191
192 if (_listeners.length > 0) {
193 for (ModelListener listener : _listeners) {
194 if (isNew) {
195 listener.onAfterCreate(igImage);
196 }
197 else {
198 listener.onAfterUpdate(igImage);
199 }
200 }
201 }
202
203 return igImage;
204 }
205
206 public IGImage updateImpl(
207 com.liferay.portlet.imagegallery.model.IGImage igImage, boolean merge)
208 throws SystemException {
209 if (Validator.isNull(igImage.getUuid())) {
210 String uuid = PortalUUIDUtil.generate();
211
212 igImage.setUuid(uuid);
213 }
214
215 Session session = null;
216
217 try {
218 session = openSession();
219
220 if (merge) {
221 session.merge(igImage);
222 }
223 else {
224 if (igImage.isNew()) {
225 session.save(igImage);
226 }
227 }
228
229 session.flush();
230
231 igImage.setNew(false);
232
233 return igImage;
234 }
235 catch (Exception e) {
236 throw processException(e);
237 }
238 finally {
239 closeSession(session);
240
241 FinderCacheUtil.clearCache(IGImage.class.getName());
242 }
243 }
244
245 public IGImage findByPrimaryKey(long imageId)
246 throws NoSuchImageException, SystemException {
247 IGImage igImage = fetchByPrimaryKey(imageId);
248
249 if (igImage == null) {
250 if (_log.isWarnEnabled()) {
251 _log.warn("No IGImage exists with the primary key " + imageId);
252 }
253
254 throw new NoSuchImageException(
255 "No IGImage exists with the primary key " + imageId);
256 }
257
258 return igImage;
259 }
260
261 public IGImage fetchByPrimaryKey(long imageId) throws SystemException {
262 Session session = null;
263
264 try {
265 session = openSession();
266
267 return (IGImage)session.get(IGImageImpl.class, new Long(imageId));
268 }
269 catch (Exception e) {
270 throw processException(e);
271 }
272 finally {
273 closeSession(session);
274 }
275 }
276
277 public List<IGImage> findByUuid(String uuid) throws SystemException {
278 boolean finderClassNameCacheEnabled = IGImageModelImpl.CACHE_ENABLED;
279 String finderClassName = IGImage.class.getName();
280 String finderMethodName = "findByUuid";
281 String[] finderParams = new String[] { String.class.getName() };
282 Object[] finderArgs = new Object[] { uuid };
283
284 Object result = null;
285
286 if (finderClassNameCacheEnabled) {
287 result = FinderCacheUtil.getResult(finderClassName,
288 finderMethodName, finderParams, finderArgs, this);
289 }
290
291 if (result == null) {
292 Session session = null;
293
294 try {
295 session = openSession();
296
297 StringBuilder query = new StringBuilder();
298
299 query.append(
300 "FROM com.liferay.portlet.imagegallery.model.IGImage WHERE ");
301
302 if (uuid == null) {
303 query.append("uuid_ IS NULL");
304 }
305 else {
306 query.append("uuid_ = ?");
307 }
308
309 query.append(" ");
310
311 query.append("ORDER BY ");
312
313 query.append("imageId ASC");
314
315 Query q = session.createQuery(query.toString());
316
317 QueryPos qPos = QueryPos.getInstance(q);
318
319 if (uuid != null) {
320 qPos.add(uuid);
321 }
322
323 List<IGImage> list = q.list();
324
325 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
326 finderClassName, finderMethodName, finderParams,
327 finderArgs, list);
328
329 return list;
330 }
331 catch (Exception e) {
332 throw processException(e);
333 }
334 finally {
335 closeSession(session);
336 }
337 }
338 else {
339 return (List<IGImage>)result;
340 }
341 }
342
343 public List<IGImage> findByUuid(String uuid, int start, int end)
344 throws SystemException {
345 return findByUuid(uuid, start, end, null);
346 }
347
348 public List<IGImage> findByUuid(String uuid, int start, int end,
349 OrderByComparator obc) throws SystemException {
350 boolean finderClassNameCacheEnabled = IGImageModelImpl.CACHE_ENABLED;
351 String finderClassName = IGImage.class.getName();
352 String finderMethodName = "findByUuid";
353 String[] finderParams = new String[] {
354 String.class.getName(),
355
356 "java.lang.Integer", "java.lang.Integer",
357 "com.liferay.portal.kernel.util.OrderByComparator"
358 };
359 Object[] finderArgs = new Object[] {
360 uuid,
361
362 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
363 };
364
365 Object result = null;
366
367 if (finderClassNameCacheEnabled) {
368 result = FinderCacheUtil.getResult(finderClassName,
369 finderMethodName, finderParams, finderArgs, this);
370 }
371
372 if (result == null) {
373 Session session = null;
374
375 try {
376 session = openSession();
377
378 StringBuilder query = new StringBuilder();
379
380 query.append(
381 "FROM com.liferay.portlet.imagegallery.model.IGImage WHERE ");
382
383 if (uuid == null) {
384 query.append("uuid_ IS NULL");
385 }
386 else {
387 query.append("uuid_ = ?");
388 }
389
390 query.append(" ");
391
392 if (obc != null) {
393 query.append("ORDER BY ");
394 query.append(obc.getOrderBy());
395 }
396
397 else {
398 query.append("ORDER BY ");
399
400 query.append("imageId ASC");
401 }
402
403 Query q = session.createQuery(query.toString());
404
405 QueryPos qPos = QueryPos.getInstance(q);
406
407 if (uuid != null) {
408 qPos.add(uuid);
409 }
410
411 List<IGImage> list = (List<IGImage>)QueryUtil.list(q,
412 getDialect(), start, end);
413
414 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
415 finderClassName, finderMethodName, finderParams,
416 finderArgs, list);
417
418 return list;
419 }
420 catch (Exception e) {
421 throw processException(e);
422 }
423 finally {
424 closeSession(session);
425 }
426 }
427 else {
428 return (List<IGImage>)result;
429 }
430 }
431
432 public IGImage findByUuid_First(String uuid, OrderByComparator obc)
433 throws NoSuchImageException, SystemException {
434 List<IGImage> list = findByUuid(uuid, 0, 1, obc);
435
436 if (list.size() == 0) {
437 StringBuilder msg = new StringBuilder();
438
439 msg.append("No IGImage exists with the key {");
440
441 msg.append("uuid=" + uuid);
442
443 msg.append(StringPool.CLOSE_CURLY_BRACE);
444
445 throw new NoSuchImageException(msg.toString());
446 }
447 else {
448 return list.get(0);
449 }
450 }
451
452 public IGImage findByUuid_Last(String uuid, OrderByComparator obc)
453 throws NoSuchImageException, SystemException {
454 int count = countByUuid(uuid);
455
456 List<IGImage> list = findByUuid(uuid, count - 1, count, obc);
457
458 if (list.size() == 0) {
459 StringBuilder msg = new StringBuilder();
460
461 msg.append("No IGImage exists with the key {");
462
463 msg.append("uuid=" + uuid);
464
465 msg.append(StringPool.CLOSE_CURLY_BRACE);
466
467 throw new NoSuchImageException(msg.toString());
468 }
469 else {
470 return list.get(0);
471 }
472 }
473
474 public IGImage[] findByUuid_PrevAndNext(long imageId, String uuid,
475 OrderByComparator obc) throws NoSuchImageException, SystemException {
476 IGImage igImage = findByPrimaryKey(imageId);
477
478 int count = countByUuid(uuid);
479
480 Session session = null;
481
482 try {
483 session = openSession();
484
485 StringBuilder query = new StringBuilder();
486
487 query.append(
488 "FROM com.liferay.portlet.imagegallery.model.IGImage WHERE ");
489
490 if (uuid == null) {
491 query.append("uuid_ IS NULL");
492 }
493 else {
494 query.append("uuid_ = ?");
495 }
496
497 query.append(" ");
498
499 if (obc != null) {
500 query.append("ORDER BY ");
501 query.append(obc.getOrderBy());
502 }
503
504 else {
505 query.append("ORDER BY ");
506
507 query.append("imageId ASC");
508 }
509
510 Query q = session.createQuery(query.toString());
511
512 QueryPos qPos = QueryPos.getInstance(q);
513
514 if (uuid != null) {
515 qPos.add(uuid);
516 }
517
518 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, igImage);
519
520 IGImage[] array = new IGImageImpl[3];
521
522 array[0] = (IGImage)objArray[0];
523 array[1] = (IGImage)objArray[1];
524 array[2] = (IGImage)objArray[2];
525
526 return array;
527 }
528 catch (Exception e) {
529 throw processException(e);
530 }
531 finally {
532 closeSession(session);
533 }
534 }
535
536 public List<IGImage> findByFolderId(long folderId)
537 throws SystemException {
538 boolean finderClassNameCacheEnabled = IGImageModelImpl.CACHE_ENABLED;
539 String finderClassName = IGImage.class.getName();
540 String finderMethodName = "findByFolderId";
541 String[] finderParams = new String[] { Long.class.getName() };
542 Object[] finderArgs = new Object[] { new Long(folderId) };
543
544 Object result = null;
545
546 if (finderClassNameCacheEnabled) {
547 result = FinderCacheUtil.getResult(finderClassName,
548 finderMethodName, finderParams, finderArgs, this);
549 }
550
551 if (result == null) {
552 Session session = null;
553
554 try {
555 session = openSession();
556
557 StringBuilder query = new StringBuilder();
558
559 query.append(
560 "FROM com.liferay.portlet.imagegallery.model.IGImage WHERE ");
561
562 query.append("folderId = ?");
563
564 query.append(" ");
565
566 query.append("ORDER BY ");
567
568 query.append("imageId ASC");
569
570 Query q = session.createQuery(query.toString());
571
572 QueryPos qPos = QueryPos.getInstance(q);
573
574 qPos.add(folderId);
575
576 List<IGImage> list = q.list();
577
578 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
579 finderClassName, finderMethodName, finderParams,
580 finderArgs, list);
581
582 return list;
583 }
584 catch (Exception e) {
585 throw processException(e);
586 }
587 finally {
588 closeSession(session);
589 }
590 }
591 else {
592 return (List<IGImage>)result;
593 }
594 }
595
596 public List<IGImage> findByFolderId(long folderId, int start, int end)
597 throws SystemException {
598 return findByFolderId(folderId, start, end, null);
599 }
600
601 public List<IGImage> findByFolderId(long folderId, int start, int end,
602 OrderByComparator obc) throws SystemException {
603 boolean finderClassNameCacheEnabled = IGImageModelImpl.CACHE_ENABLED;
604 String finderClassName = IGImage.class.getName();
605 String finderMethodName = "findByFolderId";
606 String[] finderParams = new String[] {
607 Long.class.getName(),
608
609 "java.lang.Integer", "java.lang.Integer",
610 "com.liferay.portal.kernel.util.OrderByComparator"
611 };
612 Object[] finderArgs = new Object[] {
613 new Long(folderId),
614
615 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
616 };
617
618 Object result = null;
619
620 if (finderClassNameCacheEnabled) {
621 result = FinderCacheUtil.getResult(finderClassName,
622 finderMethodName, finderParams, finderArgs, this);
623 }
624
625 if (result == null) {
626 Session session = null;
627
628 try {
629 session = openSession();
630
631 StringBuilder query = new StringBuilder();
632
633 query.append(
634 "FROM com.liferay.portlet.imagegallery.model.IGImage WHERE ");
635
636 query.append("folderId = ?");
637
638 query.append(" ");
639
640 if (obc != null) {
641 query.append("ORDER BY ");
642 query.append(obc.getOrderBy());
643 }
644
645 else {
646 query.append("ORDER BY ");
647
648 query.append("imageId ASC");
649 }
650
651 Query q = session.createQuery(query.toString());
652
653 QueryPos qPos = QueryPos.getInstance(q);
654
655 qPos.add(folderId);
656
657 List<IGImage> list = (List<IGImage>)QueryUtil.list(q,
658 getDialect(), start, end);
659
660 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
661 finderClassName, finderMethodName, finderParams,
662 finderArgs, list);
663
664 return list;
665 }
666 catch (Exception e) {
667 throw processException(e);
668 }
669 finally {
670 closeSession(session);
671 }
672 }
673 else {
674 return (List<IGImage>)result;
675 }
676 }
677
678 public IGImage findByFolderId_First(long folderId, OrderByComparator obc)
679 throws NoSuchImageException, SystemException {
680 List<IGImage> list = findByFolderId(folderId, 0, 1, obc);
681
682 if (list.size() == 0) {
683 StringBuilder msg = new StringBuilder();
684
685 msg.append("No IGImage exists with the key {");
686
687 msg.append("folderId=" + folderId);
688
689 msg.append(StringPool.CLOSE_CURLY_BRACE);
690
691 throw new NoSuchImageException(msg.toString());
692 }
693 else {
694 return list.get(0);
695 }
696 }
697
698 public IGImage findByFolderId_Last(long folderId, OrderByComparator obc)
699 throws NoSuchImageException, SystemException {
700 int count = countByFolderId(folderId);
701
702 List<IGImage> list = findByFolderId(folderId, count - 1, count, obc);
703
704 if (list.size() == 0) {
705 StringBuilder msg = new StringBuilder();
706
707 msg.append("No IGImage exists with the key {");
708
709 msg.append("folderId=" + folderId);
710
711 msg.append(StringPool.CLOSE_CURLY_BRACE);
712
713 throw new NoSuchImageException(msg.toString());
714 }
715 else {
716 return list.get(0);
717 }
718 }
719
720 public IGImage[] findByFolderId_PrevAndNext(long imageId, long folderId,
721 OrderByComparator obc) throws NoSuchImageException, SystemException {
722 IGImage igImage = findByPrimaryKey(imageId);
723
724 int count = countByFolderId(folderId);
725
726 Session session = null;
727
728 try {
729 session = openSession();
730
731 StringBuilder query = new StringBuilder();
732
733 query.append(
734 "FROM com.liferay.portlet.imagegallery.model.IGImage WHERE ");
735
736 query.append("folderId = ?");
737
738 query.append(" ");
739
740 if (obc != null) {
741 query.append("ORDER BY ");
742 query.append(obc.getOrderBy());
743 }
744
745 else {
746 query.append("ORDER BY ");
747
748 query.append("imageId ASC");
749 }
750
751 Query q = session.createQuery(query.toString());
752
753 QueryPos qPos = QueryPos.getInstance(q);
754
755 qPos.add(folderId);
756
757 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, igImage);
758
759 IGImage[] array = new IGImageImpl[3];
760
761 array[0] = (IGImage)objArray[0];
762 array[1] = (IGImage)objArray[1];
763 array[2] = (IGImage)objArray[2];
764
765 return array;
766 }
767 catch (Exception e) {
768 throw processException(e);
769 }
770 finally {
771 closeSession(session);
772 }
773 }
774
775 public IGImage findBySmallImageId(long smallImageId)
776 throws NoSuchImageException, SystemException {
777 IGImage igImage = fetchBySmallImageId(smallImageId);
778
779 if (igImage == null) {
780 StringBuilder msg = new StringBuilder();
781
782 msg.append("No IGImage exists with the key {");
783
784 msg.append("smallImageId=" + smallImageId);
785
786 msg.append(StringPool.CLOSE_CURLY_BRACE);
787
788 if (_log.isWarnEnabled()) {
789 _log.warn(msg.toString());
790 }
791
792 throw new NoSuchImageException(msg.toString());
793 }
794
795 return igImage;
796 }
797
798 public IGImage fetchBySmallImageId(long smallImageId)
799 throws SystemException {
800 boolean finderClassNameCacheEnabled = IGImageModelImpl.CACHE_ENABLED;
801 String finderClassName = IGImage.class.getName();
802 String finderMethodName = "fetchBySmallImageId";
803 String[] finderParams = new String[] { Long.class.getName() };
804 Object[] finderArgs = new Object[] { new Long(smallImageId) };
805
806 Object result = null;
807
808 if (finderClassNameCacheEnabled) {
809 result = FinderCacheUtil.getResult(finderClassName,
810 finderMethodName, finderParams, finderArgs, this);
811 }
812
813 if (result == null) {
814 Session session = null;
815
816 try {
817 session = openSession();
818
819 StringBuilder query = new StringBuilder();
820
821 query.append(
822 "FROM com.liferay.portlet.imagegallery.model.IGImage WHERE ");
823
824 query.append("smallImageId = ?");
825
826 query.append(" ");
827
828 query.append("ORDER BY ");
829
830 query.append("imageId ASC");
831
832 Query q = session.createQuery(query.toString());
833
834 QueryPos qPos = QueryPos.getInstance(q);
835
836 qPos.add(smallImageId);
837
838 List<IGImage> list = q.list();
839
840 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
841 finderClassName, finderMethodName, finderParams,
842 finderArgs, list);
843
844 if (list.size() == 0) {
845 return null;
846 }
847 else {
848 return list.get(0);
849 }
850 }
851 catch (Exception e) {
852 throw processException(e);
853 }
854 finally {
855 closeSession(session);
856 }
857 }
858 else {
859 List<IGImage> list = (List<IGImage>)result;
860
861 if (list.size() == 0) {
862 return null;
863 }
864 else {
865 return list.get(0);
866 }
867 }
868 }
869
870 public IGImage findByLargeImageId(long largeImageId)
871 throws NoSuchImageException, SystemException {
872 IGImage igImage = fetchByLargeImageId(largeImageId);
873
874 if (igImage == null) {
875 StringBuilder msg = new StringBuilder();
876
877 msg.append("No IGImage exists with the key {");
878
879 msg.append("largeImageId=" + largeImageId);
880
881 msg.append(StringPool.CLOSE_CURLY_BRACE);
882
883 if (_log.isWarnEnabled()) {
884 _log.warn(msg.toString());
885 }
886
887 throw new NoSuchImageException(msg.toString());
888 }
889
890 return igImage;
891 }
892
893 public IGImage fetchByLargeImageId(long largeImageId)
894 throws SystemException {
895 boolean finderClassNameCacheEnabled = IGImageModelImpl.CACHE_ENABLED;
896 String finderClassName = IGImage.class.getName();
897 String finderMethodName = "fetchByLargeImageId";
898 String[] finderParams = new String[] { Long.class.getName() };
899 Object[] finderArgs = new Object[] { new Long(largeImageId) };
900
901 Object result = null;
902
903 if (finderClassNameCacheEnabled) {
904 result = FinderCacheUtil.getResult(finderClassName,
905 finderMethodName, finderParams, finderArgs, this);
906 }
907
908 if (result == null) {
909 Session session = null;
910
911 try {
912 session = openSession();
913
914 StringBuilder query = new StringBuilder();
915
916 query.append(
917 "FROM com.liferay.portlet.imagegallery.model.IGImage WHERE ");
918
919 query.append("largeImageId = ?");
920
921 query.append(" ");
922
923 query.append("ORDER BY ");
924
925 query.append("imageId ASC");
926
927 Query q = session.createQuery(query.toString());
928
929 QueryPos qPos = QueryPos.getInstance(q);
930
931 qPos.add(largeImageId);
932
933 List<IGImage> list = q.list();
934
935 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
936 finderClassName, finderMethodName, finderParams,
937 finderArgs, list);
938
939 if (list.size() == 0) {
940 return null;
941 }
942 else {
943 return list.get(0);
944 }
945 }
946 catch (Exception e) {
947 throw processException(e);
948 }
949 finally {
950 closeSession(session);
951 }
952 }
953 else {
954 List<IGImage> list = (List<IGImage>)result;
955
956 if (list.size() == 0) {
957 return null;
958 }
959 else {
960 return list.get(0);
961 }
962 }
963 }
964
965 public IGImage findByCustom1ImageId(long custom1ImageId)
966 throws NoSuchImageException, SystemException {
967 IGImage igImage = fetchByCustom1ImageId(custom1ImageId);
968
969 if (igImage == null) {
970 StringBuilder msg = new StringBuilder();
971
972 msg.append("No IGImage exists with the key {");
973
974 msg.append("custom1ImageId=" + custom1ImageId);
975
976 msg.append(StringPool.CLOSE_CURLY_BRACE);
977
978 if (_log.isWarnEnabled()) {
979 _log.warn(msg.toString());
980 }
981
982 throw new NoSuchImageException(msg.toString());
983 }
984
985 return igImage;
986 }
987
988 public IGImage fetchByCustom1ImageId(long custom1ImageId)
989 throws SystemException {
990 boolean finderClassNameCacheEnabled = IGImageModelImpl.CACHE_ENABLED;
991 String finderClassName = IGImage.class.getName();
992 String finderMethodName = "fetchByCustom1ImageId";
993 String[] finderParams = new String[] { Long.class.getName() };
994 Object[] finderArgs = new Object[] { new Long(custom1ImageId) };
995
996 Object result = null;
997
998 if (finderClassNameCacheEnabled) {
999 result = FinderCacheUtil.getResult(finderClassName,
1000 finderMethodName, finderParams, finderArgs, this);
1001 }
1002
1003 if (result == null) {
1004 Session session = null;
1005
1006 try {
1007 session = openSession();
1008
1009 StringBuilder query = new StringBuilder();
1010
1011 query.append(
1012 "FROM com.liferay.portlet.imagegallery.model.IGImage WHERE ");
1013
1014 query.append("custom1ImageId = ?");
1015
1016 query.append(" ");
1017
1018 query.append("ORDER BY ");
1019
1020 query.append("imageId ASC");
1021
1022 Query q = session.createQuery(query.toString());
1023
1024 QueryPos qPos = QueryPos.getInstance(q);
1025
1026 qPos.add(custom1ImageId);
1027
1028 List<IGImage> list = q.list();
1029
1030 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1031 finderClassName, finderMethodName, finderParams,
1032 finderArgs, list);
1033
1034 if (list.size() == 0) {
1035 return null;
1036 }
1037 else {
1038 return list.get(0);
1039 }
1040 }
1041 catch (Exception e) {
1042 throw processException(e);
1043 }
1044 finally {
1045 closeSession(session);
1046 }
1047 }
1048 else {
1049 List<IGImage> list = (List<IGImage>)result;
1050
1051 if (list.size() == 0) {
1052 return null;
1053 }
1054 else {
1055 return list.get(0);
1056 }
1057 }
1058 }
1059
1060 public IGImage findByCustom2ImageId(long custom2ImageId)
1061 throws NoSuchImageException, SystemException {
1062 IGImage igImage = fetchByCustom2ImageId(custom2ImageId);
1063
1064 if (igImage == null) {
1065 StringBuilder msg = new StringBuilder();
1066
1067 msg.append("No IGImage exists with the key {");
1068
1069 msg.append("custom2ImageId=" + custom2ImageId);
1070
1071 msg.append(StringPool.CLOSE_CURLY_BRACE);
1072
1073 if (_log.isWarnEnabled()) {
1074 _log.warn(msg.toString());
1075 }
1076
1077 throw new NoSuchImageException(msg.toString());
1078 }
1079
1080 return igImage;
1081 }
1082
1083 public IGImage fetchByCustom2ImageId(long custom2ImageId)
1084 throws SystemException {
1085 boolean finderClassNameCacheEnabled = IGImageModelImpl.CACHE_ENABLED;
1086 String finderClassName = IGImage.class.getName();
1087 String finderMethodName = "fetchByCustom2ImageId";
1088 String[] finderParams = new String[] { Long.class.getName() };
1089 Object[] finderArgs = new Object[] { new Long(custom2ImageId) };
1090
1091 Object result = null;
1092
1093 if (finderClassNameCacheEnabled) {
1094 result = FinderCacheUtil.getResult(finderClassName,
1095 finderMethodName, finderParams, finderArgs, this);
1096 }
1097
1098 if (result == null) {
1099 Session session = null;
1100
1101 try {
1102 session = openSession();
1103
1104 StringBuilder query = new StringBuilder();
1105
1106 query.append(
1107 "FROM com.liferay.portlet.imagegallery.model.IGImage WHERE ");
1108
1109 query.append("custom2ImageId = ?");
1110
1111 query.append(" ");
1112
1113 query.append("ORDER BY ");
1114
1115 query.append("imageId ASC");
1116
1117 Query q = session.createQuery(query.toString());
1118
1119 QueryPos qPos = QueryPos.getInstance(q);
1120
1121 qPos.add(custom2ImageId);
1122
1123 List<IGImage> list = q.list();
1124
1125 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1126 finderClassName, finderMethodName, finderParams,
1127 finderArgs, list);
1128
1129 if (list.size() == 0) {
1130 return null;
1131 }
1132 else {
1133 return list.get(0);
1134 }
1135 }
1136 catch (Exception e) {
1137 throw processException(e);
1138 }
1139 finally {
1140 closeSession(session);
1141 }
1142 }
1143 else {
1144 List<IGImage> list = (List<IGImage>)result;
1145
1146 if (list.size() == 0) {
1147 return null;
1148 }
1149 else {
1150 return list.get(0);
1151 }
1152 }
1153 }
1154
1155 public List<IGImage> findByF_N(long folderId, String name)
1156 throws SystemException {
1157 boolean finderClassNameCacheEnabled = IGImageModelImpl.CACHE_ENABLED;
1158 String finderClassName = IGImage.class.getName();
1159 String finderMethodName = "findByF_N";
1160 String[] finderParams = new String[] {
1161 Long.class.getName(), String.class.getName()
1162 };
1163 Object[] finderArgs = new Object[] { new Long(folderId), name };
1164
1165 Object result = null;
1166
1167 if (finderClassNameCacheEnabled) {
1168 result = FinderCacheUtil.getResult(finderClassName,
1169 finderMethodName, finderParams, finderArgs, this);
1170 }
1171
1172 if (result == null) {
1173 Session session = null;
1174
1175 try {
1176 session = openSession();
1177
1178 StringBuilder query = new StringBuilder();
1179
1180 query.append(
1181 "FROM com.liferay.portlet.imagegallery.model.IGImage WHERE ");
1182
1183 query.append("folderId = ?");
1184
1185 query.append(" AND ");
1186
1187 if (name == null) {
1188 query.append("name IS NULL");
1189 }
1190 else {
1191 query.append("name = ?");
1192 }
1193
1194 query.append(" ");
1195
1196 query.append("ORDER BY ");
1197
1198 query.append("imageId ASC");
1199
1200 Query q = session.createQuery(query.toString());
1201
1202 QueryPos qPos = QueryPos.getInstance(q);
1203
1204 qPos.add(folderId);
1205
1206 if (name != null) {
1207 qPos.add(name);
1208 }
1209
1210 List<IGImage> list = q.list();
1211
1212 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1213 finderClassName, finderMethodName, finderParams,
1214 finderArgs, list);
1215
1216 return list;
1217 }
1218 catch (Exception e) {
1219 throw processException(e);
1220 }
1221 finally {
1222 closeSession(session);
1223 }
1224 }
1225 else {
1226 return (List<IGImage>)result;
1227 }
1228 }
1229
1230 public List<IGImage> findByF_N(long folderId, String name, int start,
1231 int end) throws SystemException {
1232 return findByF_N(folderId, name, start, end, null);
1233 }
1234
1235 public List<IGImage> findByF_N(long folderId, String name, int start,
1236 int end, OrderByComparator obc) throws SystemException {
1237 boolean finderClassNameCacheEnabled = IGImageModelImpl.CACHE_ENABLED;
1238 String finderClassName = IGImage.class.getName();
1239 String finderMethodName = "findByF_N";
1240 String[] finderParams = new String[] {
1241 Long.class.getName(), String.class.getName(),
1242
1243 "java.lang.Integer", "java.lang.Integer",
1244 "com.liferay.portal.kernel.util.OrderByComparator"
1245 };
1246 Object[] finderArgs = new Object[] {
1247 new Long(folderId),
1248
1249 name,
1250
1251 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1252 };
1253
1254 Object result = null;
1255
1256 if (finderClassNameCacheEnabled) {
1257 result = FinderCacheUtil.getResult(finderClassName,
1258 finderMethodName, finderParams, finderArgs, this);
1259 }
1260
1261 if (result == null) {
1262 Session session = null;
1263
1264 try {
1265 session = openSession();
1266
1267 StringBuilder query = new StringBuilder();
1268
1269 query.append(
1270 "FROM com.liferay.portlet.imagegallery.model.IGImage WHERE ");
1271
1272 query.append("folderId = ?");
1273
1274 query.append(" AND ");
1275
1276 if (name == null) {
1277 query.append("name IS NULL");
1278 }
1279 else {
1280 query.append("name = ?");
1281 }
1282
1283 query.append(" ");
1284
1285 if (obc != null) {
1286 query.append("ORDER BY ");
1287 query.append(obc.getOrderBy());
1288 }
1289
1290 else {
1291 query.append("ORDER BY ");
1292
1293 query.append("imageId ASC");
1294 }
1295
1296 Query q = session.createQuery(query.toString());
1297
1298 QueryPos qPos = QueryPos.getInstance(q);
1299
1300 qPos.add(folderId);
1301
1302 if (name != null) {
1303 qPos.add(name);
1304 }
1305
1306 List<IGImage> list = (List<IGImage>)QueryUtil.list(q,
1307 getDialect(), start, end);
1308
1309 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1310 finderClassName, finderMethodName, finderParams,
1311 finderArgs, list);
1312
1313 return list;
1314 }
1315 catch (Exception e) {
1316 throw processException(e);
1317 }
1318 finally {
1319 closeSession(session);
1320 }
1321 }
1322 else {
1323 return (List<IGImage>)result;
1324 }
1325 }
1326
1327 public IGImage findByF_N_First(long folderId, String name,
1328 OrderByComparator obc) throws NoSuchImageException, SystemException {
1329 List<IGImage> list = findByF_N(folderId, name, 0, 1, obc);
1330
1331 if (list.size() == 0) {
1332 StringBuilder msg = new StringBuilder();
1333
1334 msg.append("No IGImage exists with the key {");
1335
1336 msg.append("folderId=" + folderId);
1337
1338 msg.append(", ");
1339 msg.append("name=" + name);
1340
1341 msg.append(StringPool.CLOSE_CURLY_BRACE);
1342
1343 throw new NoSuchImageException(msg.toString());
1344 }
1345 else {
1346 return list.get(0);
1347 }
1348 }
1349
1350 public IGImage findByF_N_Last(long folderId, String name,
1351 OrderByComparator obc) throws NoSuchImageException, SystemException {
1352 int count = countByF_N(folderId, name);
1353
1354 List<IGImage> list = findByF_N(folderId, name, count - 1, count, obc);
1355
1356 if (list.size() == 0) {
1357 StringBuilder msg = new StringBuilder();
1358
1359 msg.append("No IGImage exists with the key {");
1360
1361 msg.append("folderId=" + folderId);
1362
1363 msg.append(", ");
1364 msg.append("name=" + name);
1365
1366 msg.append(StringPool.CLOSE_CURLY_BRACE);
1367
1368 throw new NoSuchImageException(msg.toString());
1369 }
1370 else {
1371 return list.get(0);
1372 }
1373 }
1374
1375 public IGImage[] findByF_N_PrevAndNext(long imageId, long folderId,
1376 String name, OrderByComparator obc)
1377 throws NoSuchImageException, SystemException {
1378 IGImage igImage = findByPrimaryKey(imageId);
1379
1380 int count = countByF_N(folderId, name);
1381
1382 Session session = null;
1383
1384 try {
1385 session = openSession();
1386
1387 StringBuilder query = new StringBuilder();
1388
1389 query.append(
1390 "FROM com.liferay.portlet.imagegallery.model.IGImage WHERE ");
1391
1392 query.append("folderId = ?");
1393
1394 query.append(" AND ");
1395
1396 if (name == null) {
1397 query.append("name IS NULL");
1398 }
1399 else {
1400 query.append("name = ?");
1401 }
1402
1403 query.append(" ");
1404
1405 if (obc != null) {
1406 query.append("ORDER BY ");
1407 query.append(obc.getOrderBy());
1408 }
1409
1410 else {
1411 query.append("ORDER BY ");
1412
1413 query.append("imageId ASC");
1414 }
1415
1416 Query q = session.createQuery(query.toString());
1417
1418 QueryPos qPos = QueryPos.getInstance(q);
1419
1420 qPos.add(folderId);
1421
1422 if (name != null) {
1423 qPos.add(name);
1424 }
1425
1426 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, igImage);
1427
1428 IGImage[] array = new IGImageImpl[3];
1429
1430 array[0] = (IGImage)objArray[0];
1431 array[1] = (IGImage)objArray[1];
1432 array[2] = (IGImage)objArray[2];
1433
1434 return array;
1435 }
1436 catch (Exception e) {
1437 throw processException(e);
1438 }
1439 finally {
1440 closeSession(session);
1441 }
1442 }
1443
1444 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
1445 throws SystemException {
1446 Session session = null;
1447
1448 try {
1449 session = openSession();
1450
1451 dynamicQuery.compile(session);
1452
1453 return dynamicQuery.list();
1454 }
1455 catch (Exception e) {
1456 throw processException(e);
1457 }
1458 finally {
1459 closeSession(session);
1460 }
1461 }
1462
1463 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
1464 int start, int end) throws SystemException {
1465 Session session = null;
1466
1467 try {
1468 session = openSession();
1469
1470 dynamicQuery.setLimit(start, end);
1471
1472 dynamicQuery.compile(session);
1473
1474 return dynamicQuery.list();
1475 }
1476 catch (Exception e) {
1477 throw processException(e);
1478 }
1479 finally {
1480 closeSession(session);
1481 }
1482 }
1483
1484 public List<IGImage> findAll() throws SystemException {
1485 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1486 }
1487
1488 public List<IGImage> findAll(int start, int end) throws SystemException {
1489 return findAll(start, end, null);
1490 }
1491
1492 public List<IGImage> findAll(int start, int end, OrderByComparator obc)
1493 throws SystemException {
1494 boolean finderClassNameCacheEnabled = IGImageModelImpl.CACHE_ENABLED;
1495 String finderClassName = IGImage.class.getName();
1496 String finderMethodName = "findAll";
1497 String[] finderParams = new String[] {
1498 "java.lang.Integer", "java.lang.Integer",
1499 "com.liferay.portal.kernel.util.OrderByComparator"
1500 };
1501 Object[] finderArgs = new Object[] {
1502 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1503 };
1504
1505 Object result = null;
1506
1507 if (finderClassNameCacheEnabled) {
1508 result = FinderCacheUtil.getResult(finderClassName,
1509 finderMethodName, finderParams, finderArgs, this);
1510 }
1511
1512 if (result == null) {
1513 Session session = null;
1514
1515 try {
1516 session = openSession();
1517
1518 StringBuilder query = new StringBuilder();
1519
1520 query.append(
1521 "FROM com.liferay.portlet.imagegallery.model.IGImage ");
1522
1523 if (obc != null) {
1524 query.append("ORDER BY ");
1525 query.append(obc.getOrderBy());
1526 }
1527
1528 else {
1529 query.append("ORDER BY ");
1530
1531 query.append("imageId ASC");
1532 }
1533
1534 Query q = session.createQuery(query.toString());
1535
1536 List<IGImage> list = (List<IGImage>)QueryUtil.list(q,
1537 getDialect(), start, end);
1538
1539 if (obc == null) {
1540 Collections.sort(list);
1541 }
1542
1543 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1544 finderClassName, finderMethodName, finderParams,
1545 finderArgs, list);
1546
1547 return list;
1548 }
1549 catch (Exception e) {
1550 throw processException(e);
1551 }
1552 finally {
1553 closeSession(session);
1554 }
1555 }
1556 else {
1557 return (List<IGImage>)result;
1558 }
1559 }
1560
1561 public void removeByUuid(String uuid) throws SystemException {
1562 for (IGImage igImage : findByUuid(uuid)) {
1563 remove(igImage);
1564 }
1565 }
1566
1567 public void removeByFolderId(long folderId) throws SystemException {
1568 for (IGImage igImage : findByFolderId(folderId)) {
1569 remove(igImage);
1570 }
1571 }
1572
1573 public void removeBySmallImageId(long smallImageId)
1574 throws NoSuchImageException, SystemException {
1575 IGImage igImage = findBySmallImageId(smallImageId);
1576
1577 remove(igImage);
1578 }
1579
1580 public void removeByLargeImageId(long largeImageId)
1581 throws NoSuchImageException, SystemException {
1582 IGImage igImage = findByLargeImageId(largeImageId);
1583
1584 remove(igImage);
1585 }
1586
1587 public void removeByCustom1ImageId(long custom1ImageId)
1588 throws NoSuchImageException, SystemException {
1589 IGImage igImage = findByCustom1ImageId(custom1ImageId);
1590
1591 remove(igImage);
1592 }
1593
1594 public void removeByCustom2ImageId(long custom2ImageId)
1595 throws NoSuchImageException, SystemException {
1596 IGImage igImage = findByCustom2ImageId(custom2ImageId);
1597
1598 remove(igImage);
1599 }
1600
1601 public void removeByF_N(long folderId, String name)
1602 throws SystemException {
1603 for (IGImage igImage : findByF_N(folderId, name)) {
1604 remove(igImage);
1605 }
1606 }
1607
1608 public void removeAll() throws SystemException {
1609 for (IGImage igImage : findAll()) {
1610 remove(igImage);
1611 }
1612 }
1613
1614 public int countByUuid(String uuid) throws SystemException {
1615 boolean finderClassNameCacheEnabled = IGImageModelImpl.CACHE_ENABLED;
1616 String finderClassName = IGImage.class.getName();
1617 String finderMethodName = "countByUuid";
1618 String[] finderParams = new String[] { String.class.getName() };
1619 Object[] finderArgs = new Object[] { uuid };
1620
1621 Object result = null;
1622
1623 if (finderClassNameCacheEnabled) {
1624 result = FinderCacheUtil.getResult(finderClassName,
1625 finderMethodName, finderParams, finderArgs, this);
1626 }
1627
1628 if (result == null) {
1629 Session session = null;
1630
1631 try {
1632 session = openSession();
1633
1634 StringBuilder query = new StringBuilder();
1635
1636 query.append("SELECT COUNT(*) ");
1637 query.append(
1638 "FROM com.liferay.portlet.imagegallery.model.IGImage WHERE ");
1639
1640 if (uuid == null) {
1641 query.append("uuid_ IS NULL");
1642 }
1643 else {
1644 query.append("uuid_ = ?");
1645 }
1646
1647 query.append(" ");
1648
1649 Query q = session.createQuery(query.toString());
1650
1651 QueryPos qPos = QueryPos.getInstance(q);
1652
1653 if (uuid != null) {
1654 qPos.add(uuid);
1655 }
1656
1657 Long count = null;
1658
1659 Iterator<Long> itr = q.list().iterator();
1660
1661 if (itr.hasNext()) {
1662 count = itr.next();
1663 }
1664
1665 if (count == null) {
1666 count = new Long(0);
1667 }
1668
1669 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1670 finderClassName, finderMethodName, finderParams,
1671 finderArgs, count);
1672
1673 return count.intValue();
1674 }
1675 catch (Exception e) {
1676 throw processException(e);
1677 }
1678 finally {
1679 closeSession(session);
1680 }
1681 }
1682 else {
1683 return ((Long)result).intValue();
1684 }
1685 }
1686
1687 public int countByFolderId(long folderId) throws SystemException {
1688 boolean finderClassNameCacheEnabled = IGImageModelImpl.CACHE_ENABLED;
1689 String finderClassName = IGImage.class.getName();
1690 String finderMethodName = "countByFolderId";
1691 String[] finderParams = new String[] { Long.class.getName() };
1692 Object[] finderArgs = new Object[] { new Long(folderId) };
1693
1694 Object result = null;
1695
1696 if (finderClassNameCacheEnabled) {
1697 result = FinderCacheUtil.getResult(finderClassName,
1698 finderMethodName, finderParams, finderArgs, this);
1699 }
1700
1701 if (result == null) {
1702 Session session = null;
1703
1704 try {
1705 session = openSession();
1706
1707 StringBuilder query = new StringBuilder();
1708
1709 query.append("SELECT COUNT(*) ");
1710 query.append(
1711 "FROM com.liferay.portlet.imagegallery.model.IGImage WHERE ");
1712
1713 query.append("folderId = ?");
1714
1715 query.append(" ");
1716
1717 Query q = session.createQuery(query.toString());
1718
1719 QueryPos qPos = QueryPos.getInstance(q);
1720
1721 qPos.add(folderId);
1722
1723 Long count = null;
1724
1725 Iterator<Long> itr = q.list().iterator();
1726
1727 if (itr.hasNext()) {
1728 count = itr.next();
1729 }
1730
1731 if (count == null) {
1732 count = new Long(0);
1733 }
1734
1735 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1736 finderClassName, finderMethodName, finderParams,
1737 finderArgs, count);
1738
1739 return count.intValue();
1740 }
1741 catch (Exception e) {
1742 throw processException(e);
1743 }
1744 finally {
1745 closeSession(session);
1746 }
1747 }
1748 else {
1749 return ((Long)result).intValue();
1750 }
1751 }
1752
1753 public int countBySmallImageId(long smallImageId) throws SystemException {
1754 boolean finderClassNameCacheEnabled = IGImageModelImpl.CACHE_ENABLED;
1755 String finderClassName = IGImage.class.getName();
1756 String finderMethodName = "countBySmallImageId";
1757 String[] finderParams = new String[] { Long.class.getName() };
1758 Object[] finderArgs = new Object[] { new Long(smallImageId) };
1759
1760 Object result = null;
1761
1762 if (finderClassNameCacheEnabled) {
1763 result = FinderCacheUtil.getResult(finderClassName,
1764 finderMethodName, finderParams, finderArgs, this);
1765 }
1766
1767 if (result == null) {
1768 Session session = null;
1769
1770 try {
1771 session = openSession();
1772
1773 StringBuilder query = new StringBuilder();
1774
1775 query.append("SELECT COUNT(*) ");
1776 query.append(
1777 "FROM com.liferay.portlet.imagegallery.model.IGImage WHERE ");
1778
1779 query.append("smallImageId = ?");
1780
1781 query.append(" ");
1782
1783 Query q = session.createQuery(query.toString());
1784
1785 QueryPos qPos = QueryPos.getInstance(q);
1786
1787 qPos.add(smallImageId);
1788
1789 Long count = null;
1790
1791 Iterator<Long> itr = q.list().iterator();
1792
1793 if (itr.hasNext()) {
1794 count = itr.next();
1795 }
1796
1797 if (count == null) {
1798 count = new Long(0);
1799 }
1800
1801 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1802 finderClassName, finderMethodName, finderParams,
1803 finderArgs, count);
1804
1805 return count.intValue();
1806 }
1807 catch (Exception e) {
1808 throw processException(e);
1809 }
1810 finally {
1811 closeSession(session);
1812 }
1813 }
1814 else {
1815 return ((Long)result).intValue();
1816 }
1817 }
1818
1819 public int countByLargeImageId(long largeImageId) throws SystemException {
1820 boolean finderClassNameCacheEnabled = IGImageModelImpl.CACHE_ENABLED;
1821 String finderClassName = IGImage.class.getName();
1822 String finderMethodName = "countByLargeImageId";
1823 String[] finderParams = new String[] { Long.class.getName() };
1824 Object[] finderArgs = new Object[] { new Long(largeImageId) };
1825
1826 Object result = null;
1827
1828 if (finderClassNameCacheEnabled) {
1829 result = FinderCacheUtil.getResult(finderClassName,
1830 finderMethodName, finderParams, finderArgs, this);
1831 }
1832
1833 if (result == null) {
1834 Session session = null;
1835
1836 try {
1837 session = openSession();
1838
1839 StringBuilder query = new StringBuilder();
1840
1841 query.append("SELECT COUNT(*) ");
1842 query.append(
1843 "FROM com.liferay.portlet.imagegallery.model.IGImage WHERE ");
1844
1845 query.append("largeImageId = ?");
1846
1847 query.append(" ");
1848
1849 Query q = session.createQuery(query.toString());
1850
1851 QueryPos qPos = QueryPos.getInstance(q);
1852
1853 qPos.add(largeImageId);
1854
1855 Long count = null;
1856
1857 Iterator<Long> itr = q.list().iterator();
1858
1859 if (itr.hasNext()) {
1860 count = itr.next();
1861 }
1862
1863 if (count == null) {
1864 count = new Long(0);
1865 }
1866
1867 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1868 finderClassName, finderMethodName, finderParams,
1869 finderArgs, count);
1870
1871 return count.intValue();
1872 }
1873 catch (Exception e) {
1874 throw processException(e);
1875 }
1876 finally {
1877 closeSession(session);
1878 }
1879 }
1880 else {
1881 return ((Long)result).intValue();
1882 }
1883 }
1884
1885 public int countByCustom1ImageId(long custom1ImageId)
1886 throws SystemException {
1887 boolean finderClassNameCacheEnabled = IGImageModelImpl.CACHE_ENABLED;
1888 String finderClassName = IGImage.class.getName();
1889 String finderMethodName = "countByCustom1ImageId";
1890 String[] finderParams = new String[] { Long.class.getName() };
1891 Object[] finderArgs = new Object[] { new Long(custom1ImageId) };
1892
1893 Object result = null;
1894
1895 if (finderClassNameCacheEnabled) {
1896 result = FinderCacheUtil.getResult(finderClassName,
1897 finderMethodName, finderParams, finderArgs, this);
1898 }
1899
1900 if (result == null) {
1901 Session session = null;
1902
1903 try {
1904 session = openSession();
1905
1906 StringBuilder query = new StringBuilder();
1907
1908 query.append("SELECT COUNT(*) ");
1909 query.append(
1910 "FROM com.liferay.portlet.imagegallery.model.IGImage WHERE ");
1911
1912 query.append("custom1ImageId = ?");
1913
1914 query.append(" ");
1915
1916 Query q = session.createQuery(query.toString());
1917
1918 QueryPos qPos = QueryPos.getInstance(q);
1919
1920 qPos.add(custom1ImageId);
1921
1922 Long count = null;
1923
1924 Iterator<Long> itr = q.list().iterator();
1925
1926 if (itr.hasNext()) {
1927 count = itr.next();
1928 }
1929
1930 if (count == null) {
1931 count = new Long(0);
1932 }
1933
1934 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1935 finderClassName, finderMethodName, finderParams,
1936 finderArgs, count);
1937
1938 return count.intValue();
1939 }
1940 catch (Exception e) {
1941 throw processException(e);
1942 }
1943 finally {
1944 closeSession(session);
1945 }
1946 }
1947 else {
1948 return ((Long)result).intValue();
1949 }
1950 }
1951
1952 public int countByCustom2ImageId(long custom2ImageId)
1953 throws SystemException {
1954 boolean finderClassNameCacheEnabled = IGImageModelImpl.CACHE_ENABLED;
1955 String finderClassName = IGImage.class.getName();
1956 String finderMethodName = "countByCustom2ImageId";
1957 String[] finderParams = new String[] { Long.class.getName() };
1958 Object[] finderArgs = new Object[] { new Long(custom2ImageId) };
1959
1960 Object result = null;
1961
1962 if (finderClassNameCacheEnabled) {
1963 result = FinderCacheUtil.getResult(finderClassName,
1964 finderMethodName, finderParams, finderArgs, this);
1965 }
1966
1967 if (result == null) {
1968 Session session = null;
1969
1970 try {
1971 session = openSession();
1972
1973 StringBuilder query = new StringBuilder();
1974
1975 query.append("SELECT COUNT(*) ");
1976 query.append(
1977 "FROM com.liferay.portlet.imagegallery.model.IGImage WHERE ");
1978
1979 query.append("custom2ImageId = ?");
1980
1981 query.append(" ");
1982
1983 Query q = session.createQuery(query.toString());
1984
1985 QueryPos qPos = QueryPos.getInstance(q);
1986
1987 qPos.add(custom2ImageId);
1988
1989 Long count = null;
1990
1991 Iterator<Long> itr = q.list().iterator();
1992
1993 if (itr.hasNext()) {
1994 count = itr.next();
1995 }
1996
1997 if (count == null) {
1998 count = new Long(0);
1999 }
2000
2001 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2002 finderClassName, finderMethodName, finderParams,
2003 finderArgs, count);
2004
2005 return count.intValue();
2006 }
2007 catch (Exception e) {
2008 throw processException(e);
2009 }
2010 finally {
2011 closeSession(session);
2012 }
2013 }
2014 else {
2015 return ((Long)result).intValue();
2016 }
2017 }
2018
2019 public int countByF_N(long folderId, String name) throws SystemException {
2020 boolean finderClassNameCacheEnabled = IGImageModelImpl.CACHE_ENABLED;
2021 String finderClassName = IGImage.class.getName();
2022 String finderMethodName = "countByF_N";
2023 String[] finderParams = new String[] {
2024 Long.class.getName(), String.class.getName()
2025 };
2026 Object[] finderArgs = new Object[] { new Long(folderId), name };
2027
2028 Object result = null;
2029
2030 if (finderClassNameCacheEnabled) {
2031 result = FinderCacheUtil.getResult(finderClassName,
2032 finderMethodName, finderParams, finderArgs, this);
2033 }
2034
2035 if (result == null) {
2036 Session session = null;
2037
2038 try {
2039 session = openSession();
2040
2041 StringBuilder query = new StringBuilder();
2042
2043 query.append("SELECT COUNT(*) ");
2044 query.append(
2045 "FROM com.liferay.portlet.imagegallery.model.IGImage WHERE ");
2046
2047 query.append("folderId = ?");
2048
2049 query.append(" AND ");
2050
2051 if (name == null) {
2052 query.append("name IS NULL");
2053 }
2054 else {
2055 query.append("name = ?");
2056 }
2057
2058 query.append(" ");
2059
2060 Query q = session.createQuery(query.toString());
2061
2062 QueryPos qPos = QueryPos.getInstance(q);
2063
2064 qPos.add(folderId);
2065
2066 if (name != null) {
2067 qPos.add(name);
2068 }
2069
2070 Long count = null;
2071
2072 Iterator<Long> itr = q.list().iterator();
2073
2074 if (itr.hasNext()) {
2075 count = itr.next();
2076 }
2077
2078 if (count == null) {
2079 count = new Long(0);
2080 }
2081
2082 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2083 finderClassName, finderMethodName, finderParams,
2084 finderArgs, count);
2085
2086 return count.intValue();
2087 }
2088 catch (Exception e) {
2089 throw processException(e);
2090 }
2091 finally {
2092 closeSession(session);
2093 }
2094 }
2095 else {
2096 return ((Long)result).intValue();
2097 }
2098 }
2099
2100 public int countAll() throws SystemException {
2101 boolean finderClassNameCacheEnabled = IGImageModelImpl.CACHE_ENABLED;
2102 String finderClassName = IGImage.class.getName();
2103 String finderMethodName = "countAll";
2104 String[] finderParams = new String[] { };
2105 Object[] finderArgs = new Object[] { };
2106
2107 Object result = null;
2108
2109 if (finderClassNameCacheEnabled) {
2110 result = FinderCacheUtil.getResult(finderClassName,
2111 finderMethodName, finderParams, finderArgs, this);
2112 }
2113
2114 if (result == null) {
2115 Session session = null;
2116
2117 try {
2118 session = openSession();
2119
2120 Query q = session.createQuery(
2121 "SELECT COUNT(*) FROM com.liferay.portlet.imagegallery.model.IGImage");
2122
2123 Long count = null;
2124
2125 Iterator<Long> itr = q.list().iterator();
2126
2127 if (itr.hasNext()) {
2128 count = itr.next();
2129 }
2130
2131 if (count == null) {
2132 count = new Long(0);
2133 }
2134
2135 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2136 finderClassName, finderMethodName, finderParams,
2137 finderArgs, count);
2138
2139 return count.intValue();
2140 }
2141 catch (Exception e) {
2142 throw processException(e);
2143 }
2144 finally {
2145 closeSession(session);
2146 }
2147 }
2148 else {
2149 return ((Long)result).intValue();
2150 }
2151 }
2152
2153 public void registerListener(ModelListener listener) {
2154 List<ModelListener> listeners = ListUtil.fromArray(_listeners);
2155
2156 listeners.add(listener);
2157
2158 _listeners = listeners.toArray(new ModelListener[listeners.size()]);
2159 }
2160
2161 public void unregisterListener(ModelListener listener) {
2162 List<ModelListener> listeners = ListUtil.fromArray(_listeners);
2163
2164 listeners.remove(listener);
2165
2166 _listeners = listeners.toArray(new ModelListener[listeners.size()]);
2167 }
2168
2169 public void afterPropertiesSet() {
2170 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2171 com.liferay.portal.util.PropsUtil.get(
2172 "value.object.listener.com.liferay.portlet.imagegallery.model.IGImage")));
2173
2174 if (listenerClassNames.length > 0) {
2175 try {
2176 List<ModelListener> listeners = new ArrayList<ModelListener>();
2177
2178 for (String listenerClassName : listenerClassNames) {
2179 listeners.add((ModelListener)Class.forName(
2180 listenerClassName).newInstance());
2181 }
2182
2183 _listeners = listeners.toArray(new ModelListener[listeners.size()]);
2184 }
2185 catch (Exception e) {
2186 _log.error(e);
2187 }
2188 }
2189 }
2190
2191 private static Log _log = LogFactory.getLog(IGImagePersistenceImpl.class);
2192 private ModelListener[] _listeners = new ModelListener[0];
2193}