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