001
014
015 package com.liferay.portlet.asset.service.persistence.impl;
016
017 import aQute.bnd.annotation.ProviderType;
018
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.log.Log;
029 import com.liferay.portal.kernel.log.LogFactoryUtil;
030 import com.liferay.portal.kernel.util.OrderByComparator;
031 import com.liferay.portal.kernel.util.SetUtil;
032 import com.liferay.portal.kernel.util.StringBundler;
033 import com.liferay.portal.kernel.util.StringPool;
034 import com.liferay.portal.kernel.util.StringUtil;
035 import com.liferay.portal.kernel.util.Validator;
036 import com.liferay.portal.model.CacheModel;
037 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
038 import com.liferay.portal.service.persistence.impl.TableMapper;
039 import com.liferay.portal.service.persistence.impl.TableMapperFactory;
040
041 import com.liferay.portlet.asset.NoSuchEntryException;
042 import com.liferay.portlet.asset.model.AssetEntry;
043 import com.liferay.portlet.asset.model.impl.AssetEntryImpl;
044 import com.liferay.portlet.asset.model.impl.AssetEntryModelImpl;
045 import com.liferay.portlet.asset.service.persistence.AssetCategoryPersistence;
046 import com.liferay.portlet.asset.service.persistence.AssetEntryPersistence;
047 import com.liferay.portlet.asset.service.persistence.AssetTagPersistence;
048
049 import java.io.Serializable;
050
051 import java.sql.Timestamp;
052
053 import java.util.Collections;
054 import java.util.Date;
055 import java.util.HashMap;
056 import java.util.HashSet;
057 import java.util.Iterator;
058 import java.util.List;
059 import java.util.Map;
060 import java.util.Set;
061
062
074 @ProviderType
075 public class AssetEntryPersistenceImpl extends BasePersistenceImpl<AssetEntry>
076 implements AssetEntryPersistence {
077
082 public static final String FINDER_CLASS_NAME_ENTITY = AssetEntryImpl.class.getName();
083 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
084 ".List1";
085 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
086 ".List2";
087 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
088 AssetEntryModelImpl.FINDER_CACHE_ENABLED, AssetEntryImpl.class,
089 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
090 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
091 AssetEntryModelImpl.FINDER_CACHE_ENABLED, AssetEntryImpl.class,
092 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
093 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
094 AssetEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
095 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
096 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
097 AssetEntryModelImpl.FINDER_CACHE_ENABLED, AssetEntryImpl.class,
098 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
099 new String[] {
100 Long.class.getName(),
101
102 Integer.class.getName(), Integer.class.getName(),
103 OrderByComparator.class.getName()
104 });
105 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
106 new FinderPath(AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
107 AssetEntryModelImpl.FINDER_CACHE_ENABLED, AssetEntryImpl.class,
108 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
109 new String[] { Long.class.getName() },
110 AssetEntryModelImpl.GROUPID_COLUMN_BITMASK);
111 public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
112 AssetEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
113 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
114 new String[] { Long.class.getName() });
115
116
122 @Override
123 public List<AssetEntry> findByGroupId(long groupId) {
124 return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
125 }
126
127
139 @Override
140 public List<AssetEntry> findByGroupId(long groupId, int start, int end) {
141 return findByGroupId(groupId, start, end, null);
142 }
143
144
157 @Override
158 public List<AssetEntry> findByGroupId(long groupId, int start, int end,
159 OrderByComparator<AssetEntry> orderByComparator) {
160 boolean pagination = true;
161 FinderPath finderPath = null;
162 Object[] finderArgs = null;
163
164 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
165 (orderByComparator == null)) {
166 pagination = false;
167 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
168 finderArgs = new Object[] { groupId };
169 }
170 else {
171 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
172 finderArgs = new Object[] { groupId, start, end, orderByComparator };
173 }
174
175 List<AssetEntry> list = (List<AssetEntry>)FinderCacheUtil.getResult(finderPath,
176 finderArgs, this);
177
178 if ((list != null) && !list.isEmpty()) {
179 for (AssetEntry assetEntry : list) {
180 if ((groupId != assetEntry.getGroupId())) {
181 list = null;
182
183 break;
184 }
185 }
186 }
187
188 if (list == null) {
189 StringBundler query = null;
190
191 if (orderByComparator != null) {
192 query = new StringBundler(3 +
193 (orderByComparator.getOrderByFields().length * 3));
194 }
195 else {
196 query = new StringBundler(3);
197 }
198
199 query.append(_SQL_SELECT_ASSETENTRY_WHERE);
200
201 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
202
203 if (orderByComparator != null) {
204 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
205 orderByComparator);
206 }
207 else
208 if (pagination) {
209 query.append(AssetEntryModelImpl.ORDER_BY_JPQL);
210 }
211
212 String sql = query.toString();
213
214 Session session = null;
215
216 try {
217 session = openSession();
218
219 Query q = session.createQuery(sql);
220
221 QueryPos qPos = QueryPos.getInstance(q);
222
223 qPos.add(groupId);
224
225 if (!pagination) {
226 list = (List<AssetEntry>)QueryUtil.list(q, getDialect(),
227 start, end, false);
228
229 Collections.sort(list);
230
231 list = Collections.unmodifiableList(list);
232 }
233 else {
234 list = (List<AssetEntry>)QueryUtil.list(q, getDialect(),
235 start, end);
236 }
237
238 cacheResult(list);
239
240 FinderCacheUtil.putResult(finderPath, finderArgs, list);
241 }
242 catch (Exception e) {
243 FinderCacheUtil.removeResult(finderPath, finderArgs);
244
245 throw processException(e);
246 }
247 finally {
248 closeSession(session);
249 }
250 }
251
252 return list;
253 }
254
255
263 @Override
264 public AssetEntry findByGroupId_First(long groupId,
265 OrderByComparator<AssetEntry> orderByComparator)
266 throws NoSuchEntryException {
267 AssetEntry assetEntry = fetchByGroupId_First(groupId, orderByComparator);
268
269 if (assetEntry != null) {
270 return assetEntry;
271 }
272
273 StringBundler msg = new StringBundler(4);
274
275 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
276
277 msg.append("groupId=");
278 msg.append(groupId);
279
280 msg.append(StringPool.CLOSE_CURLY_BRACE);
281
282 throw new NoSuchEntryException(msg.toString());
283 }
284
285
292 @Override
293 public AssetEntry fetchByGroupId_First(long groupId,
294 OrderByComparator<AssetEntry> orderByComparator) {
295 List<AssetEntry> list = findByGroupId(groupId, 0, 1, orderByComparator);
296
297 if (!list.isEmpty()) {
298 return list.get(0);
299 }
300
301 return null;
302 }
303
304
312 @Override
313 public AssetEntry findByGroupId_Last(long groupId,
314 OrderByComparator<AssetEntry> orderByComparator)
315 throws NoSuchEntryException {
316 AssetEntry assetEntry = fetchByGroupId_Last(groupId, orderByComparator);
317
318 if (assetEntry != null) {
319 return assetEntry;
320 }
321
322 StringBundler msg = new StringBundler(4);
323
324 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
325
326 msg.append("groupId=");
327 msg.append(groupId);
328
329 msg.append(StringPool.CLOSE_CURLY_BRACE);
330
331 throw new NoSuchEntryException(msg.toString());
332 }
333
334
341 @Override
342 public AssetEntry fetchByGroupId_Last(long groupId,
343 OrderByComparator<AssetEntry> orderByComparator) {
344 int count = countByGroupId(groupId);
345
346 if (count == 0) {
347 return null;
348 }
349
350 List<AssetEntry> list = findByGroupId(groupId, count - 1, count,
351 orderByComparator);
352
353 if (!list.isEmpty()) {
354 return list.get(0);
355 }
356
357 return null;
358 }
359
360
369 @Override
370 public AssetEntry[] findByGroupId_PrevAndNext(long entryId, long groupId,
371 OrderByComparator<AssetEntry> orderByComparator)
372 throws NoSuchEntryException {
373 AssetEntry assetEntry = findByPrimaryKey(entryId);
374
375 Session session = null;
376
377 try {
378 session = openSession();
379
380 AssetEntry[] array = new AssetEntryImpl[3];
381
382 array[0] = getByGroupId_PrevAndNext(session, assetEntry, groupId,
383 orderByComparator, true);
384
385 array[1] = assetEntry;
386
387 array[2] = getByGroupId_PrevAndNext(session, assetEntry, groupId,
388 orderByComparator, false);
389
390 return array;
391 }
392 catch (Exception e) {
393 throw processException(e);
394 }
395 finally {
396 closeSession(session);
397 }
398 }
399
400 protected AssetEntry getByGroupId_PrevAndNext(Session session,
401 AssetEntry assetEntry, long groupId,
402 OrderByComparator<AssetEntry> orderByComparator, boolean previous) {
403 StringBundler query = null;
404
405 if (orderByComparator != null) {
406 query = new StringBundler(6 +
407 (orderByComparator.getOrderByFields().length * 6));
408 }
409 else {
410 query = new StringBundler(3);
411 }
412
413 query.append(_SQL_SELECT_ASSETENTRY_WHERE);
414
415 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
416
417 if (orderByComparator != null) {
418 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
419
420 if (orderByConditionFields.length > 0) {
421 query.append(WHERE_AND);
422 }
423
424 for (int i = 0; i < orderByConditionFields.length; i++) {
425 query.append(_ORDER_BY_ENTITY_ALIAS);
426 query.append(orderByConditionFields[i]);
427
428 if ((i + 1) < orderByConditionFields.length) {
429 if (orderByComparator.isAscending() ^ previous) {
430 query.append(WHERE_GREATER_THAN_HAS_NEXT);
431 }
432 else {
433 query.append(WHERE_LESSER_THAN_HAS_NEXT);
434 }
435 }
436 else {
437 if (orderByComparator.isAscending() ^ previous) {
438 query.append(WHERE_GREATER_THAN);
439 }
440 else {
441 query.append(WHERE_LESSER_THAN);
442 }
443 }
444 }
445
446 query.append(ORDER_BY_CLAUSE);
447
448 String[] orderByFields = orderByComparator.getOrderByFields();
449
450 for (int i = 0; i < orderByFields.length; i++) {
451 query.append(_ORDER_BY_ENTITY_ALIAS);
452 query.append(orderByFields[i]);
453
454 if ((i + 1) < orderByFields.length) {
455 if (orderByComparator.isAscending() ^ previous) {
456 query.append(ORDER_BY_ASC_HAS_NEXT);
457 }
458 else {
459 query.append(ORDER_BY_DESC_HAS_NEXT);
460 }
461 }
462 else {
463 if (orderByComparator.isAscending() ^ previous) {
464 query.append(ORDER_BY_ASC);
465 }
466 else {
467 query.append(ORDER_BY_DESC);
468 }
469 }
470 }
471 }
472 else {
473 query.append(AssetEntryModelImpl.ORDER_BY_JPQL);
474 }
475
476 String sql = query.toString();
477
478 Query q = session.createQuery(sql);
479
480 q.setFirstResult(0);
481 q.setMaxResults(2);
482
483 QueryPos qPos = QueryPos.getInstance(q);
484
485 qPos.add(groupId);
486
487 if (orderByComparator != null) {
488 Object[] values = orderByComparator.getOrderByConditionValues(assetEntry);
489
490 for (Object value : values) {
491 qPos.add(value);
492 }
493 }
494
495 List<AssetEntry> list = q.list();
496
497 if (list.size() == 2) {
498 return list.get(1);
499 }
500 else {
501 return null;
502 }
503 }
504
505
510 @Override
511 public void removeByGroupId(long groupId) {
512 for (AssetEntry assetEntry : findByGroupId(groupId, QueryUtil.ALL_POS,
513 QueryUtil.ALL_POS, null)) {
514 remove(assetEntry);
515 }
516 }
517
518
524 @Override
525 public int countByGroupId(long groupId) {
526 FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
527
528 Object[] finderArgs = new Object[] { groupId };
529
530 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
531 this);
532
533 if (count == null) {
534 StringBundler query = new StringBundler(2);
535
536 query.append(_SQL_COUNT_ASSETENTRY_WHERE);
537
538 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
539
540 String sql = query.toString();
541
542 Session session = null;
543
544 try {
545 session = openSession();
546
547 Query q = session.createQuery(sql);
548
549 QueryPos qPos = QueryPos.getInstance(q);
550
551 qPos.add(groupId);
552
553 count = (Long)q.uniqueResult();
554
555 FinderCacheUtil.putResult(finderPath, finderArgs, count);
556 }
557 catch (Exception e) {
558 FinderCacheUtil.removeResult(finderPath, finderArgs);
559
560 throw processException(e);
561 }
562 finally {
563 closeSession(session);
564 }
565 }
566
567 return count.intValue();
568 }
569
570 private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "assetEntry.groupId = ?";
571 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
572 new FinderPath(AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
573 AssetEntryModelImpl.FINDER_CACHE_ENABLED, AssetEntryImpl.class,
574 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
575 new String[] {
576 Long.class.getName(),
577
578 Integer.class.getName(), Integer.class.getName(),
579 OrderByComparator.class.getName()
580 });
581 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
582 new FinderPath(AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
583 AssetEntryModelImpl.FINDER_CACHE_ENABLED, AssetEntryImpl.class,
584 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
585 new String[] { Long.class.getName() },
586 AssetEntryModelImpl.COMPANYID_COLUMN_BITMASK);
587 public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
588 AssetEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
589 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
590 new String[] { Long.class.getName() });
591
592
598 @Override
599 public List<AssetEntry> findByCompanyId(long companyId) {
600 return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
601 null);
602 }
603
604
616 @Override
617 public List<AssetEntry> findByCompanyId(long companyId, int start, int end) {
618 return findByCompanyId(companyId, start, end, null);
619 }
620
621
634 @Override
635 public List<AssetEntry> findByCompanyId(long companyId, int start, int end,
636 OrderByComparator<AssetEntry> orderByComparator) {
637 boolean pagination = true;
638 FinderPath finderPath = null;
639 Object[] finderArgs = null;
640
641 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
642 (orderByComparator == null)) {
643 pagination = false;
644 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
645 finderArgs = new Object[] { companyId };
646 }
647 else {
648 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
649 finderArgs = new Object[] { companyId, start, end, orderByComparator };
650 }
651
652 List<AssetEntry> list = (List<AssetEntry>)FinderCacheUtil.getResult(finderPath,
653 finderArgs, this);
654
655 if ((list != null) && !list.isEmpty()) {
656 for (AssetEntry assetEntry : list) {
657 if ((companyId != assetEntry.getCompanyId())) {
658 list = null;
659
660 break;
661 }
662 }
663 }
664
665 if (list == null) {
666 StringBundler query = null;
667
668 if (orderByComparator != null) {
669 query = new StringBundler(3 +
670 (orderByComparator.getOrderByFields().length * 3));
671 }
672 else {
673 query = new StringBundler(3);
674 }
675
676 query.append(_SQL_SELECT_ASSETENTRY_WHERE);
677
678 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
679
680 if (orderByComparator != null) {
681 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
682 orderByComparator);
683 }
684 else
685 if (pagination) {
686 query.append(AssetEntryModelImpl.ORDER_BY_JPQL);
687 }
688
689 String sql = query.toString();
690
691 Session session = null;
692
693 try {
694 session = openSession();
695
696 Query q = session.createQuery(sql);
697
698 QueryPos qPos = QueryPos.getInstance(q);
699
700 qPos.add(companyId);
701
702 if (!pagination) {
703 list = (List<AssetEntry>)QueryUtil.list(q, getDialect(),
704 start, end, false);
705
706 Collections.sort(list);
707
708 list = Collections.unmodifiableList(list);
709 }
710 else {
711 list = (List<AssetEntry>)QueryUtil.list(q, getDialect(),
712 start, end);
713 }
714
715 cacheResult(list);
716
717 FinderCacheUtil.putResult(finderPath, finderArgs, list);
718 }
719 catch (Exception e) {
720 FinderCacheUtil.removeResult(finderPath, finderArgs);
721
722 throw processException(e);
723 }
724 finally {
725 closeSession(session);
726 }
727 }
728
729 return list;
730 }
731
732
740 @Override
741 public AssetEntry findByCompanyId_First(long companyId,
742 OrderByComparator<AssetEntry> orderByComparator)
743 throws NoSuchEntryException {
744 AssetEntry assetEntry = fetchByCompanyId_First(companyId,
745 orderByComparator);
746
747 if (assetEntry != null) {
748 return assetEntry;
749 }
750
751 StringBundler msg = new StringBundler(4);
752
753 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
754
755 msg.append("companyId=");
756 msg.append(companyId);
757
758 msg.append(StringPool.CLOSE_CURLY_BRACE);
759
760 throw new NoSuchEntryException(msg.toString());
761 }
762
763
770 @Override
771 public AssetEntry fetchByCompanyId_First(long companyId,
772 OrderByComparator<AssetEntry> orderByComparator) {
773 List<AssetEntry> list = findByCompanyId(companyId, 0, 1,
774 orderByComparator);
775
776 if (!list.isEmpty()) {
777 return list.get(0);
778 }
779
780 return null;
781 }
782
783
791 @Override
792 public AssetEntry findByCompanyId_Last(long companyId,
793 OrderByComparator<AssetEntry> orderByComparator)
794 throws NoSuchEntryException {
795 AssetEntry assetEntry = fetchByCompanyId_Last(companyId,
796 orderByComparator);
797
798 if (assetEntry != null) {
799 return assetEntry;
800 }
801
802 StringBundler msg = new StringBundler(4);
803
804 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
805
806 msg.append("companyId=");
807 msg.append(companyId);
808
809 msg.append(StringPool.CLOSE_CURLY_BRACE);
810
811 throw new NoSuchEntryException(msg.toString());
812 }
813
814
821 @Override
822 public AssetEntry fetchByCompanyId_Last(long companyId,
823 OrderByComparator<AssetEntry> orderByComparator) {
824 int count = countByCompanyId(companyId);
825
826 if (count == 0) {
827 return null;
828 }
829
830 List<AssetEntry> list = findByCompanyId(companyId, count - 1, count,
831 orderByComparator);
832
833 if (!list.isEmpty()) {
834 return list.get(0);
835 }
836
837 return null;
838 }
839
840
849 @Override
850 public AssetEntry[] findByCompanyId_PrevAndNext(long entryId,
851 long companyId, OrderByComparator<AssetEntry> orderByComparator)
852 throws NoSuchEntryException {
853 AssetEntry assetEntry = findByPrimaryKey(entryId);
854
855 Session session = null;
856
857 try {
858 session = openSession();
859
860 AssetEntry[] array = new AssetEntryImpl[3];
861
862 array[0] = getByCompanyId_PrevAndNext(session, assetEntry,
863 companyId, orderByComparator, true);
864
865 array[1] = assetEntry;
866
867 array[2] = getByCompanyId_PrevAndNext(session, assetEntry,
868 companyId, orderByComparator, false);
869
870 return array;
871 }
872 catch (Exception e) {
873 throw processException(e);
874 }
875 finally {
876 closeSession(session);
877 }
878 }
879
880 protected AssetEntry getByCompanyId_PrevAndNext(Session session,
881 AssetEntry assetEntry, long companyId,
882 OrderByComparator<AssetEntry> orderByComparator, boolean previous) {
883 StringBundler query = null;
884
885 if (orderByComparator != null) {
886 query = new StringBundler(6 +
887 (orderByComparator.getOrderByFields().length * 6));
888 }
889 else {
890 query = new StringBundler(3);
891 }
892
893 query.append(_SQL_SELECT_ASSETENTRY_WHERE);
894
895 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
896
897 if (orderByComparator != null) {
898 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
899
900 if (orderByConditionFields.length > 0) {
901 query.append(WHERE_AND);
902 }
903
904 for (int i = 0; i < orderByConditionFields.length; i++) {
905 query.append(_ORDER_BY_ENTITY_ALIAS);
906 query.append(orderByConditionFields[i]);
907
908 if ((i + 1) < orderByConditionFields.length) {
909 if (orderByComparator.isAscending() ^ previous) {
910 query.append(WHERE_GREATER_THAN_HAS_NEXT);
911 }
912 else {
913 query.append(WHERE_LESSER_THAN_HAS_NEXT);
914 }
915 }
916 else {
917 if (orderByComparator.isAscending() ^ previous) {
918 query.append(WHERE_GREATER_THAN);
919 }
920 else {
921 query.append(WHERE_LESSER_THAN);
922 }
923 }
924 }
925
926 query.append(ORDER_BY_CLAUSE);
927
928 String[] orderByFields = orderByComparator.getOrderByFields();
929
930 for (int i = 0; i < orderByFields.length; i++) {
931 query.append(_ORDER_BY_ENTITY_ALIAS);
932 query.append(orderByFields[i]);
933
934 if ((i + 1) < orderByFields.length) {
935 if (orderByComparator.isAscending() ^ previous) {
936 query.append(ORDER_BY_ASC_HAS_NEXT);
937 }
938 else {
939 query.append(ORDER_BY_DESC_HAS_NEXT);
940 }
941 }
942 else {
943 if (orderByComparator.isAscending() ^ previous) {
944 query.append(ORDER_BY_ASC);
945 }
946 else {
947 query.append(ORDER_BY_DESC);
948 }
949 }
950 }
951 }
952 else {
953 query.append(AssetEntryModelImpl.ORDER_BY_JPQL);
954 }
955
956 String sql = query.toString();
957
958 Query q = session.createQuery(sql);
959
960 q.setFirstResult(0);
961 q.setMaxResults(2);
962
963 QueryPos qPos = QueryPos.getInstance(q);
964
965 qPos.add(companyId);
966
967 if (orderByComparator != null) {
968 Object[] values = orderByComparator.getOrderByConditionValues(assetEntry);
969
970 for (Object value : values) {
971 qPos.add(value);
972 }
973 }
974
975 List<AssetEntry> list = q.list();
976
977 if (list.size() == 2) {
978 return list.get(1);
979 }
980 else {
981 return null;
982 }
983 }
984
985
990 @Override
991 public void removeByCompanyId(long companyId) {
992 for (AssetEntry assetEntry : findByCompanyId(companyId,
993 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
994 remove(assetEntry);
995 }
996 }
997
998
1004 @Override
1005 public int countByCompanyId(long companyId) {
1006 FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
1007
1008 Object[] finderArgs = new Object[] { companyId };
1009
1010 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1011 this);
1012
1013 if (count == null) {
1014 StringBundler query = new StringBundler(2);
1015
1016 query.append(_SQL_COUNT_ASSETENTRY_WHERE);
1017
1018 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1019
1020 String sql = query.toString();
1021
1022 Session session = null;
1023
1024 try {
1025 session = openSession();
1026
1027 Query q = session.createQuery(sql);
1028
1029 QueryPos qPos = QueryPos.getInstance(q);
1030
1031 qPos.add(companyId);
1032
1033 count = (Long)q.uniqueResult();
1034
1035 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1036 }
1037 catch (Exception e) {
1038 FinderCacheUtil.removeResult(finderPath, finderArgs);
1039
1040 throw processException(e);
1041 }
1042 finally {
1043 closeSession(session);
1044 }
1045 }
1046
1047 return count.intValue();
1048 }
1049
1050 private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "assetEntry.companyId = ?";
1051 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_VISIBLE = new FinderPath(AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
1052 AssetEntryModelImpl.FINDER_CACHE_ENABLED, AssetEntryImpl.class,
1053 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByVisible",
1054 new String[] {
1055 Boolean.class.getName(),
1056
1057 Integer.class.getName(), Integer.class.getName(),
1058 OrderByComparator.class.getName()
1059 });
1060 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_VISIBLE =
1061 new FinderPath(AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
1062 AssetEntryModelImpl.FINDER_CACHE_ENABLED, AssetEntryImpl.class,
1063 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByVisible",
1064 new String[] { Boolean.class.getName() },
1065 AssetEntryModelImpl.VISIBLE_COLUMN_BITMASK);
1066 public static final FinderPath FINDER_PATH_COUNT_BY_VISIBLE = new FinderPath(AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
1067 AssetEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
1068 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByVisible",
1069 new String[] { Boolean.class.getName() });
1070
1071
1077 @Override
1078 public List<AssetEntry> findByVisible(boolean visible) {
1079 return findByVisible(visible, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1080 }
1081
1082
1094 @Override
1095 public List<AssetEntry> findByVisible(boolean visible, int start, int end) {
1096 return findByVisible(visible, start, end, null);
1097 }
1098
1099
1112 @Override
1113 public List<AssetEntry> findByVisible(boolean visible, int start, int end,
1114 OrderByComparator<AssetEntry> orderByComparator) {
1115 boolean pagination = true;
1116 FinderPath finderPath = null;
1117 Object[] finderArgs = null;
1118
1119 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1120 (orderByComparator == null)) {
1121 pagination = false;
1122 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_VISIBLE;
1123 finderArgs = new Object[] { visible };
1124 }
1125 else {
1126 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_VISIBLE;
1127 finderArgs = new Object[] { visible, start, end, orderByComparator };
1128 }
1129
1130 List<AssetEntry> list = (List<AssetEntry>)FinderCacheUtil.getResult(finderPath,
1131 finderArgs, this);
1132
1133 if ((list != null) && !list.isEmpty()) {
1134 for (AssetEntry assetEntry : list) {
1135 if ((visible != assetEntry.getVisible())) {
1136 list = null;
1137
1138 break;
1139 }
1140 }
1141 }
1142
1143 if (list == null) {
1144 StringBundler query = null;
1145
1146 if (orderByComparator != null) {
1147 query = new StringBundler(3 +
1148 (orderByComparator.getOrderByFields().length * 3));
1149 }
1150 else {
1151 query = new StringBundler(3);
1152 }
1153
1154 query.append(_SQL_SELECT_ASSETENTRY_WHERE);
1155
1156 query.append(_FINDER_COLUMN_VISIBLE_VISIBLE_2);
1157
1158 if (orderByComparator != null) {
1159 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1160 orderByComparator);
1161 }
1162 else
1163 if (pagination) {
1164 query.append(AssetEntryModelImpl.ORDER_BY_JPQL);
1165 }
1166
1167 String sql = query.toString();
1168
1169 Session session = null;
1170
1171 try {
1172 session = openSession();
1173
1174 Query q = session.createQuery(sql);
1175
1176 QueryPos qPos = QueryPos.getInstance(q);
1177
1178 qPos.add(visible);
1179
1180 if (!pagination) {
1181 list = (List<AssetEntry>)QueryUtil.list(q, getDialect(),
1182 start, end, false);
1183
1184 Collections.sort(list);
1185
1186 list = Collections.unmodifiableList(list);
1187 }
1188 else {
1189 list = (List<AssetEntry>)QueryUtil.list(q, getDialect(),
1190 start, end);
1191 }
1192
1193 cacheResult(list);
1194
1195 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1196 }
1197 catch (Exception e) {
1198 FinderCacheUtil.removeResult(finderPath, finderArgs);
1199
1200 throw processException(e);
1201 }
1202 finally {
1203 closeSession(session);
1204 }
1205 }
1206
1207 return list;
1208 }
1209
1210
1218 @Override
1219 public AssetEntry findByVisible_First(boolean visible,
1220 OrderByComparator<AssetEntry> orderByComparator)
1221 throws NoSuchEntryException {
1222 AssetEntry assetEntry = fetchByVisible_First(visible, orderByComparator);
1223
1224 if (assetEntry != null) {
1225 return assetEntry;
1226 }
1227
1228 StringBundler msg = new StringBundler(4);
1229
1230 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1231
1232 msg.append("visible=");
1233 msg.append(visible);
1234
1235 msg.append(StringPool.CLOSE_CURLY_BRACE);
1236
1237 throw new NoSuchEntryException(msg.toString());
1238 }
1239
1240
1247 @Override
1248 public AssetEntry fetchByVisible_First(boolean visible,
1249 OrderByComparator<AssetEntry> orderByComparator) {
1250 List<AssetEntry> list = findByVisible(visible, 0, 1, orderByComparator);
1251
1252 if (!list.isEmpty()) {
1253 return list.get(0);
1254 }
1255
1256 return null;
1257 }
1258
1259
1267 @Override
1268 public AssetEntry findByVisible_Last(boolean visible,
1269 OrderByComparator<AssetEntry> orderByComparator)
1270 throws NoSuchEntryException {
1271 AssetEntry assetEntry = fetchByVisible_Last(visible, orderByComparator);
1272
1273 if (assetEntry != null) {
1274 return assetEntry;
1275 }
1276
1277 StringBundler msg = new StringBundler(4);
1278
1279 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1280
1281 msg.append("visible=");
1282 msg.append(visible);
1283
1284 msg.append(StringPool.CLOSE_CURLY_BRACE);
1285
1286 throw new NoSuchEntryException(msg.toString());
1287 }
1288
1289
1296 @Override
1297 public AssetEntry fetchByVisible_Last(boolean visible,
1298 OrderByComparator<AssetEntry> orderByComparator) {
1299 int count = countByVisible(visible);
1300
1301 if (count == 0) {
1302 return null;
1303 }
1304
1305 List<AssetEntry> list = findByVisible(visible, count - 1, count,
1306 orderByComparator);
1307
1308 if (!list.isEmpty()) {
1309 return list.get(0);
1310 }
1311
1312 return null;
1313 }
1314
1315
1324 @Override
1325 public AssetEntry[] findByVisible_PrevAndNext(long entryId,
1326 boolean visible, OrderByComparator<AssetEntry> orderByComparator)
1327 throws NoSuchEntryException {
1328 AssetEntry assetEntry = findByPrimaryKey(entryId);
1329
1330 Session session = null;
1331
1332 try {
1333 session = openSession();
1334
1335 AssetEntry[] array = new AssetEntryImpl[3];
1336
1337 array[0] = getByVisible_PrevAndNext(session, assetEntry, visible,
1338 orderByComparator, true);
1339
1340 array[1] = assetEntry;
1341
1342 array[2] = getByVisible_PrevAndNext(session, assetEntry, visible,
1343 orderByComparator, false);
1344
1345 return array;
1346 }
1347 catch (Exception e) {
1348 throw processException(e);
1349 }
1350 finally {
1351 closeSession(session);
1352 }
1353 }
1354
1355 protected AssetEntry getByVisible_PrevAndNext(Session session,
1356 AssetEntry assetEntry, boolean visible,
1357 OrderByComparator<AssetEntry> orderByComparator, boolean previous) {
1358 StringBundler query = null;
1359
1360 if (orderByComparator != null) {
1361 query = new StringBundler(6 +
1362 (orderByComparator.getOrderByFields().length * 6));
1363 }
1364 else {
1365 query = new StringBundler(3);
1366 }
1367
1368 query.append(_SQL_SELECT_ASSETENTRY_WHERE);
1369
1370 query.append(_FINDER_COLUMN_VISIBLE_VISIBLE_2);
1371
1372 if (orderByComparator != null) {
1373 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1374
1375 if (orderByConditionFields.length > 0) {
1376 query.append(WHERE_AND);
1377 }
1378
1379 for (int i = 0; i < orderByConditionFields.length; i++) {
1380 query.append(_ORDER_BY_ENTITY_ALIAS);
1381 query.append(orderByConditionFields[i]);
1382
1383 if ((i + 1) < orderByConditionFields.length) {
1384 if (orderByComparator.isAscending() ^ previous) {
1385 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1386 }
1387 else {
1388 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1389 }
1390 }
1391 else {
1392 if (orderByComparator.isAscending() ^ previous) {
1393 query.append(WHERE_GREATER_THAN);
1394 }
1395 else {
1396 query.append(WHERE_LESSER_THAN);
1397 }
1398 }
1399 }
1400
1401 query.append(ORDER_BY_CLAUSE);
1402
1403 String[] orderByFields = orderByComparator.getOrderByFields();
1404
1405 for (int i = 0; i < orderByFields.length; i++) {
1406 query.append(_ORDER_BY_ENTITY_ALIAS);
1407 query.append(orderByFields[i]);
1408
1409 if ((i + 1) < orderByFields.length) {
1410 if (orderByComparator.isAscending() ^ previous) {
1411 query.append(ORDER_BY_ASC_HAS_NEXT);
1412 }
1413 else {
1414 query.append(ORDER_BY_DESC_HAS_NEXT);
1415 }
1416 }
1417 else {
1418 if (orderByComparator.isAscending() ^ previous) {
1419 query.append(ORDER_BY_ASC);
1420 }
1421 else {
1422 query.append(ORDER_BY_DESC);
1423 }
1424 }
1425 }
1426 }
1427 else {
1428 query.append(AssetEntryModelImpl.ORDER_BY_JPQL);
1429 }
1430
1431 String sql = query.toString();
1432
1433 Query q = session.createQuery(sql);
1434
1435 q.setFirstResult(0);
1436 q.setMaxResults(2);
1437
1438 QueryPos qPos = QueryPos.getInstance(q);
1439
1440 qPos.add(visible);
1441
1442 if (orderByComparator != null) {
1443 Object[] values = orderByComparator.getOrderByConditionValues(assetEntry);
1444
1445 for (Object value : values) {
1446 qPos.add(value);
1447 }
1448 }
1449
1450 List<AssetEntry> list = q.list();
1451
1452 if (list.size() == 2) {
1453 return list.get(1);
1454 }
1455 else {
1456 return null;
1457 }
1458 }
1459
1460
1465 @Override
1466 public void removeByVisible(boolean visible) {
1467 for (AssetEntry assetEntry : findByVisible(visible, QueryUtil.ALL_POS,
1468 QueryUtil.ALL_POS, null)) {
1469 remove(assetEntry);
1470 }
1471 }
1472
1473
1479 @Override
1480 public int countByVisible(boolean visible) {
1481 FinderPath finderPath = FINDER_PATH_COUNT_BY_VISIBLE;
1482
1483 Object[] finderArgs = new Object[] { visible };
1484
1485 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1486 this);
1487
1488 if (count == null) {
1489 StringBundler query = new StringBundler(2);
1490
1491 query.append(_SQL_COUNT_ASSETENTRY_WHERE);
1492
1493 query.append(_FINDER_COLUMN_VISIBLE_VISIBLE_2);
1494
1495 String sql = query.toString();
1496
1497 Session session = null;
1498
1499 try {
1500 session = openSession();
1501
1502 Query q = session.createQuery(sql);
1503
1504 QueryPos qPos = QueryPos.getInstance(q);
1505
1506 qPos.add(visible);
1507
1508 count = (Long)q.uniqueResult();
1509
1510 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1511 }
1512 catch (Exception e) {
1513 FinderCacheUtil.removeResult(finderPath, finderArgs);
1514
1515 throw processException(e);
1516 }
1517 finally {
1518 closeSession(session);
1519 }
1520 }
1521
1522 return count.intValue();
1523 }
1524
1525 private static final String _FINDER_COLUMN_VISIBLE_VISIBLE_2 = "assetEntry.visible = ?";
1526 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_PUBLISHDATE =
1527 new FinderPath(AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
1528 AssetEntryModelImpl.FINDER_CACHE_ENABLED, AssetEntryImpl.class,
1529 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByPublishDate",
1530 new String[] {
1531 Date.class.getName(),
1532
1533 Integer.class.getName(), Integer.class.getName(),
1534 OrderByComparator.class.getName()
1535 });
1536 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PUBLISHDATE =
1537 new FinderPath(AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
1538 AssetEntryModelImpl.FINDER_CACHE_ENABLED, AssetEntryImpl.class,
1539 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByPublishDate",
1540 new String[] { Date.class.getName() },
1541 AssetEntryModelImpl.PUBLISHDATE_COLUMN_BITMASK);
1542 public static final FinderPath FINDER_PATH_COUNT_BY_PUBLISHDATE = new FinderPath(AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
1543 AssetEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
1544 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByPublishDate",
1545 new String[] { Date.class.getName() });
1546
1547
1553 @Override
1554 public List<AssetEntry> findByPublishDate(Date publishDate) {
1555 return findByPublishDate(publishDate, QueryUtil.ALL_POS,
1556 QueryUtil.ALL_POS, null);
1557 }
1558
1559
1571 @Override
1572 public List<AssetEntry> findByPublishDate(Date publishDate, int start,
1573 int end) {
1574 return findByPublishDate(publishDate, start, end, null);
1575 }
1576
1577
1590 @Override
1591 public List<AssetEntry> findByPublishDate(Date publishDate, int start,
1592 int end, OrderByComparator<AssetEntry> orderByComparator) {
1593 boolean pagination = true;
1594 FinderPath finderPath = null;
1595 Object[] finderArgs = null;
1596
1597 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1598 (orderByComparator == null)) {
1599 pagination = false;
1600 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PUBLISHDATE;
1601 finderArgs = new Object[] { publishDate };
1602 }
1603 else {
1604 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_PUBLISHDATE;
1605 finderArgs = new Object[] { publishDate, start, end, orderByComparator };
1606 }
1607
1608 List<AssetEntry> list = (List<AssetEntry>)FinderCacheUtil.getResult(finderPath,
1609 finderArgs, this);
1610
1611 if ((list != null) && !list.isEmpty()) {
1612 for (AssetEntry assetEntry : list) {
1613 if (!Validator.equals(publishDate, assetEntry.getPublishDate())) {
1614 list = null;
1615
1616 break;
1617 }
1618 }
1619 }
1620
1621 if (list == null) {
1622 StringBundler query = null;
1623
1624 if (orderByComparator != null) {
1625 query = new StringBundler(3 +
1626 (orderByComparator.getOrderByFields().length * 3));
1627 }
1628 else {
1629 query = new StringBundler(3);
1630 }
1631
1632 query.append(_SQL_SELECT_ASSETENTRY_WHERE);
1633
1634 boolean bindPublishDate = false;
1635
1636 if (publishDate == null) {
1637 query.append(_FINDER_COLUMN_PUBLISHDATE_PUBLISHDATE_1);
1638 }
1639 else {
1640 bindPublishDate = true;
1641
1642 query.append(_FINDER_COLUMN_PUBLISHDATE_PUBLISHDATE_2);
1643 }
1644
1645 if (orderByComparator != null) {
1646 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1647 orderByComparator);
1648 }
1649 else
1650 if (pagination) {
1651 query.append(AssetEntryModelImpl.ORDER_BY_JPQL);
1652 }
1653
1654 String sql = query.toString();
1655
1656 Session session = null;
1657
1658 try {
1659 session = openSession();
1660
1661 Query q = session.createQuery(sql);
1662
1663 QueryPos qPos = QueryPos.getInstance(q);
1664
1665 if (bindPublishDate) {
1666 qPos.add(new Timestamp(publishDate.getTime()));
1667 }
1668
1669 if (!pagination) {
1670 list = (List<AssetEntry>)QueryUtil.list(q, getDialect(),
1671 start, end, false);
1672
1673 Collections.sort(list);
1674
1675 list = Collections.unmodifiableList(list);
1676 }
1677 else {
1678 list = (List<AssetEntry>)QueryUtil.list(q, getDialect(),
1679 start, end);
1680 }
1681
1682 cacheResult(list);
1683
1684 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1685 }
1686 catch (Exception e) {
1687 FinderCacheUtil.removeResult(finderPath, finderArgs);
1688
1689 throw processException(e);
1690 }
1691 finally {
1692 closeSession(session);
1693 }
1694 }
1695
1696 return list;
1697 }
1698
1699
1707 @Override
1708 public AssetEntry findByPublishDate_First(Date publishDate,
1709 OrderByComparator<AssetEntry> orderByComparator)
1710 throws NoSuchEntryException {
1711 AssetEntry assetEntry = fetchByPublishDate_First(publishDate,
1712 orderByComparator);
1713
1714 if (assetEntry != null) {
1715 return assetEntry;
1716 }
1717
1718 StringBundler msg = new StringBundler(4);
1719
1720 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1721
1722 msg.append("publishDate=");
1723 msg.append(publishDate);
1724
1725 msg.append(StringPool.CLOSE_CURLY_BRACE);
1726
1727 throw new NoSuchEntryException(msg.toString());
1728 }
1729
1730
1737 @Override
1738 public AssetEntry fetchByPublishDate_First(Date publishDate,
1739 OrderByComparator<AssetEntry> orderByComparator) {
1740 List<AssetEntry> list = findByPublishDate(publishDate, 0, 1,
1741 orderByComparator);
1742
1743 if (!list.isEmpty()) {
1744 return list.get(0);
1745 }
1746
1747 return null;
1748 }
1749
1750
1758 @Override
1759 public AssetEntry findByPublishDate_Last(Date publishDate,
1760 OrderByComparator<AssetEntry> orderByComparator)
1761 throws NoSuchEntryException {
1762 AssetEntry assetEntry = fetchByPublishDate_Last(publishDate,
1763 orderByComparator);
1764
1765 if (assetEntry != null) {
1766 return assetEntry;
1767 }
1768
1769 StringBundler msg = new StringBundler(4);
1770
1771 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1772
1773 msg.append("publishDate=");
1774 msg.append(publishDate);
1775
1776 msg.append(StringPool.CLOSE_CURLY_BRACE);
1777
1778 throw new NoSuchEntryException(msg.toString());
1779 }
1780
1781
1788 @Override
1789 public AssetEntry fetchByPublishDate_Last(Date publishDate,
1790 OrderByComparator<AssetEntry> orderByComparator) {
1791 int count = countByPublishDate(publishDate);
1792
1793 if (count == 0) {
1794 return null;
1795 }
1796
1797 List<AssetEntry> list = findByPublishDate(publishDate, count - 1,
1798 count, orderByComparator);
1799
1800 if (!list.isEmpty()) {
1801 return list.get(0);
1802 }
1803
1804 return null;
1805 }
1806
1807
1816 @Override
1817 public AssetEntry[] findByPublishDate_PrevAndNext(long entryId,
1818 Date publishDate, OrderByComparator<AssetEntry> orderByComparator)
1819 throws NoSuchEntryException {
1820 AssetEntry assetEntry = findByPrimaryKey(entryId);
1821
1822 Session session = null;
1823
1824 try {
1825 session = openSession();
1826
1827 AssetEntry[] array = new AssetEntryImpl[3];
1828
1829 array[0] = getByPublishDate_PrevAndNext(session, assetEntry,
1830 publishDate, orderByComparator, true);
1831
1832 array[1] = assetEntry;
1833
1834 array[2] = getByPublishDate_PrevAndNext(session, assetEntry,
1835 publishDate, orderByComparator, false);
1836
1837 return array;
1838 }
1839 catch (Exception e) {
1840 throw processException(e);
1841 }
1842 finally {
1843 closeSession(session);
1844 }
1845 }
1846
1847 protected AssetEntry getByPublishDate_PrevAndNext(Session session,
1848 AssetEntry assetEntry, Date publishDate,
1849 OrderByComparator<AssetEntry> orderByComparator, boolean previous) {
1850 StringBundler query = null;
1851
1852 if (orderByComparator != null) {
1853 query = new StringBundler(6 +
1854 (orderByComparator.getOrderByFields().length * 6));
1855 }
1856 else {
1857 query = new StringBundler(3);
1858 }
1859
1860 query.append(_SQL_SELECT_ASSETENTRY_WHERE);
1861
1862 boolean bindPublishDate = false;
1863
1864 if (publishDate == null) {
1865 query.append(_FINDER_COLUMN_PUBLISHDATE_PUBLISHDATE_1);
1866 }
1867 else {
1868 bindPublishDate = true;
1869
1870 query.append(_FINDER_COLUMN_PUBLISHDATE_PUBLISHDATE_2);
1871 }
1872
1873 if (orderByComparator != null) {
1874 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1875
1876 if (orderByConditionFields.length > 0) {
1877 query.append(WHERE_AND);
1878 }
1879
1880 for (int i = 0; i < orderByConditionFields.length; i++) {
1881 query.append(_ORDER_BY_ENTITY_ALIAS);
1882 query.append(orderByConditionFields[i]);
1883
1884 if ((i + 1) < orderByConditionFields.length) {
1885 if (orderByComparator.isAscending() ^ previous) {
1886 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1887 }
1888 else {
1889 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1890 }
1891 }
1892 else {
1893 if (orderByComparator.isAscending() ^ previous) {
1894 query.append(WHERE_GREATER_THAN);
1895 }
1896 else {
1897 query.append(WHERE_LESSER_THAN);
1898 }
1899 }
1900 }
1901
1902 query.append(ORDER_BY_CLAUSE);
1903
1904 String[] orderByFields = orderByComparator.getOrderByFields();
1905
1906 for (int i = 0; i < orderByFields.length; i++) {
1907 query.append(_ORDER_BY_ENTITY_ALIAS);
1908 query.append(orderByFields[i]);
1909
1910 if ((i + 1) < orderByFields.length) {
1911 if (orderByComparator.isAscending() ^ previous) {
1912 query.append(ORDER_BY_ASC_HAS_NEXT);
1913 }
1914 else {
1915 query.append(ORDER_BY_DESC_HAS_NEXT);
1916 }
1917 }
1918 else {
1919 if (orderByComparator.isAscending() ^ previous) {
1920 query.append(ORDER_BY_ASC);
1921 }
1922 else {
1923 query.append(ORDER_BY_DESC);
1924 }
1925 }
1926 }
1927 }
1928 else {
1929 query.append(AssetEntryModelImpl.ORDER_BY_JPQL);
1930 }
1931
1932 String sql = query.toString();
1933
1934 Query q = session.createQuery(sql);
1935
1936 q.setFirstResult(0);
1937 q.setMaxResults(2);
1938
1939 QueryPos qPos = QueryPos.getInstance(q);
1940
1941 if (bindPublishDate) {
1942 qPos.add(new Timestamp(publishDate.getTime()));
1943 }
1944
1945 if (orderByComparator != null) {
1946 Object[] values = orderByComparator.getOrderByConditionValues(assetEntry);
1947
1948 for (Object value : values) {
1949 qPos.add(value);
1950 }
1951 }
1952
1953 List<AssetEntry> list = q.list();
1954
1955 if (list.size() == 2) {
1956 return list.get(1);
1957 }
1958 else {
1959 return null;
1960 }
1961 }
1962
1963
1968 @Override
1969 public void removeByPublishDate(Date publishDate) {
1970 for (AssetEntry assetEntry : findByPublishDate(publishDate,
1971 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1972 remove(assetEntry);
1973 }
1974 }
1975
1976
1982 @Override
1983 public int countByPublishDate(Date publishDate) {
1984 FinderPath finderPath = FINDER_PATH_COUNT_BY_PUBLISHDATE;
1985
1986 Object[] finderArgs = new Object[] { publishDate };
1987
1988 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1989 this);
1990
1991 if (count == null) {
1992 StringBundler query = new StringBundler(2);
1993
1994 query.append(_SQL_COUNT_ASSETENTRY_WHERE);
1995
1996 boolean bindPublishDate = false;
1997
1998 if (publishDate == null) {
1999 query.append(_FINDER_COLUMN_PUBLISHDATE_PUBLISHDATE_1);
2000 }
2001 else {
2002 bindPublishDate = true;
2003
2004 query.append(_FINDER_COLUMN_PUBLISHDATE_PUBLISHDATE_2);
2005 }
2006
2007 String sql = query.toString();
2008
2009 Session session = null;
2010
2011 try {
2012 session = openSession();
2013
2014 Query q = session.createQuery(sql);
2015
2016 QueryPos qPos = QueryPos.getInstance(q);
2017
2018 if (bindPublishDate) {
2019 qPos.add(new Timestamp(publishDate.getTime()));
2020 }
2021
2022 count = (Long)q.uniqueResult();
2023
2024 FinderCacheUtil.putResult(finderPath, finderArgs, count);
2025 }
2026 catch (Exception e) {
2027 FinderCacheUtil.removeResult(finderPath, finderArgs);
2028
2029 throw processException(e);
2030 }
2031 finally {
2032 closeSession(session);
2033 }
2034 }
2035
2036 return count.intValue();
2037 }
2038
2039 private static final String _FINDER_COLUMN_PUBLISHDATE_PUBLISHDATE_1 = "assetEntry.publishDate IS NULL";
2040 private static final String _FINDER_COLUMN_PUBLISHDATE_PUBLISHDATE_2 = "assetEntry.publishDate = ?";
2041 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_EXPIRATIONDATE =
2042 new FinderPath(AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
2043 AssetEntryModelImpl.FINDER_CACHE_ENABLED, AssetEntryImpl.class,
2044 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByExpirationDate",
2045 new String[] {
2046 Date.class.getName(),
2047
2048 Integer.class.getName(), Integer.class.getName(),
2049 OrderByComparator.class.getName()
2050 });
2051 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_EXPIRATIONDATE =
2052 new FinderPath(AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
2053 AssetEntryModelImpl.FINDER_CACHE_ENABLED, AssetEntryImpl.class,
2054 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByExpirationDate",
2055 new String[] { Date.class.getName() },
2056 AssetEntryModelImpl.EXPIRATIONDATE_COLUMN_BITMASK);
2057 public static final FinderPath FINDER_PATH_COUNT_BY_EXPIRATIONDATE = new FinderPath(AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
2058 AssetEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
2059 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByExpirationDate",
2060 new String[] { Date.class.getName() });
2061
2062
2068 @Override
2069 public List<AssetEntry> findByExpirationDate(Date expirationDate) {
2070 return findByExpirationDate(expirationDate, QueryUtil.ALL_POS,
2071 QueryUtil.ALL_POS, null);
2072 }
2073
2074
2086 @Override
2087 public List<AssetEntry> findByExpirationDate(Date expirationDate,
2088 int start, int end) {
2089 return findByExpirationDate(expirationDate, start, end, null);
2090 }
2091
2092
2105 @Override
2106 public List<AssetEntry> findByExpirationDate(Date expirationDate,
2107 int start, int end, OrderByComparator<AssetEntry> orderByComparator) {
2108 boolean pagination = true;
2109 FinderPath finderPath = null;
2110 Object[] finderArgs = null;
2111
2112 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2113 (orderByComparator == null)) {
2114 pagination = false;
2115 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_EXPIRATIONDATE;
2116 finderArgs = new Object[] { expirationDate };
2117 }
2118 else {
2119 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_EXPIRATIONDATE;
2120 finderArgs = new Object[] {
2121 expirationDate,
2122
2123 start, end, orderByComparator
2124 };
2125 }
2126
2127 List<AssetEntry> list = (List<AssetEntry>)FinderCacheUtil.getResult(finderPath,
2128 finderArgs, this);
2129
2130 if ((list != null) && !list.isEmpty()) {
2131 for (AssetEntry assetEntry : list) {
2132 if (!Validator.equals(expirationDate,
2133 assetEntry.getExpirationDate())) {
2134 list = null;
2135
2136 break;
2137 }
2138 }
2139 }
2140
2141 if (list == null) {
2142 StringBundler query = null;
2143
2144 if (orderByComparator != null) {
2145 query = new StringBundler(3 +
2146 (orderByComparator.getOrderByFields().length * 3));
2147 }
2148 else {
2149 query = new StringBundler(3);
2150 }
2151
2152 query.append(_SQL_SELECT_ASSETENTRY_WHERE);
2153
2154 boolean bindExpirationDate = false;
2155
2156 if (expirationDate == null) {
2157 query.append(_FINDER_COLUMN_EXPIRATIONDATE_EXPIRATIONDATE_1);
2158 }
2159 else {
2160 bindExpirationDate = true;
2161
2162 query.append(_FINDER_COLUMN_EXPIRATIONDATE_EXPIRATIONDATE_2);
2163 }
2164
2165 if (orderByComparator != null) {
2166 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2167 orderByComparator);
2168 }
2169 else
2170 if (pagination) {
2171 query.append(AssetEntryModelImpl.ORDER_BY_JPQL);
2172 }
2173
2174 String sql = query.toString();
2175
2176 Session session = null;
2177
2178 try {
2179 session = openSession();
2180
2181 Query q = session.createQuery(sql);
2182
2183 QueryPos qPos = QueryPos.getInstance(q);
2184
2185 if (bindExpirationDate) {
2186 qPos.add(new Timestamp(expirationDate.getTime()));
2187 }
2188
2189 if (!pagination) {
2190 list = (List<AssetEntry>)QueryUtil.list(q, getDialect(),
2191 start, end, false);
2192
2193 Collections.sort(list);
2194
2195 list = Collections.unmodifiableList(list);
2196 }
2197 else {
2198 list = (List<AssetEntry>)QueryUtil.list(q, getDialect(),
2199 start, end);
2200 }
2201
2202 cacheResult(list);
2203
2204 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2205 }
2206 catch (Exception e) {
2207 FinderCacheUtil.removeResult(finderPath, finderArgs);
2208
2209 throw processException(e);
2210 }
2211 finally {
2212 closeSession(session);
2213 }
2214 }
2215
2216 return list;
2217 }
2218
2219
2227 @Override
2228 public AssetEntry findByExpirationDate_First(Date expirationDate,
2229 OrderByComparator<AssetEntry> orderByComparator)
2230 throws NoSuchEntryException {
2231 AssetEntry assetEntry = fetchByExpirationDate_First(expirationDate,
2232 orderByComparator);
2233
2234 if (assetEntry != null) {
2235 return assetEntry;
2236 }
2237
2238 StringBundler msg = new StringBundler(4);
2239
2240 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2241
2242 msg.append("expirationDate=");
2243 msg.append(expirationDate);
2244
2245 msg.append(StringPool.CLOSE_CURLY_BRACE);
2246
2247 throw new NoSuchEntryException(msg.toString());
2248 }
2249
2250
2257 @Override
2258 public AssetEntry fetchByExpirationDate_First(Date expirationDate,
2259 OrderByComparator<AssetEntry> orderByComparator) {
2260 List<AssetEntry> list = findByExpirationDate(expirationDate, 0, 1,
2261 orderByComparator);
2262
2263 if (!list.isEmpty()) {
2264 return list.get(0);
2265 }
2266
2267 return null;
2268 }
2269
2270
2278 @Override
2279 public AssetEntry findByExpirationDate_Last(Date expirationDate,
2280 OrderByComparator<AssetEntry> orderByComparator)
2281 throws NoSuchEntryException {
2282 AssetEntry assetEntry = fetchByExpirationDate_Last(expirationDate,
2283 orderByComparator);
2284
2285 if (assetEntry != null) {
2286 return assetEntry;
2287 }
2288
2289 StringBundler msg = new StringBundler(4);
2290
2291 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2292
2293 msg.append("expirationDate=");
2294 msg.append(expirationDate);
2295
2296 msg.append(StringPool.CLOSE_CURLY_BRACE);
2297
2298 throw new NoSuchEntryException(msg.toString());
2299 }
2300
2301
2308 @Override
2309 public AssetEntry fetchByExpirationDate_Last(Date expirationDate,
2310 OrderByComparator<AssetEntry> orderByComparator) {
2311 int count = countByExpirationDate(expirationDate);
2312
2313 if (count == 0) {
2314 return null;
2315 }
2316
2317 List<AssetEntry> list = findByExpirationDate(expirationDate, count - 1,
2318 count, orderByComparator);
2319
2320 if (!list.isEmpty()) {
2321 return list.get(0);
2322 }
2323
2324 return null;
2325 }
2326
2327
2336 @Override
2337 public AssetEntry[] findByExpirationDate_PrevAndNext(long entryId,
2338 Date expirationDate, OrderByComparator<AssetEntry> orderByComparator)
2339 throws NoSuchEntryException {
2340 AssetEntry assetEntry = findByPrimaryKey(entryId);
2341
2342 Session session = null;
2343
2344 try {
2345 session = openSession();
2346
2347 AssetEntry[] array = new AssetEntryImpl[3];
2348
2349 array[0] = getByExpirationDate_PrevAndNext(session, assetEntry,
2350 expirationDate, orderByComparator, true);
2351
2352 array[1] = assetEntry;
2353
2354 array[2] = getByExpirationDate_PrevAndNext(session, assetEntry,
2355 expirationDate, orderByComparator, false);
2356
2357 return array;
2358 }
2359 catch (Exception e) {
2360 throw processException(e);
2361 }
2362 finally {
2363 closeSession(session);
2364 }
2365 }
2366
2367 protected AssetEntry getByExpirationDate_PrevAndNext(Session session,
2368 AssetEntry assetEntry, Date expirationDate,
2369 OrderByComparator<AssetEntry> orderByComparator, boolean previous) {
2370 StringBundler query = null;
2371
2372 if (orderByComparator != null) {
2373 query = new StringBundler(6 +
2374 (orderByComparator.getOrderByFields().length * 6));
2375 }
2376 else {
2377 query = new StringBundler(3);
2378 }
2379
2380 query.append(_SQL_SELECT_ASSETENTRY_WHERE);
2381
2382 boolean bindExpirationDate = false;
2383
2384 if (expirationDate == null) {
2385 query.append(_FINDER_COLUMN_EXPIRATIONDATE_EXPIRATIONDATE_1);
2386 }
2387 else {
2388 bindExpirationDate = true;
2389
2390 query.append(_FINDER_COLUMN_EXPIRATIONDATE_EXPIRATIONDATE_2);
2391 }
2392
2393 if (orderByComparator != null) {
2394 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2395
2396 if (orderByConditionFields.length > 0) {
2397 query.append(WHERE_AND);
2398 }
2399
2400 for (int i = 0; i < orderByConditionFields.length; i++) {
2401 query.append(_ORDER_BY_ENTITY_ALIAS);
2402 query.append(orderByConditionFields[i]);
2403
2404 if ((i + 1) < orderByConditionFields.length) {
2405 if (orderByComparator.isAscending() ^ previous) {
2406 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2407 }
2408 else {
2409 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2410 }
2411 }
2412 else {
2413 if (orderByComparator.isAscending() ^ previous) {
2414 query.append(WHERE_GREATER_THAN);
2415 }
2416 else {
2417 query.append(WHERE_LESSER_THAN);
2418 }
2419 }
2420 }
2421
2422 query.append(ORDER_BY_CLAUSE);
2423
2424 String[] orderByFields = orderByComparator.getOrderByFields();
2425
2426 for (int i = 0; i < orderByFields.length; i++) {
2427 query.append(_ORDER_BY_ENTITY_ALIAS);
2428 query.append(orderByFields[i]);
2429
2430 if ((i + 1) < orderByFields.length) {
2431 if (orderByComparator.isAscending() ^ previous) {
2432 query.append(ORDER_BY_ASC_HAS_NEXT);
2433 }
2434 else {
2435 query.append(ORDER_BY_DESC_HAS_NEXT);
2436 }
2437 }
2438 else {
2439 if (orderByComparator.isAscending() ^ previous) {
2440 query.append(ORDER_BY_ASC);
2441 }
2442 else {
2443 query.append(ORDER_BY_DESC);
2444 }
2445 }
2446 }
2447 }
2448 else {
2449 query.append(AssetEntryModelImpl.ORDER_BY_JPQL);
2450 }
2451
2452 String sql = query.toString();
2453
2454 Query q = session.createQuery(sql);
2455
2456 q.setFirstResult(0);
2457 q.setMaxResults(2);
2458
2459 QueryPos qPos = QueryPos.getInstance(q);
2460
2461 if (bindExpirationDate) {
2462 qPos.add(new Timestamp(expirationDate.getTime()));
2463 }
2464
2465 if (orderByComparator != null) {
2466 Object[] values = orderByComparator.getOrderByConditionValues(assetEntry);
2467
2468 for (Object value : values) {
2469 qPos.add(value);
2470 }
2471 }
2472
2473 List<AssetEntry> list = q.list();
2474
2475 if (list.size() == 2) {
2476 return list.get(1);
2477 }
2478 else {
2479 return null;
2480 }
2481 }
2482
2483
2488 @Override
2489 public void removeByExpirationDate(Date expirationDate) {
2490 for (AssetEntry assetEntry : findByExpirationDate(expirationDate,
2491 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2492 remove(assetEntry);
2493 }
2494 }
2495
2496
2502 @Override
2503 public int countByExpirationDate(Date expirationDate) {
2504 FinderPath finderPath = FINDER_PATH_COUNT_BY_EXPIRATIONDATE;
2505
2506 Object[] finderArgs = new Object[] { expirationDate };
2507
2508 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2509 this);
2510
2511 if (count == null) {
2512 StringBundler query = new StringBundler(2);
2513
2514 query.append(_SQL_COUNT_ASSETENTRY_WHERE);
2515
2516 boolean bindExpirationDate = false;
2517
2518 if (expirationDate == null) {
2519 query.append(_FINDER_COLUMN_EXPIRATIONDATE_EXPIRATIONDATE_1);
2520 }
2521 else {
2522 bindExpirationDate = true;
2523
2524 query.append(_FINDER_COLUMN_EXPIRATIONDATE_EXPIRATIONDATE_2);
2525 }
2526
2527 String sql = query.toString();
2528
2529 Session session = null;
2530
2531 try {
2532 session = openSession();
2533
2534 Query q = session.createQuery(sql);
2535
2536 QueryPos qPos = QueryPos.getInstance(q);
2537
2538 if (bindExpirationDate) {
2539 qPos.add(new Timestamp(expirationDate.getTime()));
2540 }
2541
2542 count = (Long)q.uniqueResult();
2543
2544 FinderCacheUtil.putResult(finderPath, finderArgs, count);
2545 }
2546 catch (Exception e) {
2547 FinderCacheUtil.removeResult(finderPath, finderArgs);
2548
2549 throw processException(e);
2550 }
2551 finally {
2552 closeSession(session);
2553 }
2554 }
2555
2556 return count.intValue();
2557 }
2558
2559 private static final String _FINDER_COLUMN_EXPIRATIONDATE_EXPIRATIONDATE_1 = "assetEntry.expirationDate IS NULL";
2560 private static final String _FINDER_COLUMN_EXPIRATIONDATE_EXPIRATIONDATE_2 = "assetEntry.expirationDate = ?";
2561 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_LAYOUTUUID =
2562 new FinderPath(AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
2563 AssetEntryModelImpl.FINDER_CACHE_ENABLED, AssetEntryImpl.class,
2564 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByLayoutUuid",
2565 new String[] {
2566 String.class.getName(),
2567
2568 Integer.class.getName(), Integer.class.getName(),
2569 OrderByComparator.class.getName()
2570 });
2571 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LAYOUTUUID =
2572 new FinderPath(AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
2573 AssetEntryModelImpl.FINDER_CACHE_ENABLED, AssetEntryImpl.class,
2574 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByLayoutUuid",
2575 new String[] { String.class.getName() },
2576 AssetEntryModelImpl.LAYOUTUUID_COLUMN_BITMASK);
2577 public static final FinderPath FINDER_PATH_COUNT_BY_LAYOUTUUID = new FinderPath(AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
2578 AssetEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
2579 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByLayoutUuid",
2580 new String[] { String.class.getName() });
2581
2582
2588 @Override
2589 public List<AssetEntry> findByLayoutUuid(String layoutUuid) {
2590 return findByLayoutUuid(layoutUuid, QueryUtil.ALL_POS,
2591 QueryUtil.ALL_POS, null);
2592 }
2593
2594
2606 @Override
2607 public List<AssetEntry> findByLayoutUuid(String layoutUuid, int start,
2608 int end) {
2609 return findByLayoutUuid(layoutUuid, start, end, null);
2610 }
2611
2612
2625 @Override
2626 public List<AssetEntry> findByLayoutUuid(String layoutUuid, int start,
2627 int end, OrderByComparator<AssetEntry> orderByComparator) {
2628 boolean pagination = true;
2629 FinderPath finderPath = null;
2630 Object[] finderArgs = null;
2631
2632 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2633 (orderByComparator == null)) {
2634 pagination = false;
2635 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LAYOUTUUID;
2636 finderArgs = new Object[] { layoutUuid };
2637 }
2638 else {
2639 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_LAYOUTUUID;
2640 finderArgs = new Object[] { layoutUuid, start, end, orderByComparator };
2641 }
2642
2643 List<AssetEntry> list = (List<AssetEntry>)FinderCacheUtil.getResult(finderPath,
2644 finderArgs, this);
2645
2646 if ((list != null) && !list.isEmpty()) {
2647 for (AssetEntry assetEntry : list) {
2648 if (!Validator.equals(layoutUuid, assetEntry.getLayoutUuid())) {
2649 list = null;
2650
2651 break;
2652 }
2653 }
2654 }
2655
2656 if (list == null) {
2657 StringBundler query = null;
2658
2659 if (orderByComparator != null) {
2660 query = new StringBundler(3 +
2661 (orderByComparator.getOrderByFields().length * 3));
2662 }
2663 else {
2664 query = new StringBundler(3);
2665 }
2666
2667 query.append(_SQL_SELECT_ASSETENTRY_WHERE);
2668
2669 boolean bindLayoutUuid = false;
2670
2671 if (layoutUuid == null) {
2672 query.append(_FINDER_COLUMN_LAYOUTUUID_LAYOUTUUID_1);
2673 }
2674 else if (layoutUuid.equals(StringPool.BLANK)) {
2675 query.append(_FINDER_COLUMN_LAYOUTUUID_LAYOUTUUID_3);
2676 }
2677 else {
2678 bindLayoutUuid = true;
2679
2680 query.append(_FINDER_COLUMN_LAYOUTUUID_LAYOUTUUID_2);
2681 }
2682
2683 if (orderByComparator != null) {
2684 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2685 orderByComparator);
2686 }
2687 else
2688 if (pagination) {
2689 query.append(AssetEntryModelImpl.ORDER_BY_JPQL);
2690 }
2691
2692 String sql = query.toString();
2693
2694 Session session = null;
2695
2696 try {
2697 session = openSession();
2698
2699 Query q = session.createQuery(sql);
2700
2701 QueryPos qPos = QueryPos.getInstance(q);
2702
2703 if (bindLayoutUuid) {
2704 qPos.add(layoutUuid);
2705 }
2706
2707 if (!pagination) {
2708 list = (List<AssetEntry>)QueryUtil.list(q, getDialect(),
2709 start, end, false);
2710
2711 Collections.sort(list);
2712
2713 list = Collections.unmodifiableList(list);
2714 }
2715 else {
2716 list = (List<AssetEntry>)QueryUtil.list(q, getDialect(),
2717 start, end);
2718 }
2719
2720 cacheResult(list);
2721
2722 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2723 }
2724 catch (Exception e) {
2725 FinderCacheUtil.removeResult(finderPath, finderArgs);
2726
2727 throw processException(e);
2728 }
2729 finally {
2730 closeSession(session);
2731 }
2732 }
2733
2734 return list;
2735 }
2736
2737
2745 @Override
2746 public AssetEntry findByLayoutUuid_First(String layoutUuid,
2747 OrderByComparator<AssetEntry> orderByComparator)
2748 throws NoSuchEntryException {
2749 AssetEntry assetEntry = fetchByLayoutUuid_First(layoutUuid,
2750 orderByComparator);
2751
2752 if (assetEntry != null) {
2753 return assetEntry;
2754 }
2755
2756 StringBundler msg = new StringBundler(4);
2757
2758 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2759
2760 msg.append("layoutUuid=");
2761 msg.append(layoutUuid);
2762
2763 msg.append(StringPool.CLOSE_CURLY_BRACE);
2764
2765 throw new NoSuchEntryException(msg.toString());
2766 }
2767
2768
2775 @Override
2776 public AssetEntry fetchByLayoutUuid_First(String layoutUuid,
2777 OrderByComparator<AssetEntry> orderByComparator) {
2778 List<AssetEntry> list = findByLayoutUuid(layoutUuid, 0, 1,
2779 orderByComparator);
2780
2781 if (!list.isEmpty()) {
2782 return list.get(0);
2783 }
2784
2785 return null;
2786 }
2787
2788
2796 @Override
2797 public AssetEntry findByLayoutUuid_Last(String layoutUuid,
2798 OrderByComparator<AssetEntry> orderByComparator)
2799 throws NoSuchEntryException {
2800 AssetEntry assetEntry = fetchByLayoutUuid_Last(layoutUuid,
2801 orderByComparator);
2802
2803 if (assetEntry != null) {
2804 return assetEntry;
2805 }
2806
2807 StringBundler msg = new StringBundler(4);
2808
2809 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2810
2811 msg.append("layoutUuid=");
2812 msg.append(layoutUuid);
2813
2814 msg.append(StringPool.CLOSE_CURLY_BRACE);
2815
2816 throw new NoSuchEntryException(msg.toString());
2817 }
2818
2819
2826 @Override
2827 public AssetEntry fetchByLayoutUuid_Last(String layoutUuid,
2828 OrderByComparator<AssetEntry> orderByComparator) {
2829 int count = countByLayoutUuid(layoutUuid);
2830
2831 if (count == 0) {
2832 return null;
2833 }
2834
2835 List<AssetEntry> list = findByLayoutUuid(layoutUuid, count - 1, count,
2836 orderByComparator);
2837
2838 if (!list.isEmpty()) {
2839 return list.get(0);
2840 }
2841
2842 return null;
2843 }
2844
2845
2854 @Override
2855 public AssetEntry[] findByLayoutUuid_PrevAndNext(long entryId,
2856 String layoutUuid, OrderByComparator<AssetEntry> orderByComparator)
2857 throws NoSuchEntryException {
2858 AssetEntry assetEntry = findByPrimaryKey(entryId);
2859
2860 Session session = null;
2861
2862 try {
2863 session = openSession();
2864
2865 AssetEntry[] array = new AssetEntryImpl[3];
2866
2867 array[0] = getByLayoutUuid_PrevAndNext(session, assetEntry,
2868 layoutUuid, orderByComparator, true);
2869
2870 array[1] = assetEntry;
2871
2872 array[2] = getByLayoutUuid_PrevAndNext(session, assetEntry,
2873 layoutUuid, orderByComparator, false);
2874
2875 return array;
2876 }
2877 catch (Exception e) {
2878 throw processException(e);
2879 }
2880 finally {
2881 closeSession(session);
2882 }
2883 }
2884
2885 protected AssetEntry getByLayoutUuid_PrevAndNext(Session session,
2886 AssetEntry assetEntry, String layoutUuid,
2887 OrderByComparator<AssetEntry> orderByComparator, boolean previous) {
2888 StringBundler query = null;
2889
2890 if (orderByComparator != null) {
2891 query = new StringBundler(6 +
2892 (orderByComparator.getOrderByFields().length * 6));
2893 }
2894 else {
2895 query = new StringBundler(3);
2896 }
2897
2898 query.append(_SQL_SELECT_ASSETENTRY_WHERE);
2899
2900 boolean bindLayoutUuid = false;
2901
2902 if (layoutUuid == null) {
2903 query.append(_FINDER_COLUMN_LAYOUTUUID_LAYOUTUUID_1);
2904 }
2905 else if (layoutUuid.equals(StringPool.BLANK)) {
2906 query.append(_FINDER_COLUMN_LAYOUTUUID_LAYOUTUUID_3);
2907 }
2908 else {
2909 bindLayoutUuid = true;
2910
2911 query.append(_FINDER_COLUMN_LAYOUTUUID_LAYOUTUUID_2);
2912 }
2913
2914 if (orderByComparator != null) {
2915 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2916
2917 if (orderByConditionFields.length > 0) {
2918 query.append(WHERE_AND);
2919 }
2920
2921 for (int i = 0; i < orderByConditionFields.length; i++) {
2922 query.append(_ORDER_BY_ENTITY_ALIAS);
2923 query.append(orderByConditionFields[i]);
2924
2925 if ((i + 1) < orderByConditionFields.length) {
2926 if (orderByComparator.isAscending() ^ previous) {
2927 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2928 }
2929 else {
2930 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2931 }
2932 }
2933 else {
2934 if (orderByComparator.isAscending() ^ previous) {
2935 query.append(WHERE_GREATER_THAN);
2936 }
2937 else {
2938 query.append(WHERE_LESSER_THAN);
2939 }
2940 }
2941 }
2942
2943 query.append(ORDER_BY_CLAUSE);
2944
2945 String[] orderByFields = orderByComparator.getOrderByFields();
2946
2947 for (int i = 0; i < orderByFields.length; i++) {
2948 query.append(_ORDER_BY_ENTITY_ALIAS);
2949 query.append(orderByFields[i]);
2950
2951 if ((i + 1) < orderByFields.length) {
2952 if (orderByComparator.isAscending() ^ previous) {
2953 query.append(ORDER_BY_ASC_HAS_NEXT);
2954 }
2955 else {
2956 query.append(ORDER_BY_DESC_HAS_NEXT);
2957 }
2958 }
2959 else {
2960 if (orderByComparator.isAscending() ^ previous) {
2961 query.append(ORDER_BY_ASC);
2962 }
2963 else {
2964 query.append(ORDER_BY_DESC);
2965 }
2966 }
2967 }
2968 }
2969 else {
2970 query.append(AssetEntryModelImpl.ORDER_BY_JPQL);
2971 }
2972
2973 String sql = query.toString();
2974
2975 Query q = session.createQuery(sql);
2976
2977 q.setFirstResult(0);
2978 q.setMaxResults(2);
2979
2980 QueryPos qPos = QueryPos.getInstance(q);
2981
2982 if (bindLayoutUuid) {
2983 qPos.add(layoutUuid);
2984 }
2985
2986 if (orderByComparator != null) {
2987 Object[] values = orderByComparator.getOrderByConditionValues(assetEntry);
2988
2989 for (Object value : values) {
2990 qPos.add(value);
2991 }
2992 }
2993
2994 List<AssetEntry> list = q.list();
2995
2996 if (list.size() == 2) {
2997 return list.get(1);
2998 }
2999 else {
3000 return null;
3001 }
3002 }
3003
3004
3009 @Override
3010 public void removeByLayoutUuid(String layoutUuid) {
3011 for (AssetEntry assetEntry : findByLayoutUuid(layoutUuid,
3012 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3013 remove(assetEntry);
3014 }
3015 }
3016
3017
3023 @Override
3024 public int countByLayoutUuid(String layoutUuid) {
3025 FinderPath finderPath = FINDER_PATH_COUNT_BY_LAYOUTUUID;
3026
3027 Object[] finderArgs = new Object[] { layoutUuid };
3028
3029 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3030 this);
3031
3032 if (count == null) {
3033 StringBundler query = new StringBundler(2);
3034
3035 query.append(_SQL_COUNT_ASSETENTRY_WHERE);
3036
3037 boolean bindLayoutUuid = false;
3038
3039 if (layoutUuid == null) {
3040 query.append(_FINDER_COLUMN_LAYOUTUUID_LAYOUTUUID_1);
3041 }
3042 else if (layoutUuid.equals(StringPool.BLANK)) {
3043 query.append(_FINDER_COLUMN_LAYOUTUUID_LAYOUTUUID_3);
3044 }
3045 else {
3046 bindLayoutUuid = true;
3047
3048 query.append(_FINDER_COLUMN_LAYOUTUUID_LAYOUTUUID_2);
3049 }
3050
3051 String sql = query.toString();
3052
3053 Session session = null;
3054
3055 try {
3056 session = openSession();
3057
3058 Query q = session.createQuery(sql);
3059
3060 QueryPos qPos = QueryPos.getInstance(q);
3061
3062 if (bindLayoutUuid) {
3063 qPos.add(layoutUuid);
3064 }
3065
3066 count = (Long)q.uniqueResult();
3067
3068 FinderCacheUtil.putResult(finderPath, finderArgs, count);
3069 }
3070 catch (Exception e) {
3071 FinderCacheUtil.removeResult(finderPath, finderArgs);
3072
3073 throw processException(e);
3074 }
3075 finally {
3076 closeSession(session);
3077 }
3078 }
3079
3080 return count.intValue();
3081 }
3082
3083 private static final String _FINDER_COLUMN_LAYOUTUUID_LAYOUTUUID_1 = "assetEntry.layoutUuid IS NULL";
3084 private static final String _FINDER_COLUMN_LAYOUTUUID_LAYOUTUUID_2 = "assetEntry.layoutUuid = ?";
3085 private static final String _FINDER_COLUMN_LAYOUTUUID_LAYOUTUUID_3 = "(assetEntry.layoutUuid IS NULL OR assetEntry.layoutUuid = '')";
3086 public static final FinderPath FINDER_PATH_FETCH_BY_G_CU = new FinderPath(AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
3087 AssetEntryModelImpl.FINDER_CACHE_ENABLED, AssetEntryImpl.class,
3088 FINDER_CLASS_NAME_ENTITY, "fetchByG_CU",
3089 new String[] { Long.class.getName(), String.class.getName() },
3090 AssetEntryModelImpl.GROUPID_COLUMN_BITMASK |
3091 AssetEntryModelImpl.CLASSUUID_COLUMN_BITMASK);
3092 public static final FinderPath FINDER_PATH_COUNT_BY_G_CU = new FinderPath(AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
3093 AssetEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
3094 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_CU",
3095 new String[] { Long.class.getName(), String.class.getName() });
3096
3097
3105 @Override
3106 public AssetEntry findByG_CU(long groupId, String classUuid)
3107 throws NoSuchEntryException {
3108 AssetEntry assetEntry = fetchByG_CU(groupId, classUuid);
3109
3110 if (assetEntry == null) {
3111 StringBundler msg = new StringBundler(6);
3112
3113 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3114
3115 msg.append("groupId=");
3116 msg.append(groupId);
3117
3118 msg.append(", classUuid=");
3119 msg.append(classUuid);
3120
3121 msg.append(StringPool.CLOSE_CURLY_BRACE);
3122
3123 if (_log.isWarnEnabled()) {
3124 _log.warn(msg.toString());
3125 }
3126
3127 throw new NoSuchEntryException(msg.toString());
3128 }
3129
3130 return assetEntry;
3131 }
3132
3133
3140 @Override
3141 public AssetEntry fetchByG_CU(long groupId, String classUuid) {
3142 return fetchByG_CU(groupId, classUuid, true);
3143 }
3144
3145
3153 @Override
3154 public AssetEntry fetchByG_CU(long groupId, String classUuid,
3155 boolean retrieveFromCache) {
3156 Object[] finderArgs = new Object[] { groupId, classUuid };
3157
3158 Object result = null;
3159
3160 if (retrieveFromCache) {
3161 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_CU,
3162 finderArgs, this);
3163 }
3164
3165 if (result instanceof AssetEntry) {
3166 AssetEntry assetEntry = (AssetEntry)result;
3167
3168 if ((groupId != assetEntry.getGroupId()) ||
3169 !Validator.equals(classUuid, assetEntry.getClassUuid())) {
3170 result = null;
3171 }
3172 }
3173
3174 if (result == null) {
3175 StringBundler query = new StringBundler(4);
3176
3177 query.append(_SQL_SELECT_ASSETENTRY_WHERE);
3178
3179 query.append(_FINDER_COLUMN_G_CU_GROUPID_2);
3180
3181 boolean bindClassUuid = false;
3182
3183 if (classUuid == null) {
3184 query.append(_FINDER_COLUMN_G_CU_CLASSUUID_1);
3185 }
3186 else if (classUuid.equals(StringPool.BLANK)) {
3187 query.append(_FINDER_COLUMN_G_CU_CLASSUUID_3);
3188 }
3189 else {
3190 bindClassUuid = true;
3191
3192 query.append(_FINDER_COLUMN_G_CU_CLASSUUID_2);
3193 }
3194
3195 String sql = query.toString();
3196
3197 Session session = null;
3198
3199 try {
3200 session = openSession();
3201
3202 Query q = session.createQuery(sql);
3203
3204 QueryPos qPos = QueryPos.getInstance(q);
3205
3206 qPos.add(groupId);
3207
3208 if (bindClassUuid) {
3209 qPos.add(classUuid);
3210 }
3211
3212 List<AssetEntry> list = q.list();
3213
3214 if (list.isEmpty()) {
3215 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_CU,
3216 finderArgs, list);
3217 }
3218 else {
3219 if ((list.size() > 1) && _log.isWarnEnabled()) {
3220 _log.warn(
3221 "AssetEntryPersistenceImpl.fetchByG_CU(long, String, boolean) with parameters (" +
3222 StringUtil.merge(finderArgs) +
3223 ") 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.");
3224 }
3225
3226 AssetEntry assetEntry = list.get(0);
3227
3228 result = assetEntry;
3229
3230 cacheResult(assetEntry);
3231
3232 if ((assetEntry.getGroupId() != groupId) ||
3233 (assetEntry.getClassUuid() == null) ||
3234 !assetEntry.getClassUuid().equals(classUuid)) {
3235 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_CU,
3236 finderArgs, assetEntry);
3237 }
3238 }
3239 }
3240 catch (Exception e) {
3241 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_CU,
3242 finderArgs);
3243
3244 throw processException(e);
3245 }
3246 finally {
3247 closeSession(session);
3248 }
3249 }
3250
3251 if (result instanceof List<?>) {
3252 return null;
3253 }
3254 else {
3255 return (AssetEntry)result;
3256 }
3257 }
3258
3259
3266 @Override
3267 public AssetEntry removeByG_CU(long groupId, String classUuid)
3268 throws NoSuchEntryException {
3269 AssetEntry assetEntry = findByG_CU(groupId, classUuid);
3270
3271 return remove(assetEntry);
3272 }
3273
3274
3281 @Override
3282 public int countByG_CU(long groupId, String classUuid) {
3283 FinderPath finderPath = FINDER_PATH_COUNT_BY_G_CU;
3284
3285 Object[] finderArgs = new Object[] { groupId, classUuid };
3286
3287 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3288 this);
3289
3290 if (count == null) {
3291 StringBundler query = new StringBundler(3);
3292
3293 query.append(_SQL_COUNT_ASSETENTRY_WHERE);
3294
3295 query.append(_FINDER_COLUMN_G_CU_GROUPID_2);
3296
3297 boolean bindClassUuid = false;
3298
3299 if (classUuid == null) {
3300 query.append(_FINDER_COLUMN_G_CU_CLASSUUID_1);
3301 }
3302 else if (classUuid.equals(StringPool.BLANK)) {
3303 query.append(_FINDER_COLUMN_G_CU_CLASSUUID_3);
3304 }
3305 else {
3306 bindClassUuid = true;
3307
3308 query.append(_FINDER_COLUMN_G_CU_CLASSUUID_2);
3309 }
3310
3311 String sql = query.toString();
3312
3313 Session session = null;
3314
3315 try {
3316 session = openSession();
3317
3318 Query q = session.createQuery(sql);
3319
3320 QueryPos qPos = QueryPos.getInstance(q);
3321
3322 qPos.add(groupId);
3323
3324 if (bindClassUuid) {
3325 qPos.add(classUuid);
3326 }
3327
3328 count = (Long)q.uniqueResult();
3329
3330 FinderCacheUtil.putResult(finderPath, finderArgs, count);
3331 }
3332 catch (Exception e) {
3333 FinderCacheUtil.removeResult(finderPath, finderArgs);
3334
3335 throw processException(e);
3336 }
3337 finally {
3338 closeSession(session);
3339 }
3340 }
3341
3342 return count.intValue();
3343 }
3344
3345 private static final String _FINDER_COLUMN_G_CU_GROUPID_2 = "assetEntry.groupId = ? AND ";
3346 private static final String _FINDER_COLUMN_G_CU_CLASSUUID_1 = "assetEntry.classUuid IS NULL";
3347 private static final String _FINDER_COLUMN_G_CU_CLASSUUID_2 = "assetEntry.classUuid = ?";
3348 private static final String _FINDER_COLUMN_G_CU_CLASSUUID_3 = "(assetEntry.classUuid IS NULL OR assetEntry.classUuid = '')";
3349 public static final FinderPath FINDER_PATH_FETCH_BY_C_C = new FinderPath(AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
3350 AssetEntryModelImpl.FINDER_CACHE_ENABLED, AssetEntryImpl.class,
3351 FINDER_CLASS_NAME_ENTITY, "fetchByC_C",
3352 new String[] { Long.class.getName(), Long.class.getName() },
3353 AssetEntryModelImpl.CLASSNAMEID_COLUMN_BITMASK |
3354 AssetEntryModelImpl.CLASSPK_COLUMN_BITMASK);
3355 public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
3356 AssetEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
3357 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C",
3358 new String[] { Long.class.getName(), Long.class.getName() });
3359
3360
3368 @Override
3369 public AssetEntry findByC_C(long classNameId, long classPK)
3370 throws NoSuchEntryException {
3371 AssetEntry assetEntry = fetchByC_C(classNameId, classPK);
3372
3373 if (assetEntry == null) {
3374 StringBundler msg = new StringBundler(6);
3375
3376 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3377
3378 msg.append("classNameId=");
3379 msg.append(classNameId);
3380
3381 msg.append(", classPK=");
3382 msg.append(classPK);
3383
3384 msg.append(StringPool.CLOSE_CURLY_BRACE);
3385
3386 if (_log.isWarnEnabled()) {
3387 _log.warn(msg.toString());
3388 }
3389
3390 throw new NoSuchEntryException(msg.toString());
3391 }
3392
3393 return assetEntry;
3394 }
3395
3396
3403 @Override
3404 public AssetEntry fetchByC_C(long classNameId, long classPK) {
3405 return fetchByC_C(classNameId, classPK, true);
3406 }
3407
3408
3416 @Override
3417 public AssetEntry fetchByC_C(long classNameId, long classPK,
3418 boolean retrieveFromCache) {
3419 Object[] finderArgs = new Object[] { classNameId, classPK };
3420
3421 Object result = null;
3422
3423 if (retrieveFromCache) {
3424 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_C,
3425 finderArgs, this);
3426 }
3427
3428 if (result instanceof AssetEntry) {
3429 AssetEntry assetEntry = (AssetEntry)result;
3430
3431 if ((classNameId != assetEntry.getClassNameId()) ||
3432 (classPK != assetEntry.getClassPK())) {
3433 result = null;
3434 }
3435 }
3436
3437 if (result == null) {
3438 StringBundler query = new StringBundler(4);
3439
3440 query.append(_SQL_SELECT_ASSETENTRY_WHERE);
3441
3442 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
3443
3444 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
3445
3446 String sql = query.toString();
3447
3448 Session session = null;
3449
3450 try {
3451 session = openSession();
3452
3453 Query q = session.createQuery(sql);
3454
3455 QueryPos qPos = QueryPos.getInstance(q);
3456
3457 qPos.add(classNameId);
3458
3459 qPos.add(classPK);
3460
3461 List<AssetEntry> list = q.list();
3462
3463 if (list.isEmpty()) {
3464 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
3465 finderArgs, list);
3466 }
3467 else {
3468 AssetEntry assetEntry = list.get(0);
3469
3470 result = assetEntry;
3471
3472 cacheResult(assetEntry);
3473
3474 if ((assetEntry.getClassNameId() != classNameId) ||
3475 (assetEntry.getClassPK() != classPK)) {
3476 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
3477 finderArgs, assetEntry);
3478 }
3479 }
3480 }
3481 catch (Exception e) {
3482 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C,
3483 finderArgs);
3484
3485 throw processException(e);
3486 }
3487 finally {
3488 closeSession(session);
3489 }
3490 }
3491
3492 if (result instanceof List<?>) {
3493 return null;
3494 }
3495 else {
3496 return (AssetEntry)result;
3497 }
3498 }
3499
3500
3507 @Override
3508 public AssetEntry removeByC_C(long classNameId, long classPK)
3509 throws NoSuchEntryException {
3510 AssetEntry assetEntry = findByC_C(classNameId, classPK);
3511
3512 return remove(assetEntry);
3513 }
3514
3515
3522 @Override
3523 public int countByC_C(long classNameId, long classPK) {
3524 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C;
3525
3526 Object[] finderArgs = new Object[] { classNameId, classPK };
3527
3528 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3529 this);
3530
3531 if (count == null) {
3532 StringBundler query = new StringBundler(3);
3533
3534 query.append(_SQL_COUNT_ASSETENTRY_WHERE);
3535
3536 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
3537
3538 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
3539
3540 String sql = query.toString();
3541
3542 Session session = null;
3543
3544 try {
3545 session = openSession();
3546
3547 Query q = session.createQuery(sql);
3548
3549 QueryPos qPos = QueryPos.getInstance(q);
3550
3551 qPos.add(classNameId);
3552
3553 qPos.add(classPK);
3554
3555 count = (Long)q.uniqueResult();
3556
3557 FinderCacheUtil.putResult(finderPath, finderArgs, count);
3558 }
3559 catch (Exception e) {
3560 FinderCacheUtil.removeResult(finderPath, finderArgs);
3561
3562 throw processException(e);
3563 }
3564 finally {
3565 closeSession(session);
3566 }
3567 }
3568
3569 return count.intValue();
3570 }
3571
3572 private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "assetEntry.classNameId = ? AND ";
3573 private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "assetEntry.classPK = ?";
3574
3575 public AssetEntryPersistenceImpl() {
3576 setModelClass(AssetEntry.class);
3577 }
3578
3579
3584 @Override
3585 public void cacheResult(AssetEntry assetEntry) {
3586 EntityCacheUtil.putResult(AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
3587 AssetEntryImpl.class, assetEntry.getPrimaryKey(), assetEntry);
3588
3589 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_CU,
3590 new Object[] { assetEntry.getGroupId(), assetEntry.getClassUuid() },
3591 assetEntry);
3592
3593 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
3594 new Object[] { assetEntry.getClassNameId(), assetEntry.getClassPK() },
3595 assetEntry);
3596
3597 assetEntry.resetOriginalValues();
3598 }
3599
3600
3605 @Override
3606 public void cacheResult(List<AssetEntry> assetEntries) {
3607 for (AssetEntry assetEntry : assetEntries) {
3608 if (EntityCacheUtil.getResult(
3609 AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
3610 AssetEntryImpl.class, assetEntry.getPrimaryKey()) == null) {
3611 cacheResult(assetEntry);
3612 }
3613 else {
3614 assetEntry.resetOriginalValues();
3615 }
3616 }
3617 }
3618
3619
3626 @Override
3627 public void clearCache() {
3628 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
3629 CacheRegistryUtil.clear(AssetEntryImpl.class.getName());
3630 }
3631
3632 EntityCacheUtil.clearCache(AssetEntryImpl.class);
3633
3634 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
3635 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3636 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3637 }
3638
3639
3646 @Override
3647 public void clearCache(AssetEntry assetEntry) {
3648 EntityCacheUtil.removeResult(AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
3649 AssetEntryImpl.class, assetEntry.getPrimaryKey());
3650
3651 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3652 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3653
3654 clearUniqueFindersCache(assetEntry);
3655 }
3656
3657 @Override
3658 public void clearCache(List<AssetEntry> assetEntries) {
3659 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3660 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3661
3662 for (AssetEntry assetEntry : assetEntries) {
3663 EntityCacheUtil.removeResult(AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
3664 AssetEntryImpl.class, assetEntry.getPrimaryKey());
3665
3666 clearUniqueFindersCache(assetEntry);
3667 }
3668 }
3669
3670 protected void cacheUniqueFindersCache(AssetEntry assetEntry) {
3671 if (assetEntry.isNew()) {
3672 Object[] args = new Object[] {
3673 assetEntry.getGroupId(), assetEntry.getClassUuid()
3674 };
3675
3676 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_CU, args,
3677 Long.valueOf(1));
3678 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_CU, args,
3679 assetEntry);
3680
3681 args = new Object[] {
3682 assetEntry.getClassNameId(), assetEntry.getClassPK()
3683 };
3684
3685 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, args,
3686 Long.valueOf(1));
3687 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C, args, assetEntry);
3688 }
3689 else {
3690 AssetEntryModelImpl assetEntryModelImpl = (AssetEntryModelImpl)assetEntry;
3691
3692 if ((assetEntryModelImpl.getColumnBitmask() &
3693 FINDER_PATH_FETCH_BY_G_CU.getColumnBitmask()) != 0) {
3694 Object[] args = new Object[] {
3695 assetEntry.getGroupId(), assetEntry.getClassUuid()
3696 };
3697
3698 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_CU, args,
3699 Long.valueOf(1));
3700 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_CU, args,
3701 assetEntry);
3702 }
3703
3704 if ((assetEntryModelImpl.getColumnBitmask() &
3705 FINDER_PATH_FETCH_BY_C_C.getColumnBitmask()) != 0) {
3706 Object[] args = new Object[] {
3707 assetEntry.getClassNameId(), assetEntry.getClassPK()
3708 };
3709
3710 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, args,
3711 Long.valueOf(1));
3712 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C, args,
3713 assetEntry);
3714 }
3715 }
3716 }
3717
3718 protected void clearUniqueFindersCache(AssetEntry assetEntry) {
3719 AssetEntryModelImpl assetEntryModelImpl = (AssetEntryModelImpl)assetEntry;
3720
3721 Object[] args = new Object[] {
3722 assetEntry.getGroupId(), assetEntry.getClassUuid()
3723 };
3724
3725 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_CU, args);
3726 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_CU, args);
3727
3728 if ((assetEntryModelImpl.getColumnBitmask() &
3729 FINDER_PATH_FETCH_BY_G_CU.getColumnBitmask()) != 0) {
3730 args = new Object[] {
3731 assetEntryModelImpl.getOriginalGroupId(),
3732 assetEntryModelImpl.getOriginalClassUuid()
3733 };
3734
3735 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_CU, args);
3736 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_CU, args);
3737 }
3738
3739 args = new Object[] { assetEntry.getClassNameId(), assetEntry.getClassPK() };
3740
3741 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
3742 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C, args);
3743
3744 if ((assetEntryModelImpl.getColumnBitmask() &
3745 FINDER_PATH_FETCH_BY_C_C.getColumnBitmask()) != 0) {
3746 args = new Object[] {
3747 assetEntryModelImpl.getOriginalClassNameId(),
3748 assetEntryModelImpl.getOriginalClassPK()
3749 };
3750
3751 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
3752 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C, args);
3753 }
3754 }
3755
3756
3762 @Override
3763 public AssetEntry create(long entryId) {
3764 AssetEntry assetEntry = new AssetEntryImpl();
3765
3766 assetEntry.setNew(true);
3767 assetEntry.setPrimaryKey(entryId);
3768
3769 return assetEntry;
3770 }
3771
3772
3779 @Override
3780 public AssetEntry remove(long entryId) throws NoSuchEntryException {
3781 return remove((Serializable)entryId);
3782 }
3783
3784
3791 @Override
3792 public AssetEntry remove(Serializable primaryKey)
3793 throws NoSuchEntryException {
3794 Session session = null;
3795
3796 try {
3797 session = openSession();
3798
3799 AssetEntry assetEntry = (AssetEntry)session.get(AssetEntryImpl.class,
3800 primaryKey);
3801
3802 if (assetEntry == null) {
3803 if (_log.isWarnEnabled()) {
3804 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
3805 }
3806
3807 throw new NoSuchEntryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
3808 primaryKey);
3809 }
3810
3811 return remove(assetEntry);
3812 }
3813 catch (NoSuchEntryException nsee) {
3814 throw nsee;
3815 }
3816 catch (Exception e) {
3817 throw processException(e);
3818 }
3819 finally {
3820 closeSession(session);
3821 }
3822 }
3823
3824 @Override
3825 protected AssetEntry removeImpl(AssetEntry assetEntry) {
3826 assetEntry = toUnwrappedModel(assetEntry);
3827
3828 assetEntryToAssetCategoryTableMapper.deleteLeftPrimaryKeyTableMappings(assetEntry.getPrimaryKey());
3829
3830 assetEntryToAssetTagTableMapper.deleteLeftPrimaryKeyTableMappings(assetEntry.getPrimaryKey());
3831
3832 Session session = null;
3833
3834 try {
3835 session = openSession();
3836
3837 if (!session.contains(assetEntry)) {
3838 assetEntry = (AssetEntry)session.get(AssetEntryImpl.class,
3839 assetEntry.getPrimaryKeyObj());
3840 }
3841
3842 if (assetEntry != null) {
3843 session.delete(assetEntry);
3844 }
3845 }
3846 catch (Exception e) {
3847 throw processException(e);
3848 }
3849 finally {
3850 closeSession(session);
3851 }
3852
3853 if (assetEntry != null) {
3854 clearCache(assetEntry);
3855 }
3856
3857 return assetEntry;
3858 }
3859
3860 @Override
3861 public AssetEntry updateImpl(
3862 com.liferay.portlet.asset.model.AssetEntry assetEntry) {
3863 assetEntry = toUnwrappedModel(assetEntry);
3864
3865 boolean isNew = assetEntry.isNew();
3866
3867 AssetEntryModelImpl assetEntryModelImpl = (AssetEntryModelImpl)assetEntry;
3868
3869 Session session = null;
3870
3871 try {
3872 session = openSession();
3873
3874 if (assetEntry.isNew()) {
3875 session.save(assetEntry);
3876
3877 assetEntry.setNew(false);
3878 }
3879 else {
3880 session.merge(assetEntry);
3881 }
3882 }
3883 catch (Exception e) {
3884 throw processException(e);
3885 }
3886 finally {
3887 closeSession(session);
3888 }
3889
3890 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3891
3892 if (isNew || !AssetEntryModelImpl.COLUMN_BITMASK_ENABLED) {
3893 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3894 }
3895
3896 else {
3897 if ((assetEntryModelImpl.getColumnBitmask() &
3898 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
3899 Object[] args = new Object[] {
3900 assetEntryModelImpl.getOriginalGroupId()
3901 };
3902
3903 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
3904 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
3905 args);
3906
3907 args = new Object[] { assetEntryModelImpl.getGroupId() };
3908
3909 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
3910 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
3911 args);
3912 }
3913
3914 if ((assetEntryModelImpl.getColumnBitmask() &
3915 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
3916 Object[] args = new Object[] {
3917 assetEntryModelImpl.getOriginalCompanyId()
3918 };
3919
3920 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
3921 args);
3922 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
3923 args);
3924
3925 args = new Object[] { assetEntryModelImpl.getCompanyId() };
3926
3927 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
3928 args);
3929 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
3930 args);
3931 }
3932
3933 if ((assetEntryModelImpl.getColumnBitmask() &
3934 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_VISIBLE.getColumnBitmask()) != 0) {
3935 Object[] args = new Object[] {
3936 assetEntryModelImpl.getOriginalVisible()
3937 };
3938
3939 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_VISIBLE, args);
3940 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_VISIBLE,
3941 args);
3942
3943 args = new Object[] { assetEntryModelImpl.getVisible() };
3944
3945 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_VISIBLE, args);
3946 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_VISIBLE,
3947 args);
3948 }
3949
3950 if ((assetEntryModelImpl.getColumnBitmask() &
3951 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PUBLISHDATE.getColumnBitmask()) != 0) {
3952 Object[] args = new Object[] {
3953 assetEntryModelImpl.getOriginalPublishDate()
3954 };
3955
3956 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_PUBLISHDATE,
3957 args);
3958 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PUBLISHDATE,
3959 args);
3960
3961 args = new Object[] { assetEntryModelImpl.getPublishDate() };
3962
3963 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_PUBLISHDATE,
3964 args);
3965 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PUBLISHDATE,
3966 args);
3967 }
3968
3969 if ((assetEntryModelImpl.getColumnBitmask() &
3970 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_EXPIRATIONDATE.getColumnBitmask()) != 0) {
3971 Object[] args = new Object[] {
3972 assetEntryModelImpl.getOriginalExpirationDate()
3973 };
3974
3975 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_EXPIRATIONDATE,
3976 args);
3977 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_EXPIRATIONDATE,
3978 args);
3979
3980 args = new Object[] { assetEntryModelImpl.getExpirationDate() };
3981
3982 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_EXPIRATIONDATE,
3983 args);
3984 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_EXPIRATIONDATE,
3985 args);
3986 }
3987
3988 if ((assetEntryModelImpl.getColumnBitmask() &
3989 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LAYOUTUUID.getColumnBitmask()) != 0) {
3990 Object[] args = new Object[] {
3991 assetEntryModelImpl.getOriginalLayoutUuid()
3992 };
3993
3994 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_LAYOUTUUID,
3995 args);
3996 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LAYOUTUUID,
3997 args);
3998
3999 args = new Object[] { assetEntryModelImpl.getLayoutUuid() };
4000
4001 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_LAYOUTUUID,
4002 args);
4003 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LAYOUTUUID,
4004 args);
4005 }
4006 }
4007
4008 EntityCacheUtil.putResult(AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
4009 AssetEntryImpl.class, assetEntry.getPrimaryKey(), assetEntry, false);
4010
4011 clearUniqueFindersCache(assetEntry);
4012 cacheUniqueFindersCache(assetEntry);
4013
4014 assetEntry.resetOriginalValues();
4015
4016 return assetEntry;
4017 }
4018
4019 protected AssetEntry toUnwrappedModel(AssetEntry assetEntry) {
4020 if (assetEntry instanceof AssetEntryImpl) {
4021 return assetEntry;
4022 }
4023
4024 AssetEntryImpl assetEntryImpl = new AssetEntryImpl();
4025
4026 assetEntryImpl.setNew(assetEntry.isNew());
4027 assetEntryImpl.setPrimaryKey(assetEntry.getPrimaryKey());
4028
4029 assetEntryImpl.setEntryId(assetEntry.getEntryId());
4030 assetEntryImpl.setGroupId(assetEntry.getGroupId());
4031 assetEntryImpl.setCompanyId(assetEntry.getCompanyId());
4032 assetEntryImpl.setUserId(assetEntry.getUserId());
4033 assetEntryImpl.setUserName(assetEntry.getUserName());
4034 assetEntryImpl.setCreateDate(assetEntry.getCreateDate());
4035 assetEntryImpl.setModifiedDate(assetEntry.getModifiedDate());
4036 assetEntryImpl.setClassNameId(assetEntry.getClassNameId());
4037 assetEntryImpl.setClassPK(assetEntry.getClassPK());
4038 assetEntryImpl.setClassUuid(assetEntry.getClassUuid());
4039 assetEntryImpl.setClassTypeId(assetEntry.getClassTypeId());
4040 assetEntryImpl.setListable(assetEntry.isListable());
4041 assetEntryImpl.setVisible(assetEntry.isVisible());
4042 assetEntryImpl.setStartDate(assetEntry.getStartDate());
4043 assetEntryImpl.setEndDate(assetEntry.getEndDate());
4044 assetEntryImpl.setPublishDate(assetEntry.getPublishDate());
4045 assetEntryImpl.setExpirationDate(assetEntry.getExpirationDate());
4046 assetEntryImpl.setMimeType(assetEntry.getMimeType());
4047 assetEntryImpl.setTitle(assetEntry.getTitle());
4048 assetEntryImpl.setDescription(assetEntry.getDescription());
4049 assetEntryImpl.setSummary(assetEntry.getSummary());
4050 assetEntryImpl.setUrl(assetEntry.getUrl());
4051 assetEntryImpl.setLayoutUuid(assetEntry.getLayoutUuid());
4052 assetEntryImpl.setHeight(assetEntry.getHeight());
4053 assetEntryImpl.setWidth(assetEntry.getWidth());
4054 assetEntryImpl.setPriority(assetEntry.getPriority());
4055 assetEntryImpl.setViewCount(assetEntry.getViewCount());
4056
4057 return assetEntryImpl;
4058 }
4059
4060
4067 @Override
4068 public AssetEntry findByPrimaryKey(Serializable primaryKey)
4069 throws NoSuchEntryException {
4070 AssetEntry assetEntry = fetchByPrimaryKey(primaryKey);
4071
4072 if (assetEntry == null) {
4073 if (_log.isWarnEnabled()) {
4074 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
4075 }
4076
4077 throw new NoSuchEntryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
4078 primaryKey);
4079 }
4080
4081 return assetEntry;
4082 }
4083
4084
4091 @Override
4092 public AssetEntry findByPrimaryKey(long entryId)
4093 throws NoSuchEntryException {
4094 return findByPrimaryKey((Serializable)entryId);
4095 }
4096
4097
4103 @Override
4104 public AssetEntry fetchByPrimaryKey(Serializable primaryKey) {
4105 AssetEntry assetEntry = (AssetEntry)EntityCacheUtil.getResult(AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
4106 AssetEntryImpl.class, primaryKey);
4107
4108 if (assetEntry == _nullAssetEntry) {
4109 return null;
4110 }
4111
4112 if (assetEntry == null) {
4113 Session session = null;
4114
4115 try {
4116 session = openSession();
4117
4118 assetEntry = (AssetEntry)session.get(AssetEntryImpl.class,
4119 primaryKey);
4120
4121 if (assetEntry != null) {
4122 cacheResult(assetEntry);
4123 }
4124 else {
4125 EntityCacheUtil.putResult(AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
4126 AssetEntryImpl.class, primaryKey, _nullAssetEntry);
4127 }
4128 }
4129 catch (Exception e) {
4130 EntityCacheUtil.removeResult(AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
4131 AssetEntryImpl.class, primaryKey);
4132
4133 throw processException(e);
4134 }
4135 finally {
4136 closeSession(session);
4137 }
4138 }
4139
4140 return assetEntry;
4141 }
4142
4143
4149 @Override
4150 public AssetEntry fetchByPrimaryKey(long entryId) {
4151 return fetchByPrimaryKey((Serializable)entryId);
4152 }
4153
4154 @Override
4155 public Map<Serializable, AssetEntry> fetchByPrimaryKeys(
4156 Set<Serializable> primaryKeys) {
4157 if (primaryKeys.isEmpty()) {
4158 return Collections.emptyMap();
4159 }
4160
4161 Map<Serializable, AssetEntry> map = new HashMap<Serializable, AssetEntry>();
4162
4163 if (primaryKeys.size() == 1) {
4164 Iterator<Serializable> iterator = primaryKeys.iterator();
4165
4166 Serializable primaryKey = iterator.next();
4167
4168 AssetEntry assetEntry = fetchByPrimaryKey(primaryKey);
4169
4170 if (assetEntry != null) {
4171 map.put(primaryKey, assetEntry);
4172 }
4173
4174 return map;
4175 }
4176
4177 Set<Serializable> uncachedPrimaryKeys = null;
4178
4179 for (Serializable primaryKey : primaryKeys) {
4180 AssetEntry assetEntry = (AssetEntry)EntityCacheUtil.getResult(AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
4181 AssetEntryImpl.class, primaryKey);
4182
4183 if (assetEntry == null) {
4184 if (uncachedPrimaryKeys == null) {
4185 uncachedPrimaryKeys = new HashSet<Serializable>();
4186 }
4187
4188 uncachedPrimaryKeys.add(primaryKey);
4189 }
4190 else {
4191 map.put(primaryKey, assetEntry);
4192 }
4193 }
4194
4195 if (uncachedPrimaryKeys == null) {
4196 return map;
4197 }
4198
4199 StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
4200 1);
4201
4202 query.append(_SQL_SELECT_ASSETENTRY_WHERE_PKS_IN);
4203
4204 for (Serializable primaryKey : uncachedPrimaryKeys) {
4205 query.append(String.valueOf(primaryKey));
4206
4207 query.append(StringPool.COMMA);
4208 }
4209
4210 query.setIndex(query.index() - 1);
4211
4212 query.append(StringPool.CLOSE_PARENTHESIS);
4213
4214 String sql = query.toString();
4215
4216 Session session = null;
4217
4218 try {
4219 session = openSession();
4220
4221 Query q = session.createQuery(sql);
4222
4223 for (AssetEntry assetEntry : (List<AssetEntry>)q.list()) {
4224 map.put(assetEntry.getPrimaryKeyObj(), assetEntry);
4225
4226 cacheResult(assetEntry);
4227
4228 uncachedPrimaryKeys.remove(assetEntry.getPrimaryKeyObj());
4229 }
4230
4231 for (Serializable primaryKey : uncachedPrimaryKeys) {
4232 EntityCacheUtil.putResult(AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
4233 AssetEntryImpl.class, primaryKey, _nullAssetEntry);
4234 }
4235 }
4236 catch (Exception e) {
4237 throw processException(e);
4238 }
4239 finally {
4240 closeSession(session);
4241 }
4242
4243 return map;
4244 }
4245
4246
4251 @Override
4252 public List<AssetEntry> findAll() {
4253 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
4254 }
4255
4256
4267 @Override
4268 public List<AssetEntry> findAll(int start, int end) {
4269 return findAll(start, end, null);
4270 }
4271
4272
4284 @Override
4285 public List<AssetEntry> findAll(int start, int end,
4286 OrderByComparator<AssetEntry> orderByComparator) {
4287 boolean pagination = true;
4288 FinderPath finderPath = null;
4289 Object[] finderArgs = null;
4290
4291 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4292 (orderByComparator == null)) {
4293 pagination = false;
4294 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
4295 finderArgs = FINDER_ARGS_EMPTY;
4296 }
4297 else {
4298 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
4299 finderArgs = new Object[] { start, end, orderByComparator };
4300 }
4301
4302 List<AssetEntry> list = (List<AssetEntry>)FinderCacheUtil.getResult(finderPath,
4303 finderArgs, this);
4304
4305 if (list == null) {
4306 StringBundler query = null;
4307 String sql = null;
4308
4309 if (orderByComparator != null) {
4310 query = new StringBundler(2 +
4311 (orderByComparator.getOrderByFields().length * 3));
4312
4313 query.append(_SQL_SELECT_ASSETENTRY);
4314
4315 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4316 orderByComparator);
4317
4318 sql = query.toString();
4319 }
4320 else {
4321 sql = _SQL_SELECT_ASSETENTRY;
4322
4323 if (pagination) {
4324 sql = sql.concat(AssetEntryModelImpl.ORDER_BY_JPQL);
4325 }
4326 }
4327
4328 Session session = null;
4329
4330 try {
4331 session = openSession();
4332
4333 Query q = session.createQuery(sql);
4334
4335 if (!pagination) {
4336 list = (List<AssetEntry>)QueryUtil.list(q, getDialect(),
4337 start, end, false);
4338
4339 Collections.sort(list);
4340
4341 list = Collections.unmodifiableList(list);
4342 }
4343 else {
4344 list = (List<AssetEntry>)QueryUtil.list(q, getDialect(),
4345 start, end);
4346 }
4347
4348 cacheResult(list);
4349
4350 FinderCacheUtil.putResult(finderPath, finderArgs, list);
4351 }
4352 catch (Exception e) {
4353 FinderCacheUtil.removeResult(finderPath, finderArgs);
4354
4355 throw processException(e);
4356 }
4357 finally {
4358 closeSession(session);
4359 }
4360 }
4361
4362 return list;
4363 }
4364
4365
4369 @Override
4370 public void removeAll() {
4371 for (AssetEntry assetEntry : findAll()) {
4372 remove(assetEntry);
4373 }
4374 }
4375
4376
4381 @Override
4382 public int countAll() {
4383 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
4384 FINDER_ARGS_EMPTY, this);
4385
4386 if (count == null) {
4387 Session session = null;
4388
4389 try {
4390 session = openSession();
4391
4392 Query q = session.createQuery(_SQL_COUNT_ASSETENTRY);
4393
4394 count = (Long)q.uniqueResult();
4395
4396 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
4397 FINDER_ARGS_EMPTY, count);
4398 }
4399 catch (Exception e) {
4400 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
4401 FINDER_ARGS_EMPTY);
4402
4403 throw processException(e);
4404 }
4405 finally {
4406 closeSession(session);
4407 }
4408 }
4409
4410 return count.intValue();
4411 }
4412
4413
4419 @Override
4420 public long[] getAssetCategoryPrimaryKeys(long pk) {
4421 long[] pks = assetEntryToAssetCategoryTableMapper.getRightPrimaryKeys(pk);
4422
4423 return pks.clone();
4424 }
4425
4426
4432 @Override
4433 public List<com.liferay.portlet.asset.model.AssetCategory> getAssetCategories(
4434 long pk) {
4435 return getAssetCategories(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
4436 }
4437
4438
4450 @Override
4451 public List<com.liferay.portlet.asset.model.AssetCategory> getAssetCategories(
4452 long pk, int start, int end) {
4453 return getAssetCategories(pk, start, end, null);
4454 }
4455
4456
4469 @Override
4470 public List<com.liferay.portlet.asset.model.AssetCategory> getAssetCategories(
4471 long pk, int start, int end,
4472 OrderByComparator<com.liferay.portlet.asset.model.AssetCategory> orderByComparator) {
4473 return assetEntryToAssetCategoryTableMapper.getRightBaseModels(pk,
4474 start, end, orderByComparator);
4475 }
4476
4477
4483 @Override
4484 public int getAssetCategoriesSize(long pk) {
4485 long[] pks = assetEntryToAssetCategoryTableMapper.getRightPrimaryKeys(pk);
4486
4487 return pks.length;
4488 }
4489
4490
4497 @Override
4498 public boolean containsAssetCategory(long pk, long assetCategoryPK) {
4499 return assetEntryToAssetCategoryTableMapper.containsTableMapping(pk,
4500 assetCategoryPK);
4501 }
4502
4503
4509 @Override
4510 public boolean containsAssetCategories(long pk) {
4511 if (getAssetCategoriesSize(pk) > 0) {
4512 return true;
4513 }
4514 else {
4515 return false;
4516 }
4517 }
4518
4519
4525 @Override
4526 public void addAssetCategory(long pk, long assetCategoryPK) {
4527 assetEntryToAssetCategoryTableMapper.addTableMapping(pk, assetCategoryPK);
4528 }
4529
4530
4536 @Override
4537 public void addAssetCategory(long pk,
4538 com.liferay.portlet.asset.model.AssetCategory assetCategory) {
4539 assetEntryToAssetCategoryTableMapper.addTableMapping(pk,
4540 assetCategory.getPrimaryKey());
4541 }
4542
4543
4549 @Override
4550 public void addAssetCategories(long pk, long[] assetCategoryPKs) {
4551 for (long assetCategoryPK : assetCategoryPKs) {
4552 assetEntryToAssetCategoryTableMapper.addTableMapping(pk,
4553 assetCategoryPK);
4554 }
4555 }
4556
4557
4563 @Override
4564 public void addAssetCategories(long pk,
4565 List<com.liferay.portlet.asset.model.AssetCategory> assetCategories) {
4566 for (com.liferay.portlet.asset.model.AssetCategory assetCategory : assetCategories) {
4567 assetEntryToAssetCategoryTableMapper.addTableMapping(pk,
4568 assetCategory.getPrimaryKey());
4569 }
4570 }
4571
4572
4577 @Override
4578 public void clearAssetCategories(long pk) {
4579 assetEntryToAssetCategoryTableMapper.deleteLeftPrimaryKeyTableMappings(pk);
4580 }
4581
4582
4588 @Override
4589 public void removeAssetCategory(long pk, long assetCategoryPK) {
4590 assetEntryToAssetCategoryTableMapper.deleteTableMapping(pk,
4591 assetCategoryPK);
4592 }
4593
4594
4600 @Override
4601 public void removeAssetCategory(long pk,
4602 com.liferay.portlet.asset.model.AssetCategory assetCategory) {
4603 assetEntryToAssetCategoryTableMapper.deleteTableMapping(pk,
4604 assetCategory.getPrimaryKey());
4605 }
4606
4607
4613 @Override
4614 public void removeAssetCategories(long pk, long[] assetCategoryPKs) {
4615 for (long assetCategoryPK : assetCategoryPKs) {
4616 assetEntryToAssetCategoryTableMapper.deleteTableMapping(pk,
4617 assetCategoryPK);
4618 }
4619 }
4620
4621
4627 @Override
4628 public void removeAssetCategories(long pk,
4629 List<com.liferay.portlet.asset.model.AssetCategory> assetCategories) {
4630 for (com.liferay.portlet.asset.model.AssetCategory assetCategory : assetCategories) {
4631 assetEntryToAssetCategoryTableMapper.deleteTableMapping(pk,
4632 assetCategory.getPrimaryKey());
4633 }
4634 }
4635
4636
4642 @Override
4643 public void setAssetCategories(long pk, long[] assetCategoryPKs) {
4644 Set<Long> newAssetCategoryPKsSet = SetUtil.fromArray(assetCategoryPKs);
4645 Set<Long> oldAssetCategoryPKsSet = SetUtil.fromArray(assetEntryToAssetCategoryTableMapper.getRightPrimaryKeys(
4646 pk));
4647
4648 Set<Long> removeAssetCategoryPKsSet = new HashSet<Long>(oldAssetCategoryPKsSet);
4649
4650 removeAssetCategoryPKsSet.removeAll(newAssetCategoryPKsSet);
4651
4652 for (long removeAssetCategoryPK : removeAssetCategoryPKsSet) {
4653 assetEntryToAssetCategoryTableMapper.deleteTableMapping(pk,
4654 removeAssetCategoryPK);
4655 }
4656
4657 newAssetCategoryPKsSet.removeAll(oldAssetCategoryPKsSet);
4658
4659 for (long newAssetCategoryPK : newAssetCategoryPKsSet) {
4660 assetEntryToAssetCategoryTableMapper.addTableMapping(pk,
4661 newAssetCategoryPK);
4662 }
4663 }
4664
4665
4671 @Override
4672 public void setAssetCategories(long pk,
4673 List<com.liferay.portlet.asset.model.AssetCategory> assetCategories) {
4674 try {
4675 long[] assetCategoryPKs = new long[assetCategories.size()];
4676
4677 for (int i = 0; i < assetCategories.size(); i++) {
4678 com.liferay.portlet.asset.model.AssetCategory assetCategory = assetCategories.get(i);
4679
4680 assetCategoryPKs[i] = assetCategory.getPrimaryKey();
4681 }
4682
4683 setAssetCategories(pk, assetCategoryPKs);
4684 }
4685 catch (Exception e) {
4686 throw processException(e);
4687 }
4688 }
4689
4690
4696 @Override
4697 public long[] getAssetTagPrimaryKeys(long pk) {
4698 long[] pks = assetEntryToAssetTagTableMapper.getRightPrimaryKeys(pk);
4699
4700 return pks.clone();
4701 }
4702
4703
4709 @Override
4710 public List<com.liferay.portlet.asset.model.AssetTag> getAssetTags(long pk) {
4711 return getAssetTags(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
4712 }
4713
4714
4726 @Override
4727 public List<com.liferay.portlet.asset.model.AssetTag> getAssetTags(
4728 long pk, int start, int end) {
4729 return getAssetTags(pk, start, end, null);
4730 }
4731
4732
4745 @Override
4746 public List<com.liferay.portlet.asset.model.AssetTag> getAssetTags(
4747 long pk, int start, int end,
4748 OrderByComparator<com.liferay.portlet.asset.model.AssetTag> orderByComparator) {
4749 return assetEntryToAssetTagTableMapper.getRightBaseModels(pk, start,
4750 end, orderByComparator);
4751 }
4752
4753
4759 @Override
4760 public int getAssetTagsSize(long pk) {
4761 long[] pks = assetEntryToAssetTagTableMapper.getRightPrimaryKeys(pk);
4762
4763 return pks.length;
4764 }
4765
4766
4773 @Override
4774 public boolean containsAssetTag(long pk, long assetTagPK) {
4775 return assetEntryToAssetTagTableMapper.containsTableMapping(pk,
4776 assetTagPK);
4777 }
4778
4779
4785 @Override
4786 public boolean containsAssetTags(long pk) {
4787 if (getAssetTagsSize(pk) > 0) {
4788 return true;
4789 }
4790 else {
4791 return false;
4792 }
4793 }
4794
4795
4801 @Override
4802 public void addAssetTag(long pk, long assetTagPK) {
4803 assetEntryToAssetTagTableMapper.addTableMapping(pk, assetTagPK);
4804 }
4805
4806
4812 @Override
4813 public void addAssetTag(long pk,
4814 com.liferay.portlet.asset.model.AssetTag assetTag) {
4815 assetEntryToAssetTagTableMapper.addTableMapping(pk,
4816 assetTag.getPrimaryKey());
4817 }
4818
4819
4825 @Override
4826 public void addAssetTags(long pk, long[] assetTagPKs) {
4827 for (long assetTagPK : assetTagPKs) {
4828 assetEntryToAssetTagTableMapper.addTableMapping(pk, assetTagPK);
4829 }
4830 }
4831
4832
4838 @Override
4839 public void addAssetTags(long pk,
4840 List<com.liferay.portlet.asset.model.AssetTag> assetTags) {
4841 for (com.liferay.portlet.asset.model.AssetTag assetTag : assetTags) {
4842 assetEntryToAssetTagTableMapper.addTableMapping(pk,
4843 assetTag.getPrimaryKey());
4844 }
4845 }
4846
4847
4852 @Override
4853 public void clearAssetTags(long pk) {
4854 assetEntryToAssetTagTableMapper.deleteLeftPrimaryKeyTableMappings(pk);
4855 }
4856
4857
4863 @Override
4864 public void removeAssetTag(long pk, long assetTagPK) {
4865 assetEntryToAssetTagTableMapper.deleteTableMapping(pk, assetTagPK);
4866 }
4867
4868
4874 @Override
4875 public void removeAssetTag(long pk,
4876 com.liferay.portlet.asset.model.AssetTag assetTag) {
4877 assetEntryToAssetTagTableMapper.deleteTableMapping(pk,
4878 assetTag.getPrimaryKey());
4879 }
4880
4881
4887 @Override
4888 public void removeAssetTags(long pk, long[] assetTagPKs) {
4889 for (long assetTagPK : assetTagPKs) {
4890 assetEntryToAssetTagTableMapper.deleteTableMapping(pk, assetTagPK);
4891 }
4892 }
4893
4894
4900 @Override
4901 public void removeAssetTags(long pk,
4902 List<com.liferay.portlet.asset.model.AssetTag> assetTags) {
4903 for (com.liferay.portlet.asset.model.AssetTag assetTag : assetTags) {
4904 assetEntryToAssetTagTableMapper.deleteTableMapping(pk,
4905 assetTag.getPrimaryKey());
4906 }
4907 }
4908
4909
4915 @Override
4916 public void setAssetTags(long pk, long[] assetTagPKs) {
4917 Set<Long> newAssetTagPKsSet = SetUtil.fromArray(assetTagPKs);
4918 Set<Long> oldAssetTagPKsSet = SetUtil.fromArray(assetEntryToAssetTagTableMapper.getRightPrimaryKeys(
4919 pk));
4920
4921 Set<Long> removeAssetTagPKsSet = new HashSet<Long>(oldAssetTagPKsSet);
4922
4923 removeAssetTagPKsSet.removeAll(newAssetTagPKsSet);
4924
4925 for (long removeAssetTagPK : removeAssetTagPKsSet) {
4926 assetEntryToAssetTagTableMapper.deleteTableMapping(pk,
4927 removeAssetTagPK);
4928 }
4929
4930 newAssetTagPKsSet.removeAll(oldAssetTagPKsSet);
4931
4932 for (long newAssetTagPK : newAssetTagPKsSet) {
4933 assetEntryToAssetTagTableMapper.addTableMapping(pk, newAssetTagPK);
4934 }
4935 }
4936
4937
4943 @Override
4944 public void setAssetTags(long pk,
4945 List<com.liferay.portlet.asset.model.AssetTag> assetTags) {
4946 try {
4947 long[] assetTagPKs = new long[assetTags.size()];
4948
4949 for (int i = 0; i < assetTags.size(); i++) {
4950 com.liferay.portlet.asset.model.AssetTag assetTag = assetTags.get(i);
4951
4952 assetTagPKs[i] = assetTag.getPrimaryKey();
4953 }
4954
4955 setAssetTags(pk, assetTagPKs);
4956 }
4957 catch (Exception e) {
4958 throw processException(e);
4959 }
4960 }
4961
4962
4965 public void afterPropertiesSet() {
4966 assetEntryToAssetCategoryTableMapper = TableMapperFactory.getTableMapper("AssetEntries_AssetCategories",
4967 "entryId", "categoryId", this, assetCategoryPersistence);
4968
4969 assetEntryToAssetTagTableMapper = TableMapperFactory.getTableMapper("AssetEntries_AssetTags",
4970 "entryId", "tagId", this, assetTagPersistence);
4971 }
4972
4973 public void destroy() {
4974 EntityCacheUtil.removeCache(AssetEntryImpl.class.getName());
4975 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
4976 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4977 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4978
4979 TableMapperFactory.removeTableMapper("AssetEntries_AssetCategories");
4980 TableMapperFactory.removeTableMapper("AssetEntries_AssetTags");
4981 }
4982
4983 @BeanReference(type = AssetCategoryPersistence.class)
4984 protected AssetCategoryPersistence assetCategoryPersistence;
4985 protected TableMapper<AssetEntry, com.liferay.portlet.asset.model.AssetCategory> assetEntryToAssetCategoryTableMapper;
4986 @BeanReference(type = AssetTagPersistence.class)
4987 protected AssetTagPersistence assetTagPersistence;
4988 protected TableMapper<AssetEntry, com.liferay.portlet.asset.model.AssetTag> assetEntryToAssetTagTableMapper;
4989 private static final String _SQL_SELECT_ASSETENTRY = "SELECT assetEntry FROM AssetEntry assetEntry";
4990 private static final String _SQL_SELECT_ASSETENTRY_WHERE_PKS_IN = "SELECT assetEntry FROM AssetEntry assetEntry WHERE entryId IN (";
4991 private static final String _SQL_SELECT_ASSETENTRY_WHERE = "SELECT assetEntry FROM AssetEntry assetEntry WHERE ";
4992 private static final String _SQL_COUNT_ASSETENTRY = "SELECT COUNT(assetEntry) FROM AssetEntry assetEntry";
4993 private static final String _SQL_COUNT_ASSETENTRY_WHERE = "SELECT COUNT(assetEntry) FROM AssetEntry assetEntry WHERE ";
4994 private static final String _ORDER_BY_ENTITY_ALIAS = "assetEntry.";
4995 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No AssetEntry exists with the primary key ";
4996 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No AssetEntry exists with the key {";
4997 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
4998 private static final Log _log = LogFactoryUtil.getLog(AssetEntryPersistenceImpl.class);
4999 private static final AssetEntry _nullAssetEntry = new AssetEntryImpl() {
5000 @Override
5001 public Object clone() {
5002 return this;
5003 }
5004
5005 @Override
5006 public CacheModel<AssetEntry> toCacheModel() {
5007 return _nullAssetEntryCacheModel;
5008 }
5009 };
5010
5011 private static final CacheModel<AssetEntry> _nullAssetEntryCacheModel = new CacheModel<AssetEntry>() {
5012 @Override
5013 public AssetEntry toEntityModel() {
5014 return _nullAssetEntry;
5015 }
5016 };
5017 }