001
014
015 package com.liferay.portlet.softwarecatalog.service.persistence;
016
017 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
018 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
019 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
020 import com.liferay.portal.kernel.dao.orm.FinderPath;
021 import com.liferay.portal.kernel.dao.orm.Query;
022 import com.liferay.portal.kernel.dao.orm.QueryPos;
023 import com.liferay.portal.kernel.dao.orm.QueryUtil;
024 import com.liferay.portal.kernel.dao.orm.Session;
025 import com.liferay.portal.kernel.exception.SystemException;
026 import com.liferay.portal.kernel.log.Log;
027 import com.liferay.portal.kernel.log.LogFactoryUtil;
028 import com.liferay.portal.kernel.util.GetterUtil;
029 import com.liferay.portal.kernel.util.InstanceFactory;
030 import com.liferay.portal.kernel.util.OrderByComparator;
031 import com.liferay.portal.kernel.util.StringBundler;
032 import com.liferay.portal.kernel.util.StringPool;
033 import com.liferay.portal.kernel.util.StringUtil;
034 import com.liferay.portal.kernel.util.UnmodifiableList;
035 import com.liferay.portal.model.CacheModel;
036 import com.liferay.portal.model.ModelListener;
037 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
038
039 import com.liferay.portlet.softwarecatalog.NoSuchProductScreenshotException;
040 import com.liferay.portlet.softwarecatalog.model.SCProductScreenshot;
041 import com.liferay.portlet.softwarecatalog.model.impl.SCProductScreenshotImpl;
042 import com.liferay.portlet.softwarecatalog.model.impl.SCProductScreenshotModelImpl;
043
044 import java.io.Serializable;
045
046 import java.util.ArrayList;
047 import java.util.Collections;
048 import java.util.List;
049
050
062 public class SCProductScreenshotPersistenceImpl extends BasePersistenceImpl<SCProductScreenshot>
063 implements SCProductScreenshotPersistence {
064
069 public static final String FINDER_CLASS_NAME_ENTITY = SCProductScreenshotImpl.class.getName();
070 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
071 ".List1";
072 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
073 ".List2";
074 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(SCProductScreenshotModelImpl.ENTITY_CACHE_ENABLED,
075 SCProductScreenshotModelImpl.FINDER_CACHE_ENABLED,
076 SCProductScreenshotImpl.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(SCProductScreenshotModelImpl.ENTITY_CACHE_ENABLED,
079 SCProductScreenshotModelImpl.FINDER_CACHE_ENABLED,
080 SCProductScreenshotImpl.class,
081 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
082 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(SCProductScreenshotModelImpl.ENTITY_CACHE_ENABLED,
083 SCProductScreenshotModelImpl.FINDER_CACHE_ENABLED, Long.class,
084 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
085 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_PRODUCTENTRYID =
086 new FinderPath(SCProductScreenshotModelImpl.ENTITY_CACHE_ENABLED,
087 SCProductScreenshotModelImpl.FINDER_CACHE_ENABLED,
088 SCProductScreenshotImpl.class,
089 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByProductEntryId",
090 new String[] {
091 Long.class.getName(),
092
093 Integer.class.getName(), Integer.class.getName(),
094 OrderByComparator.class.getName()
095 });
096 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PRODUCTENTRYID =
097 new FinderPath(SCProductScreenshotModelImpl.ENTITY_CACHE_ENABLED,
098 SCProductScreenshotModelImpl.FINDER_CACHE_ENABLED,
099 SCProductScreenshotImpl.class,
100 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByProductEntryId",
101 new String[] { Long.class.getName() },
102 SCProductScreenshotModelImpl.PRODUCTENTRYID_COLUMN_BITMASK |
103 SCProductScreenshotModelImpl.PRIORITY_COLUMN_BITMASK);
104 public static final FinderPath FINDER_PATH_COUNT_BY_PRODUCTENTRYID = new FinderPath(SCProductScreenshotModelImpl.ENTITY_CACHE_ENABLED,
105 SCProductScreenshotModelImpl.FINDER_CACHE_ENABLED, Long.class,
106 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByProductEntryId",
107 new String[] { Long.class.getName() });
108
109
116 public List<SCProductScreenshot> findByProductEntryId(long productEntryId)
117 throws SystemException {
118 return findByProductEntryId(productEntryId, QueryUtil.ALL_POS,
119 QueryUtil.ALL_POS, null);
120 }
121
122
135 public List<SCProductScreenshot> findByProductEntryId(long productEntryId,
136 int start, int end) throws SystemException {
137 return findByProductEntryId(productEntryId, start, end, null);
138 }
139
140
154 public List<SCProductScreenshot> findByProductEntryId(long productEntryId,
155 int start, int end, OrderByComparator orderByComparator)
156 throws SystemException {
157 boolean pagination = true;
158 FinderPath finderPath = null;
159 Object[] finderArgs = null;
160
161 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
162 (orderByComparator == null)) {
163 pagination = false;
164 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PRODUCTENTRYID;
165 finderArgs = new Object[] { productEntryId };
166 }
167 else {
168 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_PRODUCTENTRYID;
169 finderArgs = new Object[] {
170 productEntryId,
171
172 start, end, orderByComparator
173 };
174 }
175
176 List<SCProductScreenshot> list = (List<SCProductScreenshot>)FinderCacheUtil.getResult(finderPath,
177 finderArgs, this);
178
179 if ((list != null) && !list.isEmpty()) {
180 for (SCProductScreenshot scProductScreenshot : list) {
181 if ((productEntryId != scProductScreenshot.getProductEntryId())) {
182 list = null;
183
184 break;
185 }
186 }
187 }
188
189 if (list == null) {
190 StringBundler query = null;
191
192 if (orderByComparator != null) {
193 query = new StringBundler(3 +
194 (orderByComparator.getOrderByFields().length * 3));
195 }
196 else {
197 query = new StringBundler(3);
198 }
199
200 query.append(_SQL_SELECT_SCPRODUCTSCREENSHOT_WHERE);
201
202 query.append(_FINDER_COLUMN_PRODUCTENTRYID_PRODUCTENTRYID_2);
203
204 if (orderByComparator != null) {
205 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
206 orderByComparator);
207 }
208 else
209 if (pagination) {
210 query.append(SCProductScreenshotModelImpl.ORDER_BY_JPQL);
211 }
212
213 String sql = query.toString();
214
215 Session session = null;
216
217 try {
218 session = openSession();
219
220 Query q = session.createQuery(sql);
221
222 QueryPos qPos = QueryPos.getInstance(q);
223
224 qPos.add(productEntryId);
225
226 if (!pagination) {
227 list = (List<SCProductScreenshot>)QueryUtil.list(q,
228 getDialect(), start, end, false);
229
230 Collections.sort(list);
231
232 list = new UnmodifiableList<SCProductScreenshot>(list);
233 }
234 else {
235 list = (List<SCProductScreenshot>)QueryUtil.list(q,
236 getDialect(), start, end);
237 }
238
239 cacheResult(list);
240
241 FinderCacheUtil.putResult(finderPath, finderArgs, list);
242 }
243 catch (Exception e) {
244 FinderCacheUtil.removeResult(finderPath, finderArgs);
245
246 throw processException(e);
247 }
248 finally {
249 closeSession(session);
250 }
251 }
252
253 return list;
254 }
255
256
265 public SCProductScreenshot findByProductEntryId_First(long productEntryId,
266 OrderByComparator orderByComparator)
267 throws NoSuchProductScreenshotException, SystemException {
268 SCProductScreenshot scProductScreenshot = fetchByProductEntryId_First(productEntryId,
269 orderByComparator);
270
271 if (scProductScreenshot != null) {
272 return scProductScreenshot;
273 }
274
275 StringBundler msg = new StringBundler(4);
276
277 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
278
279 msg.append("productEntryId=");
280 msg.append(productEntryId);
281
282 msg.append(StringPool.CLOSE_CURLY_BRACE);
283
284 throw new NoSuchProductScreenshotException(msg.toString());
285 }
286
287
295 public SCProductScreenshot fetchByProductEntryId_First(
296 long productEntryId, OrderByComparator orderByComparator)
297 throws SystemException {
298 List<SCProductScreenshot> list = findByProductEntryId(productEntryId,
299 0, 1, orderByComparator);
300
301 if (!list.isEmpty()) {
302 return list.get(0);
303 }
304
305 return null;
306 }
307
308
317 public SCProductScreenshot findByProductEntryId_Last(long productEntryId,
318 OrderByComparator orderByComparator)
319 throws NoSuchProductScreenshotException, SystemException {
320 SCProductScreenshot scProductScreenshot = fetchByProductEntryId_Last(productEntryId,
321 orderByComparator);
322
323 if (scProductScreenshot != null) {
324 return scProductScreenshot;
325 }
326
327 StringBundler msg = new StringBundler(4);
328
329 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
330
331 msg.append("productEntryId=");
332 msg.append(productEntryId);
333
334 msg.append(StringPool.CLOSE_CURLY_BRACE);
335
336 throw new NoSuchProductScreenshotException(msg.toString());
337 }
338
339
347 public SCProductScreenshot fetchByProductEntryId_Last(long productEntryId,
348 OrderByComparator orderByComparator) throws SystemException {
349 int count = countByProductEntryId(productEntryId);
350
351 List<SCProductScreenshot> list = findByProductEntryId(productEntryId,
352 count - 1, count, orderByComparator);
353
354 if (!list.isEmpty()) {
355 return list.get(0);
356 }
357
358 return null;
359 }
360
361
371 public SCProductScreenshot[] findByProductEntryId_PrevAndNext(
372 long productScreenshotId, long productEntryId,
373 OrderByComparator orderByComparator)
374 throws NoSuchProductScreenshotException, SystemException {
375 SCProductScreenshot scProductScreenshot = findByPrimaryKey(productScreenshotId);
376
377 Session session = null;
378
379 try {
380 session = openSession();
381
382 SCProductScreenshot[] array = new SCProductScreenshotImpl[3];
383
384 array[0] = getByProductEntryId_PrevAndNext(session,
385 scProductScreenshot, productEntryId, orderByComparator, true);
386
387 array[1] = scProductScreenshot;
388
389 array[2] = getByProductEntryId_PrevAndNext(session,
390 scProductScreenshot, productEntryId, orderByComparator,
391 false);
392
393 return array;
394 }
395 catch (Exception e) {
396 throw processException(e);
397 }
398 finally {
399 closeSession(session);
400 }
401 }
402
403 protected SCProductScreenshot getByProductEntryId_PrevAndNext(
404 Session session, SCProductScreenshot scProductScreenshot,
405 long productEntryId, OrderByComparator orderByComparator,
406 boolean previous) {
407 StringBundler query = null;
408
409 if (orderByComparator != null) {
410 query = new StringBundler(6 +
411 (orderByComparator.getOrderByFields().length * 6));
412 }
413 else {
414 query = new StringBundler(3);
415 }
416
417 query.append(_SQL_SELECT_SCPRODUCTSCREENSHOT_WHERE);
418
419 query.append(_FINDER_COLUMN_PRODUCTENTRYID_PRODUCTENTRYID_2);
420
421 if (orderByComparator != null) {
422 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
423
424 if (orderByConditionFields.length > 0) {
425 query.append(WHERE_AND);
426 }
427
428 for (int i = 0; i < orderByConditionFields.length; i++) {
429 query.append(_ORDER_BY_ENTITY_ALIAS);
430 query.append(orderByConditionFields[i]);
431
432 if ((i + 1) < orderByConditionFields.length) {
433 if (orderByComparator.isAscending() ^ previous) {
434 query.append(WHERE_GREATER_THAN_HAS_NEXT);
435 }
436 else {
437 query.append(WHERE_LESSER_THAN_HAS_NEXT);
438 }
439 }
440 else {
441 if (orderByComparator.isAscending() ^ previous) {
442 query.append(WHERE_GREATER_THAN);
443 }
444 else {
445 query.append(WHERE_LESSER_THAN);
446 }
447 }
448 }
449
450 query.append(ORDER_BY_CLAUSE);
451
452 String[] orderByFields = orderByComparator.getOrderByFields();
453
454 for (int i = 0; i < orderByFields.length; i++) {
455 query.append(_ORDER_BY_ENTITY_ALIAS);
456 query.append(orderByFields[i]);
457
458 if ((i + 1) < orderByFields.length) {
459 if (orderByComparator.isAscending() ^ previous) {
460 query.append(ORDER_BY_ASC_HAS_NEXT);
461 }
462 else {
463 query.append(ORDER_BY_DESC_HAS_NEXT);
464 }
465 }
466 else {
467 if (orderByComparator.isAscending() ^ previous) {
468 query.append(ORDER_BY_ASC);
469 }
470 else {
471 query.append(ORDER_BY_DESC);
472 }
473 }
474 }
475 }
476 else {
477 query.append(SCProductScreenshotModelImpl.ORDER_BY_JPQL);
478 }
479
480 String sql = query.toString();
481
482 Query q = session.createQuery(sql);
483
484 q.setFirstResult(0);
485 q.setMaxResults(2);
486
487 QueryPos qPos = QueryPos.getInstance(q);
488
489 qPos.add(productEntryId);
490
491 if (orderByComparator != null) {
492 Object[] values = orderByComparator.getOrderByConditionValues(scProductScreenshot);
493
494 for (Object value : values) {
495 qPos.add(value);
496 }
497 }
498
499 List<SCProductScreenshot> list = q.list();
500
501 if (list.size() == 2) {
502 return list.get(1);
503 }
504 else {
505 return null;
506 }
507 }
508
509
515 public void removeByProductEntryId(long productEntryId)
516 throws SystemException {
517 for (SCProductScreenshot scProductScreenshot : findByProductEntryId(
518 productEntryId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
519 remove(scProductScreenshot);
520 }
521 }
522
523
530 public int countByProductEntryId(long productEntryId)
531 throws SystemException {
532 FinderPath finderPath = FINDER_PATH_COUNT_BY_PRODUCTENTRYID;
533
534 Object[] finderArgs = new Object[] { productEntryId };
535
536 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
537 this);
538
539 if (count == null) {
540 StringBundler query = new StringBundler(2);
541
542 query.append(_SQL_COUNT_SCPRODUCTSCREENSHOT_WHERE);
543
544 query.append(_FINDER_COLUMN_PRODUCTENTRYID_PRODUCTENTRYID_2);
545
546 String sql = query.toString();
547
548 Session session = null;
549
550 try {
551 session = openSession();
552
553 Query q = session.createQuery(sql);
554
555 QueryPos qPos = QueryPos.getInstance(q);
556
557 qPos.add(productEntryId);
558
559 count = (Long)q.uniqueResult();
560
561 FinderCacheUtil.putResult(finderPath, finderArgs, count);
562 }
563 catch (Exception e) {
564 FinderCacheUtil.removeResult(finderPath, finderArgs);
565
566 throw processException(e);
567 }
568 finally {
569 closeSession(session);
570 }
571 }
572
573 return count.intValue();
574 }
575
576 private static final String _FINDER_COLUMN_PRODUCTENTRYID_PRODUCTENTRYID_2 = "scProductScreenshot.productEntryId = ?";
577 public static final FinderPath FINDER_PATH_FETCH_BY_THUMBNAILID = new FinderPath(SCProductScreenshotModelImpl.ENTITY_CACHE_ENABLED,
578 SCProductScreenshotModelImpl.FINDER_CACHE_ENABLED,
579 SCProductScreenshotImpl.class, FINDER_CLASS_NAME_ENTITY,
580 "fetchByThumbnailId", new String[] { Long.class.getName() },
581 SCProductScreenshotModelImpl.THUMBNAILID_COLUMN_BITMASK);
582 public static final FinderPath FINDER_PATH_COUNT_BY_THUMBNAILID = new FinderPath(SCProductScreenshotModelImpl.ENTITY_CACHE_ENABLED,
583 SCProductScreenshotModelImpl.FINDER_CACHE_ENABLED, Long.class,
584 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByThumbnailId",
585 new String[] { Long.class.getName() });
586
587
595 public SCProductScreenshot findByThumbnailId(long thumbnailId)
596 throws NoSuchProductScreenshotException, SystemException {
597 SCProductScreenshot scProductScreenshot = fetchByThumbnailId(thumbnailId);
598
599 if (scProductScreenshot == null) {
600 StringBundler msg = new StringBundler(4);
601
602 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
603
604 msg.append("thumbnailId=");
605 msg.append(thumbnailId);
606
607 msg.append(StringPool.CLOSE_CURLY_BRACE);
608
609 if (_log.isWarnEnabled()) {
610 _log.warn(msg.toString());
611 }
612
613 throw new NoSuchProductScreenshotException(msg.toString());
614 }
615
616 return scProductScreenshot;
617 }
618
619
626 public SCProductScreenshot fetchByThumbnailId(long thumbnailId)
627 throws SystemException {
628 return fetchByThumbnailId(thumbnailId, true);
629 }
630
631
639 public SCProductScreenshot fetchByThumbnailId(long thumbnailId,
640 boolean retrieveFromCache) throws SystemException {
641 Object[] finderArgs = new Object[] { thumbnailId };
642
643 Object result = null;
644
645 if (retrieveFromCache) {
646 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_THUMBNAILID,
647 finderArgs, this);
648 }
649
650 if (result instanceof SCProductScreenshot) {
651 SCProductScreenshot scProductScreenshot = (SCProductScreenshot)result;
652
653 if ((thumbnailId != scProductScreenshot.getThumbnailId())) {
654 result = null;
655 }
656 }
657
658 if (result == null) {
659 StringBundler query = new StringBundler(3);
660
661 query.append(_SQL_SELECT_SCPRODUCTSCREENSHOT_WHERE);
662
663 query.append(_FINDER_COLUMN_THUMBNAILID_THUMBNAILID_2);
664
665 String sql = query.toString();
666
667 Session session = null;
668
669 try {
670 session = openSession();
671
672 Query q = session.createQuery(sql);
673
674 QueryPos qPos = QueryPos.getInstance(q);
675
676 qPos.add(thumbnailId);
677
678 List<SCProductScreenshot> list = q.list();
679
680 if (list.isEmpty()) {
681 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_THUMBNAILID,
682 finderArgs, list);
683 }
684 else {
685 if ((list.size() > 1) && _log.isWarnEnabled()) {
686 _log.warn(
687 "SCProductScreenshotPersistenceImpl.fetchByThumbnailId(long, boolean) with parameters (" +
688 StringUtil.merge(finderArgs) +
689 ") yields a result set with more than 1 result. This violates the logical unique restriction. There is no order guarantee on which result is returned by this finder.");
690 }
691
692 SCProductScreenshot scProductScreenshot = list.get(0);
693
694 result = scProductScreenshot;
695
696 cacheResult(scProductScreenshot);
697
698 if ((scProductScreenshot.getThumbnailId() != thumbnailId)) {
699 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_THUMBNAILID,
700 finderArgs, scProductScreenshot);
701 }
702 }
703 }
704 catch (Exception e) {
705 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_THUMBNAILID,
706 finderArgs);
707
708 throw processException(e);
709 }
710 finally {
711 closeSession(session);
712 }
713 }
714
715 if (result instanceof List<?>) {
716 return null;
717 }
718 else {
719 return (SCProductScreenshot)result;
720 }
721 }
722
723
730 public SCProductScreenshot removeByThumbnailId(long thumbnailId)
731 throws NoSuchProductScreenshotException, SystemException {
732 SCProductScreenshot scProductScreenshot = findByThumbnailId(thumbnailId);
733
734 return remove(scProductScreenshot);
735 }
736
737
744 public int countByThumbnailId(long thumbnailId) throws SystemException {
745 FinderPath finderPath = FINDER_PATH_COUNT_BY_THUMBNAILID;
746
747 Object[] finderArgs = new Object[] { thumbnailId };
748
749 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
750 this);
751
752 if (count == null) {
753 StringBundler query = new StringBundler(2);
754
755 query.append(_SQL_COUNT_SCPRODUCTSCREENSHOT_WHERE);
756
757 query.append(_FINDER_COLUMN_THUMBNAILID_THUMBNAILID_2);
758
759 String sql = query.toString();
760
761 Session session = null;
762
763 try {
764 session = openSession();
765
766 Query q = session.createQuery(sql);
767
768 QueryPos qPos = QueryPos.getInstance(q);
769
770 qPos.add(thumbnailId);
771
772 count = (Long)q.uniqueResult();
773
774 FinderCacheUtil.putResult(finderPath, finderArgs, count);
775 }
776 catch (Exception e) {
777 FinderCacheUtil.removeResult(finderPath, finderArgs);
778
779 throw processException(e);
780 }
781 finally {
782 closeSession(session);
783 }
784 }
785
786 return count.intValue();
787 }
788
789 private static final String _FINDER_COLUMN_THUMBNAILID_THUMBNAILID_2 = "scProductScreenshot.thumbnailId = ?";
790 public static final FinderPath FINDER_PATH_FETCH_BY_FULLIMAGEID = new FinderPath(SCProductScreenshotModelImpl.ENTITY_CACHE_ENABLED,
791 SCProductScreenshotModelImpl.FINDER_CACHE_ENABLED,
792 SCProductScreenshotImpl.class, FINDER_CLASS_NAME_ENTITY,
793 "fetchByFullImageId", new String[] { Long.class.getName() },
794 SCProductScreenshotModelImpl.FULLIMAGEID_COLUMN_BITMASK);
795 public static final FinderPath FINDER_PATH_COUNT_BY_FULLIMAGEID = new FinderPath(SCProductScreenshotModelImpl.ENTITY_CACHE_ENABLED,
796 SCProductScreenshotModelImpl.FINDER_CACHE_ENABLED, Long.class,
797 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByFullImageId",
798 new String[] { Long.class.getName() });
799
800
808 public SCProductScreenshot findByFullImageId(long fullImageId)
809 throws NoSuchProductScreenshotException, SystemException {
810 SCProductScreenshot scProductScreenshot = fetchByFullImageId(fullImageId);
811
812 if (scProductScreenshot == null) {
813 StringBundler msg = new StringBundler(4);
814
815 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
816
817 msg.append("fullImageId=");
818 msg.append(fullImageId);
819
820 msg.append(StringPool.CLOSE_CURLY_BRACE);
821
822 if (_log.isWarnEnabled()) {
823 _log.warn(msg.toString());
824 }
825
826 throw new NoSuchProductScreenshotException(msg.toString());
827 }
828
829 return scProductScreenshot;
830 }
831
832
839 public SCProductScreenshot fetchByFullImageId(long fullImageId)
840 throws SystemException {
841 return fetchByFullImageId(fullImageId, true);
842 }
843
844
852 public SCProductScreenshot fetchByFullImageId(long fullImageId,
853 boolean retrieveFromCache) throws SystemException {
854 Object[] finderArgs = new Object[] { fullImageId };
855
856 Object result = null;
857
858 if (retrieveFromCache) {
859 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_FULLIMAGEID,
860 finderArgs, this);
861 }
862
863 if (result instanceof SCProductScreenshot) {
864 SCProductScreenshot scProductScreenshot = (SCProductScreenshot)result;
865
866 if ((fullImageId != scProductScreenshot.getFullImageId())) {
867 result = null;
868 }
869 }
870
871 if (result == null) {
872 StringBundler query = new StringBundler(3);
873
874 query.append(_SQL_SELECT_SCPRODUCTSCREENSHOT_WHERE);
875
876 query.append(_FINDER_COLUMN_FULLIMAGEID_FULLIMAGEID_2);
877
878 String sql = query.toString();
879
880 Session session = null;
881
882 try {
883 session = openSession();
884
885 Query q = session.createQuery(sql);
886
887 QueryPos qPos = QueryPos.getInstance(q);
888
889 qPos.add(fullImageId);
890
891 List<SCProductScreenshot> list = q.list();
892
893 if (list.isEmpty()) {
894 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_FULLIMAGEID,
895 finderArgs, list);
896 }
897 else {
898 if ((list.size() > 1) && _log.isWarnEnabled()) {
899 _log.warn(
900 "SCProductScreenshotPersistenceImpl.fetchByFullImageId(long, boolean) with parameters (" +
901 StringUtil.merge(finderArgs) +
902 ") yields a result set with more than 1 result. This violates the logical unique restriction. There is no order guarantee on which result is returned by this finder.");
903 }
904
905 SCProductScreenshot scProductScreenshot = list.get(0);
906
907 result = scProductScreenshot;
908
909 cacheResult(scProductScreenshot);
910
911 if ((scProductScreenshot.getFullImageId() != fullImageId)) {
912 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_FULLIMAGEID,
913 finderArgs, scProductScreenshot);
914 }
915 }
916 }
917 catch (Exception e) {
918 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_FULLIMAGEID,
919 finderArgs);
920
921 throw processException(e);
922 }
923 finally {
924 closeSession(session);
925 }
926 }
927
928 if (result instanceof List<?>) {
929 return null;
930 }
931 else {
932 return (SCProductScreenshot)result;
933 }
934 }
935
936
943 public SCProductScreenshot removeByFullImageId(long fullImageId)
944 throws NoSuchProductScreenshotException, SystemException {
945 SCProductScreenshot scProductScreenshot = findByFullImageId(fullImageId);
946
947 return remove(scProductScreenshot);
948 }
949
950
957 public int countByFullImageId(long fullImageId) throws SystemException {
958 FinderPath finderPath = FINDER_PATH_COUNT_BY_FULLIMAGEID;
959
960 Object[] finderArgs = new Object[] { fullImageId };
961
962 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
963 this);
964
965 if (count == null) {
966 StringBundler query = new StringBundler(2);
967
968 query.append(_SQL_COUNT_SCPRODUCTSCREENSHOT_WHERE);
969
970 query.append(_FINDER_COLUMN_FULLIMAGEID_FULLIMAGEID_2);
971
972 String sql = query.toString();
973
974 Session session = null;
975
976 try {
977 session = openSession();
978
979 Query q = session.createQuery(sql);
980
981 QueryPos qPos = QueryPos.getInstance(q);
982
983 qPos.add(fullImageId);
984
985 count = (Long)q.uniqueResult();
986
987 FinderCacheUtil.putResult(finderPath, finderArgs, count);
988 }
989 catch (Exception e) {
990 FinderCacheUtil.removeResult(finderPath, finderArgs);
991
992 throw processException(e);
993 }
994 finally {
995 closeSession(session);
996 }
997 }
998
999 return count.intValue();
1000 }
1001
1002 private static final String _FINDER_COLUMN_FULLIMAGEID_FULLIMAGEID_2 = "scProductScreenshot.fullImageId = ?";
1003 public static final FinderPath FINDER_PATH_FETCH_BY_P_P = new FinderPath(SCProductScreenshotModelImpl.ENTITY_CACHE_ENABLED,
1004 SCProductScreenshotModelImpl.FINDER_CACHE_ENABLED,
1005 SCProductScreenshotImpl.class, FINDER_CLASS_NAME_ENTITY,
1006 "fetchByP_P",
1007 new String[] { Long.class.getName(), Integer.class.getName() },
1008 SCProductScreenshotModelImpl.PRODUCTENTRYID_COLUMN_BITMASK |
1009 SCProductScreenshotModelImpl.PRIORITY_COLUMN_BITMASK);
1010 public static final FinderPath FINDER_PATH_COUNT_BY_P_P = new FinderPath(SCProductScreenshotModelImpl.ENTITY_CACHE_ENABLED,
1011 SCProductScreenshotModelImpl.FINDER_CACHE_ENABLED, Long.class,
1012 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByP_P",
1013 new String[] { Long.class.getName(), Integer.class.getName() });
1014
1015
1024 public SCProductScreenshot findByP_P(long productEntryId, int priority)
1025 throws NoSuchProductScreenshotException, SystemException {
1026 SCProductScreenshot scProductScreenshot = fetchByP_P(productEntryId,
1027 priority);
1028
1029 if (scProductScreenshot == null) {
1030 StringBundler msg = new StringBundler(6);
1031
1032 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1033
1034 msg.append("productEntryId=");
1035 msg.append(productEntryId);
1036
1037 msg.append(", priority=");
1038 msg.append(priority);
1039
1040 msg.append(StringPool.CLOSE_CURLY_BRACE);
1041
1042 if (_log.isWarnEnabled()) {
1043 _log.warn(msg.toString());
1044 }
1045
1046 throw new NoSuchProductScreenshotException(msg.toString());
1047 }
1048
1049 return scProductScreenshot;
1050 }
1051
1052
1060 public SCProductScreenshot fetchByP_P(long productEntryId, int priority)
1061 throws SystemException {
1062 return fetchByP_P(productEntryId, priority, true);
1063 }
1064
1065
1074 public SCProductScreenshot fetchByP_P(long productEntryId, int priority,
1075 boolean retrieveFromCache) throws SystemException {
1076 Object[] finderArgs = new Object[] { productEntryId, priority };
1077
1078 Object result = null;
1079
1080 if (retrieveFromCache) {
1081 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_P_P,
1082 finderArgs, this);
1083 }
1084
1085 if (result instanceof SCProductScreenshot) {
1086 SCProductScreenshot scProductScreenshot = (SCProductScreenshot)result;
1087
1088 if ((productEntryId != scProductScreenshot.getProductEntryId()) ||
1089 (priority != scProductScreenshot.getPriority())) {
1090 result = null;
1091 }
1092 }
1093
1094 if (result == null) {
1095 StringBundler query = new StringBundler(4);
1096
1097 query.append(_SQL_SELECT_SCPRODUCTSCREENSHOT_WHERE);
1098
1099 query.append(_FINDER_COLUMN_P_P_PRODUCTENTRYID_2);
1100
1101 query.append(_FINDER_COLUMN_P_P_PRIORITY_2);
1102
1103 String sql = query.toString();
1104
1105 Session session = null;
1106
1107 try {
1108 session = openSession();
1109
1110 Query q = session.createQuery(sql);
1111
1112 QueryPos qPos = QueryPos.getInstance(q);
1113
1114 qPos.add(productEntryId);
1115
1116 qPos.add(priority);
1117
1118 List<SCProductScreenshot> list = q.list();
1119
1120 if (list.isEmpty()) {
1121 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_P_P,
1122 finderArgs, list);
1123 }
1124 else {
1125 if ((list.size() > 1) && _log.isWarnEnabled()) {
1126 _log.warn(
1127 "SCProductScreenshotPersistenceImpl.fetchByP_P(long, int, boolean) with parameters (" +
1128 StringUtil.merge(finderArgs) +
1129 ") yields a result set with more than 1 result. This violates the logical unique restriction. There is no order guarantee on which result is returned by this finder.");
1130 }
1131
1132 SCProductScreenshot scProductScreenshot = list.get(0);
1133
1134 result = scProductScreenshot;
1135
1136 cacheResult(scProductScreenshot);
1137
1138 if ((scProductScreenshot.getProductEntryId() != productEntryId) ||
1139 (scProductScreenshot.getPriority() != priority)) {
1140 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_P_P,
1141 finderArgs, scProductScreenshot);
1142 }
1143 }
1144 }
1145 catch (Exception e) {
1146 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_P_P,
1147 finderArgs);
1148
1149 throw processException(e);
1150 }
1151 finally {
1152 closeSession(session);
1153 }
1154 }
1155
1156 if (result instanceof List<?>) {
1157 return null;
1158 }
1159 else {
1160 return (SCProductScreenshot)result;
1161 }
1162 }
1163
1164
1172 public SCProductScreenshot removeByP_P(long productEntryId, int priority)
1173 throws NoSuchProductScreenshotException, SystemException {
1174 SCProductScreenshot scProductScreenshot = findByP_P(productEntryId,
1175 priority);
1176
1177 return remove(scProductScreenshot);
1178 }
1179
1180
1188 public int countByP_P(long productEntryId, int priority)
1189 throws SystemException {
1190 FinderPath finderPath = FINDER_PATH_COUNT_BY_P_P;
1191
1192 Object[] finderArgs = new Object[] { productEntryId, priority };
1193
1194 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1195 this);
1196
1197 if (count == null) {
1198 StringBundler query = new StringBundler(3);
1199
1200 query.append(_SQL_COUNT_SCPRODUCTSCREENSHOT_WHERE);
1201
1202 query.append(_FINDER_COLUMN_P_P_PRODUCTENTRYID_2);
1203
1204 query.append(_FINDER_COLUMN_P_P_PRIORITY_2);
1205
1206 String sql = query.toString();
1207
1208 Session session = null;
1209
1210 try {
1211 session = openSession();
1212
1213 Query q = session.createQuery(sql);
1214
1215 QueryPos qPos = QueryPos.getInstance(q);
1216
1217 qPos.add(productEntryId);
1218
1219 qPos.add(priority);
1220
1221 count = (Long)q.uniqueResult();
1222
1223 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1224 }
1225 catch (Exception e) {
1226 FinderCacheUtil.removeResult(finderPath, finderArgs);
1227
1228 throw processException(e);
1229 }
1230 finally {
1231 closeSession(session);
1232 }
1233 }
1234
1235 return count.intValue();
1236 }
1237
1238 private static final String _FINDER_COLUMN_P_P_PRODUCTENTRYID_2 = "scProductScreenshot.productEntryId = ? AND ";
1239 private static final String _FINDER_COLUMN_P_P_PRIORITY_2 = "scProductScreenshot.priority = ?";
1240
1241
1246 public void cacheResult(SCProductScreenshot scProductScreenshot) {
1247 EntityCacheUtil.putResult(SCProductScreenshotModelImpl.ENTITY_CACHE_ENABLED,
1248 SCProductScreenshotImpl.class, scProductScreenshot.getPrimaryKey(),
1249 scProductScreenshot);
1250
1251 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_THUMBNAILID,
1252 new Object[] { scProductScreenshot.getThumbnailId() },
1253 scProductScreenshot);
1254
1255 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_FULLIMAGEID,
1256 new Object[] { scProductScreenshot.getFullImageId() },
1257 scProductScreenshot);
1258
1259 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_P_P,
1260 new Object[] {
1261 scProductScreenshot.getProductEntryId(),
1262 scProductScreenshot.getPriority()
1263 }, scProductScreenshot);
1264
1265 scProductScreenshot.resetOriginalValues();
1266 }
1267
1268
1273 public void cacheResult(List<SCProductScreenshot> scProductScreenshots) {
1274 for (SCProductScreenshot scProductScreenshot : scProductScreenshots) {
1275 if (EntityCacheUtil.getResult(
1276 SCProductScreenshotModelImpl.ENTITY_CACHE_ENABLED,
1277 SCProductScreenshotImpl.class,
1278 scProductScreenshot.getPrimaryKey()) == null) {
1279 cacheResult(scProductScreenshot);
1280 }
1281 else {
1282 scProductScreenshot.resetOriginalValues();
1283 }
1284 }
1285 }
1286
1287
1294 @Override
1295 public void clearCache() {
1296 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
1297 CacheRegistryUtil.clear(SCProductScreenshotImpl.class.getName());
1298 }
1299
1300 EntityCacheUtil.clearCache(SCProductScreenshotImpl.class.getName());
1301
1302 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
1303 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1304 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1305 }
1306
1307
1314 @Override
1315 public void clearCache(SCProductScreenshot scProductScreenshot) {
1316 EntityCacheUtil.removeResult(SCProductScreenshotModelImpl.ENTITY_CACHE_ENABLED,
1317 SCProductScreenshotImpl.class, scProductScreenshot.getPrimaryKey());
1318
1319 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1320 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1321
1322 clearUniqueFindersCache(scProductScreenshot);
1323 }
1324
1325 @Override
1326 public void clearCache(List<SCProductScreenshot> scProductScreenshots) {
1327 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1328 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1329
1330 for (SCProductScreenshot scProductScreenshot : scProductScreenshots) {
1331 EntityCacheUtil.removeResult(SCProductScreenshotModelImpl.ENTITY_CACHE_ENABLED,
1332 SCProductScreenshotImpl.class,
1333 scProductScreenshot.getPrimaryKey());
1334
1335 clearUniqueFindersCache(scProductScreenshot);
1336 }
1337 }
1338
1339 protected void cacheUniqueFindersCache(
1340 SCProductScreenshot scProductScreenshot) {
1341 if (scProductScreenshot.isNew()) {
1342 Object[] args = new Object[] { scProductScreenshot.getThumbnailId() };
1343
1344 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_THUMBNAILID, args,
1345 Long.valueOf(1));
1346 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_THUMBNAILID, args,
1347 scProductScreenshot);
1348
1349 args = new Object[] { scProductScreenshot.getFullImageId() };
1350
1351 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_FULLIMAGEID, args,
1352 Long.valueOf(1));
1353 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_FULLIMAGEID, args,
1354 scProductScreenshot);
1355
1356 args = new Object[] {
1357 scProductScreenshot.getProductEntryId(),
1358 scProductScreenshot.getPriority()
1359 };
1360
1361 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_P_P, args,
1362 Long.valueOf(1));
1363 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_P_P, args,
1364 scProductScreenshot);
1365 }
1366 else {
1367 SCProductScreenshotModelImpl scProductScreenshotModelImpl = (SCProductScreenshotModelImpl)scProductScreenshot;
1368
1369 if ((scProductScreenshotModelImpl.getColumnBitmask() &
1370 FINDER_PATH_FETCH_BY_THUMBNAILID.getColumnBitmask()) != 0) {
1371 Object[] args = new Object[] {
1372 scProductScreenshot.getThumbnailId()
1373 };
1374
1375 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_THUMBNAILID,
1376 args, Long.valueOf(1));
1377 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_THUMBNAILID,
1378 args, scProductScreenshot);
1379 }
1380
1381 if ((scProductScreenshotModelImpl.getColumnBitmask() &
1382 FINDER_PATH_FETCH_BY_FULLIMAGEID.getColumnBitmask()) != 0) {
1383 Object[] args = new Object[] {
1384 scProductScreenshot.getFullImageId()
1385 };
1386
1387 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_FULLIMAGEID,
1388 args, Long.valueOf(1));
1389 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_FULLIMAGEID,
1390 args, scProductScreenshot);
1391 }
1392
1393 if ((scProductScreenshotModelImpl.getColumnBitmask() &
1394 FINDER_PATH_FETCH_BY_P_P.getColumnBitmask()) != 0) {
1395 Object[] args = new Object[] {
1396 scProductScreenshot.getProductEntryId(),
1397 scProductScreenshot.getPriority()
1398 };
1399
1400 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_P_P, args,
1401 Long.valueOf(1));
1402 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_P_P, args,
1403 scProductScreenshot);
1404 }
1405 }
1406 }
1407
1408 protected void clearUniqueFindersCache(
1409 SCProductScreenshot scProductScreenshot) {
1410 SCProductScreenshotModelImpl scProductScreenshotModelImpl = (SCProductScreenshotModelImpl)scProductScreenshot;
1411
1412 Object[] args = new Object[] { scProductScreenshot.getThumbnailId() };
1413
1414 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_THUMBNAILID, args);
1415 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_THUMBNAILID, args);
1416
1417 if ((scProductScreenshotModelImpl.getColumnBitmask() &
1418 FINDER_PATH_FETCH_BY_THUMBNAILID.getColumnBitmask()) != 0) {
1419 args = new Object[] {
1420 scProductScreenshotModelImpl.getOriginalThumbnailId()
1421 };
1422
1423 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_THUMBNAILID, args);
1424 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_THUMBNAILID, args);
1425 }
1426
1427 args = new Object[] { scProductScreenshot.getFullImageId() };
1428
1429 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_FULLIMAGEID, args);
1430 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_FULLIMAGEID, args);
1431
1432 if ((scProductScreenshotModelImpl.getColumnBitmask() &
1433 FINDER_PATH_FETCH_BY_FULLIMAGEID.getColumnBitmask()) != 0) {
1434 args = new Object[] {
1435 scProductScreenshotModelImpl.getOriginalFullImageId()
1436 };
1437
1438 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_FULLIMAGEID, args);
1439 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_FULLIMAGEID, args);
1440 }
1441
1442 args = new Object[] {
1443 scProductScreenshot.getProductEntryId(),
1444 scProductScreenshot.getPriority()
1445 };
1446
1447 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_P_P, args);
1448 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_P_P, args);
1449
1450 if ((scProductScreenshotModelImpl.getColumnBitmask() &
1451 FINDER_PATH_FETCH_BY_P_P.getColumnBitmask()) != 0) {
1452 args = new Object[] {
1453 scProductScreenshotModelImpl.getOriginalProductEntryId(),
1454 scProductScreenshotModelImpl.getOriginalPriority()
1455 };
1456
1457 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_P_P, args);
1458 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_P_P, args);
1459 }
1460 }
1461
1462
1468 public SCProductScreenshot create(long productScreenshotId) {
1469 SCProductScreenshot scProductScreenshot = new SCProductScreenshotImpl();
1470
1471 scProductScreenshot.setNew(true);
1472 scProductScreenshot.setPrimaryKey(productScreenshotId);
1473
1474 return scProductScreenshot;
1475 }
1476
1477
1485 public SCProductScreenshot remove(long productScreenshotId)
1486 throws NoSuchProductScreenshotException, SystemException {
1487 return remove((Serializable)productScreenshotId);
1488 }
1489
1490
1498 @Override
1499 public SCProductScreenshot remove(Serializable primaryKey)
1500 throws NoSuchProductScreenshotException, SystemException {
1501 Session session = null;
1502
1503 try {
1504 session = openSession();
1505
1506 SCProductScreenshot scProductScreenshot = (SCProductScreenshot)session.get(SCProductScreenshotImpl.class,
1507 primaryKey);
1508
1509 if (scProductScreenshot == null) {
1510 if (_log.isWarnEnabled()) {
1511 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1512 }
1513
1514 throw new NoSuchProductScreenshotException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1515 primaryKey);
1516 }
1517
1518 return remove(scProductScreenshot);
1519 }
1520 catch (NoSuchProductScreenshotException nsee) {
1521 throw nsee;
1522 }
1523 catch (Exception e) {
1524 throw processException(e);
1525 }
1526 finally {
1527 closeSession(session);
1528 }
1529 }
1530
1531 @Override
1532 protected SCProductScreenshot removeImpl(
1533 SCProductScreenshot scProductScreenshot) throws SystemException {
1534 scProductScreenshot = toUnwrappedModel(scProductScreenshot);
1535
1536 Session session = null;
1537
1538 try {
1539 session = openSession();
1540
1541 if (!session.contains(scProductScreenshot)) {
1542 scProductScreenshot = (SCProductScreenshot)session.get(SCProductScreenshotImpl.class,
1543 scProductScreenshot.getPrimaryKeyObj());
1544 }
1545
1546 if (scProductScreenshot != null) {
1547 session.delete(scProductScreenshot);
1548 }
1549 }
1550 catch (Exception e) {
1551 throw processException(e);
1552 }
1553 finally {
1554 closeSession(session);
1555 }
1556
1557 if (scProductScreenshot != null) {
1558 clearCache(scProductScreenshot);
1559 }
1560
1561 return scProductScreenshot;
1562 }
1563
1564 @Override
1565 public SCProductScreenshot updateImpl(
1566 com.liferay.portlet.softwarecatalog.model.SCProductScreenshot scProductScreenshot)
1567 throws SystemException {
1568 scProductScreenshot = toUnwrappedModel(scProductScreenshot);
1569
1570 boolean isNew = scProductScreenshot.isNew();
1571
1572 SCProductScreenshotModelImpl scProductScreenshotModelImpl = (SCProductScreenshotModelImpl)scProductScreenshot;
1573
1574 Session session = null;
1575
1576 try {
1577 session = openSession();
1578
1579 if (scProductScreenshot.isNew()) {
1580 session.save(scProductScreenshot);
1581
1582 scProductScreenshot.setNew(false);
1583 }
1584 else {
1585 session.merge(scProductScreenshot);
1586 }
1587 }
1588 catch (Exception e) {
1589 throw processException(e);
1590 }
1591 finally {
1592 closeSession(session);
1593 }
1594
1595 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1596
1597 if (isNew || !SCProductScreenshotModelImpl.COLUMN_BITMASK_ENABLED) {
1598 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1599 }
1600
1601 else {
1602 if ((scProductScreenshotModelImpl.getColumnBitmask() &
1603 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PRODUCTENTRYID.getColumnBitmask()) != 0) {
1604 Object[] args = new Object[] {
1605 scProductScreenshotModelImpl.getOriginalProductEntryId()
1606 };
1607
1608 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_PRODUCTENTRYID,
1609 args);
1610 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PRODUCTENTRYID,
1611 args);
1612
1613 args = new Object[] {
1614 scProductScreenshotModelImpl.getProductEntryId()
1615 };
1616
1617 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_PRODUCTENTRYID,
1618 args);
1619 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PRODUCTENTRYID,
1620 args);
1621 }
1622 }
1623
1624 EntityCacheUtil.putResult(SCProductScreenshotModelImpl.ENTITY_CACHE_ENABLED,
1625 SCProductScreenshotImpl.class, scProductScreenshot.getPrimaryKey(),
1626 scProductScreenshot);
1627
1628 clearUniqueFindersCache(scProductScreenshot);
1629 cacheUniqueFindersCache(scProductScreenshot);
1630
1631 return scProductScreenshot;
1632 }
1633
1634 protected SCProductScreenshot toUnwrappedModel(
1635 SCProductScreenshot scProductScreenshot) {
1636 if (scProductScreenshot instanceof SCProductScreenshotImpl) {
1637 return scProductScreenshot;
1638 }
1639
1640 SCProductScreenshotImpl scProductScreenshotImpl = new SCProductScreenshotImpl();
1641
1642 scProductScreenshotImpl.setNew(scProductScreenshot.isNew());
1643 scProductScreenshotImpl.setPrimaryKey(scProductScreenshot.getPrimaryKey());
1644
1645 scProductScreenshotImpl.setProductScreenshotId(scProductScreenshot.getProductScreenshotId());
1646 scProductScreenshotImpl.setCompanyId(scProductScreenshot.getCompanyId());
1647 scProductScreenshotImpl.setGroupId(scProductScreenshot.getGroupId());
1648 scProductScreenshotImpl.setProductEntryId(scProductScreenshot.getProductEntryId());
1649 scProductScreenshotImpl.setThumbnailId(scProductScreenshot.getThumbnailId());
1650 scProductScreenshotImpl.setFullImageId(scProductScreenshot.getFullImageId());
1651 scProductScreenshotImpl.setPriority(scProductScreenshot.getPriority());
1652
1653 return scProductScreenshotImpl;
1654 }
1655
1656
1664 @Override
1665 public SCProductScreenshot findByPrimaryKey(Serializable primaryKey)
1666 throws NoSuchProductScreenshotException, SystemException {
1667 SCProductScreenshot scProductScreenshot = fetchByPrimaryKey(primaryKey);
1668
1669 if (scProductScreenshot == null) {
1670 if (_log.isWarnEnabled()) {
1671 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1672 }
1673
1674 throw new NoSuchProductScreenshotException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1675 primaryKey);
1676 }
1677
1678 return scProductScreenshot;
1679 }
1680
1681
1689 public SCProductScreenshot findByPrimaryKey(long productScreenshotId)
1690 throws NoSuchProductScreenshotException, SystemException {
1691 return findByPrimaryKey((Serializable)productScreenshotId);
1692 }
1693
1694
1701 @Override
1702 public SCProductScreenshot fetchByPrimaryKey(Serializable primaryKey)
1703 throws SystemException {
1704 SCProductScreenshot scProductScreenshot = (SCProductScreenshot)EntityCacheUtil.getResult(SCProductScreenshotModelImpl.ENTITY_CACHE_ENABLED,
1705 SCProductScreenshotImpl.class, primaryKey);
1706
1707 if (scProductScreenshot == _nullSCProductScreenshot) {
1708 return null;
1709 }
1710
1711 if (scProductScreenshot == null) {
1712 Session session = null;
1713
1714 try {
1715 session = openSession();
1716
1717 scProductScreenshot = (SCProductScreenshot)session.get(SCProductScreenshotImpl.class,
1718 primaryKey);
1719
1720 if (scProductScreenshot != null) {
1721 cacheResult(scProductScreenshot);
1722 }
1723 else {
1724 EntityCacheUtil.putResult(SCProductScreenshotModelImpl.ENTITY_CACHE_ENABLED,
1725 SCProductScreenshotImpl.class, primaryKey,
1726 _nullSCProductScreenshot);
1727 }
1728 }
1729 catch (Exception e) {
1730 EntityCacheUtil.removeResult(SCProductScreenshotModelImpl.ENTITY_CACHE_ENABLED,
1731 SCProductScreenshotImpl.class, primaryKey);
1732
1733 throw processException(e);
1734 }
1735 finally {
1736 closeSession(session);
1737 }
1738 }
1739
1740 return scProductScreenshot;
1741 }
1742
1743
1750 public SCProductScreenshot fetchByPrimaryKey(long productScreenshotId)
1751 throws SystemException {
1752 return fetchByPrimaryKey((Serializable)productScreenshotId);
1753 }
1754
1755
1761 public List<SCProductScreenshot> findAll() throws SystemException {
1762 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1763 }
1764
1765
1777 public List<SCProductScreenshot> findAll(int start, int end)
1778 throws SystemException {
1779 return findAll(start, end, null);
1780 }
1781
1782
1795 public List<SCProductScreenshot> findAll(int start, int end,
1796 OrderByComparator orderByComparator) throws SystemException {
1797 boolean pagination = true;
1798 FinderPath finderPath = null;
1799 Object[] finderArgs = null;
1800
1801 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1802 (orderByComparator == null)) {
1803 pagination = false;
1804 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1805 finderArgs = FINDER_ARGS_EMPTY;
1806 }
1807 else {
1808 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1809 finderArgs = new Object[] { start, end, orderByComparator };
1810 }
1811
1812 List<SCProductScreenshot> list = (List<SCProductScreenshot>)FinderCacheUtil.getResult(finderPath,
1813 finderArgs, this);
1814
1815 if (list == null) {
1816 StringBundler query = null;
1817 String sql = null;
1818
1819 if (orderByComparator != null) {
1820 query = new StringBundler(2 +
1821 (orderByComparator.getOrderByFields().length * 3));
1822
1823 query.append(_SQL_SELECT_SCPRODUCTSCREENSHOT);
1824
1825 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1826 orderByComparator);
1827
1828 sql = query.toString();
1829 }
1830 else {
1831 sql = _SQL_SELECT_SCPRODUCTSCREENSHOT;
1832
1833 if (pagination) {
1834 sql = sql.concat(SCProductScreenshotModelImpl.ORDER_BY_JPQL);
1835 }
1836 }
1837
1838 Session session = null;
1839
1840 try {
1841 session = openSession();
1842
1843 Query q = session.createQuery(sql);
1844
1845 if (!pagination) {
1846 list = (List<SCProductScreenshot>)QueryUtil.list(q,
1847 getDialect(), start, end, false);
1848
1849 Collections.sort(list);
1850
1851 list = new UnmodifiableList<SCProductScreenshot>(list);
1852 }
1853 else {
1854 list = (List<SCProductScreenshot>)QueryUtil.list(q,
1855 getDialect(), start, end);
1856 }
1857
1858 cacheResult(list);
1859
1860 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1861 }
1862 catch (Exception e) {
1863 FinderCacheUtil.removeResult(finderPath, finderArgs);
1864
1865 throw processException(e);
1866 }
1867 finally {
1868 closeSession(session);
1869 }
1870 }
1871
1872 return list;
1873 }
1874
1875
1880 public void removeAll() throws SystemException {
1881 for (SCProductScreenshot scProductScreenshot : findAll()) {
1882 remove(scProductScreenshot);
1883 }
1884 }
1885
1886
1892 public int countAll() throws SystemException {
1893 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1894 FINDER_ARGS_EMPTY, this);
1895
1896 if (count == null) {
1897 Session session = null;
1898
1899 try {
1900 session = openSession();
1901
1902 Query q = session.createQuery(_SQL_COUNT_SCPRODUCTSCREENSHOT);
1903
1904 count = (Long)q.uniqueResult();
1905
1906 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1907 FINDER_ARGS_EMPTY, count);
1908 }
1909 catch (Exception e) {
1910 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
1911 FINDER_ARGS_EMPTY);
1912
1913 throw processException(e);
1914 }
1915 finally {
1916 closeSession(session);
1917 }
1918 }
1919
1920 return count.intValue();
1921 }
1922
1923
1926 public void afterPropertiesSet() {
1927 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1928 com.liferay.portal.util.PropsUtil.get(
1929 "value.object.listener.com.liferay.portlet.softwarecatalog.model.SCProductScreenshot")));
1930
1931 if (listenerClassNames.length > 0) {
1932 try {
1933 List<ModelListener<SCProductScreenshot>> listenersList = new ArrayList<ModelListener<SCProductScreenshot>>();
1934
1935 for (String listenerClassName : listenerClassNames) {
1936 listenersList.add((ModelListener<SCProductScreenshot>)InstanceFactory.newInstance(
1937 listenerClassName));
1938 }
1939
1940 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1941 }
1942 catch (Exception e) {
1943 _log.error(e);
1944 }
1945 }
1946 }
1947
1948 public void destroy() {
1949 EntityCacheUtil.removeCache(SCProductScreenshotImpl.class.getName());
1950 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1951 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1952 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1953 }
1954
1955 private static final String _SQL_SELECT_SCPRODUCTSCREENSHOT = "SELECT scProductScreenshot FROM SCProductScreenshot scProductScreenshot";
1956 private static final String _SQL_SELECT_SCPRODUCTSCREENSHOT_WHERE = "SELECT scProductScreenshot FROM SCProductScreenshot scProductScreenshot WHERE ";
1957 private static final String _SQL_COUNT_SCPRODUCTSCREENSHOT = "SELECT COUNT(scProductScreenshot) FROM SCProductScreenshot scProductScreenshot";
1958 private static final String _SQL_COUNT_SCPRODUCTSCREENSHOT_WHERE = "SELECT COUNT(scProductScreenshot) FROM SCProductScreenshot scProductScreenshot WHERE ";
1959 private static final String _ORDER_BY_ENTITY_ALIAS = "scProductScreenshot.";
1960 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No SCProductScreenshot exists with the primary key ";
1961 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No SCProductScreenshot exists with the key {";
1962 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1963 private static Log _log = LogFactoryUtil.getLog(SCProductScreenshotPersistenceImpl.class);
1964 private static SCProductScreenshot _nullSCProductScreenshot = new SCProductScreenshotImpl() {
1965 @Override
1966 public Object clone() {
1967 return this;
1968 }
1969
1970 @Override
1971 public CacheModel<SCProductScreenshot> toCacheModel() {
1972 return _nullSCProductScreenshotCacheModel;
1973 }
1974 };
1975
1976 private static CacheModel<SCProductScreenshot> _nullSCProductScreenshotCacheModel =
1977 new CacheModel<SCProductScreenshot>() {
1978 public SCProductScreenshot toEntityModel() {
1979 return _nullSCProductScreenshot;
1980 }
1981 };
1982 }