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