001
014
015 package com.liferay.portal.service.persistence;
016
017 import com.liferay.portal.NoSuchImageException;
018 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
019 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
020 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderPath;
022 import com.liferay.portal.kernel.dao.orm.Query;
023 import com.liferay.portal.kernel.dao.orm.QueryPos;
024 import com.liferay.portal.kernel.dao.orm.QueryUtil;
025 import com.liferay.portal.kernel.dao.orm.Session;
026 import com.liferay.portal.kernel.exception.SystemException;
027 import com.liferay.portal.kernel.log.Log;
028 import com.liferay.portal.kernel.log.LogFactoryUtil;
029 import com.liferay.portal.kernel.util.GetterUtil;
030 import com.liferay.portal.kernel.util.InstanceFactory;
031 import com.liferay.portal.kernel.util.OrderByComparator;
032 import com.liferay.portal.kernel.util.StringBundler;
033 import com.liferay.portal.kernel.util.StringPool;
034 import com.liferay.portal.kernel.util.StringUtil;
035 import com.liferay.portal.kernel.util.UnmodifiableList;
036 import com.liferay.portal.model.CacheModel;
037 import com.liferay.portal.model.Image;
038 import com.liferay.portal.model.ModelListener;
039 import com.liferay.portal.model.impl.ImageImpl;
040 import com.liferay.portal.model.impl.ImageModelImpl;
041 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
042
043 import java.io.Serializable;
044
045 import java.util.ArrayList;
046 import java.util.Collections;
047 import java.util.List;
048
049
061 public class ImagePersistenceImpl extends BasePersistenceImpl<Image>
062 implements ImagePersistence {
063
068 public static final String FINDER_CLASS_NAME_ENTITY = ImageImpl.class.getName();
069 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
070 ".List1";
071 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
072 ".List2";
073 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(ImageModelImpl.ENTITY_CACHE_ENABLED,
074 ImageModelImpl.FINDER_CACHE_ENABLED, ImageImpl.class,
075 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
076 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(ImageModelImpl.ENTITY_CACHE_ENABLED,
077 ImageModelImpl.FINDER_CACHE_ENABLED, ImageImpl.class,
078 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
079 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ImageModelImpl.ENTITY_CACHE_ENABLED,
080 ImageModelImpl.FINDER_CACHE_ENABLED, Long.class,
081 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
082 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_LTSIZE = new FinderPath(ImageModelImpl.ENTITY_CACHE_ENABLED,
083 ImageModelImpl.FINDER_CACHE_ENABLED, ImageImpl.class,
084 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByLtSize",
085 new String[] {
086 Integer.class.getName(),
087
088 Integer.class.getName(), Integer.class.getName(),
089 OrderByComparator.class.getName()
090 });
091 public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_LTSIZE = new FinderPath(ImageModelImpl.ENTITY_CACHE_ENABLED,
092 ImageModelImpl.FINDER_CACHE_ENABLED, Long.class,
093 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByLtSize",
094 new String[] { Integer.class.getName() });
095
096
103 public List<Image> findByLtSize(int size) throws SystemException {
104 return findByLtSize(size, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
105 }
106
107
120 public List<Image> findByLtSize(int size, int start, int end)
121 throws SystemException {
122 return findByLtSize(size, start, end, null);
123 }
124
125
139 public List<Image> findByLtSize(int size, int start, int end,
140 OrderByComparator orderByComparator) throws SystemException {
141 boolean pagination = true;
142 FinderPath finderPath = null;
143 Object[] finderArgs = null;
144
145 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_LTSIZE;
146 finderArgs = new Object[] { size, start, end, orderByComparator };
147
148 List<Image> list = (List<Image>)FinderCacheUtil.getResult(finderPath,
149 finderArgs, this);
150
151 if ((list != null) && !list.isEmpty()) {
152 for (Image image : list) {
153 if ((size != image.getSize())) {
154 list = null;
155
156 break;
157 }
158 }
159 }
160
161 if (list == null) {
162 StringBundler query = null;
163
164 if (orderByComparator != null) {
165 query = new StringBundler(3 +
166 (orderByComparator.getOrderByFields().length * 3));
167 }
168 else {
169 query = new StringBundler(3);
170 }
171
172 query.append(_SQL_SELECT_IMAGE_WHERE);
173
174 query.append(_FINDER_COLUMN_LTSIZE_SIZE_2);
175
176 if (orderByComparator != null) {
177 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
178 orderByComparator);
179 }
180 else
181 if (pagination) {
182 query.append(ImageModelImpl.ORDER_BY_JPQL);
183 }
184
185 String sql = query.toString();
186
187 Session session = null;
188
189 try {
190 session = openSession();
191
192 Query q = session.createQuery(sql);
193
194 QueryPos qPos = QueryPos.getInstance(q);
195
196 qPos.add(size);
197
198 if (!pagination) {
199 list = (List<Image>)QueryUtil.list(q, getDialect(), start,
200 end, false);
201
202 Collections.sort(list);
203
204 list = new UnmodifiableList<Image>(list);
205 }
206 else {
207 list = (List<Image>)QueryUtil.list(q, getDialect(), start,
208 end);
209 }
210
211 cacheResult(list);
212
213 FinderCacheUtil.putResult(finderPath, finderArgs, list);
214 }
215 catch (Exception e) {
216 FinderCacheUtil.removeResult(finderPath, finderArgs);
217
218 throw processException(e);
219 }
220 finally {
221 closeSession(session);
222 }
223 }
224
225 return list;
226 }
227
228
237 public Image findByLtSize_First(int size,
238 OrderByComparator orderByComparator)
239 throws NoSuchImageException, SystemException {
240 Image image = fetchByLtSize_First(size, orderByComparator);
241
242 if (image != null) {
243 return image;
244 }
245
246 StringBundler msg = new StringBundler(4);
247
248 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
249
250 msg.append("size=");
251 msg.append(size);
252
253 msg.append(StringPool.CLOSE_CURLY_BRACE);
254
255 throw new NoSuchImageException(msg.toString());
256 }
257
258
266 public Image fetchByLtSize_First(int size,
267 OrderByComparator orderByComparator) throws SystemException {
268 List<Image> list = findByLtSize(size, 0, 1, orderByComparator);
269
270 if (!list.isEmpty()) {
271 return list.get(0);
272 }
273
274 return null;
275 }
276
277
286 public Image findByLtSize_Last(int size, OrderByComparator orderByComparator)
287 throws NoSuchImageException, SystemException {
288 Image image = fetchByLtSize_Last(size, orderByComparator);
289
290 if (image != null) {
291 return image;
292 }
293
294 StringBundler msg = new StringBundler(4);
295
296 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
297
298 msg.append("size=");
299 msg.append(size);
300
301 msg.append(StringPool.CLOSE_CURLY_BRACE);
302
303 throw new NoSuchImageException(msg.toString());
304 }
305
306
314 public Image fetchByLtSize_Last(int size,
315 OrderByComparator orderByComparator) throws SystemException {
316 int count = countByLtSize(size);
317
318 List<Image> list = findByLtSize(size, count - 1, count,
319 orderByComparator);
320
321 if (!list.isEmpty()) {
322 return list.get(0);
323 }
324
325 return null;
326 }
327
328
338 public Image[] findByLtSize_PrevAndNext(long imageId, int size,
339 OrderByComparator orderByComparator)
340 throws NoSuchImageException, SystemException {
341 Image image = findByPrimaryKey(imageId);
342
343 Session session = null;
344
345 try {
346 session = openSession();
347
348 Image[] array = new ImageImpl[3];
349
350 array[0] = getByLtSize_PrevAndNext(session, image, size,
351 orderByComparator, true);
352
353 array[1] = image;
354
355 array[2] = getByLtSize_PrevAndNext(session, image, size,
356 orderByComparator, false);
357
358 return array;
359 }
360 catch (Exception e) {
361 throw processException(e);
362 }
363 finally {
364 closeSession(session);
365 }
366 }
367
368 protected Image getByLtSize_PrevAndNext(Session session, Image image,
369 int size, OrderByComparator orderByComparator, boolean previous) {
370 StringBundler query = null;
371
372 if (orderByComparator != null) {
373 query = new StringBundler(6 +
374 (orderByComparator.getOrderByFields().length * 6));
375 }
376 else {
377 query = new StringBundler(3);
378 }
379
380 query.append(_SQL_SELECT_IMAGE_WHERE);
381
382 query.append(_FINDER_COLUMN_LTSIZE_SIZE_2);
383
384 if (orderByComparator != null) {
385 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
386
387 if (orderByConditionFields.length > 0) {
388 query.append(WHERE_AND);
389 }
390
391 for (int i = 0; i < orderByConditionFields.length; i++) {
392 query.append(_ORDER_BY_ENTITY_ALIAS);
393 query.append(orderByConditionFields[i]);
394
395 if ((i + 1) < orderByConditionFields.length) {
396 if (orderByComparator.isAscending() ^ previous) {
397 query.append(WHERE_GREATER_THAN_HAS_NEXT);
398 }
399 else {
400 query.append(WHERE_LESSER_THAN_HAS_NEXT);
401 }
402 }
403 else {
404 if (orderByComparator.isAscending() ^ previous) {
405 query.append(WHERE_GREATER_THAN);
406 }
407 else {
408 query.append(WHERE_LESSER_THAN);
409 }
410 }
411 }
412
413 query.append(ORDER_BY_CLAUSE);
414
415 String[] orderByFields = orderByComparator.getOrderByFields();
416
417 for (int i = 0; i < orderByFields.length; i++) {
418 query.append(_ORDER_BY_ENTITY_ALIAS);
419 query.append(orderByFields[i]);
420
421 if ((i + 1) < orderByFields.length) {
422 if (orderByComparator.isAscending() ^ previous) {
423 query.append(ORDER_BY_ASC_HAS_NEXT);
424 }
425 else {
426 query.append(ORDER_BY_DESC_HAS_NEXT);
427 }
428 }
429 else {
430 if (orderByComparator.isAscending() ^ previous) {
431 query.append(ORDER_BY_ASC);
432 }
433 else {
434 query.append(ORDER_BY_DESC);
435 }
436 }
437 }
438 }
439 else {
440 query.append(ImageModelImpl.ORDER_BY_JPQL);
441 }
442
443 String sql = query.toString();
444
445 Query q = session.createQuery(sql);
446
447 q.setFirstResult(0);
448 q.setMaxResults(2);
449
450 QueryPos qPos = QueryPos.getInstance(q);
451
452 qPos.add(size);
453
454 if (orderByComparator != null) {
455 Object[] values = orderByComparator.getOrderByConditionValues(image);
456
457 for (Object value : values) {
458 qPos.add(value);
459 }
460 }
461
462 List<Image> list = q.list();
463
464 if (list.size() == 2) {
465 return list.get(1);
466 }
467 else {
468 return null;
469 }
470 }
471
472
478 public void removeByLtSize(int size) throws SystemException {
479 for (Image image : findByLtSize(size, QueryUtil.ALL_POS,
480 QueryUtil.ALL_POS, null)) {
481 remove(image);
482 }
483 }
484
485
492 public int countByLtSize(int size) throws SystemException {
493 FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_LTSIZE;
494
495 Object[] finderArgs = new Object[] { size };
496
497 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
498 this);
499
500 if (count == null) {
501 StringBundler query = new StringBundler(2);
502
503 query.append(_SQL_COUNT_IMAGE_WHERE);
504
505 query.append(_FINDER_COLUMN_LTSIZE_SIZE_2);
506
507 String sql = query.toString();
508
509 Session session = null;
510
511 try {
512 session = openSession();
513
514 Query q = session.createQuery(sql);
515
516 QueryPos qPos = QueryPos.getInstance(q);
517
518 qPos.add(size);
519
520 count = (Long)q.uniqueResult();
521
522 FinderCacheUtil.putResult(finderPath, finderArgs, count);
523 }
524 catch (Exception e) {
525 FinderCacheUtil.removeResult(finderPath, finderArgs);
526
527 throw processException(e);
528 }
529 finally {
530 closeSession(session);
531 }
532 }
533
534 return count.intValue();
535 }
536
537 private static final String _FINDER_COLUMN_LTSIZE_SIZE_2 = "image.size < ?";
538
539
544 public void cacheResult(Image image) {
545 EntityCacheUtil.putResult(ImageModelImpl.ENTITY_CACHE_ENABLED,
546 ImageImpl.class, image.getPrimaryKey(), image);
547
548 image.resetOriginalValues();
549 }
550
551
556 public void cacheResult(List<Image> images) {
557 for (Image image : images) {
558 if (EntityCacheUtil.getResult(ImageModelImpl.ENTITY_CACHE_ENABLED,
559 ImageImpl.class, image.getPrimaryKey()) == null) {
560 cacheResult(image);
561 }
562 else {
563 image.resetOriginalValues();
564 }
565 }
566 }
567
568
575 @Override
576 public void clearCache() {
577 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
578 CacheRegistryUtil.clear(ImageImpl.class.getName());
579 }
580
581 EntityCacheUtil.clearCache(ImageImpl.class.getName());
582
583 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
584 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
585 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
586 }
587
588
595 @Override
596 public void clearCache(Image image) {
597 EntityCacheUtil.removeResult(ImageModelImpl.ENTITY_CACHE_ENABLED,
598 ImageImpl.class, image.getPrimaryKey());
599
600 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
601 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
602 }
603
604 @Override
605 public void clearCache(List<Image> images) {
606 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
607 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
608
609 for (Image image : images) {
610 EntityCacheUtil.removeResult(ImageModelImpl.ENTITY_CACHE_ENABLED,
611 ImageImpl.class, image.getPrimaryKey());
612 }
613 }
614
615
621 public Image create(long imageId) {
622 Image image = new ImageImpl();
623
624 image.setNew(true);
625 image.setPrimaryKey(imageId);
626
627 return image;
628 }
629
630
638 public Image remove(long imageId)
639 throws NoSuchImageException, SystemException {
640 return remove((Serializable)imageId);
641 }
642
643
651 @Override
652 public Image remove(Serializable primaryKey)
653 throws NoSuchImageException, SystemException {
654 Session session = null;
655
656 try {
657 session = openSession();
658
659 Image image = (Image)session.get(ImageImpl.class, primaryKey);
660
661 if (image == null) {
662 if (_log.isWarnEnabled()) {
663 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
664 }
665
666 throw new NoSuchImageException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
667 primaryKey);
668 }
669
670 return remove(image);
671 }
672 catch (NoSuchImageException nsee) {
673 throw nsee;
674 }
675 catch (Exception e) {
676 throw processException(e);
677 }
678 finally {
679 closeSession(session);
680 }
681 }
682
683 @Override
684 protected Image removeImpl(Image image) throws SystemException {
685 image = toUnwrappedModel(image);
686
687 Session session = null;
688
689 try {
690 session = openSession();
691
692 if (!session.contains(image)) {
693 image = (Image)session.get(ImageImpl.class,
694 image.getPrimaryKeyObj());
695 }
696
697 if (image != null) {
698 session.delete(image);
699 }
700 }
701 catch (Exception e) {
702 throw processException(e);
703 }
704 finally {
705 closeSession(session);
706 }
707
708 if (image != null) {
709 clearCache(image);
710 }
711
712 return image;
713 }
714
715 @Override
716 public Image updateImpl(com.liferay.portal.model.Image image)
717 throws SystemException {
718 image = toUnwrappedModel(image);
719
720 boolean isNew = image.isNew();
721
722 Session session = null;
723
724 try {
725 session = openSession();
726
727 if (image.isNew()) {
728 session.save(image);
729
730 image.setNew(false);
731 }
732 else {
733 session.merge(image);
734 }
735 }
736 catch (Exception e) {
737 throw processException(e);
738 }
739 finally {
740 closeSession(session);
741 }
742
743 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
744
745 if (isNew || !ImageModelImpl.COLUMN_BITMASK_ENABLED) {
746 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
747 }
748
749 EntityCacheUtil.putResult(ImageModelImpl.ENTITY_CACHE_ENABLED,
750 ImageImpl.class, image.getPrimaryKey(), image);
751
752 return image;
753 }
754
755 protected Image toUnwrappedModel(Image image) {
756 if (image instanceof ImageImpl) {
757 return image;
758 }
759
760 ImageImpl imageImpl = new ImageImpl();
761
762 imageImpl.setNew(image.isNew());
763 imageImpl.setPrimaryKey(image.getPrimaryKey());
764
765 imageImpl.setImageId(image.getImageId());
766 imageImpl.setModifiedDate(image.getModifiedDate());
767 imageImpl.setType(image.getType());
768 imageImpl.setHeight(image.getHeight());
769 imageImpl.setWidth(image.getWidth());
770 imageImpl.setSize(image.getSize());
771
772 return imageImpl;
773 }
774
775
783 @Override
784 public Image findByPrimaryKey(Serializable primaryKey)
785 throws NoSuchImageException, SystemException {
786 Image image = fetchByPrimaryKey(primaryKey);
787
788 if (image == null) {
789 if (_log.isWarnEnabled()) {
790 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
791 }
792
793 throw new NoSuchImageException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
794 primaryKey);
795 }
796
797 return image;
798 }
799
800
808 public Image findByPrimaryKey(long imageId)
809 throws NoSuchImageException, SystemException {
810 return findByPrimaryKey((Serializable)imageId);
811 }
812
813
820 @Override
821 public Image fetchByPrimaryKey(Serializable primaryKey)
822 throws SystemException {
823 Image image = (Image)EntityCacheUtil.getResult(ImageModelImpl.ENTITY_CACHE_ENABLED,
824 ImageImpl.class, primaryKey);
825
826 if (image == _nullImage) {
827 return null;
828 }
829
830 if (image == null) {
831 Session session = null;
832
833 try {
834 session = openSession();
835
836 image = (Image)session.get(ImageImpl.class, primaryKey);
837
838 if (image != null) {
839 cacheResult(image);
840 }
841 else {
842 EntityCacheUtil.putResult(ImageModelImpl.ENTITY_CACHE_ENABLED,
843 ImageImpl.class, primaryKey, _nullImage);
844 }
845 }
846 catch (Exception e) {
847 EntityCacheUtil.removeResult(ImageModelImpl.ENTITY_CACHE_ENABLED,
848 ImageImpl.class, primaryKey);
849
850 throw processException(e);
851 }
852 finally {
853 closeSession(session);
854 }
855 }
856
857 return image;
858 }
859
860
867 public Image fetchByPrimaryKey(long imageId) throws SystemException {
868 return fetchByPrimaryKey((Serializable)imageId);
869 }
870
871
877 public List<Image> findAll() throws SystemException {
878 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
879 }
880
881
893 public List<Image> findAll(int start, int end) throws SystemException {
894 return findAll(start, end, null);
895 }
896
897
910 public List<Image> findAll(int start, int end,
911 OrderByComparator orderByComparator) throws SystemException {
912 boolean pagination = true;
913 FinderPath finderPath = null;
914 Object[] finderArgs = null;
915
916 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
917 (orderByComparator == null)) {
918 pagination = false;
919 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
920 finderArgs = FINDER_ARGS_EMPTY;
921 }
922 else {
923 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
924 finderArgs = new Object[] { start, end, orderByComparator };
925 }
926
927 List<Image> list = (List<Image>)FinderCacheUtil.getResult(finderPath,
928 finderArgs, this);
929
930 if (list == null) {
931 StringBundler query = null;
932 String sql = null;
933
934 if (orderByComparator != null) {
935 query = new StringBundler(2 +
936 (orderByComparator.getOrderByFields().length * 3));
937
938 query.append(_SQL_SELECT_IMAGE);
939
940 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
941 orderByComparator);
942
943 sql = query.toString();
944 }
945 else {
946 sql = _SQL_SELECT_IMAGE;
947
948 if (pagination) {
949 sql = sql.concat(ImageModelImpl.ORDER_BY_JPQL);
950 }
951 }
952
953 Session session = null;
954
955 try {
956 session = openSession();
957
958 Query q = session.createQuery(sql);
959
960 if (!pagination) {
961 list = (List<Image>)QueryUtil.list(q, getDialect(), start,
962 end, false);
963
964 Collections.sort(list);
965
966 list = new UnmodifiableList<Image>(list);
967 }
968 else {
969 list = (List<Image>)QueryUtil.list(q, getDialect(), start,
970 end);
971 }
972
973 cacheResult(list);
974
975 FinderCacheUtil.putResult(finderPath, finderArgs, list);
976 }
977 catch (Exception e) {
978 FinderCacheUtil.removeResult(finderPath, finderArgs);
979
980 throw processException(e);
981 }
982 finally {
983 closeSession(session);
984 }
985 }
986
987 return list;
988 }
989
990
995 public void removeAll() throws SystemException {
996 for (Image image : findAll()) {
997 remove(image);
998 }
999 }
1000
1001
1007 public int countAll() throws SystemException {
1008 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1009 FINDER_ARGS_EMPTY, this);
1010
1011 if (count == null) {
1012 Session session = null;
1013
1014 try {
1015 session = openSession();
1016
1017 Query q = session.createQuery(_SQL_COUNT_IMAGE);
1018
1019 count = (Long)q.uniqueResult();
1020
1021 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1022 FINDER_ARGS_EMPTY, count);
1023 }
1024 catch (Exception e) {
1025 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
1026 FINDER_ARGS_EMPTY);
1027
1028 throw processException(e);
1029 }
1030 finally {
1031 closeSession(session);
1032 }
1033 }
1034
1035 return count.intValue();
1036 }
1037
1038
1041 public void afterPropertiesSet() {
1042 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1043 com.liferay.portal.util.PropsUtil.get(
1044 "value.object.listener.com.liferay.portal.model.Image")));
1045
1046 if (listenerClassNames.length > 0) {
1047 try {
1048 List<ModelListener<Image>> listenersList = new ArrayList<ModelListener<Image>>();
1049
1050 for (String listenerClassName : listenerClassNames) {
1051 listenersList.add((ModelListener<Image>)InstanceFactory.newInstance(
1052 listenerClassName));
1053 }
1054
1055 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1056 }
1057 catch (Exception e) {
1058 _log.error(e);
1059 }
1060 }
1061 }
1062
1063 public void destroy() {
1064 EntityCacheUtil.removeCache(ImageImpl.class.getName());
1065 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1066 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1067 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1068 }
1069
1070 private static final String _SQL_SELECT_IMAGE = "SELECT image FROM Image image";
1071 private static final String _SQL_SELECT_IMAGE_WHERE = "SELECT image FROM Image image WHERE ";
1072 private static final String _SQL_COUNT_IMAGE = "SELECT COUNT(image) FROM Image image";
1073 private static final String _SQL_COUNT_IMAGE_WHERE = "SELECT COUNT(image) FROM Image image WHERE ";
1074 private static final String _ORDER_BY_ENTITY_ALIAS = "image.";
1075 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Image exists with the primary key ";
1076 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Image exists with the key {";
1077 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1078 private static Log _log = LogFactoryUtil.getLog(ImagePersistenceImpl.class);
1079 private static Image _nullImage = new ImageImpl() {
1080 @Override
1081 public Object clone() {
1082 return this;
1083 }
1084
1085 @Override
1086 public CacheModel<Image> toCacheModel() {
1087 return _nullImageCacheModel;
1088 }
1089 };
1090
1091 private static CacheModel<Image> _nullImageCacheModel = new CacheModel<Image>() {
1092 public Image toEntityModel() {
1093 return _nullImage;
1094 }
1095 };
1096 }