001
014
015 package com.liferay.portal.service.persistence;
016
017 import com.liferay.portal.NoSuchImageException;
018 import com.liferay.portal.NoSuchModelException;
019 import com.liferay.portal.kernel.bean.BeanReference;
020 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
021 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
023 import com.liferay.portal.kernel.dao.orm.FinderPath;
024 import com.liferay.portal.kernel.dao.orm.Query;
025 import com.liferay.portal.kernel.dao.orm.QueryPos;
026 import com.liferay.portal.kernel.dao.orm.QueryUtil;
027 import com.liferay.portal.kernel.dao.orm.Session;
028 import com.liferay.portal.kernel.exception.SystemException;
029 import com.liferay.portal.kernel.log.Log;
030 import com.liferay.portal.kernel.log.LogFactoryUtil;
031 import com.liferay.portal.kernel.util.GetterUtil;
032 import com.liferay.portal.kernel.util.InstanceFactory;
033 import com.liferay.portal.kernel.util.OrderByComparator;
034 import com.liferay.portal.kernel.util.StringBundler;
035 import com.liferay.portal.kernel.util.StringPool;
036 import com.liferay.portal.kernel.util.StringUtil;
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 com.liferay.portlet.documentlibrary.service.persistence.DLFileEntryPersistence;
045
046 import java.io.Serializable;
047
048 import java.util.ArrayList;
049 import java.util.Collections;
050 import java.util.List;
051
052
064 public class ImagePersistenceImpl extends BasePersistenceImpl<Image>
065 implements ImagePersistence {
066
071 public static final String FINDER_CLASS_NAME_ENTITY = ImageImpl.class.getName();
072 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
073 ".List1";
074 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
075 ".List2";
076 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_LTSIZE = new FinderPath(ImageModelImpl.ENTITY_CACHE_ENABLED,
077 ImageModelImpl.FINDER_CACHE_ENABLED, ImageImpl.class,
078 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByLtSize",
079 new String[] {
080 Integer.class.getName(),
081
082 "java.lang.Integer", "java.lang.Integer",
083 "com.liferay.portal.kernel.util.OrderByComparator"
084 });
085 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LTSIZE =
086 new FinderPath(ImageModelImpl.ENTITY_CACHE_ENABLED,
087 ImageModelImpl.FINDER_CACHE_ENABLED, ImageImpl.class,
088 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByLtSize",
089 new String[] { Integer.class.getName() },
090 ImageModelImpl.SIZE_COLUMN_BITMASK);
091 public static final FinderPath FINDER_PATH_COUNT_BY_LTSIZE = new FinderPath(ImageModelImpl.ENTITY_CACHE_ENABLED,
092 ImageModelImpl.FINDER_CACHE_ENABLED, Long.class,
093 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByLtSize",
094 new String[] { Integer.class.getName() });
095 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(ImageModelImpl.ENTITY_CACHE_ENABLED,
096 ImageModelImpl.FINDER_CACHE_ENABLED, ImageImpl.class,
097 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
098 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(ImageModelImpl.ENTITY_CACHE_ENABLED,
099 ImageModelImpl.FINDER_CACHE_ENABLED, ImageImpl.class,
100 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
101 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ImageModelImpl.ENTITY_CACHE_ENABLED,
102 ImageModelImpl.FINDER_CACHE_ENABLED, Long.class,
103 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
104
105
110 public void cacheResult(Image image) {
111 EntityCacheUtil.putResult(ImageModelImpl.ENTITY_CACHE_ENABLED,
112 ImageImpl.class, image.getPrimaryKey(), image);
113
114 image.resetOriginalValues();
115 }
116
117
122 public void cacheResult(List<Image> images) {
123 for (Image image : images) {
124 if (EntityCacheUtil.getResult(ImageModelImpl.ENTITY_CACHE_ENABLED,
125 ImageImpl.class, image.getPrimaryKey()) == null) {
126 cacheResult(image);
127 }
128 else {
129 image.resetOriginalValues();
130 }
131 }
132 }
133
134
141 @Override
142 public void clearCache() {
143 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
144 CacheRegistryUtil.clear(ImageImpl.class.getName());
145 }
146
147 EntityCacheUtil.clearCache(ImageImpl.class.getName());
148
149 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
150 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
151 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
152 }
153
154
161 @Override
162 public void clearCache(Image image) {
163 EntityCacheUtil.removeResult(ImageModelImpl.ENTITY_CACHE_ENABLED,
164 ImageImpl.class, image.getPrimaryKey());
165
166 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
167 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
168 }
169
170 @Override
171 public void clearCache(List<Image> images) {
172 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
173 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
174
175 for (Image image : images) {
176 EntityCacheUtil.removeResult(ImageModelImpl.ENTITY_CACHE_ENABLED,
177 ImageImpl.class, image.getPrimaryKey());
178 }
179 }
180
181
187 public Image create(long imageId) {
188 Image image = new ImageImpl();
189
190 image.setNew(true);
191 image.setPrimaryKey(imageId);
192
193 return image;
194 }
195
196
204 public Image remove(long imageId)
205 throws NoSuchImageException, SystemException {
206 return remove(Long.valueOf(imageId));
207 }
208
209
217 @Override
218 public Image remove(Serializable primaryKey)
219 throws NoSuchImageException, SystemException {
220 Session session = null;
221
222 try {
223 session = openSession();
224
225 Image image = (Image)session.get(ImageImpl.class, primaryKey);
226
227 if (image == null) {
228 if (_log.isWarnEnabled()) {
229 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
230 }
231
232 throw new NoSuchImageException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
233 primaryKey);
234 }
235
236 return remove(image);
237 }
238 catch (NoSuchImageException nsee) {
239 throw nsee;
240 }
241 catch (Exception e) {
242 throw processException(e);
243 }
244 finally {
245 closeSession(session);
246 }
247 }
248
249 @Override
250 protected Image removeImpl(Image image) throws SystemException {
251 image = toUnwrappedModel(image);
252
253 Session session = null;
254
255 try {
256 session = openSession();
257
258 BatchSessionUtil.delete(session, image);
259 }
260 catch (Exception e) {
261 throw processException(e);
262 }
263 finally {
264 closeSession(session);
265 }
266
267 clearCache(image);
268
269 return image;
270 }
271
272 @Override
273 public Image updateImpl(com.liferay.portal.model.Image image, boolean merge)
274 throws SystemException {
275 image = toUnwrappedModel(image);
276
277 boolean isNew = image.isNew();
278
279 ImageModelImpl imageModelImpl = (ImageModelImpl)image;
280
281 Session session = null;
282
283 try {
284 session = openSession();
285
286 BatchSessionUtil.update(session, image, merge);
287
288 image.setNew(false);
289 }
290 catch (Exception e) {
291 throw processException(e);
292 }
293 finally {
294 closeSession(session);
295 }
296
297 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
298
299 if (isNew || !ImageModelImpl.COLUMN_BITMASK_ENABLED) {
300 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
301 }
302
303 else {
304 if ((imageModelImpl.getColumnBitmask() &
305 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LTSIZE.getColumnBitmask()) != 0) {
306 Object[] args = new Object[] {
307 Integer.valueOf(imageModelImpl.getOriginalSize())
308 };
309
310 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_LTSIZE, args);
311 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LTSIZE,
312 args);
313
314 args = new Object[] { Integer.valueOf(imageModelImpl.getSize()) };
315
316 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_LTSIZE, args);
317 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LTSIZE,
318 args);
319 }
320 }
321
322 EntityCacheUtil.putResult(ImageModelImpl.ENTITY_CACHE_ENABLED,
323 ImageImpl.class, image.getPrimaryKey(), image);
324
325 return image;
326 }
327
328 protected Image toUnwrappedModel(Image image) {
329 if (image instanceof ImageImpl) {
330 return image;
331 }
332
333 ImageImpl imageImpl = new ImageImpl();
334
335 imageImpl.setNew(image.isNew());
336 imageImpl.setPrimaryKey(image.getPrimaryKey());
337
338 imageImpl.setImageId(image.getImageId());
339 imageImpl.setModifiedDate(image.getModifiedDate());
340 imageImpl.setText(image.getText());
341 imageImpl.setType(image.getType());
342 imageImpl.setHeight(image.getHeight());
343 imageImpl.setWidth(image.getWidth());
344 imageImpl.setSize(image.getSize());
345
346 return imageImpl;
347 }
348
349
357 @Override
358 public Image findByPrimaryKey(Serializable primaryKey)
359 throws NoSuchModelException, SystemException {
360 return findByPrimaryKey(((Long)primaryKey).longValue());
361 }
362
363
371 public Image findByPrimaryKey(long imageId)
372 throws NoSuchImageException, SystemException {
373 Image image = fetchByPrimaryKey(imageId);
374
375 if (image == null) {
376 if (_log.isWarnEnabled()) {
377 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + imageId);
378 }
379
380 throw new NoSuchImageException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
381 imageId);
382 }
383
384 return image;
385 }
386
387
394 @Override
395 public Image fetchByPrimaryKey(Serializable primaryKey)
396 throws SystemException {
397 return fetchByPrimaryKey(((Long)primaryKey).longValue());
398 }
399
400
407 public Image fetchByPrimaryKey(long imageId) throws SystemException {
408 Image image = (Image)EntityCacheUtil.getResult(ImageModelImpl.ENTITY_CACHE_ENABLED,
409 ImageImpl.class, imageId);
410
411 if (image == _nullImage) {
412 return null;
413 }
414
415 if (image == null) {
416 Session session = null;
417
418 boolean hasException = false;
419
420 try {
421 session = openSession();
422
423 image = (Image)session.get(ImageImpl.class,
424 Long.valueOf(imageId));
425 }
426 catch (Exception e) {
427 hasException = true;
428
429 throw processException(e);
430 }
431 finally {
432 if (image != null) {
433 cacheResult(image);
434 }
435 else if (!hasException) {
436 EntityCacheUtil.putResult(ImageModelImpl.ENTITY_CACHE_ENABLED,
437 ImageImpl.class, imageId, _nullImage);
438 }
439
440 closeSession(session);
441 }
442 }
443
444 return image;
445 }
446
447
454 public List<Image> findByLtSize(int size) throws SystemException {
455 return findByLtSize(size, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
456 }
457
458
471 public List<Image> findByLtSize(int size, int start, int end)
472 throws SystemException {
473 return findByLtSize(size, start, end, null);
474 }
475
476
490 public List<Image> findByLtSize(int size, int start, int end,
491 OrderByComparator orderByComparator) throws SystemException {
492 FinderPath finderPath = null;
493 Object[] finderArgs = null;
494
495 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
496 (orderByComparator == null)) {
497 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LTSIZE;
498 finderArgs = new Object[] { size };
499 }
500 else {
501 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_LTSIZE;
502 finderArgs = new Object[] { size, start, end, orderByComparator };
503 }
504
505 List<Image> list = (List<Image>)FinderCacheUtil.getResult(finderPath,
506 finderArgs, this);
507
508 if (list == null) {
509 StringBundler query = null;
510
511 if (orderByComparator != null) {
512 query = new StringBundler(3 +
513 (orderByComparator.getOrderByFields().length * 3));
514 }
515 else {
516 query = new StringBundler(3);
517 }
518
519 query.append(_SQL_SELECT_IMAGE_WHERE);
520
521 query.append(_FINDER_COLUMN_LTSIZE_SIZE_2);
522
523 if (orderByComparator != null) {
524 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
525 orderByComparator);
526 }
527
528 else {
529 query.append(ImageModelImpl.ORDER_BY_JPQL);
530 }
531
532 String sql = query.toString();
533
534 Session session = null;
535
536 try {
537 session = openSession();
538
539 Query q = session.createQuery(sql);
540
541 QueryPos qPos = QueryPos.getInstance(q);
542
543 qPos.add(size);
544
545 list = (List<Image>)QueryUtil.list(q, getDialect(), start, end);
546 }
547 catch (Exception e) {
548 throw processException(e);
549 }
550 finally {
551 if (list == null) {
552 FinderCacheUtil.removeResult(finderPath, finderArgs);
553 }
554 else {
555 cacheResult(list);
556
557 FinderCacheUtil.putResult(finderPath, finderArgs, list);
558 }
559
560 closeSession(session);
561 }
562 }
563
564 return list;
565 }
566
567
580 public Image findByLtSize_First(int size,
581 OrderByComparator orderByComparator)
582 throws NoSuchImageException, SystemException {
583 List<Image> list = findByLtSize(size, 0, 1, orderByComparator);
584
585 if (list.isEmpty()) {
586 StringBundler msg = new StringBundler(4);
587
588 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
589
590 msg.append("size=");
591 msg.append(size);
592
593 msg.append(StringPool.CLOSE_CURLY_BRACE);
594
595 throw new NoSuchImageException(msg.toString());
596 }
597 else {
598 return list.get(0);
599 }
600 }
601
602
615 public Image findByLtSize_Last(int size, OrderByComparator orderByComparator)
616 throws NoSuchImageException, SystemException {
617 int count = countByLtSize(size);
618
619 List<Image> list = findByLtSize(size, count - 1, count,
620 orderByComparator);
621
622 if (list.isEmpty()) {
623 StringBundler msg = new StringBundler(4);
624
625 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
626
627 msg.append("size=");
628 msg.append(size);
629
630 msg.append(StringPool.CLOSE_CURLY_BRACE);
631
632 throw new NoSuchImageException(msg.toString());
633 }
634 else {
635 return list.get(0);
636 }
637 }
638
639
653 public Image[] findByLtSize_PrevAndNext(long imageId, int size,
654 OrderByComparator orderByComparator)
655 throws NoSuchImageException, SystemException {
656 Image image = findByPrimaryKey(imageId);
657
658 Session session = null;
659
660 try {
661 session = openSession();
662
663 Image[] array = new ImageImpl[3];
664
665 array[0] = getByLtSize_PrevAndNext(session, image, size,
666 orderByComparator, true);
667
668 array[1] = image;
669
670 array[2] = getByLtSize_PrevAndNext(session, image, size,
671 orderByComparator, false);
672
673 return array;
674 }
675 catch (Exception e) {
676 throw processException(e);
677 }
678 finally {
679 closeSession(session);
680 }
681 }
682
683 protected Image getByLtSize_PrevAndNext(Session session, Image image,
684 int size, OrderByComparator orderByComparator, boolean previous) {
685 StringBundler query = null;
686
687 if (orderByComparator != null) {
688 query = new StringBundler(6 +
689 (orderByComparator.getOrderByFields().length * 6));
690 }
691 else {
692 query = new StringBundler(3);
693 }
694
695 query.append(_SQL_SELECT_IMAGE_WHERE);
696
697 query.append(_FINDER_COLUMN_LTSIZE_SIZE_2);
698
699 if (orderByComparator != null) {
700 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
701
702 if (orderByConditionFields.length > 0) {
703 query.append(WHERE_AND);
704 }
705
706 for (int i = 0; i < orderByConditionFields.length; i++) {
707 query.append(_ORDER_BY_ENTITY_ALIAS);
708 query.append(orderByConditionFields[i]);
709
710 if ((i + 1) < orderByConditionFields.length) {
711 if (orderByComparator.isAscending() ^ previous) {
712 query.append(WHERE_GREATER_THAN_HAS_NEXT);
713 }
714 else {
715 query.append(WHERE_LESSER_THAN_HAS_NEXT);
716 }
717 }
718 else {
719 if (orderByComparator.isAscending() ^ previous) {
720 query.append(WHERE_GREATER_THAN);
721 }
722 else {
723 query.append(WHERE_LESSER_THAN);
724 }
725 }
726 }
727
728 query.append(ORDER_BY_CLAUSE);
729
730 String[] orderByFields = orderByComparator.getOrderByFields();
731
732 for (int i = 0; i < orderByFields.length; i++) {
733 query.append(_ORDER_BY_ENTITY_ALIAS);
734 query.append(orderByFields[i]);
735
736 if ((i + 1) < orderByFields.length) {
737 if (orderByComparator.isAscending() ^ previous) {
738 query.append(ORDER_BY_ASC_HAS_NEXT);
739 }
740 else {
741 query.append(ORDER_BY_DESC_HAS_NEXT);
742 }
743 }
744 else {
745 if (orderByComparator.isAscending() ^ previous) {
746 query.append(ORDER_BY_ASC);
747 }
748 else {
749 query.append(ORDER_BY_DESC);
750 }
751 }
752 }
753 }
754
755 else {
756 query.append(ImageModelImpl.ORDER_BY_JPQL);
757 }
758
759 String sql = query.toString();
760
761 Query q = session.createQuery(sql);
762
763 q.setFirstResult(0);
764 q.setMaxResults(2);
765
766 QueryPos qPos = QueryPos.getInstance(q);
767
768 qPos.add(size);
769
770 if (orderByComparator != null) {
771 Object[] values = orderByComparator.getOrderByConditionValues(image);
772
773 for (Object value : values) {
774 qPos.add(value);
775 }
776 }
777
778 List<Image> list = q.list();
779
780 if (list.size() == 2) {
781 return list.get(1);
782 }
783 else {
784 return null;
785 }
786 }
787
788
794 public List<Image> findAll() throws SystemException {
795 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
796 }
797
798
810 public List<Image> findAll(int start, int end) throws SystemException {
811 return findAll(start, end, null);
812 }
813
814
827 public List<Image> findAll(int start, int end,
828 OrderByComparator orderByComparator) throws SystemException {
829 FinderPath finderPath = null;
830 Object[] finderArgs = new Object[] { start, end, orderByComparator };
831
832 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
833 (orderByComparator == null)) {
834 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
835 finderArgs = FINDER_ARGS_EMPTY;
836 }
837 else {
838 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
839 finderArgs = new Object[] { start, end, orderByComparator };
840 }
841
842 List<Image> list = (List<Image>)FinderCacheUtil.getResult(finderPath,
843 finderArgs, this);
844
845 if (list == null) {
846 StringBundler query = null;
847 String sql = null;
848
849 if (orderByComparator != null) {
850 query = new StringBundler(2 +
851 (orderByComparator.getOrderByFields().length * 3));
852
853 query.append(_SQL_SELECT_IMAGE);
854
855 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
856 orderByComparator);
857
858 sql = query.toString();
859 }
860 else {
861 sql = _SQL_SELECT_IMAGE.concat(ImageModelImpl.ORDER_BY_JPQL);
862 }
863
864 Session session = null;
865
866 try {
867 session = openSession();
868
869 Query q = session.createQuery(sql);
870
871 if (orderByComparator == null) {
872 list = (List<Image>)QueryUtil.list(q, getDialect(), start,
873 end, false);
874
875 Collections.sort(list);
876 }
877 else {
878 list = (List<Image>)QueryUtil.list(q, getDialect(), start,
879 end);
880 }
881 }
882 catch (Exception e) {
883 throw processException(e);
884 }
885 finally {
886 if (list == null) {
887 FinderCacheUtil.removeResult(finderPath, finderArgs);
888 }
889 else {
890 cacheResult(list);
891
892 FinderCacheUtil.putResult(finderPath, finderArgs, list);
893 }
894
895 closeSession(session);
896 }
897 }
898
899 return list;
900 }
901
902
908 public void removeByLtSize(int size) throws SystemException {
909 for (Image image : findByLtSize(size)) {
910 remove(image);
911 }
912 }
913
914
919 public void removeAll() throws SystemException {
920 for (Image image : findAll()) {
921 remove(image);
922 }
923 }
924
925
932 public int countByLtSize(int size) throws SystemException {
933 Object[] finderArgs = new Object[] { size };
934
935 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_LTSIZE,
936 finderArgs, this);
937
938 if (count == null) {
939 StringBundler query = new StringBundler(2);
940
941 query.append(_SQL_COUNT_IMAGE_WHERE);
942
943 query.append(_FINDER_COLUMN_LTSIZE_SIZE_2);
944
945 String sql = query.toString();
946
947 Session session = null;
948
949 try {
950 session = openSession();
951
952 Query q = session.createQuery(sql);
953
954 QueryPos qPos = QueryPos.getInstance(q);
955
956 qPos.add(size);
957
958 count = (Long)q.uniqueResult();
959 }
960 catch (Exception e) {
961 throw processException(e);
962 }
963 finally {
964 if (count == null) {
965 count = Long.valueOf(0);
966 }
967
968 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_LTSIZE,
969 finderArgs, count);
970
971 closeSession(session);
972 }
973 }
974
975 return count.intValue();
976 }
977
978
984 public int countAll() throws SystemException {
985 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
986 FINDER_ARGS_EMPTY, this);
987
988 if (count == null) {
989 Session session = null;
990
991 try {
992 session = openSession();
993
994 Query q = session.createQuery(_SQL_COUNT_IMAGE);
995
996 count = (Long)q.uniqueResult();
997 }
998 catch (Exception e) {
999 throw processException(e);
1000 }
1001 finally {
1002 if (count == null) {
1003 count = Long.valueOf(0);
1004 }
1005
1006 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1007 FINDER_ARGS_EMPTY, count);
1008
1009 closeSession(session);
1010 }
1011 }
1012
1013 return count.intValue();
1014 }
1015
1016
1019 public void afterPropertiesSet() {
1020 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1021 com.liferay.portal.util.PropsUtil.get(
1022 "value.object.listener.com.liferay.portal.model.Image")));
1023
1024 if (listenerClassNames.length > 0) {
1025 try {
1026 List<ModelListener<Image>> listenersList = new ArrayList<ModelListener<Image>>();
1027
1028 for (String listenerClassName : listenerClassNames) {
1029 listenersList.add((ModelListener<Image>)InstanceFactory.newInstance(
1030 listenerClassName));
1031 }
1032
1033 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1034 }
1035 catch (Exception e) {
1036 _log.error(e);
1037 }
1038 }
1039 }
1040
1041 public void destroy() {
1042 EntityCacheUtil.removeCache(ImageImpl.class.getName());
1043 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1044 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1045 }
1046
1047 @BeanReference(type = AccountPersistence.class)
1048 protected AccountPersistence accountPersistence;
1049 @BeanReference(type = AddressPersistence.class)
1050 protected AddressPersistence addressPersistence;
1051 @BeanReference(type = BrowserTrackerPersistence.class)
1052 protected BrowserTrackerPersistence browserTrackerPersistence;
1053 @BeanReference(type = ClassNamePersistence.class)
1054 protected ClassNamePersistence classNamePersistence;
1055 @BeanReference(type = ClusterGroupPersistence.class)
1056 protected ClusterGroupPersistence clusterGroupPersistence;
1057 @BeanReference(type = CompanyPersistence.class)
1058 protected CompanyPersistence companyPersistence;
1059 @BeanReference(type = ContactPersistence.class)
1060 protected ContactPersistence contactPersistence;
1061 @BeanReference(type = CountryPersistence.class)
1062 protected CountryPersistence countryPersistence;
1063 @BeanReference(type = EmailAddressPersistence.class)
1064 protected EmailAddressPersistence emailAddressPersistence;
1065 @BeanReference(type = GroupPersistence.class)
1066 protected GroupPersistence groupPersistence;
1067 @BeanReference(type = ImagePersistence.class)
1068 protected ImagePersistence imagePersistence;
1069 @BeanReference(type = LayoutPersistence.class)
1070 protected LayoutPersistence layoutPersistence;
1071 @BeanReference(type = LayoutBranchPersistence.class)
1072 protected LayoutBranchPersistence layoutBranchPersistence;
1073 @BeanReference(type = LayoutPrototypePersistence.class)
1074 protected LayoutPrototypePersistence layoutPrototypePersistence;
1075 @BeanReference(type = LayoutRevisionPersistence.class)
1076 protected LayoutRevisionPersistence layoutRevisionPersistence;
1077 @BeanReference(type = LayoutSetPersistence.class)
1078 protected LayoutSetPersistence layoutSetPersistence;
1079 @BeanReference(type = LayoutSetBranchPersistence.class)
1080 protected LayoutSetBranchPersistence layoutSetBranchPersistence;
1081 @BeanReference(type = LayoutSetPrototypePersistence.class)
1082 protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
1083 @BeanReference(type = ListTypePersistence.class)
1084 protected ListTypePersistence listTypePersistence;
1085 @BeanReference(type = LockPersistence.class)
1086 protected LockPersistence lockPersistence;
1087 @BeanReference(type = MembershipRequestPersistence.class)
1088 protected MembershipRequestPersistence membershipRequestPersistence;
1089 @BeanReference(type = OrganizationPersistence.class)
1090 protected OrganizationPersistence organizationPersistence;
1091 @BeanReference(type = OrgGroupPermissionPersistence.class)
1092 protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1093 @BeanReference(type = OrgGroupRolePersistence.class)
1094 protected OrgGroupRolePersistence orgGroupRolePersistence;
1095 @BeanReference(type = OrgLaborPersistence.class)
1096 protected OrgLaborPersistence orgLaborPersistence;
1097 @BeanReference(type = PasswordPolicyPersistence.class)
1098 protected PasswordPolicyPersistence passwordPolicyPersistence;
1099 @BeanReference(type = PasswordPolicyRelPersistence.class)
1100 protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1101 @BeanReference(type = PasswordTrackerPersistence.class)
1102 protected PasswordTrackerPersistence passwordTrackerPersistence;
1103 @BeanReference(type = PermissionPersistence.class)
1104 protected PermissionPersistence permissionPersistence;
1105 @BeanReference(type = PhonePersistence.class)
1106 protected PhonePersistence phonePersistence;
1107 @BeanReference(type = PluginSettingPersistence.class)
1108 protected PluginSettingPersistence pluginSettingPersistence;
1109 @BeanReference(type = PortalPreferencesPersistence.class)
1110 protected PortalPreferencesPersistence portalPreferencesPersistence;
1111 @BeanReference(type = PortletPersistence.class)
1112 protected PortletPersistence portletPersistence;
1113 @BeanReference(type = PortletItemPersistence.class)
1114 protected PortletItemPersistence portletItemPersistence;
1115 @BeanReference(type = PortletPreferencesPersistence.class)
1116 protected PortletPreferencesPersistence portletPreferencesPersistence;
1117 @BeanReference(type = RegionPersistence.class)
1118 protected RegionPersistence regionPersistence;
1119 @BeanReference(type = ReleasePersistence.class)
1120 protected ReleasePersistence releasePersistence;
1121 @BeanReference(type = RepositoryPersistence.class)
1122 protected RepositoryPersistence repositoryPersistence;
1123 @BeanReference(type = RepositoryEntryPersistence.class)
1124 protected RepositoryEntryPersistence repositoryEntryPersistence;
1125 @BeanReference(type = ResourcePersistence.class)
1126 protected ResourcePersistence resourcePersistence;
1127 @BeanReference(type = ResourceActionPersistence.class)
1128 protected ResourceActionPersistence resourceActionPersistence;
1129 @BeanReference(type = ResourceBlockPersistence.class)
1130 protected ResourceBlockPersistence resourceBlockPersistence;
1131 @BeanReference(type = ResourceBlockPermissionPersistence.class)
1132 protected ResourceBlockPermissionPersistence resourceBlockPermissionPersistence;
1133 @BeanReference(type = ResourceCodePersistence.class)
1134 protected ResourceCodePersistence resourceCodePersistence;
1135 @BeanReference(type = ResourcePermissionPersistence.class)
1136 protected ResourcePermissionPersistence resourcePermissionPersistence;
1137 @BeanReference(type = ResourceTypePermissionPersistence.class)
1138 protected ResourceTypePermissionPersistence resourceTypePermissionPersistence;
1139 @BeanReference(type = RolePersistence.class)
1140 protected RolePersistence rolePersistence;
1141 @BeanReference(type = ServiceComponentPersistence.class)
1142 protected ServiceComponentPersistence serviceComponentPersistence;
1143 @BeanReference(type = ShardPersistence.class)
1144 protected ShardPersistence shardPersistence;
1145 @BeanReference(type = SubscriptionPersistence.class)
1146 protected SubscriptionPersistence subscriptionPersistence;
1147 @BeanReference(type = TeamPersistence.class)
1148 protected TeamPersistence teamPersistence;
1149 @BeanReference(type = TicketPersistence.class)
1150 protected TicketPersistence ticketPersistence;
1151 @BeanReference(type = UserPersistence.class)
1152 protected UserPersistence userPersistence;
1153 @BeanReference(type = UserGroupPersistence.class)
1154 protected UserGroupPersistence userGroupPersistence;
1155 @BeanReference(type = UserGroupGroupRolePersistence.class)
1156 protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
1157 @BeanReference(type = UserGroupRolePersistence.class)
1158 protected UserGroupRolePersistence userGroupRolePersistence;
1159 @BeanReference(type = UserIdMapperPersistence.class)
1160 protected UserIdMapperPersistence userIdMapperPersistence;
1161 @BeanReference(type = UserNotificationEventPersistence.class)
1162 protected UserNotificationEventPersistence userNotificationEventPersistence;
1163 @BeanReference(type = UserTrackerPersistence.class)
1164 protected UserTrackerPersistence userTrackerPersistence;
1165 @BeanReference(type = UserTrackerPathPersistence.class)
1166 protected UserTrackerPathPersistence userTrackerPathPersistence;
1167 @BeanReference(type = VirtualHostPersistence.class)
1168 protected VirtualHostPersistence virtualHostPersistence;
1169 @BeanReference(type = WebDAVPropsPersistence.class)
1170 protected WebDAVPropsPersistence webDAVPropsPersistence;
1171 @BeanReference(type = WebsitePersistence.class)
1172 protected WebsitePersistence websitePersistence;
1173 @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
1174 protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
1175 @BeanReference(type = WorkflowInstanceLinkPersistence.class)
1176 protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
1177 @BeanReference(type = DLFileEntryPersistence.class)
1178 protected DLFileEntryPersistence dlFileEntryPersistence;
1179 private static final String _SQL_SELECT_IMAGE = "SELECT image FROM Image image";
1180 private static final String _SQL_SELECT_IMAGE_WHERE = "SELECT image FROM Image image WHERE ";
1181 private static final String _SQL_COUNT_IMAGE = "SELECT COUNT(image) FROM Image image";
1182 private static final String _SQL_COUNT_IMAGE_WHERE = "SELECT COUNT(image) FROM Image image WHERE ";
1183 private static final String _FINDER_COLUMN_LTSIZE_SIZE_2 = "image.size < ?";
1184 private static final String _ORDER_BY_ENTITY_ALIAS = "image.";
1185 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Image exists with the primary key ";
1186 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Image exists with the key {";
1187 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1188 private static Log _log = LogFactoryUtil.getLog(ImagePersistenceImpl.class);
1189 private static Image _nullImage = new ImageImpl() {
1190 @Override
1191 public Object clone() {
1192 return this;
1193 }
1194
1195 @Override
1196 public CacheModel<Image> toCacheModel() {
1197 return _nullImageCacheModel;
1198 }
1199 };
1200
1201 private static CacheModel<Image> _nullImageCacheModel = new CacheModel<Image>() {
1202 public Image toEntityModel() {
1203 return _nullImage;
1204 }
1205 };
1206 }